Engineering
Releases
News and Events

Introducing Spring Cloud App Broker

We recently announced the general availability of Spring Cloud Services 3.0, which involved a major redesign of the previous architecture used in that project. As detailed in the related blog post, Spring Cloud Services has moved to the latest versions of Spring Framework and Spring Boot, and is now built on a Reactive programming model and Spring WebFlux. Two key components of this redesign are offered as open source Spring Cloud projects.

The first project is Spring Cloud Open Service Broker. This project has been available for some time; however, the recent 3.0.0 release has itself been redesigned to incorporate a Reactive programming model and updated to support Spring WebFlux.

The second project, which is being introduced today, is Spring Cloud App Broker. Spring Cloud App Broker represents an abstraction of a significant piece of the underlying architecture in Spring Cloud Services, and we are pleased to announce that Spring Cloud App Broker 1.0.1 is now available.

Background

The Open Service Broker API project allows developers to deliver services to applications running within cloud native platforms such as Cloud Foundry, Kubernetes, and OpenShift. To date, the only option for building a Spring Boot based service broker application has been to add the Spring Cloud Open Service Broker starter to your project, include the required configuration, and implement the required interfaces. Spring Cloud Open Service Broker is less opinionated about service broker implementation and leaves many of those decisions to the developer, requiring the developer to implement all of the service broker application logic themselves.

Introduction

Spring Cloud App Broker is also a framework for building Spring Boot applications that implement the Open Service Broker API. It provides a framework based on Spring Boot that enables the developer to quickly create a service broker that deploys applications and services to the platform when managed services are provisioned. It builds on Spring Cloud Open Service Broker by offering opinionated implementations of the Spring Cloud Open Service Broker interfaces.

What does this mean in practical terms? Imagine that the managed services that are deployed by a service broker have a dependency on additional services or applications. Utilizing App Broker configuration properties, these services and applications can be declared and the dependencies defined. When the service broker receives a request to provision a new service instance, App Broker will manage the deployment or provisioning of dependent apps and services, and bind those services and apps where appropriate. Conversely, when a request is received to delete a service instance, App Broker will unbind and delete any dependent services and applications that were previously provisioned.

Getting Started

Create a Spring Boot application and include the Spring Cloud App Broker dependency in the application’s build file.

Maven Dependencies

Include the following in your application’s pom.xml file:

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-app-broker-cloudfoundry</artifactId>
        <version>1.0.1.RELEASE</version>
    </dependency>
</dependencies>

Gradle Dependencies

Include the following in your application’s build.gradle file:

dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-app-broker-cloudfoundry:1.0.1.RELEASE'
}

Configuring the Service Broker

The service broker is configured using Spring Boot externalized configuration, supplied using a YAML or Java Properties file (for example, you can provide configuration in the application.yml file). Because Spring Cloud App Broker builds on Spring Cloud Open Service Broker, you must provide Spring Cloud Open Service Broker configuration in order to use Spring Cloud App Broker.

Include Spring Cloud Open Service Broker configuration using properties under spring.cloud.openservicebroker, as in the following example:

spring:
  cloud:
    openservicebroker:
      catalog:
        services:
        - name: example
          id: ebca66fd-461d-415b-bba3-5e379d671c88
          description: A useful service
          bindable: true
          tags:
          - example
          plans:
          - name: standard
            id: e19e6bc3-37c1-4478-b70f-c7157ebbb28c
            description: A standard plan
            free: true

Include Spring Cloud App Broker configuration using properties under spring.cloud.appbroker, as in the following example:

spring:
  cloud:
    appbroker:
      services:
        - service-name: example
          plan-name: standard
          apps:
            - name: example-service-app1
              path: classpath:app1.jar
            - name: example-service-app2
              path: classpath:app2.jar
      deployer:
        cloudfoundry:
          api-host: api.sys.example.com
          api-port: 443
          username: admin
          password: adminpass
          default-org: test
          default-space: development

Service Instances

Backing apps and dependent services can be configured for one or more services that are managed by a service broker by using the following properties.

App Deployment Properties

Properties for a backing app can be configured as default for all app deployments, or each service’s backing app deployment may be configured individually. See the reference documentation for a more comprehensive list of available properties.

spring:
  cloud:
    appbroker:
      deployer:
        cloudfoundry:
          properties:
            memory: 1G
            health-check: http
            health-check-http-endpoint: /health
            health-check-timeout: 180

Set overriding values for a specific service in the service’s configuration under spring.cloud.appbroker.services.*, as shown in the following example:

spring:
  cloud:
    appbroker:
      services:
        - service-name: example
          plan-name: standard
          apps:
            - name: example-service-app1
              path: classpath:app1.jar
              properties:
                memory: 2G
                count: 2
                no-route: true
Service Configuration

A backing app may require one or more dependent services. For example, an app may require the use of a MySQL database. App Broker will create any configured services and bind them to the associated app. Services are configured using properties under services for the deployed app, as in the following example:

spring:
  cloud:
    appbroker:
      services:
        - service-name: example
          plan-name: standard
          apps:
            - name: example-service-app1
              path: classpath:app1.jar
              services:
              - service-instance-name: example-db
                name: mysql
                plan: small
                parameters:
                  param-key: param-value

Further Customization

In addition to the supported configuration described above, Spring Cloud App Broker offers further methods of customizing the process of provisioning service instances. For example, App Broker can generate and assign unique credentials for each backing app deployment through the use of customized credential providers.

Workflows are also provided for the various stages of creating, updating, and deleting service instances, and for creating and deleting service instance bindings. For example, CreateServiceInstanceWorkflow can be implemented and configured as a Spring Bean within the application to hook additional functionality into the request to create a service instance. This may be as simple as processing specific logging requirements.

Conclusion

Building functional service brokers can be challenging, but with the availability of projects such as Spring Cloud Open Service Broker and Spring Cloud App Broker, we are hoping to reduce the amount of boilerplate code and enable you to more quickly build your own service broker.

comments powered by Disqus