Adding example on how to create a custom Target service

This commit is contained in:
Alberto Rios
2020-02-27 12:50:40 +01:00
committed by Alberto C. Ríos
parent 20b3143bf3
commit 53e58832d5
2 changed files with 212 additions and 0 deletions

View File

@@ -212,6 +212,54 @@ If you use the `SpacePerServiceInstance` target, App Broker will deploy backing
If you use the `ServiceInstanceGuidSuffix` target, App Broker will deploy backing applications using a unique name and hostname that incorporates the service instance GUID provided by the platform at service instance create time. For Cloud Foundry, the target location will be the org named by `spring.cloud.appbroker.deployer.cloudfoundry.default-org`, the space named by `spring.cloud.appbroker.deployer.cloudfoundry.default-space`, and an application name as `[APP-NAME]-[SI-GUID]`, where `[APP-NAME]` is the `name` listed for the application under `spring.cloud.appbroker.services.apps` and `[SI-GUID]` is the service instance GUID. The application will also use a hostname incorporating the service instance GUID as a suffix, as `[APP-NAME]-[SI-GUID]`.
====== Creating a custom Target
If you want to create a custom Target, app broker provides a flexible way to add new targets by just creating a new `Bean` that extends from `TargetFactory` and implementing the `create` method:
[source,java]
----
public class CustomSpaceTarget extends TargetFactory<CustomSpaceTarget.Config> {
public CustomSpaceTarget() {
super(Config.class);
}
@Override
public Target create(Config config) {
return this::apply;
}
private ArtifactDetails apply(Map<String, String> properties, String name, String serviceInstanceId) {
String space = "my-custom-space";
properties.put(DeploymentProperties.TARGET_PROPERTY_KEY, space);
return ArtifactDetails.builder()
.name(name)
.properties(properties)
.build();
}
public static class Config {
}
}
----
Once configured, we can specify in our service the new custom Target:
[source, yml, indent=0]
----
spring:
cloud:
appbroker:
services:
- service-name: example
plan-name: standard
target:
name: CustomSpaceTarget
----
===== Service Instance Parameters
When a user provides parameters while creating or updating a service instance, App Broker can transform these parameters into details of the backing app deployment using parameters transformers. You can configure parameters transformers using properties under `parameters-transformers`, as in the following example: