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");
}
}
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.");
}
}
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;
}
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);
}
}
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;
}
Aggregations