Java Code Examples for org.springframework.cloud.deployer.spi.task.LaunchState#complete()

The following examples show how to use org.springframework.cloud.deployer.spi.task.LaunchState#complete() . 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: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
private TaskStatus buildPodStatus(String id) {
	Pod pod = getPodByName(id);
	if (pod == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}

	PodStatus podStatus = pod.getStatus();
	if (podStatus == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}

	String phase = podStatus.getPhase();

	switch (phase) {
	case "Pending":
		return new TaskStatus(id, LaunchState.launching, new HashMap<>());
	case "Failed":
		return new TaskStatus(id, LaunchState.failed, new HashMap<>());
	case "Succeeded":
		return new TaskStatus(id, LaunchState.complete, new HashMap<>());
	default:
		return new TaskStatus(id, LaunchState.running, new HashMap<>());
	}
}
 
Example 2
Source File: AbstractCloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
protected TaskStatus toTaskStatus(GetTaskResponse response) {
	switch (response.getState()) {
	case SUCCEEDED:
		return new TaskStatus(response.getId(), LaunchState.complete, null);
	case RUNNING:
		return new TaskStatus(response.getId(), LaunchState.running, null);
	case PENDING:
		return new TaskStatus(response.getId(), LaunchState.launching, null);
	case CANCELING:
		return new TaskStatus(response.getId(), LaunchState.cancelled, null);
	case FAILED:
		return new TaskStatus(response.getId(), LaunchState.failed, null);
	default:
		throw new IllegalStateException(String.format("Unsupported CF task state %s", response.getState()));
	}
}
 
Example 3
Source File: LocalTaskLauncher.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
public LaunchState getState() {
	if (cancelled) {
		return LaunchState.cancelled;
	}
	Integer exit = getProcessExitValue(process);
	// TODO: consider using exit code mapper concept from batch
	if (exit != null) {
		if (exit == 0) {
			return LaunchState.complete;
		}
		else {
			return LaunchState.failed;
		}
	}
	try {
		HttpURLConnection urlConnection = (HttpURLConnection) baseUrl.openConnection();
		urlConnection.setConnectTimeout(100);
		urlConnection.connect();
		urlConnection.disconnect();
		return LaunchState.running;
	}
	catch (IOException e) {
		return LaunchState.launching;
	}
}
 
Example 4
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
TaskStatus buildTaskStatus(String id) {

		if(properties.isCreateJob()){
			Job job = getJob(id);

			if (job == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			JobStatus jobStatus = job.getStatus();

			if (jobStatus == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			boolean failed = jobStatus.getFailed() != null && jobStatus.getFailed() > 0;
			boolean succeeded = jobStatus.getSucceeded() != null && jobStatus.getSucceeded() > 0;
			if (failed) {
				return new TaskStatus(id, LaunchState.failed, new HashMap<>());
			}
			if (succeeded) {
				return new TaskStatus(id, LaunchState.complete, new HashMap<>());
			}
			return new TaskStatus(id, LaunchState.launching, new HashMap<>());

		} else {
			return buildPodStatus(id);
		}
	}
 
Example 5
Source File: ChronosTaskLauncher.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
protected TaskStatus buildTaskStatus(ChronosTaskLauncherProperties properties, String id, Job job, String csv) {
	if (job == null) {
		return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
	}
	String last = null;
	String state= null;
	if (StringUtils.hasText(csv)) {
		List<String> csvLines = Arrays.asList(csv.split("\\r?\\n"));
		for (String line : csvLines) {
			if (line.startsWith("node")) {
				List<String> values = Arrays.asList(line.split("\\s*,\\s*"));
				if (values.size() >= 4) {
					if (id.equals(values.get(1))) {
						last = values.get(2);
						state = values.get(3);
						break;
					}
				}
			}
		}
	}
	if ("running".equals(state)) {
		return new TaskStatus(id, LaunchState.running, new HashMap<>());
	}
	if ("queued".equals(state)) {
		return new TaskStatus(id, LaunchState.launching, new HashMap<>());
	}
	if ("success".equals(last)) {
		return new TaskStatus(id, LaunchState.complete, new HashMap<>());
	}
	else {
		// TODO: state == idle could indicate cancelled?
		return new TaskStatus(id, LaunchState.failed, new HashMap<>());
	}
}
 
Example 6
Source File: TaskConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public String launch(AppDeploymentRequest request) {
	this.state = LaunchState.complete;
	this.commandlineArguments = request.getCommandlineArguments();
	this.applicationName = request.getDefinition().getName();
	return null;
}
 
Example 7
Source File: TaskSinkConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public String launch(AppDeploymentRequest request) {
	state = LaunchState.complete;
	return null;
}