use of org.apache.airavata.gfac.core.context.ProcessContext in project airavata by apache.
the class ArchiveTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
// implement archive logic with jscp
TaskStatus status = new TaskStatus(TaskState.EXECUTING);
ProcessContext processContext = taskContext.getParentProcessContext();
RemoteCluster remoteCluster = processContext.getJobSubmissionRemoteCluster();
AuthenticationInfo authenticationInfo = null;
DataStagingTaskModel subTaskModel = null;
try {
subTaskModel = (DataStagingTaskModel) ThriftUtils.getSubTaskModel(taskContext.getTaskModel());
} catch (TException e) {
String msg = "Error! Deserialization issue with SubTask 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;
}
try {
StorageResourceDescription storageResource = taskContext.getParentProcessContext().getStorageResource();
if (storageResource != null) {
hostName = storageResource.getHostName();
} else {
throw new GFacException("Storage Resource is null");
}
userName = processContext.getStorageResourceLoginUserName();
inputPath = processContext.getStorageFileSystemRootLocation();
inputPath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator);
status = new TaskStatus(TaskState.COMPLETED);
Session srcSession = Factory.getSSHSession(Factory.getComputerResourceSSHKeyAuthentication(processContext), processContext.getComputeResourceServerInfo());
Session destSession = Factory.getSSHSession(Factory.getStorageSSHKeyAuthentication(processContext), processContext.getStorageResourceServerInfo());
URI sourceURI = new URI(subTaskModel.getSource());
URI destinationURI = null;
String workingDirName = null, path = null;
if (sourceURI.getPath().endsWith("/")) {
path = sourceURI.getPath().substring(0, sourceURI.getPath().length() - 1);
} else {
path = sourceURI.getPath();
}
workingDirName = path.substring(path.lastIndexOf(File.separator) + 1, path.length());
// tar working dir
// cd /Users/syodage/Desktop/temp/.. && tar -cvf path/workingDir.tar temp
String archiveTar = "archive.tar";
String resourceAbsTarFilePath = path + "/" + archiveTar;
CommandInfo commandInfo = new RawCommandInfo("cd " + path + " && tar -cvf " + resourceAbsTarFilePath + " ./* ");
// move tar to storage resource
remoteCluster.execute(commandInfo);
destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, archiveTar);
remoteCluster.scpThirdParty(resourceAbsTarFilePath, srcSession, destinationURI.getPath(), destSession, RemoteCluster.DIRECTION.FROM, true);
// delete tar in remote computer resource
commandInfo = new RawCommandInfo("rm " + resourceAbsTarFilePath);
remoteCluster.execute(commandInfo);
// untar file and delete tar in storage resource
String destPath = destinationURI.getPath();
String destParent = destPath.substring(0, destPath.lastIndexOf("/"));
String storageArchiveDir = "ARCHIVE";
commandInfo = new RawCommandInfo("cd " + destParent + " && mkdir " + storageArchiveDir + " && tar -xvf " + archiveTar + " -C " + storageArchiveDir + " && rm " + archiveTar + " && chmod 755 -R " + storageArchiveDir + "/*");
executeCommand(destSession, commandInfo, new StandardOutReader());
} catch (CredentialStoreException e) {
String msg = "Storage authentication issue, make sure you are passing valid credential token";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
} catch (URISyntaxException | GFacException e) {
String msg = "Error! Archive task failed";
log.error(msg, e);
status.setState(TaskState.FAILED);
status.setReason(msg);
status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
}
return status;
}
use of org.apache.airavata.gfac.core.context.ProcessContext in project airavata by apache.
the class AuroraJobSubmissionTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
// set to completed.
TaskStatus taskStatus = new TaskStatus(TaskState.COMPLETED);
ProcessContext processContext = taskContext.getParentProcessContext();
JobModel jobModel = processContext.getJobModel();
jobModel.setTaskId(taskContext.getTaskId());
String jobIdAndName = "A" + GFacUtils.generateJobName();
jobModel.setJobName(jobIdAndName);
JobStatus jobStatus = new JobStatus();
jobStatus.setJobState(JobState.SUBMITTED);
try {
JobKeyBean jobKey = new JobKeyBean(AuroraUtils.ENVIRONMENT, AuroraUtils.ROLE, jobIdAndName);
IdentityBean owner = new IdentityBean(AuroraUtils.ROLE);
GroovyMap groovyMap = GFacUtils.createGroovyMap(processContext, taskContext);
groovyMap.add(Script.JOB_SUBMITTER_COMMAND, "sh");
String templateFileName = GFacUtils.getTemplateFileName(ResourceJobManagerType.CLOUD);
String script = GFacUtils.generateScript(groovyMap, templateFileName);
Set<ProcessBean> processes = new LinkedHashSet<>();
ProcessBean process_1 = new ProcessBean("main_process", script, false);
processes.add(process_1);
groovyMap.getStringValue(Script.STANDARD_OUT_FILE).ifPresent(stdout -> {
ProcessBean stdOutProcess = new ProcessBean("stdout_copy_process", "cp .logs/main_process/0/stdout " + stdout, false);
processes.add(stdOutProcess);
});
groovyMap.getStringValue(Script.STANDARD_ERROR_FILE).ifPresent(stderr -> {
ProcessBean stdErrProcess = new ProcessBean("stderr_copy_process", "cp .logs/main_process/0/stderr " + stderr, false);
processes.add(stdErrProcess);
});
ResourceBean resources = new ResourceBean(1.5, 512, 512);
TaskConfigBean taskConfig = new TaskConfigBean("Airavata-Aurora-" + jobIdAndName, processes, resources);
JobConfigBean jobConfig = new JobConfigBean(jobKey, owner, taskConfig, AuroraUtils.CLUSTER);
String executorConfigJson = AuroraThriftClientUtil.getExecutorConfigJson(jobConfig);
log.info("Executor Config for Job {} , {}", jobIdAndName, executorConfigJson);
AuroraThriftClient client = AuroraThriftClient.getAuroraThriftClient();
ResponseBean response = client.createJob(jobConfig);
log.info("Response for job {}, {}", jobIdAndName, response);
jobModel.setJobDescription(resources.toString());
jobModel.setJobId(jobIdAndName);
jobStatus.setReason("Successfully Submitted");
jobModel.setJobStatuses(Arrays.asList(jobStatus));
jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
taskContext.getParentProcessContext().setJobModel(jobModel);
GFacUtils.saveJobModel(processContext, jobModel);
GFacUtils.saveJobStatus(processContext, jobModel);
taskStatus.setReason("Successfully submitted job to Aurora");
} catch (Throwable e) {
String msg = "Error occurred while submitting Aurora job";
log.error(msg, e);
taskStatus.setState(TaskState.FAILED);
taskStatus.setReason(msg);
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
ErrorModel errorModel = new ErrorModel();
errorModel.setActualErrorMessage(e.getMessage());
errorModel.setUserFriendlyMessage(msg);
taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
}
taskContext.setTaskStatus(taskStatus);
try {
GFacUtils.saveAndPublishTaskStatus(taskContext);
} catch (GFacException e) {
log.error("Error while saving task status", e);
}
return taskStatus;
}
use of org.apache.airavata.gfac.core.context.ProcessContext in project airavata by apache.
the class GFacUtils method createGroovyMap.
public static GroovyMap createGroovyMap(ProcessContext processContext, TaskContext taskContext) throws GFacException, AppCatalogException, ApplicationSettingsException {
GroovyMap groovyMap = new GroovyMap();
ProcessModel processModel = processContext.getProcessModel();
ResourceJobManager resourceJobManager = getResourceJobManager(processContext);
// set email options and addresses
setMailAddresses(processContext, groovyMap);
groovyMap.add(Script.INPUT_DIR, processContext.getInputDir());
groovyMap.add(Script.OUTPUT_DIR, processContext.getOutputDir());
groovyMap.add(Script.EXECUTABLE_PATH, processContext.getApplicationDeploymentDescription().getExecutablePath());
groovyMap.add(Script.STANDARD_OUT_FILE, processContext.getStdoutLocation());
groovyMap.add(Script.STANDARD_ERROR_FILE, processContext.getStderrLocation());
groovyMap.add(Script.SCRATCH_LOCATION, processContext.getScratchLocation());
groovyMap.add(Script.GATEWAY_ID, processContext.getGatewayId());
groovyMap.add(Script.GATEWAY_USER_NAME, processContext.getProcessModel().getUserName());
groovyMap.add(Script.APPLICATION_NAME, processContext.getApplicationInterfaceDescription().getApplicationName());
groovyMap.add(Script.QUEUE_SPECIFIC_MACROS, processContext.getQueueSpecificMacros());
groovyMap.add(Script.ACCOUNT_STRING, processContext.getAllocationProjectNumber());
groovyMap.add(Script.RESERVATION, processContext.getReservation());
// To make job name alpha numeric
groovyMap.add(Script.JOB_NAME, "A" + String.valueOf(generateJobName()));
groovyMap.add(Script.WORKING_DIR, processContext.getWorkingDir());
List<String> inputValues = getProcessInputValues(processModel.getProcessInputs());
inputValues.addAll(getProcessOutputValues(processModel.getProcessOutputs()));
groovyMap.add(Script.INPUTS, inputValues);
groovyMap.add(Script.USER_NAME, processContext.getJobSubmissionRemoteCluster().getServerInfo().getUserName());
groovyMap.add(Script.SHELL_NAME, "/bin/bash");
// get walltime
if (taskContext != null) {
try {
JobSubmissionTaskModel jobSubmissionTaskModel = ((JobSubmissionTaskModel) taskContext.getSubTaskModel());
if (jobSubmissionTaskModel.getWallTime() > 0) {
groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculator(jobSubmissionTaskModel.getWallTime()));
if (resourceJobManager != null) {
if (resourceJobManager.getResourceJobManagerType().equals(ResourceJobManagerType.LSF)) {
groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculatorForLSF(jobSubmissionTaskModel.getWallTime()));
}
}
}
} catch (TException e) {
log.error("Error while getting job submission sub task model", e);
}
}
// NOTE: Give precedence to data comes with experiment
// qos per queue
String qoS = getQoS(processContext.getQualityOfService(), processContext.getQueueName());
if (qoS != null) {
groovyMap.add(Script.QUALITY_OF_SERVICE, qoS);
}
ComputationalResourceSchedulingModel scheduling = processModel.getProcessResourceSchedule();
if (scheduling != null) {
int totalNodeCount = scheduling.getNodeCount();
int totalCPUCount = scheduling.getTotalCPUCount();
if (isValid(scheduling.getQueueName())) {
groovyMap.add(Script.QUEUE_NAME, scheduling.getQueueName());
}
if (totalNodeCount > 0) {
groovyMap.add(Script.NODES, totalNodeCount);
}
if (totalCPUCount > 0) {
int ppn = totalCPUCount / totalNodeCount;
groovyMap.add(Script.PROCESS_PER_NODE, ppn);
groovyMap.add(Script.CPU_COUNT, totalCPUCount);
}
// if so we ignore scheduling configuration.
if (scheduling.getWallTimeLimit() > 0 && groovyMap.get(Script.MAX_WALL_TIME) == null) {
groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculator(scheduling.getWallTimeLimit()));
if (resourceJobManager != null) {
if (resourceJobManager.getResourceJobManagerType().equals(ResourceJobManagerType.LSF)) {
groovyMap.add(Script.MAX_WALL_TIME, GFacUtils.maxWallTimeCalculatorForLSF(scheduling.getWallTimeLimit()));
}
}
}
if (scheduling.getTotalPhysicalMemory() > 0) {
groovyMap.add(Script.USED_MEM, scheduling.getTotalPhysicalMemory());
}
if (isValid(scheduling.getOverrideLoginUserName())) {
groovyMap.add(Script.USER_NAME, scheduling.getOverrideLoginUserName());
}
if (isValid(scheduling.getOverrideAllocationProjectNumber())) {
groovyMap.add(Script.ACCOUNT_STRING, scheduling.getOverrideAllocationProjectNumber());
}
if (isValid(scheduling.getStaticWorkingDir())) {
groovyMap.add(Script.WORKING_DIR, scheduling.getStaticWorkingDir());
}
} else {
log.error("Task scheduling cannot be null at this point..");
}
ApplicationDeploymentDescription appDepDescription = processContext.getApplicationDeploymentDescription();
List<CommandObject> moduleCmds = appDepDescription.getModuleLoadCmds();
if (moduleCmds != null) {
List<String> modulesCmdCollect = moduleCmds.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> map.getCommand()).collect(Collectors.toList());
groovyMap.add(Script.MODULE_COMMANDS, modulesCmdCollect);
}
List<CommandObject> preJobCommands = appDepDescription.getPreJobCommands();
if (preJobCommands != null) {
List<String> preJobCmdCollect = preJobCommands.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> parseCommands(map.getCommand(), groovyMap)).collect(Collectors.toList());
groovyMap.add(Script.PRE_JOB_COMMANDS, preJobCmdCollect);
}
List<CommandObject> postJobCommands = appDepDescription.getPostJobCommands();
if (postJobCommands != null) {
List<String> postJobCmdCollect = postJobCommands.stream().sorted((e1, e2) -> e1.getCommandOrder() - e2.getCommandOrder()).map(map -> parseCommands(map.getCommand(), groovyMap)).collect(Collectors.toList());
groovyMap.add(Script.POST_JOB_COMMANDS, postJobCmdCollect);
}
ApplicationParallelismType parallelism = appDepDescription.getParallelism();
if (parallelism != null) {
if (parallelism != ApplicationParallelismType.SERIAL) {
Map<ApplicationParallelismType, String> parallelismPrefix = processContext.getResourceJobManager().getParallelismPrefix();
if (parallelismPrefix != null) {
String parallelismCommand = parallelismPrefix.get(parallelism);
if (parallelismCommand != null) {
groovyMap.add(Script.JOB_SUBMITTER_COMMAND, parallelismCommand);
} else {
throw new GFacException("Parallelism prefix is not defined for given parallelism type " + parallelism + ".. Please define the parallelism prefix at App Catalog");
}
}
}
}
return groovyMap;
}
use of org.apache.airavata.gfac.core.context.ProcessContext in project airavata by apache.
the class EmailBasedMonitor method stopMonitor.
@Override
public void stopMonitor(String jobId, boolean runOutflow) {
TaskContext taskContext = jobMonitorMap.remove(jobId);
if (taskContext != null && runOutflow) {
try {
ProcessContext pc = taskContext.getParentProcessContext();
if (taskContext.isCancel()) {
// Moved job status to cancel
JobModel jobModel = pc.getJobModel();
JobStatus newJobStatus = new JobStatus(JobState.CANCELED);
newJobStatus.setReason("Moving job status to cancel, as we didn't see any email from this job " + "for a while after execute job cancel command. This may happen if job was in queued state " + "when we run the cancel command");
jobModel.setJobStatuses(Arrays.asList(newJobStatus));
GFacUtils.saveJobStatus(pc, jobModel);
}
ProcessStatus pStatus = new ProcessStatus(ProcessState.CANCELLING);
pStatus.setReason("Job cancelled");
pc.setProcessStatus(pStatus);
GFacUtils.saveAndPublishProcessStatus(pc);
GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(pc));
} catch (GFacException e) {
log.info("[EJM]: Error while running output tasks", e);
}
}
}
use of org.apache.airavata.gfac.core.context.ProcessContext in project airavata by apache.
the class CancelRequestWatcherImpl method cancelProcess.
private void cancelProcess(int retryAttempt) throws GFacException {
ProcessContext processContext = Factory.getGfacContext().getProcess(processId);
if (processContext != null) {
processContext.setCancel(true);
log.info("expId {}, processId : {}, Cancelling process", experimentId, processId);
Factory.getGFacEngine().cancelProcess(processContext);
} else {
if (retryAttempt < max_retry) {
log.info("expId: {}, Cancel request came for processId {} but couldn't find process context. " + "retry in {} s ", experimentId, processId, retryAttempt * 3);
try {
Thread.sleep(retryAttempt++ * 3000);
} catch (InterruptedException e) {
// ignore we don't care this exception.
}
cancelProcess(retryAttempt);
} else {
log.info("expId: {}, Cancel request came for processId {} but couldn't find process context.", experimentId, processId);
}
}
}
Aggregations