* @param jobExecutionId
* @return job status
* @throws NoSuchJobException
*/
public TaskRead getJobExecutionStatus(long jobExecutionId) {
JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
if (jobExecution == null) {
throw BddException.NOT_FOUND("Task", Long.toString(jobExecutionId));
}
TaskRead jobStatus = new TaskRead();
jobStatus.setId(jobExecutionId);
//identify VHM jobs
String jobName = jobExecution.getJobInstance().getJobName();
if (jobName.equals(JobConstants.SET_MANUAL_ELASTICITY_JOB_NAME)) {
jobStatus.setType(Type.VHM);
} else if (jobName.equals(JobConstants.DELETE_CLUSTER_JOB_NAME)) {
jobStatus.setType(Type.DELETE);
}
JobParameters jobParameters =
jobExecution.getJobInstance().getJobParameters();
String clusterName =
jobParameters.getString(JobConstants.CLUSTER_NAME_JOB_PARAM);
jobStatus.setTarget(clusterName);
long subJobEnabled = jobParameters.getLong(JobConstants.SUB_JOB_ENABLED);
if (subJobEnabled != 1) {
jobStatus.setProgress(jobExecutionStatusHolder
.getCurrentProgress(jobExecutionId));
} else {
jobStatus.setProgress(mainJobExecutionStatusHolder
.getCurrentProgress(jobExecutionId));
}
Status status = null;
switch (jobExecution.getStatus()) {
case ABANDONED:
status = Status.ABANDONED;
break;
case COMPLETED:
status = Status.COMPLETED;
break;
case FAILED:
status = Status.FAILED;
break;
case STARTED:
status = Status.STARTED;
break;
case STARTING:
status = Status.STARTING;
break;
case STOPPED:
status = Status.STOPPED;
break;
case STOPPING:
status = Status.STOPPING;
break;
case UNKNOWN:
default:
status = Status.UNKNOWN;
}
jobStatus.setStatus(status);
if (subJobEnabled == 1) {
List<NodeOperationStatus> succeedNodes =
(ArrayList<NodeOperationStatus>) jobExecution.getExecutionContext()
.get(JobConstants.SUB_JOB_NODES_SUCCEED);
List<NodeOperationStatus> failNodes =
(ArrayList<NodeOperationStatus>) jobExecution.getExecutionContext()
.get(JobConstants.SUB_JOB_NODES_FAIL);
if (succeedNodes != null) {
jobStatus.setSucceedNodes(convert(succeedNodes));
}
if (failNodes != null) {
jobStatus.setFailNodes(convert(failNodes));
}
}
if (status.equals(Status.FAILED) && subJobEnabled != 1) {
String workDir =
TrackableTasklet.getFromJobExecutionContext(
jobExecution.getExecutionContext(),
JobConstants.CURRENT_COMMAND_WORK_DIR, String.class);
String errorMessage =
TrackableTasklet.getFromJobExecutionContext(
jobExecution.getExecutionContext(),
JobConstants.CURRENT_ERROR_MESSAGE, String.class);
jobStatus.setErrorMessage(errorMessage);
jobStatus.setWorkDir(workDir);
logger.error("mark task as failed: " + errorMessage);
}