use of org.apache.airavata.gfac.core.monitor.JobMonitor in project airavata by apache.
the class Factory method getMonitorService.
public static JobMonitor getMonitorService(MonitorMode monitorMode) throws AiravataException, GFacException {
JobMonitor jobMonitor = jobMonitorServices.get(monitorMode);
if (jobMonitor == null) {
synchronized (JobMonitor.class) {
jobMonitor = jobMonitorServices.get(monitorMode);
if (jobMonitor == null) {
switch(monitorMode) {
case JOB_EMAIL_NOTIFICATION_MONITOR:
EmailBasedMonitor emailBasedMonitor = new EmailBasedMonitor(Factory.getResourceConfig());
jobMonitorServices.put(MonitorMode.JOB_EMAIL_NOTIFICATION_MONITOR, emailBasedMonitor);
jobMonitor = emailBasedMonitor;
new Thread(emailBasedMonitor).start();
break;
case CLOUD_JOB_MONITOR:
AuroraJobMonitor auroraJobMonitor = AuroraJobMonitor.getInstance();
new Thread(auroraJobMonitor).start();
jobMonitorServices.put(MonitorMode.CLOUD_JOB_MONITOR, auroraJobMonitor);
jobMonitor = auroraJobMonitor;
break;
default:
throw new GFacException("Unsupported monitor mode :" + monitorMode.name());
}
}
}
}
return jobMonitor;
}
use of org.apache.airavata.gfac.core.monitor.JobMonitor in project airavata by apache.
the class GFacEngineImpl method executeCancel.
private void executeCancel(TaskContext taskContext, JobSubmissionTask jSTask) throws GFacException {
try {
JobStatus oldJobStatus = jSTask.cancel(taskContext);
// If Job was in Queued state when cancel command runs, then there won't be any email from this job.
ProcessContext pc = taskContext.getParentProcessContext();
JobMonitor monitorService = Factory.getMonitorService(pc.getMonitorMode());
monitorService.canceledJob(pc.getJobModel().getJobId());
} catch (TaskException e) {
throw new GFacException("Error while cancelling job");
} catch (AiravataException e) {
throw new GFacException("Error wile getting monitoring service");
}
}
use of org.apache.airavata.gfac.core.monitor.JobMonitor in project airavata by apache.
the class GFacEngineImpl method executeJobMonitoring.
private void executeJobMonitoring(TaskContext taskContext, boolean recovery) throws GFacException {
ProcessContext processContext = taskContext.getParentProcessContext();
TaskStatus taskStatus;
JobMonitor monitorService = null;
try {
taskStatus = new TaskStatus(TaskState.EXECUTING);
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
taskContext.setTaskStatus(taskStatus);
GFacUtils.saveAndPublishTaskStatus(taskContext);
MonitorTaskModel monitorTaskModel = ((MonitorTaskModel) taskContext.getSubTaskModel());
monitorService = Factory.getMonitorService(monitorTaskModel.getMonitorMode());
if (!monitorService.isMonitoring(processContext.getJobModel().getJobId())) {
monitorService.monitor(processContext.getJobModel().getJobId(), taskContext);
} else {
log.warn("Jobid: {}, already in monitoring map", processContext.getJobModel().getJobId());
}
} catch (AiravataException | TException e) {
taskStatus = new TaskStatus(TaskState.FAILED);
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
taskStatus.setReason("Couldn't handover jobId {} to monitor service, monitor service type {}");
taskContext.setTaskStatus(taskStatus);
GFacUtils.saveAndPublishTaskStatus(taskContext);
String errorMsg = new StringBuilder("expId: ").append(processContext.getExperimentId()).append(", processId: ").append(processContext.getProcessId()).append(", taskId: ").append(taskContext.getTaskId()).append(", type: ").append(taskContext.getTaskType().name()).append(" :- Input staging failed. Reason: ").append(taskStatus.getReason()).toString();
ErrorModel errorModel = new ErrorModel();
errorModel.setUserFriendlyMessage("Error while staging output data");
errorModel.setActualErrorMessage(errorMsg);
GFacUtils.saveTaskError(taskContext, errorModel);
throw new GFacException(e);
}
if (processContext.isPauseTaskExecution()) {
// we won't update task status to complete, job monitor will update task status to complete after it complete monitoring for this job id.
return;
}
taskStatus = new TaskStatus(TaskState.COMPLETED);
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
taskStatus.setReason("Successfully handed over job id to job monitor service.");
taskContext.setTaskStatus(taskStatus);
GFacUtils.saveAndPublishTaskStatus(taskContext);
}
Aggregations