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.common.catalog.transformation;
017:
018: import org.griphyn.cPlanner.classes.TCMap;
019: import org.griphyn.cPlanner.common.LogManager;
020: import org.griphyn.cPlanner.common.PegasusProperties;
021: import org.griphyn.cPlanner.poolinfo.PoolInfoProvider;
022: import org.griphyn.cPlanner.poolinfo.PoolMode;
023: import org.griphyn.common.catalog.TransformationCatalog;
024: import org.griphyn.common.util.DynamicLoader;
025: import org.griphyn.common.util.Separator;
026:
027: import java.util.ArrayList;
028: import java.util.List;
029: import java.util.Map;
030:
031: /**
032: * This is an interface for generating valid TC maps which will be used for
033: * executable staging. The interface sort of access as an accessor for Pegasus
034: * to the transformation catalog. The map ends up being built as and when the
035: * query for a particular lfn is made to it.
036: *
037: * @author Gaurang Mehta
038: * @version $Revision: 50 $
039: */
040: public abstract class Mapper {
041:
042: /**
043: * The name of the package where the implementing classes reside.
044: */
045: public static final String PACKAGE_NAME = "org.griphyn.common.catalog.transformation.mapper";
046:
047: /**
048: * The handle to the tranformation catalog.
049: */
050: protected TransformationCatalog mTCHandle;
051:
052: /**
053: * The handle to the RIC.
054: */
055: protected PoolInfoProvider mPoolHandle;
056:
057: /**
058: * Handle to Pegasus Properties
059: */
060: protected PegasusProperties mProps;
061:
062: /**
063: * Handle to the TCMap
064: */
065: protected TCMap mTCMap = null;
066:
067: /**
068: * Handle to the logger.
069: */
070: protected LogManager mLogger;
071:
072: /**
073: * Loads the implementing class corresponding to the mode specified by the user
074: * at runtime in the properties file.
075: *
076: * @param className The name of the class that implements the mode. It is the
077: * name of the class, not the complete name with package. That
078: * is added by itself.
079: *
080: * @return Mapper
081: */
082: public static Mapper loadTCMapper(String className) {
083:
084: //prepend the package name
085: className = PACKAGE_NAME + "." + className;
086:
087: //try loading the class dynamically
088: Mapper ss = null;
089: DynamicLoader dl = new DynamicLoader(className);
090: try {
091: Object argList[] = new Object[0];
092: ss = (Mapper) dl.instantiate(argList);
093: } catch (Exception e) {
094: System.err.println(dl.convertException(e));
095: System.exit(1);
096: }
097:
098: return ss;
099: }
100:
101: /**
102: * The private constructor.
103: */
104: protected Mapper() {
105: mLogger = LogManager.getInstance();
106: mTCHandle = TCMode.loadInstance();
107: mProps = PegasusProperties.getInstance();
108: mTCMap = new TCMap();
109: String mPoolClass = PoolMode.getImplementingClass(mProps
110: .getPoolMode());
111: String mPoolFile = mProps.getPoolFile();
112: mPoolHandle = PoolMode.loadPoolInstance(mPoolClass, mPoolFile,
113: PoolMode.SINGLETON_LOAD);
114:
115: }
116:
117: /**
118: * This method returns a Map of compute sites to List of
119: * TransformationCatalogEntry objects that are valid for that site.
120: *
121: * @param namespace the namespace of the transformation.
122: * @param name the name of the transformation.
123: * @param version the version of the transformation.
124: * @param siteids the sites for which you want the map.
125: *
126: * @return Map Key=String SiteId , Values = List of TransformationCatalogEntry
127: * object. Returns null if no entries are found.
128: */
129: public abstract Map getSiteMap(String namespace, String name,
130: String version, List siteids);
131:
132: /**
133: * Returns the TCMapper Mode.
134: *
135: * @return String
136: */
137: public abstract String getMode();
138:
139: /**
140: * This method returns a List of TransformationCatalog Objects valid for a
141: * particular transformation and for a particular compute site
142: *
143: * @param namespace the namespace of the transformation.
144: * @param name the name of the transformation.
145: * @param version the version of the transformation.
146: * @param siteid the compute site for which you want the List.
147: * @return List Returns null if no entries are found.
148: */
149: public List getTCList(String namespace, String name,
150: String version, String siteid) {
151: List siteids = new ArrayList(1);
152: List tcentries = null;
153: String lfn = Separator.combine(namespace, name, version);
154: siteids.add(siteid);
155:
156: if (getSiteMap(namespace, name, version, siteids) != null) {
157: tcentries = mTCMap.getSiteTCEntries(lfn, siteid);
158: }
159: return tcentries;
160: }
161:
162: /**
163: * Returns a list of sites that are valid sites for a given lfn and a list of sites.
164: *
165: * @param namespace the namespace of the transformation.
166: * @param name the name of the transformation.
167: * @param version the version of the transformation.
168: * @param siteids the list of sites on which the transformation is to be checked.
169: *
170: * @return List
171: */
172: public List getSiteList(String namespace, String name,
173: String version, List siteids) {
174: List sites = null;
175: String lfn = Separator.combine(namespace, name, version);
176: if (getSiteMap(namespace, name, version, siteids) != null) {
177: sites = mTCMap.getSiteList(lfn, siteids);
178: }
179: return sites;
180: }
181:
182: /**
183: * Checks if a give site is valid for a given transformation.
184: *
185: * @param namespace the namespace of the transformation.
186: * @param name the name of the transformation.
187: * @param version the version of the transformation.
188: * @param siteid the site that needs to be checked.
189: *
190: * @return boolean
191: */
192: public boolean isSiteValid(String namespace, String name,
193: String version, String siteid) {
194: List siteids = new ArrayList(1);
195: siteids.add(siteid);
196: Map m = getSiteMap(namespace, name, version, siteids);
197: return (m == null || m.isEmpty()) ? false : true;
198:
199: }
200:
201: }
|