001: /**
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found at $PEGASUS_HOME/GTPL or
004: * http://www.globus.org/toolkit/download/license.html.
005: * This notice must appear in redistributions of this file
006: * with or without modification.
007: *
008: * Redistributions of this Software, with or without modification, must reproduce
009: * the GTPL in:
010: * (1) the Software, or
011: * (2) the Documentation or
012: * some other similar material which is provided with the Software (if any).
013: *
014: * Copyright 1999-2004
015: * University of Chicago and The University of Southern California.
016: * All rights reserved.
017: */package org.griphyn.cPlanner.classes;
018:
019: /**
020: * This is a data class that is used to store information about a jobmanager and
021: * the information that it reports about a remote pool.
022: *
023: * <p>
024: * The various attributes that can be associated with the the server are
025: * displayed in the following table.
026: *
027: * <p>
028: * <table border="1">
029: * <tr align="left"><th>Attribute Name</th><th>Attribute Description</th></tr>
030: * <tr align="left"><th>url</th>
031: * <td>the url string pointing to the jobmanager.</td>
032: * </tr>
033: * <tr align="left"><th>universe</th>
034: * <td>the VDS universe that is associated with this job. Can be transfer or
035: * vanilla or any other user defined type.</td>
036: * </tr>
037: * <tr align="left"><th>jobamanager type</th>
038: * <td>remote scheduler type to which the jobmanager talks to.</td>
039: * </tr>
040: * <tr align="left"><th>idle nodes</th>
041: * <td>the number of idle nodes on the remote resource.</td>
042: * </tr>
043: * <tr align="left"><th>total nodes</th>
044: * <td>the total number of nodes on the remote resource.</td>
045: * </tr>
046: * <tr align="left"><th>free memory</th>
047: * <td>the free memory.</td>
048: * </tr>
049: * <tr align="left"><th>total memory</th>
050: * <td>the total memory</td>
051: * </tr>
052: * <tr align="left"><th>jobs in queue</th>
053: * <td>the number of jobs in the queue on the remote scheduler.</td>
054: * </tr>
055: * <tr align="left"><th>running jobs</th>
056: * <td>the number of jobs currently running on the remote site.</td>
057: * </tr>
058: * <tr align="left"><th>max count</th>
059: * <td>the maximum number of jobs that can be run.</td>
060: * </tr>
061: * <tr align="left"><th>max cpu time</th>
062: * <td>the max walltime for the jobs on the remote resource.</td>
063: * </tr>
064: * <tr align="left"><th>os type/th>
065: * <td>the operating system type of the remote machines to which the jobmanager
066: * talks to.</td>
067: * </tr>
068: * <tr align="left"><th>architecture type</th>
069: * <td>the architecture type of the remote machines to which the jobmanager
070: * talks to.</td>
071: * </tr>
072: * </table>
073: *
074: * @author Gaurang Mehta gmehta@isi.edu
075: * @author Karan Vahi vahi@isi.edu
076: *
077: * @version $Revision: 360 $
078: */
079: public class JobManager {
080:
081: /**
082: * Array storing the names of the attributes that are stored with the
083: * jobmanager.
084: */
085: public static final String JOBMANAGERINFO[] = { "url", "universe",
086: "globus-version", "type", "idle-nodes", "total-nodes",
087: "free-mem", "total-mem", "jobs-in-queue", "running-jobs",
088: "max-count", "max-cpu-time", "os", "arch" };
089:
090: /**
091: * The jobmanager type associated with the compute jobs.
092: */
093: public static final String VANILLA_JOBMANAGER_TYPE = "vanilla";
094:
095: /**
096: * The jobmanager type associated with the transfer jobs.
097: */
098: public static final String FORK_JOBMANAGER_TYPE = "transfer";
099:
100: /**
101: * The constant to be passed to the accessor functions to get or set the url.
102: */
103: public static final int URL = 0;
104:
105: /**
106: * The constant to be passed to the accessor functions to get or set the
107: * universe.
108: */
109: public static final int UNIVERSE = 1;
110:
111: /**
112: * The constant to be passed to the accessor functions to get or set the
113: * globus version.
114: */
115: public static final int GLOBUS_VERSION = 2;
116:
117: /**
118: * The constant to be passed to the accessor functions to get or set the
119: * jobmanager type.
120: */
121: public static final int JOBMANAGER_TYPE = 3;
122:
123: /**
124: * The constant to be passed to the accessor functions to get or set the
125: * idle nodes.
126: */
127: public static final int IDLE_NODES = 4;
128:
129: /**
130: * The constant to be passed to the accessor functions to get or set the total
131: * number of nodes.
132: */
133: public static final int TOTAL_NODES = 5;
134:
135: /**
136: * The constant to be passed to the accessor functions to get or set the free
137: * memory .
138: */
139: public static final int FREE_MEM = 6;
140:
141: /**
142: * The constant to be passed to the accessor functions to get or set the
143: * total memory.
144: */
145: public static final int TOTAL_MEM = 7;
146:
147: /**
148: * The constant to be passed to the accessor functions to get or set the
149: * number of the jobs in the queue attribute.
150: */
151: public static final int JOBS_IN_QUEUE = 8;
152:
153: /**
154: * The constant to be passed to the accessor functions to get or set the
155: * number of running jobs attribute.
156: */
157: public static final int RUNNING_JOBS = 9;
158:
159: /**
160: * The constant to be passed to the accessor functions to get or set the
161: * maximum number of jobs that can be in the queue.
162: */
163: public static final int MAX_COUNT = 10;
164:
165: /**
166: * The constant to be passed to the accessor functions to get or set the
167: * maxwalltime for the jobs.
168: */
169: public static final int MAX_CPU_TIME = 11;
170:
171: /**
172: * The constant to be passed to the accessor functions to get or set the
173: * operating system type of the remote machines to which the jobmanager talks
174: * to.
175: */
176: public static final int OS_TYPE = 12;
177:
178: /**
179: * The constant to be passed to the accessor functions to get or set the
180: * architecture type of the remote machines to which the jobmanager talks to.
181: */
182: public static final int ARCH_TYPE = 13;
183:
184: /**
185: * The total memory that the jobmanager reports.
186: */
187: private String mTotalMem;
188:
189: /**
190: * The free memory that the jobmanager reports.
191: */
192: private String mFreeMem;
193:
194: /**
195: * The total number of nodes that the jobmanager reports are on the remote
196: * site.
197: */
198: private String mTotalNodes;
199:
200: /**
201: * The total number of idle nodes that the jobmanager reports are on the
202: * remote site.
203: */
204: private String mIdleNodes;
205:
206: /**
207: * The maximum number of jobs that can be running on the remote site.
208: */
209: private String mMaxCount;
210:
211: /**
212: * The max walltime of the jobs that are run on the remote site.
213: */
214: private String mMaxCPUTime;
215:
216: /**
217: * The number of jobs in the remote queue at the remote site.
218: */
219: private String mJobsInQueue;
220:
221: /**
222: * The number of jobs in the remote queue that are running at the remote site.
223: */
224: private String mRunningJobs;
225:
226: /**
227: * The operating system type type of the remote machines to which the
228: * jobmanager talks to.
229: */
230: private String mOSType;
231:
232: /**
233: * The architecture type of the remote machines to which the jobmanager
234: * talks to.
235: */
236: private String mArchType;
237:
238: /**
239: * The type of remote scheduler to which the jobmanager talks to.
240: */
241: private String mJobManagerType;
242:
243: /**
244: * The url to the jobmanager on the remote site.
245: */
246: private String mURL;
247:
248: /**
249: * The VDS universe with which the jobmanager is associated with.
250: */
251: private String mUniverse;
252:
253: /**
254: * The globus version that is installed on the remote site.
255: */
256: private String mGlobusVersion;
257:
258: /**
259: * Default constructor for the class.
260: */
261: public JobManager() {
262: // m_jobmanager_info = new HashMap(14);
263: mTotalMem = null;
264: mFreeMem = null;
265: mTotalNodes = null;
266: mIdleNodes = null;
267: mMaxCount = null;
268: mMaxCPUTime = null;
269: mJobsInQueue = null;
270: mRunningJobs = null;
271: mOSType = null;
272: mArchType = null;
273: mJobManagerType = null;
274: mURL = null;
275: mUniverse = null;
276: mGlobusVersion = null;
277:
278: }
279:
280: /**
281: * Sets an attribute associated with the jobmanager.
282: *
283: * @param key the attribute key, which is one of the predefined keys.
284: * @param value value of the attribute.
285: *
286: */
287: public void setInfo(int key, String value) {
288:
289: switch (key) {
290:
291: case 0:
292: mURL = value == null ? null : new String(value);
293: break;
294:
295: case 1:
296: mUniverse = value == null ? null : new String(value);
297: break;
298:
299: case 2:
300: mGlobusVersion = value == null ? null : new String(
301: new GlobusVersion(value).getGlobusVersion());
302: break;
303:
304: case 3:
305: mJobManagerType = value == null ? null : new String(value);
306: break;
307:
308: case 4:
309: mIdleNodes = value == null ? null : new String(value);
310: break;
311:
312: case 5:
313: mTotalNodes = value == null ? null : new String(value);
314: break;
315:
316: case 6:
317: mFreeMem = value == null ? null : new String(value);
318: break;
319:
320: case 7:
321: mTotalMem = value == null ? null : new String(value);
322: break;
323:
324: case 8:
325: mJobsInQueue = value == null ? null : new String(value);
326: break;
327:
328: case 9:
329: mRunningJobs = value == null ? null : new String(value);
330: break;
331:
332: case 10:
333: mMaxCount = value == null ? null : new String(value);
334: break;
335:
336: case 11:
337: mMaxCPUTime = value == null ? null : new String(value);
338: break;
339:
340: case 12:
341: mOSType = value == null ? null : new String(value);
342: break;
343:
344: case 13:
345: mArchType = value == null ? null : new String(value);
346: break;
347:
348: default:
349: throw new RuntimeException(
350: "Wrong key ="
351: + key
352: + ". Please have one of the prefedefined jobmanager keys");
353: }
354: }
355:
356: /**
357: * Returns the attribute value of a particular attribute of the jobmanager.
358: *
359: * @param key the key/attribute name.
360: *
361: * @return the attribute value
362: */
363: public String getInfo(int key) {
364:
365: switch (key) {
366:
367: case 0:
368: return mURL;
369:
370: case 1:
371: return mUniverse;
372:
373: case 2:
374: return mGlobusVersion;
375:
376: case 3:
377: return mJobManagerType;
378:
379: case 4:
380: return mIdleNodes;
381:
382: case 5:
383: return mTotalNodes;
384:
385: case 6:
386: return mFreeMem;
387:
388: case 7:
389: return mTotalMem;
390:
391: case 8:
392: return mJobsInQueue;
393:
394: case 9:
395: return mRunningJobs;
396:
397: case 10:
398: return mMaxCount;
399:
400: case 11:
401: return mMaxCPUTime;
402:
403: case 12:
404: return mOSType;
405:
406: case 13:
407: return mArchType;
408:
409: default:
410: throw new RuntimeException(
411: "Wrong key="
412: + key
413: + ". Please have one of the prefedefined jobmanager keys");
414: }
415:
416: }
417:
418: /**
419: * Checks if an object is similar to the one referred to by this class.
420: * We compare the primary key to determine if it is the same or not.
421: *
422: * @param o the object to be compared for equality.
423: *
424: * @return true if the primary key (url) match.
425: * else false.
426: */
427: public boolean equals(Object o) {
428: JobManager jm = (JobManager) o;
429: //for the time being only match on url.
430: if (/*this.mUniverse == jm.mUniverse && */
431: this .mURL.equals(jm.mURL)) {
432: return true;
433: }
434: return false;
435: }
436:
437: /**
438: * Returns the textual description of the contents of <code>JobManager</code>
439: * object in the multiline format.
440: *
441: * @return the textual description in multiline format.
442: */
443: public String toMultiLine() {
444: String output = "universe";
445: if (mUniverse != null) {
446: output += " " + mUniverse;
447: }
448: if (mURL != null) {
449: output += " \"" + mURL + "\"";
450: }
451: if (mGlobusVersion != null) {
452: output += " \"" + mGlobusVersion + "\"";
453: }
454: return output;
455: }
456:
457: /**
458: * Returns the textual description of the contents of <code>JobManager</code>
459: * object.
460: *
461: * @return the textual description.
462: */
463: public String toString() {
464: String output = "jobmanager";
465: if (mUniverse != null) {
466: output += " " + mUniverse;
467: }
468: if (mURL != null) {
469: output += " \"" + mURL + "\"";
470: }
471: if (mGlobusVersion != null) {
472: output += " \"" + mGlobusVersion + "\"";
473: }
474: if (mUniverse != null) {
475: output += " " + JOBMANAGERINFO[UNIVERSE] + "=" + mUniverse;
476: }
477: if (mURL != null) {
478: output += " " + JOBMANAGERINFO[URL] + "=" + mURL;
479: }
480: if (mGlobusVersion != null) {
481: output += " " + JOBMANAGERINFO[GLOBUS_VERSION] + "="
482: + mGlobusVersion;
483: }
484: if (mJobManagerType != null) {
485: output += " " + JOBMANAGERINFO[JOBMANAGER_TYPE] + "="
486: + mJobManagerType;
487: }
488: if (mOSType != null) {
489: output += " " + JOBMANAGERINFO[OS_TYPE] + "=" + mOSType;
490: }
491: if (mArchType != null) {
492: output += " " + JOBMANAGERINFO[ARCH_TYPE] + "=" + mArchType;
493: }
494: if (mRunningJobs != null) {
495: output += " " + JOBMANAGERINFO[RUNNING_JOBS] + "="
496: + mRunningJobs;
497: }
498: if (mJobsInQueue != null) {
499: output += " " + JOBMANAGERINFO[JOBS_IN_QUEUE] + "="
500: + mJobsInQueue;
501: }
502: if (mMaxCPUTime != null) {
503: output += " " + JOBMANAGERINFO[MAX_CPU_TIME] + "="
504: + mMaxCPUTime;
505: }
506: if (mMaxCount != null) {
507: output += " " + JOBMANAGERINFO[MAX_COUNT] + "=" + mMaxCount;
508: }
509: if (mTotalNodes != null) {
510: output += " " + JOBMANAGERINFO[TOTAL_NODES] + "="
511: + mTotalNodes;
512: }
513: if (mIdleNodes != null) {
514: output += " " + JOBMANAGERINFO[IDLE_NODES] + "="
515: + mIdleNodes;
516: }
517: if (mTotalMem != null) {
518: output += " " + JOBMANAGERINFO[TOTAL_MEM] + "=" + mTotalMem;
519: }
520: if (mFreeMem != null) {
521: output += " " + JOBMANAGERINFO[FREE_MEM] + "=" + mFreeMem;
522: }
523: output += " )";
524:
525: // System.out.println(output);
526: return output;
527: }
528:
529: /**
530: * Returns the XML description of the contents of <code>JobManager</code>
531: * object.
532: *
533: * @return the xml description.
534: */
535: public String toXML() {
536: String output = "<jobmanager";
537:
538: if (mUniverse != null) {
539: output += " " + JOBMANAGERINFO[UNIVERSE] + "=\""
540: + mUniverse + "\"";
541: }
542: if (mURL != null) {
543: output += " " + JOBMANAGERINFO[URL] + "=\"" + mURL + "\"";
544: }
545: if (mGlobusVersion != null) {
546:
547: GlobusVersion gv = new GlobusVersion(mGlobusVersion);
548: output += " major=\""
549: + gv.getGlobusVersion(GlobusVersion.MAJOR) + "\""
550: + " minor=\""
551: + gv.getGlobusVersion(GlobusVersion.MINOR) + "\""
552: + " patch=\""
553: + gv.getGlobusVersion(GlobusVersion.PATCH) + "\"";
554:
555: }
556: if (mJobManagerType != null) {
557: output += " " + JOBMANAGERINFO[JOBMANAGER_TYPE] + "=\""
558: + mJobManagerType + "\"";
559: }
560: if (mOSType != null) {
561: output += " " + JOBMANAGERINFO[OS_TYPE] + "=\"" + mOSType
562: + "\"";
563: }
564: if (mArchType != null) {
565: output += " " + JOBMANAGERINFO[ARCH_TYPE] + "=\""
566: + mArchType + "\"";
567: }
568: if (mRunningJobs != null) {
569: output += " " + JOBMANAGERINFO[RUNNING_JOBS] + "=\""
570: + mRunningJobs + "\"";
571: }
572: if (mJobsInQueue != null) {
573: output += " " + JOBMANAGERINFO[JOBS_IN_QUEUE] + "=\""
574: + mJobsInQueue + "\"";
575: }
576: if (mMaxCPUTime != null) {
577: output += " " + JOBMANAGERINFO[MAX_CPU_TIME] + "=\""
578: + mMaxCPUTime + "\"";
579: }
580: if (mMaxCount != null) {
581: output += " " + JOBMANAGERINFO[MAX_COUNT] + "=\""
582: + mMaxCount + "\"";
583: }
584: if (mTotalNodes != null) {
585: output += " " + JOBMANAGERINFO[TOTAL_NODES] + "=\""
586: + mTotalNodes + "\"";
587: }
588: if (mIdleNodes != null) {
589: output += " " + JOBMANAGERINFO[IDLE_NODES] + "=\""
590: + mIdleNodes + "\"";
591: }
592: if (mTotalMem != null) {
593: output += " " + JOBMANAGERINFO[TOTAL_MEM] + "=\""
594: + mTotalMem + "\"";
595: }
596: if (mFreeMem != null) {
597: output += " " + JOBMANAGERINFO[FREE_MEM] + "=\"" + mFreeMem
598: + "\"";
599: }
600: output += " />";
601: return output;
602: }
603:
604: }
|