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.common.catalog.toolkit;
018:
019: import org.griphyn.cPlanner.common.LogManager;
020:
021: import org.griphyn.common.catalog.TransformationCatalog;
022: import org.griphyn.common.catalog.transformation.TransformationFactory;
023: import org.griphyn.common.catalog.transformation.TransformationFactoryException;
024:
025: import org.griphyn.common.catalog.transformation.client.TCAdd;
026: import org.griphyn.common.catalog.transformation.client.TCDelete;
027: import org.griphyn.common.catalog.transformation.client.TCQuery;
028:
029: import org.griphyn.common.util.Version;
030: import org.griphyn.common.util.FactoryException;
031:
032: import java.util.HashMap;
033: import java.util.Map;
034:
035: import gnu.getopt.Getopt;
036: import gnu.getopt.LongOpt;
037:
038: /**
039: * A commom client to add, modify, delete, query any Transformation Catalog
040: * implementation.
041: *
042: * @author Gaurang Mehta
043: * @version $Revision: 50 $
044: */
045: public class TCClient {
046:
047: public String classname;
048:
049: private int add = 0;
050:
051: private int query = 0;
052:
053: private int delete = 0;
054:
055: private int bulk = 0;
056:
057: private int islfn = 0;
058:
059: private int ispfn = 0;
060:
061: private int isresource = 0;
062:
063: private int isprofile = 0;
064:
065: private int istype = 0;
066:
067: private int issysinfo = 0;
068:
069: private boolean isxml = false;
070:
071: private String lfn = null;
072:
073: private String pfn = null;
074:
075: private String profile = null;
076:
077: private String type = null;
078:
079: private String resource = null;
080:
081: private String system = null;
082:
083: private String file = null;
084:
085: private TransformationCatalog tc = null;
086:
087: private Map argsmap = null;
088:
089: private LogManager mLogger = LogManager.getInstance();
090:
091: private Version version = Version.instance();
092:
093: public TCClient() {
094: super ();
095: }
096:
097: public void loadProperties() {
098: }
099:
100: public LongOpt[] generateValidOptions() {
101: LongOpt[] longopts = new LongOpt[14];
102: longopts[0] = new LongOpt("add", LongOpt.NO_ARGUMENT, null, 'a');
103: longopts[1] = new LongOpt("delete", LongOpt.NO_ARGUMENT, null,
104: 'd');
105: longopts[2] = new LongOpt("query", LongOpt.NO_ARGUMENT, null,
106: 'q');
107: longopts[3] = new LongOpt("lfn", LongOpt.REQUIRED_ARGUMENT,
108: null, 'l');
109: longopts[4] = new LongOpt("pfn", LongOpt.REQUIRED_ARGUMENT,
110: null, 'p');
111: longopts[5] = new LongOpt("profile", LongOpt.REQUIRED_ARGUMENT,
112: null, 'e');
113: longopts[6] = new LongOpt("type", LongOpt.REQUIRED_ARGUMENT,
114: null, 't');
115: longopts[7] = new LongOpt("file", LongOpt.REQUIRED_ARGUMENT,
116: null, 'f');
117: longopts[8] = new LongOpt("help", LongOpt.NO_ARGUMENT, null,
118: 'h');
119: longopts[9] = new LongOpt("version", LongOpt.NO_ARGUMENT, null,
120: 'V');
121: longopts[10] = new LongOpt("verbose", LongOpt.NO_ARGUMENT,
122: null, 'v');
123: longopts[11] = new LongOpt("resource",
124: LongOpt.REQUIRED_ARGUMENT, null, 'r');
125: longopts[12] = new LongOpt("system", LongOpt.REQUIRED_ARGUMENT,
126: null, 's');
127: longopts[13] = new LongOpt("xml", LongOpt.NO_ARGUMENT, null,
128: 'x');
129: return longopts;
130: }
131:
132: /**
133: * Call the correct commands depending on options.
134: * @param opts String[] The arguments obtained from the command line.
135: */
136:
137: public void executeCommand(String[] opts) {
138: LongOpt[] longOptions = generateValidOptions();
139: Getopt g = new Getopt("TCClient", opts,
140: "adqhvxVLPERTBSs:t:l:p:r:e:f:", longOptions, false);
141: int option = 0;
142: int noOfOptions = 0;
143: int level = 0;
144: while ((option = g.getopt()) != -1) {
145: switch (option) {
146: case 'q': //output
147: query = 1;
148: break;
149: case 'a':
150: add = 2;
151: break;
152: case 'd':
153: delete = 4;
154: break;
155: case 'B':
156: bulk = 1;
157: break;
158: case 'L':
159: islfn = 2;
160: break;
161: case 'P':
162: ispfn = 4;
163: break;
164: case 'R':
165: isresource = 8;
166: break;
167: case 'E':
168: isprofile = 16;
169: break;
170: case 'T':
171: istype = 32;
172: break;
173: case 'S':
174: issysinfo = 64;
175: break;
176: case 't':
177: type = g.getOptarg();
178: break;
179: case 's':
180: system = g.getOptarg();
181: break;
182: case 'l':
183: lfn = g.getOptarg();
184: break;
185: case 'p':
186: pfn = g.getOptarg();
187: break;
188: case 'e':
189: if (profile != null) {
190: profile = profile + ";" + g.getOptarg();
191: } else {
192: profile = g.getOptarg();
193: }
194: break;
195: case 'f':
196: file = g.getOptarg();
197: break;
198: case 'r':
199: resource = g.getOptarg();
200: break;
201: case 'h': //help
202: printLongVersion();
203: System.exit(0);
204: break;
205: case 'V': //version
206: mLogger.log(version.toString(),
207: LogManager.INFO_MESSAGE_LEVEL);
208: System.exit(0);
209: case 'v': //Verbose mode
210: level++;
211: break;
212: case 'x': //Is XML
213: isxml = true;
214: break;
215: default:
216: mLogger.log("Unrecognized Option : " + (char) option,
217: LogManager.FATAL_MESSAGE_LEVEL);
218: printShortVersion();
219: System.exit(1);
220: break;
221: }
222: }
223: mLogger.setLevel(level);
224:
225: //calculating the value of the trigger
226: int trigger = bulk + islfn + ispfn + isresource + isprofile
227: + istype + issysinfo;
228:
229: argsmap = new HashMap(11);
230: argsmap.put("trigger", new java.lang.Integer(trigger));
231: argsmap.put("lfn", lfn);
232: argsmap.put("pfn", pfn);
233: argsmap.put("profile", profile);
234: argsmap.put("type", type);
235: argsmap.put("resource", resource);
236: argsmap.put("system", system);
237: argsmap.put("file", file);
238: argsmap.put("isxml", new Boolean(isxml));
239:
240: //Select what operation is to be performed.
241: int operationcase = query + add + delete;
242:
243: //load the transformation catalog if required
244: try {
245: if (operationcase == 1 || operationcase == 4
246: || operationcase == 2) {
247: tc = TransformationFactory.loadInstance();
248: }
249: } catch (FactoryException fe) {
250: mLogger.log(fe.convertException(),
251: LogManager.FATAL_MESSAGE_LEVEL);
252: System.exit(2);
253: }
254:
255: switch (operationcase) {
256: case 1: //QUERY OPERATION SELECTED
257: TCQuery tcquery = new TCQuery(tc, mLogger, argsmap);
258: tcquery.doQuery();
259:
260: break;
261: case 2: //ADD OPERATION SELECTED
262: TCAdd tcadd = new TCAdd(tc, mLogger, argsmap);
263: tcadd.doAdds();
264: break;
265:
266: case 4: //DELETE OPERATION SELECTED
267: TCDelete tcdelete = new TCDelete(tc, mLogger, argsmap);
268: tcdelete.doDelete();
269: break;
270: default: //ERROR IN SELECTION OPERATION
271: mLogger
272: .log(
273: "Please specify the correct operation for the client."
274: + "Only one operation can be done at a time.",
275: LogManager.FATAL_MESSAGE_LEVEL);
276: this .printShortVersion();
277: System.exit(-1);
278: }
279: }
280:
281: public void printShortVersion() {
282: String text = "\n "
283: + version.toString()
284: + "\n Usage :tc-client [ operation ] [ operation arguments ]"
285: + "\n Type tc-client -h for more details";
286:
287: mLogger.log(text, LogManager.ERROR_MESSAGE_LEVEL);
288: System.exit(1);
289: }
290:
291: public void printLongVersion() {
292: String text = "\n"
293: + version.toString()
294: + "\n"
295: + "\n tc-client - This client is used to add, delete, query any Tranformation Catalog implemented to the TC interface."
296: + "\n"
297: + "\n Usage: tc-client [Operation] [Triggers] [Options]...."
298: + "\n"
299: + "\n Operations :"
300: + "\n ------------"
301: + "\n Always one of these operations have to be specified."
302: + "\n"
303: + "\n -a | --add Perform addition operations on the TC."
304: + "\n -d | --delete Perform delete operations on the TC."
305: + "\n -q | --query Perform query operations on the TC."
306: + "\n"
307: + "\n Triggers :"
308: + "\n ----------"
309: + "\n"
310: + "\n -L Triggers an operation on a logical transformation"
311: + "\n -P Triggers an operation on a physical transformation"
312: + "\n -R Triggers an operation on a resource"
313: + "\n -E Triggers an operation on a Profile"
314: + "\n -T Triggers an operation on a Type"
315: + "\n -B Triggers a bulk operation."
316: + "\n"
317: + "\n Options :"
318: + "\n ---------"
319: + "\n"
320: + "\n -l | --lfn <logical txmation> The logical transformation to be added in the format NAMESPACE::NAME:VERSION."
321: + "\n (The name is always required, namespace and version are optional.)"
322: + "\n -p | ---pfn <physical txmation> The physical transfromation to be added. "
323: + "\n For INSTALLED executables its a local file path, for all others its a url."
324: + "\n -t | --type <type of txmation> The type of physical transformation. Valid values are :"
325: + "\n INSTALLED, STATIC_BINARY, DYNAMIC_BINARY, SCRIPT, SOURCE, PACMAN_PACKAGE. "
326: + "\n -r | --resource <resource id> The Id of the resource where the transformation is located. "
327: + "\n -e | --profile <profiles> The profiles belonging to the transformation."
328: + "\n Mulitple profiles of same namespace can be added simultaneously"
329: + "\n by seperating them with a comma \",\"."
330: + "\n Each profile section is written as NAMESPACE::KEY=VALUE,KEY2=VALUE2 "
331: + "\n e.g. ENV::JAVA_HOME=/usr/bin/java2,PEGASUS_HOME=/usr/local/vds"
332: + "\n To add muliple namespaces you need to repeat the -e option for each namespace."
333: + "\n e.g -e ENV::JAVA_HOME=/usr/bin/java -e GLOBUS::JobType=MPI,COUNT=10"
334: + "\n -s | --system <system type> The architecture,os and glibc if any for the executable."
335: + "\n Each system info is written in the form ARCH::OS:OSVER:GLIBC"
336: + "\n The allowed ARCH's are INTEL32, INTEL64, SPARCV7, SPARCV9"
337: + "\n The allowed OS's are LINUX, SUNOS, AIX"
338: + "\n"
339: + "\n Other Options :"
340: + "\n ---------------"
341: + "\n"
342: + "\n --verbose | -v increases the verbosity level"
343: + "\n --version | -V Displays the version number of the Griphyn Virtual Data System software "
344: + "\n --help | -h Generates this help"
345: + "\n"
346: + "\n Valid Combinations :"
347: + "\n --------------------"
348: + "\n ADD"
349: + "\n ---"
350: + "\n "
351: + "\n\tAdd TC Entry : -a -l <lfn> -p <pfn> -r <resource> [-t <type>] [-s <system>] [-e <profiles> ....]"
352: + "\n\tAdd PFN Profile : -a -P -E -p <pfn> -t <type> -r <resource> -e <profiles> ...."
353: + "\n\tAdd LFN Profile : -a -L -E -l <lfn> -e <profiles> ...."
354: + "\n\tAdd Bulk Entries : -a -B -f <file>"
355: + "\n"
356: + "\n DELETE"
357: + "\n ------"
358: + "\n"
359: + "\n\tDelete all TC : -d -BPRELST "
360: + "\n\t (!!!WARNING : THIS DELETETS THE ENTIRE TC!!!)"
361: + "\n\tDelete by LFN : -d -L -l <lfn> [-r <resource>] [-t <type>]"
362: + "\n\tDelete by PFN : -d -P -l <lfn> -p <pfn> [-r <resource>] [-t type]"
363: + "\n\tDelete by Type : -d -T -t <type> [-r <resource>]"
364: + "\n\tDelete by Resource : -d -R -r <resource>"
365: + "\n\tDelete by SysInfo : -d -S -s <sysinfo>"
366: + "\n\tDelete Pfn Profile : -d -P -E -p <pfn> -r <resource> -t <type> [-e <profiles> ....]"
367: + "\n\tDelete Lfn Profile : -d -L -E -l <lfn> [-e <profiles> .....]"
368: + "\n"
369: + "\n QUERY"
370: + "\n -----"
371: + "\n "
372: + "\n\tQuery Bulk : -q -B"
373: + "\n\tQuery LFN : -q -L [-r <resource>] [-t <type>]"
374: + "\n\tQuery PFN : -q -P -l <lfn> [-r <resource>] [-t <type>]"
375: + "\n\tQuery Resource : -q -R [-l <lfn>] [-t <type>]"
376: + "\n\tQuery Lfn Profile : -q -L -E -l <lfn>"
377: + "\n\tQuery Pfn Profile : -q -P -E -p <pfn> -r <resource> -t <type>"
378: + "\n";
379:
380: mLogger.log(text, LogManager.INFO_MESSAGE_LEVEL);
381: System.exit(0);
382: }
383:
384: public static void main(String[] args) throws Exception {
385: TCClient client = new TCClient();
386: client.executeCommand(args);
387: }
388:
389: }
|