use of org.apache.airavata.gfac.impl.GFacWorker in project airavata by apache.
the class EmailBasedMonitor method stopMonitor.
@Override
public void stopMonitor(String jobId, boolean runOutflow) {
TaskContext taskContext = jobMonitorMap.remove(jobId);
if (taskContext != null && runOutflow) {
try {
ProcessContext pc = taskContext.getParentProcessContext();
if (taskContext.isCancel()) {
// Moved job status to cancel
JobModel jobModel = pc.getJobModel();
JobStatus newJobStatus = new JobStatus(JobState.CANCELED);
newJobStatus.setReason("Moving job status to cancel, as we didn't see any email from this job " + "for a while after execute job cancel command. This may happen if job was in queued state " + "when we run the cancel command");
jobModel.setJobStatuses(Arrays.asList(newJobStatus));
GFacUtils.saveJobStatus(pc, jobModel);
}
ProcessStatus pStatus = new ProcessStatus(ProcessState.CANCELLING);
pStatus.setReason("Job cancelled");
pc.setProcessStatus(pStatus);
GFacUtils.saveAndPublishProcessStatus(pc);
GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(pc));
} catch (GFacException e) {
log.info("[EJM]: Error while running output tasks", e);
}
}
}
use of org.apache.airavata.gfac.impl.GFacWorker in project airavata by apache.
the class GfacServerHandler method submitProcess.
/**
* * After creating the experiment Data and Task Data in the orchestrator
* * Orchestrator has to invoke this operation for each Task per experiment to run
* * the actual Job related actions.
* *
* * @param experimentID
* * @param taskID
* * @param gatewayId:
* * The GatewayId is inferred from security context and passed onto gfac.
* * @return sucess/failure
* *
* *
*
* @param processId - processModel id in registry
* @param gatewayId - gateway Identification
*/
public boolean submitProcess(String processId, String gatewayId, String tokenId) throws TException {
MDC.put(MDCConstants.PROCESS_ID, processId);
MDC.put(MDCConstants.GATEWAY_ID, gatewayId);
MDC.put(MDCConstants.TOKEN_ID, tokenId);
try {
executorService.execute(MDCUtil.wrapWithMDC(new GFacWorker(processId, gatewayId, tokenId)));
} catch (GFacException e) {
log.error("Failed to submit process", e);
throw new TException("Failed to submit process", e);
} catch (CredentialStoreException e) {
log.error("Failed to submit process due to credential issue, " + "make sure you are passing a valid credentials");
throw new TException("Failed to submit process due to credential issue, " + "make sure you are passing a valid credential token", e);
} catch (Exception e) {
log.error("Error creating zookeeper nodes", e);
throw new TException("Error creating zookeeper nodes", e);
}
return true;
}
use of org.apache.airavata.gfac.impl.GFacWorker in project airavata by apache.
the class EmailBasedMonitor method process.
private void process(JobStatusResult jobStatusResult, TaskContext taskContext) {
canceledJobs.remove(jobStatusResult.getJobId());
JobState resultState = jobStatusResult.getState();
// TODO : update job state on process context
boolean runOutflowTasks = false;
JobStatus jobStatus = new JobStatus();
ProcessContext parentProcessContext = taskContext.getParentProcessContext();
JobModel jobModel = parentProcessContext.getJobModel();
String jobDetails = "JobName : " + jobStatusResult.getJobName() + ", JobId : " + jobStatusResult.getJobId();
JobState currentState = null;
List<JobStatus> jobStatusList = jobModel.getJobStatuses();
if (jobStatusList != null && jobStatusList.size() > 0) {
JobStatus lastStatus = jobStatusList.get(0);
for (JobStatus temp : jobStatusList) {
if (temp.getTimeOfStateChange() >= lastStatus.getTimeOfStateChange()) {
lastStatus = temp;
}
}
currentState = lastStatus.getJobState();
}
// FIXME - What if non-authoritative email comes later (getting accumulated in the email account)
if (resultState == JobState.COMPLETE) {
if (jobStatusResult.isAuthoritative()) {
if (currentState != null && currentState == JobState.COMPLETE) {
jobMonitorMap.remove(jobStatusResult.getJobId());
runOutflowTasks = false;
log.info("[EJM]: Authoritative job Complete email received after early Airavata custom complete email," + " removed job from job monitoring. " + jobDetails);
} else {
jobMonitorMap.remove(jobStatusResult.getJobId());
runOutflowTasks = true;
jobStatus.setJobState(JobState.COMPLETE);
jobStatus.setReason("Complete email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Authoritative job Complete email received , removed job from job monitoring. " + jobDetails);
}
} else {
runOutflowTasks = true;
jobStatus.setJobState(JobState.COMPLETE);
jobStatus.setReason("Complete email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Non Authoritative Job Complete email received. " + jobDetails);
}
} else if (resultState == JobState.QUEUED) {
// scheduler
if (currentState != JobState.COMPLETE) {
// nothing special thing to do, update the status change to rabbit mq at the end of this method.
jobStatus.setJobState(JobState.QUEUED);
jobStatus.setReason("Queue email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Job Queued email received, " + jobDetails);
}
} else if (resultState == JobState.ACTIVE) {
// scheduler
if (currentState != JobState.COMPLETE) {
// nothing special thing to do, update the status change to rabbit mq at the end of this method.
jobStatus.setJobState(JobState.ACTIVE);
jobStatus.setReason("Active email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Job Active email received, " + jobDetails);
}
} else if (resultState == JobState.FAILED) {
// scheduler
if (currentState != JobState.COMPLETE) {
jobMonitorMap.remove(jobStatusResult.getJobId());
runOutflowTasks = true;
jobStatus.setJobState(JobState.FAILED);
jobStatus.setReason("Failed email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Job failed email received , removed job from job monitoring. " + jobDetails);
}
} else if (resultState == JobState.CANCELED) {
// scheduler
if (currentState != JobState.COMPLETE) {
jobMonitorMap.remove(jobStatusResult.getJobId());
jobStatus.setJobState(JobState.CANCELED);
jobStatus.setReason("Canceled email received");
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
log.info("[EJM]: Job canceled mail received, removed job from job monitoring. " + jobDetails);
// we run out flow and this will move process to cancel state.
runOutflowTasks = true;
}
}
if (jobStatus.getJobState() != null) {
try {
jobModel.setJobStatuses(Arrays.asList(jobStatus));
log.info("[EJM]: Publishing status changes to amqp. " + jobDetails);
GFacUtils.saveJobStatus(parentProcessContext, jobModel);
} catch (GFacException e) {
log.error("expId: {}, processId: {}, taskId: {}, jobId: {} :- Error while save and publishing Job " + "status {}", taskContext.getExperimentId(), taskContext.getProcessId(), jobModel.getTaskId(), jobModel.getJobId(), jobStatus.getJobState());
}
}
if (runOutflowTasks) {
log.info("[EJM]: Calling Out Handler chain of " + jobDetails);
try {
TaskStatus taskStatus = new TaskStatus(TaskState.COMPLETED);
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
taskStatus.setReason("Job monitoring completed with final state: " + TaskState.COMPLETED.name());
taskContext.setTaskStatus(taskStatus);
GFacUtils.saveAndPublishTaskStatus(taskContext);
if (parentProcessContext.isCancel()) {
ProcessStatus processStatus = new ProcessStatus(ProcessState.CANCELLING);
processStatus.setReason("Process has been cancelled");
parentProcessContext.setProcessStatus(processStatus);
GFacUtils.saveAndPublishProcessStatus(parentProcessContext);
}
GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(parentProcessContext));
} catch (GFacException e) {
log.info("[EJM]: Error while running output tasks", e);
}
}
}
Aggregations