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.cPlanner.classes;
017:
018: /**
019: * A Workflow metrics class that stores the metrics about the workflow.
020: *
021: * @author Karan Vahi
022: * @version $Revision: 319 $
023: */
024: public class WorkflowMetrics extends Data {
025:
026: /**
027: * The total number of jobs in the executable workflow.
028: */
029: private int mNumTotalJobs;
030:
031: /**
032: * The number of compute jobs.
033: */
034: private int mNumComputeJobs;
035:
036: /**
037: * The number of stage in transfer jobs.
038: */
039: private int mNumSITxJobs;
040:
041: /**
042: * The number of stage-out transfer jobs.
043: */
044: private int mNumSOTxJobs;
045:
046: /**
047: * The number of inter-site transfer jobs.
048: */
049: private int mNumInterTxJobs;
050:
051: /**
052: * The number of registration jobs.
053: */
054: private int mNumRegJobs;
055:
056: /**
057: * The number of cleanup jobs.
058: */
059: private int mNumCleanupJobs;
060:
061: /**
062: * The label of the dax.
063: */
064: private String mDAXLabel;
065:
066: /**
067: * The default constructor.
068: */
069: public WorkflowMetrics() {
070: reset();
071: }
072:
073: /**
074: * Resets the internal counters to zero.
075: */
076: public void reset() {
077: mNumTotalJobs = 0;
078: mNumComputeJobs = 0;
079: mNumSITxJobs = 0;
080: mNumSOTxJobs = 0;
081: mNumInterTxJobs = 0;
082: mNumRegJobs = 0;
083: mNumCleanupJobs = 0;
084: }
085:
086: /**
087: * Sets the DAXlabel.
088: *
089: * @param label the dax label
090: */
091: public void setLabel(String label) {
092: mDAXLabel = label;
093: }
094:
095: /**
096: * Returns the DAXlabel.
097: *
098: * @return the dax label
099: */
100: public String getLabel() {
101: return mDAXLabel;
102: }
103:
104: /**
105: * Increment the metrics when on the basis of type of job.
106: *
107: * @param job the job being added.
108: */
109: public void increment(SubInfo job) {
110: //sanity check
111: if (job == null) {
112: return;
113: }
114:
115: //increment the total
116: mNumTotalJobs++;
117:
118: //increment on basis of type of job
119: int type = job.getJobType();
120: switch (type) {
121:
122: //treating compute and staged compute as same
123: case SubInfo.COMPUTE_JOB:
124: case SubInfo.STAGED_COMPUTE_JOB:
125: mNumComputeJobs++;
126: break;
127:
128: case SubInfo.STAGE_IN_JOB:
129: mNumSITxJobs++;
130: break;
131:
132: case SubInfo.STAGE_OUT_JOB:
133: mNumSOTxJobs++;
134: break;
135:
136: case SubInfo.INTER_POOL_JOB:
137: mNumInterTxJobs++;
138: break;
139:
140: case SubInfo.REPLICA_REG_JOB:
141: mNumRegJobs++;
142: break;
143:
144: case SubInfo.CLEANUP_JOB:
145: mNumCleanupJobs++;
146: break;
147: }
148:
149: }
150:
151: /**
152: * Decrement the metrics when on the basis of type of job.
153: *
154: * @param job the job being removed.
155: */
156: public void decrement(SubInfo job) {
157: //sanity check
158: if (job == null) {
159: return;
160: }
161:
162: //increment the total
163: mNumTotalJobs--;
164:
165: //increment on basis of type of job
166: int type = job.getJobType();
167: switch (type) {
168:
169: //treating compute and staged compute as same
170: case SubInfo.COMPUTE_JOB:
171: case SubInfo.STAGED_COMPUTE_JOB:
172: mNumComputeJobs--;
173: break;
174:
175: case SubInfo.STAGE_IN_JOB:
176: mNumSITxJobs--;
177: break;
178:
179: case SubInfo.STAGE_OUT_JOB:
180: mNumSOTxJobs--;
181: break;
182:
183: case SubInfo.INTER_POOL_JOB:
184: mNumInterTxJobs--;
185: break;
186:
187: case SubInfo.REPLICA_REG_JOB:
188: mNumRegJobs--;
189: break;
190:
191: case SubInfo.CLEANUP_JOB:
192: mNumCleanupJobs--;
193: break;
194:
195: }
196:
197: }
198:
199: /**
200: * Returns a textual description of the object.
201: *
202: * @return Object
203: */
204: public String toString() {
205: StringBuffer sb = new StringBuffer();
206:
207: append(sb, "dax-label", this .mDAXLabel);
208: append(sb, "compute-jobs.count", this .mNumComputeJobs);
209: append(sb, "si-jobs.count", this .mNumSITxJobs);
210: append(sb, "so-jobs.count", this .mNumSOTxJobs);
211: append(sb, "inter-jobs.count", this .mNumInterTxJobs);
212: append(sb, "reg-jobs.count", this .mNumRegJobs);
213: append(sb, "cleanup-jobs.count", this .mNumCleanupJobs);
214: append(sb, "total-jobs.count", this .mNumTotalJobs);
215:
216: return sb.toString();
217: }
218:
219: /**
220: * Appends a key=value pair to the StringBuffer.
221: *
222: * @param buffer the StringBuffer that is to be appended to.
223: * @param key the key.
224: * @param value the value.
225: */
226: protected void append(StringBuffer buffer, String key, String value) {
227: buffer.append(key).append(" = ").append(value).append("\n");
228: }
229:
230: /**
231: * Appends a key=value pair to the StringBuffer.
232: *
233: * @param buffer the StringBuffer that is to be appended to.
234: * @param key the key.
235: * @param value the value.
236: */
237: protected void append(StringBuffer buffer, String key, int value) {
238: buffer.append(key).append(" = ").append(value).append("\n");
239: }
240:
241: /**
242: * Returns the clone of the object.
243: *
244: * @return the clone
245: */
246: public Object clone() {
247: WorkflowMetrics wm;
248: try {
249: wm = (WorkflowMetrics) super .clone();
250: } catch (CloneNotSupportedException e) {
251: //somewhere in the hierarch chain clone is not implemented
252: throw new RuntimeException(
253: "Clone not implemented in the base class of "
254: + this.getClass().getName(), e);
255: }
256:
257: wm.mNumCleanupJobs = this.mNumCleanupJobs;
258: wm.mNumComputeJobs = this.mNumComputeJobs;
259: wm.mNumInterTxJobs = this.mNumInterTxJobs;
260: wm.mNumRegJobs = this.mNumRegJobs;
261: wm.mNumSITxJobs = this.mNumSITxJobs;
262: wm.mNumSOTxJobs = this.mNumSOTxJobs;
263: wm.mNumTotalJobs = this.mNumTotalJobs;
264: wm.mDAXLabel = this.mDAXLabel;
265:
266: return wm;
267: }
268:
269: }
|