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

The following examples show how to use org.cloudfoundry.client.v2.applications.SummaryApplicationRequest. 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: AppDetailTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<AppDetail> getSummaryInfo(AppDetail fragment) {
    log.trace("Fetching application summary for org={}, space={}, id={}, name={}", fragment.getOrganization(), fragment.getSpace(), fragment.getAppId(), fragment.getAppName());
    return opsClient
            .getCloudFoundryClient()
                .applicationsV2()
                    .summary(SummaryApplicationRequest.builder().applicationId(fragment.getAppId()).build())
                    .flatMap(sar ->
                        Mono
                            .just(AppDetail
                                    .from(fragment)
                                        .buildpack(getBuildpack(sar.getDetectedBuildpackId()))
                                        .buildpackVersion(getBuildpackVersion(sar.getDetectedBuildpackId()))
                                        .image(sar.getDockerImage())
                                        .stack(nullSafeStack(sar.getStackId()))
                                        .lastPushed(nullSafeLocalDateTime(sar.getPackageUpdatedAt()))
                                        .buildpackReleaseType(getBuildpackReleaseType(sar.getDetectedBuildpackId()))
                                        .buildpackReleaseDate(getBuildpackReleaseDate(sar.getDetectedBuildpackId()))                                           
                                        .buildpackLatestVersion(getBuildpackLatestVersion(sar.getDetectedBuildpackId()))
                                        .buildpackLatestUrl(getBuildpackReleaseNotesUrl(sar.getDetectedBuildpackId()))
                                    .build()
                            )
                    )
                    .onErrorResume(ClientV2Exception.class, e -> Mono.just(fragment));
}
 
Example #2
Source File: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void updateAppWithUpgrade() {
	ArgumentCaptor<org.cloudfoundry.client.v2.applications.UpdateApplicationRequest> updateApplicationRequestCaptor =
		ArgumentCaptor.forClass(org.cloudfoundry.client.v2.applications.UpdateApplicationRequest.class);

	given(applicationsV2.update(any())).willReturn(Mono.just(UpdateApplicationResponse.builder().build()));

	UpdateApplicationRequest request = UpdateApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.property("upgrade", "true")
		.environment("TEST_KEY", "TEST_VALUE")
		.build();

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

	then(applicationsV2).should().summary(any(SummaryApplicationRequest.class));
	then(applicationsV2).should().update(updateApplicationRequestCaptor.capture());
	assertThat(updateApplicationRequestCaptor.getValue().getEnvironmentJsons().get("SPRING_APPLICATION_JSON"))
		.isEqualTo("{\"TEST_KEY\":\"TEST_VALUE\"}");
	then(applicationsV2).shouldHaveNoMoreInteractions();
}
 
Example #3
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 #4
Source File: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void updateAppWithNewServices() {
	given(operationsServices.bind(any(BindServiceInstanceRequest.class)))
		.willReturn(Mono.empty());
	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(operationsServices).should()
		.bind(BindServiceInstanceRequest.builder().serviceInstanceName("service-1").applicationName(APP_NAME)
			.build());
	then(operationsServices).should()
		.bind(BindServiceInstanceRequest.builder().serviceInstanceName("service-2").applicationName(APP_NAME)
			.build());
	then(applicationsV2).should().update(argThat(arg -> arg.getApplicationId().equals(APP_ID)));

	then(operationsServices).shouldHaveNoMoreInteractions();
	then(applicationsV2).shouldHaveNoMoreInteractions();
}
 
Example #5
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 #6
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetApplicationResponse> get(GetApplicationRequest request) {
	final String appName = request.getName();

	return operationsUtils.getOperations(request.getProperties())
		.flatMap(cfOperations -> cfOperations.applications()
			.get(org.cloudfoundry.operations.applications.GetApplicationRequest.builder()
				.name(appName)
				.build())
			.doOnRequest(l -> {
				LOG.info("Getting application. appName={}", appName);
				LOG.debug(REQUEST_LOG_TEMPLATE, request);
			})
			.doOnSuccess(response -> {
				LOG.info("Success getting application. appName={}", appName);
				LOG.debug(RESPONSE_LOG_TEMPLATE, response);
			})
			.doOnError(e -> LOG.error(String.format("Error getting application. appName=%s, " + ERROR_LOG_TEMPLATE,
				appName, e.getMessage()), e))
			.map(ApplicationDetail::getId)
			.flatMap(id -> client.applicationsV2().summary(SummaryApplicationRequest.builder()
				.applicationId(id)
				.build())))
		.flatMap(summary -> Flux.fromIterable(summary.getServices())
			.map(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance::getName)
			.collectList()
			.map(services -> GetApplicationResponse.builder()
				.id(summary.getId())
				.name(summary.getName())
				.services(services)
				.environment(summary.getEnvironmentJsons())
				.build()))
		.doOnRequest(l -> {
			LOG.info("Getting application summary. appName={}", appName);
			LOG.debug(REQUEST_LOG_TEMPLATE, request);
		})
		.doOnSuccess(response -> {
			LOG.info("Success getting application summary. appName={}", appName);
			LOG.debug(RESPONSE_LOG_TEMPLATE, response);
		})
		.doOnError(e -> LOG.error(String.format("Error getting application summary. appName=%s, " +
			ERROR_LOG_TEMPLATE, appName, e.getMessage()), e));
}
 
Example #7
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 #8
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();
}