Search in sources :

Example 1 with GroovyMap

use of org.apache.airavata.gfac.core.GroovyMap 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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JobConfigBean(org.apache.airavata.cloud.aurora.client.bean.JobConfigBean) ResourceBean(org.apache.airavata.cloud.aurora.client.bean.ResourceBean) TaskStatus(org.apache.airavata.model.status.TaskStatus) ProcessBean(org.apache.airavata.cloud.aurora.client.bean.ProcessBean) AuroraThriftClient(org.apache.airavata.cloud.aurora.client.AuroraThriftClient) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobStatus(org.apache.airavata.model.status.JobStatus) GFacException(org.apache.airavata.gfac.core.GFacException) ErrorModel(org.apache.airavata.model.commons.ErrorModel) JobModel(org.apache.airavata.model.job.JobModel) ResponseBean(org.apache.airavata.cloud.aurora.client.bean.ResponseBean) GroovyMap(org.apache.airavata.gfac.core.GroovyMap) JobKeyBean(org.apache.airavata.cloud.aurora.client.bean.JobKeyBean) IdentityBean(org.apache.airavata.cloud.aurora.client.bean.IdentityBean) TaskConfigBean(org.apache.airavata.cloud.aurora.client.bean.TaskConfigBean)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 AuroraThriftClient (org.apache.airavata.cloud.aurora.client.AuroraThriftClient)1 IdentityBean (org.apache.airavata.cloud.aurora.client.bean.IdentityBean)1 JobConfigBean (org.apache.airavata.cloud.aurora.client.bean.JobConfigBean)1 JobKeyBean (org.apache.airavata.cloud.aurora.client.bean.JobKeyBean)1 ProcessBean (org.apache.airavata.cloud.aurora.client.bean.ProcessBean)1 ResourceBean (org.apache.airavata.cloud.aurora.client.bean.ResourceBean)1 ResponseBean (org.apache.airavata.cloud.aurora.client.bean.ResponseBean)1 TaskConfigBean (org.apache.airavata.cloud.aurora.client.bean.TaskConfigBean)1 GFacException (org.apache.airavata.gfac.core.GFacException)1 GroovyMap (org.apache.airavata.gfac.core.GroovyMap)1 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)1 ErrorModel (org.apache.airavata.model.commons.ErrorModel)1 JobModel (org.apache.airavata.model.job.JobModel)1 JobStatus (org.apache.airavata.model.status.JobStatus)1 TaskStatus (org.apache.airavata.model.status.TaskStatus)1