Search in sources :

Example 1 with TaskException

use of org.apache.airavata.gfac.core.task.TaskException 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 2 with TaskException

use of org.apache.airavata.gfac.core.task.TaskException in project airavata by apache.

the class DefaultJobSubmissionTask method cancel.

@Override
public JobStatus cancel(TaskContext taskcontext) throws TaskException {
    ProcessContext processContext = taskcontext.getParentProcessContext();
    RemoteCluster remoteCluster = processContext.getJobSubmissionRemoteCluster();
    JobModel jobModel = processContext.getJobModel();
    int retryCount = 0;
    if (jobModel != null) {
        if (processContext.getProcessState() == ProcessState.EXECUTING) {
            while (jobModel.getJobId() == null) {
                log.info("Cancellation pause {} secs until process get jobId", pauseTimeInSec);
                try {
                    Thread.sleep(waitForProcessIdmillis);
                } catch (InterruptedException e) {
                // ignore
                }
            }
        }
        try {
            JobStatus oldJobStatus = remoteCluster.getJobStatus(jobModel.getJobId());
            while (oldJobStatus == null && retryCount <= 5) {
                retryCount++;
                Thread.sleep(retryCount * 1000);
                oldJobStatus = remoteCluster.getJobStatus(jobModel.getJobId());
            }
            if (oldJobStatus != null) {
                oldJobStatus = remoteCluster.cancelJob(jobModel.getJobId());
                return oldJobStatus;
            } else {
                throw new TaskException("Cancel operation failed, Job status couldn't find in resource, JobId " + jobModel.getJobId());
            }
        } catch (GFacException | InterruptedException e) {
            throw new TaskException("Error while cancelling job " + jobModel.getJobId(), e);
        }
    } else {
        throw new TaskException("Couldn't complete cancel operation, JobModel is null in ProcessContext.");
    }
}
Also used : TaskException(org.apache.airavata.gfac.core.task.TaskException) RemoteCluster(org.apache.airavata.gfac.core.cluster.RemoteCluster) JobModel(org.apache.airavata.model.job.JobModel) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext)

Example 3 with TaskException

use of org.apache.airavata.gfac.core.task.TaskException in project airavata by apache.

the class SimpleOrchestratorImpl method getInputDataStagingTask.

private TaskModel getInputDataStagingTask(ProcessModel processModel, InputDataObjectType processInput, String gatewayId) throws RegistryException, TException, AppCatalogException, TaskException, AiravataException {
    // create new task model for this task
    TaskModel taskModel = new TaskModel();
    taskModel.setParentProcessId(processModel.getProcessId());
    taskModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
    taskModel.setLastUpdateTime(taskModel.getCreationTime());
    TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskModel.setTaskStatuses(Arrays.asList(taskStatus));
    taskModel.setTaskType(TaskTypes.DATA_STAGING);
    // create data staging sub task model
    DataStagingTaskModel submodel = new DataStagingTaskModel();
    ComputeResourceDescription computeResource = orchestratorContext.getRegistry().getAppCatalog().getComputeResource().getComputeResource(processModel.getComputeResourceId());
    String workingDir = OrchestratorUtils.getScratchLocation(orchestratorContext, processModel, gatewayId) + File.separator + processModel.getProcessId() + File.separator;
    URI destination = null;
    try {
        DataMovementProtocol dataMovementProtocol = OrchestratorUtils.getPreferredDataMovementProtocol(orchestratorContext, processModel, gatewayId);
        String loginUserName = OrchestratorUtils.getLoginUserName(orchestratorContext, processModel, gatewayId);
        destination = new URI(dataMovementProtocol.name(), loginUserName, computeResource.getHostName(), OrchestratorUtils.getDataMovementPort(orchestratorContext, processModel, gatewayId), workingDir, null, null);
    } catch (URISyntaxException e) {
        throw new TaskException("Error while constructing destination file URI");
    }
    submodel.setType(DataStageType.INPUT);
    submodel.setSource(processInput.getValue());
    submodel.setProcessInput(processInput);
    submodel.setDestination(destination.toString());
    taskModel.setSubTaskModel(ThriftUtils.serializeThriftObject(submodel));
    return taskModel;
}
Also used : TaskException(org.apache.airavata.gfac.core.task.TaskException) DataMovementProtocol(org.apache.airavata.model.data.movement.DataMovementProtocol) URISyntaxException(java.net.URISyntaxException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URI(java.net.URI)

Example 4 with TaskException

use of org.apache.airavata.gfac.core.task.TaskException in project airavata by apache.

the class SimpleOrchestratorImpl method getOutputDataStagingTask.

private TaskModel getOutputDataStagingTask(ProcessModel processModel, OutputDataObjectType processOutput, String gatewayId) throws RegistryException, TException, AiravataException {
    try {
        // create new task model for this task
        TaskModel taskModel = new TaskModel();
        taskModel.setParentProcessId(processModel.getProcessId());
        taskModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
        taskModel.setLastUpdateTime(taskModel.getCreationTime());
        TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
        taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        taskModel.setTaskStatuses(Arrays.asList(taskStatus));
        taskModel.setTaskType(TaskTypes.DATA_STAGING);
        ComputeResourceDescription computeResource = orchestratorContext.getRegistry().getAppCatalog().getComputeResource().getComputeResource(processModel.getComputeResourceId());
        String workingDir = OrchestratorUtils.getScratchLocation(orchestratorContext, processModel, gatewayId) + File.separator + processModel.getProcessId() + File.separator;
        DataStagingTaskModel submodel = new DataStagingTaskModel();
        DataMovementProtocol dataMovementProtocol = OrchestratorUtils.getPreferredDataMovementProtocol(orchestratorContext, processModel, gatewayId);
        URI source = null;
        try {
            String loginUserName = OrchestratorUtils.getLoginUserName(orchestratorContext, processModel, gatewayId);
            if (processOutput != null) {
                submodel.setType(DataStageType.OUPUT);
                submodel.setProcessOutput(processOutput);
                source = new URI(dataMovementProtocol.name(), loginUserName, computeResource.getHostName(), OrchestratorUtils.getDataMovementPort(orchestratorContext, processModel, gatewayId), workingDir + processOutput.getValue(), null, null);
            } else {
                // archive
                submodel.setType(DataStageType.ARCHIVE_OUTPUT);
                source = new URI(dataMovementProtocol.name(), loginUserName, computeResource.getHostName(), OrchestratorUtils.getDataMovementPort(orchestratorContext, processModel, gatewayId), workingDir, null, null);
            }
        } catch (URISyntaxException e) {
            throw new TaskException("Error while constructing source file URI");
        }
        // We don't know destination location at this time, data staging task will set this.
        // because destination is required field we set dummy destination
        submodel.setSource(source.toString());
        // We don't know destination location at this time, data staging task will set this.
        // because destination is required field we set dummy destination
        submodel.setDestination("dummy://temp/file/location");
        taskModel.setSubTaskModel(ThriftUtils.serializeThriftObject(submodel));
        return taskModel;
    } catch (AppCatalogException | TaskException e) {
        throw new RegistryException("Error occurred while retrieving data movement from app catalog", e);
    }
}
Also used : TaskException(org.apache.airavata.gfac.core.task.TaskException) DataMovementProtocol(org.apache.airavata.model.data.movement.DataMovementProtocol) URISyntaxException(java.net.URISyntaxException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URI(java.net.URI)

Example 5 with TaskException

use of org.apache.airavata.gfac.core.task.TaskException in project airavata by apache.

the class SimpleOrchestratorImpl method createAndSaveInputDataStagingTasks.

public List<String> createAndSaveInputDataStagingTasks(ProcessModel processModel, String gatewayId) throws RegistryException, AiravataException {
    List<String> dataStagingTaskIds = new ArrayList<>();
    List<InputDataObjectType> processInputs = processModel.getProcessInputs();
    sortByInputOrder(processInputs);
    if (processInputs != null) {
        for (InputDataObjectType processInput : processInputs) {
            DataType type = processInput.getType();
            switch(type) {
                case STDERR:
                    break;
                case STDOUT:
                    break;
                case URI:
                case URI_COLLECTION:
                    try {
                        TaskModel inputDataStagingTask = getInputDataStagingTask(processModel, processInput, gatewayId);
                        String taskId = (String) orchestratorContext.getRegistry().getExperimentCatalog().add(ExpCatChildDataType.TASK, inputDataStagingTask, processModel.getProcessId());
                        inputDataStagingTask.setTaskId(taskId);
                        dataStagingTaskIds.add(inputDataStagingTask.getTaskId());
                    } catch (TException | AppCatalogException | TaskException e) {
                        throw new RegistryException("Error while serializing data staging sub task model");
                    }
                    break;
                default:
                    // nothing to do
                    break;
            }
        }
    }
    return dataStagingTaskIds;
}
Also used : TException(org.apache.thrift.TException) TaskException(org.apache.airavata.gfac.core.task.TaskException) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) DataType(org.apache.airavata.model.application.io.DataType)

Aggregations

TaskException (org.apache.airavata.gfac.core.task.TaskException)6 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 TaskStatus (org.apache.airavata.model.status.TaskStatus)3 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)2 DataMovementProtocol (org.apache.airavata.model.data.movement.DataMovementProtocol)2 AiravataException (org.apache.airavata.common.exception.AiravataException)1 GFacException (org.apache.airavata.gfac.core.GFacException)1 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)1 ServerInfo (org.apache.airavata.gfac.core.cluster.ServerInfo)1 TaskContext (org.apache.airavata.gfac.core.context.TaskContext)1 JobMonitor (org.apache.airavata.gfac.core.monitor.JobMonitor)1 DataType (org.apache.airavata.model.application.io.DataType)1 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)1 JobModel (org.apache.airavata.model.job.JobModel)1 JobStatus (org.apache.airavata.model.status.JobStatus)1 DataStagingTaskModel (org.apache.airavata.model.task.DataStagingTaskModel)1 EnvironmentSetupTaskModel (org.apache.airavata.model.task.EnvironmentSetupTaskModel)1 JobSubmissionTaskModel (org.apache.airavata.model.task.JobSubmissionTaskModel)1 MonitorTaskModel (org.apache.airavata.model.task.MonitorTaskModel)1