Search in sources :

Example 1 with JobMonitor

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;
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) EmailBasedMonitor(org.apache.airavata.gfac.monitor.email.EmailBasedMonitor) AuroraJobMonitor(org.apache.airavata.gfac.monitor.cloud.AuroraJobMonitor) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) AuroraJobMonitor(org.apache.airavata.gfac.monitor.cloud.AuroraJobMonitor)

Example 2 with 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");
    }
}
Also used : JobStatus(org.apache.airavata.model.status.JobStatus) TaskException(org.apache.airavata.gfac.core.task.TaskException) GFacException(org.apache.airavata.gfac.core.GFacException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 3 with JobMonitor

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);
}
Also used : TException(org.apache.thrift.TException) GFacException(org.apache.airavata.gfac.core.GFacException) ErrorModel(org.apache.airavata.model.commons.ErrorModel) TaskStatus(org.apache.airavata.model.status.TaskStatus) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) AiravataException(org.apache.airavata.common.exception.AiravataException)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)3 JobMonitor (org.apache.airavata.gfac.core.monitor.JobMonitor)3 AiravataException (org.apache.airavata.common.exception.AiravataException)2 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)2 TaskException (org.apache.airavata.gfac.core.task.TaskException)1 AuroraJobMonitor (org.apache.airavata.gfac.monitor.cloud.AuroraJobMonitor)1 EmailBasedMonitor (org.apache.airavata.gfac.monitor.email.EmailBasedMonitor)1 ErrorModel (org.apache.airavata.model.commons.ErrorModel)1 JobStatus (org.apache.airavata.model.status.JobStatus)1 TaskStatus (org.apache.airavata.model.status.TaskStatus)1 MonitorTaskModel (org.apache.airavata.model.task.MonitorTaskModel)1 TException (org.apache.thrift.TException)1