+++ /dev/null
-/* Copyright (c) 2009 Peter Troshin\r
- * \r
- * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
- * \r
- * This library is free software; you can redistribute it and/or modify it under the terms of the\r
- * Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- * License for more details.\r
- * \r
- * A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-package compbio.engine.cluster.drmaa;\r
-\r
-import java.util.Collections;\r
-import java.util.Iterator;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-\r
-import org.ggf.drmaa.DrmCommunicationException;\r
-import org.ggf.drmaa.DrmaaException;\r
-import org.ggf.drmaa.JobInfo;\r
-import org.ggf.drmaa.JobTemplate;\r
-import org.ggf.drmaa.Session;\r
-import org.ggf.drmaa.SessionFactory;\r
-\r
-class _DrmaaExample {\r
-\r
- private static int NBULKS = 3;\r
- private static int JOB_CHUNK = 8;\r
- private static Session session = null;\r
-\r
- public static void main(String[] args) throws Exception {\r
- String jobPath = args[0];\r
-\r
- SessionFactory factory = SessionFactory.getFactory();\r
-\r
- session = factory.getSession();\r
- session.init(null);\r
-\r
- JobTemplate jt = createJobTemplate(jobPath, 5, true);\r
-\r
- List allJobIds = new LinkedList();\r
- List jobIds = null;\r
- boolean retry = true;\r
-\r
- for (int count = 0; count < NBULKS; count++) {\r
- do {\r
- try {\r
- jobIds = session.runBulkJobs(jt, 1, JOB_CHUNK, 1);\r
- retry = false;\r
- } catch (DrmCommunicationException e) {\r
- System.err.println("runBulkJobs() failed - retry: "\r
- + e.getMessage());\r
-\r
- Thread.sleep(1000);\r
- }\r
- } while (retry);\r
-\r
- allJobIds.addAll(jobIds);\r
-\r
- System.out.println("submitted bulk job with jobids:");\r
-\r
- Iterator i = jobIds.iterator();\r
-\r
- while (i.hasNext()) {\r
- System.out.println("\t \"" + i.next() + "\"");\r
- }\r
- }\r
-\r
- session.deleteJobTemplate(jt);\r
-\r
- /* submit some sequential jobs */\r
- jt = createJobTemplate(jobPath, 5, false);\r
-\r
- String jobId = null;\r
- retry = true;\r
-\r
- for (int count = 0; count < JOB_CHUNK; count++) {\r
- while (retry) {\r
- try {\r
- jobId = session.runJob(jt);\r
- retry = false;\r
- } catch (DrmCommunicationException e) {\r
- System.err.println("runBulkJobs() failed - retry: "\r
- + e.getMessage());\r
-\r
- Thread.sleep(1000);\r
- }\r
- }\r
-\r
- System.out.println("\t \"" + jobId + "\"");\r
- allJobIds.add(jobId);\r
- }\r
-\r
- session.deleteJobTemplate(jt);\r
-\r
- /* synchronize with all jobs */\r
- session.synchronize(allJobIds, Session.TIMEOUT_WAIT_FOREVER, false);\r
- System.out.println("synchronized with all jobs");\r
-\r
- /* wait all those jobs */\r
- Iterator i = allJobIds.iterator();\r
-\r
- while (i.hasNext()) {\r
- JobInfo status = null;\r
- jobId = (String) i.next();\r
-\r
- status = session.wait(jobId, Session.TIMEOUT_WAIT_FOREVER);\r
-\r
- /* report how job finished */\r
- if (status.wasAborted()) {\r
- System.out.println("job \"" + jobId + "\" never ran");\r
- } else if (status.hasExited()) {\r
- System.out.println("job \"" + jobId\r
- + "\" finished regularly with exit status "\r
- + status.getExitStatus());\r
- } else if (status.hasSignaled()) {\r
- System.out.println("job \"" + jobId\r
- + "\" finished due to signal "\r
- + status.getTerminatingSignal());\r
- } else {\r
- System.out.println("job \"" + jobId\r
- + "\" finished with unclear conditions");\r
- }\r
- }\r
- }\r
-\r
- private static JobTemplate createJobTemplate(String jobPath, int seconds,\r
- boolean isBulkJob) throws DrmaaException {\r
- JobTemplate jt = session.createJobTemplate();\r
-\r
- jt.setWorkingDirectory("$drmaa_hd_ph$");\r
- jt.setRemoteCommand(jobPath);\r
- jt.setArgs(Collections.singletonList(Integer.toString(seconds)));\r
- jt.setJoinFiles(true);\r
-\r
- if (!isBulkJob) {\r
- jt.setOutputPath(":$drmaa_hd_ph$/DRMAA_JOB");\r
- } else {\r
- jt.setOutputPath(":$drmaa_hd_ph$/DRMAA_JOB$drmaa_incr_ph$");\r
- }\r
-\r
- return jt;\r
- }\r
-\r
-}\r