org.cloudfoundry.operations.applications.ApplicationDetail Java Examples

The following examples show how to use org.cloudfoundry.operations.applications.ApplicationDetail. 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: CloudFoundryDiscoveryClient.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Override
public List<ServiceInstance> getInstances(String serviceId) {
	return this.cloudFoundryService.getApplicationInstances(serviceId).map(tuple -> {
		ApplicationDetail applicationDetail = tuple.getT1();
		InstanceDetail instanceDetail = tuple.getT2();

		String applicationId = applicationDetail.getId();
		String applicationIndex = instanceDetail.getIndex();
		String instanceId = applicationId + "." + applicationIndex;
		String name = applicationDetail.getName();
		String url = applicationDetail.getUrls().size() > 0
				? applicationDetail.getUrls().get(0) : null;
		boolean secure = (url + "").toLowerCase().startsWith("https");

		HashMap<String, String> metadata = new HashMap<>();
		metadata.put("applicationId", applicationId);
		metadata.put("instanceId", applicationIndex);

		return (ServiceInstance) new DefaultServiceInstance(instanceId, name, url,
				secure ? 443 : 80, secure, metadata);
	}).collectList().blockOptional().orElse(new ArrayList<>());
}
 
Example #2
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
private AppStatus createAppStatus(ApplicationDetail applicationDetail, String deploymentId) {
	logger.trace("Gathering instances for " + applicationDetail);
	logger.trace("InstanceDetails: " + applicationDetail.getInstanceDetails());

	AppStatus.Builder builder = AppStatus.of(deploymentId);

	int i = 0;
	for (InstanceDetail instanceDetail : applicationDetail.getInstanceDetails()) {
		builder.with(new CloudFoundryAppInstanceStatus(applicationDetail, instanceDetail, i++));
	}
	for (; i < applicationDetail.getInstances(); i++) {
		builder.with(new CloudFoundryAppInstanceStatus(applicationDetail, null, i));
	}

	return builder.build();
}
 
Example #3
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
private Mono<ApplicationDetail> requestGetApplication(String id) {
	return CacheMono
		.lookup(k -> Mono.defer(() -> {
			ApplicationDetail ifPresent = cache.getIfPresent(id);
			logger.debug("Cache get {}", ifPresent);
			return Mono.justOrEmpty(ifPresent).map(Signal::next);
		}), id)
		.onCacheMissResume(Mono.defer(() -> {
			logger.debug("Cache miss {}", id);
			return getApplicationDetail(id);
		}))
		.andWriteWith((k, sig) -> Mono.fromRunnable(() -> {
			ApplicationDetail ap = sig.get();
			if (ap != null) {
				logger.debug("Cache put {} {}", k, ap);
				cache.put(k, ap);
			}
		}));
}
 
Example #4
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class)
public void deployWithMultipleRoutesAndHostOrDomainMutuallyExclusive() {
	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

	givenRequestGetApplication("test-application-id",
			Mono.error(new IllegalArgumentException()),
			Mono.just(ApplicationDetail.builder()
					.id("test-application-id")
					.name("test-application")
					.build()));

	this.deploymentProperties.setHost("route0");
	this.deploymentProperties.setDomain("test-domain");
	this.deploymentProperties.setRoutes(Sets.newHashSet("route1.test-domain", "route2.test-domain"));

	this.deployer.deploy(new AppDeploymentRequest(
			new AppDefinition("test-application", Collections.emptyMap()),
			resource,
			Collections.emptyMap()));

	fail("routes and hosts cannot be set, expect cf java client to throw an exception");
}
 
Example #5
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfCrashedApplicationIsFailed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("CRASHED").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.failed));
}
 
Example #6
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfDownApplicationIsDeploying() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("DOWN").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deploying));
}
 
Example #7
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfFlappingApplicationIsDeployed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("FLAPPING").index("1").build())
		.build()));

	AppStatus status = deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deployed));
}
 
Example #8
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfRunningApplicationIsDeployed() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deployed));
	assertThat(status.getInstances().get("test-application-0").toString(),
		equalTo("CloudFoundryAppInstanceStatus[test-application-0 : deployed]"));
	assertThat(status.getInstances().get("test-application-0").getAttributes(),
		equalTo(Collections.singletonMap("guid", "test-application:0")));
}
 
Example #9
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfStartingApplicationIsDeploying() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("STARTING").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.deploying));
}
 
Example #10
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusOfUnknownApplicationIsUnknown() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("UNKNOWN").index("1").build())
		.build()));

	AppStatus status = this.deployer.status("test-application-id");

	assertThat(status.getState(), equalTo(DeploymentState.unknown));
}
 
Example #11
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void statusWithAbnormalInstanceStateThrowsException() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("ABNORMAL").index("1").build())
		.build()));

	try {
		this.deployer.status("test-application-id").getState();

		fail();
	} catch (IllegalStateException e) {
		assertThat(e.getMessage(), containsString("Unsupported CF state"));
	}
}
 
Example #12
Source File: AppManagementRestartAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 6 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_1,
	"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
	"spring.cloud.appbroker.services[0].apps[1].name=" + APP_2,
	"spring.cloud.appbroker.services[0].apps[1].path=" + BACKING_APP_PATH
})
void restartApps() {
	List<ApplicationDetail> apps = getApplications(APP_1, APP_2).block();
	Date originallySince1 = apps.get(0).getInstanceDetails().get(0).getSince();
	Date originallySince2 = apps.get(1).getInstanceDetails().get(0).getSince();

	StepVerifier.create(manageApps(SI_NAME, APP_SERVICE_NAME, PLAN_NAME, "restart"))
		.assertNext(result -> assertThat(result).contains("restarting"))
		.verifyComplete();

	List<ApplicationDetail> restagedApps = getApplications(APP_1, APP_2).block();
	Date since1 = restagedApps.get(0).getInstanceDetails().get(0).getSince();
	Date since2 = restagedApps.get(1).getInstanceDetails().get(0).getSince();
	assertThat(restagedApps).extracting("runningInstances").containsOnly(1);
	assertThat(since1).isAfter(originallySince1);
	assertThat(since2).isAfter(originallySince2);
}
 
Example #13
Source File: AppManagementRestageAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 6 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_1,
	"spring.cloud.appbroker.services[0].apps[0].path=" + BACKING_APP_PATH,
	"spring.cloud.appbroker.services[0].apps[1].name=" + APP_2,
	"spring.cloud.appbroker.services[0].apps[1].path=" + BACKING_APP_PATH
})
void restageApps() throws Exception {
	List<ApplicationDetail> apps = getApplications(APP_1, APP_2).block();
	Date originallySince1 = apps.get(0).getInstanceDetails().get(0).getSince();
	Date originallySince2 = apps.get(1).getInstanceDetails().get(0).getSince();
	assertThat(apps).extracting("runningInstances").containsOnly(1);

	StepVerifier.create(manageApps(SI_NAME, APP_SERVICE_NAME, PLAN_NAME, "restage"))
		.assertNext(result -> assertThat(result).contains("restaging"))
		.verifyComplete();

	List<ApplicationDetail> restagedApps = getApplications(APP_1, APP_2).block();
	Date since1 = restagedApps.get(0).getInstanceDetails().get(0).getSince();
	Date since2 = restagedApps.get(1).getInstanceDetails().get(0).getSince();
	assertThat(restagedApps).extracting("runningInstances").containsOnly(1);
	assertThat(since1).isAfter(originallySince1);
	assertThat(since2).isAfter(originallySince2);
}
 
Example #14
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void undeploy() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
		.diskQuota(0)
		.id("test-application-id")
		.instances(1)
		.memoryLimit(0)
		.name("test-application")
		.requestedState("RUNNING")
		.runningInstances(1)
		.stack("test-stack")
		.instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build())
		.build()));
	givenRequestDeleteApplication("test-application-id", Mono.empty());

	this.deployer.undeploy("test-application-id");

}
 
Example #15
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
public Mono<Void> updateBrokerApp(String appName, String brokerClientId, List<String> appBrokerProperties) {
	return cloudFoundryOperations.applications().get(GetApplicationRequest.builder().name(appName).build())
		.map(ApplicationDetail::getId)
		.flatMap(applicationId -> cloudFoundryClient.applicationsV2().update(UpdateApplicationRequest
			.builder()
			.applicationId(applicationId)
			.putAllEnvironmentJsons(appBrokerDeployerEnvironmentVariables(brokerClientId))
			.putAllEnvironmentJsons(propertiesToEnvironment(appBrokerProperties))
			.name(appName)
			.memory(1024)
			.build())
			.thenReturn(applicationId))
		.then(cloudFoundryOperations.applications().restart(RestartApplicationRequest.builder()
			.name(appName)
			.build()))
		.doOnSuccess(item -> LOG.info("Updated broker app " + appName))
		.doOnError(error -> LOG.error("Error updating broker app " + appName + ": " + error))
		.then();
}
 
Example #16
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void scale() {
	givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder()
			.diskQuota(0)
			.id("test-application-id")
			.instances(2)
			.memoryLimit(0)
			.name("test-application")
			.requestedState("RUNNING")
			.runningInstances(2)
			.stack("test-stack")
			.instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build())
			.build()));
	givenRequestScaleApplication("test-application-id", 2, 1024, 1024, Mono.empty());
	this.deployer.scale(new AppScaleRequest("test-application-id", 2));
}
 
Example #17
Source File: CloudFoundryManifestApplicationDeployer.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
private AppStatus createAppStatus(ApplicationDetail applicationDetail, String deploymentId) {
	logger.trace("Gathering instances for " + applicationDetail);
	logger.trace("InstanceDetails: " + applicationDetail.getInstanceDetails());

	AppStatus.Builder builder = AppStatus.of(deploymentId);

	int i = 0;
	for (InstanceDetail instanceDetail : applicationDetail.getInstanceDetails()) {
		builder.with(new CloudFoundryAppInstanceStatus(applicationDetail, instanceDetail, i++));
	}
	for (; i < applicationDetail.getInstances(); i++) {
		builder.with(new CloudFoundryAppInstanceStatus(applicationDetail, null, i));
	}

	return builder.build();
}
 
Example #18
Source File: CloudFoundryAppServiceDiscoveryClient.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Override
public List<ServiceInstance> getInstances(String serviceId) {
	return getCloudFoundryService()
			.getApplicationInstances(serviceId).filter(tuple -> tuple.getT1()
					.getUrls().stream().anyMatch(this::isInternalDomain))
			.map(tuple -> {
				ApplicationDetail applicationDetail = tuple.getT1();
				InstanceDetail instanceDetail = tuple.getT2();
				String applicationId = applicationDetail.getId();
				String applicationIndex = instanceDetail.getIndex();
				String name = applicationDetail.getName();
				String url = applicationDetail.getUrls().stream()
						.filter(this::isInternalDomain).findFirst()
						.map(x -> instanceDetail.getIndex() + "." + x).get();
				HashMap<String, String> metadata = new HashMap<>();
				metadata.put("applicationId", applicationId);
				metadata.put("instanceId", applicationIndex);
				return (ServiceInstance) new DefaultServiceInstance(name, url, 8080,
						false, metadata);
			}).collectList().block();
}
 
Example #19
Source File: CloudFoundryNativeReactiveDiscoveryClient.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
protected ServiceInstance mapApplicationInstanceToServiceInstance(
		Tuple2<ApplicationDetail, InstanceDetail> tuple) {
	ApplicationDetail applicationDetail = tuple.getT1();
	InstanceDetail instanceDetail = tuple.getT2();

	String applicationId = applicationDetail.getId();
	String applicationIndex = instanceDetail.getIndex();
	String instanceId = applicationId + "." + applicationIndex;
	String name = applicationDetail.getName();
	String url = applicationDetail.getUrls().size() > 0
			? applicationDetail.getUrls().get(0) : null;
	boolean secure = (url + "").toLowerCase().startsWith("https");

	HashMap<String, String> metadata = new HashMap<>();
	metadata.put("applicationId", applicationId);
	metadata.put("instanceId", applicationIndex);

	return new DefaultServiceInstance(instanceId, name, url, secure ? 443 : 80,
			secure, metadata);
}
 
Example #20
Source File: CfGetDetailsTaskDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
private ApplicationDetail sampleApplicationDetail() {
    return ApplicationDetail.builder()
        .id("id")
        .instances(1)
        .name("test")
        .stack("stack")
        .diskQuota(1)
        .requestedState("started")
        .memoryLimit(1000)
        .runningInstances(2)
        .build();
}
 
Example #21
Source File: CloudFoundryAcceptanceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<List<ApplicationDetail>> getApplications(String app1, String app2) {
	return Flux.merge(cloudFoundryService.getApplication(app1),
		cloudFoundryService.getApplication(app2))
		.parallel()
		.runOn(Schedulers.parallel())
		.sequential()
		.collectList();
}
 
Example #22
Source File: CfAppDetailsDelegate.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public Mono<Optional<ApplicationDetail>> getAppDetails(
    CloudFoundryOperations cfOperations, CfProperties cfProperties) {
    Mono<ApplicationDetail> applicationDetailMono = cfOperations.applications()
        .get(GetApplicationRequest.builder().name(cfProperties.name()).build())
        .doOnSubscribe((c) -> {
            LOGGER.lifecycle("Checking details of app '{}'", cfProperties.name());
        });

    return applicationDetailMono
        .map(appDetail -> Optional.ofNullable(appDetail))
        .onErrorResume(Exception.class, e -> Mono.just(Optional.empty()));
}
 
Example #23
Source File: PcfDevIntegrationTests.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
    public void getAppDetailTests() {
        ConnectionContext connectionContext = DefaultConnectionContext.builder()
            .apiHost("api.local.pcfdev.io")
            .skipSslValidation(true)
            .build();

        TokenProvider tokenProvider = PasswordGrantTokenProvider.builder()
            .password("admin")
            .username("admin")
            .build();

        CloudFoundryClient cfClient = ReactorCloudFoundryClient.builder()
            .connectionContext(connectionContext)
            .tokenProvider(tokenProvider)
            .build();

        CloudFoundryOperations cfOperations = DefaultCloudFoundryOperations.builder()
            .cloudFoundryClient(cfClient)
            .organization("pcfdev-org")
            .space("pcfdev-space")
            .build();

        CfAppDetailsDelegate appDetailsTaskDelegate = new CfAppDetailsDelegate();
        CfProperties cfAppProps = envDetails();
        Mono<Optional<ApplicationDetail>> applicationDetailMono = appDetailsTaskDelegate
            .getAppDetails(cfOperations, cfAppProps);


//		Mono<Void> resp = applicationDetailMono.then(applicationDetail -> Mono.fromSupplier(() -> {
//			return 1;
//		})).then();
//
//		resp.block();
//		ApplicationDetail applicationDetail = applicationDetailMono.block(Duration.ofMillis(5000));
//		System.out.println("applicationDetail = " + applicationDetail);
    }
 
Example #24
Source File: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private ApplicationDetail createApplicationDetail() {
	return ApplicationDetail
		.builder()
		.id(APP_ID)
		.stack("")
		.diskQuota(512)
		.instances(1)
		.memoryLimit(512)
		.name(APP_NAME)
		.requestedState("STARTED")
		.runningInstances(1)
		.build();
}
 
Example #25
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void givenRequestGetApplication(String name, Mono<ApplicationDetail> response) {
	given(this.operations.applications()
		.get(GetApplicationRequest.builder()
			.name(name)
			.build()))
		.willReturn(response);
}
 
Example #26
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void setupTaskWithNonExistentApplicationAndRetrievingApplicationSummaryFails(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.error(new UnsupportedOperationException()));

}
 
Example #27
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void setupTaskWithNonExistentApplicationAndStoppingApplicationFails(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.error(new UnsupportedOperationException()));
}
 
Example #28
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void deployResource(CloudFoundryAppDeployer deployer, Resource resource) throws IOException {
	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

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

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
			.manifest(ApplicationManifest.builder()
					.path(resource.getFile().toPath())
					.buildpack(deploymentProperties.getBuildpack())
					.disk(1024)
					.instances(1)
					.memory(1024)
					.name("test-application-id")
					.build())
			.stagingTimeout(this.deploymentProperties.getStagingTimeout())
			.startupTimeout(this.deploymentProperties.getStartupTimeout())
			.build(), Mono.empty());

	deployer.deploy(
			new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()), resource,
					Collections.EMPTY_MAP));

}
 
Example #29
Source File: CloudFoundryAppDeployerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void deployDockerResource() {
	Resource resource = new DockerResource("somecorp/someimage:latest");

	given(this.applicationNameGenerator.generateAppName("test-application")).willReturn("test-application-id");

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

	givenRequestPushApplication(PushApplicationManifestRequest.builder()
		.manifest(ApplicationManifest.builder()
			.docker(Docker.builder().image("somecorp/someimage:latest").build())
			.disk(1024)
			.environmentVariables(defaultEnvironmentVariables())
			.instances(1)
			.memory(1024)
			.name("test-application-id")
			.service("test-service-2")
			.service("test-service-1")
			.build())
		.stagingTimeout(this.deploymentProperties.getStagingTimeout())
		.startupTimeout(this.deploymentProperties.getStartupTimeout())
		.build(), Mono.empty());

	String deploymentId = this.deployer.deploy(
		new AppDeploymentRequest(new AppDefinition("test-application", Collections.emptyMap()), resource,
			Collections.emptyMap()));

	assertThat(deploymentId, equalTo("test-application-id"));
}
 
Example #30
Source File: CloudFoundryService.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(
		String serviceId) {
	GetApplicationRequest applicationRequest = GetApplicationRequest.builder()
			.name(serviceId).build();
	return this.cloudFoundryOperations.applications().get(applicationRequest)
			.flatMapMany(applicationDetail -> {
				Flux<InstanceDetail> ids = Flux
						.fromStream(applicationDetail.getInstanceDetails().stream())
						.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
				Flux<ApplicationDetail> generate = Flux
						.generate(sink -> sink.next(applicationDetail));
				return generate.zipWith(ids);
			});
}