Submitting jobs
Two pieces of good news today.
First, the honorable Charlotte W. Woolard deemed my predicament of having multiple large software projects, a Monday Summer of Code check-in deadline, and a San Francisco move-out date of August 1 worthy of getting excused from a jury.
Which made possible the second piece: job submission, at least in its basic form, is working. Jobs with arguments—but not with stdin or environment settings—can be successfully submitted via XgridDRMAA.
It wasn’t too complicated. In short, this is what happens:
- The client code constructs a job template, as per the DRMAA spec, which includes details of the job like what command to run, what arguments to pass the command, etc.
- The client code then calls
-[DRMAASession runJobWithJobTemplate:error:]. - The
runJobWithJobTemplate:error:method does the fancy work. It first asks the job template instance (which is actually an instance of the subclassXgridDRMAAJobTemplate) for an Xgrid-style job specification dictionary. It passes this on, via Distributed Objects, to a helper method. - The helper method,
submitXgridJobWithSpecification:, submits the job using-[XGController performSubmitJobActionWithJobSpecification:gridIdentifier:], getting back anXGActionMonitorinstance. It runs the run loop on the secondary thread until either failure or success has been recorded. If successful, the job identifier is returned from theresultsdictionary; if not, aNSErrorinstance is generated in theDRMAAErrordomain, encapsulating the BEEP error generated by Xgrid.
(For the record, sometimes I hate how long Objective-C method names are. When I use ObjC, I miss Java. And vice-versa.)
To see it in code, a super-simple OCUnit test (which assumes a working Xgrid setup and valid XgridDRMAA user defaults settings) looks like this:
- (void)testRunSimpleJob
{
[_session begin:nil];
DRMAAJobTemplate *jobTemplate = [_session jobTemplate];
[jobTemplate setRemoteCommand:@"/bin/ps"];
[jobTemplate setJobName:@"testRunSimpleJob"];
NSError *error = nil;
NSString *jobId = [_session runJobWithJobTemplate:jobTemplate error:&error];
STAssertNotNil(jobId, @"job run failed");
if(jobId)
{
NSLog(@"jobId: %@", jobId);
}
else
{
STAssertNotNil(error, @"no error generated on failure");
if(error) NSLog(@"error code: %d", [error code]);
}
[_session end:nil];
}