org.cloudfoundry.operations.applications.ApplicationSummary Java Examples

The following examples show how to use org.cloudfoundry.operations.applications.ApplicationSummary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example #2
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: CreateInstanceWithServiceInstanceGuidSuffixTargetAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: CloudFoundryDiscoveryClientTest.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #5
Source File: CloudFoundryNativeReactiveDiscoveryClientTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #6
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example #7
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
						});
			});
}
 
Example #8
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #9
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example #10
Source File: UpgradeInstanceAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: UpgradeInstanceAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #12
Source File: CloudFoundryAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Optional<ApplicationSummary> getApplicationSummary(String appName) {
	return cloudFoundryService
		.getApplications()
		.flatMapMany(Flux::fromIterable)
		.filter(applicationSummary -> appName.equals(applicationSummary.getName()))
		.next()
		.blockOptional();
}
 
Example #13
Source File: UpdateInstanceWithNewServiceAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: UpdateInstanceAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #15
Source File: CloudFoundryDiscoveryClient.java    From spring-cloud-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
public List<String> getServices() {
	return this.cloudFoundryOperations.applications().list()
			.map(ApplicationSummary::getName).collectList().blockOptional()
			.orElse(new ArrayList<>());
}
 
Example #16
Source File: CloudFoundryNativeReactiveDiscoveryClient.java    From spring-cloud-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<String> getServices() {
	return this.cloudFoundryOperations.applications().list()
			.map(ApplicationSummary::getName);
}
 
Example #17
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void givenRequestListApplications(Flux<ApplicationSummary> response) {
	given(this.operations.applications()
			.list())
			.willReturn(response);
}
 
Example #18
Source File: CloudFoundryAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
protected Optional<ApplicationSummary> getApplicationSummary(String appName, String space) {
	return cloudFoundryService.getApplication(appName, space).blockOptional();
}
 
Example #19
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void givenRequestListApplications(Flux<ApplicationSummary> response) {
	given(this.operations.applications()
		.list())
		.willReturn(response);
}
 
Example #20
Source File: UpdateInstanceWithNewServiceAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #21
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve a cached {@link Flux} of {@link ApplicationSummary}s.
 */
private Flux<ApplicationSummary> cacheAppSummaries() {
	return requestListApplications()
			.cache(); //cache results from first call.  No need to re-retrieve each time.
}
 
Example #22
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve a  {@link Flux} of {@link ApplicationSummary}s.
 */
private Flux<ApplicationSummary> requestListApplications() {
	return this.operations.applications()
			.list();
}
 
Example #23
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private Flux<ApplicationSummary> requestSummary() {
	return this.operations.applications().list();
}
 
Example #24
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
public Mono<List<ApplicationSummary>> getApplications() {
	return listApplications(cloudFoundryOperations)
		.collectList();
}
 
Example #25
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Map<String, DeploymentState>> statesReactive(String... ids) {
	return requestSummary()
		.collect(Collectors.toMap(ApplicationSummary::getName, this::mapShallowAppState));
}
 
Example #26
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, DeploymentState> states(String... ids) {
	return requestSummary()
		.collect(Collectors.toMap(ApplicationSummary::getName, this::mapShallowAppState))
		.block();
}
 
Example #27
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private Flux<ApplicationSummary> requestListApplications() {
	return this.operations.applications()
		.list();
}
 
Example #28
Source File: UpdateInstanceWithServicesAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #29
Source File: UpdateInstanceWithHostAndDomainAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@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");
}
 
Example #30
Source File: CreateInstanceWithParametersAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@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);
}