Set an environment variable on backing apps with the value of the service instance GUID.
This commit is contained in:
committed by
Oliver Hughes
parent
6cd9c68058
commit
219aa16e1e
@@ -32,11 +32,11 @@ public class BackingAppDeploymentService {
|
||||
this.deployerClient = deployerClient;
|
||||
}
|
||||
|
||||
public Flux<String> deploy(List<BackingApplication> backingApps) {
|
||||
public Flux<String> deploy(List<BackingApplication> 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<String> update(List<BackingApplication> backingApps) {
|
||||
public Flux<String> update(List<BackingApplication> 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))
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DeployerClient {
|
||||
this.appDeployer = appDeployer;
|
||||
}
|
||||
|
||||
Mono<String> deploy(BackingApplication backingApplication) {
|
||||
Mono<String> 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<String> update(BackingApplication backingApplication) {
|
||||
Mono<String> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {}/{}",
|
||||
|
||||
@@ -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 {}/{}",
|
||||
|
||||
@@ -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<String> 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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String, Object> 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"));
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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<String, Object> getEnvironmentVariables(Map<String, String> properties,
|
||||
Map<String, Object> environment) {
|
||||
Map<String, Object> environment,
|
||||
String serviceInstanceId) {
|
||||
Map<String, Object> 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<String, Object> getApplicationEnvironment(Map<String, String> properties,
|
||||
Map<String, Object> environment) {
|
||||
Map<String, Object> applicationEnvironment = getSanitizedApplicationEnvironment(environment);
|
||||
Map<String, Object> applicationEnvironment = sanitizeApplicationEnvironment(environment);
|
||||
|
||||
if (!applicationEnvironment.isEmpty() && useSpringApplicationJson(properties)) {
|
||||
try {
|
||||
@@ -564,7 +567,7 @@ public class CloudFoundryAppDeployer implements AppDeployer, ResourceLoaderAware
|
||||
return applicationEnvironment;
|
||||
}
|
||||
|
||||
private Map<String, Object> getSanitizedApplicationEnvironment(Map<String, Object> environment) {
|
||||
private Map<String, Object> sanitizeApplicationEnvironment(Map<String, Object> environment) {
|
||||
Map<String, Object> applicationEnvironment = new HashMap<>(environment);
|
||||
|
||||
// Remove server.port as CF assigns a port for us, and we don't want to override that
|
||||
|
||||
@@ -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<>());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,17 +33,17 @@ public class DeployApplicationRequest {
|
||||
|
||||
private final List<String> services;
|
||||
|
||||
private final String serviceInstanceId;
|
||||
|
||||
DeployApplicationRequest(String name, String path, Map<String, String> properties,
|
||||
Map<String, Object> environment, List<String> services) {
|
||||
Map<String, Object> environment, List<String> 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<String, String> properties = new HashMap<>();
|
||||
|
||||
private final Map<String, Object> environment = new HashMap<>();
|
||||
|
||||
private final List<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,17 +33,17 @@ public class UpdateApplicationRequest {
|
||||
|
||||
private final List<String> services;
|
||||
|
||||
private final String serviceInstanceId;
|
||||
|
||||
UpdateApplicationRequest(String name, String path, Map<String, String> properties,
|
||||
Map<String, Object> environment, List<String> services) {
|
||||
Map<String, Object> environment, List<String> 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<String, String> properties = new HashMap<>();
|
||||
|
||||
private final Map<String, Object> environment = new HashMap<>();
|
||||
|
||||
private final List<String> 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<String, String> properties) {
|
||||
public UpdateApplicationRequestBuilder properties(Map<String, String> 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<String, Object> environment) {
|
||||
public UpdateApplicationRequestBuilder environment(Map<String, Object> 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<String> services) {
|
||||
public UpdateApplicationRequestBuilder services(List<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user