Workflow Tutorial 3 - Cross Domain Orchestration
Cross domain data and job orchestration
Tutorials on how to use the GRIA Client Interface API
Page
7
of
15.
Introduction
The learning objectives for this exercise are:
- Learn how to delegate access to resources across domains.
Step 1:
Create a client proxy to the first remote job service and start a job similar to Exercise 2.StateRepository repository = new MemoryStateRepository();
RemoteJobService jobService1 = (RemoteJobService)
repository.getOrCreateObject(RemoteJobService.class,ConversationID.getEPR(JOB_SERVICE_ENDPOINT1));
JobConversation jobConv1 = jobService1.createJob(APPLICATION1, null, "");
DataConversation[] inputs1 = jobConv1.getInputs();
DataConversation[] outputs1 = jobConv1.getOutputs();
inputs1[0].save(new DataHandler(new FileDataSource(INPUT_FILE)));
jobConv1.submitJob(null, new String[]{});
while(jobConv1.stillActive()) {
Thread.sleep(2000);
}
JobStatus jobStatus = jobConv.checkJob();
if(jobStatus.getExitStatus() != 0) {
// handle the failure
throw new RuntimeException("Swirl job failed. Here is the log:\n" + jobStatus.getLogText());
}
Step 2:
Create the second job at the second Service Provider.RemoteJobService jobService2 = (RemoteJobService) repository.getOrCreateObject(RemoteJobService.class,ConversationID.getEPR(JOB_SERVICE_ENDPOINT2)); JobConversation jobConv2 = jobService2.createJob(APPLICATION2, null, "");
Step 3:
Instead of uploading a file as input for the job, copy the output from Job1. First we must allow access to the output stager by adding a MatchRule on the output resource. The MatchRule states that jobService2 is allowed 'read' access to the output of job 1.DataConversation[] inputs2 = jobConv2.getInputs(); DataConversation[] outputs2 = jobConv2.getOutputs(); outputs1[0].addPolicyRule(new PolicyRule(new MatchPattern(jobService2.getServiceProviderID(),jobService2.getServiceProviderIssuer()),"reader")); inputs2[0].copyFrom(outputs1[0]);
Step 4:
We run the job in the normal way, and then finish both jobs.jobConv2.submitJob(null, new String[]{});
while(jobConv2.stillActive()) {
Thread.sleep(2000);
}
JobStatus jobStatus2 = jobConv2.checkJob();
if(jobStatus2.getExitStatus() != 0) {
// handle the failure
throw new RuntimeException("Job failed. Here is the log:\n" +
jobStatus2.getLogText());
}
outputs2[0].read(new File(OUTPUT_FILE));
jobConv1.finish();
jobConv2.finish();
Completed Java
If you need some help here is a completed version of the java file.
import java.io.File;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import uk.ac.soton.ecs.iam.grid.client.staterepos.MemoryStateRepository;
import uk.ac.soton.ecs.iam.grid.client.staterepos.RemoteJobServiceImpl;
import uk.ac.soton.ecs.iam.grid.comms.client.DataConversation;
import uk.ac.soton.ecs.iam.grid.comms.client.JobConversation;
import uk.ac.soton.ecs.iam.grid.comms.client.RemoteJobService;
import uk.ac.soton.itinnovation.grid.service.types.JobStatus;
import uk.ac.soton.itinnovation.grid.types.ConversationID;
/**
* Simple data and job orchestration example. Edit JOB_SERVICE_ENDPOINT to be the soap endpoint of your job service. */
public class JobExecutionCompleted {
/** Change this Variable to point to your job service!!! */
private static final String JOB_SERVICE_ENDPOINT = "https://....:8443/gria-basic-app-services/services/JobService";
/** The application to execute, identified by its URI */
private static final String APPLICATION = "http://it-innovation.soton.ac.uk/grid/imagemagick/swirl";
/** The input file to upload to the job */
private static final String INPUT_FILE = "data/input-image.png";
/** The ouptut file to download the results to */
private static final String OUTPUT_FILE = "data/output-image.png";
public static void main(String[] args) throws Exception {
RemoteJobService jobService = new RemoteJobServiceImpl(
new MemoryStateRepository(), ConversationID.getEPR(JOB_SERVICE_ENDPOINT));
JobConversation jobConv = jobService.createJob(APPLICATION, null, "");
DataConversation[] inputs = jobConv.getInputs();
DataConversation[] outputs = jobConv.getOutputs();
inputs[0].save(new DataHandler(new FileDataSource(INPUT_FILE)));
jobConv.submitJob(null, new String[] {});
// poll job status
while(jobConv.stillActive()) {
System.out.println(".");
Thread.sleep(2000);
}
JobStatus jobStatus = jobConv.checkJob();
if(jobStatus.getExitStatus() != 0) {
// handle the failure
throw new RuntimeException("Swirl job failed. Here is the log:\n" + jobStatus.getLogText());
}
outputs[0].read(new File(OUTPUT_FILE));
System.out.println("Swirl job completed. Output downloaded to: " + OUTPUT_FILE);
// clean up resources at the server
jobConv.finish();
}
}
