org.cloudfoundry.client.v2.applications.SummaryApplicationResponse Java Examples

The following examples show how to use org.cloudfoundry.client.v2.applications.SummaryApplicationResponse. 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: RawCloudApplication.java    From cf-java-client-sap with Apache License 2.0 6 votes vote down vote up
@Override
public CloudApplication derive() {
    Resource<ApplicationEntity> resource = getResource();
    ApplicationEntity entity = resource.getEntity();
    SummaryApplicationResponse summary = getSummary();
    return ImmutableCloudApplication.builder()
                                    .metadata(parseResourceMetadata(resource))
                                    .name(summary.getName())
                                    .memory(summary.getMemory())
                                    .uris(toUrlStrings(summary.getRoutes()))
                                    .diskQuota(summary.getDiskQuota())
                                    .instances(summary.getInstances())
                                    .runningInstances(summary.getRunningInstances())
                                    .state(parseState(summary.getState()))
                                    .staging(parseStaging(summary, getStack()))
                                    .packageState(parsePackageState(summary.getPackageState()))
                                    .stagingError(summary.getStagingFailedDescription())
                                    .services(getNames(summary.getServices()))
                                    .env(parseEnv(entity.getEnvironmentJsons()))
                                    .space(getSpace().derive())
                                    .build();
}
 
Example #2
Source File: RawCloudApplicationTest.java    From cf-java-client-sap with Apache License 2.0 6 votes vote down vote up
private static SummaryApplicationResponse buildApplicationSummary() {
    return SummaryApplicationResponse.builder()
                                     .name(RawCloudEntityTest.NAME)
                                     .memory(MEMORY)
                                     .diskQuota(DISK_QUOTA)
                                     .routes(ROUTES)
                                     .instances(INSTANCES)
                                     .runningInstances(RUNNING_INSTANCES)
                                     .state(STATE)
                                     .packageState(PACKAGE_STATE)
                                     .stagingFailedDescription(STAGING_ERROR)
                                     .healthCheckHttpEndpoint(HEALTH_CHECK_HTTP_ENDPOINT)
                                     .healthCheckTimeout(HEALTH_CHECK_TIMEOUT)
                                     .healthCheckType(HEALTH_CHECK_TYPE)
                                     .enableSsh(SSH_ENABLED)
                                     .dockerImage(DOCKER_IMAGE)
                                     .dockerCredentials(DOCKER_CREDENTIALS)
                                     .command(COMMAND)
                                     .buildpack(BUILDPACK)
                                     .detectedBuildpack(DETECTED_BUILDPACK)
                                     .services(SERVICE_INSTANCES)
                                     .build();
}
 
Example #3
Source File: RawCloudApplicationTest.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static RawCloudApplication buildRawApplicationWithoutDockerCredentials() {
    SummaryApplicationResponse summary = buildApplicationSummary();
    SummaryApplicationResponse summaryWithoutDockerCredentials = SummaryApplicationResponse.builder()
                                                                                           .from(summary)
                                                                                           .dockerCredentials(null)
                                                                                           .build();
    return buildRawApplication(buildApplicationResource(), summaryWithoutDockerCredentials);
}
 
Example #4
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void stageTaskWithNonExistentApplicationBindingOneService() throws IOException {
	setupTaskWithNonExistentApplicationBindingOneService(this.resource);
	AppDeploymentRequest request = deploymentRequest(this.resource,
			Collections.singletonMap(CloudFoundryDeploymentProperties.SERVICES_PROPERTY_KEY, "test-service-instance-2"));

	SummaryApplicationResponse response = this.launcher.stage(request);
	assertThat(response.getId(), equalTo("test-application-id"));
	assertThat(response.getDetectedStartCommand(), equalTo("test-command"));
}
 
Example #5
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void stageTaskWithNonExistentApplication() throws IOException {
	setupTaskWithNonExistentApplication(this.resource);

	SummaryApplicationResponse response = this.launcher.stage(defaultRequest());
	assertThat(response.getId(), equalTo("test-application-id"));
	assertThat(response.getDetectedStartCommand(), equalTo("test-command"));
}
 
Example #6
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void stageTaskApplicationExists() {
	setupExistingAppSuccessful();
	SummaryApplicationResponse response = this.launcher.stage(defaultRequest());

	assertThat(response.getId(), equalTo("test-application-id"));
	assertThat(response.getDetectedStartCommand(), equalTo("test-command"));
}
 
Example #7
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Stages the application specified in the {@link ScheduleRequest} on the CF server.
 * @param scheduleRequest {@link ScheduleRequest} containing the information required to schedule a task.
 * @return the command string for the scheduled task.
 */
private String stageTask(ScheduleRequest scheduleRequest) {
	logger.debug(String.format("Staging Task: ",
			scheduleRequest.getDefinition().getName()));
	AppDeploymentRequest request = new AppDeploymentRequest(
			scheduleRequest.getDefinition(),
			scheduleRequest.getResource(),
			scheduleRequest.getDeploymentProperties(),
			scheduleRequest.getCommandlineArguments());
	SummaryApplicationResponse response = taskLauncher.stage(request);
	return taskLauncher.getCommand(response, request);
}
 
Example #8
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void stageTaskWithNonExistentApplicationBindingThreeServices() throws IOException {
	setupTaskWithNonExistentApplicationBindingThreeServices(this.resource);
	AppDeploymentRequest request = deploymentRequest(this.resource,
			Collections.singletonMap(CloudFoundryDeploymentProperties.SERVICES_PROPERTY_KEY,
					"test-service-instance-1,test-service-instance-2,test-service-instance-3"));

	SummaryApplicationResponse response = this.launcher.stage(request);
	assertThat(response.getId(), equalTo("test-application-id"));
	assertThat(response.getDetectedStartCommand(), equalTo("test-command"));
}
 
Example #9
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<String> launchTask(SummaryApplicationResponse application, AppDeploymentRequest request) {
	return requestCreateTask(application.getId(),
			getCommand(application, request),
			memory(request),
			request.getDefinition().getName())
		.map(CreateTaskResponse::getId);
}
 
Example #10
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommand() {
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition(
			"test-app-1", null),
			this.resource,
			Collections.singletonMap("test-key-1", "test-val-1"),
			Collections.singletonList("test-command-arg-1"));
	String command = this.launcher.getCommand(SummaryApplicationResponse
			.builder()
			.detectedStartCommand("command-val")
			.build(),
			request);
	assertThat(command, equalTo("command-val test-command-arg-1"));
}
 
Example #11
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the command string required to launch a task by a service on Cloud Foundry.
 * @param application the {@link SummaryApplicationResponse} containing the result of the requested staging.
 * @param request The {@link AppDeploymentRequest} associated with the task staging.
 * @return the command string
 */
public String getCommand(SummaryApplicationResponse application, AppDeploymentRequest request) {
	final boolean appHasCfEnv = hasCfEnv(request.getResource());
	return Stream.concat(Stream.of(application.getDetectedStartCommand()), request.getCommandlineArguments().stream())
			.map( arg-> appHasCfEnv ? CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg(arg) : arg)
			.collect(Collectors.joining(" "));
}
 
Example #12
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void givenRequestGetApplicationSummary(String applicationId, Mono<SummaryApplicationResponse> response) {
	given(this.client.applicationsV2()
		.summary(org.cloudfoundry.client.v2.applications.SummaryApplicationRequest.builder()
			.applicationId(applicationId)
			.build()))
		.willReturn(response);
}
 
Example #13
Source File: RawCloudApplicationTest.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static RawCloudApplication buildRawApplication(Resource<ApplicationEntity> applicationResource,
                                                       SummaryApplicationResponse summary) {
    return ImmutableRawCloudApplication.builder()
                                       .resource(applicationResource)
                                       .summary(summary)
                                       .stack(STACK)
                                       .space(SPACE)
                                       .build();
}
 
Example #14
Source File: RawCloudApplicationTest.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static RawCloudApplication buildRawApplicationWithoutDockerInfo() {
    SummaryApplicationResponse summary = buildApplicationSummary();
    SummaryApplicationResponse summaryWithoutDockerInfo = SummaryApplicationResponse.builder()
                                                                                    .from(summary)
                                                                                    .dockerImage(null)
                                                                                    .dockerCredentials(null)
                                                                                    .build();
    return buildRawApplication(buildApplicationResource(), summaryWithoutDockerInfo);
}
 
Example #15
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 #16
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private Mono<SummaryApplicationResponse> getApplicationSummary(UUID guid) {
    SummaryApplicationRequest request = SummaryApplicationRequest.builder()
                                                                 .applicationId(guid.toString())
                                                                 .build();
    return delegate.applicationsV2()
                   .summary(request);
}
 
Example #17
Source File: RawCloudApplication.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static DockerCredentials parseDockerCredentials(SummaryApplicationResponse summary) {
    org.cloudfoundry.client.v2.applications.DockerCredentials credentials = summary.getDockerCredentials();
    if (credentials == null) {
        return null;
    }
    return ImmutableDockerCredentials.builder()
                                     .username(credentials.getUsername())
                                     .password(credentials.getPassword())
                                     .build();
}
 
Example #18
Source File: RawCloudApplication.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static DockerInfo parseDockerInfo(SummaryApplicationResponse summary) {
    String image = summary.getDockerImage();
    if (image == null) {
        return null;
    }
    return ImmutableDockerInfo.builder()
                              .image(image)
                              .credentials(parseDockerCredentials(summary))
                              .build();
}
 
Example #19
Source File: RawCloudApplication.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private static Staging parseStaging(SummaryApplicationResponse summary, Derivable<CloudStack> stack) {
    return ImmutableStaging.builder()
                           .addBuildpack(summary.getBuildpack())
                           .command(summary.getCommand())
                           .detectedBuildpack(summary.getDetectedBuildpack())
                           .healthCheckHttpEndpoint(summary.getHealthCheckHttpEndpoint())
                           .healthCheckTimeout(summary.getHealthCheckTimeout())
                           .healthCheckType(summary.getHealthCheckType())
                           .isSshEnabled(summary.getEnableSsh())
                           .dockerInfo(parseDockerInfo(summary))
                           .stack(parseStackName(stack))
                           .build();
}
 
Example #20
Source File: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void updateAppWithNoNewServices() {
	given(applicationsV2.summary(any(SummaryApplicationRequest.class)))
		.willReturn(Mono.just(SummaryApplicationResponse.builder()
			.id(APP_ID)
			.name(APP_NAME)
			.service(ServiceInstance.builder()
				.name("service-1")
				.build())
			.service(ServiceInstance.builder()
				.name("service-2")
				.build())
			.build()));
	given(applicationsV2.update(any()))
		.willReturn(Mono.just(UpdateApplicationResponse.builder()
			.build()));

	UpdateApplicationRequest request = UpdateApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.service("service-1")
		.service("service-2")
		.build();

	StepVerifier.create(appDeployer.update(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();

	then(applicationsV2).should().summary(SummaryApplicationRequest.builder().applicationId(APP_ID).build());
	then(applicationsV2).should().update(argThat(arg -> arg.getApplicationId().equals(APP_ID)));
	then(operationsServices).shouldHaveNoMoreInteractions();
	then(applicationsV2).shouldHaveNoMoreInteractions();
}
 
Example #21
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplicationBindingThreeServices(Resource resource) throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack(deploymentProperties.getBuildpack())
					.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
					.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
					.environmentVariable("SPRING_APPLICATION_JSON", "{}")
					.healthCheckType(ApplicationHealthCheck.NONE)
					.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
					.name("test-application")
					.noRoute(true)
					.service("test-service-instance-1")
					.service("test-service-instance-2")
					.service("test-service-instance-3")
					.build())
			.stagingTimeout(this.deploymentProperties.getStagingTimeout())
			.startupTimeout(this.deploymentProperties.getStartupTimeout())
			.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(1)
			.stack("test-stack")
			.build()));

	givenRequestStopApplication("test-application", Mono.empty());

	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.SUCCEEDED)
			.build()));
}
 
Example #22
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplication(Resource resource) throws IOException{
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(
			PushApplicationManifestRequest.builder()
					.manifest(ApplicationManifest.builder()
							.path(resource.getFile().toPath())
							.buildpack(deploymentProperties.getBuildpack())
							.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
							.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
							.environmentVariable("SPRING_APPLICATION_JSON", "{}")
							.healthCheckType(ApplicationHealthCheck.NONE)
							.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
							.name("test-application")
							.noRoute(true)
							.services(Collections.emptySet())
							.build())
					.stagingTimeout(this.deploymentProperties.getStagingTimeout())
					.startupTimeout(this.deploymentProperties.getStartupTimeout())
					.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(1)
			.stack("test-stack")
			.build()));

	givenRequestStopApplication("test-application", Mono.empty());

	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.SUCCEEDED)
			.build()));
}
 
Example #23
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private void setupTaskWithNonExistentApplicationBindingOneService(Resource resource) throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack(deploymentProperties.getBuildpack())
					.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
					.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
					.environmentVariable("SPRING_APPLICATION_JSON", "{}")
					.healthCheckType(ApplicationHealthCheck.NONE)
					.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
					.name("test-application")
					.noRoute(true)
					.service("test-service-instance-2")
					.build())
			.stagingTimeout(this.deploymentProperties.getStagingTimeout())
			.startupTimeout(this.deploymentProperties.getStartupTimeout())
			.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(1)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(1)
			.stack("test-stack")
			.build()));

	givenRequestStopApplication("test-application", Mono.empty());

	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.SUCCEEDED)
			.build()));
}
 
Example #24
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void launchTaskWithNonExistentApplicationAndTaskCreationFails() throws IOException {
	givenRequestListApplications(Flux.empty());

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.path(this.resource.getFile().toPath())
			.buildpack(deploymentProperties.getBuildpack())
			.command("echo '*** First run of container to allow droplet creation.***' && sleep 300")
			.disk((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getDisk()))
			.environmentVariable("SPRING_APPLICATION_JSON", "{}")
			.healthCheckType(ApplicationHealthCheck.NONE)
			.memory((int) ByteSizeUtils.parseToMebibytes(this.deploymentProperties.getMemory()))
			.name("test-application")
			.noRoute(true)
			.services(Collections.emptySet())
			.build())
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build(), Mono.empty());

	givenRequestGetApplication("test-application", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.build()));

	givenRequestStopApplication("test-application", Mono.empty());

	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.error(new UnsupportedOperationException()));

	this.launcher.launch(defaultRequest());
}
 
Example #25
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private Mono<SummaryApplicationResponse> requestGetApplicationSummary(String applicationId) {
	return this.client.applicationsV2()
		.summary(org.cloudfoundry.client.v2.applications.SummaryApplicationRequest.builder()
			.applicationId(applicationId)
			.build());
}
 
Example #26
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private Mono<SummaryApplicationResponse> getOrDeployApplication(AppDeploymentRequest request) {
	return getOptionalApplication(request)
		.switchIfEmpty(deployApplication(request))
		.flatMap(application -> requestGetApplicationSummary(application.getId()));
}
 
Example #27
Source File: CloudControllerRestClientImpl.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private Mono<? extends Resource<StackEntity>> getApplicationStackResource(SummaryApplicationResponse summary) {
    UUID stackGuid = UUID.fromString(summary.getStackId());
    return getStackResource(stackGuid);
}
 
Example #28
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void getDeployedAppByNameAndSpace() {
	given(operationsApplications.get(any(org.cloudfoundry.operations.applications.GetApplicationRequest.class)))
		.willReturn(Mono.just(ApplicationDetail.builder()
			.id("foo-id")
			.name("foo-name")
			// fields below are required by builder but we don't care
			.stack("").diskQuota(1).instances(1).memoryLimit(1).requestedState("").runningInstances(1) //
			.build()));
	given(clientApplications.summary(any(SummaryApplicationRequest.class)))
		.willReturn(Mono.just(SummaryApplicationResponse.builder()
			.id("foo-id")
			.name("foo-name")
			.service(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance.builder()
				.name("foo-service-1")
				.build())
			.service(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance.builder()
				.name("foo-service-2")
				.build())
			.environmentJson("foo-key", "foo-value")
			.build()));

	GetApplicationRequest request = GetApplicationRequest.builder()
		.name("foo-name")
		.properties(singletonMap(TARGET_PROPERTY_KEY, "foo-space"))
		.build();
	StepVerifier.create(appDeployer.get(request))
		.assertNext(response -> {
			assertThat(response.getName()).isEqualTo("foo-name");
			assertThat(response.getServices()).hasSize(2);
			assertThat(response.getServices().get(0)).isEqualTo("foo-service-1");
			assertThat(response.getServices().get(1)).isEqualTo("foo-service-2");
			assertThat(response.getEnvironment()).isEqualTo(singletonMap("foo-key", "foo-value"));
		})
		.verifyComplete();

	then(operationsUtils).should().getOperations(
		argThat(argument -> "foo-space".equals(argument.get(TARGET_PROPERTY_KEY))));
	then(cloudFoundryOperations).should().applications();
	then(operationsApplications).should().get(argThat(req -> "foo-name".equals(req.getName())));
	then(clientApplications).should().summary(argThat(req -> "foo-id".equals(req.getApplicationId())));
	then(operationsApplications).shouldHaveNoMoreInteractions();
	then(clientApplications).shouldHaveNoMoreInteractions();
	then(cloudFoundryOperations).shouldHaveNoMoreInteractions();
	then(operationsUtils).shouldHaveNoMoreInteractions();
}
 
Example #29
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void getDeployedAppByName() {
	given(operationsApplications.get(any(org.cloudfoundry.operations.applications.GetApplicationRequest.class)))
		.willReturn(Mono.just(ApplicationDetail.builder()
			.id("foo-id")
			.name("foo-name")
			// fields below are required by builder but we don't care
			.stack("").diskQuota(1).instances(1).memoryLimit(1).requestedState("").runningInstances(1) //
			.build()));
	given(clientApplications.summary(any(SummaryApplicationRequest.class)))
		.willReturn(Mono.just(SummaryApplicationResponse.builder()
			.id("foo-id")
			.name("foo-name")
			.service(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance.builder()
				.name("foo-service-1")
				.build())
			.service(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance.builder()
				.name("foo-service-2")
				.build())
			.environmentJson("foo-key", "foo-value")
			.build()));

	StepVerifier.create(appDeployer.get(GetApplicationRequest.builder().name("foo-name").build()))
		.assertNext(response -> {
			assertThat(response.getName()).isEqualTo("foo-name");
			assertThat(response.getServices()).hasSize(2);
			assertThat(response.getServices().get(0)).isEqualTo("foo-service-1");
			assertThat(response.getServices().get(1)).isEqualTo("foo-service-2");
			assertThat(response.getEnvironment()).isEqualTo(singletonMap("foo-key", "foo-value"));
		})
		.verifyComplete();

	then(operationsUtils).should().getOperations(argThat(CollectionUtils::isEmpty));
	then(cloudFoundryOperations).should().applications();
	then(operationsApplications).should().get(argThat(request -> "foo-name".equals(request.getName())));
	then(clientApplications).should().summary(argThat(request -> "foo-id".equals(request.getApplicationId())));
	then(operationsApplications).shouldHaveNoMoreInteractions();
	then(clientApplications).shouldHaveNoMoreInteractions();
	then(cloudFoundryOperations).shouldHaveNoMoreInteractions();
	then(operationsUtils).shouldHaveNoMoreInteractions();
}
 
Example #30
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 3 votes vote down vote up
/**
 * Set up a reactor flow to stage a task. Before staging check if the base
 * application exists. If not, then stage it.
 *
 * @param request description of the application to be staged.
 * @return SummaryApplicationResponse containing the status of the staging.
 */
public SummaryApplicationResponse stage(AppDeploymentRequest request) {
	return getOrDeployApplication(request).doOnSuccess(r ->
				logger.info("Task {} staged successfully", request.getDefinition().getName()))
			.doOnError(logError(String.format("Task %s stage failed", request.getDefinition().getName())))
			.block(Duration.ofSeconds(this.deploymentProperties.getApiTimeout()));
}