Basic Application Services Java Interface
Using the Data Service
Having added a data service to our repository and created a RemoteDataService object as above, we can invoke a number of operations on it to create new stagers. This Method returns DataConversation proxy object for the Data Stager, the first parameter is a human readable label for the data stager.
DataConversation data = dataService.createStagingArea("My data stager");
Some services are unmanaged (free), whereas managed services require billing information. The method above automatically finds out the policy of the service and will try to find an appropriate billing EndpointReference in your StateRepository to send to the service. With the method below you can specify the billing information to use to use. This could be the endpoint of an SLA.
DataConversation data = dataService.createStagingArea(billingInfo, "My data stager");
To upload data from a DataSource to a stager, use the save method:
DataSource src = new FileDataSource("picture.jpg");
DataHandler inputHandler = new DataHandler(src);
data.save(inputHandler);
Using the Job Service
A job service RemoteJobService can be added to the repository in the same way we added the data service above:
EndpointReference jobServiceEPR = new EndpointReference("https://example.com/services/JobService");
RemoteJobService jobService = repository.getOrCreateObject(RemoteJobService.class, jobServiceEPR);
Creating a job
We can then use the RemoteJobService object to create a processing job (JobConversation):
JobConversation swirl = jobService.createJob("http://it-innovation.soton.ac.uk/grid/imagemagick/swirl","My Swirl Job");
JobConversation swirl = jobService.createJob("http://it-innovation.soton.ac.uk/grid/imagemagick/swirl",billingInfo,"My Swirl Job");
Again here we can specify billing information, or automaticaly choose one from our StateRepository. The first argument to createJob uniquely identifies the application to use (swirl in this case). This is NOT the service provider being used, which is example.com here.
Running the job
Each job has a number of inputs and outputs. These are data stagers, and so input data is set in the same way as data is added to any other stager: using save(local data), copyFrom(another stager), or copyFromURL(an ordinary HTTP or FTP URL).
Here, we'll copy from our existing data stager to the swirl job's input:
swirl.getInputs()[0].copyFrom(data);
Once all the inputs are set we can start the job using submitJob:
swirl.submitJob(null, new String[] {});
The first paramenter is a job description file to be passed to the execution platform. This can include constraints on how long the job should run, for example. If no information needs to be passed, this can be null, as above. The second parameter is a list of arguments to pass to the application. The swirl application doesn't take any arguments, so our array above is empty.
Collecting the results
Wait until the job is complete:
while (swirl.stillActive()) {
// Wait for a bit...
}
Then download the results:
swirl.getOutputs()[0].read(new File("output.jpg"));
Of course, you don't have to download the data to your own machine. You could copy directly from the output of one job to the input of another.
When everything is complete, finish the job:
swirl.finishJob();
