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.cPlanner.selector.site;
016:
017: import org.griphyn.cPlanner.classes.SubInfo;
018:
019: import org.griphyn.cPlanner.classes.PegasusBag;
020:
021: import org.griphyn.cPlanner.common.LogManager;
022:
023: import java.util.List;
024:
025: /**
026: * A random site selector that maps to a job to a random pool, amongst the subset
027: * of pools where that particular job can be executed.
028: *
029: * @author Karan Vahi
030: * @version $Revision: 298 $
031: */
032:
033: public class Random extends AbstractPerJob {
034:
035: /**
036: * The default constructor. Should not be called. Call the overloaded one.
037: */
038: public Random() {
039: }
040:
041: /**
042: * Initializes the site selector.
043: *
044: * @param bag the bag of objects that is useful for initialization.
045: *
046: */
047: public void initialize(PegasusBag bag) {
048: super .initialize(bag);
049: }
050:
051: /**
052: * Maps a job in the workflow to an execution site.
053: *
054: * @param job the job to be mapped.
055: * @param sites the list of <code>String</code> objects representing the
056: * execution sites that can be used.
057: *
058: */
059: public void mapJob(SubInfo job, List sites) {
060:
061: List rsites = mTCMapper.getSiteList(job.getTXNamespace(), job
062: .getTXName(), job.getTXVersion(), sites);
063:
064: if (rsites == null || rsites.isEmpty()) {
065: job.setSiteHandle(null);
066: } else {
067: job.setSiteHandle(selectRandomSite(rsites));
068: mLogger.log("[Random Selector] Mapped to "
069: + job.getSiteHandle(),
070: LogManager.DEBUG_MESSAGE_LEVEL);
071: }
072: }
073:
074: /**
075: * Returns a brief description of the site selection technique being used.
076: *
077: * @return String
078: */
079: public String description() {
080: String st = "Random Site Selection";
081: return st;
082: }
083:
084: /**
085: * The random selection that selects randomly one of the records returned by
086: * the transformation catalog.
087: *
088: * @param sites List of <code>String</code>objects.
089: *
090: * @return String
091: */
092: private String selectRandomSite(List sites) {
093: double randNo;
094: int noOfRecs = sites.size();
095:
096: //means we have to choose a random location between 0 and (noOfLocs -1)
097: randNo = Math.random() * noOfRecs;
098: int recSelected = new Double(randNo).intValue();
099: /*
100: String message = "Random Site selected is " + (recSelected + 1) +
101: " amongst " + noOfRecs + " possible";
102: mLogger.logMessage(message, 1, false);
103: */
104: return (String) sites.get(recSelected);
105: }
106: }
|