Personal tools
Document Actions

Job Execution Guide

A guide to show how to execute a job on a GRIA Service

Introduction

This guide demonstrates how to execute a job at a GRIA Job Service.

This code requires the TutorialHelpers.java class previously discussed, and the job helper class.

The full Java file for job execution can be downloaded.

Job Execution Guide

Create a TutorialHelpers object and get a ProxyFactory object from it:

TutorialHelpers tutorialHelpers = new TutorialHelpers();
ProxyFactory proxyFactory = tutorialHelpers.getFactory();

Create a Proxy to the Job Service:

RemoteJobService jobService = proxyFactory.createProxy(ConversationID.getEPR(JOB_SERVICE_ENDPOINT), RemoteJobService.class);

Use the JobHelpers class to create a JSDL job description using the defaults for this type of job:

JobDescription jsdl = JobHelpers.getJobDescription("Job 1",jobService.getApplicationMetadataDetailed(APPLICATION));

Make a remote call to the Job Service to create a job resource using the JSDL we have created:

JobConversation jobConv = jobService.createJobJSDL(jsdl.toXML());

Get Proxy to the inputs and outputs of the job as DataConversation objects:

DataConversation[] inputs = jobConv.getInputs();
DataConversation[] outputs = jobConv.getOutputs();

Upload an input image to the input data stager:

URL url = JobExecution.class.getClassLoader().getResource(INPUT_FILE);
inputs[0].save(new DataHandler(url));

Tell the Job Service to start the job:

jobConv.submitJobJSDL();

Poll the job status until it is done:

while(jobConv.checkJob().getInProgress()) {
System.out.println(".");
Thread.sleep(5000);
}

Check to see if the job completed successfully:

JobStatus jobStatus = jobConv.checkJob();
if(jobStatus.getExitStatus() != 0) {
throw new RuntimeException("Swirl job failed. Here is the log:\n" + jobStatus.getLogText());
}

Read the result of the job from the output stager and save it to a disk:

outputs[0].read(new File(OUTPUT_FILE));
System.out.println("Swirl job completed. Output downloaded to: " + OUTPUT_FILE);

Clean up resources at the service by destroying the job:

jobConv.destroy();
 

Powered by Plone CMS, the Open Source Content Management System