Search in sources :

Example 1 with TaskModel

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

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

use of org.apache.airavata.model.task.TaskModel in project airavata by apache.

the class RegistryServerHandler method getJobStatuses.

/**
 * Get Job Statuses for an Experiment
 * This method to be used when need to get the job status of an Experiment. An experiment may have one or many jobs; there for one or many job statuses may turnup
 *
 * @param airavataExperimentId@return JobStatus
 *                                    Job status (string) for all all the existing jobs for the experiment will be returned in the form of a map
 */
@Override
public Map<String, JobStatus> getJobStatuses(String airavataExperimentId) throws RegistryServiceException, TException {
    try {
        experimentCatalog = RegistryFactory.getDefaultExpCatalog();
        if (!experimentCatalog.isExist(ExperimentCatalogModelType.EXPERIMENT, airavataExperimentId)) {
            logger.error(airavataExperimentId, "Error while retrieving job details, experiment {} doesn't exist.", airavataExperimentId);
            throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system..");
        }
        List<Object> processModels = experimentCatalog.get(ExperimentCatalogModelType.PROCESS, Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId);
        Map<String, JobStatus> jobStatus = new HashMap<String, JobStatus>();
        if (processModels != null && !processModels.isEmpty()) {
            for (Object process : processModels) {
                ProcessModel processModel = (ProcessModel) process;
                List<TaskModel> tasks = processModel.getTasks();
                if (tasks != null && !tasks.isEmpty()) {
                    for (TaskModel task : tasks) {
                        String taskId = task.getTaskId();
                        List<Object> jobs = experimentCatalog.get(ExperimentCatalogModelType.JOB, Constants.FieldConstants.JobConstants.TASK_ID, taskId);
                        if (jobs != null && !jobs.isEmpty()) {
                            for (Object jobObject : jobs) {
                                JobModel jobModel = (JobModel) jobObject;
                                String jobID = jobModel.getJobId();
                                List<JobStatus> status = jobModel.getJobStatuses();
                                if (status != null && status.size() > 0) {
                                    jobStatus.put(jobID, status.get(0));
                                }
                            }
                        }
                    }
                }
            }
        }
        logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId);
        return jobStatus;
    } catch (Exception e) {
        logger.error(airavataExperimentId, "Error while retrieving the job statuses", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) JobStatus(org.apache.airavata.model.status.JobStatus) JobModel(org.apache.airavata.model.job.JobModel) TaskModel(org.apache.airavata.model.task.TaskModel)

Example 4 with TaskModel

use of org.apache.airavata.model.task.TaskModel in project airavata by apache.

the class ExperimentRegistry method getTaskIds.

public List<String> getTaskIds(String fieldName, Object value) throws RegistryException {
    List<String> taskIds = new ArrayList<String>();
    List<TaskModel> tasks = getTaskList(fieldName, value);
    for (TaskModel task : tasks) {
        taskIds.add(task.getTaskId());
    }
    return taskIds;
}
Also used : TaskModel(org.apache.airavata.model.task.TaskModel)

Example 5 with TaskModel

use of org.apache.airavata.model.task.TaskModel in project airavata by apache.

the class ExperimentRegistry method getTaskList.

public List<TaskModel> getTaskList(String fieldName, Object value) throws RegistryException {
    List<TaskModel> tasks = new ArrayList<TaskModel>();
    try {
        if (fieldName.equals(Constants.FieldConstants.TaskConstants.PARENT_PROCESS_ID)) {
            ProcessResource processResource = new ProcessResource();
            processResource.setProcessId((String) value);
            List<TaskResource> resources = processResource.getTaskList();
            for (TaskResource taskResource : resources) {
                TaskModel taskModel = ThriftDataModelConversion.getTaskModel(taskResource);
                tasks.add(taskModel);
            }
            return tasks;
        } else {
            logger.error("Unsupported field name to retrieve task list...");
        }
    } catch (Exception e) {
        logger.error("Error while getting task list...", e);
        throw new RegistryException(e);
    }
    return tasks;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) TaskModel(org.apache.airavata.model.task.TaskModel) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

TaskModel (org.apache.airavata.model.task.TaskModel)11 DataStagingTaskModel (org.apache.airavata.model.task.DataStagingTaskModel)5 EnvironmentSetupTaskModel (org.apache.airavata.model.task.EnvironmentSetupTaskModel)5 JobSubmissionTaskModel (org.apache.airavata.model.task.JobSubmissionTaskModel)5 MonitorTaskModel (org.apache.airavata.model.task.MonitorTaskModel)5 RegistryException (org.apache.airavata.registry.cpi.RegistryException)4 TaskContext (org.apache.airavata.gfac.core.context.TaskContext)3 TaskStatus (org.apache.airavata.model.status.TaskStatus)3 TException (org.apache.thrift.TException)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 GFacException (org.apache.airavata.gfac.core.GFacException)2 JobModel (org.apache.airavata.model.job.JobModel)2 ProcessModel (org.apache.airavata.model.process.ProcessModel)2 JobStatus (org.apache.airavata.model.status.JobStatus)2 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServerInfo (org.apache.airavata.gfac.core.cluster.ServerInfo)1