Search in sources :

Example 1 with TaskStatus

use of org.apache.airavata.model.status.TaskStatus in project airavata by apache.

the class GFacEngineImpl method outputDataStaging.

/**
 * @param taskContext
 * @param recovery
 * @return <code>true</code> if process execution interrupted , <code>false</code> otherwise.
 * @throws GFacException
 */
private boolean outputDataStaging(TaskContext taskContext, boolean recovery, boolean isArchive) throws GFacException {
    TaskStatus taskStatus = new TaskStatus(TaskState.EXECUTING);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
    ProcessContext processContext = taskContext.getParentProcessContext();
    Task dMoveTask = null;
    if (isArchive) {
        dMoveTask = Factory.getArchiveTask();
    } else {
        dMoveTask = Factory.getDataMovementTask(processContext.getDataMovementProtocol());
    }
    if (null == dMoveTask) {
        throw new GFacException("Unsupported security protocol, Airavata doesn't support " + processContext.getDataMovementProtocol() + " protocol yet.");
    }
    taskStatus = executeTask(taskContext, dMoveTask, recovery);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
    if (taskStatus.getState() == TaskState.FAILED) {
        log.error("expId: {}, processId: {}, taskId: {} type: {},:- output staging failed, " + "reason:" + " {}", taskContext.getParentProcessContext().getExperimentId(), taskContext.getParentProcessContext().getProcessId(), taskContext.getTaskId(), dMoveTask.getType().name(), taskStatus.getReason());
        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(" :- Output 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);
    }
    return false;
}
Also used : DataStreamingTask(org.apache.airavata.gfac.impl.task.DataStreamingTask) Task(org.apache.airavata.gfac.core.task.Task) JobSubmissionTask(org.apache.airavata.gfac.core.task.JobSubmissionTask) EnvironmentSetupTask(org.apache.airavata.gfac.impl.task.EnvironmentSetupTask) 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)

Example 2 with TaskStatus

use of org.apache.airavata.model.status.TaskStatus in project airavata by apache.

the class GFacEngineImpl method getJobSubmissionTaskContext.

private TaskContext getJobSubmissionTaskContext(ProcessContext processContext) throws GFacException {
    TaskContext taskCtx = new TaskContext();
    taskCtx.setParentProcessContext(processContext);
    TaskModel taskModel = new TaskModel();
    taskModel.setParentProcessId(processContext.getProcessId());
    taskModel.setCreationTime(new Date().getTime());
    taskModel.setLastUpdateTime(taskModel.getCreationTime());
    TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskModel.setTaskStatuses(Arrays.asList(taskStatus));
    taskModel.setTaskType(TaskTypes.JOB_SUBMISSION);
    taskCtx.setTaskModel(taskModel);
    return taskCtx;
}
Also used : TaskContext(org.apache.airavata.gfac.core.context.TaskContext) TaskStatus(org.apache.airavata.model.status.TaskStatus) EnvironmentSetupTaskModel(org.apache.airavata.model.task.EnvironmentSetupTaskModel) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) TaskModel(org.apache.airavata.model.task.TaskModel) Date(java.util.Date)

Example 3 with TaskStatus

use of org.apache.airavata.model.status.TaskStatus in project airavata by apache.

the class GFacEngineImpl method inputDataStaging.

private boolean inputDataStaging(TaskContext taskContext, boolean recover) throws GFacException, TException {
    TaskStatus taskStatus = new TaskStatus(TaskState.EXECUTING);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
    ProcessContext processContext = taskContext.getParentProcessContext();
    // handle URI_COLLECTION input data type
    Task dMoveTask = Factory.getDataMovementTask(processContext.getDataMovementProtocol());
    if (null == dMoveTask) {
        throw new GFacException("Unsupported security protocol, Airavata doesn't support " + processContext.getDataMovementProtocol() + " protocol yet.");
    }
    if (taskContext.getProcessInput().getType() == DataType.URI_COLLECTION) {
        String values = taskContext.getProcessInput().getValue();
        String[] multiple_inputs = values.split(GFacConstants.MULTIPLE_INPUTS_SPLITTER);
        DataStagingTaskModel subTaskModel = (DataStagingTaskModel) taskContext.getSubTaskModel();
        for (String input : multiple_inputs) {
            taskContext.getProcessInput().setValue(input);
            subTaskModel.setSource(input);
            taskStatus = executeTask(taskContext, dMoveTask, false);
        }
        taskContext.getProcessInput().setValue(values);
    } else {
        taskStatus = executeTask(taskContext, dMoveTask, false);
    }
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
    checkFailures(taskContext, taskStatus, dMoveTask);
    return false;
}
Also used : DataStreamingTask(org.apache.airavata.gfac.impl.task.DataStreamingTask) Task(org.apache.airavata.gfac.core.task.Task) JobSubmissionTask(org.apache.airavata.gfac.core.task.JobSubmissionTask) EnvironmentSetupTask(org.apache.airavata.gfac.impl.task.EnvironmentSetupTask) GFacException(org.apache.airavata.gfac.core.GFacException) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) TaskStatus(org.apache.airavata.model.status.TaskStatus) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext)

Example 4 with TaskStatus

use of org.apache.airavata.model.status.TaskStatus in project airavata by apache.

the class GFacEngineImpl method executeTaskListFrom.

private void executeTaskListFrom(ProcessContext processContext, String startingTaskId) throws GFacException {
    // checkpoint
    if (processContext.isInterrupted() && processContext.getProcessState() != ProcessState.MONITORING) {
        GFacUtils.handleProcessInterrupt(processContext);
        return;
    }
    List<TaskModel> taskList = processContext.getTaskList();
    Map<String, TaskModel> taskMap = processContext.getTaskMap();
    boolean fastForward = true;
    for (String taskId : processContext.getTaskExecutionOrder()) {
        if (fastForward) {
            if (taskId.equalsIgnoreCase(startingTaskId)) {
                fastForward = false;
            } else {
                continue;
            }
        }
        TaskModel taskModel = taskMap.get(taskId);
        processContext.setCurrentExecutingTaskModel(taskModel);
        TaskTypes taskType = taskModel.getTaskType();
        TaskContext taskContext = getTaskContext(processContext);
        taskContext.setTaskModel(taskModel);
        ProcessStatus status = null;
        switch(taskType) {
            case ENV_SETUP:
                status = new ProcessStatus(ProcessState.CONFIGURING_WORKSPACE);
                status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                processContext.setProcessStatus(status);
                GFacUtils.saveAndPublishProcessStatus(processContext);
                // checkpoint
                if (processContext.isInterrupted()) {
                    GFacUtils.handleProcessInterrupt(processContext);
                    return;
                }
                configureWorkspace(taskContext, processContext.isRecovery());
                // checkpoint
                if (processContext.isInterrupted()) {
                    GFacUtils.handleProcessInterrupt(processContext);
                    return;
                }
                break;
            case DATA_STAGING:
                try {
                    // checkpoint
                    if (processContext.isInterrupted()) {
                        GFacUtils.handleProcessInterrupt(processContext);
                        return;
                    }
                    DataStagingTaskModel subTaskModel = (DataStagingTaskModel) taskContext.getSubTaskModel();
                    DataStageType type = subTaskModel.getType();
                    switch(type) {
                        case INPUT:
                            status = new ProcessStatus(ProcessState.INPUT_DATA_STAGING);
                            status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                            processContext.setProcessStatus(status);
                            GFacUtils.saveAndPublishProcessStatus(processContext);
                            taskContext.setProcessInput(subTaskModel.getProcessInput());
                            inputDataStaging(taskContext, processContext.isRecovery());
                            break;
                        case OUPUT:
                            status = new ProcessStatus(ProcessState.OUTPUT_DATA_STAGING);
                            status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                            processContext.setProcessStatus(status);
                            GFacUtils.saveAndPublishProcessStatus(processContext);
                            taskContext.setProcessOutput(subTaskModel.getProcessOutput());
                            outputDataStaging(taskContext, processContext.isRecovery(), false);
                            break;
                        case ARCHIVE_OUTPUT:
                            status = new ProcessStatus(ProcessState.OUTPUT_DATA_STAGING);
                            status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                            processContext.setProcessStatus(status);
                            GFacUtils.saveAndPublishProcessStatus(processContext);
                            outputDataStaging(taskContext, processContext.isRecovery(), true);
                            break;
                    }
                    // checkpoint
                    if (processContext.isInterrupted()) {
                        GFacUtils.handleProcessInterrupt(processContext);
                        return;
                    }
                } catch (TException e) {
                    throw new GFacException(e);
                }
                break;
            case JOB_SUBMISSION:
                // checkpoint
                if (processContext.isInterrupted()) {
                    GFacUtils.handleProcessInterrupt(processContext);
                    return;
                }
                status = new ProcessStatus(ProcessState.EXECUTING);
                status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                processContext.setProcessStatus(status);
                GFacUtils.saveAndPublishProcessStatus(processContext);
                executeJobSubmission(taskContext, processContext.isRecovery());
                // Don't put any checkpoint in between JobSubmission and Monitoring tasks
                JobStatus jobStatus = processContext.getJobModel().getJobStatuses().get(0);
                if (jobStatus != null && (jobStatus.getJobState() == JobState.SUBMITTED || jobStatus.getJobState() == JobState.QUEUED || jobStatus.getJobState() == JobState.ACTIVE)) {
                    List<OutputDataObjectType> processOutputs = processContext.getProcessModel().getProcessOutputs();
                    if (processOutputs != null && !processOutputs.isEmpty()) {
                        for (OutputDataObjectType output : processOutputs) {
                            try {
                                if (output.isOutputStreaming()) {
                                    TaskModel streamingTaskModel = new TaskModel();
                                    streamingTaskModel.setTaskType(TaskTypes.OUTPUT_FETCHING);
                                    streamingTaskModel.setTaskStatuses(Arrays.asList(new TaskStatus(TaskState.CREATED)));
                                    streamingTaskModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
                                    streamingTaskModel.setParentProcessId(processContext.getProcessId());
                                    TaskContext streamingTaskContext = getTaskContext(processContext);
                                    DataStagingTaskModel submodel = new DataStagingTaskModel();
                                    submodel.setType(DataStageType.OUPUT);
                                    submodel.setProcessOutput(output);
                                    URI source = new URI(processContext.getDataMovementProtocol().name(), processContext.getComputeResourceLoginUserName(), processContext.getComputeResourceDescription().getHostName(), 22, processContext.getWorkingDir() + output.getValue(), null, null);
                                    submodel.setSource(source.getPath());
                                    submodel.setDestination("dummy://temp/file/location");
                                    streamingTaskModel.setSubTaskModel(ThriftUtils.serializeThriftObject(submodel));
                                    String streamTaskId = (String) processContext.getExperimentCatalog().add(ExpCatChildDataType.TASK, streamingTaskModel, processContext.getProcessId());
                                    streamingTaskModel.setTaskId(streamTaskId);
                                    streamingTaskContext.setTaskModel(streamingTaskModel);
                                    executeDataStreaming(streamingTaskContext, processContext.isRecovery());
                                }
                            } catch (URISyntaxException | TException | RegistryException e) {
                                log.error("Error while streaming output " + output.getValue());
                            }
                        }
                    }
                }
                break;
            case MONITORING:
                status = new ProcessStatus(ProcessState.MONITORING);
                status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                processContext.setProcessStatus(status);
                GFacUtils.saveAndPublishProcessStatus(processContext);
                executeJobMonitoring(taskContext, processContext.isRecovery());
                break;
            case ENV_CLEANUP:
                // TODO implement environment clean up task logic
                break;
            default:
                throw new GFacException("Unsupported Task type");
        }
        if (processContext.isPauseTaskExecution()) {
            // If any task put processContext to wait, the same task must continue processContext execution.
            return;
        }
    }
    processContext.setComplete(true);
}
Also used : TException(org.apache.thrift.TException) TaskContext(org.apache.airavata.gfac.core.context.TaskContext) ProcessStatus(org.apache.airavata.model.status.ProcessStatus) URISyntaxException(java.net.URISyntaxException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URI(java.net.URI) RegistryException(org.apache.airavata.registry.cpi.RegistryException) DataStageType(org.apache.airavata.model.task.DataStageType) JobStatus(org.apache.airavata.model.status.JobStatus) GFacException(org.apache.airavata.gfac.core.GFacException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) TaskTypes(org.apache.airavata.model.task.TaskTypes) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) EnvironmentSetupTaskModel(org.apache.airavata.model.task.EnvironmentSetupTaskModel) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) TaskModel(org.apache.airavata.model.task.TaskModel)

Example 5 with TaskStatus

use of org.apache.airavata.model.status.TaskStatus 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

TaskStatus (org.apache.airavata.model.status.TaskStatus)22 GFacException (org.apache.airavata.gfac.core.GFacException)13 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)11 ErrorModel (org.apache.airavata.model.commons.ErrorModel)10 URISyntaxException (java.net.URISyntaxException)9 TException (org.apache.thrift.TException)9 DataStagingTaskModel (org.apache.airavata.model.task.DataStagingTaskModel)8 URI (java.net.URI)7 TaskException (org.apache.airavata.gfac.core.task.TaskException)5 JobStatus (org.apache.airavata.model.status.JobStatus)5 IOException (java.io.IOException)4 AiravataException (org.apache.airavata.common.exception.AiravataException)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)4 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)4 JobSubmissionTask (org.apache.airavata.gfac.core.task.JobSubmissionTask)4 DataStreamingTask (org.apache.airavata.gfac.impl.task.DataStreamingTask)4 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)4 JobModel (org.apache.airavata.model.job.JobModel)4 EnvironmentSetupTaskModel (org.apache.airavata.model.task.EnvironmentSetupTaskModel)4