Search in sources :

Example 1 with ProcessBean

use of org.apache.airavata.cloud.aurora.client.bean.ProcessBean 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)

Example 2 with ProcessBean

use of org.apache.airavata.cloud.aurora.client.bean.ProcessBean in project airavata by apache.

the class AuroraClientSample method getRunningJobsList.

/**
 * Gets the job summary.
 *
 * @param client the client
 * @return the job summary
 * @throws Exception
 */
public static void getRunningJobsList(String ownerRole) throws Exception {
    try {
        AuroraThriftClient client = AuroraThriftClient.getAuroraThriftClient();
        ResponseBean response = client.getJobList(ownerRole);
        System.out.println("Response status: " + response.getResponseCode().name());
        if (response instanceof GetJobsResponseBean) {
            GetJobsResponseBean result = (GetJobsResponseBean) response;
            System.out.println(result);
            Set<JobConfigBean> jobConfigs = result.getJobConfigs();
            for (JobConfigBean jobConfig : jobConfigs) {
                System.out.println(jobConfig);
                JobKeyBean jobKey = jobConfig.getJob();
                IdentityBean owner = jobConfig.getOwner();
                TaskConfigBean taskConfig = jobConfig.getTaskConfig();
                Set<ProcessBean> processes = taskConfig.getProcesses();
                System.out.println("\n**** JOB CONFIG ****");
                System.out.println("\t # cluster: " + jobConfig.getCluster());
                System.out.println("\t # instanceCount: " + jobConfig.getInstances());
                System.out.println("\t # isService: " + jobConfig.isService());
                System.out.println("\t\t # priority: " + jobConfig.getPriority());
                System.out.println("\t >> Job Key <<");
                System.out.println("\t\t # name: " + jobKey.getName());
                System.out.println("\t\t # role: " + jobKey.getRole());
                System.out.println("\t\t # environment: " + jobKey.getEnvironment());
                System.out.println("\t >> Identity <<");
                System.out.println("\t\t # owner: " + owner.getUser());
                System.out.println("\t >> Task Config <<");
                System.out.println("\t\t >> Resources <<");
                System.out.println("\t\t\t # numCPUs: " + taskConfig.getResources().getNumCpus());
                System.out.println("\t\t\t # diskMb: " + taskConfig.getResources().getDiskMb());
                System.out.println("\t\t\t # ramMb: " + taskConfig.getResources().getRamMb());
                System.out.println("\t\t >> Processes <<");
                for (ProcessBean process : processes) {
                    System.out.println("\t\t\t ***** PROCESS *****");
                    System.out.println("\t\t\t # name: " + process.getName());
                    System.out.println("\t\t\t # cmdline: " + process.getCmdLine());
                }
            }
        }
    } catch (TException e) {
        e.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) JobConfigBean(org.apache.airavata.cloud.aurora.client.bean.JobConfigBean) GetJobsResponseBean(org.apache.airavata.cloud.aurora.client.bean.GetJobsResponseBean) ResponseBean(org.apache.airavata.cloud.aurora.client.bean.ResponseBean) GetJobsResponseBean(org.apache.airavata.cloud.aurora.client.bean.GetJobsResponseBean) ProcessBean(org.apache.airavata.cloud.aurora.client.bean.ProcessBean) AuroraThriftClient(org.apache.airavata.cloud.aurora.client.AuroraThriftClient) 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)

Example 3 with ProcessBean

use of org.apache.airavata.cloud.aurora.client.bean.ProcessBean in project airavata by apache.

the class AuroraClientSample method createJob.

public static void createJob() throws Exception {
    JobKeyBean jobKey = new JobKeyBean("devel", "centos", "test_job");
    IdentityBean owner = new IdentityBean("centos");
    ProcessBean proc1 = new ProcessBean("process_1", "echo 'hello_world_1'", false);
    ProcessBean proc2 = new ProcessBean("process_2", "echo 'hello_world_2'", false);
    Set<ProcessBean> processes = new HashSet<>();
    processes.add(proc1);
    processes.add(proc2);
    ResourceBean resources = new ResourceBean(0.1, 8, 1);
    TaskConfigBean taskConfig = new TaskConfigBean("task_hello_world", processes, resources);
    JobConfigBean jobConfig = new JobConfigBean(jobKey, owner, taskConfig, "example");
    String executorConfigJson = AuroraThriftClientUtil.getExecutorConfigJson(jobConfig);
    System.out.println(executorConfigJson);
    AuroraThriftClient client = AuroraThriftClient.getAuroraThriftClient();
    ResponseBean response = client.createJob(jobConfig);
    System.out.println(response);
}
Also used : JobConfigBean(org.apache.airavata.cloud.aurora.client.bean.JobConfigBean) ResourceBean(org.apache.airavata.cloud.aurora.client.bean.ResourceBean) ResponseBean(org.apache.airavata.cloud.aurora.client.bean.ResponseBean) GetJobsResponseBean(org.apache.airavata.cloud.aurora.client.bean.GetJobsResponseBean) ProcessBean(org.apache.airavata.cloud.aurora.client.bean.ProcessBean) JobKeyBean(org.apache.airavata.cloud.aurora.client.bean.JobKeyBean) AuroraThriftClient(org.apache.airavata.cloud.aurora.client.AuroraThriftClient) IdentityBean(org.apache.airavata.cloud.aurora.client.bean.IdentityBean) TaskConfigBean(org.apache.airavata.cloud.aurora.client.bean.TaskConfigBean) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with ProcessBean

use of org.apache.airavata.cloud.aurora.client.bean.ProcessBean in project airavata by apache.

the class AuroraClientSample method createAutoDockJob.

public static void createAutoDockJob() throws Exception {
    JobKeyBean jobKey = new JobKeyBean("devel", "centos", "test_autodock");
    IdentityBean owner = new IdentityBean("centos");
    String working_dir = "/home/centos/efs-mount-point/job_" + ThreadLocalRandom.current().nextInt(1, 101) + "/";
    String autodock_path = "/home/centos/efs-mount-point/autodock-vina";
    ProcessBean proc1 = new ProcessBean("process_1", "mkdir " + working_dir, false);
    ProcessBean proc2 = new ProcessBean("process_2", "cp " + autodock_path + "/vina_screenM.sh " + working_dir, false);
    ProcessBean proc3 = new ProcessBean("process_3", "cp " + autodock_path + "/ligand* " + working_dir, false);
    ProcessBean proc4 = new ProcessBean("process_4", "cd " + working_dir + " && sh vina_screenM.sh", false);
    Set<ProcessBean> processes = new LinkedHashSet<>();
    processes.add(proc1);
    processes.add(proc2);
    processes.add(proc3);
    processes.add(proc4);
    ResourceBean resources = new ResourceBean(1.5, 125, 512);
    TaskConfigBean taskConfig = new TaskConfigBean("test_autodock", processes, resources);
    JobConfigBean jobConfig = new JobConfigBean(jobKey, owner, taskConfig, "example");
    String executorConfigJson = AuroraThriftClientUtil.getExecutorConfigJson(jobConfig);
    System.out.println(executorConfigJson);
    AuroraThriftClient client = AuroraThriftClient.getAuroraThriftClient();
    ResponseBean response = client.createJob(jobConfig);
    System.out.println(response);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JobConfigBean(org.apache.airavata.cloud.aurora.client.bean.JobConfigBean) ResourceBean(org.apache.airavata.cloud.aurora.client.bean.ResourceBean) ResponseBean(org.apache.airavata.cloud.aurora.client.bean.ResponseBean) GetJobsResponseBean(org.apache.airavata.cloud.aurora.client.bean.GetJobsResponseBean) ProcessBean(org.apache.airavata.cloud.aurora.client.bean.ProcessBean) JobKeyBean(org.apache.airavata.cloud.aurora.client.bean.JobKeyBean) AuroraThriftClient(org.apache.airavata.cloud.aurora.client.AuroraThriftClient) IdentityBean(org.apache.airavata.cloud.aurora.client.bean.IdentityBean) TaskConfigBean(org.apache.airavata.cloud.aurora.client.bean.TaskConfigBean)

Example 5 with ProcessBean

use of org.apache.airavata.cloud.aurora.client.bean.ProcessBean in project airavata by apache.

the class AuroraThriftClientUtil method getExecutorConfigJson.

/**
 * Gets the executor config json.
 *
 * @param jobConfig the job config
 * @return the executor config json
 * @throws Exception the exception
 */
public static String getExecutorConfigJson(JobConfigBean jobConfig) throws Exception {
    String exeConfigJson = null;
    try {
        // read the executor config json template
        InputStream resourceAsStream = AuroraThriftClientUtil.class.getClassLoader().getResourceAsStream(ServerSettings.getAuroraExecutorConfigTemplateFileName());
        JSONObject exeConfig = new JSONObject(new JSONTokener(resourceAsStream));
        if (exeConfig != null) {
            exeConfig.put("environment", jobConfig.getJob().getEnvironment());
            exeConfig.put("name", jobConfig.getJob().getName());
            exeConfig.put("role", jobConfig.getJob().getRole());
            exeConfig.put("cluster", jobConfig.getCluster());
            exeConfig.put("max_task_failures", jobConfig.getMaxTaskFailures());
            exeConfig.put("service", jobConfig.isService());
            exeConfig.getJSONObject("task").put("name", jobConfig.getTaskConfig().getTaskName());
            // add task resources
            exeConfig.getJSONObject("task").getJSONObject("resources").put("cpu", jobConfig.getTaskConfig().getResources().getNumCpus());
            exeConfig.getJSONObject("task").getJSONObject("resources").put("disk", jobConfig.getTaskConfig().getResources().getDiskMb() * 1024 * 1024);
            exeConfig.getJSONObject("task").getJSONObject("resources").put("ram", jobConfig.getTaskConfig().getResources().getRamMb() * 1024 * 1024);
            // iterate over all processes
            for (ProcessBean process : jobConfig.getTaskConfig().getProcesses()) {
                // add process to constraints
                exeConfig.getJSONObject("task").getJSONArray("constraints").getJSONObject(0).getJSONArray("order").put(process.getName());
                // define the process json
                JSONObject processJson = new JSONObject();
                processJson.put("final", process.isFinal()).put("daemon", process.isDaemon()).put("name", process.getName()).put("ephemeral", process.isEphemeral()).put("max_failures", process.getMax_failures()).put("min_duration", process.getMin_duration()).put("cmdline", process.getCmdLine());
                // add process json to list
                exeConfig.getJSONObject("task").getJSONArray("processes").put(processJson);
            }
            // convert json object to string
            exeConfigJson = exeConfig.toString();
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw ex;
    }
    return exeConfigJson;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ProcessBean(org.apache.airavata.cloud.aurora.client.bean.ProcessBean)

Aggregations

ProcessBean (org.apache.airavata.cloud.aurora.client.bean.ProcessBean)5 AuroraThriftClient (org.apache.airavata.cloud.aurora.client.AuroraThriftClient)4 IdentityBean (org.apache.airavata.cloud.aurora.client.bean.IdentityBean)4 JobConfigBean (org.apache.airavata.cloud.aurora.client.bean.JobConfigBean)4 JobKeyBean (org.apache.airavata.cloud.aurora.client.bean.JobKeyBean)4 ResponseBean (org.apache.airavata.cloud.aurora.client.bean.ResponseBean)4 TaskConfigBean (org.apache.airavata.cloud.aurora.client.bean.TaskConfigBean)4 LinkedHashSet (java.util.LinkedHashSet)3 GetJobsResponseBean (org.apache.airavata.cloud.aurora.client.bean.GetJobsResponseBean)3 ResourceBean (org.apache.airavata.cloud.aurora.client.bean.ResourceBean)3 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)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 TException (org.apache.thrift.TException)1