SLA Managed Jobs
Introduction
This guide explains how to run jobs at a managed GRIA Job Jervice. The code is the same as the previous job execution guide with the addition of creating the endpoint reference of an existing SLA and registering it in the client's registry.
This code requires the TutorialHelpers.java class previously discussed, and the job helper class.
The full Java file for SLA managed jobs can be downloaded.
Guide to running jobs at a managed service
Create a TutorialHelpers object and get a ProxyFactory object from it:
TutorialHelpers helpers = new TutorialHelpers();
ProxyFactory proxyFactory = helpers.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));
Now we need to create the EndpointReferenceType object that refers to an SLA. Normally this will be of the form https://host:8443/gria-service-provider-mgt/services/SLAService#40894e10-1932c13d-0119-c3de5974-3518. We also have to set the type of the resource to an SLA:
EndpointReferenceType slaEPR = ConversationID.getEPR(SLA_RESOURCE_ENDPOINT);
ConversationID.setResourceType(slaEPR, SLAResource.SLA_RESOURCE_TYPE);
In the DefaultInvocationEngine the Federation Selector searches through the registry for SLAs in order to match policies returned by managed services. We must add the SLA to the registry so that the Federation Selector can find it and select it:
helpers.getRegistry().registerResource(slaEPR);
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 = SLAManagedJobs.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.stillActive()) {
System.out.print(".");
Thread.sleep(5000);
}
Check to see if the job completed sucessfully:
JobStatus jobStatus = jobConv.checkJob();
if(jobStatus.getExitStatus() != 0) {
// handle the failure
throw new RuntimeException("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));
Clean up resources at the service by destroying the job:
jobConv.destroy();