Author: challngr
Date: Mon Oct 27 18:21:39 2014
New Revision: 1634635
URL: http://svn.apache.org/r1634635
Log:
UIMA-4064 Sanitized / classloading CLI
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOption.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ATestDriver.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/TestCommandLine.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/ClassManager.java
Modified:
uima/sandbox/uima-ducc/trunk/src/main/scripts/ducc_services
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccManagedReservationMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceApi.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IDuccMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ManagedReserveAndCancel.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ReserveAndCancel.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/ServiceTester.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/test/java/org/apache/uima/ducc/cli/test/SubmitAndCancel.java
uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/DuccPropertiesResolver.java
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/PingDriver.java
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceStartEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceStopEvent.java
Modified: uima/sandbox/uima-ducc/trunk/src/main/scripts/ducc_services
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/scripts/ducc_services?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/scripts/ducc_services (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/scripts/ducc_services Mon Oct 27
18:21:39 2014
@@ -20,12 +20,48 @@
# -----------------------------------------------------------------------
import sys
+import getopt
+import os
+
from ducc_base import DuccBase
class DuccServices(DuccBase):
+ def make_classpath(self, uima_home):
+ cp = self.DUCC_HOME + '/lib/uima-ducc-cli.jar'
+ cp = cp + ':' + uima_home + '/lib/uima-core.jar'
+ cp = cp + ':' + uima_home + '/lib/uimaj-as-core.jar'
+ return cp
+
+ def handle_uima_home(self, argv):
+ answer = []
+ skip = False
+ uima_home = None
+
+ # first look for uima-home in args, and if its there, extract it
+ for a in argv:
+ if ( skip ) :
+ uima_home = a
+ skip = False
+ continue
+ if ( a in ('-u', '--uima-home') ):
+ skip = True
+ continue
+ answer.append(a)
+
+ # if no uima-home, look in environment. if not there. use DUCC's uima
+ if ( uima_home == None ):
+ if ( os.environ.has_key('UIMA_HOME') ):
+ uima_home = os.environ['UIMA_HOME']
+ else:
+ uima_home = self.DUCC_HOME + '/apache-uima'
+
+ return (answer, uima_home)
+
def main(self, argv):
- self.spawn(self.java(), '-cp', self.DUCC_HOME +
'/lib/uima-ducc-cli.jar', 'org.apache.uima.ducc.cli.DuccServiceApi', '
'.join(self.mkargs(argv)))
+ (argv, uima_home) = self.handle_uima_home(argv)
+ cp = self.make_classpath(uima_home);
+ self.spawn(self.java(), '-cp', cp,
'org.apache.uima.ducc.cli.DuccServiceApi', ' '.join(self.mkargs(argv)))
if __name__ == "__main__":
svc = DuccServices()
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
Mon Oct 27 18:21:39 2014
@@ -95,8 +95,7 @@ public abstract class AServicePing
* writes to stdout which is directed to
* the declared service log directory by the infrastructore.
*/
- protected org.apache.uima.ducc.common.utils.DuccLogger duccLogger =
-
org.apache.uima.ducc.common.utils.DuccLogger.getLogger(this.getClass().getName(),
"PING");
+ protected org.apache.uima.ducc.common.utils.DuccLogger duccLogger;
/**
* Called by the ping driver, to pass in useful things the pinger may want.
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
Mon Oct 27 18:21:39 2014
@@ -1,4 +1,4 @@
-/*
+ /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -26,27 +26,28 @@ import java.io.OutputStreamWriter;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.MissingOptionException;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.Parser;
-import org.apache.commons.cli.PosixParser;
+// import org.apache.commons.cli.CommandLine;
+// import org.apache.commons.cli.HelpFormatter;
+// import org.apache.commons.cli.MissingOptionException;
+// import org.apache.commons.cli.Option;
+// import org.apache.commons.cli.Options;
+// import org.apache.commons.cli.ParseException;
+// import org.apache.commons.cli.Parser;
+// import org.apache.commons.cli.PosixParser;
import org.apache.uima.ducc.common.IDucc;
import org.apache.uima.ducc.common.crypto.Crypto;
import org.apache.uima.ducc.common.utils.DuccProperties;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
import org.apache.uima.ducc.common.utils.Utils;
+import org.apache.uima.ducc.transport.dispatcher.ClassManager;
import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
import org.apache.uima.ducc.transport.event.AbstractDuccOrchestratorEvent;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
@@ -61,10 +62,11 @@ public abstract class CliBase
private String myClassName = "N/A";
private boolean init_done = false;
protected String ducc_home;
+ // IHttpDispatcher dispatcher;
DuccEventHttpDispatcher dispatcher;
- protected Options cliOptions;
- protected Parser parser;
+ //protected Options cliOptions;
+ //protected Parser parser;
protected CommandLine commandLine;
protected long friendlyId = -1;
@@ -91,7 +93,7 @@ public abstract class CliBase
protected Properties userSpecifiedProperties;
// Options added to the saved spec file that must be removed if used as a
--specification option
- private List<String> addedOptions =
Arrays.asList(UiOption.SubmitPid.pname(), UiOption.User.pname());
+ //private List<UiOption> addedOptions = Arrays.asList(UiOption.SubmitPid,
UiOption.User);
/**
* All extenders must implement execute - this method does whatever
processing on the input
@@ -215,25 +217,25 @@ public abstract class CliBase
}
}
- /*
- * Also used by DuccMonitor
- */
- static public Options makeOptions(UiOption[] optlist)
- {
- Options opts = new Options();
- for ( UiOption opt : optlist ) {
- String arg = opt.argname();
- Option o = new Option(opt.sname(), opt.pname(), (arg != null),
opt.makeDesc());
- o.setArgName(arg);
- o.setOptionalArg(arg != null && arg.endsWith("(optional)"));
- if (opt.multiargs()) {
- o.setArgs(Option.UNLIMITED_VALUES); // (Untested as we have no
multiarg options)
- }
- opts.addOption(o);
- // Note: avoid OptionBuilder as is not thread-safe
- }
- return opts;
- }
+// /*
+// * Also used by DuccMonitor
+// */
+// static public Options makeOptions(UiOption[] optlist)
+// {
+// Options opts = new Options();
+// for ( UiOption opt : optlist ) {
+// String arg = opt.argname();
+// Option o = new Option(opt.sname(), opt.pname(), (arg != null),
opt.makeDesc());
+// o.setArgName(arg);
+// o.setOptionalArg(arg != null && arg.endsWith("(optional)"));
+// if (opt.multiargs()) {
+// o.setArgs(Option.UNLIMITED_VALUES); // (Untested as we have
no multiarg options)
+// }
+// opts.addOption(o);
+// // Note: avoid OptionBuilder as is not thread-safe
+// }
+// return opts;
+// }
protected String[] mkArgs(Properties props)
{
@@ -249,6 +251,24 @@ public abstract class CliBase
}
return arglist.toArray(new String[arglist.size()]);
}
+
+ DuccEventHttpDispatcher makeDispatcher(String targetUrl)
+ {
+ String[] classpath = {
+ "lib/apache-camel/xstream*",
+ "lib/google-gson/gson*",
+ };
+
+ DuccEventHttpDispatcher ret = null;
+ try {
+ ClassManager cm = new ClassManager(classpath);
+ ret = (DuccEventHttpDispatcher)
cm.construct("org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher",
new Object[] {targetUrl});
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return ret;
+ }
/**
* Standard init for all except the Service calls that are sent to the SM
@@ -264,10 +284,22 @@ public abstract class CliBase
this.init (myClassName, opts, null, props, cli_props, consoleCb,
"orchestrator");
}
- protected synchronized void init(String myClassName, UiOption[] uiOpts,
String[] args, Properties props,
+ /**
+ *
+ * @param myClassName Name of the class invoking me, for help string
+ * @param uiOpts Array of IUioptions permitted for this command
+ * @param args Arguments from the command line
+ * @param props Properties passed in from the API
+ * @param cli_props (Initially) empty properties file to be filled in
+ * @param consoleCb Console callback object (optional)
+ * @param servlet The name of the http servlet that will serve this
request
+ * @throws Exception
+ */
+ protected synchronized void init(String myClassName, IUiOption[] uiOpts,
String[] args, Properties props,
DuccProperties cli_props, IDuccCallback consoleCb, String
servlet)
throws Exception
{
+
CliFixups.cleanupArgs(args, myClassName); // Default implementation
does nothing
if ( init_done ) return;
@@ -282,28 +314,43 @@ public abstract class CliBase
ducc_home = Utils.findDuccHome();
this.cli_props = cli_props;
- parser = new PosixParser();
+ if ( args != null ) {
+ fixupQuotedArgs(args);
+ }
+ commandLine = new CommandLine(args, uiOpts, props);
+ try {
+ commandLine.parse();
+ } catch (Exception e) {
+ usage(e.getMessage());
+ }
- cliOptions = makeOptions(uiOpts);
+ // cliOptions = makeOptions(uiOpts);
// If given only a properties file parse as if only have defaults
- if (args == null) {
- commandLine = parser.parse(cliOptions, null, props);
- } else {
- fixupQuotedArgs(args);
- commandLine = parser.parse(cliOptions, args);
+// if (args == null) {
+// // strings, uioptions, proerties
+// commandLine.parse(null, uiOpts, props);
+// } else {
+// fixupQuotedArgs(args);
+// commandLine = parser.parse(cliOptions, args);
+// }
+// if (commandLine.getOptions().length == 0 ||
commandLine.hasOption(UiOption.Help.pname())) {
+// usage(null);
+// }
+ if ( commandLine.contains(UiOption.Help)) {
+ usage(null);
}
- if (commandLine.getOptions().length == 0 ||
commandLine.hasOption(UiOption.Help.pname())) {
- usage(null);
- }
- debug = commandLine.hasOption(UiOption.Debug.pname());
+
+ debug = commandLine.contains(UiOption.Debug);
// Load the specification file, if given on the command line. Note
that registration
// bypasses the somewhat redundant --specification option so we check
two options.
// Cannot have both as --specification && --register are never both
valid.
String fname = null;
- for (String spec : new String[] { UiOption.Specification.pname(),
UiOption.Register.pname()}) {
- fname = commandLine.getOptionValue(spec);
- if (fname != null) break;
+ for (IUiOption spec : new IUiOption[]{ UiOption.Specification,
UiOption.Register }) {
+ if ( commandLine.isOption(spec) && commandLine.contains(spec)) {
// legal for this command, and also specified?
+ fname = commandLine.get(spec);
+ break;
+ }
}
// If have a specification file re-parse using it for default values
if ( fname != null ) {
@@ -311,19 +358,26 @@ public abstract class CliBase
Properties defaults = new Properties();
defaults.load(fis);
fis.close();
- sanitize(defaults, cliOptions); // Check for illegals as commons
cli 1.2 throws a NPE !
+ CliFixups.cleanupProps(defaults, myClassName); // By default
does nothing
+
+ // No longer needed we believe
+ // sanitize(defaults, commandLine); // Check for illegals as
commons cli 1.2 throws a NPE !
+
// If invoked with overriding properties add to or replace the
defaults
if (props != null) {
defaults.putAll(props);
}
- commandLine = parser.parse(cliOptions, args, defaults);
+ commandLine = new CommandLine(args, uiOpts, defaults);
+ commandLine.parse();
}
-
+ commandLine.verify(); // Insure all the rules specified by the
IUiOpts are enforced
+
// Check if any orphaned args left
- List<?> extraArgs = commandLine.getArgList();
- if (extraArgs.size() > 0) {
- throw new ParseException("Superfluous arguments provided (perhaps
quotes omitted?): " + extraArgs);
- }
+ // new CommandLine parser will throw IllegalArgumentException if this
happens
+// List<?> extraArgs = commandLine.getArgList();
+// if (extraArgs.size() > 0) {
+// throw new ParseException("Superfluous arguments provided
(perhaps quotes omitted?): " + extraArgs);
+// }
// Copy options into cli_props
setOptions(uiOpts);
@@ -336,6 +390,9 @@ public abstract class CliBase
// Apply defaults for and fixup the environment if needed
// -- unless default loading is inhibited, as it must be for modify
operations
+ // What this routine does is fill in all the options that weren't
specified
+ // on the command line with their defaults. For 'modify' we want
to bypass
+ // this because ONLY the options from the command line should be
set.
if ( load_defaults ) {
setDefaults(uiOpts, suppress_console_log);
}
@@ -355,6 +412,8 @@ public abstract class CliBase
initConsoleListener();
String targetUrl = DuccUiUtilities.dispatchUrl(servlet);
+
+ // dispatcher = makeDispatcher(targetUrl);
dispatcher = new DuccEventHttpDispatcher(targetUrl);
init_done = true;
@@ -363,28 +422,33 @@ public abstract class CliBase
/*
* Save options as properties after resolving any ${..} placeholders
*/
- void setOptions(UiOption[] uiOpts) throws Exception {
- for (Option opt : commandLine.getOptions()) {
- String val = opt.getValue();
+ void setOptions(IUiOption[] uiOpts)
+ throws Exception
+ {
+ Map<IUiOption, String> parsed = commandLine.allOptions();
+ for (IUiOption opt : parsed.keySet() ) {
+ String val = parsed.get(opt);
if (val == null) { // Should only happen for
no-arg options
- val = opt.hasArg() ? "" : "true"; // Treat no-arg options as
booleans ... apache.commons.cli expects this
+ val = "";
} else {
if (val.contains("${")) {
val = resolvePlaceholders(val);
}
- String oval = (String) cli_props.get(opt.getLongOpt());
- if (oval != null && !oval.equals(val)) {
- throw new Exception("Duplicate option specified: " +
opt.getLongOpt());
- }
+ // no need to check for dups, the parser does this
+// String oval = (String) cli_props.get(opt.getLongOpt());
+// if (oval != null && !oval.equals(val)) {
+// throw new Exception("Duplicate option specified: " +
opt.getLongOpt());
+// }
}
val = val.trim();
// SM cannot handle an empty list of service dependencies
- if (val.length() == 0 &&
opt.getLongOpt().equals(UiOption.ServiceDependency.pname())) {
- if (debug) System.out.println("CLI dropped empty option " +
opt.getLongOpt());
- } else {
- cli_props.put(opt.getLongOpt(), val);
- if (debug) System.out.println("CLI set " + opt.getLongOpt() +
" = '" + val + "'");
- }
+ // new parser: ServiceDependency configured to require an argument.
+// if (val.length() == 0 &&
opt.getLongOpt().equals(UiOption.ServiceDependency.pname())) {
+// if (debug) System.out.println("CLI dropped empty option " +
opt.getLongOpt());
+// } else {
+ cli_props.put(opt.pname(), val);
+ if (debug) System.out.println("CLI set " + opt.pname() + " =
'" + val + "'");
+ //}
}
}
@@ -392,17 +456,26 @@ public abstract class CliBase
* Check for missing required options, set defaults, and validate where
possible
* Also fixup the environment for all that use it.
*/
- void setDefaults(UiOption[] uiOpts, boolean suppress_console) throws
Exception {
- for (UiOption uiopt : uiOpts) {
+ void setDefaults(IUiOption[] uiOpts, boolean suppress_console) throws
Exception {
+ for (IUiOption uiopt : uiOpts) {
if (!cli_props.containsKey(uiopt.pname())) {
- if (uiopt.required()) {
- throw new MissingOptionException("Missing required option:
" + uiopt.pname());
- }
- if (uiopt.deflt() != null) {
+ //
+ // here deal with stuff that wasn't given explicitly in the
command
+ //
+ // our convention - optargs() implies boolean, but it does't
have to.
+ // If the arg is not expllicitly specified,
we assume
+ // it is (boolean,false) for the sake of
dealing with defaults.
+ // -- and then just leave it out --
+ // similarly - noargs() is definitely boolean, same
treatement
+ //
+ if ( (! uiopt.optargs()) && (! uiopt.noargs() ) &&
uiopt.deflt() != null) {
if (debug) System.out.println("CLI set default: " +
uiopt.pname() + " = " + uiopt.deflt());
cli_props.put(uiopt.pname(), uiopt.deflt());
}
} else {
+ //
+ // here clean up stuff that was specified but we want to
validate it
+ //
if (uiopt == UiOption.ClasspathOrder) {
String val = cli_props.getStringProperty(uiopt.pname());
if (!val.equals(ClasspathOrderParms.DuccBeforeUser.pname())
@@ -432,30 +505,41 @@ public abstract class CliBase
* other than 'true' or 'yes' or '1' (CLI 1.2 mishandles others)
*/
- private void sanitize(Properties props, Options opts) {
- CliFixups.cleanupProps(props, myClassName); // By default does
nothing
- for (String key : props.stringPropertyNames()) {
- if (addedOptions.contains(key)) {
- props.remove(key);
- } else {
- Option opt = cliOptions.getOption(key);
- if (opt == null) {
- throw new IllegalArgumentException("Invalid option '" +
key + "' in specification file");
- }
- if (!opt.hasArg()) {
- String val = props.getProperty(key);
- if (val.length() == 0) {
- props.setProperty(key, "true");
- } else if (!val.equalsIgnoreCase("true") &&
- !val.equalsIgnoreCase("yes") &&
- !val.equals("1")) {
- message("WARN: Ignoring illegal value: ", key, "=",
val);
- props.remove(key);
- }
- }
- }
- }
- }
+ /*
+ * Notes for removal of commons.cli:
+ * - Do not need to check for invalid options, the parser does that and
throws
+ * - Do not need to deal with missing boolean for no-opt parms, the
parsesr does that
+ * What's left? Removing stuff like 'user' and 'pid' if you're reusing a
+ * previously-submitted properties file. We probably don't need this
either.
+ *
+ * Consulting Burn, it appears we probably don't need sanitize.
+
+ * So for now I'll just remove it and see what happens,
+ */
+ // private void sanitize(Properties props, Options opts) {
+ // CliFixups.cleanupProps(props, myClassName); // By default does
nothing
+ // for (String key : props.stringPropertyNames()) {
+ // if (addedOptions.contains(key)) {
+ // props.remove(key);
+ // } else {
+ // Option opt = cliOptions.getOption(key);
+ // if (opt == null) {
+ // throw new IllegalArgumentException("Invalid option '" +
key + "' in specification file");
+ // }
+ // if (!opt.hasArg()) {
+ // String val = props.getProperty(key);
+ // if (val.length() == 0) {
+ // props.setProperty(key, "true");
+ // } else if (!val.equalsIgnoreCase("true") &&
+ // !val.equalsIgnoreCase("yes") &&
+ // !val.equals("1")) {
+ // message("WARN: Ignoring illegal value: ", key, "=",
val);
+ // props.remove(key);
+ // }
+ // }
+ // }
+ // }
+ // }
/*
* Resolve any ${..} placeholders against user's system properties and
environment
@@ -568,9 +652,7 @@ public abstract class CliBase
if ( message != null ) {
System.out.println(message);
}
- HelpFormatter formatter = new HelpFormatter();
- formatter.setWidth(DuccUiConstants.help_width);
- formatter.printHelp(myClassName, cliOptions);
+ System.out.println(commandLine.formatHelp(myClassName));
System.exit(1);
}
@@ -589,8 +671,7 @@ public abstract class CliBase
if ( key.startsWith("--") ) {
key = key.substring(2);
}
- Option option = cliOptions.getOption(key);
- if (option == null ) {
+ if ( ! commandLine.isOption(key)) {
return false;
}
cli_props.setProperty(key, value);
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java?rev=1634635&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CommandLine.java
Mon Oct 27 18:21:39 2014
@@ -0,0 +1,521 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.cli;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class CommandLine
+{
+ private String[] args; // incoming args from
java command line
+ private IUiOption[] opts; // options defined for
this command
+
+ private Map<String, IUiOption> name_to_option; // name to IUiOpton map
+ private Map<IUiOption, String> option_to_value; // UiOption to value
map
+ private Map<IUiOption, IUiOption> legal_options;
+ private Properties properties;
+
+ private int help_width = 100; // justify help
strings to about this
+
+ /**
+ * Construct a CommandLine from incoming strings and the legal options.
+ *
+ * @param args
+ * @param opts
+ */
+ public CommandLine(String[] args, IUiOption[] opts)
+ {
+ this(args, opts, null);
+ }
+
+ /**
+ * Construct a CommandLine from the incoming strings, the legal options,
and a
+ * properties file. If the properties file is supplied, it is used to
fill in
+ * options if not otherwise on the command line. The command-line strings
always
+ * take precedence.
+ *
+ * @param args
+ * @param opts
+ * @param props
+ */
+ public CommandLine(String[] args, IUiOption[] opts, Properties props)
+ {
+
+ this.args = args;
+ this.opts = opts;
+ this.properties = props;
+ this.name_to_option = new HashMap<String, IUiOption>();
+ this.option_to_value = new HashMap<IUiOption, String>();
+ this.legal_options = new HashMap<IUiOption, IUiOption>();
+
+ for ( IUiOption o : opts ) {
+ name_to_option.put(o.pname(), o); // String -->
option mapping
+ legal_options.put(o, o); // quick lookup for
legal options
+
+ if ( o.sname() != null ) { // if it has a short name, point into
the same place
+ name_to_option.put(o.sname(), o);
+ }
+ }
+ }
+
+ /**
+ * Returns whether the parsesd command line contained the specified option
(by IUiOption).
+ *
+ * @param opt This is the option to test for.
+ *
+ * @return <b>true</b> if the specified option was found in the parsed
command line, <b>false</b> otherwise
+ */
+ public boolean contains(IUiOption opt)
+ {
+ // does the command contain this option?
+ return option_to_value.containsKey(opt);
+ }
+
+ /**
+ * Returns whether the parsesd command line contained the specified option
(by string name).
+ *
+ * @param opt This is the option to test for.
+ *
+ * @return <b>true</b> if the specified option was found in the parsed
command line, <b>false</b> otherwise
+ */
+ public boolean contains(String opt)
+ {
+ // does the command contain this option?
+ IUiOption o = name_to_option.get(opt); // see if it's known
+ if ( o == null ) return false; // not known
+ return contains(o); // does it have a value?
+ }
+
+ public boolean isOption(String s)
+ {
+ // is this string a legal option?
+ // for use in parsing values that start with - or --
+ if ( s.startsWith("--") ) s = s.substring(2);
+ else if ( s.startsWith("-") ) s = s.substring(1);
+
+ return name_to_option.containsKey(s);
+ }
+
+ public boolean isOption(IUiOption k)
+ {
+ // is this a legal option?
+ return legal_options.containsKey(k);
+ }
+
+ /**
+ * Returns the string value parsed from the command for the specified
option, or <b>null</b> if the
+ * option was not in the command line.
+ *
+ * @param opt This is the option to look for.
+ *
+ * @return the parsed value from the command line for the option or
<b>null</b> if the option was not in the
+ * command line.
+ *
+ * @throws IllegalArgumentException if the option was not found in the
command line.
+ */
+ public String get(IUiOption k)
+ throws IllegalArgumentException
+ {
+ // what was the parsesd value of this opt
+ if ( legal_options.containsKey(k) ) {
+ return option_to_value.get(k);
+ }
+ throw new IllegalArgumentException("Option '" + k.pname() + "' is not
a legal option.");
+ }
+
+ /**
+ * Returns the map of all options found in the command, keyed on the
corresponding UiOption.
+ * @return Map of options found in the command line.
+ */
+ public Map<IUiOption, String> allOptions()
+ {
+ return option_to_value;
+ }
+
+ public int getInt(IUiOption k)
+ throws IllegalArgumentException,
+ NumberFormatException
+ {
+ // Note - get() checks for existance. parse() would have filled in
defaults.
+ return Integer.parseInt(get(k));
+ }
+
+ public long getLong(IUiOption k)
+ throws IllegalArgumentException,
+ NumberFormatException
+ {
+ // Note - get() checks for existance. parse() would have filled in
defaults.
+ return Long.parseLong(get(k));
+ }
+
+ public boolean getBoolean(IUiOption k)
+ throws IllegalArgumentException
+ {
+ // Note - get() checks for existance. parse() would have filled in
defaults.
+ // String values for boolean can be confusing because, Language. So
it's useful
+ // and friendly to be quite permissive:
+ // Any capitilaztion of true, t, yes, y, 1 --------> true
+ // Any capitilaztion of false, f, no, n, 0 --------> false
+
+ if ( k.noargs() && get(k) == null ) return true;
+
+ String v = get(k).toUpperCase();
+ if ( v.equals("TRUE") || v.equals("T") || v.equals("YES") ||
v.equals("Y") || v.equals("1") ) return true;
+ if ( v.equals("FALSE") || v.equals("F") || v.equals("NO") ||
v.equals("N") || v.equals("0") ) return false;
+ throw new IllegalArgumentException("Value is not true | false for
argument " + k.pname());
+ }
+
+ private void add(IUiOption k, String v)
+ {
+ if ( contains(k) ) {
+ throw new IllegalArgumentException("Duplicate argument " +
k.pname() + " not allowed.");
+ }
+ option_to_value.put(k,v);
+ }
+
+ private String justify(int leader, String txt)
+ {
+ int real_width = help_width - leader;
+ String blanks = String.format(("%" + leader + "s"), " ");
+
+ if ( txt.length() < real_width ) { // trivial case, the
string fits with no splits
+ return blanks + txt;
+ }
+
+ List<String> pieces_parts = new ArrayList<String>();
+ int nparts = txt.length() / real_width;
+ if ( txt.length() % real_width > 0 ) {
+ nparts++;
+ }
+
+ for ( int i = 0; i < nparts-1; i++ ) {
+ pieces_parts.add(txt.substring(0, real_width));
+ txt = txt.substring(real_width);
+ }
+ pieces_parts.add(txt);
+
+
+ StringBuffer sb = new StringBuffer();
+ for ( String s : pieces_parts ) {
+ sb.append(blanks);
+ sb.append(s);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Formats the options into a help screen.
+ * @return The formatted help string.
+ */
+ public String formatHelp(String commandName)
+ {
+ //
+ // Strategy
+ // - try to keep line length to witnin maybe 100 chars by wrapping
+ // - get width of widest opt to set first column
+ // - then set argname, required, and default
+ // - on a new line do justified description with indent
+ // - on last line show the example with indent
+ //
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("Usage:\n");
+ sb.append(" ");
+ sb.append(commandName);
+ sb.append(" [options]\n");
+ sb.append("Where options are:\n");
+
+ int len = 0;
+ for (IUiOption o: opts) {
+
+ int namelen = o.pname().length();
+ if ( o.sname() != null ) {
+ namelen += o.sname().length() + 3; // +1 for -, 1 for space, 1
for comma
+ }
+ len = Math.max(len, namelen);
+ }
+ String fmt1 = "%-" + (len) + "s"; // space for -- and another space
+ String fmt2 = "%-" + (len+3) + "s"; // A bit more for description and
example lines
+
+ for (IUiOption o: opts) {
+ sb.append("--");
+ String cmd = o.pname();
+ if ( o.sname() != null ) {
+ cmd = cmd + ", -" + o.sname();
+ }
+ sb.append(String.format(fmt1, cmd));
+ if ( o.argname() != null ) {
+ sb.append(" <");
+ sb.append(o.argname());
+ sb.append(">");
+ }
+ if ( o.required() ) {
+ sb.append(" (required)");
+ }
+ if ( o.optargs() ) {
+ sb.append(" Default: ");
+ sb.append(o.deflt());
+ }
+ if ( o.noargs() ) {
+ sb.append(" (no arguments)");
+ }
+ if ( o.description() != null ) {
+ sb.append("\n");
+ sb.append(justify(len+3,o.description()));
+ }
+ if ( o.example() != null ) {
+ sb.append("\n");
+ sb.append(String.format(fmt2, ""));
+ sb.append("Example: ");
+ sb.append(o.example());
+ }
+
+ sb.append("\n\n");
+ }
+ return sb.toString();
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ for ( IUiOption k : option_to_value.keySet() ) {
+ sb.append(k.pname());
+ sb.append("=");
+ sb.append(option_to_value.get(k));
+ sb.append(" ");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Make sure the arguments make sense
+ */
+ public void sanity()
+ {
+ /**
+ * If multiargs is true,
+ * noargs MUSt be false
+ * optargs MAY be true
+ * If noargs is true,
+ * multargs MUSt be false
+ * optargs MUSt be false
+ * default must be empty
+ * NOTE This is clumsy if the desired input comes from property
files.
+ * The reason being, Properties extend HashTable which
disallows
+ * null values (throws gratuitous NPE). So we'll make an
+ * assumption that noargs() options are implicitly boolean,
+ * and allow (but not require) any of the reasonable boolean
+ * representations as values for the default:
+ * true/false, t/f, yes/no, y/n, 1/0
+ * If optargs is true
+ * multargs MAY be true
+ * noargs MUST be false
+ * deflt must be non-null, non-empty-string
+ */
+
+ boolean error = false;
+ StringBuffer sb = new StringBuffer();
+ for ( IUiOption o : opts ) {
+ if ( o.multiargs() && o.noargs() ) {
+ if ( error ) sb.append("\n");
+ sb.append("Option '" );
+ sb.append(o.pname());
+ sb.append("': multiargs() is true but noargs() is also true.");
+ error = true;
+ continue;
+ }
+
+ if ( o.noargs() && o.optargs() ) {
+ if ( error ) sb.append("\n");
+ sb.append("Option '" );
+ sb.append(o.pname());
+ sb.append("': optargs() is true but noargs() is also true.");
+ error = true;
+ continue;
+ }
+
+ if ( o.noargs() && o.deflt() != null ) {
+ try {
+ getBoolean(o); // if this doesn't
throw the value is a boolean, which we allow
+ } catch ( IllegalArgumentException e ) {
+ if ( error ) sb.append("\n");
+ sb.append("Option '" );
+ sb.append(o.pname());
+ sb.append("': noargs() is true but a non-boolean default
is defined.");
+ error = true;
+ }
+ }
+
+ if ( o.optargs() && ( o.deflt() == null ) ) {
+ if ( error ) sb.append("\n");
+ sb.append("Option '" );
+ sb.append(o.pname());
+ sb.append("': optargs() is true but no default is provided.");
+ error = true;
+ continue;
+ }
+ }
+
+ if ( error ) {
+ throw new IllegalArgumentException(sb.toString());
+ }
+ }
+
+ private void addProperties()
+ {
+ // precondition, caller must insure properties exists
+ //
+ // Similar to the parse loop, only no need to parse for -- strings,
just get the (k, v) pair from the properties
+ //
+ for (String p : properties.stringPropertyNames()) {
+ IUiOption opt = name_to_option.get(p);
+ if ( opt == null ) {
+ throw new IllegalArgumentException("Illegal keyword for this
command: " + p);
+ }
+ if ( ! contains(opt) ) { // proceed only if we don't
have it
+ if ( opt.multiargs() ) {
+ // bop along to end, or next '-' collecting the arguments
+ //TODO - note, we don't have any multi-argument options in
DUCC right now
+ throw new IllegalArgumentException("multiargs() is not yet
implemented.");
+ } else {
+ String v = properties.getProperty(p);
+ if ( opt.noargs() ) { // must
have no arguments
+ if ( v == null ) {
+ add(opt, null);
+ } else {
+ try {
+ getBoolean(opt); //
throws if not boolean
+ add(opt, v);
+ } catch ( IllegalArgumentException e ) {
+ throw new IllegalArgumentException("Argument "
+ opt.pname() + ": no value allowed. Found " + v);
+ }
+ }
+ } else if ( opt.optargs() ) { // may
or may not have optional arguments
+ // deal with optional argument
+ if ( v == null ) {
+ add(opt, opt.deflt()); //
sanity checker insures deflt() is non-null
+ } else {
+ add(opt, v);
+ }
+
+ } else {
+ // Pick up a single argument, and next must start with
'-', otherwise its an error.
+ if ( v == null ) {
+ // nope, required argument is missing
+ throw new IllegalArgumentException("Missing
required value for argument " + opt.pname());
+ }
+ add(opt, v);
+ }
+ }
+
+ }
+ // else nothing, because the command-strings take precedence
+ }
+ }
+
+ private void addCommandLine()
+ {
+
+ int i = 0;
+ String k;
+ String v;
+ for ( i = 0; i < args.length; i++ ) {
+
+ // constant: at the top of the loop we must be poised at the next
'-' string
+ // must throw otherwise
+ if ( args[i].startsWith("--") ) {
+ k = args[i].substring(2);
+ } else if ( args[i].startsWith("-") ) {
+ k = args[i].substring(1);
+ } else {
+ throw new IllegalArgumentException("Unrecognized keywoard: "
+ args[i]);
+ }
+
+ IUiOption opt = name_to_option.get(k);
+ if ( opt == null ) {
+ throw new IllegalArgumentException("Illegal keyword for this
command: " + args[i]);
+ }
+
+ if ( opt.multiargs() ) {
+ // bop along to end, or next '-' collecting the arguments
+ //TODO - note, we don't have any multi-argument options in
DUCC right now
+ throw new IllegalArgumentException("multiargs() is not yet
implemented.");
+ } else {
+ if ( i+1 < args.length ) {
+ v = args[i+1];
+ } else {
+ v = null;
+ }
+ if ( opt.noargs() ) { // must
have no arguments
+ if ( v == null || isOption(v) ) {
+ add(opt, null);
+ } else {
+ throw new IllegalArgumentException("Argument " +
opt.pname() + ": no value allowed. Found " + v);
+ }
+ } else if ( opt.optargs() ) { // may or
may not have optional arguments
+ // deal with optional argument
+ if ( v == null || isOption(v) ) {
+ add(opt, opt.deflt()); // sanity
checker insures deflt() is non-null
+ } else {
+ add(opt, v);
+ i++;
+ }
+
+ } else {
+ // Pick up a single argument, and next must be an options,
else it's an error
+ if ( v == null || isOption(v) ) {
+ // nope, required argument is missing
+ throw new IllegalArgumentException("Missing required
value for argument " + opt.pname());
+ }
+ i++;
+ add(opt, v);
+ }
+ }
+ }
+ }
+
+ /**
+ * Final verification of the parsed command line.
+ *
+ * Checks that all required arguments are present.
+ */
+ public void verify()
+ {
+ for (IUiOption o : opts) {
+ if ( o.required() && ! contains(o) ) {
+ throw new IllegalArgumentException("Missing required argument
" + o.pname());
+ }
+ }
+ }
+
+ public void parse()
+ {
+ sanity();
+
+ if ( args != null ) addCommandLine();
+ if ( properties != null ) addProperties();
+
+ }
+
+}
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobMonitor.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobMonitor.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobMonitor.java
Mon Oct 27 18:21:39 2014
@@ -20,8 +20,8 @@ package org.apache.uima.ducc.cli;
import java.util.ArrayList;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
+//import org.apache.commons.cli.HelpFormatter;
+//import org.apache.commons.cli.Options;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.CancelReasons.CancelReason;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
@@ -55,13 +55,12 @@ public class DuccJobMonitor extends Ducc
System.exit(code);
}
- @Override
- public void help(Options options) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.setWidth(DuccUiConstants.help_width);
- formatter.printHelp(DuccJobMonitor.class.getName(), options);
- return;
- }
+ // @Override
+ // public void help(IUiOption[] options)
+ // {
+ // command_line.formatHelp(this.getClass().getName());
+ // return;
+ // }
@Override
public void cancel() {
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
Mon Oct 27 18:21:39 2014
@@ -341,6 +341,7 @@ public class DuccJobSubmit
*/
public static void main(String[] args) {
try {
+
DuccJobSubmit ds = new DuccJobSubmit(args, null);
boolean rc = ds.execute();
// If the return is 'true' then as best the API can tell, the
submit worked
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccManagedReservationMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccManagedReservationMonitor.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccManagedReservationMonitor.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccManagedReservationMonitor.java
Mon Oct 27 18:21:39 2014
@@ -20,8 +20,6 @@ package org.apache.uima.ducc.cli;
import java.util.ArrayList;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.CancelReasons.CancelReason;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
@@ -54,13 +52,13 @@ public class DuccManagedReservationMonit
System.exit(code);
}
- @Override
- public void help(Options options) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.setWidth(DuccUiConstants.help_width);
-
formatter.printHelp(DuccManagedReservationMonitor.class.getName(), options);
- return;
- }
+// @Override
+// public void help(IUiOption) {
+// HelpFormatter formatter = new HelpFormatter();
+// formatter.setWidth(DuccUiConstants.help_width);
+//
formatter.printHelp(DuccManagedReservationMonitor.class.getName(), options);
+// return;
+// }
@Override
public void cancel() {
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
Mon Oct 27 18:21:39 2014
@@ -18,31 +18,24 @@
*/
package org.apache.uima.ducc.cli;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.PosixParser;
+// import org.apache.commons.cli.CommandLine;
+// import org.apache.commons.cli.CommandLineParser;
+// import org.apache.commons.cli.HelpFormatter;
+// import org.apache.commons.cli.Options;
+// import org.apache.commons.cli.PosixParser;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.json.MonitorInfo;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
import org.apache.uima.ducc.common.utils.SynchronizedSimpleDateFormat;
import org.apache.uima.ducc.common.utils.Utils;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
-import com.google.gson.Gson;
-
public abstract class DuccMonitor {
protected static final int RC_SUCCESS = 0;
@@ -54,9 +47,11 @@ public abstract class DuccMonitor {
protected static final String StateCompleting = "Completing";
protected static final String StateCompleted = "Completed";
- private Options options = new Options();
+ protected CommandLine command_line = null;
+
+ // private Options options = new Options();
- private UiOption[] opts = new UiOption[0];
+ private IUiOption[] opts = new UiOption[0];
private String id = null;
@@ -83,18 +78,18 @@ public abstract class DuccMonitor {
private SynchronizedSimpleDateFormat sdf = new
SynchronizedSimpleDateFormat(
"dd/MM/yyyy HH:mm:ss");
- private UiOption[] optsSubmitJob = new UiOption[] { UiOption.Help,
+ private IUiOption[] optsSubmitJob = new UiOption[] { UiOption.Help,
UiOption.Debug, UiOption.Quiet, UiOption.Timestamp,
UiOption.JobId,
UiOption.CancelOnInterrupt, };
- private UiOption[] optsMonitorJob = new UiOption[] { UiOption.Help,
+ private IUiOption[] optsMonitorJob = new UiOption[] { UiOption.Help,
UiOption.Debug, UiOption.Quiet, UiOption.Timestamp,
UiOption.JobId, };
- private UiOption[] optsSubmitManagedReservation = new UiOption[] {
+ private IUiOption[] optsSubmitManagedReservation = new UiOption[] {
UiOption.Help, UiOption.Debug, UiOption.Quiet,
UiOption.Timestamp,
UiOption.ManagedReservationId,
UiOption.CancelOnInterrupt, };
- private UiOption[] optsMonitorManagedReservation = new UiOption[] {
+ private IUiOption[] optsMonitorManagedReservation = new UiOption[] {
UiOption.Help, UiOption.Debug, UiOption.Quiet,
UiOption.Timestamp,
UiOption.ManagedReservationId, };
@@ -107,7 +102,10 @@ public abstract class DuccMonitor {
initialize(context, submit, messageProcessor);
}
- public abstract void help(Options options);
+ public void help(IUiOption[] options)
+ {
+ System.out.println(command_line.formatHelp(this.getClass().getName()));
+ }
public abstract void cancel();
@@ -155,7 +153,7 @@ public abstract class DuccMonitor {
break;
}
}
- options = CliBase.makeOptions(opts);
+ // options = CliBase.makeOptions(opts);
// message processor
if (messageProcessor != null) {
this.messageProcessor = messageProcessor;
@@ -247,39 +245,39 @@ public abstract class DuccMonitor {
duccPropertiesResolver = DuccPropertiesResolver.getInstance();
// Parse
synchronized (DuccMonitor.class) {
- CommandLineParser parser = new PosixParser();
- CommandLine commandLine = parser.parse(options, args);
- if (commandLine.hasOption(DuccUiConstants.name_help)) {
- help(options);
- return RC_HELP;
- }
- if (commandLine.getOptions().length == 0) {
- help(options);
+ command_line = new CommandLine(args, opts);
+ try {
+ command_line.parse();
+ } catch ( IllegalArgumentException e ) {
+ System.out.println("Illegal arguments: " + e.getMessage());
+ help(opts);
+ return RC_HELP;
+ }
+
+ if (command_line.contains(UiOption.Help)) {
+ help(opts);
return RC_HELP;
}
- if (commandLine.hasOption(UiOption.Timestamp.pname())) {
+
+ if (command_line.contains(UiOption.Timestamp)) {
flag_timestamp.set(true);
}
- if (commandLine.hasOption(UiOption.Quiet.pname())) {
+ if (command_line.contains(UiOption.Quiet)) {
flag_info.set(false);
flag_error.set(false);
}
- if (commandLine.hasOption(UiOption.Debug.pname())) {
+ if (command_line.contains(UiOption.Debug)) {
flag_debug.set(true);
}
- if
(commandLine.hasOption(UiOption.CancelOnInterrupt.pname())) {
+ if (command_line.contains(UiOption.CancelOnInterrupt)) {
flag_cancel_on_interrupt.set(true);
}
- if (commandLine.hasOption(UiOption.JobId.pname())) {
- id =
commandLine.getOptionValue(UiOption.JobId.pname());
- } else if
(commandLine.hasOption(UiOption.ManagedReservationId
- .pname())) {
- id =
commandLine.getOptionValue(UiOption.ManagedReservationId
- .pname());
- } else {
- HelpFormatter formatter = new HelpFormatter();
- formatter.setWidth(110);
-
formatter.printHelp(DuccJobMonitor.class.getName(), options);
+ if (command_line.contains(UiOption.JobId)) {
+ id = command_line.get(UiOption.JobId);
+ } else if
(command_line.contains(UiOption.ManagedReservationId)) {
+ id =
command_line.get(UiOption.ManagedReservationId);
+ } else {
+
System.out.println(command_line.formatHelp(DuccJobMonitor.class.getName()));
return RC_HELP;
}
}
@@ -300,12 +298,15 @@ public abstract class DuccMonitor {
info(message.toString());
// Poll until finished
while (flag_observer.get()) {
- String json = getSingleLineStatus(urlString);
- if (json != null) {
- debug(json);
- Gson gson = new Gson();
- MonitorInfo monitorInfo = gson
- .fromJson(json,
MonitorInfo.class);
+ DuccEventHttpDispatcher dispatcher = new
DuccEventHttpDispatcher(urlString, urlTimeout);
+ MonitorInfo monitorInfo = (MonitorInfo)
dispatcher.dispatchJson(MonitorInfo.class);
+ // String json = getSingleLineStatus(urlString);
+ // if (json != null) {
+ // debug(json);
+ // Gson gson = new Gson();
+ // MonitorInfo monitorInfo = gson
+ // .fromJson(json,
MonitorInfo.class);
+ if ( monitorInfo != null ) {
int stateCount =
monitorInfo.stateSequence.size();
debug("states:" + stateCount);
if (stateCount <= 0) {
@@ -429,24 +430,24 @@ public abstract class DuccMonitor {
return retVal;
}
- private String getSingleLineStatus(String urlString) {
- String line = null;
- URL url = null;
- try {
- url = new URL(urlString);
- URLConnection uc = url.openConnection();
- uc.setReadTimeout(urlTimeout);
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- uc.getInputStream()));
- line = br.readLine();
- br.close();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return line;
- }
+// private String getSingleLineStatus(String urlString) {
+// String line = null;
+// URL url = null;
+// try {
+// url = new URL(urlString);
+// URLConnection uc = url.openConnection();
+// uc.setReadTimeout(urlTimeout);
+// BufferedReader br = new BufferedReader(new
InputStreamReader(
+// uc.getInputStream()));
+// line = br.readLine();
+// br.close();
+// } catch (MalformedURLException e) {
+// e.printStackTrace();
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
+// return line;
+// }
private class Killer extends Thread {
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceApi.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceApi.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceApi.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceApi.java
Mon Oct 27 18:21:39 2014
@@ -21,8 +21,6 @@ package org.apache.uima.ducc.cli;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
import org.apache.uima.ducc.common.Pair;
import org.apache.uima.ducc.common.utils.DuccProperties;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
@@ -111,7 +109,6 @@ public class DuccServiceApi
UiOption.Debug,
UiOption.Start,
UiOption.Instances,
- UiOption.Update,
UiOption.RoleAdministrator,
};
@@ -120,7 +117,6 @@ public class DuccServiceApi
UiOption.Debug,
UiOption.Stop,
UiOption.Instances,
- UiOption.Update,
UiOption.RoleAdministrator,
};
@@ -192,14 +188,13 @@ public class DuccServiceApi
//
// generate modify options, same as registration options, only with
the verb
// Modify insteady of Register, and on extra option, Activate.
- // The length here: same as registration options,
- // plus 1 for Activate,
+ // The length here, based on registration options:
// minus 1 for ProcessDD
// minus 1 for ServiceRequestEndpoint
// plus 1 for RoleAdministrator
- // ==> no lengh admustments
+ // ==> -1 length
//
- modify_options = new UiOption[registration_options.length];
+ modify_options = new UiOption[registration_options.length - 1];
int i = 0;
for ( UiOption o : registration_options ) {
@@ -211,7 +206,7 @@ public class DuccServiceApi
modify_options[i++] = o;
}
modify_options[i++] = UiOption.RoleAdministrator;
- modify_options[i++] = UiOption.Activate;
+ // modify_options[i++] = UiOption.Activate;
}
private Pair<Integer, String> getId(UiOption opt)
@@ -273,15 +268,15 @@ public class DuccServiceApi
}
- private boolean getActivate()
- {
- return cli_props.containsKey(UiOption.Activate.pname());
- }
-
- private boolean getUpdate()
- {
- return cli_props.containsKey(UiOption.Update.pname());
- }
+// private boolean getActivate()
+// {
+// return cli_props.containsKey(UiOption.Activate.pname());
+// }
+
+// private boolean getUpdate()
+// {
+// return cli_props.containsKey(UiOption.Update.pname());
+// }
private void setLinger()
{
@@ -523,10 +518,10 @@ public class DuccServiceApi
ev.setAdministrative(asAdministrator);
int instances = getInstances(-1);
- boolean update = getUpdate();
+ //boolean update = getUpdate();
ev.setInstances(instances);
- ev.setUpdate(update);
+ //ev.setUpdate(update);
try {
return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
@@ -557,10 +552,10 @@ public class DuccServiceApi
ev.setAdministrative(asAdministrator);
int instances = getInstances(-1);
- boolean update = getUpdate();
+ //boolean update = getUpdate();
ev.setInstances(instances);
- ev.setUpdate(update);
+ //ev.setUpdate(update);
try {
return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
@@ -624,7 +619,7 @@ public class DuccServiceApi
ServiceModifyEvent ev = new ServiceModifyEvent(user, id.first(),
id.second(), mods, auth_block, CliVersion.getVersion());
int instances = getInstances(-1);
Trinary autostart = getAutostart();
- boolean activate = getActivate();
+ // boolean activate = getActivate();
String pingArguments =
cli_props.getProperty(UiOption.ServicePingArguments.pname());
String pingClass =
cli_props.getProperty(UiOption.ServicePingClass.pname());
String pingClasspath =
cli_props.getProperty(UiOption.ServicePingClasspath.pname());
@@ -641,8 +636,8 @@ public class DuccServiceApi
default:
break;
}
- if ( activate ) mods.setProperty("activate", "true");
- else mods.setProperty("activate", "false");
+// if ( activate ) mods.setProperty("activate", "true");
+// else mods.setProperty("activate", "false");
if ( pingArguments != null )
mods.setProperty("service_ping_arguments", pingArguments);
if ( pingClass != null ) mods.setProperty("service_ping_class"
, pingClass);
@@ -777,34 +772,25 @@ public class DuccServiceApi
void help()
{
- HelpFormatter formatter = new HelpFormatter();
- Options options;
+ CommandLine cl;
+
+ cl = new CommandLine(null, registration_options);
+ System.out.println(cl.formatHelp("--------------- Registr Options
-------------"));
+
+ cl = new CommandLine(null, unregister_options);
+ System.out.println(cl.formatHelp("\n\n------------- Unregister Options
------------------"));
+
+ cl = new CommandLine(null, start_options);
+ System.out.println(cl.formatHelp("\n\n------------- Start Options
------------------"));
+
+ cl = new CommandLine(null, stop_options);
+ System.out.println(cl.formatHelp("\n\n------------- Stop Options
------------------"));
- formatter.setWidth(IUiOptions.help_width);
+ cl = new CommandLine(null, modify_options);
+ System.out.println(cl.formatHelp("\n\n------------- Modify Options
------------------"));
- System.out.println("------------- Register Options
------------------");
- options = makeOptions(registration_options);
- formatter.printHelp(this.getClass().getName(), options);
-
- System.out.println("\n\n------------- Unregister Options
------------------");
- options = makeOptions(unregister_options);
- formatter.printHelp(this.getClass().getName(), options);
-
- System.out.println("\n\n------------- Start Options
------------------");
- options = makeOptions(start_options);
- formatter.printHelp(this.getClass().getName(), options);
-
- System.out.println("\n\n------------- Stop Options
------------------");
- options = makeOptions(stop_options);
- formatter.printHelp(this.getClass().getName(), options);
-
- System.out.println("\n\n------------- Modify Options
------------------");
- options = makeOptions(modify_options);
- formatter.printHelp(this.getClass().getName(), options);
-
- System.out.println("\n\n------------- Query Options
------------------");
- options = makeOptions(query_options);
- formatter.printHelp(this.getClass().getName(), options);
+ cl = new CommandLine(null, modify_options);
+ System.out.println(cl.formatHelp("\n\n------------- Query Options
------------------"));
System.exit(1);
}
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IDuccMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IDuccMonitor.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IDuccMonitor.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IDuccMonitor.java
Mon Oct 27 18:21:39 2014
@@ -18,11 +18,9 @@
*/
package org.apache.uima.ducc.cli;
-import org.apache.commons.cli.Options;
-
public interface IDuccMonitor {
- public void help(Options options);
+ //public void help(IUiOption[] options);
public void cancel();
public String getUrl(String id);
}
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOption.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOption.java?rev=1634635&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOption.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOption.java
Mon Oct 27 18:21:39 2014
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ducc.cli;
+
+/**
+ * This interface defines the rules by which every command-line token must
conform.
+ *
+ * The interface is intended (but not required) to be used as a base
+ * for an Enum whose members define each keyword token. For example:
+ * <code>
+ * enum UiOption
+ * implements IUiOption
+ * {
+ * Activate {
+ * public String pname() { return "activate"; }
+ * public String argname() { return null; }
+ * public boolean optargs() { return true; }
+ * public String description() { return "If present, apply current
service updates to the running instances.."; }
+ * public String example() { return null; }
+ * public String label() { return name(); }
+ * },
+ *
+ * AllInOne {
+ * public String pname() { return "all_in_one"; }
+ * public String argname() { return "local|remote"; }
+ * public String description() { return "Run driver and pipeline in
single process."; }
+ * public String example() { return null; }
+ * public String label() { return name(); }
+ * },
+ * public boolean multiargs() { return false; } // the option can have
>1 arg
+ * public boolean required() { return false; } // this option is
required
+ * public String deflt() { return null; } // default, or ""
+ * public String label() { return null; } // Parameter name for
label in web form
+ * public String sname() { return null; } // short name of option
+ * public boolean optargs() { return false; } // is the argument
optional?
+ *
+ * public String makeDesc()
+ * {
+ * if ( example() == null ) return description();
+ * return description() + "\nexample: " + example();
+ * }
+ * };
+ *
+ * </code>
+ */
+public interface IUiOption
+{
+
+ /**
+ * Some sanity checking is done by the parser before parsing starts, to
insure
+ * consistency of the parse and argument specification:
+ *
+ * If multiargs is true,
+ * noargs MUSt be false
+ * optargs MAY be true
+ * If noargs is true,
+ * multargs MUSt be false
+ * optargs MUSt be false
+ * If optargs is true
+ * multargs MAY be true
+ * noargs MUST be false
+ * deflt must be non-null, non-empty-string
+ */
+ // Each option must implement the first few methods,
+ public String pname(); // name of the option, e.g.
--description
+ public String argname(); // type of its argument, or null if
none
+ public String description(); // description of what it is
+ public String example(); // example of usage
+ public boolean multiargs(); // the option can have >1 arg
+ public boolean required(); // this option is required
+ public boolean optargs(); // the arguments are optional
+ public boolean noargs(); // no arguments allowed
+ public String deflt(); // default, if any
+ public String label(); // Parameter name for label in web form
+ public String sname(); // short name of option, if any
+
+}
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java?rev=1634635&r1=1634634&r2=1634635&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
Mon Oct 27 18:21:39 2014
@@ -45,18 +45,34 @@ public interface IUiOptions
static final int help_width = 120;
+ //
+ // NOTE regarding noargs() and optargs: if the option can occur in a
properties file
+ // the option should be configured with
+ // optargs true
+ // deflt "true"
+ // or
+ // deflt ""
+ // because the Java properties class will NPE if you have a key and
no value. This
+ // Java restriction makes it hard to create a true boolean value.
+ //
+ // This doesn't matter if the properties is a file because the
properties reader
+ // inserts a "" which we interpret as "no argument provided", but in
the API,
+ // you want to provide a meaningful value, or no value, not "".
+ //
enum UiOption
+ implements IUiOption
{
- Activate {
- public String pname() { return "activate"; }
- public String argname() { return null; }
- public String description() { return "If present, apply current
service updates to the running instances.."; }
- public String example() { return null; }
+ Administrators {
+ public String pname() { return "administrators"; }
+ public String argname() { return "list of ids"; }
+ public String description() { return "Blank-delimited list of
userids allowed to manage this service."; }
+ public String example() { return "bob mary jimbo"; }
public String label() { return name(); }
},
+
AllInOne {
- public String pname() { return "all_in_one"; }
+ public String pname() { return "all_in_one"; }
public String argname() { return "local|remote"; }
public String description() { return "Run driver and pipeline in
single process."; }
public String example() { return null; }
@@ -65,14 +81,15 @@ public interface IUiOptions
AttachConsole {
public String pname() { return "attach_console"; }
- public String argname() { return null; }
+ public boolean optargs() { return true; }
+ public String deflt() { return "true"; }
public String description() { return "If specified, redirect
remote stdout and stderr to the local submitting console."; }
public String example() { return null; }
public String label() { return name(); }
},
Autostart {
- public String pname() { return "autostart"; }
+ public String pname() { return "autostart"; }
public String argname() { return "boolean: true or false"; }
public String description() { return "If True, start the service
when DUCC starts."; }
public String example() { return null; }
@@ -81,7 +98,8 @@ public interface IUiOptions
CancelOnInterrupt {
public String pname() { return
SpecificationProperties.key_cancel_on_interrupt; }
- public String argname() { return null; }
+ public boolean optargs() { return true; }
+ public String deflt() { return "true"; }
public String description() { return "Cancel on interrupt
(Ctrl-C). Implies "+WaitForCompletion.pname(); }
public String example() { return null; }
public String label() { return name(); }
@@ -106,7 +124,7 @@ public interface IUiOptions
Debug {
public String pname() { return "debug"; }
- public String argname() { return null; }
+ public boolean noargs() { return true; }
public String description() { return "Enable CLI Debugging
messages."; }
public String example() { return null; }
public String label() { return null; }
@@ -133,7 +151,7 @@ public interface IUiOptions
public String argname() { return "string"; }
public String description() { return "Description of the run."; }
public String example() { return "My excellent job!"; }
- public String deflt() { return "none"; }
+ public String deflt() { return "[Empty Description]"; }
public String label() { return "Description"; }
},
@@ -180,20 +198,12 @@ public interface IUiOptions
Help {
public String pname() { return "help"; }
- public String argname() { return null; }
+ public boolean noargs() { return true; }
public String description() { return "Print this help message"; }
public String example() { return null; }
public String label() { return null; }
},
- Administrators {
- public String pname() { return "administrators"; }
- public String argname() { return "list of ids"; }
- public String description() { return "Blank-delimited list of
userids allowed to manage this service."; }
- public String example() { return "bob mary jimbo"; }
- public String label() { return name(); }
- },
-
Instances {
public String pname() { return "instances"; }
public String argname() { return "integer"; }
@@ -247,8 +257,8 @@ public interface IUiOptions
Jvm {
public String pname() { return
JobSpecificationProperties.key_jvm; }
public String argname() { return "path-name-to-java"; }
- public String description() { return "The jvm to use. Must be a
full path to the 'java' executable. Default is\n the jvm that DUCC is
using."; }
- public String example() { return null; }
+ public String description() { return "The jvm to use. Must be a
full path to the 'java' executable. Default is the jvm that DUCC is using."; }
+ public String example() { return
"/opt/vendor/jdk-1.7/bin/java"; }
public String label() { return "Jvm"; }
},
@@ -289,6 +299,8 @@ public interface IUiOptions
Quiet {
public String pname() { return "quiet"; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
+ public String deflt() { return "true"; }
public String description() { return "Disable CLI Informational
messages."; }
public String example() { return null; }
public String label() { return null; }
@@ -297,6 +309,8 @@ public interface IUiOptions
Register {
public String pname() { return "register"; }
public String argname() { return "specification-file
(optional)"; }
+ public boolean optargs() { return true; }
+ public String deflt() { return ""; } // "" is correct
public String description() { return "Register a service."; }
public String example() { return null; }
public String label() { return name(); }
@@ -353,6 +367,7 @@ public interface IUiOptions
ServiceTypeCustom {
public String pname() { return
ServiceRequestProperties.key_service_type_custom; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return "Service type - internally
generated"; }
public String example() { return null; }
public String label() { return null; }
@@ -361,6 +376,7 @@ public interface IUiOptions
ServiceTypeOther {
public String pname() { return
ServiceRequestProperties.key_service_type_other; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return "Service type - internally
generated"; }
public String example() { return null; }
public String label() { return null; }
@@ -369,6 +385,7 @@ public interface IUiOptions
ServiceTypeUima {
public String pname() { return
ServiceRequestProperties.key_service_type_uima; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return "Service type - internally
generated"; }
public String example() { return null; }
public String label() { return null; }
@@ -426,6 +443,7 @@ public interface IUiOptions
// generated
public String pname() { return
JobRequestProperties.key_submitter_pid_at_host; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return null; }
public String example() { return null; }
public String label() { return null; }
@@ -590,6 +608,8 @@ public interface IUiOptions
Query {
public String pname() { return "query"; }
public String argname() { return "service-id-or-endpoint
(optional)" ; }
+ public boolean optargs() { return true; }
+ public String deflt() { return ""; } // "" is correct,
interpreted as all
public String description() { return "Query a registered service,
or all." ; }
public String example() { return null; }
public String label() { return name(); }
@@ -624,7 +644,7 @@ public interface IUiOptions
RoleAdministrator {
public String pname() { return
JobSpecificationProperties.key_role_administrator; }
- public String argname() { return null; }
+ public boolean noargs() { return true; }
public String description() { return "Act in the capacity of DUCC
administrator."; }
public String example() { return null; }
public String label() { return null; }
@@ -668,6 +688,7 @@ public interface IUiOptions
// generated, not public
public String pname() { return
JobSpecificationProperties.key_signature; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return null; }
public String example() { return null; }
public String label() { return null; }
@@ -686,6 +707,7 @@ public interface IUiOptions
// generated, not public
public String pname() { return
JobSpecificationProperties.key_submit_errors; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return null; }
public String example() { return null; }
public String label() { return null; }
@@ -695,14 +717,16 @@ public interface IUiOptions
// generated, not public
public String pname() { return
JobSpecificationProperties.key_submit_warnings; }
public String argname() { return null; }
+ public boolean optargs() { return true; }
public String description() { return null; }
public String example() { return null; }
public String label() { return null; }
},
-
+
SuppressConsoleLog {
public String pname() { return "suppress_console_log"; }
public String argname() { return null; }
+ public boolean noargs() { return true; }
public String description() { return "Do not copy stdout to a log
file."; }
public String example() { return null; }
public String label() { return name(); }
@@ -711,6 +735,7 @@ public interface IUiOptions
Timestamp {
public String pname() { return "timestamp"; }
public String argname() { return null; }
+ public boolean noargs() { return true; }
public String description() { return "Enables timestamp on monitor
messages."; }
public String example() { return null; }
public String label() { return "ProcessTimestamp"; }
@@ -724,14 +749,6 @@ public interface IUiOptions
public String label() { return null; }
},
- Update {
- public String pname() { return "update"; }
- public String argname() { return null; }
- public String description() { return "If specified, update service
registry with accompanying parameters."; }
- public String example() { return null; }
- public String label() { return null; }
- },
-
User {
public String pname() { return
JobSpecificationProperties.key_user; };
public String argname() { return "userid"; }
@@ -742,6 +759,8 @@ public interface IUiOptions
WaitForCompletion {
public String pname() { return "wait_for_completion"; }
+ public boolean optargs() { return true; }
+ public String deflt() { return "true"; }
public String argname() { return null; }
public String description() { return "Do not exit until job is
completed."; }
public String example() { return null; }
@@ -757,24 +776,16 @@ public interface IUiOptions
public String label() { return "WorkingDirectory"; }
},
;
-
- // Each option must implement the first few methods,
- public abstract String pname(); // name of the option,
e.g. --description
- public abstract String argname(); // type of its argument,
or null if none
- public abstract String description(); // description of what it
is
- public abstract String example(); // example of usage
+
+ public String argname() { return null; } // the type of argument,
if any
public boolean multiargs() { return false; } // the option can have >1
arg
- public boolean required() { return false; } // this option is required
- public String deflt() { return null; } // default, or ""
+ public boolean required() { return false; } // this option must be
specified in the command line
+ public String deflt() { return null; } // default, required if
optargs == true
public String label() { return null; } // Parameter name for
label in web form
public String sname() { return null; } // short name of option
-
- public String makeDesc()
- {
- if ( example() == null ) return description();
- return description() + "\nexample: " + example();
- }
-
+ public boolean optargs() { return false; } // this option takes 0 or
more arguments
+ public boolean noargs() { return false; } // this option takes no
arguments
+
};
public enum ClasspathOrderParms