Richard Hierlmeier's Weblog
- All
- General
- Grid Engine
Java DRMAA binding with JavaScript
I visited last week the Open Source Grid Conference in Oakland California. There was one guy who asked if it is possible to use the scripting features of Java 6 for submitting jobs into a Grid Engine cluster.
Java 6 includes a JavaScript engine. The jrunscript tool (comes with jdk6) can be used to run javascripts. For submitting jobs into a Grid Engine cluster I am using the Java DRMAA binding (included into the Grid Engine distribution). However the script requires a correct setup of the environement:
% source $SGE_ROOT/default/common/settings.sh
% SGE_ARCH=`$SGE_ROOT/util/arch`
% export LD_LIBRARY_PATH=$SGE_ROOT/lib/$SGE_ARCH
% jrunscript -cp $SGE_ROOT/lib/drmaa.jar -f <script file>
I used the example of Dan Templetons Java DRMAA tutorial and translated it into JavaScript:
importPackage(org.ggf.drmaa);
importPackage(java.util);
importPackage(java.lang);
var factory = SessionFactory.getFactory();
var session = factory.getSession();
session.init("");
try {
var sgeRoot = System.getenv("SGE_ROOT");
var jt = session.createJobTemplate();
jt.setRemoteCommand(sgeRoot + "/examples/jobs/sleeper.sh");
jt.setJobName("Sleeper");
jt.setArgs(Collections.singletonList("10"));
var jobId = session.runJob(jt);
System.out.println("Job " + jobId + " submitted");
var info = session.wait(jobId, Session.TIMEOUT_WAIT_FOREVER);
System.out.println("Job " + jobId + " has ended");
if (!info.hasExited()) {
System.err.println("Job terminated abnormally");
System.exit(1);
}
var usage = info.getResourceUsage ();
var cpuTime = Double.parseDouble (usage.get ("cpu"));
System.out.println ("===============");
System.out.println ("CPU Time: " + cpuTime);
} finally {
session.exit();
}
To run the script:
% jrunscript -cp $SGE_ROOT/lib/drmaa.jar -f drmaa.jsJob 2 submitted
Job 2 has ended
Job terminated abnormally
%
Posted at 03:09PM May 26, 2008 by rhierlmeier in Grid Engine |