Adding service instance name to services

This commit is contained in:
Alberto Rios
2018-10-25 17:19:35 +02:00
committed by Alberto Ríos
parent a0e3032020
commit f6b68c800e
6 changed files with 79 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ class CreateInstanceWithExistingServicesAcceptanceTest extends CloudFoundryAccep
"spring.cloud.appbroker.services[0].plan-name=standard",
"spring.cloud.appbroker.services[0].apps[0].name=" + BROKER_APP_SERVICES,
"spring.cloud.appbroker.services[0].apps[0].path=classpath:demo.jar",
"spring.cloud.appbroker.services[0].apps[0].services[0]=" + SI_1_NAME
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + SI_1_NAME
})
void shouldPushAppWithServicesBind() {
// given that a service instance of the specified service exists

View File

@@ -31,7 +31,7 @@ public class BackingApplication {
private String path;
private Map<String, String> properties;
private Map<String, String> environment;
private List<String> services;
private List<ServicesSpec> services;
private List<ParametersTransformerSpec> parametersTransformers;
private List<CredentialProviderSpec> credentialProviders;
private TargetSpec target;
@@ -63,7 +63,7 @@ public class BackingApplication {
BackingApplication(String name, String path,
Map<String, String> properties,
Map<String, String> environment,
List<String> services,
List<ServicesSpec> services,
List<ParametersTransformerSpec> parametersTransformers,
List<CredentialProviderSpec> credentialProviders,
TargetSpec target) {
@@ -117,11 +117,11 @@ public class BackingApplication {
environment.put(key, value);
}
public List<String> getServices() {
public List<ServicesSpec> getServices() {
return services;
}
public void setServices(List<String> services) {
public void setServices(List<ServicesSpec> services) {
this.services = services;
}
@@ -209,7 +209,7 @@ public class BackingApplication {
private String path;
private final Map<String, String> properties = new HashMap<>();
private final Map<String, String> environment = new HashMap<>();
private final List<String> services = new ArrayList<>();
private final List<ServicesSpec> services = new ArrayList<>();
private final List<ParametersTransformerSpec> parameterTransformers = new ArrayList<>();
private final List<CredentialProviderSpec> credentialProviders = new ArrayList<>();
private TargetSpec target;
@@ -247,7 +247,7 @@ public class BackingApplication {
return this;
}
public BackingApplicationBuilder services(String... services) {
public BackingApplicationBuilder services(ServicesSpec... services) {
this.services.addAll(Arrays.asList(services));
return this;
}

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.appbroker.deployer;
import java.util.stream.Collectors;
import reactor.core.publisher.Mono;
import reactor.util.Logger;
import reactor.util.Loggers;
@@ -36,7 +38,7 @@ public class DeployerClient {
.path(backingApplication.getPath())
.properties(backingApplication.getProperties())
.environment(backingApplication.getEnvironment())
.services(backingApplication.getServices())
.services(backingApplication.getServices().stream().map(ServicesSpec::getServiceInstanceName).collect(Collectors.toList()))
.build())
.doOnRequest(l -> log.info("Deploying application {}", backingApplication.getName()))
.doOnSuccess(d -> log.info("Finished deploying application {}", backingApplication.getName()))

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.appbroker.deployer;
public class ServicesSpec {
private String serviceInstanceName;
private ServicesSpec() {
}
ServicesSpec(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
}
public String getServiceInstanceName() {
return serviceInstanceName;
}
public void setServiceInstanceName(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
}
public static ServicesSpecBuilder builder() {
return new ServicesSpecBuilder();
}
public static class ServicesSpecBuilder {
private String serviceInstanceName;
ServicesSpecBuilder() {
}
ServicesSpecBuilder serviceInstanceName(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
return this;
}
public ServicesSpec build() {
return new ServicesSpec(serviceInstanceName);
}
}
}

View File

@@ -105,11 +105,15 @@ class DeployerClientTest {
// given
setupAppDeployer();
BackingApplication application = BackingApplication.builder()
.name(APP_NAME)
.path(APP_PATH)
.services("my-db-service")
.build();
BackingApplication application =
BackingApplication
.builder()
.name(APP_NAME)
.path(APP_PATH)
.services(ServicesSpec.builder()
.serviceInstanceName("my-db-service")
.build())
.build();
// when
StepVerifier.create(deployerClient.deploy(application))

View File

@@ -38,8 +38,8 @@ import static org.springframework.cloud.appbroker.sample.CreateInstanceWithExist
"spring.cloud.appbroker.services[0].plan-name=standard",
"spring.cloud.appbroker.services[0].apps[0].path=classpath:demo.jar",
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].services[0]=" + SERVICE_INSTANCE_1_NAME,
"spring.cloud.appbroker.services[0].apps[0].services[1]=" + SERVICE_INSTANCE_2_NAME
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + SERVICE_INSTANCE_1_NAME,
"spring.cloud.appbroker.services[0].apps[0].services[1].service-instance-name=" + SERVICE_INSTANCE_2_NAME
})
class CreateInstanceWithExistingServicesComponentTest extends WiremockComponentTest {