diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java index 1c1731a..cd097c1 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentService.java @@ -32,11 +32,11 @@ public class BackingAppDeploymentService { this.deployerClient = deployerClient; } - public Flux deploy(List backingApps) { + public Flux deploy(List backingApps, String serviceInstanceId) { return Flux.fromIterable(backingApps) .parallel() .runOn(Schedulers.parallel()) - .flatMap(deployerClient::deploy) + .flatMap(backingApplication -> deployerClient.deploy(backingApplication, serviceInstanceId)) .sequential() .doOnRequest(l -> log.debug("Deploying applications {}", backingApps)) .doOnEach(response -> log.debug("Finished deploying application {}", response)) @@ -45,11 +45,11 @@ public class BackingAppDeploymentService { backingApps, exception.getMessage())); } - public Flux update(List backingApps) { + public Flux update(List backingApps, String serviceInstanceId) { return Flux.fromIterable(backingApps) .parallel() .runOn(Schedulers.parallel()) - .flatMap(deployerClient::update) + .flatMap(backingApplication -> deployerClient.update(backingApplication, serviceInstanceId)) .sequential() .doOnRequest(l -> log.debug("Updating applications {}", backingApps)) .doOnEach(response -> log.debug("Finished updating application {}", response)) diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/DeployerClient.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/DeployerClient.java index ca36bc5..2ea7739 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/DeployerClient.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/deployer/DeployerClient.java @@ -32,7 +32,7 @@ public class DeployerClient { this.appDeployer = appDeployer; } - Mono deploy(BackingApplication backingApplication) { + Mono deploy(BackingApplication backingApplication, String serviceInstanceId) { return appDeployer .deploy(DeployApplicationRequest .builder() @@ -40,7 +40,10 @@ public class DeployerClient { .path(backingApplication.getPath()) .properties(backingApplication.getProperties()) .environment(backingApplication.getEnvironment()) - .services(backingApplication.getServices().stream().map(ServicesSpec::getServiceInstanceName).collect(Collectors.toList())) + .services(backingApplication.getServices().stream() + .map(ServicesSpec::getServiceInstanceName) + .collect(Collectors.toList())) + .serviceInstanceId(serviceInstanceId) .build()) .doOnRequest(l -> log.debug("Deploying application {}", backingApplication)) .doOnSuccess(response -> log.debug("Finished deploying application {}", backingApplication)) @@ -49,7 +52,7 @@ public class DeployerClient { .map(DeployApplicationResponse::getName); } - Mono update(BackingApplication backingApplication) { + Mono update(BackingApplication backingApplication, String serviceInstanceId) { return appDeployer .update(UpdateApplicationRequest .builder() @@ -57,11 +60,15 @@ public class DeployerClient { .path(backingApplication.getPath()) .properties(backingApplication.getProperties()) .environment(backingApplication.getEnvironment()) - .services(backingApplication.getServices().stream().map(ServicesSpec::getServiceInstanceName).collect(Collectors.toList())) + .services(backingApplication.getServices().stream() + .map(ServicesSpec::getServiceInstanceName) + .collect(Collectors.toList())) + .serviceInstanceId(serviceInstanceId) .build()) .doOnRequest(l -> log.debug("Updating application {}", backingApplication)) .doOnSuccess(response -> log.debug("Finished updating application {}", backingApplication)) - .doOnError(exception -> log.error("Error updating application {} with error {}", backingApplication, exception)) + .doOnError(exception -> log.error("Error updating application {} with error {}", + backingApplication, exception)) .map(UpdateApplicationResponse::getName); } diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflow.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflow.java index e3f4f7c..28b17f8 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflow.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflow.java @@ -101,7 +101,7 @@ public class AppDeploymentCreateServiceInstanceWorkflow .flatMap(backingApps -> credentialProviderService.addCredentials(backingApps, request.getServiceInstanceId())) - .flatMapMany(deploymentService::deploy) + .flatMapMany(backingApps -> deploymentService.deploy(backingApps, request.getServiceInstanceId())) .doOnRequest(l -> log.debug("Deploying backing applications for {}/{}", request.getServiceDefinition().getName(), request.getPlan().getName())) .doOnComplete(() -> log.debug("Finished deploying backing applications for {}/{}", diff --git a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflow.java b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflow.java index 7e064c3..ac9fab0 100644 --- a/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflow.java +++ b/spring-cloud-app-broker-core/src/main/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflow.java @@ -92,7 +92,7 @@ public class AppDeploymentUpdateServiceInstanceWorkflow request.getServiceInstanceId())) .flatMap(backingApps -> appsParametersTransformationService.transformParameters(backingApps, request.getParameters())) - .flatMapMany(deploymentService::update) + .flatMapMany(backingApps -> deploymentService.update(backingApps, request.getServiceInstanceId())) .doOnRequest(l -> log.debug("Updating backing applications for {}/{}", request.getServiceDefinition().getName(), request.getPlan().getName())) .doOnComplete(() -> log.debug("Finished updating backing applications for {}/{}", diff --git a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentServiceTest.java b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentServiceTest.java index eb2f90d..416fec8 100644 --- a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentServiceTest.java +++ b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/BackingAppDeploymentServiceTest.java @@ -41,15 +41,15 @@ class BackingAppDeploymentServiceTest { @SuppressWarnings("UnassignedFluxMonoInstance") void shouldDeployApplications() { doReturn(Mono.just("app1")) - .when(deployerClient).deploy(backingApps.get(0)); + .when(deployerClient).deploy(backingApps.get(0), "instance-id"); doReturn(Mono.just("app2")) - .when(deployerClient).deploy(backingApps.get(1)); + .when(deployerClient).deploy(backingApps.get(1), "instance-id"); List expectedValues = new ArrayList<>(); expectedValues.add("app1"); expectedValues.add("app2"); - StepVerifier.create(backingAppDeploymentService.deploy(backingApps)) + StepVerifier.create(backingAppDeploymentService.deploy(backingApps, "instance-id")) // deployments are run in parallel, so the order of completion is not predictable // ensure that both expected signals are sent in any order .expectNextMatches(expectedValues::remove) diff --git a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/DeployerClientTest.java b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/DeployerClientTest.java index 90b0141..2619776 100644 --- a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/DeployerClientTest.java +++ b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/deployer/DeployerClientTest.java @@ -64,7 +64,7 @@ class DeployerClientTest { .build(); // when - StepVerifier.create(deployerClient.deploy(application)) + StepVerifier.create(deployerClient.deploy(application, "instance-id")) // then .expectNext(APP_NAME) .verifyComplete(); @@ -90,7 +90,7 @@ class DeployerClientTest { .build(); // when - StepVerifier.create(deployerClient.deploy(application)) + StepVerifier.create(deployerClient.deploy(application, "instance-id")) // then .expectNext(APP_NAME) .verifyComplete(); @@ -116,7 +116,7 @@ class DeployerClientTest { .build(); // when - StepVerifier.create(deployerClient.deploy(application)) + StepVerifier.create(deployerClient.deploy(application, "instance-id")) // then .expectNext(APP_NAME) .verifyComplete(); @@ -142,7 +142,7 @@ class DeployerClientTest { .build(); // when - StepVerifier.create(deployerClient.deploy(application)) + StepVerifier.create(deployerClient.deploy(application, "instance-id")) // then .expectNext(APP_NAME) .verifyComplete(); diff --git a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflowTest.java b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflowTest.java index 6fdb03c..e5c1ac8 100644 --- a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflowTest.java +++ b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentCreateServiceInstanceWorkflowTest.java @@ -146,7 +146,7 @@ class AppDeploymentCreateServiceInstanceWorkflowTest { .expectNext() .verifyComplete(); - verify(appDeploymentService).deploy(backingApps); + verify(appDeploymentService).deploy(backingApps, request.getServiceInstanceId()); verify(servicesProvisionService).createServiceInstance(backingServices); final String expectedServiceId = "service-instance-id"; @@ -161,8 +161,7 @@ class AppDeploymentCreateServiceInstanceWorkflowTest { void createServiceInstanceWithParametersSucceeds() { Map parameters = singletonMap("ENV_VAR_1", "value from parameters"); - CreateServiceInstanceRequest request = buildRequest("service1", "plan1", - parameters); + CreateServiceInstanceRequest request = buildRequest("service1", "plan1", parameters); CreateServiceInstanceResponse response = CreateServiceInstanceResponse.builder().build(); setupMocks(request); @@ -173,7 +172,7 @@ class AppDeploymentCreateServiceInstanceWorkflowTest { .expectNext() .verifyComplete(); - verify(appDeploymentService).deploy(backingApps); + verify(appDeploymentService).deploy(backingApps, request.getServiceInstanceId()); verify(servicesProvisionService).createServiceInstance(backingServices); verify(appsParametersTransformationService) @@ -198,7 +197,7 @@ class AppDeploymentCreateServiceInstanceWorkflowTest { } private void setupMocks(CreateServiceInstanceRequest request) { - given(this.appDeploymentService.deploy(eq(backingApps))) + given(this.appDeploymentService.deploy(eq(backingApps), eq(request.getServiceInstanceId()))) .willReturn(Flux.just("app1", "app2")); given(this.servicesProvisionService.createServiceInstance(eq(backingServices))) .willReturn(Flux.just("my-service-instance")); diff --git a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflowTest.java b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflowTest.java index 6850402..f52fda8 100644 --- a/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflowTest.java +++ b/spring-cloud-app-broker-core/src/test/java/org/springframework/cloud/appbroker/workflow/instance/AppDeploymentUpdateServiceInstanceWorkflowTest.java @@ -136,7 +136,7 @@ class AppDeploymentUpdateServiceInstanceWorkflowTest { .expectNext() .verifyComplete(); - verify(appDeploymentService).update(backingApps); + verify(appDeploymentService).update(backingApps, request.getServiceInstanceId()); verify(servicesProvisionService).updateServiceInstance(backingServices); final String expectedServiceId = "service-instance-id"; @@ -176,7 +176,7 @@ class AppDeploymentUpdateServiceInstanceWorkflowTest { } private void setupMocks(UpdateServiceInstanceRequest request) { - given(this.appDeploymentService.update(eq(backingApps))) + given(this.appDeploymentService.update(eq(backingApps), eq(request.getServiceInstanceId()))) .willReturn(Flux.just("app1", "app2")); given(this.servicesProvisionService.updateServiceInstance(eq(backingServices))) .willReturn(Flux.just("my-service-instance")); diff --git a/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java b/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java index 87419a5..7ffe9b8 100644 --- a/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java +++ b/spring-cloud-app-broker-deployer-cloudfoundry/src/main/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployer.java @@ -388,7 +388,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware ApplicationManifest.Builder manifest = ApplicationManifest.builder() .name(request.getName()) .path(getApplication(appResource)) - .environmentVariables(getEnvironmentVariables(deploymentProperties, request.getEnvironment())) + .environmentVariables(getEnvironmentVariables(deploymentProperties, + request.getEnvironment(), request.getServiceInstanceId())) .services(request.getServices()) .instances(instances(deploymentProperties)) .memory(memory(deploymentProperties)) @@ -533,7 +534,8 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware } private Map getEnvironmentVariables(Map properties, - Map environment) { + Map environment, + String serviceInstanceId) { Map envVariables = getApplicationEnvironment(properties, environment); String javaOpts = javaOpts(properties); @@ -541,15 +543,16 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware envVariables.put("JAVA_OPTS", javaOpts); } - envVariables.put("SPRING_CLOUD_APPLICATION_GUID", "${vcap.application.name}:${vcap.application.instance_index}"); - envVariables.put("SPRING_APPLICATION_INDEX", "${vcap.application.instance_index}"); + if (serviceInstanceId != null) { + envVariables.put("SPRING_CLOUD_APPBROKER_SERVICE_INSTANCE_ID", serviceInstanceId); + } return envVariables; } private Map getApplicationEnvironment(Map properties, Map environment) { - Map applicationEnvironment = getSanitizedApplicationEnvironment(environment); + Map applicationEnvironment = sanitizeApplicationEnvironment(environment); if (!applicationEnvironment.isEmpty() && useSpringApplicationJson(properties)) { try { @@ -564,7 +567,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware return applicationEnvironment; } - private Map getSanitizedApplicationEnvironment(Map environment) { + private Map sanitizeApplicationEnvironment(Map environment) { Map applicationEnvironment = new HashMap<>(environment); // Remove server.port as CF assigns a port for us, and we don't want to override that diff --git a/spring-cloud-app-broker-deployer-cloudfoundry/src/test/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployerTest.java b/spring-cloud-app-broker-deployer-cloudfoundry/src/test/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployerTest.java index f78ef46..a0199b3 100644 --- a/spring-cloud-app-broker-deployer-cloudfoundry/src/test/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployerTest.java +++ b/spring-cloud-app-broker-deployer-cloudfoundry/src/test/java/org/springframework/cloud/appbroker/deployer/cloudfoundry/CloudFoundryAppDeployerTest.java @@ -69,6 +69,7 @@ class CloudFoundryAppDeployerTest { private static final String APP_NAME = "test-app"; private static final String APP_PATH = "test.jar"; + private static final String SERVICE_INSTANCE_ID = "service-instance-id"; private AppDeployer appDeployer; @@ -117,6 +118,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .build(); StepVerifier.create(appDeployer.deploy(request)) @@ -136,6 +138,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .property(DeploymentProperties.COUNT_PROPERTY_KEY, "3") .property(DeploymentProperties.MEMORY_PROPERTY_KEY, "2G") .property(DeploymentProperties.DISK_PROPERTY_KEY, "3G") @@ -182,6 +185,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .build(); StepVerifier.create(appDeployer.deploy(request)) @@ -218,6 +222,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .property(DeploymentProperties.COUNT_PROPERTY_KEY, "5") .property(DeploymentProperties.MEMORY_PROPERTY_KEY, "4G") .property(DeploymentProperties.DISK_PROPERTY_KEY, "5G") @@ -257,6 +262,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .property(CloudFoundryDeploymentProperties.JAVA_OPTS_PROPERTY_KEY, "-Xms512m -Xmx1024m") .environment("ENV_VAR_1", "value1") .environment("ENV_VAR_2", "value2") @@ -283,6 +289,7 @@ class CloudFoundryAppDeployerTest { DeployApplicationRequest request = DeployApplicationRequest.builder() .name(APP_NAME) .path(APP_PATH) + .serviceInstanceId(SERVICE_INSTANCE_ID) .property(CloudFoundryDeploymentProperties.JAVA_OPTS_PROPERTY_KEY, "-Xms512m -Xmx1024m") .environment("ENV_VAR_1", "value1") .environment("ENV_VAR_2", "value2") @@ -469,8 +476,7 @@ class CloudFoundryAppDeployerTest { private ApplicationManifest.Builder baseManifest() { return ApplicationManifest.builder() - .environmentVariable("SPRING_APPLICATION_INDEX", "${vcap.application.instance_index}") - .environmentVariable("SPRING_CLOUD_APPLICATION_GUID", "${vcap.application.name}:${vcap.application.instance_index}") + .environmentVariable("SPRING_CLOUD_APPBROKER_SERVICE_INSTANCE_ID", SERVICE_INSTANCE_ID) .services(new ArrayList<>()); } diff --git a/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/DeployApplicationRequest.java b/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/DeployApplicationRequest.java index b36faf0..1be3cfc 100644 --- a/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/DeployApplicationRequest.java +++ b/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/DeployApplicationRequest.java @@ -33,17 +33,17 @@ public class DeployApplicationRequest { private final List services; + private final String serviceInstanceId; + DeployApplicationRequest(String name, String path, Map properties, - Map environment, List services) { + Map environment, List services, + String serviceInstanceId) { this.name = name; this.path = path; this.properties = properties; this.environment = environment; this.services = services; - } - - public static DeployApplicationRequestBuilder builder() { - return new DeployApplicationRequestBuilder(); + this.serviceInstanceId = serviceInstanceId; } public String getName() { @@ -66,17 +66,22 @@ public class DeployApplicationRequest { return services; } + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public static DeployApplicationRequestBuilder builder() { + return new DeployApplicationRequestBuilder(); + } + public static class DeployApplicationRequestBuilder { private String name; - private String path; - private final Map properties = new HashMap<>(); - private final Map environment = new HashMap<>(); - private final List services = new ArrayList<>(); + private String serviceInstanceId; DeployApplicationRequestBuilder() { } @@ -127,8 +132,13 @@ public class DeployApplicationRequest { return this; } + public DeployApplicationRequestBuilder serviceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + return this; + } + public DeployApplicationRequest build() { - return new DeployApplicationRequest(name, path, properties, environment, services); + return new DeployApplicationRequest(name, path, properties, environment, services, serviceInstanceId); } } diff --git a/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/UpdateApplicationRequest.java b/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/UpdateApplicationRequest.java index 18c4980..d2bbb0f 100644 --- a/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/UpdateApplicationRequest.java +++ b/spring-cloud-app-broker-deployer/src/main/java/org/springframework/cloud/appbroker/deployer/UpdateApplicationRequest.java @@ -33,17 +33,17 @@ public class UpdateApplicationRequest { private final List services; + private final String serviceInstanceId; + UpdateApplicationRequest(String name, String path, Map properties, - Map environment, List services) { + Map environment, List services, + String serviceInstanceId) { this.name = name; this.path = path; this.properties = properties; this.environment = environment; this.services = services; - } - - public static DeployApplicationRequestBuilder builder() { - return new DeployApplicationRequestBuilder(); + this.serviceInstanceId = serviceInstanceId; } public String getName() { @@ -66,37 +66,42 @@ public class UpdateApplicationRequest { return services; } - public static class DeployApplicationRequestBuilder { + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public static UpdateApplicationRequestBuilder builder() { + return new UpdateApplicationRequestBuilder(); + } + + public static class UpdateApplicationRequestBuilder { private String name; - private String path; - private final Map properties = new HashMap<>(); - private final Map environment = new HashMap<>(); - private final List services = new ArrayList<>(); + private String serviceInstanceId; - DeployApplicationRequestBuilder() { + UpdateApplicationRequestBuilder() { } - public DeployApplicationRequestBuilder name(String name) { + public UpdateApplicationRequestBuilder name(String name) { this.name = name; return this; } - public DeployApplicationRequestBuilder path(String path) { + public UpdateApplicationRequestBuilder path(String path) { this.path = path; return this; } - public DeployApplicationRequestBuilder property(String key, String value) { + public UpdateApplicationRequestBuilder property(String key, String value) { this.properties.put(key, value); return this; } - public DeployApplicationRequestBuilder properties(Map properties) { + public UpdateApplicationRequestBuilder properties(Map properties) { if (properties == null) { return this; } @@ -104,12 +109,12 @@ public class UpdateApplicationRequest { return this; } - public DeployApplicationRequestBuilder environment(String key, String value) { + public UpdateApplicationRequestBuilder environment(String key, String value) { this.environment.put(key, value); return this; } - public DeployApplicationRequestBuilder environment(Map environment) { + public UpdateApplicationRequestBuilder environment(Map environment) { if (environment == null) { return this; } @@ -117,18 +122,23 @@ public class UpdateApplicationRequest { return this; } - public DeployApplicationRequestBuilder service(String service) { + public UpdateApplicationRequestBuilder service(String service) { this.services.add(service); return this; } - public DeployApplicationRequestBuilder services(List services) { + public UpdateApplicationRequestBuilder services(List services) { this.services.addAll(services); return this; } + public UpdateApplicationRequestBuilder serviceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + return this; + } + public UpdateApplicationRequest build() { - return new UpdateApplicationRequest(name, path, properties, environment, services); + return new UpdateApplicationRequest(name, path, properties, environment, services, serviceInstanceId); } } diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateBindingWithCredHubComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateBindingWithCredHubComponentTest.java index 0594ef1..d9912db 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateBindingWithCredHubComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateBindingWithCredHubComponentTest.java @@ -27,7 +27,7 @@ import org.springframework.test.context.TestPropertySource; import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath; import static io.restassured.RestAssured.given; -import static org.springframework.cloud.appbroker.integration.CreateInstanceWithBasicAuthCredentialsComponentTest.APP_NAME; +import static org.springframework.cloud.appbroker.integration.CreateBindingWithCredHubComponentTest.APP_NAME; @TestPropertySource(properties = { "spring.cloud.appbroker.services[0].service-name=example", @@ -39,6 +39,8 @@ import static org.springframework.cloud.appbroker.integration.CreateInstanceWith }) class CreateBindingWithCredHubComponentTest extends WiremockComponentTest { + static final String APP_NAME = "create-binding-credhub"; + private static final String SERVICE_INSTANCE_ID = "instance-id"; private static final String BINDING_ID = "binding-id"; private static final String CREDENTIAL_NAME = "credentials-json"; diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceComponentTest.java index 8b39dbb..02c14b0 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceComponentTest.java @@ -24,6 +24,7 @@ import org.springframework.cloud.servicebroker.model.instance.OperationState; import org.springframework.http.HttpStatus; import org.springframework.test.context.TestPropertySource; +import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -37,13 +38,16 @@ import static org.springframework.cloud.appbroker.integration.CreateInstanceComp "spring.cloud.appbroker.services[0].apps[0].path=classpath:demo.jar", "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME_1, "spring.cloud.appbroker.services[0].apps[1].path=classpath:demo.jar", - "spring.cloud.appbroker.services[0].apps[1].name=" + APP_NAME_2 + "spring.cloud.appbroker.services[0].apps[1].name=" + APP_NAME_2, + "spring.cloud.appbroker.services[0].apps[1].properties.use-spring-application-json=false" }) class CreateInstanceComponentTest extends WiremockComponentTest { static final String APP_NAME_1 = "first-app"; static final String APP_NAME_2 = "second-app"; + private static final String SERVICE_INSTANCE_ID = "instance-id"; + @Autowired private OpenServiceBrokerApiFixture brokerFixture; @@ -53,26 +57,30 @@ class CreateInstanceComponentTest extends WiremockComponentTest { @Test void pushAppsWhenTheyDoNotExist() { cloudControllerFixture.stubAppDoesNotExist(APP_NAME_1); - cloudControllerFixture.stubPushApp(APP_NAME_1); + cloudControllerFixture.stubPushApp(APP_NAME_1, + matchingJsonPath("$.environment_json[?(@.SPRING_CLOUD_APPBROKER_SERVICE_INSTANCE_ID =~ " + + "/.*" + SERVICE_INSTANCE_ID + ".*/)]")); cloudControllerFixture.stubAppDoesNotExist(APP_NAME_2); - cloudControllerFixture.stubPushApp(APP_NAME_2); + cloudControllerFixture.stubPushApp(APP_NAME_2, + matchingJsonPath("$.environment_json[?(@.SPRING_CLOUD_APPBROKER_SERVICE_INSTANCE_ID =~ " + + "/.*" + SERVICE_INSTANCE_ID + ".*/)]")); // when a service instance is created given(brokerFixture.serviceInstanceRequest()) .when() - .put(brokerFixture.createServiceInstanceUrl(), "instance-id") + .put(brokerFixture.createServiceInstanceUrl(), SERVICE_INSTANCE_ID) .then() .statusCode(HttpStatus.ACCEPTED.value()); // when the "last_operation" API is polled given(brokerFixture.serviceInstanceRequest()) .when() - .get(brokerFixture.getLastInstanceOperationUrl(), "instance-id") + .get(brokerFixture.getLastInstanceOperationUrl(), SERVICE_INSTANCE_ID) .then() .statusCode(HttpStatus.OK.value()) .body("state", is(equalTo(OperationState.IN_PROGRESS.toString()))); - String state = brokerFixture.waitForAsyncOperationComplete("instance-id"); + String state = brokerFixture.waitForAsyncOperationComplete(SERVICE_INSTANCE_ID); assertThat(state).isEqualTo(OperationState.SUCCEEDED.toString()); } } \ No newline at end of file diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCredHubCredentialsComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCredHubCredentialsComponentTest.java index 5fe57ff..190a0cf 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCredHubCredentialsComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCredHubCredentialsComponentTest.java @@ -30,7 +30,7 @@ import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.springframework.cloud.appbroker.integration.CreateInstanceWithBasicAuthCredentialsComponentTest.APP_NAME; +import static org.springframework.cloud.appbroker.integration.CreateInstanceWithCredHubCredentialsComponentTest.APP_NAME; @TestPropertySource(properties = { "spring.cloud.appbroker.services[0].service-name=example", diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomCreationParametersComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomParametersMappingComponentTest.java similarity index 95% rename from spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomCreationParametersComponentTest.java rename to spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomParametersMappingComponentTest.java index ea4572a..ee554d5 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomCreationParametersComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCustomParametersMappingComponentTest.java @@ -44,7 +44,7 @@ import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.springframework.cloud.appbroker.integration.CreateInstanceWithCustomCreationParametersComponentTest.APP_NAME; +import static org.springframework.cloud.appbroker.integration.CreateInstanceWithCustomParametersMappingComponentTest.APP_NAME; @TestPropertySource(properties = { "spring.cloud.appbroker.services[0].service-name=example", @@ -53,8 +53,8 @@ import static org.springframework.cloud.appbroker.integration.CreateInstanceWith "spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME, "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].name=CustomMapping" }) -@ContextConfiguration(classes = CreateInstanceWithCustomCreationParametersComponentTest.CustomConfig.class) -class CreateInstanceWithCustomCreationParametersComponentTest extends WiremockComponentTest { +@ContextConfiguration(classes = CreateInstanceWithCustomParametersMappingComponentTest.CustomConfig.class) +class CreateInstanceWithCustomParametersMappingComponentTest extends WiremockComponentTest { static final String APP_NAME = "app-with-request-create-params"; diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCreationParametersComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithParametersMappingComponentTest.java similarity index 96% rename from spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCreationParametersComponentTest.java rename to spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithParametersMappingComponentTest.java index 9396802..6490dc9 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithCreationParametersComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/CreateInstanceWithParametersMappingComponentTest.java @@ -32,7 +32,7 @@ import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.springframework.cloud.appbroker.integration.CreateInstanceWithCreationParametersComponentTest.APP_NAME; +import static org.springframework.cloud.appbroker.integration.CreateInstanceWithParametersMappingComponentTest.APP_NAME; @TestPropertySource(properties = { "spring.cloud.appbroker.services[0].service-name=example", @@ -47,7 +47,7 @@ import static org.springframework.cloud.appbroker.integration.CreateInstanceWith "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].name=PropertyMapping", "spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].args.include=count,memory" }) -class CreateInstanceWithCreationParametersComponentTest extends WiremockComponentTest { +class CreateInstanceWithParametersMappingComponentTest extends WiremockComponentTest { static final String APP_NAME = "app-with-env-create-params"; diff --git a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/DeleteBindingWithCredHubComponentTest.java b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/DeleteBindingWithCredHubComponentTest.java index b1c7a31..4262acb 100644 --- a/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/DeleteBindingWithCredHubComponentTest.java +++ b/spring-cloud-app-broker-integration-tests/src/test/java/org.springframework.cloud.appbroker/integration/DeleteBindingWithCredHubComponentTest.java @@ -25,7 +25,7 @@ import org.springframework.http.HttpStatus; import org.springframework.test.context.TestPropertySource; import static io.restassured.RestAssured.given; -import static org.springframework.cloud.appbroker.integration.CreateInstanceWithBasicAuthCredentialsComponentTest.APP_NAME; +import static org.springframework.cloud.appbroker.integration.DeleteBindingWithCredHubComponentTest.APP_NAME; @TestPropertySource(properties = { "spring.cloud.appbroker.services[0].service-name=example", @@ -37,6 +37,8 @@ import static org.springframework.cloud.appbroker.integration.CreateInstanceWith }) class DeleteBindingWithCredHubComponentTest extends WiremockComponentTest { + static final String APP_NAME = "delete-binding-credhub"; + private static final String SERVICE_INSTANCE_ID = "instance-id"; private static final String BINDING_ID = "binding-id"; private static final String CREDENTIAL_NAME = "credentials-json";