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.js

Job 2 submitted
Job 2 has ended
Job terminated abnormally
%

 


Comments:

Post a Comment:
Comments are closed for this entry.
About

rhierlmeier

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today