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.vdl.planner;
017:
018: import java.io.*;
019: import java.util.*;
020:
021: import org.griphyn.common.util.*;
022: import org.griphyn.vdl.util.Logging;
023: import org.griphyn.cPlanner.classes.SiteInfo;
024: import org.griphyn.cPlanner.classes.Profile;
025: import org.griphyn.cPlanner.classes.WorkDir;
026: import org.griphyn.cPlanner.poolinfo.PoolMode;
027: import org.griphyn.cPlanner.poolinfo.PoolInfoProvider;
028: import org.griphyn.cPlanner.common.PegasusProperties;
029:
030: /**
031: * This class wraps the shell planner's request into the new site
032: * catalog API. The site catalog is only queried for the contents of its
033: * "local" special site.
034: *
035: * @author Jens-S. Vöckler
036: * @author Yong Zhao
037: * @version $Revision: 50 $
038: *
039: */
040: public class SCWrapper implements Wrapper {
041: /**
042: * site catalog API reference.
043: */
044: private PoolInfoProvider m_sc = null;
045:
046: /**
047: * Connects the interface with the site catalog implementation. The
048: * choice of backend is configured through properties.
049: */
050: public SCWrapper() {
051: try {
052: PegasusProperties p = PegasusProperties
053: .nonSingletonInstance();
054: String poolClass = PoolMode.getImplementingClass(p
055: .getPoolMode());
056: m_sc = PoolMode.loadPoolInstance(poolClass,
057: p.getPoolFile(), PoolMode.NON_SINGLETON_LOAD);
058: } catch (Exception e) {
059: Logging.instance().log(
060: "planner",
061: 0,
062: "Warning: While loading SC: " + e.getMessage()
063: + ", ignoring");
064: m_sc = null;
065: }
066: }
067:
068: /**
069: * Frees resources taken by the instance of the replica catalog. This
070: * method is safe to be called on failed or already closed catalogs.
071: */
072: public void close() {
073: if (m_sc != null)
074: m_sc = null;
075: }
076:
077: /**
078: * garbage collection.
079: */
080: protected void finalize() {
081: close();
082: }
083:
084: /**
085: * Determines the working directory for the site "local".
086: *
087: * @return the working directory, of <code>null</code>, if
088: * not available.
089: */
090: public String getWorkingDirectory() {
091: // sanity check
092: if (m_sc == null)
093: return null;
094:
095: String result = null;
096: try {
097: result = m_sc.getExecPoolWorkDir("local");
098: } catch (NullPointerException npe) {
099: // noop
100: }
101:
102: // sanitization
103: if (result != null && result.length() == 0)
104: result = null;
105: return result;
106: }
107:
108: /**
109: * Determines the path to the local installation of a grid launcher
110: * for site "local".
111: *
112: * @return the path to the local kickstart, or <code>null</code>, if
113: * not available.
114: */
115: public String getGridLaunch() {
116: // sanity check
117: if (m_sc == null)
118: return null;
119:
120: String result = null;
121: try {
122: SiteInfo siv = m_sc.getPoolEntry("local", "vanilla");
123: SiteInfo sit = m_sc.getPoolEntry("local", "transfer");
124: if (siv != null) {
125: result = siv.getKickstartPath();
126: } else if (sit != null) {
127: result = sit.getKickstartPath();
128: }
129: } catch (NullPointerException npe) {
130: // noop
131: }
132:
133: // sanitization
134: if (result != null && result.length() == 0)
135: result = null;
136: return result;
137: }
138:
139: /**
140: * Gathers all profiles declared for pool local.
141: *
142: * @return a map of maps, the outer map indexed by the profile
143: * namespace, and the inner map indexed by the key in the profile.
144: * Returns <code>null</code> in case of error.
145: */
146: public Map getProfiles() {
147: Map result = new HashMap();
148:
149: // sanity checks
150: if (m_sc == null)
151: return null;
152:
153: // ask site catalog
154: List lop = m_sc.getPoolProfile("local");
155:
156: // return empty maps now, if there are no profiles
157: if (lop == null || lop.size() == 0)
158: return result;
159:
160: Map submap;
161: for (Iterator i = lop.iterator(); i.hasNext();) {
162: org.griphyn.cPlanner.classes.Profile p = (org.griphyn.cPlanner.classes.Profile) i
163: .next();
164: String ns = p.getProfileNamespace().trim().toLowerCase();
165: String key = p.getProfileKey().trim();
166: String value = p.getProfileValue();
167:
168: // insert at the right place into the result map
169: if (result.containsKey(ns)) {
170: submap = (Map) result.get(ns);
171: } else {
172: result.put(ns, (submap = new HashMap()));
173: }
174: submap.put(key, value);
175: }
176:
177: return result;
178: }
179:
180: /**
181: * Obtains the name of the class implementing the replica catalog.
182: *
183: * @return class name of the replica catalog implementor.
184: */
185: public String getName() {
186: return (m_sc == null ? null : m_sc.getClass().getName());
187: }
188:
189: /**
190: * Shows the contents of the catalog as one string. Warning, this may
191: * be very large, slow, and memory expensive.
192: *
193: * @return the string with the complete catalog contents.
194: * @throws RuntimeException because the method is not implemented.
195: */
196: public String toString() {
197: throw new RuntimeException("method not implemented");
198: }
199: }
|