+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Â
Implement Service Broker with Spring Boot #cf_tokyo
1. Implement  Service  Broker Â
with  Spring  Boot
Toshiaki  Maki  (@making)
Sr.  Solutions  Architect  @Pivotal
2016-âââ06-âââ01  Cloud  Foundry  Tokyo  Meetup #2
2. Who  am  I  ?
â˘Toshiaki  Maki  (@making)
â˘https://blog.ik.am
â˘Sr.  Solutions  Architect
â˘Spring  Framework  enthusiast
Spring
Framework
ĺžšĺşâźĺ Ľâž¨é
(Coming Â
Soon?)
ăăźăă§ăŻă
Java  EE
(Coming Â
Soon?)
5. Services  in  Cloud  Foundry
Application
Service  Broker
Service  Instance
User  Provided  Service
Managed  Services
MySQL
Redis
RabbitMQ ex.)  Oracle  DB
create-âââuser-âââprovided-âââservicecreate-âââservice
bind-âââservice
marketplace
6. Services  in  Cloud  Foundry
Application
Service  Broker
Service  Instance
User  Provided  Service
Managed  Services
MySQL
Redis
RabbitMQ ex.)  Oracle  DB
create-âââuser-âââprovided-âââservicecreate-âââservice
bind-âââservice
marketplace
đ
7. 7  APIs  in  Service  Broker
⢠GET  /v2/catalog
⢠PUT  /v2/service_̲instances/:instance_̲id
⢠PATCH  /v2/service_̲instances/:instance_̲id
⢠DELETE  /v2/service_̲instances/:instance_̲id
⢠PUT  /v2/service_̲instances/:instance_̲id/service_̲bindings/:binding_̲id
⢠DELETE  /v2/service_̲instances/:instance_̲id/service_̲bindings/:binding_̲id
⢠GET  /v2/service_̲instances/:instance_̲id/last_̲operation
8. API  Overview (create  service)
Cloud  Controller
Service
cf create-service PUT
/v2/service_̲instances/:instance_̲id
Service  Broker
cf delete-service DELETE
/v2/service_̲instances/:instance_̲id
9. API  Overview  (bind  service)
Cloud  Controller
Service
cf bind-service PUT
/v2/service_̲instances/:instance_̲id
/service_̲bindings/:binding_̲id
Service  Broker
cf unbind-service
DELETE
/v2/service_̲instances/:instance_̲id
/service_̲bindings/:binding_̲id
21. API Â Overview
Cloud  Controller
Service
cf create-service PUT
/v2/service_̲instances/:instance_̲id
Service  Broker
cf delete-service DELETE
/v2/service_̲instances/:instance_̲id
Implement  APIs
23. @SpringBootApplication @RestController
public class FakeServiceBroker {
// ...
@GetMapping("/v2/catalog")
CatalogResponse showCatalog() {/*...*/}
@PutMapping("/v2/service_instances/{instanceId}")
CreateResponse createServiceInstance(
@PathVariable String instanceId,
@RequestBody CreateRequest req) {/*...*/}
@PutMapping("/v2/service_instances/{instanceId}/service_bindings/{bindingId}")
BindResponse createServiceBinding(
@PathVariable String instanceId ,
@PathVariable String bindingId ,
@RequestBody BindRequest req) {/*...*/}
// ...
}
A lot  of
parameters
Need  to  handle Â
Exceptions  ...
24. @SpringBootApplication @RestController
public class FakeServiceBroker {
// ...
@GetMapping("/v2/catalog")
Map<String, Object> showCatalog() {/*...*/}
@PutMapping("/v2/service_instances/{instanceId}")
Map<String, Object> createServiceInstance(
@PathVariable String instanceId,
@RequestBody Map<String, Object> req) {/*...*/}
@PutMapping("/v2/service_instances/{instanceId}/service_bindings/{bindingId}")
Map<String, Object> createServiceBinding(
@PathVariable String instanceId ,
@PathVariable String bindingId ,
@RequestBody Map<String, Object> req) {/*...*/}
// ...
}
There  is Â
a convenient  way
đ
25. Spring  Cloud  CloudFoundry Service  Broker
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-
service-broker</artifactId>
<version>1.0.0.RC3</version>
</dependency>
https://github.com/spring-Ââcloud/spring-Ââcloud-Ââcloudfoundry-Ââservice-Ââbroker
Service  Broker  API  Version: 2.8 (cf-ââârelease  v226+)
28. @Component
public class FakeServiceInstanceService
implements ServiceInstanceService {
public CreateServiceInstanceResponse createServiceInstance(
CreateServiceInstanceRequest req) {
String serviceInstanceId = req.getServiceInstanceId();
// ...
return new CreateServiceInstanceResponse();
}
public GetLastServiceOperationResponse getLastOperation(
GetLastServiceOperationRequest req) {/* ... */}
public DeleteServiceInstanceResponse deleteServiceInstance(
DeleteServiceInstanceRequest req) {/* ... */}
public UpdateServiceInstanceResponse updateServiceInstance(
UpdateServiceInstanceRequest req) {/* ... */}}
29. @Component
public class FakeServiceInstanceService
implements ServiceInstanceService {
public CreateServiceInstanceResponse createServiceInstance(
CreateServiceInstanceRequest req) {
String serviceInstanceId = req.getServiceInstanceId();
// ...
return new CreateServiceInstanceResponse();
}
public GetLastServiceOperationResponse getLastOperation(
GetLastServiceOperationRequest req) {/* ... */}
public DeleteServiceInstanceResponse deleteServiceInstance(
DeleteServiceInstanceRequest req) {/* ... */}
public UpdateServiceInstanceResponse updateServiceInstance(
UpdateServiceInstanceRequest req) {/* ... */}}
Corresponds  to
PUT  /v2/service_̲instances/:instance_̲id
30. @Component
public class FakeServiceInstanceBindingService
implements ServiceInstanceBindingService {
public CreateServiceInstanceBindingResponse createServiceInstanceBinding(
CreateServiceInstanceBindingRequest req) {
String serviceInstanceId = req.getServiceInstanceId();
String bindingId = req.getBindingId();
// ...
Map<String, Object> credentials = new HashMap<String, Object>() {{
put("url", "...");
put("username", "...");
put("password", "...");
}};
return new CreateServiceInstanceAppBindingResponse()
.withCredentials(credentials);
}
public void deleteServiceInstanceBinding(
DeleteServiceInstanceBindingRequest req) {
// ...
}
}
31. @Component
public class FakeServiceInstanceBindingService
implements ServiceInstanceBindingService {
public CreateServiceInstanceBindingResponse createServiceInstanceBinding(
CreateServiceInstanceBindingRequest req) {
String serviceInstanceId = req.getServiceInstanceId();
String bindingId = req.getBindingId();
// ...
Map<String, Object> credentials = new HashMap<String, Object>() {{
put("url", "...");
put("username", "...");
put("password", "...");
}};
return new CreateServiceInstanceAppBindingResponse()
.withCredentials(credentials);
}
public void deleteServiceInstanceBinding(
DeleteServiceInstanceBindingRequest req) {
// ...
}
}
Corresponds  to
PUT  /v2/service_̲instances/:instance_̲id
/service_̲bindings/:binding_̲id
32. @SpringBootApplication
public class FakeServiceBroker {
public static void main(String[] args) {
SpringBootApplication.run(
FakeServiceBroker.class, args);
}
@Bean
Catalog catalog() {
return new Catalog(singletonList(
new ServiceDefinition(
"fake-broker",
"p-fake",
"A fake service broker", ...)));
}
}
33. @SpringBootApplication
public class FakeServiceBroker {
public static void main(String[] args) {
SpringBootApplication.run(
FakeServiceBroker.class, args);
}
@Bean
Catalog catalog() {
return new Catalog(singletonList(
new ServiceDefinition(
"fake-broker",
"p-fake",
"A fake service broker", ...)));
}
}
Corresponds  to  GET  /v2/catalog
37. Deploy  Service  Broker
to  Cloud  Foundry
$ ./mvnw clean package
$ cf push fake -p target/fake-1.0.0-SNAPSHOT.jar
$ curl http://fake.local.pcfdev.io/v2/catalog
38. Enable  Service  Broker
$ cf create-service-broker p-fake fake fake ÂĽ
http://fake.local.pcfdev.io
$ cf enable-service-access p-fake
Service  Name Username Password
41. Enable  Service  Broker
$ cf create-service-broker p-fake fake fake ÂĽ
http://fake.cfapp.io
Server error, status code: 403, error code:
10003, message: You are not authorized to
perform the requested action
đŤ
42. $ cf create-service-broker p-fake fake fake ÂĽ
http://fake.cfapps.io ÂĽ
--space-scoped
Enable  Service  Broker
(Space  Scoped)
CF Â CLI Â 6.16.0+