org.cloudfoundry.operations.applications.InstanceDetail Java Examples

The following examples show how to use org.cloudfoundry.operations.applications.InstanceDetail. 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: 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 #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: 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 #4
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 #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 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 #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 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 #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 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 #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 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 #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 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 #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 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 #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 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 #12
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 #13
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 #14
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 #15
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);
			});
}
 
Example #16
Source File: CloudFoundryAppInstanceStatus.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
public CloudFoundryAppInstanceStatus(ApplicationDetail applicationDetail, InstanceDetail instanceDetail, int index) {
	this.applicationDetail = applicationDetail;
	this.instanceDetail = instanceDetail;
	this.index = index;
}