Java源码示例:org.cloudfoundry.operations.applications.ApplicationSummary
示例1
private Mono<AbstractApplicationSummary> getOptionalApplication(AppDeploymentRequest request) {
String name = request.getDefinition().getName();
Flux<ApplicationSummary> applications = requestListApplications()
.filter(application -> name.equals(application.getName()));
if (!pushTaskAppsEnabled()) {
return applications
.single()
.onErrorMap(t->
t instanceof NoSuchElementException ?
new IllegalStateException(String.format("Application %s does not exist", name)) : t)
.cast(AbstractApplicationSummary.class);
}
return applications
.singleOrEmpty()
.cast(AbstractApplicationSummary.class);
}
示例2
private void mockAppResultsInAppList() {
givenRequestListApplications(Flux.just(ApplicationSummary.builder()
.diskQuota(0)
.id("test-application-id-1")
.instances(1)
.memoryLimit(0)
.name("test-application-1")
.requestedState("RUNNING")
.runningInstances(1)
.build(),
ApplicationSummary.builder()
.diskQuota(0)
.id("test-application-id-2")
.instances(1)
.memoryLimit(0)
.name("test-application-2")
.requestedState("RUNNING")
.runningInstances(1)
.build()));
}
示例3
@Test
@Tag("first")
@Order(FIRST_TEST)
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.parameter1=old-config1",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter2=old-config2"
})
void createsServiceInstance() {
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the environment variables are applied correctly
DocumentContext json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.parameter1").toString()).isEqualTo("old-config1");
assertThat(json.read("$.parameter2").toString()).isEqualTo("old-config2");
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
}
示例4
@Test
@Order(SECOND_TEST)
@Tag("last")
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.parameter1=new-config1",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter3=new-config3"
})
void upgradesTheServiceInstanceWithNewBackingServiceAndEnvironmentVariables() {
// when the service instance is updated with a new service
updateServiceInstance(SI_NAME, Collections.singletonMap("upgrade", true));
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
// then a backing application is re-deployed
Optional<ApplicationSummary> updatedBackingApplication = getApplicationSummary(APP_NAME);
assertThat(updatedBackingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// the backing application is updated with the new parameters
DocumentContext json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.parameter1").toString()).isEqualTo("new-config1");
assertThat(json.read("$.parameter3").toString()).isEqualTo("new-config3");
assertThat(json.jsonString()).doesNotContain("parameter2");
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the backing application is deleted
Optional<ApplicationSummary> backingApplicationAfterDeletion = getApplicationSummary(APP_NAME);
assertThat(backingApplicationAfterDeletion).isEmpty();
}
示例5
protected Optional<ApplicationSummary> getApplicationSummary(String appName) {
return cloudFoundryService
.getApplications()
.flatMapMany(Flux::fromIterable)
.filter(applicationSummary -> appName.equals(applicationSummary.getName()))
.next()
.blockOptional();
}
示例6
@Test
@Tag("first")
@Order(FIRST_TEST)
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + OLD_BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + OLD_BACKING_SI_NAME
})
void weCreateAService() {
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the services are bound to it
ServiceInstance backingServiceInstance = getBackingServiceInstance(OLD_BACKING_SI_NAME);
assertThat(backingServiceInstance.getApplications()).contains(APP_NAME);
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
}
示例7
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME_1,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].target.name=ServiceInstanceGuidSuffix"
})
void deployAppsWithServiceInstanceGuidSuffixOnCreateService() {
// when a service instance is created with target
createServiceInstance(SI_NAME);
// then backing application is created
final String serviceInstanceGuid = getServiceInstanceGuid(SI_NAME);
// then backing application is named as the concatenation of the name and it's service instance id
final String truncatedAppName = APP_NAME_1.substring(0, 13);
final String expectedApplicationName = truncatedAppName + "-" + serviceInstanceGuid;
Optional<ApplicationSummary> backingApplication = getApplicationSummary(expectedApplicationName);
assertThat(backingApplication).hasValueSatisfying(app -> {
assertThat(app.getName()).isEqualTo(expectedApplicationName);
assertThat(app.getRunningInstances()).isEqualTo(1);
});
// and the services are bound to it
final String expectedServiceInstanceName = BACKING_SI_NAME + "-" + serviceInstanceGuid;
ServiceInstance serviceInstance1 = getBackingServiceInstance(expectedServiceInstanceName);
assertThat(serviceInstance1.getApplications()).contains(expectedApplicationName);
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// and the backing service is deleted
assertThat(listServiceInstances()).doesNotContain(expectedServiceInstanceName);
}
示例8
private DeploymentState mapShallowAppState(ApplicationSummary applicationSummary) {
if (applicationSummary.getRunningInstances().equals(applicationSummary.getInstances())) {
return DeploymentState.deployed;
}
else if (applicationSummary.getInstances() > 0) {
return DeploymentState.partial;
} else {
return DeploymentState.undeployed;
}
}
示例9
/**
* Retrieve a {@link Mono} containing the {@link ApplicationSummary} associated with the appId.
* @param applicationSummaries {@link Flux} of {@link ApplicationSummary}s to filter.
* @param appId the id of the {@link ApplicationSummary} to search.
*/
private Mono<ApplicationSummary> getApplication(Flux<ApplicationSummary> applicationSummaries,
String appId) {
return applicationSummaries
.filter(application -> appId.equals(application.getId()))
.singleOrEmpty();
}
示例10
/**
* Retrieve a Flux of {@link ScheduleInfo}s for the pageNumber specified.
* The PCF-Scheduler returns all data in pages of 50 entries. This method
* retrieves the specified page and transforms the {@link Flux} of {@link Job}s to
* a {@link Flux} of {@link ScheduleInfo}s
*
* @param pageNumber integer containing the page offset for the {@link ScheduleInfo}s to retrieve.
* @return {@link Flux} containing the {@link ScheduleInfo}s for the specified page number.
*/
private Flux<ScheduleInfo> getSchedules(int pageNumber) {
Flux<ApplicationSummary> applicationSummaries = cacheAppSummaries();
return this.getSpace(this.properties.getSpace()).flatMap(requestSummary -> {
return this.client.jobs().list(ListJobsRequest.builder()
.spaceId(requestSummary.getId())
.page(pageNumber)
.detailed(true).build());})
.flatMapIterable(jobs -> jobs.getResources())// iterate over the resources returned.
.flatMap(job -> {
return getApplication(applicationSummaries,
job.getApplicationId()) // get the application name for each job.
.map(optionalApp -> {
ScheduleInfo scheduleInfo = new ScheduleInfo();
scheduleInfo.setScheduleProperties(new HashMap<>());
scheduleInfo.setScheduleName(job.getName());
scheduleInfo.setTaskDefinitionName(optionalApp.getName());
if (job.getJobSchedules() != null) {
scheduleInfo.getScheduleProperties().put(SchedulerPropertyKeys.CRON_EXPRESSION,
job.getJobSchedules().get(0).getExpression());
}
else {
logger.warn(String.format("Job %s does not have an associated schedule", job.getName()));
}
return scheduleInfo;
});
});
}
示例11
private void setupExistingAppSuccessful() {
givenRequestListApplications(Flux.just(ApplicationSummary.builder()
.diskQuota(0)
.id("test-application-id")
.instances(1)
.memoryLimit(0)
.name("test-application")
.requestedState("RUNNING")
.runningInstances(1)
.build()));
givenRequestGetApplicationSummary("test-application-id", Mono.just(SummaryApplicationResponse.builder()
.id("test-application-id")
.detectedStartCommand("test-command")
.build()));
givenRequestCreateTask("test-application-id",
"test-command",
this.deploymentProperties.getMemory(),
"test-application",
Mono.just(CreateTaskResponse.builder()
.id("test-task-id")
.memoryInMb(1024)
.diskInMb(1024)
.dropletId("1")
.createdAt(new Date().toString())
.updatedAt(new Date().toString())
.sequenceId(1)
.name("test-task-id")
.state(TaskState.FAILED)
.build()));
}
示例12
@Test
public void shouldReturnFluxOfServices() {
Applications apps = mock(Applications.class);
when(operations.applications()).thenReturn(apps);
ApplicationSummary summary = ApplicationSummary.builder()
.id(UUID.randomUUID().toString()).instances(1).memoryLimit(1024)
.requestedState("requestedState").diskQuota(1024).name("service")
.runningInstances(1).build();
when(apps.list()).thenReturn(Flux.just(summary));
Flux<String> services = this.client.getServices();
StepVerifier.create(services).expectNext("service").expectComplete().verify();
}
示例13
@Test
public void testServiceResolution() {
Applications apps = mock(Applications.class);
ApplicationSummary s = ApplicationSummary.builder()
.id(UUID.randomUUID().toString()).instances(2).memoryLimit(1024)
.requestedState("requestedState").diskQuota(1024)
.name(this.hiServiceServiceId).runningInstances(2).build();
Mockito.when(apps.list()).thenReturn(Flux.just(s));
Mockito.when(this.ops.applications()).thenReturn(apps);
List<String> serviceNames = this.cloudFoundryDiscoveryClient.getServices();
assertThat(serviceNames.contains(this.hiServiceServiceId))
.as("there should be one registered service.").isTrue();
serviceNames.forEach(serviceName -> this.log
.debug("\t discovered serviceName: " + serviceName));
}
示例14
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].name=PropertyMapping",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].args.include=host,domain"
})
void deployAppsOnUpdateService() {
// given a service instance is created
createServiceInstance(SI_NAME);
// and a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
// and the domain exists
createDomain("mydomain.com");
// when the service instance is updated
Map<String, Object> parameters = new HashMap<>();
parameters.put("host", "myhost");
parameters.put("domain", "mydomain.com");
updateServiceInstance(SI_NAME, parameters);
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getUrls()).contains("myhost.mydomain.com"));
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the backing application is deleted
Optional<ApplicationSummary> backingApplicationAfterDeletion = getApplicationSummary(APP_NAME);
assertThat(backingApplicationAfterDeletion).isEmpty();
deleteDomain("mydomain.com");
}
示例15
protected Optional<ApplicationSummary> getApplicationSummary(String appName, String space) {
return cloudFoundryService.getApplication(appName, space).blockOptional();
}
示例16
@Test
@Order(SECOND_TEST)
@Tag("last")
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + NEW_BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + NEW_BACKING_SI_NAME
})
void weUpdateTheServiceInstanceWithANewBackingService() {
// when the service instance is updated with a new service
updateServiceInstance(SI_NAME, Collections.emptyMap());
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
// then a backing application is re-deployed
Optional<ApplicationSummary> updatedBackingApplication = getApplicationSummary(APP_NAME);
assertThat(updatedBackingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the new backing service is bound to it
ServiceInstance newBackingServiceInstance = getBackingServiceInstance(NEW_BACKING_SI_NAME);
assertThat(newBackingServiceInstance.getApplications()).contains(APP_NAME);
// and the old backing service is deleted
assertThat(listServiceInstances()).doesNotContain(OLD_BACKING_SI_NAME);
// then the service instance is deleted
deleteServiceInstance(SI_NAME);
// and the backing service is deleted
assertThat(listServiceInstances()).doesNotContain(NEW_BACKING_SI_NAME);
}
示例17
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.parameter1=config1",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter2=config2",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter3=config3",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter4=config4",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].name=EnvironmentMapping",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].args.include=parameter1,parameter3",
"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"
})
public void deployAppsOnUpdateService() {
// given a service instance is created
createServiceInstance(SI_NAME);
// and a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
DocumentContext json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.parameter1").toString()).isEqualTo("config1");
assertThat(json.read("$.parameter2").toString()).isEqualTo("config2");
assertThat(json.read("$.parameter3").toString()).isEqualTo("config3");
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
// when the service instance is updated
Map<String, Object> parameters = new HashMap<>();
parameters.put("parameter1", "value1");
parameters.put("parameter2", "value2");
parameters.put("parameter3", "value3");
parameters.put("count", 2);
updateServiceInstance(SI_NAME, parameters);
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
// the backing application is updated with the new parameters
json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.parameter1").toString()).isEqualTo("value1");
assertThat(json.read("$.parameter2").toString()).isEqualTo("config2");
assertThat(json.read("$.parameter3").toString()).isEqualTo("value3");
assertThat(json.read("$.parameter4").toString()).isEqualTo("config4");
backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(2));
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the backing application is deleted
Optional<ApplicationSummary> backingApplicationAfterDeletion = getApplicationSummary(APP_NAME);
assertThat(backingApplicationAfterDeletion).isEmpty();
}
示例18
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].services[0].rebind-on-update=true"
})
void shouldPushAppWithServicesBind() {
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the services are bound to it
ServiceInstance backingServiceInstance = getBackingServiceInstance(BACKING_SI_NAME);
assertThat(backingServiceInstance.getApplications()).contains(APP_NAME);
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
// when the service instance is updated
Map<String, Object> parameters = new HashMap<>();
parameters.put("parameter1", "value1");
parameters.put("parameter2", "value2");
parameters.put("parameter3", "value3");
updateServiceInstance(SI_NAME, parameters);
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
// then a backing application is re-deployed
Optional<ApplicationSummary> updatedBackingApplication = getApplicationSummary(APP_NAME);
assertThat(updatedBackingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the services are still bound to it
ServiceInstance backingServiceInstanceUpdated = getBackingServiceInstance(BACKING_SI_NAME);
assertThat(backingServiceInstanceUpdated.getApplications()).contains(APP_NAME);
// then the service instance is deleted
deleteServiceInstance(SI_NAME);
// and the backing service is deleted
assertThat(listServiceInstances()).doesNotContain(BACKING_SI_NAME);
}
示例19
public Mono<List<ApplicationSummary>> getApplications() {
return listApplications(cloudFoundryOperations)
.collectList();
}
示例20
public Mono<ApplicationSummary> getApplication(String appName, String space) {
return listApplications(createOperationsForSpace(space))
.filter(applicationSummary -> applicationSummary.getName().equals(appName))
.single();
}
示例21
private Flux<ApplicationSummary> listApplications(CloudFoundryOperations operations) {
return operations.applications()
.list()
.doOnComplete(() -> LOG.info("Listed applications"))
.doOnError(e -> LOG.error(String.format("Error listing applications. error=%s", e.getMessage()), e));
}
示例22
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].name=SpringSecurityOAuth2",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.registration=sample-app-client",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.grant-types=[\"client_credentials\"]",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.authorities=[\"uaa.resource\"]",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.length=12",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-uppercase-alpha=false",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-lowercase-alpha=true",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-numeric=false",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-special=false"
})
void deployAppsWithOAuth2OnCreateService() {
// when a service instance is created
createServiceInstance(SI_NAME);
String serviceInstanceGuid = getServiceInstanceGuid(SI_NAME);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and has the environment variables
DocumentContext json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.['spring.security.oauth2.client.registration.sample-app-client.client-id']").toString())
.isEqualTo(uaaClientId(serviceInstanceGuid));
assertThat(
json.read("$.['spring.security.oauth2.client.registration.sample-app-client.client-secret']").toString())
.matches("[a-zA-Z]{12}");
// and a UAA client is created
Optional<GetClientResponse> uaaClient = getUaaClient(uaaClientId(serviceInstanceGuid));
assertThat(uaaClient).hasValueSatisfying(client -> {
assertThat(client.getAuthorities()).contains("uaa.resource");
assertThat(client.getAuthorizedGrantTypes()).contains(GrantType.CLIENT_CREDENTIALS);
});
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the backing application is deleted
Optional<ApplicationSummary> backingApplicationAfterDeletion = getApplicationSummary(APP_NAME);
assertThat(backingApplicationAfterDeletion).isEmpty();
// and the UAA client is deleted
Optional<GetClientResponse> uaaClientAfterDeletion = getUaaClient(uaaClientId(serviceInstanceGuid));
assertThat(uaaClientAfterDeletion).isEmpty();
}
示例23
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_CREATE_1,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.ENV_VAR_1=value1",
"spring.cloud.appbroker.services[0].apps[0].environment.ENV_VAR_2=value2",
"spring.cloud.appbroker.services[0].apps[0].properties.memory=2G",
"spring.cloud.appbroker.services[0].apps[0].properties.count=2",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].name=SpringSecurityBasicAuth",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.length=14",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-uppercase-alpha=true",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-lowercase-alpha=true",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-numeric=false",
"spring.cloud.appbroker.services[0].apps[0].credential-providers[0].args.include-special=false",
"spring.cloud.appbroker.services[0].apps[1].name=" + APP_CREATE_2,
"spring.cloud.appbroker.services[0].apps[1].path=" + BACKING_APP_PATH
})
void deployAppsOnCreateService() {
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing applications are deployed
Optional<ApplicationSummary> backingApplication1 = getApplicationSummary(APP_CREATE_1);
assertThat(backingApplication1).hasValueSatisfying(app -> {
assertThat(app.getInstances()).isEqualTo(2);
assertThat(app.getRunningInstances()).isGreaterThanOrEqualTo(1);
assertThat(app.getMemoryLimit()).isEqualTo(2048);
});
Optional<ApplicationSummary> backingApplication2 = getApplicationSummary(APP_CREATE_2);
assertThat(backingApplication2).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and has the environment variables
DocumentContext json = getSpringAppJson(APP_CREATE_1);
assertEnvironmentVariablesSet(json);
assertBasicAuthCredentialsProvided(json);
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the backing applications are deleted
Optional<ApplicationSummary> backingApplication1AfterDeletion = getApplicationSummary(APP_CREATE_1);
assertThat(backingApplication1AfterDeletion).isEmpty();
Optional<ApplicationSummary> backingApplication2AfterDeletion = getApplicationSummary(APP_CREATE_2);
assertThat(backingApplication2AfterDeletion).isEmpty();
}
示例24
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.parameter1=config1",
"spring.cloud.appbroker.services[0].target.name=SpacePerServiceInstance"
})
void deployAppsInTargetSpaceOnUpdateService() {
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing application is deployed in a space named as the service instance id
String spaceName = getServiceInstanceGuid(SI_NAME);
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME, spaceName);
assertThat(backingApplication).hasValueSatisfying(app -> {
assertThat(app.getRunningInstances()).isEqualTo(1);
// and has its route with the service instance id appended to it
assertThat(app.getUrls()).isNotEmpty();
assertThat(app.getUrls().get(0)).startsWith(APP_NAME + "-" + spaceName);
});
String path = backingApplication.get().getUrls().get(0);
healthListener.start(path);
// when the service instance is updated
updateServiceInstance(SI_NAME, Collections.singletonMap("parameter2", "config2"));
// then the backing application was updated with zero downtime
healthListener.stop();
assertThat(healthListener.getFailures()).isEqualTo(0);
assertThat(healthListener.getSuccesses()).isGreaterThan(0);
// then the service instance has the initial parameters
DocumentContext json = getSpringAppJson(APP_NAME, spaceName);
assertThat(json.read("$.parameter1").toString()).isEqualTo("config1");
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the space is deleted
List<String> spaces = getSpaces();
assertThat(spaces).doesNotContain(spaceName);
}
示例25
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_1_NAME,
"spring.cloud.appbroker.services[0].apps[0].services[1].service-instance-name=" + BACKING_SI_2_NAME,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_1_NAME
})
void deployAppsAndCreateServicesOnCreateService() {
// given that a service is available in the marketplace
createBackingServiceInstance(BACKING_SERVICE_NAME, PLAN_NAME, BACKING_SI_2_NAME, emptyMap());
// when a service instance is created
createServiceInstance(SI_NAME);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the services are bound to it
ServiceInstance serviceInstance1 = getBackingServiceInstance(BACKING_SI_1_NAME);
assertThat(serviceInstance1.getApplications()).contains(APP_NAME);
ServiceInstance serviceInstance2 = getBackingServiceInstance(BACKING_SI_2_NAME);
assertThat(serviceInstance2.getApplications()).contains(APP_NAME);
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// and the backing services are deleted
assertThat(listServiceInstances()).doesNotContain(BACKING_SI_1_NAME);
assertThat(listServiceInstances()).doesNotContain(BACKING_SI_2_NAME);
// TODO: another story to only remove the instances with service definition specified (https://github.com/spring-cloud/spring-cloud-app-broker/issues/316)
// // service without specification has no applications bound to it
// ServiceInstance serviceInstance2AfterDeletion = getServiceInstance(BACKING_SI_2_NAME);
// assertThat(serviceInstance2AfterDeletion.getApplications()).isEmpty();
//
// deleteServiceInstance(BACKING_SI_2_NAME);
}
示例26
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME_1,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].apps[1].name=" + APP_NAME_2,
"spring.cloud.appbroker.services[0].apps[1].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].services[0].name=" + BACKING_SERVICE_NAME,
"spring.cloud.appbroker.services[0].services[0].plan=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].services[0].service-instance-name=" + BACKING_SI_NAME,
"spring.cloud.appbroker.services[0].target.name=SpacePerServiceInstance"
})
void deployAppsInTargetSpaceOnCreateService() {
// when a service instance is created with targets
createServiceInstance(SI_NAME);
// then backing applications are deployed in a space named as the service instance id
String spaceName = getServiceInstanceGuid(SI_NAME);
Optional<ApplicationSummary> backingApplication1 = getApplicationSummary(APP_NAME_1, spaceName);
assertThat(backingApplication1).hasValueSatisfying(app -> {
assertThat(app.getRunningInstances()).isEqualTo(1);
// and has its route with the service instance id appended to it
assertThat(app.getUrls()).isNotEmpty();
assertThat(app.getUrls().get(0)).startsWith(APP_NAME_1 + "-" + spaceName);
});
Optional<ApplicationSummary> backingApplication2 = getApplicationSummary(APP_NAME_2, spaceName);
assertThat(backingApplication2).hasValueSatisfying(app ->
assertThat(app.getRunningInstances()).isEqualTo(1));
// and the services are bound to it
ServiceInstance serviceInstance1 = getBackingServiceInstance(BACKING_SI_NAME, spaceName);
assertThat(serviceInstance1.getApplications()).contains(APP_NAME_1);
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
// then the space is deleted
List<String> spaces = getSpaces();
assertThat(spaces).doesNotContain(spaceName);
}
示例27
@Test
@AppBrokerTestProperties({
"spring.cloud.appbroker.services[0].service-name=" + APP_SERVICE_NAME,
"spring.cloud.appbroker.services[0].plan-name=" + PLAN_NAME,
"spring.cloud.appbroker.services[0].apps[0].name=" + APP_NAME,
"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
"spring.cloud.appbroker.services[0].apps[0].environment.parameter1=config1",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter2=config2",
"spring.cloud.appbroker.services[0].apps[0].environment.parameter3=config3",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].name=EnvironmentMapping",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[0].args.include=parameter1,parameter3",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].name=PropertyMapping",
"spring.cloud.appbroker.services[0].apps[0].parameters-transformers[1].args.include=memory"
})
void deployAppsWithParametersOnCreateService() {
// when a service instance is created
Map<String, Object> parameters = new HashMap<>();
parameters.put("parameter1", "value1");
parameters.put("parameter2", "value2");
parameters.put("parameter3", "value3");
parameters.put("count", 5);
parameters.put("memory", "2G");
createServiceInstance(SI_NAME, parameters);
// then a backing application is deployed
Optional<ApplicationSummary> backingApplication = getApplicationSummary(APP_NAME);
assertThat(backingApplication).hasValueSatisfying(app -> {
assertThat(app.getInstances()).isEqualTo(1);
assertThat(app.getRunningInstances()).isEqualTo(1);
assertThat(app.getMemoryLimit()).isEqualTo(2048);
});
// and has the environment variables
DocumentContext json = getSpringAppJson(APP_NAME);
assertThat(json.read("$.parameter1").toString()).isEqualTo("value1");
assertThat(json.read("$.parameter2").toString()).isEqualTo("config2");
assertThat(json.read("$.parameter3").toString()).isEqualTo("value3");
// when the service instance is deleted
deleteServiceInstance(SI_NAME);
}
示例28
private Flux<ApplicationSummary> requestListApplications() {
return this.operations.applications()
.list();
}
示例29
@Override
public Map<String, DeploymentState> states(String... ids) {
return requestSummary()
.collect(Collectors.toMap(ApplicationSummary::getName, this::mapShallowAppState))
.block();
}
示例30
@Override
public Mono<Map<String, DeploymentState>> statesReactive(String... ids) {
return requestSummary()
.collect(Collectors.toMap(ApplicationSummary::getName, this::mapShallowAppState));
}