1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.engine.cluster.drmaa;
\r
21 import org.apache.log4j.Logger;
\r
22 import org.ggf.drmaa.DrmaaException;
\r
24 import compbio.engine.AsyncExecutor;
\r
25 import compbio.engine.Cleaner;
\r
26 import compbio.engine.Configurator;
\r
27 import compbio.engine.client.ConfiguredExecutable;
\r
28 import compbio.engine.client.EngineUtil;
\r
29 import compbio.metadata.JobSubmissionException;
\r
30 import compbio.metadata.ResultNotAvailableException;
\r
33 * Single cluster job runner class
\r
36 * @version 1.0 August 2009
\r
38 * TODO after call to submitJob() no setters really work as the job
\r
39 * template gets deleted, this needs to be taken into account in this
\r
42 public class AsyncClusterRunner implements AsyncExecutor {
\r
44 private static Logger log = Logger.getLogger(AsyncClusterRunner.class);
\r
47 public String submitJob(ConfiguredExecutable<?> executable) throws JobSubmissionException {
\r
48 ClusterRunner jr = new ClusterRunner(executable);
\r
50 // ignore cluster job id as it could be retrieved from fs
\r
51 return executable.getTaskId();
\r
55 public boolean cancelJob(String jobId) {
\r
56 ClusterSession clustSession = ClusterSession.getInstance();
\r
57 return compbio.engine.cluster.drmaa.ClusterEngineUtil.cancelJob(jobId, clustSession);
\r
61 * This will never return clust.engine.JobStatus.CANCELLED as for sun grid
\r
62 * engine cancelled job is the same as failed. Cancelled jobs needs to be
\r
66 public compbio.metadata.JobStatus getJobStatus(String jobId) {
\r
67 return ClusterRunner.getJobStatus(jobId);
\r
71 public boolean cleanup(String jobId) {
\r
72 String workDir = Configurator.getWorkDirectory(jobId);
\r
73 return Cleaner.deleteAllFiles(workDir);
\r
77 public ConfiguredExecutable<?> getResults(String jobId) throws ResultNotAvailableException {
\r
78 assert EngineUtil.isValidJobId(jobId);
\r
79 ClusterSession csession = ClusterSession.getInstance();
\r
80 ConfiguredExecutable<?> exec;
\r
82 exec = csession.getResults(jobId);
\r
83 } catch (DrmaaException e) {
\r
84 log.error(e.getLocalizedMessage(), e.getCause());
\r
85 throw new ResultNotAvailableException(e);
\r
91 public String getWorkDirectory(String jobId) {
\r
92 return Configurator.getWorkDirectory(jobId);
\r