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.poolinfo;
018:
019: import org.griphyn.cPlanner.classes.PoolConfig;
020: import org.griphyn.cPlanner.classes.SiteInfo;
021:
022: import org.griphyn.cPlanner.common.LogManager;
023:
024: import org.griphyn.common.classes.SysInfo;
025:
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.ArrayList;
029: import java.util.Map;
030: import java.util.HashMap;
031: import java.util.Set;
032:
033: /**
034: * An abstract implementation of the PoolInfoProvider. Implementations should
035: * extend it, only if they are statically loading information into a
036: * <code>PoolConfig</code> object. The object once populated contains all
037: * the contents of the catalog.
038: *
039: * @author Karan Vahi
040: * @version $Revision: 50 $
041: *
042: * @see #mPoolConfig
043: */
044: public abstract class Abstract extends PoolInfoProvider {
045:
046: /**
047: * Handle to the PoolConfig object
048: */
049: protected PoolConfig mPoolConfig = null;
050:
051: /**
052: * Returns the System information for a bunch of sites.
053: *
054: * @param siteids List The siteid whose system information is required
055: *
056: * @return Map The key is the siteid and the value is a SysInfo object
057: *
058: * @see org.griphyn.common.classes.SysInfo
059: */
060: public Map getSysinfos(List siteids) {
061: logMessage("Map getSysinfos(List siteIDS)");
062: logMessage("\t getSysinfos(" + siteids + ")");
063: HashMap sysinfomap = null;
064: for (Iterator i = siteids.iterator(); i.hasNext();) {
065: String site = (String) i.next();
066: SiteInfo siteinfo = mPoolConfig.get(site);
067: if (siteinfo != null) {
068: if (sysinfomap == null) {
069: sysinfomap = new HashMap(5);
070: }
071: sysinfomap
072: .put(site, siteinfo.getInfo(SiteInfo.SYSINFO));
073: }
074: }
075: return sysinfomap;
076: }
077:
078: /**
079: * Returns the System information for a single site.
080: *
081: * @param siteID String The site whose system information is requested
082: *
083: * @return SysInfo The system information as a SysInfo object
084: *
085: * @see org.griphyn.common.classes.SysInfo
086: */
087: public SysInfo getSysinfo(String siteID) {
088: logMessage("SysInfo getSysinfo(String siteID)");
089: logMessage("\t getSysinfo(" + siteID + ")");
090: SiteInfo siteinfo = mPoolConfig.get(siteID);
091: if (siteinfo != null) {
092: return (SysInfo) siteinfo.getInfo(SiteInfo.SYSINFO);
093: }
094: return null;
095: }
096:
097: /**
098: * Gets the pool information from the pool.config file on the basis
099: * of the name of the pool, and the universe.
100: *
101: * @param siteID the name of the site
102: * @param universe the execution universe for the job
103: *
104: * @return the corresponding pool object for the entry if found
105: * else null
106: */
107: public SiteInfo getPoolEntry(String siteID, String universe) {
108: logMessage("SiteInfo getPoolEntry(String siteID,String universe)");
109: logMessage("\tSiteInfo getPoolEntry(" + siteID + "," + universe
110: + ")");
111: SiteInfo site = mPoolConfig.get(siteID);
112: return site;
113: }
114:
115: /**
116: * It returns the profile information associated with a particular pool. If
117: * the pool provider has no such information it should return null.
118: * The name of the object may purport that it is specific to GVDS format, but
119: * in fact it a tuple consisting of namespace, key and value that can be used
120: * by other Pool providers too.
121: *
122: * @param siteID the name of the site, whose profile information you want.
123: *
124: * @return List of <code>Profile</code> objects
125: * null if the information about the site is not with the pool provider.
126: *
127: * @see org.griphyn.cPlanner.classes.Profile
128: */
129: public List getPoolProfile(String siteID) {
130: logMessage("List getPoolProfile(String siteID)");
131: logMessage("\tList getPoolProfile(" + siteID + ")");
132: SiteInfo poolInfo = mPoolConfig.get(siteID);
133: ArrayList profileList = null;
134:
135: try {
136: profileList = (poolInfo == null) ? null
137: : (ArrayList) poolInfo.getInfo(SiteInfo.PROFILE);
138:
139: if (profileList == null) {
140: return null;
141: }
142:
143: } catch (Exception e) {
144: throw new RuntimeException(
145: "While getting profiles for site " + siteID, e);
146: }
147: return profileList;
148: }
149:
150: /**
151: * It returns all the jobmanagers corresponding to a specified site.
152: *
153: * @param siteID the name of the site at which the jobmanager runs.
154: *
155: * @return list of <code>JobManager</code>, each referring to
156: * one jobmanager contact string. An empty list if no jobmanagers
157: * found.
158: */
159: public List getJobmanagers(String siteID) {
160: logMessage("List getJobmanagers(String siteID)");
161: logMessage("\tList getJobamager(" + siteID + ")");
162: SiteInfo poolInfo = mPoolConfig.get(siteID);
163: return (poolInfo == null) ? new java.util.ArrayList(0)
164: : poolInfo.getJobmanagers();
165: }
166:
167: /**
168: * It returns all the jobmanagers corresponding to a specified pool and
169: * universe.
170: *
171: * @param siteID the name of the site at which the jobmanager runs.
172: * @param universe the gvds universe with which it is associated.
173: *
174: * @return list of <code>JobManager</code>, each referring to
175: * one jobmanager contact string. An empty list if no jobmanagers
176: * found.
177: */
178: public List getJobmanagers(String siteID, String universe) {
179: logMessage("List getJobmanagers(String siteID,String universe");
180: logMessage("\tList getJobmanagers( " + siteID + "," + universe
181: + ")");
182: SiteInfo poolInfo = mPoolConfig.get(siteID);
183: return (poolInfo == null) ? new java.util.ArrayList(0)
184: : poolInfo.getJobmanagers(universe);
185: }
186:
187: /**
188: * It returns all the gridftp servers corresponding to a specified pool.
189: *
190: * @param siteID the name of the site at which the jobmanager runs.
191: *
192: * @return List of <code>GridFTPServer</code>, each referring to one
193: * GridFtp Server.
194: */
195: public List getGridFTPServers(String siteID) {
196: logMessage("List getGridFTPServers(String siteID)");
197: logMessage("\tList getGridFTPServers(" + siteID + ")");
198: SiteInfo poolInfo = mPoolConfig.get(siteID);
199: if (poolInfo == null) {
200: return new java.util.ArrayList();
201: }
202:
203: ArrayList gridftp = (ArrayList) poolInfo
204: .getInfo(SiteInfo.GRIDFTP);
205:
206: return gridftp;
207: }
208:
209: /**
210: * It returns all the pools available in the site catalog
211: *
212: * @return List of names of the pools available as String
213: */
214: public List getPools() {
215: logMessage("List getPools()");
216: Set s = mPoolConfig.getSites().keySet();
217: return new ArrayList(s);
218: }
219:
220: /**
221: * This is a soft state remove, that removes a jobmanager from a particular
222: * pool entry. The cause of this removal could be the inability to
223: * authenticate against it at runtime. The successful removal lead Pegasus
224: * not to schedule job on that particular jobmanager.
225: *
226: * @param siteID the name of the site at which the jobmanager runs.
227: * @param universe the gvds universe with which it is associated.
228: * @param jobManagerContact the contact string to the jobmanager.
229: *
230: * @return true if was able to remove the jobmanager from the cache
231: * false if unable to remove, or the matching entry is not found
232: * or if the implementing class does not maintain a soft state.
233: */
234: public boolean removeJobManager(String siteID, String universe,
235: String jobManagerContact) {
236: logMessage("boolean removeJobManager(String siteID, String universe,"
237: + "String jobManagerContact)");
238: logMessage("\tboolean removeJobManager(" + siteID + ","
239: + universe + "," + jobManagerContact + ")");
240: SiteInfo poolinfo = mPoolConfig.get(siteID);
241:
242: return (poolinfo == null) ? false : poolinfo.removeJobmanager(
243: universe, jobManagerContact);
244:
245: }
246:
247: /**
248: * This is a soft state remove, that removes a gridftp server from a particular
249: * pool entry. The cause of this removal could be the inability to
250: * authenticate against it at runtime. The successful removal lead Pegasus
251: * not to schedule any transfers on that particular gridftp server.
252: *
253: * @param siteID the name of the site at which the gridftp runs.
254: * @param urlPrefix the url prefix containing the protocol,hostname and port.
255: *
256: * @return true if was able to remove the gridftp from the cache
257: * false if unable to remove, or the matching entry is not found
258: * or if the implementing class does not maintain a soft state.
259: * or the information about site is not in the site catalog.
260: */
261: public boolean removeGridFtp(String siteID, String urlPrefix) {
262: logMessage("boolean removeGrid(String siteID, String urlPrefix)");
263: logMessage("\t boolean removeGrid(" + siteID + "," + urlPrefix
264: + ")");
265: SiteInfo poolinfo = mPoolConfig.get(siteID);
266:
267: return (poolinfo == null) ? false : poolinfo
268: .removeGridFtp(urlPrefix);
269:
270: }
271:
272: }
|