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: package org.griphyn.vdl.workflow;
016:
017: import org.griphyn.common.util.Currently;
018: import java.util.*;
019:
020: /**
021: * This class is the container for a Workflow record. The record itself
022: * contains information about the job or jobs that ran.
023: *
024: * @author Jens-S. Vöckler
025: * @author Mike Wilde
026: * @version $Revision: 50 $
027: */
028: public class WorkEntry implements Workflow, Cloneable {
029: /**
030: * primary key: unique workflow identifier.
031: */
032: private long m_id = -1;
033:
034: /**
035: * secondary key, part 1: base directory
036: */
037: private String m_basedir;
038:
039: /**
040: * secondary key, part 2: VO group
041: */
042: private String m_vogroup;
043:
044: /**
045: * secondary key, part 3: workflow label
046: */
047: private String m_label;
048:
049: /**
050: * secondary key, part 4: run directory
051: */
052: private String m_run;
053:
054: /**
055: * workflow creator as an account name.
056: */
057: private String m_creator;
058:
059: /**
060: * workflow creation time as time stamp.
061: */
062: private Date m_ctime;
063:
064: /**
065: * workflow state as integer to represent future, current or past
066: * workflows.
067: */
068: private int m_state;
069:
070: /**
071: * last modification time of workflow state as time stamp.
072: */
073: private Date m_mtime;
074:
075: /**
076: * list of jobs associated with the workflow.
077: */
078: private Map m_jobMap;
079:
080: /**
081: * Creates and returns a copy of this object.
082: * @return a new instance with a deep copy of everything.
083: */
084: public Object clone() {
085: WorkEntry result = new WorkEntry(getID(), getBaseDirectory(),
086: getVOGroup(), getWorkflowLabel(), getRunDirectory());
087: result.setCreator(getCreator());
088: result.setCreationTime(getCreationTime());
089: result.setState(getState());
090: result.setModificationTime(getModificationTime());
091:
092: // now the tricky portion -- deep clone jobs
093: for (Iterator i = iterateJob(); i.hasNext();) {
094: result.addJob((JobStateEntry) ((JobStateEntry) i.next())
095: .clone());
096: }
097: return result;
098: }
099:
100: /**
101: * Default constructor, should not be used.
102: */
103: private WorkEntry() {
104: m_jobMap = new TreeMap();
105: }
106:
107: /**
108: * Constructs another empty class.
109: *
110: * @param id is the workflow primary key
111: */
112: public WorkEntry(long id) {
113: m_jobMap = new TreeMap();
114: m_id = id;
115: }
116:
117: /**
118: * Constructs another empty class.
119: *
120: * @param id is the workflow primary key
121: * @param basedir is the base directory
122: * @param vogroup is the VO group identifier
123: * @param label is the workflow label
124: * @param run is the workflow run directory
125: */
126: public WorkEntry(long id, String basedir, String vogroup,
127: String label, String run) {
128: m_jobMap = new TreeMap();
129: m_id = id;
130: m_basedir = basedir;
131: m_vogroup = vogroup;
132: m_label = label;
133: m_run = run;
134: }
135:
136: /**
137: * Accessor
138: *
139: * @see #setID(long)
140: */
141: public long getID() {
142: return this .m_id;
143: }
144:
145: /**
146: * Accessor.
147: *
148: * @param id
149: * @see #getID()
150: */
151: public void setID(long id) {
152: this .m_id = id;
153: }
154:
155: /**
156: * Accessor
157: *
158: * @see #setBaseDirectory(String)
159: */
160: public String getBaseDirectory() {
161: return this .m_basedir;
162: }
163:
164: /**
165: * Accessor.
166: *
167: * @param basedir
168: * @see #getBaseDirectory()
169: */
170: public void setBaseDirectory(String basedir) {
171: this .m_basedir = basedir;
172: }
173:
174: /**
175: * Accessor
176: *
177: * @see #setVOGroup(String)
178: */
179: public String getVOGroup() {
180: return this .m_vogroup;
181: }
182:
183: /**
184: * Accessor.
185: *
186: * @param vogroup
187: * @see #getVOGroup()
188: */
189: public void setVOGroup(String vogroup) {
190: this .m_vogroup = vogroup;
191: }
192:
193: /**
194: * Accessor
195: *
196: * @see #setWorkflowLabel(String)
197: */
198: public String getWorkflowLabel() {
199: return this .m_label;
200: }
201:
202: /**
203: * Accessor.
204: *
205: * @param label
206: * @see #getWorkflowLabel()
207: */
208: public void setWorkflowLabel(String label) {
209: this .m_label = label;
210: }
211:
212: /**
213: * Accessor
214: *
215: * @see #setRunDirectory(String)
216: */
217: public String getRunDirectory() {
218: return this .m_run;
219: }
220:
221: /**
222: * Accessor.
223: *
224: * @param run
225: * @see #getRunDirectory()
226: */
227: public void setRunDirectory(String run) {
228: this .m_run = run;
229: }
230:
231: /**
232: * Accessor
233: *
234: * @see #setCreator(String)
235: */
236: public String getCreator() {
237: return this .m_creator;
238: }
239:
240: /**
241: * Accessor.
242: *
243: * @param creator
244: * @see #getCreator()
245: */
246: public void setCreator(String creator) {
247: this .m_creator = creator;
248: }
249:
250: /**
251: * Accessor
252: *
253: * @see #setCreationTime(Date)
254: */
255: public Date getCreationTime() {
256: return this .m_ctime;
257: }
258:
259: /**
260: * Accessor.
261: *
262: * @param ctime
263: * @see #getCreationTime()
264: */
265: public void setCreationTime(Date ctime) {
266: this .m_ctime = ctime;
267: }
268:
269: /**
270: * Accessor
271: *
272: * @see #setState(int)
273: */
274: public int getState() {
275: return this .m_state;
276: }
277:
278: /**
279: * Accessor.
280: *
281: * @param state
282: * @see #getState()
283: */
284: public void setState(int state) {
285: this .m_state = state;
286: }
287:
288: /**
289: * Accessor
290: *
291: * @see #setModificationTime(Date)
292: */
293: public Date getModificationTime() {
294: return this .m_mtime;
295: }
296:
297: /**
298: * Accessor.
299: *
300: * @param mtime
301: * @see #getModificationTime()
302: */
303: public void setModificationTime(Date mtime) {
304: this .m_mtime = mtime;
305: }
306:
307: /**
308: * Accessor: Adds a job to the bag of jobs.
309: *
310: * @param job is the job to add.
311: * @see JobStateEntry
312: */
313: public void addJob(JobStateEntry job) {
314: this .m_jobMap.put(job.getID(), job);
315: }
316:
317: /**
318: * Accessor: Obtains an job by the job id.
319: *
320: * @param id is the job identifier in the workflow.
321: * @return a reference to the job of this name.
322: * @see JobStateEntry
323: */
324: public JobStateEntry getJob(String id) {
325: return (JobStateEntry) this .m_jobMap.get(id);
326: }
327:
328: /**
329: * Accessor: Counts the number of jobs in this workflow.
330: *
331: * @return the number of jobs in the internal bag.
332: */
333: public int getJobCount() {
334: return this .m_jobMap.size();
335: }
336:
337: /**
338: * Accessor: A list of all jobs known to this workflow. This list is
339: * read-only.
340: *
341: * @return an array with <code>JobStateEntry</code> elements.
342: * @see JobStateEntry
343: */
344: public java.util.List getJobList() {
345: return Collections.unmodifiableList(new ArrayList(this .m_jobMap
346: .values()));
347: }
348:
349: /**
350: * Accessor: Obtains all jobs references by their id. The map is a
351: * read-only map to avoid modifications outside the API.
352: *
353: * @return a map with all jobs known to this workflow
354: * @see JobStateEntry
355: */
356: public java.util.Map getJobMap() {
357: return Collections.unmodifiableMap(this .m_jobMap);
358: }
359:
360: /**
361: * Accessor: Provides an iterator over the jobs of this workflow.
362: * @return an iterator to walk the <code>JobStateEntry</code> list with.
363: * @see JobStateEntry
364: */
365: public Iterator iterateJob() {
366: return this .m_jobMap.values().iterator();
367: }
368:
369: /**
370: * Accessor: Removes all jobs. Effectively empties the bag.
371: */
372: public void removeAllJob() {
373: this .m_jobMap.clear();
374: }
375:
376: /**
377: * Accessor: Removes a specific job.
378: *
379: * @param name is the job identifier.
380: * @return the object that was removed, or null, if not found.
381: * @see JobStateEntry
382: */
383: public JobStateEntry removeJob(String name) {
384: return (JobStateEntry) this .m_jobMap.remove(name);
385: }
386:
387: /**
388: * Accessor: Adds a new or overwrites an existing actual argument.
389: *
390: * @param job is a new complete job to enter.
391: * @see JobStateEntry
392: */
393: public void setJob(JobStateEntry job) {
394: this .m_jobMap.put(job.getID(), job);
395: }
396:
397: /**
398: * Accessor: Replaces all jobs with the new collection of jobs. Note
399: * that a collection can be anything in a list or set.
400: *
401: * @param jobs is a collection of jobs.
402: * @see JobStateEntry
403: */
404: public void setJob(Collection jobs) {
405: this .m_jobMap.clear();
406: for (Iterator i = jobs.iterator(); i.hasNext();) {
407: JobStateEntry j = (JobStateEntry) i.next();
408: this .m_jobMap.put(j.getID(), j);
409: }
410: }
411:
412: /**
413: * Accessor: Replaces all job mappings with new job mappings.
414: *
415: * @param jobs is a map with job id to job mappings.
416: * @see JobStateEntry
417: */
418: public void setJob(Map jobs) {
419: this .m_jobMap.clear();
420: this .m_jobMap.putAll(jobs);
421: }
422:
423: /**
424: * Constructs a sensible line of all internal data points
425: * @return a line containing all internal data.
426: */
427: public String toString() {
428: String newline = System.getProperty("line.separator", "\r\n");
429: StringBuffer result = new StringBuffer(80 * (1 + m_jobMap
430: .size()));
431:
432: // the workflow stuff
433: result.append(getID()).append('|');
434: result.append(getBaseDirectory()).append('|');
435: result.append(getVOGroup()).append('|');
436: result.append(getWorkflowLabel()).append('|');
437: result.append(getRunDirectory()).append('|');
438: result.append(getCreator()).append('|');
439: ;
440: result.append(Currently.iso8601(false, false, false,
441: getCreationTime()));
442: result.append('|');
443: result.append(Integer.toString(getState())).append('|');
444: ;
445: result.append(Currently.iso8601(false, false, false,
446: getModificationTime()));
447: result.append(newline);
448:
449: // add all jobs with space ahead
450: for (Iterator i = iterateJob(); i.hasNext();) {
451: JobStateEntry j = (JobStateEntry) i.next();
452: result.append(" ").append(j).append(newline);
453: }
454:
455: return result.toString();
456: }
457: }
|