001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.directive;
017:
018: import java.io.*;
019: import org.griphyn.common.util.VDSProperties;
020: import org.griphyn.vdl.workflow.*;
021:
022: /**
023: *
024: * A <code>WorkflowJob</code> object defines the state of a job within a Workflow
025: *
026: * @author Mike Wilde
027: * @author Eric Gilbert
028: * @version $Revision: 50 $
029: *
030: * @see org.griphyn.vdl.toolkit.VDLc
031: */
032:
033: public class WorkflowJob {
034:
035: /* Class Variables */
036:
037: public static final int MAXJOBS = 100000;
038: public static WorkflowJob[] jobs = new WorkflowJob[MAXJOBS];
039: public static int njobs;
040:
041: public static String wfjobsCmd = "/home/dscheftn/vds/bin/vds-WorkflowJob-script-wfjobs";
042:
043: /* Instance Variables */
044:
045: /* db fields
046:
047: select * from wf_jobstate;
048:
049: wfid | jobid | state | mtime | site
050: ------+----------+---------------------+------------------------+-------------
051: 2 | ID000001 | POST_SCRIPT_SUCCESS | 2005-08-21 15:55:10-05 | terminable
052: 4 | ID000001 | PRE_SCRIPT_FAILURE | 2005-08-24 15:51:11-05 |
053: 5 | ID000001 | POST_SCRIPT_SUCCESS | 2005-08-24 16:23:43-05 | terminable
054: 6 | ID000001 | JOB_RELEASED | 2005-08-24 17:26:59-05 |
055: */
056:
057: public String wfid;
058: public String jobid;
059: public String state;
060: public String mtime;
061: public String site;
062:
063: /* Class Methods */
064:
065: public static boolean refresh() {
066: Process p;
067: int rc;
068: Reader is;
069: StringBuffer sb = new StringBuffer();
070: char[] b = new char[100000];
071: int n;
072:
073: /* Run status command to get job states */
074:
075: try {
076: p = Runtime.getRuntime().exec(wfjobsCmd);
077:
078: InputStream out = p.getInputStream();
079: InputStreamReader r = new InputStreamReader(out);
080: BufferedReader in = new BufferedReader(r);
081:
082: String line;
083: njobs = 0;
084:
085: while ((line = in.readLine()) != null) {
086: WorkflowJob j = new WorkflowJob();
087: String[] t = line.split("\\|");
088: int nt = t.length;
089: if (nt > 1)
090: j.wfid = t[1];
091: if (nt > 2)
092: j.jobid = t[2];
093: if (nt > 3)
094: j.state = t[3];
095: if (nt > 4)
096: j.mtime = t[4];
097: if (nt > 5)
098: j.site = t[5];
099: if (njobs < MAXJOBS) {
100: jobs[njobs++] = j;
101: } else {
102: return false;
103: }
104: }
105:
106: rc = p.waitFor();
107:
108: return true;
109:
110: } catch (Exception e) {
111: System.out.println("WorkflowJob.refresh: Exception: "
112: + e.toString());
113: return false;
114: }
115: }
116:
117: /* Instance Methods */
118:
119: public String asStatusString() {
120: return "jobid=" + jobid + " wfid=" + wfid + " state=" + state
121: + " mtime=" + mtime + " site=" + site;
122: }
123: }
|