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: */package org.griphyn.cPlanner.engine.cleanup;
015:
016: import org.griphyn.cPlanner.classes.SubInfo;
017: import org.griphyn.cPlanner.classes.PlannerOptions;
018: import org.griphyn.cPlanner.classes.PegasusFile;
019: import org.griphyn.cPlanner.classes.SiteInfo;
020:
021: import org.griphyn.cPlanner.common.PegasusProperties;
022:
023: import org.griphyn.cPlanner.namespace.Condor;
024:
025: import org.griphyn.cPlanner.poolinfo.PoolInfoProvider;
026: import org.griphyn.cPlanner.poolinfo.SiteFactory;
027: import org.griphyn.cPlanner.poolinfo.SiteFactoryException;
028:
029: import org.griphyn.common.catalog.TransformationCatalog;
030: import org.griphyn.common.catalog.TransformationCatalogEntry;
031:
032: import org.griphyn.common.catalog.transformation.TransformationFactory;
033: import org.griphyn.common.catalog.transformation.TransformationFactoryException;
034:
035: import org.griphyn.common.classes.TCType;
036:
037: import java.util.List;
038: import java.util.Iterator;
039: import java.util.HashSet;
040:
041: /**
042: * Use's RM to do removal of the files on the remote sites.
043: *
044: * @author Karan Vahi
045: * @version $Revision: 50 $
046: */
047: public class RM implements Implementation {
048:
049: /**
050: * The default logical name to rm executable.
051: */
052: public static final String DEFAULT_RM_LOGICAL_NAME = "rm";
053:
054: /**
055: * The default path to rm executable.
056: */
057: public static final String DEFAULT_RM_LOCATION = "/bin/rm";
058:
059: /**
060: * The default priority key associated with the cleanup jobs.
061: */
062: public static final String DEFAULT_PRIORITY_KEY = "1000";
063:
064: /**
065: * The handle to the transformation catalog.
066: */
067: protected TransformationCatalog mTCHandle;
068:
069: /**
070: * Handle to the site catalog.
071: */
072: protected PoolInfoProvider mSiteHandle;
073:
074: /**
075: * The handle to the properties passed to Pegasus.
076: */
077: private PegasusProperties mProps;
078:
079: /**
080: * Creates a new instance of InPlace
081: *
082: * @param properties the properties passed to the planner.
083: * @param options the options passed to the planner.
084: *
085: */
086: public RM(PegasusProperties properties, PlannerOptions options) {
087: mProps = properties;
088:
089: /* load the site catalog using the factory */
090: try {
091: mSiteHandle = SiteFactory.loadInstance(properties, false);
092: } catch (SiteFactoryException e) {
093: throw new RuntimeException("Unable to load Site Catalog "
094: + e.convertException(), e);
095: }
096:
097: /* load the transformation catalog using the factory */
098: try {
099: mTCHandle = TransformationFactory.loadInstance(properties);
100: } catch (TransformationFactoryException e) {
101: throw new RuntimeException(
102: "Unable to load Transformation Catalog "
103: + e.convertException(), e);
104: }
105:
106: }
107:
108: /**
109: * Creates a cleanup job that removes the files from remote working directory.
110: * This will eventually make way to it's own interface.
111: *
112: * @param id the identifier to be assigned to the job.
113: * @param files the list of <code>PegasusFile</code> that need to be
114: * cleaned up.
115: * @param job the primary compute job with which this cleanup job is associated.
116: *
117: * @return the cleanup job.
118: */
119: public SubInfo createCleanupJob(String id, List files, SubInfo job) {
120:
121: //we want to run the clnjob in the same directory
122: //as the compute job. So we clone.
123: SubInfo cJob = (SubInfo) job.clone();
124: cJob.setJobType(SubInfo.CLEANUP_JOB);
125: cJob.setName(id);
126: cJob.setSiteHandle(job.getSiteHandle());
127:
128: //inconsistency between job name and logical name for now
129: cJob.setTXVersion(null);
130: cJob.setTXName("rm");
131: cJob.setTXNamespace(null);
132: cJob.setLogicalID(id);
133:
134: //the compute job of the VDS supernode is this job itself
135: cJob.setVDSSuperNode(job.getID());
136:
137: //set the list of files as input files
138: //to change function signature to reflect a set only.
139: cJob.setInputFiles(new HashSet(files));
140:
141: //set the path to the rm executable
142: TransformationCatalogEntry entry = this .getTCEntry(job
143: .getSiteHandle());
144: cJob.setRemoteExecutable(entry.getPhysicalTransformation());
145:
146: //set the arguments for the cleanup job
147: StringBuffer arguments = new StringBuffer();
148: for (Iterator it = files.iterator(); it.hasNext();) {
149: PegasusFile file = (PegasusFile) it.next();
150: arguments.append(" ").append(file.getLFN());
151: }
152: cJob.setArguments(arguments.toString());
153:
154: //the cleanup job is a clone of compute
155: //need to reset the profiles first
156: cJob.resetProfiles();
157:
158: //the profile information from the pool catalog needs to be
159: //assimilated into the job.
160: cJob.updateProfiles(mSiteHandle.getPoolProfile(job
161: .getSiteHandle()));
162:
163: //the profile information from the transformation
164: //catalog needs to be assimilated into the job
165: //overriding the one from pool catalog.
166: cJob.updateProfiles(entry);
167:
168: //the profile information from the properties file
169: //is assimilated overidding the one from transformation
170: //catalog.
171: cJob.updateProfiles(mProps);
172:
173: //let us put some priority for the cleaunup jobs
174: cJob.condorVariables.construct(Condor.PRIORITY_KEY,
175: DEFAULT_PRIORITY_KEY);
176:
177: return cJob;
178: }
179:
180: /**
181: * Returns the TCEntry object for the rm executable on a grid site.
182: *
183: * @param site the site corresponding to which the entry is required.
184: *
185: * @return the TransformationCatalogEntry corresponding to the site.
186: */
187: protected TransformationCatalogEntry getTCEntry(String site) {
188: List tcentries = null;
189: TransformationCatalogEntry entry = null;
190: try {
191: tcentries = mTCHandle.getTCEntries(null,
192: DEFAULT_RM_LOGICAL_NAME, null, site,
193: TCType.INSTALLED);
194: } catch (Exception e) { /* empty catch */
195: }
196:
197: //see if any record is returned or not
198: entry = (tcentries == null) ? defaultTCEntry()
199: : (TransformationCatalogEntry) tcentries.get(0);
200:
201: return entry;
202:
203: }
204:
205: /**
206: * Returns a default TransformationCatalogEntry object for the rm executable.
207: *
208: * @return default <code>TransformationCatalogEntry</code>
209: */
210: private static TransformationCatalogEntry defaultTCEntry() {
211: TransformationCatalogEntry entry = new TransformationCatalogEntry(
212: null, DEFAULT_RM_LOGICAL_NAME, null);
213: entry.setPhysicalTransformation(DEFAULT_RM_LOCATION);
214:
215: return entry;
216: }
217: }
|