Java Code Examples for org.springframework.cloud.deployer.spi.app.AppStatus#Builder

The following examples show how to use org.springframework.cloud.deployer.spi.app.AppStatus#Builder . 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: MarathonAppDeployer.java    From spring-cloud-deployer-mesos with Apache License 2.0 6 votes vote down vote up
private AppStatus buildAppStatus(String id, App app) {
	logger.debug("Deployment " + id + " has " + app.getTasksRunning() + "/" + app.getInstances() + " tasks running");
	AppStatus.Builder result = AppStatus.of(id);
	int requestedInstances = app.getInstances();
	int actualInstances = 0;
	if (app.getTasks() != null) {
		for (Task task : app.getTasks()) {
			result.with(MarathonAppInstanceStatus.up(app, task));
			actualInstances++;
		}
	}
	for (int i = actualInstances; i < requestedInstances; i++) {
		result.with(MarathonAppInstanceStatus.down(app));
	}
	return result.build();
}
 
Example 3
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 4
Source File: DefaultReleaseManager.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
public static AppStatus copyStatus(AppStatus appStatus) {
	AppStatus.Builder builder = AppStatus.of(appStatus.getDeploymentId());
	if (CollectionUtils.isEmpty(appStatus.getInstances())) {
		builder.generalState(appStatus.getState());
	}
	else {
		appStatus.getInstances().entrySet().stream().map(Map.Entry::getValue).forEach(e -> builder.with(
				new MutableAttributesAppInstanceStatus(e.getId(), e.getState(), e.getAttributes())));
	}
	return builder.build();
}
 
Example 5
Source File: AbstractKubernetesDeployer.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
protected AppStatus buildAppStatus(String id, PodList podList, ServiceList services) {
	AppStatus.Builder statusBuilder = AppStatus.of(id);
	Service service = null;
	if (podList != null && podList.getItems() != null) {
		for (Pod pod : podList.getItems()) {
			String deploymentKey = pod.getMetadata().getLabels().get(SPRING_DEPLOYMENT_KEY);
			for (Service svc : services.getItems()) {
				if (svc.getMetadata().getName().equals(deploymentKey)) {
					service = svc;
					break;
				}
			}
			//find the container with the correct env var
			for(Container container : pod.getSpec().getContainers()) {
				if(container.getEnv().stream().anyMatch(envVar -> "SPRING_CLOUD_APPLICATION_GUID".equals(envVar.getName()))) {
					//find container status for this container
					Optional<ContainerStatus> containerStatusOptional =
						pod.getStatus().getContainerStatuses()
						   .stream().filter(containerStatus -> container.getName().equals(containerStatus.getName()))
						   .findFirst();

					statusBuilder.with(new KubernetesAppInstanceStatus(pod, service, properties, containerStatusOptional.orElse(null)));

					break;
				}
			}
		}
	}
	return statusBuilder.build();
}
 
Example 6
Source File: LocalAppDeployer.java    From spring-cloud-deployer-local with Apache License 2.0 5 votes vote down vote up
@Override
public AppStatus status(String id) {
	AppInstancesHolder holder = running.get(id);
	List<AppInstance> instances = holder != null ? holder.instances : null;
	AppStatus.Builder builder = AppStatus.of(id);

	if (instances != null) {
		for (AppInstance instance : instances) {
			builder.with(instance);
		}
	}

	return builder.build();
}