Search in sources :

Example 1 with MonitorTaskModel

use of org.apache.airavata.model.task.MonitorTaskModel 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

AiravataException (org.apache.airavata.common.exception.AiravataException)1 GFacException (org.apache.airavata.gfac.core.GFacException)1 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)1 JobMonitor (org.apache.airavata.gfac.core.monitor.JobMonitor)1 ErrorModel (org.apache.airavata.model.commons.ErrorModel)1 TaskStatus (org.apache.airavata.model.status.TaskStatus)1 MonitorTaskModel (org.apache.airavata.model.task.MonitorTaskModel)1 TException (org.apache.thrift.TException)1