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.code.gridstart;
015:
016: import org.griphyn.cPlanner.classes.SubInfo;
017:
018: import org.griphyn.cPlanner.common.PegasusProperties;
019: import org.griphyn.cPlanner.common.LogManager;
020:
021: import org.griphyn.cPlanner.namespace.Dagman;
022:
023: import org.griphyn.cPlanner.code.POSTScript;
024:
025: /**
026: * An abstract implementation of the interface, that is a superclass for
027: * all the VDS supplied postscripts. These postscripts work can parse
028: * kickstart records.
029: *
030: * @author Karan Vahi vahi@isi.edu
031: * @version $Revision: 50 $
032: */
033:
034: public abstract class VDSPOSTScript implements POSTScript {
035:
036: /**
037: * The suffix for the exitcode output file, that is generated at the
038: * submit host.
039: */
040: public static final String EXITCODE_OUTPUT_SUFFIX = "exit.log";
041:
042: /**
043: * The LogManager object which is used to log all the messages.
044: */
045: protected LogManager mLogger;
046:
047: /**
048: * The object holding all the properties pertaining to Pegasus.
049: */
050: protected PegasusProperties mProps;
051:
052: /**
053: * The path to the exitcode client that parses the exit status of
054: * the kickstart. The client is run as a postscript. It also
055: * includes the option to the command since at present it is same for all.
056: * It is $PEGASUS_HOME/bin/exitcode (no -n)!
057: */
058: protected String mExitParserPath;
059:
060: /**
061: * A boolean indicating whether to turn the debug on for the postscript or
062: * not.
063: */
064: protected boolean mPostScriptDebug;
065:
066: /**
067: * The properties that need to be passed to the postscript invocation
068: * on the command line in the java format.
069: */
070: protected String mPostScriptProperties;
071:
072: /**
073: * The submit directory where the submit files are being generated for
074: * the workflow.
075: */
076: protected String mSubmitDir;
077:
078: /**
079: * Returns the path to exitcode that is to be used on the kickstart
080: * output.
081: *
082: * @return the path to the exitcode script to be invoked.
083: */
084: protected abstract String getDefaultExitCodePath();
085:
086: /**
087: * The default constructor.
088: */
089: public VDSPOSTScript() {
090: mLogger = LogManager.getInstance();
091: }
092:
093: /**
094: * Initialize the POSTScript implementation.
095: *
096: * @param properties the <code>PegasusProperties</code> object containing all
097: * the properties required by Pegasus.
098: * @param path the path to the POSTScript on the submit host.
099: * @param submitDir the submit directory where the submit file for the job
100: * has to be generated.
101: */
102: public void initialize(PegasusProperties properties, String path,
103: String submitDir) {
104: mProps = properties;
105: mSubmitDir = submitDir;
106:
107: //construct the exitcode paths and arguments
108: mExitParserPath = (path == null) ? getDefaultExitCodePath()
109: : path;
110: mPostScriptDebug = mProps.setPostSCRIPTDebugON();
111: mPostScriptProperties = getPostScriptProperties(properties);
112:
113: }
114:
115: /**
116: * Constructs the postscript that has to be invoked on the submit host
117: * after the job has executed on the remote end. The postscript usually
118: * works on the xml output generated by kickstart. The postscript invoked
119: * is exitcode that is shipped with VDS, and can usually be found at
120: * $PEGASUS_HOME/bin/exitcode.
121: * <p>
122: * The postscript is constructed and populated as a profile
123: * in the DAGMAN namespace.
124: *
125: *
126: * @param job the <code>SubInfo</code> object containing the job description
127: * of the job that has to be enabled on the grid.
128: * @param key the key for the profile that has to be inserted.
129: *
130: * @return boolean true if postscript was generated,else false.
131: */
132: public boolean construct(SubInfo job, String key) {
133: String postscript = mExitParserPath;
134:
135: // //NO NEED TO REMOVE AS WE ARE HANDLING CORRECTLY IN DAGMAN NAMESPACE
136: // //NOW. THERE THE ARGUMENTS AND KEY ARE COMBINED. Karan May 11,2006
137: // //arguments are already taken
138: // //care of in the profile incorporation
139: // postscript += " " +
140: // (String)job.dagmanVariables.removeKey(
141: // Dagman.POST_SCRIPT_ARGUMENTS_KEY);
142:
143: //check if the initialdir condor key has been set
144: //for the job or not
145: // This is no longer required, as to support
146: // submit host execution , all kickstart outputs
147: // are propogated back to the submit directory
148: // Karan Aug 22, 2005
149: // if(job.condorVariables.containsKey("initialdir") &&
150: // !job.executionPool.equalsIgnoreCase("local")){
151: // String dir = (String)job.condorVariables.get("initialdir");
152: // //means that the kickstart output is being
153: // //generated in the initialdir instead of the directory
154: // //from where the dag is submitted
155: // sb.append(dir).append(File.separator);
156: // }
157: // //append the name of kickstart output
158: // sb.append(job.jobName).append(".out");
159:
160: //pick up whatever output has been set and set it
161: //as a corresponding DAGMAN profile. Bug Fix for VDS Bug 144
162: // postscript += " " + (String)job.condorVariables.get("output");
163: job.dagmanVariables.construct(Dagman.OUTPUT_KEY,
164: (String) job.condorVariables.get("output"));
165:
166: StringBuffer extraOptions = new StringBuffer();
167: if (mPostScriptDebug) {
168: //add in the debug options
169: appendProperty(extraOptions, "pegasus.log.default",
170: getPostScriptLogFile(job));
171: appendProperty(extraOptions, "pegasus.verbose", "5");
172: }
173: //put in the postscript properties if any
174: extraOptions.append(this .mPostScriptProperties);
175:
176: //put the extra options into the exitcode arguments
177: //in the correct order.
178: Object args = job.dagmanVariables
179: .get(Dagman.POST_SCRIPT_ARGUMENTS_KEY);
180: StringBuffer arguments = (args == null) ?
181: //only have extra options
182: extraOptions
183: :
184: //have extra options in addition to existing args
185: new StringBuffer().append(extraOptions).append(" ")
186: .append(args);
187: job.dagmanVariables.construct(Dagman.POST_SCRIPT_ARGUMENTS_KEY,
188: arguments.toString());
189:
190: //put in the postscript
191: mLogger.log("Postscript constructed is " + postscript,
192: LogManager.DEBUG_MESSAGE_LEVEL);
193: job.dagmanVariables.checkKeyInNS(key, postscript);
194:
195: return true;
196: }
197:
198: /**
199: * Returns the path to the postscript log file for a job.
200: *
201: * @param job the <code>SubInfo</code> containing job description
202: */
203: protected String getPostScriptLogFile(SubInfo job) {
204: StringBuffer sb = new StringBuffer();
205: sb.append(job.getName()).append(".").append(
206: this .EXITCODE_OUTPUT_SUFFIX);
207: return sb.toString();
208: }
209:
210: /**
211: * Returns the properties that need to be passed to the the postscript
212: * invocation in the java format. It is of the form
213: * "-Dprop1=value1 -Dprop2=value2 .."
214: *
215: * @param properties the properties object
216: *
217: * @return the properties list, else empty string.
218: */
219: protected String getPostScriptProperties(
220: PegasusProperties properties) {
221: StringBuffer sb = new StringBuffer();
222: appendProperty(sb, "pegasus.user.properties", properties
223: .getPropertiesInSubmitDirectory());
224: return sb.toString();
225:
226: }
227:
228: /**
229: * Appends a property to the StringBuffer, in the java command line format.
230: *
231: * @param sb the StringBuffer to append the property to.
232: * @param key the property.
233: * @param value the property value.
234: */
235: protected void appendProperty(StringBuffer sb, String key,
236: String value) {
237: sb.append(" ").append("-D").append(key).append("=").append(
238: value);
239: }
240:
241: }
|