1 /* Copyright (c) 2009 Peter Troshin
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
6 * Apache License version 2 as published by the Apache Software Foundation
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
10 * License for more details.
12 * A copy of the license is in apache_license.txt. It is also available here:
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
15 * Any republication or derived work distributed in source code form
16 * must include this copyright and license notice.
18 package compbio.engine.cluster.drmaa;
20 import java.io.IOException;
21 import java.text.NumberFormat;
23 import org.apache.log4j.Logger;
24 import org.ggf.drmaa.DrmaaException;
25 import org.ggf.drmaa.JobInfo;
26 import org.ggf.drmaa.Session;
28 import compbio.engine.Configurator;
29 import compbio.engine.client.Util;
30 import compbio.metadata.JobExecutionException;
31 import compbio.metadata.JobStatus;
33 public class ClusterUtil {
35 private static final Logger log = Logger.getLogger(ClusterUtil.class);
37 public static final NumberFormat CLUSTER_STAT_IN_SEC = NumberFormat
41 CLUSTER_STAT_IN_SEC.setMinimumFractionDigits(4);
44 public static final boolean cancelJob(final String jobId,
45 ClusterSession csession) {
46 assert Util.isValidJobId(jobId);
47 boolean cancelled = true;
48 Session session = csession.getSession();
50 log.info("Job " + jobId + " is successfully cancelled");
51 compbio.engine.client.Util.writeMarker(Configurator.getWorkDirectory(jobId),
53 session.control(ClusterSession.getClusterJobId(jobId).getJobId(),
55 } catch (DrmaaException e) {
57 log.error("Job " + jobId + " cancellation failed!");
58 log.error("Cause: " + e.getLocalizedMessage(), e.getCause());
60 } catch (IOException e) {
62 "Could not read JOBID file to determine cluster jobid for taskid: "
63 + jobId + " Message: " + e.getLocalizedMessage(), e
69 + " has been successfully removed from the cluster engine job list");
70 csession.removeJob(jobId);
75 public static final JobInfo waitForResult(ClusterSession csession,
76 String jobId) throws JobExecutionException {
78 assert Util.isValidJobId(jobId);
80 jinfo = csession.waitForJob(jobId);
81 } catch (DrmaaException e) {
82 log.error(e.getLocalizedMessage(), e.getCause());
83 throw new JobExecutionException(e);
84 } catch (IOException e) {
85 log.error("Could not read JOBID file for job " + jobId
86 + " Message " + e.getMessage(), e.getCause());
87 throw new JobExecutionException(e);
89 // at this point the job has finished
90 csession.removeJob(jobId);