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
18 package compbio.engine.cluster.drmaa;
\r
20 import java.io.IOException;
\r
21 import java.text.NumberFormat;
\r
23 import org.apache.log4j.Logger;
\r
24 import org.ggf.drmaa.DrmaaException;
\r
25 import org.ggf.drmaa.JobInfo;
\r
26 import org.ggf.drmaa.Session;
\r
28 import compbio.engine.Configurator;
\r
29 import compbio.engine.client.Util;
\r
30 import compbio.metadata.JobExecutionException;
\r
31 import compbio.metadata.JobStatus;
\r
33 public class ClusterUtil {
\r
35 private static final Logger log = Logger.getLogger(ClusterUtil.class);
\r
37 public static final NumberFormat CLUSTER_STAT_IN_SEC = NumberFormat
\r
41 CLUSTER_STAT_IN_SEC.setMinimumFractionDigits(4);
\r
44 public static final boolean cancelJob(final String jobId,
\r
45 ClusterSession csession) {
\r
46 assert Util.isValidJobId(jobId);
\r
47 boolean cancelled = true;
\r
48 Session session = csession.getSession();
\r
50 log.info("Job " + jobId + " is successfully cancelled");
\r
51 compbio.engine.client.Util.writeMarker(Configurator.getWorkDirectory(jobId),
\r
52 JobStatus.CANCELLED);
\r
53 session.control(ClusterSession.getClusterJobId(jobId).getJobId(),
\r
55 } catch (DrmaaException e) {
\r
57 log.error("Job " + jobId + " cancellation failed!");
\r
58 log.error("Cause: " + e.getLocalizedMessage(), e.getCause());
\r
60 } catch (IOException e) {
\r
62 "Could not read JOBID file to determine cluster jobid for taskid: "
\r
63 + jobId + " Message: " + e.getLocalizedMessage(), e
\r
69 + " has been successfully removed from the cluster engine job list");
\r
70 csession.removeJob(jobId);
\r
75 public static final JobInfo waitForResult(ClusterSession csession,
\r
76 String jobId) throws JobExecutionException {
\r
77 JobInfo jinfo = null;
\r
78 assert Util.isValidJobId(jobId);
\r
80 jinfo = csession.waitForJob(jobId);
\r
81 } catch (DrmaaException e) {
\r
82 log.error(e.getLocalizedMessage(), e.getCause());
\r
83 throw new JobExecutionException(e);
\r
84 } catch (IOException e) {
\r
85 log.error("Could not read JOBID file for job " + jobId
\r
86 + " Message " + e.getMessage(), e.getCause());
\r
87 throw new JobExecutionException(e);
\r
89 // at this point the job has finished
\r
90 csession.removeJob(jobId);
\r