Java Code Examples for org.springframework.cloud.deployer.spi.app.DeploymentState#deployed()

The following examples show how to use org.springframework.cloud.deployer.spi.app.DeploymentState#deployed() . 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: HealthCheckStep.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
public boolean isHealthy(Release replacingRelease) {
	AppDeployerData replacingAppDeployerData = this.appDeployerDataRepository
			.findByReleaseNameAndReleaseVersionRequired(
					replacingRelease.getName(), replacingRelease.getVersion());
	Map<String, String> appNamesAndDeploymentIds = (replacingAppDeployerData!= null) ?
			replacingAppDeployerData.getDeploymentDataAsMap() : Collections.EMPTY_MAP;
	AppDeployer appDeployer = this.deployerRepository
			.findByNameRequired(replacingRelease.getPlatformName())
			.getAppDeployer();
	logger.debug("Getting status for apps in replacing release {}-v{}", replacingRelease.getName(),
			replacingRelease.getVersion());
	for (Map.Entry<String, String> appNameAndDeploymentId : appNamesAndDeploymentIds.entrySet()) {
		AppStatus status = appDeployer.status(appNameAndDeploymentId.getValue());
		if (status.getState() == DeploymentState.deployed) {
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: MarathonAppInstanceStatus.java    From spring-cloud-deployer-mesos with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentState getState() {
	if (task == null) {
		if (app.getLastTaskFailure() == null) {
			return DeploymentState.unknown;
		}
		else {
			return DeploymentState.failed;
		}
	}
	else {
		if (app.getInstances().intValue() > app.getTasksRunning().intValue()) {
			return DeploymentState.deploying;
		}
		else {
			Collection<HealthCheckResult> healthCheckResults = task.getHealthCheckResults();
			boolean alive = healthCheckResults != null && healthCheckResults.iterator().next().isAlive();
			if (!alive && app.getLastTaskFailure() != null) {
				return DeploymentState.failed;
			}
			return alive ? DeploymentState.deployed : DeploymentState.deploying;
		}
	}
}
 
Example 3
Source File: CloudFoundryAppInstanceStatus.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentState getState() {
	if (instanceDetail == null) {
		return DeploymentState.failed;
	}
	switch (instanceDetail.getState()) {
		case "STARTING":
		case "DOWN":
			return DeploymentState.deploying;
		case "CRASHED":
			return DeploymentState.failed;
		// Seems the client incorrectly reports apps as FLAPPING when they are
		// obviously fine. Mapping as RUNNING for now
		case "FLAPPING":
		case "RUNNING":
			return DeploymentState.deployed;
		case "UNKNOWN":
			return DeploymentState.unknown;
		default:
			throw new IllegalStateException("Unsupported CF state: " + instanceDetail.getState());
	}
}
 
Example 4
Source File: LocalAppDeployer.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentState getState() {
	Integer exit = getProcessExitValue(process);
	// TODO: consider using exit code mapper concept from batch
	if (exit != null) {
		return DeploymentState.failed;
	}
	if (port < 1) {
		// Support case where user passed in zero or negative port indicating fully random
		// chosen by OS. In this case we simply return deployed if process is up.
		// Also we can't even try http check as we would not know port to connect to.
		return DeploymentState.deployed;
	}
	try {
		HttpURLConnection urlConnection = (HttpURLConnection) baseUrl.openConnection();
		urlConnection.setConnectTimeout(100);
		urlConnection.connect();
		urlConnection.disconnect();
		return DeploymentState.deployed;
	}
	catch (IOException e) {
		return DeploymentState.deploying;
	}
}
 
Example 5
Source File: RuntimeStreamsControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private AppInstanceStatus instance(String id, String guid, String appName) {
	return new AppInstanceStatus() {
		@Override
		public String getId() {
			return id;
		}

		@Override
		public DeploymentState getState() {
			return DeploymentState.deployed;
		}

		@Override
		public Map<String, String> getAttributes() {
			Map<String, String> attributes = new HashMap<>();
			attributes.put(StreamRuntimePropertyKeys.ATTRIBUTE_SKIPPER_APPLICATION_NAME, appName);
			if (guid != null) {
				attributes.put(StreamRuntimePropertyKeys.ATTRIBUTE_GUID, guid);
			}
			return attributes;
		}
	};
}
 
Example 6
Source File: ReleaseCommands.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
/**
 * Aggregate the set of app states into a single state for a stream.
 *
 * @param states set of states for apps of a stream
 * @return the stream state based on app states
 */
public static DeploymentState aggregateState(List<DeploymentState> states) {
	if (states.size() == 1) {
		DeploymentState state = states.iterator().next();
		logger.debug("aggregateState: Deployment State Set Size = 1.  Deployment State " + state);
		// a stream which is known to the stream definition repository
		// but unknown to deployers is undeployed
		if (state == DeploymentState.unknown) {
			logger.debug("aggregateState: Returning " + DeploymentState.undeployed);
			return DeploymentState.undeployed;
		}
		else {
			logger.debug("aggregateState: Returning " + state);
			return state;
		}
	}
	if (states.isEmpty() || states.contains(DeploymentState.error)) {
		logger.debug("aggregateState: Returning " + DeploymentState.error);
		return DeploymentState.error;
	}
	if (states.contains(DeploymentState.failed)) {
		logger.debug("aggregateState: Returning " + DeploymentState.failed);
		return DeploymentState.failed;
	}
	if (states.contains(DeploymentState.deploying)) {
		logger.debug("aggregateState: Returning " + DeploymentState.deploying);
		return DeploymentState.deploying;
	}

	if (allAppsDeployed(states)) {
		return DeploymentState.deployed;
	}

	logger.debug("aggregateState: Returning " + DeploymentState.partial);
	return DeploymentState.partial;
}
 
Example 7
Source File: ReleaseCommands.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
private static boolean allAppsDeployed(List<DeploymentState> deploymentStateList) {
	boolean allDeployed = true;
	for (DeploymentState deploymentState : deploymentStateList) {
		if (deploymentState != DeploymentState.deployed) {
			allDeployed = false;
			break;
		}
	}
	return allDeployed;
}
 
Example 8
Source File: AbstractAssertReleaseDeployedTest.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
protected boolean allAppsDeployed(List<AppStatus> appStatusList) {
	boolean allDeployed = true;
	for (AppStatus appStatus : appStatusList) {
		if (appStatus.getState() != DeploymentState.deployed) {
			allDeployed = false;
			break;
		}
	}
	return allDeployed;
}
 
Example 9
Source File: CloudFoundryHealthCheckStep.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
public boolean isHealthy(Release replacingRelease) {
	AppStatus appStatus = cfManifestApplicationDeployer.status(replacingRelease);
	if (appStatus.getState() == DeploymentState.deployed) {
		return true;
	}
	return false;
}
 
Example 10
Source File: PredicateRunningPhaseDeploymentStateResolver.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
ContainerReady(KubernetesDeployerProperties properties) {
	super(properties, DeploymentState.deployed, new ContainerStatusCondition("container ready") {
		@Override
		public boolean test(ContainerStatus containerStatus) {
			return containerStatus.getReady();
		}
	});
}
 
Example 11
Source File: YarnAppDeployer.java    From spring-cloud-deployer-yarn with Apache License 2.0 5 votes vote down vote up
public InstanceStatus(String id, boolean deployed, Map<String, String> attributes) {
	this.id = id;
	this.state = deployed ? DeploymentState.deployed : DeploymentState.unknown;
	if (attributes != null) {
		this.attributes.putAll(attributes);
	}
}
 
Example 12
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private DeploymentState mapShallowAppState(ApplicationSummary applicationSummary) {
	if (applicationSummary.getRunningInstances().equals(applicationSummary.getInstances())) {
		return DeploymentState.deployed;
	}
	else if (applicationSummary.getInstances() > 0) {
		return DeploymentState.partial;
	} else {
		return DeploymentState.undeployed;
	}
}
 
Example 13
Source File: SkipperStreamDeployer.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private DeploymentState getDeploymentStateFromStatusInfo(Info info) {
	DeploymentState result = DeploymentState.unknown;
	switch (info.getStatus().getStatusCode()) {
	case FAILED:
		result = DeploymentState.failed;
		break;
	case DELETED:
		result = DeploymentState.undeployed;
		break;
	case DEPLOYED:
		result = DeploymentState.deployed;
	}
	return result;
}
 
Example 14
Source File: DefaultStreamService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Deploys the stream with the user provided deployment properties. Implementations are
 * responsible for expanding deployment wildcard expressions.
 * @param streamName the name of the stream
 * @param deploymentProperties deployment properties to use as passed in from the client.
 */
public void deployStream(String streamName, Map<String, String> deploymentProperties) {
	if (deploymentProperties == null) {
		deploymentProperties = new HashMap<>();
	}
	StreamDefinition streamDefinition = this.streamDefinitionRepository.findById(streamName)
			.orElseThrow(() -> new NoSuchStreamDefinitionException(streamName));

	DeploymentState status = this.doCalculateStreamState(streamName);

	if (DeploymentState.deployed == status) {
		throw new StreamAlreadyDeployedException(streamName);
	}
	else if (DeploymentState.deploying == status) {
		throw new StreamAlreadyDeployingException(streamName);
	}
	Release deploymentRelease = doDeployStream(streamDefinition, deploymentProperties);
	String platformName = deploymentRelease == null ? null : deploymentRelease.getPlatformName();

	auditRecordService.populateAndSaveAuditRecordUsingMapData(
			AuditOperationType.STREAM, AuditActionType.DEPLOY,
			streamDefinition.getName(),
			this.auditServiceUtils.convertStreamDefinitionToAuditData(
					StreamDefinitionServiceUtils.sanitizeStreamDefinition(streamDefinition.getName(),
							this.streamDefinitionService.getAppDefinitions(streamDefinition)), deploymentProperties),
			platformName);
}