Search in sources :

Example 1 with ProcessStatus

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

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

the class GFacWorker method completeProcess.

private void completeProcess() throws GFacException {
    ProcessStatus status = new ProcessStatus(ProcessState.COMPLETED);
    status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    processContext.setProcessStatus(status);
    GFacUtils.saveAndPublishProcessStatus(processContext);
    sendAck();
    Factory.getGfacContext().removeProcess(processContext.getProcessId());
}
Also used : ProcessStatus(org.apache.airavata.model.status.ProcessStatus)

Example 3 with ProcessStatus

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

the class GFacWorker method cancelProcess.

private void cancelProcess() throws GFacException {
    // do cleanup works before cancel the process.
    ProcessStatus processStatus = new ProcessStatus(ProcessState.CANCELED);
    processStatus.setReason("Process cancellation has been triggered");
    processContext.setProcessStatus(processStatus);
    GFacUtils.saveAndPublishProcessStatus(processContext);
    sendAck();
    Factory.getGfacContext().removeProcess(processContext.getProcessId());
}
Also used : ProcessStatus(org.apache.airavata.model.status.ProcessStatus)

Example 4 with ProcessStatus

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

the class GFacEngineImpl method postProcessing.

/**
 * @param processContext
 * @param recovery
 * @return <code>true</code> if you need to interrupt processing <code>false</code> otherwise.
 * @throws GFacException
 */
private boolean postProcessing(ProcessContext processContext, boolean recovery) throws GFacException {
    ProcessStatus status = new ProcessStatus(ProcessState.POST_PROCESSING);
    status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    processContext.setProcessStatus(status);
    GFacUtils.saveAndPublishProcessStatus(processContext);
    // taskCtx = getEnvCleanupTaskContext(processContext);
    if (processContext.isInterrupted()) {
        GFacUtils.handleProcessInterrupt(processContext);
        return true;
    }
    return false;
}
Also used : ProcessStatus(org.apache.airavata.model.status.ProcessStatus)

Example 5 with ProcessStatus

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

the class GFacEngineImpl method updateProcessFailure.

private void updateProcessFailure(ProcessContext pc, String reason) throws GFacException {
    if (pc == null) {
        throw new GFacException("Can't update process failure, process context is null");
    }
    ProcessStatus status = new ProcessStatus(ProcessState.FAILED);
    status.setReason(reason);
    pc.setProcessStatus(status);
    try {
        GFacUtils.saveAndPublishProcessStatus(pc);
    } catch (GFacException e) {
        log.error("Error while save and publishing process failed status event");
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) ProcessStatus(org.apache.airavata.model.status.ProcessStatus)

Aggregations

ProcessStatus (org.apache.airavata.model.status.ProcessStatus)7 GFacException (org.apache.airavata.gfac.core.GFacException)4 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)2 RegistryException (org.apache.airavata.registry.cpi.RegistryException)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AiravataException (org.apache.airavata.common.exception.AiravataException)1 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)1 TaskContext (org.apache.airavata.gfac.core.context.TaskContext)1 ApplicationInterfaceDescription (org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription)1 StorageResourceDescription (org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription)1 ErrorModel (org.apache.airavata.model.commons.ErrorModel)1 JobModel (org.apache.airavata.model.job.JobModel)1 ProcessModel (org.apache.airavata.model.process.ProcessModel)1 JobStatus (org.apache.airavata.model.status.JobStatus)1 ProcessState (org.apache.airavata.model.status.ProcessState)1 TaskStatus (org.apache.airavata.model.status.TaskStatus)1 DataStageType (org.apache.airavata.model.task.DataStageType)1