use of org.apache.airavata.model.status.ProcessState in project airavata by apache.
the class DataStageTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
TaskStatus status = new TaskStatus(TaskState.COMPLETED);
if (taskContext.getTaskModel().getTaskType() != TaskTypes.DATA_STAGING) {
status.setState(TaskState.FAILED);
status.setReason("Invalid task call, expected " + TaskTypes.DATA_STAGING.toString() + " but found " + taskContext.getTaskModel().getTaskType().toString());
} else {
try {
DataStagingTaskModel subTaskModel = ((DataStagingTaskModel) taskContext.getSubTaskModel());
URI sourceURI = new URI(subTaskModel.getSource());
URI destinationURI = new URI(subTaskModel.getDestination());
ProcessState processState = taskContext.getParentProcessContext().getProcessState();
if (processState == ProcessState.INPUT_DATA_STAGING) {
/**
* copy local file to compute resource.
*/
taskContext.getParentProcessContext().getDataMovementRemoteCluster().copyTo(sourceURI.getPath(), destinationURI.getPath());
} else if (processState == ProcessState.OUTPUT_DATA_STAGING) {
/**
* copy remote file from compute resource.
*/
taskContext.getParentProcessContext().getDataMovementRemoteCluster().copyFrom(sourceURI.getPath(), destinationURI.getPath());
}
status.setReason("Successfully staged data");
} catch (GFacException e) {
String msg = "Scp attempt failed";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (TException e) {
String msg = "Invalid task invocation";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (URISyntaxException e) {
String msg = "source or destination is not a valid URI";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
}
}
return status;
}
use of org.apache.airavata.model.status.ProcessState in project airavata by apache.
the class DataStreamingTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
ProcessState processState = taskContext.getParentProcessContext().getProcessState();
try {
TaskStatus status = new TaskStatus(TaskState.EXECUTING);
final DataStagingTaskModel subTaskModel = (DataStagingTaskModel) ThriftUtils.getSubTaskModel(taskContext.getTaskModel());
if (processState == ProcessState.OUTPUT_DATA_STAGING) {
OutputDataObjectType processOutput = taskContext.getProcessOutput();
if (processOutput != null && processOutput.getValue() == null) {
log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , file name shouldn't be null", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), processOutput.getName());
status = new TaskStatus(TaskState.FAILED);
if (processOutput.isIsRequired()) {
status.setReason("File name is null, but this output's isRequired bit is not set");
} else {
status.setReason("File name is null");
}
return status;
}
if (processOutput != null) {
if (processOutput.isOutputStreaming()) {
// stream output periodically
ComputationalResourceSchedulingModel resourceSchedule = taskContext.getParentProcessContext().getProcessModel().getProcessResourceSchedule();
int wallTimeLimit = resourceSchedule.getWallTimeLimit();
if (wallTimeLimit > 10) {
int period = wallTimeLimit / 10;
Timer timer = new Timer();
StreamData streamData = new StreamData(userName, hostName, inputPath, taskContext, subTaskModel);
timer.schedule(streamData, 0, 1000 * 60 * period);
status.setState(TaskState.COMPLETED);
}
}
}
}
return null;
} catch (TException e) {
log.error("Error while creating data streaming task", e);
return null;
}
}
use of org.apache.airavata.model.status.ProcessState in project airavata by apache.
the class SCPDataStageTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
TaskStatus status = new TaskStatus(TaskState.EXECUTING);
AuthenticationInfo authenticationInfo = null;
DataStagingTaskModel subTaskModel = null;
String localDataDir = null;
ProcessContext processContext = taskContext.getParentProcessContext();
ProcessState processState = processContext.getProcessState();
try {
subTaskModel = ((DataStagingTaskModel) taskContext.getSubTaskModel());
if (processState == ProcessState.OUTPUT_DATA_STAGING) {
OutputDataObjectType processOutput = taskContext.getProcessOutput();
if (processOutput != null && processOutput.getValue() == null) {
log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , file name shouldn't be null", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), processOutput.getName());
status = new TaskStatus(TaskState.FAILED);
if (processOutput.isIsRequired()) {
status.setReason("File name is null, but this output's isRequired bit is not set");
} else {
status.setReason("File name is null");
}
return status;
}
} else if (processState == ProcessState.INPUT_DATA_STAGING) {
InputDataObjectType processInput = taskContext.getProcessInput();
if (processInput != null && processInput.getValue() == null) {
log.error("expId: {}, processId:{}, taskId: {}:- Couldn't stage file {} , file name shouldn't be null", taskContext.getExperimentId(), taskContext.getProcessId(), taskContext.getTaskId(), processInput.getName());
status = new TaskStatus(TaskState.FAILED);
if (processInput.isIsRequired()) {
status.setReason("File name is null, but this input's isRequired bit is not set");
} else {
status.setReason("File name is null");
}
return status;
}
} else {
status.setState(TaskState.FAILED);
status.setReason("Invalid task invocation, Support " + ProcessState.INPUT_DATA_STAGING.name() + " and " + "" + ProcessState.OUTPUT_DATA_STAGING.name() + " process phases. found " + processState.name());
return status;
}
StorageResourceDescription storageResource = processContext.getStorageResource();
// StoragePreference storagePreference = taskContext.getParentProcessContext().getStoragePreference();
String hostName = null;
if (storageResource != null) {
hostName = storageResource.getHostName();
} else {
throw new GFacException("Storage Resource is null");
}
String inputPath = processContext.getStorageFileSystemRootLocation();
inputPath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator);
// use rsync instead of scp if source and destination host and user name is same.
URI sourceURI = new URI(subTaskModel.getSource());
String fileName = sourceURI.getPath().substring(sourceURI.getPath().lastIndexOf(File.separator) + 1, sourceURI.getPath().length());
Session remoteSession = Factory.getSSHSession(Factory.getComputerResourceSSHKeyAuthentication(processContext), processContext.getComputeResourceServerInfo());
Session storageSession = Factory.getSSHSession(Factory.getStorageSSHKeyAuthentication(processContext), processContext.getStorageResourceServerInfo());
URI destinationURI = null;
if (subTaskModel.getDestination().startsWith("dummy")) {
destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, fileName);
subTaskModel.setDestination(destinationURI.toString());
} else {
destinationURI = new URI(subTaskModel.getDestination());
}
if (sourceURI.getHost().equalsIgnoreCase(destinationURI.getHost()) && sourceURI.getUserInfo().equalsIgnoreCase(destinationURI.getUserInfo())) {
localDataCopy(taskContext, sourceURI, destinationURI);
status.setState(TaskState.COMPLETED);
status.setReason("Locally copied file using 'cp' command ");
return status;
}
status = new TaskStatus(TaskState.COMPLETED);
// Wildcard for file name. Has to find the correct name.
if (fileName.contains("*")) {
String destParentPath = (new File(destinationURI.getPath())).getParentFile().getPath();
String sourceParentPath = (new File(sourceURI.getPath())).getParentFile().getPath();
List<String> fileNames = taskContext.getParentProcessContext().getDataMovementRemoteCluster().getFileNameFromExtension(fileName, sourceParentPath, remoteSession);
ExperimentCatalog experimentCatalog = processContext.getExperimentCatalog();
String experimentId = processContext.getExperimentId();
String processId = processContext.getProcessId();
OutputDataObjectType processOutput = taskContext.getProcessOutput();
for (int i = 0; i < fileNames.size(); i++) {
String temp = fileNames.get(i);
if (temp != null && temp != "") {
fileName = temp;
}
if (destParentPath.endsWith(File.separator)) {
destinationURI = new URI(destParentPath + fileName);
} else {
destinationURI = new URI(destParentPath + File.separator + fileName);
}
// Wildcard support is only enabled for output data staging
if (processState == ProcessState.OUTPUT_DATA_STAGING) {
processOutput.setName(fileName);
experimentCatalog.add(ExpCatChildDataType.EXPERIMENT_OUTPUT, Arrays.asList(processOutput), experimentId);
experimentCatalog.add(ExpCatChildDataType.PROCESS_OUTPUT, Arrays.asList(processOutput), processId);
taskContext.setProcessOutput(processOutput);
makeDir(taskContext, destinationURI);
// TODO - save updated subtask model with new destination
outputDataStaging(taskContext, remoteSession, sourceURI, storageSession, destinationURI);
status.setReason("Successfully staged output data");
}
}
if (processState == ProcessState.OUTPUT_DATA_STAGING) {
status.setReason("Successfully staged output data");
} else {
status.setReason("Wildcard support is only enabled for output data staging");
}
} else {
if (processState == ProcessState.INPUT_DATA_STAGING) {
inputDataStaging(taskContext, storageSession, sourceURI, remoteSession, destinationURI);
status.setReason("Successfully staged input data");
} else if (processState == ProcessState.OUTPUT_DATA_STAGING) {
makeDir(taskContext, destinationURI);
// TODO - save updated subtask model with new destination
outputDataStaging(taskContext, remoteSession, sourceURI, storageSession, destinationURI);
status.setReason("Successfully staged output data");
}
}
} catch (TException e) {
String msg = "Couldn't create subTask model thrift model";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
return status;
} catch (ApplicationSettingsException | FileNotFoundException e) {
String msg = "Failed while reading credentials";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (URISyntaxException e) {
String msg = "Source or destination uri is not correct source : " + subTaskModel.getSource() + ", " + "destination : " + subTaskModel.getDestination();
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (CredentialStoreException e) {
String msg = "Storage authentication issue, could be invalid credential token";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (AiravataException e) {
String msg = "Error while creating ssh session with client";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (JSchException | IOException e) {
String msg = "Failed to do scp with client";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (RegistryException | GFacException e) {
String msg = "Data staging failed";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
}
return status;
}
use of org.apache.airavata.model.status.ProcessState in project airavata by apache.
the class WorkflowInterpreter method handleProcessStatusChangeEvent.
/* synchronized void handleTaskOutputChangeEvent(ProcessStatusChangeEvent taskOutputChangeEvent) {
String taskId = taskOutputChangeEvent.getTaskIdentity().getTaskId();
log.debug("Task Output changed event received for workflow node : " +
taskOutputChangeEvent.getTaskIdentity().getWorkflowNodeId() + ", task : " + taskId);
WorkflowNode workflowNode = processingQueue.get(taskId);
Set<WorkflowNode> tempWfNodeSet = new HashSet<>();
if (workflowNode != null) {
if (workflowNode instanceof ApplicationNode) {
ApplicationNode applicationNode = (ApplicationNode) workflowNode;
// Workflow node can have one to many output ports and each output port can have one to many links
for (OutPort outPort : applicationNode.getOutputPorts()) {
for (OutputDataObjectType outputDataObjectType : taskOutputChangeEvent.getOutput()) {
if (outPort.getOutputObject().getName().equals(outputDataObjectType.getName())) {
outPort.getOutputObject().setValue(outputDataObjectType.getValue());
break;
}
}
for (Edge edge : outPort.getEdges()) {
edge.getToPort().getInputObject().setValue(outPort.getOutputObject().getValue());
if (edge.getToPort().getNode().isReady()) {
addToReadyQueue(edge.getToPort().getNode());
}
}
}
addToCompleteQueue(applicationNode);
log.debug("removed task from processing queue : " + taskId);
}
try {
processReadyList();
} catch (Exception e) {
log.error("Error while processing ready workflow nodes", e);
continueWorkflow = false;
}
}
}*/
void handleProcessStatusChangeEvent(ProcessStatusChangeEvent processStatusChangeEvent) {
ProcessState processState = processStatusChangeEvent.getState();
ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity();
String processId = processIdentity.getProcessId();
ApplicationNode applicationNode = (ApplicationNode) processingQueue.get(processId);
if (applicationNode != null) {
ComponentState state = applicationNode.getState();
switch(processState) {
case CREATED:
case VALIDATED:
case STARTED:
break;
case CONFIGURING_WORKSPACE:
case PRE_PROCESSING:
case INPUT_DATA_STAGING:
case EXECUTING:
case OUTPUT_DATA_STAGING:
case POST_PROCESSING:
state = ComponentState.RUNNING;
break;
case COMPLETED:
state = ComponentState.COMPLETED;
// FIXME: read output form registry and set it to node outputport then continue to next application.
break;
case FAILED:
state = ComponentState.FAILED;
// FIXME: fail workflow.
break;
case CANCELED:
case CANCELLING:
state = ComponentState.CANCELED;
// FIXME: cancel workflow.
break;
default:
break;
}
if (state != applicationNode.getState()) {
try {
updateWorkflowNodeStatus(applicationNode, new ComponentStatus(state));
} catch (RegistryException e) {
log.error("Error! Couldn't update new application state to registry. nodeInstanceId : {} " + applicationNode.getId() + " status to: " + applicationNode.getState().toString(), e);
}
}
}
}
use of org.apache.airavata.model.status.ProcessState in project airavata by apache.
the class GFacWorker method run.
@Override
public void run() {
try {
ProcessState processState = processContext.getProcessState();
switch(processState) {
case CREATED:
case VALIDATED:
case STARTED:
executeProcess();
break;
case PRE_PROCESSING:
case CONFIGURING_WORKSPACE:
case INPUT_DATA_STAGING:
case EXECUTING:
case MONITORING:
case OUTPUT_DATA_STAGING:
case POST_PROCESSING:
if (continueTaskFlow) {
continueTaskExecution();
} else {
recoverProcess();
}
break;
case COMPLETED:
completeProcess();
break;
case CANCELLING:
cancelProcess();
break;
case CANCELED:
// TODO - implement cancel scenario
break;
case FAILED:
// TODO - implement failed scenario
break;
default:
throw new GFacException("process Id : " + processId + " Couldn't identify process type");
}
if (processContext.isCancel()) {
processState = processContext.getProcessState();
switch(processState) {
case MONITORING:
case EXECUTING:
// don't send ack if the process is in MONITORING or EXECUTING states, wait until cancel email comes to airavata
break;
case CANCELLING:
cancelProcess();
break;
default:
sendAck();
Factory.getGfacContext().removeProcess(processContext.getProcessId());
break;
}
}
} catch (GFacException e) {
log.error("GFac Worker throws an exception", e);
ProcessStatus status = new ProcessStatus(ProcessState.FAILED);
status.setReason(e.getMessage());
status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
processContext.setProcessStatus(status);
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
ErrorModel errorModel = new ErrorModel();
errorModel.setUserFriendlyMessage("GFac Worker throws an exception");
errorModel.setActualErrorMessage(errors.toString());
errorModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
try {
GFacUtils.saveAndPublishProcessStatus(processContext);
GFacUtils.saveExperimentError(processContext, errorModel);
GFacUtils.saveProcessError(processContext, errorModel);
} catch (GFacException e1) {
log.error("expId: {}, processId: {} :- Couldn't save and publish process status {}", processContext.getExperimentId(), processContext.getProcessId(), processContext.getProcessState());
}
sendAck();
}
}
Aggregations