You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2013/03/12 19:23:01 UTC
svn commit: r1455662 [1/2] - in /uima/sandbox/uima-ducc/trunk:
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/
uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/
uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ uima-ducc-sm/src/main...
Author: challngr
Date: Tue Mar 12 18:23:00 2013
New Revision: 1455662
URL: http://svn.apache.org/r1455662
Log:
UIMA-2687
Modify the ServiceApi to be consistent with the rest of the API. This also brings in
user authentication via crypto because the now-common code requires it.
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceDescription.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IServiceReply.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/ServiceDescription.java
Modified:
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/DuccJobSubmit.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/DuccServiceSubmit.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-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ApiHandler.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/ServiceManagerComponent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/event/ServiceManagerEventListener.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/AServiceRequest.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceModifyEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceQueryEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceQueryReplyEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceRegisterEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceReplyEvent.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
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/ServiceUnregisterEvent.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/sm/IService.java
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=1455662&r1=1455661&r2=1455662&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 Tue Mar 12 18:23:00 2013
@@ -156,16 +156,16 @@ public abstract class CliBase
/*
* resolve ${defaultBrokerURL} in service dependencies - must fail if resolution needed but can't resolve
*/
- boolean resolve_service_dependencies(String endpoint, Properties props)
+ boolean resolve_service_dependencies(String endpoint)
{
- String jvmargs = props.getProperty(UiOption.ProcessJvmArgs.pname());
+ String jvmargs = cli_props.getProperty(UiOption.ProcessJvmArgs.pname());
Properties jvmprops = DuccUiUtilities.jvmArgsToProperties(jvmargs);
- String deps = props.getProperty(UiOption.ServiceDependency.pname());
+ String deps = cli_props.getProperty(UiOption.ServiceDependency.pname());
try {
deps = DuccUiUtilities.resolve_service_dependencies(endpoint, deps, jvmprops);
if ( deps != null ) {
- props.setProperty(UiOption.ServiceDependency.pname(), deps);
+ cli_props.setProperty(UiOption.ServiceDependency.pname(), deps);
}
return true;
} catch ( Throwable t ) {
@@ -311,10 +311,18 @@ public abstract class CliBase
usage(null);
}
- // Load the specificaiton file, if given on the command line
- String spec = UiOption.Specification.pname();
- if ( commandLine.hasOption(spec) ) {
- String val = commandLine.getOptionValue(spec);
+ // Load the specificaiton file, if given on the command line. Note that registration
+ // bypasses the somewhat redundant --specification kw so we check two options.
+ String spec1 = UiOption.Specification.pname();
+ String val = null;
+ if ( commandLine.hasOption(spec1) ) {
+ val = commandLine.getOptionValue(spec1);
+ }
+ String spec2 = UiOption.Register.pname();
+ if ( commandLine.hasOption(spec2) ) {
+ val = commandLine.getOptionValue(spec2);
+ }
+ if ( val != null ) {
File file = new File(val);
FileInputStream fis = new FileInputStream(file);
cli_props.load(fis);
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=1455662&r1=1455661&r2=1455662&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 Tue Mar 12 18:23:00 2013
@@ -356,7 +356,7 @@ public class DuccJobSubmit
/*
* resolve ${defaultBrokerURL} in service dependencies - must fail if resolution needed but can't resolve
*/
- if ( ! resolve_service_dependencies(null, jobRequestProperties) ) {
+ if ( ! resolve_service_dependencies(null) ) {
return false;
}
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=1455662&r1=1455661&r2=1455662&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 Tue Mar 12 18:23:00 2013
@@ -18,32 +18,21 @@
*/
package org.apache.uima.ducc.cli;
-import java.io.File;
-import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.apache.uima.ducc.common.IDucc;
import org.apache.uima.ducc.common.Pair;
import org.apache.uima.ducc.common.utils.DuccProperties;
-import org.apache.uima.ducc.common.utils.Utils;
-import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
-import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
import org.apache.uima.ducc.transport.event.ServiceModifyEvent;
import org.apache.uima.ducc.transport.event.ServiceQueryEvent;
-import org.apache.uima.ducc.transport.event.ServiceQueryReplyEvent;
import org.apache.uima.ducc.transport.event.ServiceRegisterEvent;
-import org.apache.uima.ducc.transport.event.ServiceReplyEvent;
import org.apache.uima.ducc.transport.event.ServiceStartEvent;
import org.apache.uima.ducc.transport.event.ServiceStopEvent;
import org.apache.uima.ducc.transport.event.ServiceUnregisterEvent;
-import org.apache.uima.ducc.transport.event.sm.IService;
+import org.apache.uima.ducc.transport.event.sm.IService.ServiceType;
+import org.apache.uima.ducc.transport.event.sm.IService.Trinary;
+import org.apache.uima.ducc.transport.event.sm.IServiceReply;
/**
@@ -51,404 +40,24 @@ import org.apache.uima.ducc.transport.ev
*/
public class DuccServiceApi
- implements IService,
- IServiceApi
+ extends CliBase
{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- String ducc_home = null;
-
- DuccProperties ducc_properties = null;
- Properties jvmargs = null; // -D vars from jvm args, as properties
-
- //String broker = null;
- //String jms_provider = "activemq";
- //String endpoint_name = "ducc.sm.request.endpoint";
- //String endpoint_type = "ducc.sm.request.endpoint.type";
- DuccEventHttpDispatcher dispatcher;
-
String sm_port = "ducc.sm.http.port";
String sm_host = "ducc.sm.http.node";
String endpoint = null;
- boolean debug = false;
-
- static boolean init_done = false;
-
public DuccServiceApi()
{
}
- static void usage(String msg)
+ private Pair<Integer, String> getId(UiOption opt)
{
- if ( msg != null ) {
- System.out.println(msg);
- }
- System.out.println("Usage:");
- System.exit(1);
- }
- static void usage(Options options)
- {
- HelpFormatter formatter = new HelpFormatter();
- formatter.setWidth(DuccUiConstants.help_width);
- formatter.printHelp(DuccServiceApi.class.getName(), options);
- System.exit(1);
- }
+ String sid = cli_props.getProperty(opt.pname());
- @SuppressWarnings("static-access")
- private void addOptions(Options options)
- {
- //
- // Verbs here
- //
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Register.decode())
- .withDescription(ServiceVerb.Register.description())
- .withArgName (ServiceVerb.Register.argname())
- .hasOptionalArg ()
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Unregister.decode())
- .withDescription(ServiceVerb.Unregister.description())
- .withArgName (ServiceVerb.Unregister.argname())
- .hasArg (true)
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Start.decode())
- .withDescription(ServiceVerb.Start.description())
- .withArgName (ServiceVerb.Start.argname())
- .hasArg (true)
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Stop.decode())
- .withDescription(ServiceVerb.Stop.description())
- .withArgName (ServiceVerb.Stop.argname())
- .hasArg (true)
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Modify.decode())
- .withDescription(ServiceVerb.Modify.description())
- .withArgName (ServiceVerb.Modify.argname())
- .hasArg (true)
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Query.decode())
- .withDescription(ServiceVerb.Query.description())
- .hasOptionalArg()
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Debug.decode())
- .withDescription(ServiceVerb.Debug.description())
- .hasArg (false)
- .create ()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceVerb.Help.decode())
- .withDescription(ServiceVerb.Help.description())
- .hasArg (false)
- .create ()
- );
-
- //
- // Options here
- //
- options.addOption(OptionBuilder
- .withLongOpt (ServiceOptions.Autostart.decode())
- .withDescription(ServiceOptions.Autostart.description())
- .withArgName (ServiceOptions.Autostart.argname())
- .withDescription("Change autostart setting for registered service.")
- .hasArg(true)
- .create()
- );
-
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceOptions.Instances.decode())
- .withDescription(ServiceOptions.Instances.description())
- .withArgName (ServiceOptions.Instances.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceOptions.Activate.decode())
- .withDescription(ServiceOptions.Activate.description())
- .withArgName (ServiceOptions.Activate.argname())
- .hasArg(false)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (ServiceOptions.Update.decode())
- .withDescription(ServiceOptions.Update.description())
- .withArgName (ServiceOptions.Update.argname())
- .hasArg(false)
- .create()
- );
-
-
- //
- // Services options that more correctly belong in properties file here
- //
- // description
- // process_DD
- // process_memory_size
- // process_classpath
- // process_jvm_args
- // process_environment
- // process_failures_limit
- // scheduling_class
- // working directory
- // log_directory
- // jvm
- // service_dependency
- // Other directives are not supported for registered services.
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ClasspathOrder.decode())
- .withDescription(RegistrationOption.ClasspathOrder.description())
- .withArgName (RegistrationOption.ClasspathOrder.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.Description.decode())
- .withDescription(RegistrationOption.Description.description())
- .withArgName (RegistrationOption.Description.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessDD.decode())
- .withDescription(RegistrationOption.ProcessDD.description())
- .withArgName (RegistrationOption.ProcessDD.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessMemorySize.decode())
- .withDescription(RegistrationOption.ProcessMemorySize.description())
- .withArgName (RegistrationOption.ProcessMemorySize.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessClasspath.decode())
- .withDescription(RegistrationOption.ProcessClasspath.description())
- .withArgName (RegistrationOption.ProcessClasspath.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessJvmArgs.decode())
- .withDescription(RegistrationOption.ProcessJvmArgs.description())
- .withArgName (RegistrationOption.ProcessJvmArgs.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessEnvironment.decode())
- .withDescription(RegistrationOption.ProcessEnvironment.description())
- .withArgName (RegistrationOption.ProcessEnvironment.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ProcessFailuresLimit.decode())
- .withDescription(RegistrationOption.ProcessFailuresLimit.description())
- .withArgName (RegistrationOption.ProcessFailuresLimit.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.SchedulingClass.decode())
- .withDescription(RegistrationOption.SchedulingClass.description())
- .withArgName (RegistrationOption.SchedulingClass.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.WorkingDirectory.decode())
- .withDescription(RegistrationOption.WorkingDirectory.description())
- .withArgName (RegistrationOption.WorkingDirectory.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.LogDirectory.decode())
- .withDescription(RegistrationOption.LogDirectory.description())
- .withArgName (RegistrationOption.LogDirectory.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.Jvm.decode())
- .withDescription(RegistrationOption.Jvm.description())
- .withArgName (RegistrationOption.Jvm.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServiceDependency.decode())
- .withDescription(RegistrationOption.ServiceDependency.description())
- .withArgName (RegistrationOption.ServiceDependency.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServiceLinger.decode())
- .withDescription(RegistrationOption.ServiceLinger.description())
- .withArgName (RegistrationOption.ServiceLinger.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServiceRequestEndpoint.decode())
- .withDescription(RegistrationOption.ServiceRequestEndpoint.description())
- .withArgName (RegistrationOption.ServiceRequestEndpoint.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServicePingClass.decode())
- .withDescription(RegistrationOption.ServicePingClass.description())
- .withArgName (RegistrationOption.ServicePingClass.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServicePingClasspath.decode())
- .withDescription(RegistrationOption.ServicePingClasspath.description())
- .withArgName (RegistrationOption.ServicePingClasspath.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServicePingJvmArgs.decode())
- .withDescription(RegistrationOption.ServicePingJvmArgs.description())
- .withArgName (RegistrationOption.ServicePingJvmArgs.argname())
- .hasArg(true)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServicePingDoLog.decode())
- .withDescription(RegistrationOption.ServicePingDoLog.description())
- .withArgName (RegistrationOption.ServicePingDoLog.argname())
- .hasArg(false)
- .create()
- );
-
- options.addOption(OptionBuilder
- .withLongOpt (RegistrationOption.ServicePingTimeout.decode())
- .withDescription(RegistrationOption.ServicePingTimeout.description())
- .withArgName (RegistrationOption.ServicePingTimeout.argname())
- .hasArg(true)
- .create()
- );
- }
-
- synchronized protected void init()
- {
-
- if ( init_done ) return;
-
- ducc_home = Utils.findDuccHome();
- if ( ducc_home == null ) {
- usage("DUCC_HOME must be set.");
- }
-
- String propsfile = ducc_home + "/resources/ducc.properties";
- try {
- ducc_properties = new DuccProperties();
- ducc_properties.load(propsfile);
-
- String host = ducc_properties.getStringProperty(sm_host);
- String port = ducc_properties.getStringProperty(sm_port);
-
- if ( host == null ) {
- throw new IllegalStateException(sm_host + " is not set in ducc.properties");
- }
-
- if ( port == null ) {
- throw new IllegalStateException(sm_port + " is not set in ducc.properties");
- }
-
- String targetUrl = "http://"+ host + ":" + port + "/sm";
- dispatcher = new DuccEventHttpDispatcher(targetUrl);
-
-// String en = ducc_properties.getStringProperty(endpoint_name);
-// String et = ducc_properties.getStringProperty(endpoint_type);
-// endpoint = jms_provider
-// + ":"
-// + et
-// + ":"
-// + en;
-
-// broker = ducc_properties.get("ducc.broker.protocol")
-// + "://"
-// + ducc_properties.get("ducc.broker.hostname")
-// + ":"
-// + ducc_properties.get("ducc.broker.port");
-// String decoration = ducc_properties.getStringProperty("ducc.broker.url.decoration");
-// if ( decoration != null ) {
-// broker = broker
-// + "?"
-// + decoration;
-// }
- } catch ( Throwable t ) {
- usage("Error loading configuration: " + t.getMessage());
- }
-
-// if ( debug ) {
-// System.out.println("DUCC_HOME : " + ducc_home);
-// System.out.println("SM Endpoint : " + endpoint);
-// System.out.println("Broker : " + broker);
-// }
-
- init_done = true;
- }
-
- private Pair<Integer, String> getId(CommandLine cl, ServiceVerb verb)
- {
- String sid = cl.getOptionValue(verb.decode());
if ( sid == null ) {
- throw new IllegalArgumentException("Missing id for --" + verb.decode() + ".");
+ throw new IllegalArgumentException("Missing service id: --id <id or endpoint>");
}
int id = -1;
@@ -464,172 +73,73 @@ public class DuccServiceApi
throw new IllegalArgumentException("Invalid id; must be numeric or start with " + ServiceType.UimaAs.decode() + " or " + ServiceType.Custom.decode() + ".");
}
- private int getInstances(CommandLine cl, int dflt)
- {
- String nstncs = cl.getOptionValue(ServiceOptions.Instances.decode());
- if ( nstncs == null ) {
- return dflt;
- }
-
- int instances = 0;
- try {
- instances = Integer.parseInt(nstncs);
- } catch ( NumberFormatException e ) {
- System.out.println (ServiceOptions.Instances.decode() + " " + nstncs + " is not numeric.");
- doExit(1);
- }
- if ( instances <= 0 ) {
- System.out.println(ServiceOptions.Instances.decode() + " " + nstncs + " must be > 0");
- doExit(1);
- }
-
- return instances;
- }
-
- private Trinary getAutostart(CommandLine cl)
+ private Trinary getAutostart()
{
- String auto = cl.getOptionValue(ServiceOptions.Autostart.decode(), null);
+ String auto = cli_props.getStringProperty(UiOption.Autostart.pname(), null);
if ( auto == null ) {
return Trinary.Unset;
}
+ boolean val = Boolean.parseBoolean(auto);
- Trinary answer = Trinary.encode(auto);
+ Trinary answer = Trinary.encode(val ? "true" : "false");
if ( answer == Trinary.Unset ) {
- System.out.println("--" + ServiceOptions.Autostart.decode() + " " + auto + " is not 'true' or 'false'");
- doExit(1);
+ throw new IllegalArgumentException("--" + UiOption.Autostart.pname() + " " + auto + " is not 'true' or 'false'");
}
return answer;
}
- private boolean getActivate(CommandLine cl)
+ private int getInstances(int dflt)
{
- return cl.hasOption(ServiceOptions.Activate.decode());
- }
+ String inst = cli_props.getProperty(UiOption.Instances.pname());
+ if ( inst == null ) return dflt;
- private boolean getUpdate(CommandLine cl)
- {
- return cl.hasOption(ServiceOptions.Update.decode());
- }
+ int instances;
+ try {
+ instances = Integer.parseInt(inst);
+ } catch ( NumberFormatException e ) {
+ throw new IllegalArgumentException(UiOption.Instances.pname() + " " + inst + " is not numeric.");
+ }
- private void overrideProperties(CommandLine cl, DuccProperties props, RegistrationOption opt)
- {
+ if ( instances <= 0 ) {
+ throw new IllegalArgumentException(UiOption.Instances.pname() + " " + inst + " must be > 0");
+ }
- String k = opt.decode();
- String v = cl.getOptionValue(k, null);
- if ( v == null ) return;
- props.put(k, v);
+ return instances;
}
- private String getLinger(DuccProperties props)
+ private boolean getActivate()
{
- String kw = RegistrationOption.ServiceLinger.decode();
- String default_linger = ducc_properties.getStringProperty("ducc.sm.default.linger", "5000");
- String linger = props.getStringProperty(kw, default_linger);
- long actual = 0;
- try {
- actual = Long.parseLong(linger); // make sure it's an int
- } catch ( NumberFormatException e ) {
- throw new IllegalArgumentException(kw + " is not numeric: " + linger);
- }
- return Long.toString(actual);
+ return cli_props.containsKey(UiOption.Activate.pname());
}
- synchronized protected DuccProperties getPropsFile(CommandLine cl)
- throws Throwable
+ private boolean getUpdate()
{
- DuccProperties reply = new DuccProperties();
-
- //
- // First read the properties file if given in
- // ducc_services --register propsfile
- String props = cl.getOptionValue(ServiceVerb.Register.decode());
- if ( props != null ) {
- reply.load(new FileInputStream(props));
- if ( debug ) {
- System.out.println("Service specification file:");
- for ( Object key: reply.keySet() ) {
- System.out.println(" Key: " + key + " Value: " + reply.getStringProperty((String)key));
- }
- }
- }
-
- //
- // Now pull in the override props.
- //
- overrideProperties(cl, reply, RegistrationOption.ClasspathOrder);
- overrideProperties(cl, reply, RegistrationOption.Description);
- overrideProperties(cl, reply, RegistrationOption.ProcessDD);
- overrideProperties(cl, reply, RegistrationOption.ProcessMemorySize);
- overrideProperties(cl, reply, RegistrationOption.ProcessClasspath);
- overrideProperties(cl, reply, RegistrationOption.ProcessJvmArgs);
- overrideProperties(cl, reply, RegistrationOption.ProcessEnvironment);
- overrideProperties(cl, reply, RegistrationOption.ProcessFailuresLimit);
- overrideProperties(cl, reply, RegistrationOption.SchedulingClass);
- overrideProperties(cl, reply, RegistrationOption.WorkingDirectory);
- overrideProperties(cl, reply, RegistrationOption.LogDirectory);
- overrideProperties(cl, reply, RegistrationOption.Jvm);
- overrideProperties(cl, reply, RegistrationOption.ServiceDependency);
- overrideProperties(cl, reply, RegistrationOption.ServiceLinger);
- overrideProperties(cl, reply, RegistrationOption.ServicePingClass);
- overrideProperties(cl, reply, RegistrationOption.ServiceRequestEndpoint);
- overrideProperties(cl, reply, RegistrationOption.ServicePingClasspath);
- overrideProperties(cl, reply, RegistrationOption.ServicePingJvmArgs);
- overrideProperties(cl, reply, RegistrationOption.ServicePingDoLog);
- overrideProperties(cl, reply, RegistrationOption.ServicePingTimeout);
-
- // now bop through the properties and make sure they and their values all valid
- for ( Object o : reply.keySet() ) {
- String k = (String) o;
-
- RegistrationOption opt = RegistrationOption.encode(k);
- if ( opt == RegistrationOption.Unknown ) {
- throw new IllegalArgumentException("Invalid regisration option: " + k);
- }
-
- switch ( opt ) {
- case ClasspathOrder:
- String v = reply.getStringProperty(RegistrationOption.ClasspathOrder.decode());
- if ( v == null ) continue;
- if ( ClasspathOrderParms.encode(v) == ClasspathOrderParms.Unknown) {
- throw new IllegalStateException("Invalid value for " + RegistrationOption.ClasspathOrder.decode());
- }
- break;
- }
- }
-
- //
- // Now: let's resolve placeholders.
- //
- String jvmarg_string = reply.getProperty(RegistrationOption.ProcessJvmArgs.decode());
- jvmargs = DuccUiUtilities.jvmArgsToProperties(jvmarg_string);
- DuccUiUtilities.resolvePropertiesPlaceholders(reply, jvmargs);
- return reply;
+ return cli_props.containsKey(UiOption.Update.pname());
}
-
- /**
- * @param endpoint This is 'my' service endpoint
- * @param props This is the service properties file with the dependencies in it.
- */
- void resolve_service_dependencies(String endpoint, DuccProperties props)
+ private void setLinger()
{
- String deps = props.getProperty(RegistrationOption.ServiceDependency.decode());
- deps = DuccUiUtilities.resolve_service_dependencies(endpoint, deps, jvmargs);
- if ( deps != null ) {
- props.setProperty(RegistrationOption.ServiceDependency.decode(), deps);
+ String default_linger = ducc_properties.getStringProperty("ducc.sm.default.linger", "5000");
+ String linger = cli_props.getStringProperty(UiOption.ServiceLinger.pname(), default_linger);
+ try {
+ @SuppressWarnings("unused")
+ long actual = Long.parseLong(linger); // make sure it's a long, don't care about the value
+ } catch ( NumberFormatException e ) {
+ throw new IllegalArgumentException(UiOption.ServiceLinger.pname() + " is not numeric: " + linger);
}
}
- String extractEndpoint(DuccProperties service_props, String working_dir)
+ String extractEndpoint(Properties jvmargs)
{
// If claspath is not specified, pick it up from the submitter's environment
- String classpath = service_props.getStringProperty(RegistrationOption.ProcessClasspath.decode(), System.getProperty("java.class.path"));
- service_props.setProperty(RegistrationOption.ProcessClasspath.decode(), classpath);
+ String classpath = cli_props.getStringProperty(UiOption.ProcessClasspath.pname(), System.getProperty("java.class.path"));
+ cli_props.setProperty(UiOption.ProcessClasspath.pname(), classpath);
// No endpoint, resolve from the DD.
- String dd = service_props.getStringProperty(RegistrationOption.ProcessDD.decode()); // will throw if can't find the prop
+ String dd = cli_props.getStringProperty(UiOption.ProcessDD.pname()); // will throw if can't find the prop
+ String working_dir = cli_props.getStringProperty(UiOption.WorkingDirectory.pname());
endpoint = DuccUiUtilities.getEndpoint(working_dir, dd, jvmargs);
if ( debug ) {
System.out.println("Service endpoint resolves to " + endpoint);
@@ -641,161 +151,170 @@ public class DuccServiceApi
* @param props Name of file in standard Java properies format with the service specification.
* @return
*/
- public ServiceReplyEvent register(DuccProperties service_props, int instances, Trinary autostart)
+ public IServiceReply register(String[] args)
throws Exception
{
- //
- // TODO: Crypto?
- //
-
- String k_wd = RegistrationOption.WorkingDirectory.decode();
- String working_dir = service_props.getStringProperty(k_wd, System.getProperty("user.dir"));
- service_props.setProperty(k_wd, working_dir);
-
- // Employ default log directory if not specified
- String k_ld = RegistrationOption.LogDirectory.decode();
- String log_directory = service_props.getStringProperty(k_ld, System.getProperty("user.home") + IDucc.userLogsSubDirectory);
- if( ! log_directory.startsWith(File.separator)) {
- // relative log directory was specified - default to user's home + relative directory
- // TODO: This logic comes from submit. But is it right? Log dir relative to $HOME instread of job's working dir?
- if (log_directory.endsWith(File.separator)) {
- log_directory = System.getProperty("user.home") + log_directory;
- } else {
- log_directory = System.getProperty("user.home") + File.separator + log_directory;
- }
- }
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Register,
+ UiOption.Autostart,
+ UiOption.Instances,
+ UiOption.ClasspathOrder,
+ UiOption.Description,
+ UiOption.ProcessDD,
+ UiOption.ProcessMemorySize,
+ UiOption.ProcessClasspath,
+ UiOption.ProcessJvmArgs,
+ UiOption.ProcessEnvironment,
+ UiOption.ProcessFailuresLimit,
+ UiOption.SchedulingClass,
+ UiOption.WorkingDirectory,
+ UiOption.LogDirectory,
+ UiOption.Jvm,
+ UiOption.ServiceDependency,
+ UiOption.ServiceLinger,
+ UiOption.ServiceRequestEndpoint,
+ UiOption.ServicePingClass,
+ UiOption.ServicePingJvmArgs,
+ UiOption.ServicePingDoLog,
+ UiOption.ServicePingTimeout,
+ };
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ // A few spurious properties are set as an artifact of parsing the overly-complex command line, and need removal
+ dp.remove(UiOption.SubmitPid.pname());
+ dp.remove(UiOption.Register.pname());
+
+ //
+ // Now: get jvm args and resolve placeholders, in particular, the broker url
+ //
+ String jvmarg_string = cli_props.getProperty(UiOption.ProcessJvmArgs.pname());
+ Properties jvmargs = DuccUiUtilities.jvmArgsToProperties(jvmarg_string);
+ DuccUiUtilities.resolvePropertiesPlaceholders(cli_props, jvmargs);
- // Insure a linger time is set
- String k_lin = RegistrationOption.ServiceLinger.decode();
- String linger = getLinger(service_props);
- service_props.setProperty(k_lin, linger);
-
- // tack on "services" to complete logging directory
- // TODO: Again, from service submit - is it really correct to force "/services" into the path if the
- // user specifies the path?
- // if(log_directory.endsWith(File.separator)) {
-// log_directory = log_directory+"services";
-// }
-// else {
-// log_directory = log_directory+File.separator+"services";
-// }
- service_props.setProperty(k_ld, log_directory);
+ setLinger();
//
// Establish my endpoint
//
- String endpoint = service_props.getStringProperty(RegistrationOption.ServiceRequestEndpoint.decode(), null);
+ String endpoint = cli_props.getStringProperty(UiOption.ServiceRequestEndpoint.pname(), null);
if ( endpoint == null ) { // not custom ... must be uima-as (or fail)
- endpoint = extractEndpoint(service_props, working_dir);
+
+ endpoint = extractEndpoint(jvmargs);
+
} else if ( endpoint.startsWith(ServiceType.Custom.decode()) ) {
// must have a pinger specified
- if ( service_props.getProperty(RegistrationOption.ServicePingClass.decode()) == null ) {
+ if ( ! cli_props.containsKey(UiOption.ServicePingClass.pname()) ) {
throw new IllegalArgumentException("Custom service is missing ping class name.");
}
- String k_scp = RegistrationOption.ServicePingClasspath.decode();
- String classpath = service_props.getStringProperty(k_scp, System.getProperty("java.class.path"));
- service_props.setProperty(k_scp, classpath);
+ String classpath = cli_props.getStringProperty(UiOption.ServicePingClasspath.pname(), System.getProperty("java.class.path"));
+ cli_props.setProperty(UiOption.ServicePingClasspath.pname(), classpath);
+
} else if ( endpoint.startsWith(ServiceType.UimaAs.decode()) ) {
- // Infer the classpath
- String classpath = service_props.getStringProperty(RegistrationOption.ProcessClasspath.decode(), System.getProperty("java.class.path"));
- service_props.setProperty(RegistrationOption.ProcessClasspath.decode(), classpath);
+
+ // Infer the classpath (DuccProperties will return the default if the value isn't found.)
+ String classpath = cli_props.getStringProperty(UiOption.ProcessClasspath.pname(), System.getProperty("java.class.path"));
+ cli_props.setProperty(UiOption.ProcessClasspath.pname(), classpath);
// Given ep must match inferred ep. Use case: an application is wrapping DuccServiceApi and has to construct
// the endpoint as well. The app passes it in and we insure that the constructed endpoint matches the one
// we extract from the DD - the job will fail otherwise, so we catch this early.
- String verify_endpoint = extractEndpoint(service_props, working_dir);
+ String verify_endpoint = extractEndpoint(jvmargs);
if ( !verify_endpoint.equals(endpoint) ) {
throw new IllegalArgumentException("Endpoint from --service_request_endpoint does not match endpoint ectracted from UIMA DD"
+ "\n--service_request_endpoint: " + endpoint
+ "\nextracted: : " + verify_endpoint );
}
} else {
- throw new IllegalArgumentException("Invalid custom endpoint: " + endpoint);
+ throw new IllegalArgumentException("Invalid service endpoint: " + endpoint);
}
// work out stuff I'm dependendent upon
- resolve_service_dependencies(endpoint, service_props);
+ resolve_service_dependencies(endpoint);
+ int instances = cli_props.getIntProperty(UiOption.Instances.pname(), 1);
+ Trinary autostart = getAutostart();
+ String user = (String) dp.remove(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.remove(UiOption.Signature.pname());
- //
- // Finally set up the the event object and ship it!
- //
- // DuccEventDispatcher dispatcher = connect();
- ServiceRegisterEvent ev = new ServiceRegisterEvent(DuccUiUtilities.getUser(), instances, autostart, endpoint, service_props);
- ServiceReplyEvent reply = null;
+ ServiceRegisterEvent ev = new ServiceRegisterEvent(user, instances, autostart, endpoint, cli_props, auth_block);
try {
- reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- // TODO: print a nice error. For now, we spew the stack.
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
}
-
-// try {
-// reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
-// }
-// finally {
-// context.stop();
-// }
-
- return reply;
}
/**
* @param id The full service id as returned by register
* @return
*/
- public ServiceReplyEvent unregister(int intId, String strId)
+ public IServiceReply unregister(String[] args)
throws Exception
{
- ServiceUnregisterEvent ev = new ServiceUnregisterEvent(DuccUiUtilities.getUser(), intId, strId);
- //DuccEventDispatcher dispatcher = connect();
- ServiceReplyEvent reply = null;
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Unregister,
+ };
+
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ Pair<Integer, String> id = getId(UiOption.Unregister);
+ String user = dp.getProperty(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.get(UiOption.Signature.pname());
+
+ ServiceUnregisterEvent ev = new ServiceUnregisterEvent(user, id.first(), id.second(), auth_block);
try {
- reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
}
-// try {
-// reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
-// }
-// finally {
-// context.stop();
-// }
-
- return reply;
}
/**
* @param props Name of file in standard Java properies format with the service specification.
* @return
*/
- public ServiceReplyEvent start(int intId, String strId, int instances, boolean update)
+ public IServiceReply start(String[] args)
throws Exception
{
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Start,
+ UiOption.Instances,
+ UiOption.Update,
+ };
+
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ Pair<Integer, String> id = getId(UiOption.Start);
+ String user = dp.getProperty(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.get(UiOption.Signature.pname());
+
+ ServiceStartEvent ev = new ServiceStartEvent(user, id.first(), id.second(), auth_block);
+
+ int instances = getInstances(-1);
+ boolean update = getUpdate();
- ServiceStartEvent ev = new ServiceStartEvent(DuccUiUtilities.getUser(), intId, strId);
ev.setInstances(instances);
ev.setUpdate(update);
-
- ServiceReplyEvent reply = null;
+
try {
- reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
}
-
- return reply;
}
@@ -803,99 +322,132 @@ public class DuccServiceApi
* @param props Name of file in standard Java properies format with the service specification.
* @return
*/
- public ServiceReplyEvent stop(int intId, String strId, int instances, boolean update)
+ public IServiceReply stop(String[] args)
throws Exception
{
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Stop,
+ UiOption.Instances,
+ UiOption.Update,
+ };
+
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ Pair<Integer, String> id = getId(UiOption.Stop);
+ String user = dp.getProperty(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.get(UiOption.Signature.pname());
+
+ ServiceStopEvent ev = new ServiceStopEvent(user, id.first(), id.second(), auth_block);
+
+ int instances = getInstances(-1);
+ boolean update = getUpdate();
- ServiceStopEvent ev = new ServiceStopEvent(DuccUiUtilities.getUser(), intId, strId);
ev.setInstances(instances);
ev.setUpdate(update);
-
- ServiceReplyEvent reply = null;
+
try {
- reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
- }
-
- return reply;
+ }
}
/**
- * @param id The id of a registered service.
- * @param instances The nubmer of instances of the service to start.
- * @param autostart Update to autostart status of the registered service.
* @return
*/
- public ServiceReplyEvent modify(int intId, String strId, int instances, Trinary autostart, boolean activate)
+ public IServiceReply modify(String[] args)
throws Exception
{
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Modify,
+ UiOption.Instances,
+ UiOption.Autostart,
+ UiOption.Activate,
+ };
+
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ Pair<Integer, String> id = getId(UiOption.Modify);
+ String user = dp.getProperty(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.get(UiOption.Signature.pname());
+
+ ServiceModifyEvent ev = new ServiceModifyEvent(user, id.first(), id.second(), auth_block);
+ int instances = getInstances(-1);
+ Trinary autostart = getAutostart();
+ boolean activate = getActivate();
- ServiceModifyEvent ev = new ServiceModifyEvent(DuccUiUtilities.getUser(), intId, strId);
ev.setInstances(instances);
ev.setAutostart(autostart);
ev.setActivate(activate);
- ServiceReplyEvent reply = null;
try {
- reply = (ServiceReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
}
-
- return reply;
}
/**
* @param props Name of file in standard Java properies format with the service specification.
* @return
*/
- public ServiceQueryReplyEvent query(int intId, String strId)
+ public IServiceReply query(String[] args)
throws Exception
{
- ServiceQueryEvent ev = new ServiceQueryEvent(DuccUiUtilities.getUser(), intId, strId);
- ServiceQueryReplyEvent reply = null;
+ UiOption[] opts = {
+ UiOption.Help,
+ UiOption.Debug,
+ UiOption.Query,
+ UiOption.Instances,
+ UiOption.Autostart,
+ UiOption.Activate,
+ };
+
+ DuccProperties dp = new DuccProperties();
+ init(this.getClass().getName(), opts, args, dp, sm_host, sm_port, "sm", null, "services");
+
+ Pair<Integer, String> id = null;
+ String sid = cli_props.getProperty(UiOption.Query.pname()).trim();
+ if ( sid == null || sid.equals("") ) {
+ id = new Pair<Integer, String>(-1, null);
+ } else {
+ id = getId(UiOption.Query);
+ }
+
+ String user = dp.getProperty(UiOption.User.pname());
+ byte[] auth_block = (byte[]) dp.get(UiOption.Signature.pname());
+
+ ServiceQueryEvent ev = new ServiceQueryEvent(user, id.first(), id.second(), auth_block);
try {
- reply = (ServiceQueryReplyEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
- } catch (Exception e) {
- e.printStackTrace();
+ return (IServiceReply) dispatcher.dispatchAndWaitForDuccReply(ev);
} finally {
dispatcher.close();
}
-
- return reply;
}
- synchronized ServiceVerb extract_verb(CommandLine cl)
+ //
+ // single common exit point for CL invoction
+ //
+ protected void doExit(int rc)
{
- boolean found_verb = false;
- ServiceVerb verb = ServiceVerb.Unknown;
-
- for ( ServiceVerb v : ServiceVerb.values() ) {
- if ( cl.hasOption(v.decode()) ) {
- if ( found_verb ) {
- usage("Duplicate option " + v + ": not allowd.");
- } else {
- found_verb = true;
- verb = v;
- }
- }
- }
-
- return verb;
+ System.exit(rc);
}
- public void print_reply(ServiceVerb verb, ServiceReplyEvent ev)
+ boolean execute() {return false;}
+
+ static boolean format_reply(UiOption verb, IServiceReply reply)
{
- String result = (ev.getReturnCode() == ServiceCode.OK) ? "succeeded" : "failed";
- String reason = (ev.getReturnCode() == ServiceCode.OK) ? "" : ": " +ev.getMessage();
- String action = "Service " + verb.decode();
- String msg = (action + " " + result + " ID " + ((ev.getId() == null) ? "<none>" : ev.getId().toString()) + " endpoint " + ev.getEndpoint() + reason);
+ String result = (reply.getReturnCode()) ? "succeeded" : "failed";
+ String reason = (reply.getReturnCode()) ? "" : ": " +reply.getMessage();
+ String action = "Service " + verb;
+ String msg = (action + " " + result + " ID " + ((reply.getId() == -1) ? "<none>" : reply.getId()) + " endpoint " + reply.getEndpoint() + reason);
switch ( verb ) {
case Register:
case Unregister:
@@ -905,110 +457,96 @@ public class DuccServiceApi
System.out.println(msg);
break;
case Query:
- System.out.println(ev.toString());
+ System.out.println(reply.toString());
break;
}
- if ( ev.getReturnCode() != ServiceCode.OK ) {
- throw new IllegalStateException("Return code NOTOK in rervice reply.");
- }
+ return reply.getReturnCode();
}
- public void run(String[] args)
- throws Throwable
+ static boolean Register(String[] args)
+ throws Exception
{
- Options options = new Options();
- synchronized(this) {
- addOptions(options);
- }
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.register(args);
+ return format_reply(UiOption.Register, reply);
+ }
- CommandLineParser parser = new PosixParser();
- CommandLine commandLine = null;
- try {
- commandLine = parser.parse(options, args);
- } catch (ParseException e) {
- usage("Cannot parse command line: " + e.getMessage());
- }
-
- /*
- * give help & exit when requested
- */
- if (commandLine.hasOption(ServiceVerb.Help.decode())) {
- usage(options);
- }
+ static boolean Unregister(String[] args)
+ throws Exception
+ {
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.unregister(args);
+ return format_reply(UiOption.Unregister, reply);
+ }
- if(commandLine.getOptions().length == 0) {
- usage(options);
- }
+ static boolean Start(String[] args)
+ throws Exception
+ {
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.start(args);
+ return format_reply(UiOption.Start, reply);
+ }
- if (commandLine.hasOption(ServiceVerb.Debug.decode())) {
- debug = true;
+ static boolean Stop(String[] args)
+ throws Exception
+ {
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.stop(args);
+ return format_reply(UiOption.Stop, reply);
+ }
+
+ static boolean Modify(String[] args)
+ throws Exception
+ {
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.modify(args);
+ return format_reply(UiOption.Modify, reply);
+ }
+
+ static boolean Query(String[] args)
+ throws Exception
+ {
+ DuccServiceApi api = new DuccServiceApi();
+ IServiceReply reply = api.query(args);
+ return format_reply(UiOption.Query, reply);
+ }
+
+ static UiOption getVerb(String[] args)
+ {
+ // need to scan args for the verb, and insure only one verb
+ UiOption[] verbs = {
+ UiOption.Register,
+ UiOption.Modify,
+ UiOption.Start,
+ UiOption.Stop,
+ UiOption.Query,
+ UiOption.Unregister
+ };
+ List<UiOption> check = new ArrayList<UiOption>();
+ UiOption reply = null; ;
+
+ for ( String s : args ) {
+ if ( ! s.startsWith("--") ) continue;
+ s = s.substring(2);
+ for ( UiOption v : verbs ) {
+ if ( s.equals(v.pname() ) ) {
+ reply = v;
+ check.add(v);
+ }
+ }
}
-
- DuccProperties props = null;
- int instances = 0;
- boolean activate = false;
- boolean update = false;
- Pair<Integer, String> id = null;
- Trinary autostart;
- try {
- ServiceVerb verb = extract_verb(commandLine);
- ServiceReplyEvent reply = null;
- switch ( verb ) {
- case Register:
- props = getPropsFile(commandLine);
- instances = getInstances(commandLine, 1);
- autostart = getAutostart(commandLine);
- reply = register(props, instances, autostart);
- break;
- case Unregister:
- id = getId(commandLine, verb);
- reply = unregister(id.first(), id.second());
- break;
- case Start:
- id = getId(commandLine, verb);
- instances = getInstances(commandLine, -1);
- update = getUpdate(commandLine);
- reply = start(id.first(), id.second(), instances, update);
- break;
- case Stop:
- id = getId(commandLine, verb);
- instances = getInstances(commandLine, -1);
- update = getUpdate(commandLine);
- reply = stop(id.first(), id.second(), instances, update);
- break;
- case Modify:
- id = getId(commandLine, verb);
- instances = getInstances(commandLine, -1);
- autostart = getAutostart(commandLine);
- activate = getActivate(commandLine);
- reply = modify(id.first(), id.second(), instances, autostart, activate);
- break;
- case Query:
- if (commandLine.getOptionValue(verb.decode()) == null ) {
- reply = query(-1, null);
- } else {
- id = getId(commandLine, verb);
- reply = query(id.first(), id.second());
- }
- break;
- case Unknown:
- throw new IllegalArgumentException("Missing Service verb (--register --unregister --start --stop --query --modify)");
+
+ if ( check.size() > 1 ) {
+ String msg = "";
+ for ( UiOption o : check ) {
+ msg = msg + " " + o;
}
- print_reply(verb, reply);
- } catch ( Throwable t ) {
- System.out.println("Service command fails: " + t.getMessage());
- doExit(1);
+ throw new IllegalArgumentException("Duplicate service actions " + msg + ": not allowed.");
}
+ return reply;
}
- //
- // single common exit point for CL invoction
- //
- protected void doExit(int rc)
- {
- System.exit(rc);
- }
/**
* DuccServiceApi <options>
@@ -1032,17 +570,37 @@ public class DuccServiceApi
* e.g. UIMA-AS@FixedSleepAE@tcp://bluej02
*/
public static void main(String[] args)
- {
-
- try {
- DuccServiceApi api = new DuccServiceApi();
- api.init();
- api.run(args);
- api.doExit(0);
- } catch (Throwable e) {
- e.printStackTrace(); // should not get this, hopefully have trapped everything
- System.exit(1);
- }
+ {
+ boolean rc = false;
+ try {
+ switch ( getVerb(args) ) {
+ case Register:
+ rc = Register(args);
+ break;
+ case Unregister:
+ rc = Unregister(args);
+ break;
+ case Start:
+ rc = Start(args);
+ break;
+ case Stop:
+ rc = Stop(args);
+ break;
+ case Modify:
+ rc = Modify(args);
+ break;
+ case Query:
+ rc = Query(args);
+ break;
+ default:
+ System.out.println("Missing service action (register, unregister, start, stop, modify, or query)");
+ System.exit(1);
+ }
+ } catch (Exception e) {
+ System.out.println("Service call failed: " + e.toString());
+ System.exit(1);
+ }
+ System.exit(rc ? 0 : 1);
}
}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceSubmit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceSubmit.java?rev=1455662&r1=1455661&r2=1455662&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceSubmit.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccServiceSubmit.java Tue Mar 12 18:23:00 2013
@@ -186,7 +186,7 @@ public class DuccServiceSubmit
return false;
}
- if ( ! resolve_service_dependencies(service_endpoint, requestProperties) ) {
+ if ( ! resolve_service_dependencies(service_endpoint) ) {
return false;
}
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=1455662&r1=1455661&r2=1455662&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 Tue Mar 12 18:23:00 2013
@@ -46,6 +46,28 @@ public interface IUiOptions
public enum UiOption
{
+ 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; }
+ public String deflt() { return null; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
+ 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; }
+ public String deflt() { return "false"; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
CancelJobOnInterrupt {
public String pname() { return "cancel_job_on_interrupt"; }
public String argname() { return null; }
@@ -200,6 +222,17 @@ public interface IUiOptions
public boolean required() { return false; }
},
+ Instances {
+ public String pname() { return "instances"; }
+ public String argname() { return "integer"; }
+ public String description() { return "Number of service instances to start or stop."; }
+ public String example() { return null; }
+ public String deflt() { return "1"; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
JobId {
public String pname() { return JobRequestProperties.key_id; }
public String argname() { return "string"; }
@@ -244,6 +277,17 @@ public interface IUiOptions
public boolean required() { return false; }
},
+ Modify {
+ public String pname() { return "modify"; }
+ public String argname() { return "modify-parameters" ; }
+ public String description() { return "Modify meta properties for a registered service." ; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return true; }
+ },
+
NumberOfInstances {
public String pname() { return ReservationSpecificationProperties.key_number_of_instances; }
public String argname() { return "integer"; }
@@ -255,6 +299,17 @@ public interface IUiOptions
public boolean required() { return false; }
},
+ Register {
+ public String pname() { return "register"; }
+ public String argname() { return null; }
+ public String description() { return "Register a service."; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
ServicePingClass {
public String pname() { return "service_ping_class"; }
public String argname() { return "classname"; }
@@ -343,6 +398,27 @@ public interface IUiOptions
public boolean required() { return false; }
},
+ Start {
+ public String pname() { return "start"; }
+ public String description() { return "Start a registered service." ; }
+ public String argname() { return "service-id-or-endpoint" ; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return null; }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
+ Stop {
+ public String pname() { return "stop"; }
+ public String description() { return "Stop a registered service." ; }
+ public String argname() { return "service-id-or-endpoint [--instances number-to-stop]" ; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return null; }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
SubmitPid {
// generated
@@ -594,6 +670,17 @@ public interface IUiOptions
public boolean required() { return false; }
},
+ Query {
+ public String pname() { return "query"; }
+ public String argname() { return null; }
+ public String description() { return "Query registered services." ; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return name(); }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
Reason {
// generated, not public
public String pname() { return JobRequestProperties.key_reason; }
@@ -737,6 +824,28 @@ public interface IUiOptions
},
+ Unregister {
+ public String pname() { return "unregister" ; }
+ public String argname() { return "service-id-or-endpoint" ; }
+ public String description() { return "Unregister a service." ; }
+ public String example() { return null; }
+ public String deflt() { return null; }
+ public String label() { return null; }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
+ 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 deflt() { return null; }
+ public String label() { return null; }
+ public boolean multiargs() { return false; }
+ public boolean required() { return false; }
+ },
+
User {
public String pname() { return JobSpecificationProperties.key_user; };
public String argname() { return "userid"; }
@@ -760,7 +869,6 @@ public interface IUiOptions
public boolean required() { return false; }
},
-
WorkingDirectory {
public String pname() { return JobSpecificationProperties.key_working_directory; }
public String argname() { return "path"; }
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java?rev=1455662&r1=1455661&r2=1455662&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java Tue Mar 12 18:23:00 2013
@@ -1536,6 +1536,84 @@ public class NodepoolScheduler
HashMap<User, TreeMap<IRmJob, IRmJob>> jobs_by_user)
{
String methodName = "takeFromTheRich";
+ // - Collect all shares from the jobs into a list, ordered by richest user and fattest job on biggst node
+ // Prune shares on machines that are too small to satisfy the request. Users are already ordered by
+ // wealth so we pick off their jobs and sort by most shares. Then collect the shares into a list
+ // doing the prune.
+ Map<Share, Share> eligible = new TreeMap<Share, Share>(new FinalEvictionSorter());
+ Map<Share, Share> removed = new HashMap<Share, Share>();
+
+ // given is not the same as donated.size() because there may be multiple donated shares that
+ // combine into a single "given". We'll track the actual number of shares made available for
+ // nh with 'given'
+ int given = 0;
+
+ int desiredOrder = nj.getShareOrder();
+ search : {
+ for ( User next_user : users_by_wealth.keySet() ) {
+ TreeMap<IRmJob, IRmJob> jobs = jobs_by_user.get(next_user); // aready ordered by largest
+ for (IRmJob j : jobs.keySet()) {
+ removed.putAll(j.getPendingRemoves());
+ HashMap<Share, Share> ss = j.getPendingShares();
+ ss.putAll(j.getAssignedShares());
+ for ( Share s : ss.keySet() ) {
+ if ( ! compatibleNodepools(s, nj) ) {
+ logger.debug(methodName, nj.getId(), "Bypassing pending share of order", s.getShareOrder(), s.toString(), "becaose of incompatible nodepool");
+ continue;
+ }
+ logger.debug(methodName, nj.getId(), "Pending share of order", s.getShareOrder(), s.toString(), "is compatible with class", nj.getResourceClass().getName());
+
+ if ( removed.containsKey(s) ) { // pending removal already
+ continue;
+ }
+
+ Machine m = s.getMachine();
+ int g = m.getVirtualShareOrder(); // unused space on the machine
+
+ // first the simplest and least disruptive case - can this be fixed by evicting a single share somewhere
+ if ( (s.getShareOrder() + g) >= desiredOrder ) { // clearing this share makes space
+ logger.debug(methodName, nj.getId(), "Share of order", s.getShareOrder(), "from", j.getId(), "donated:", s);
+ clearShare(s, nj);
+ removed.put(s, s); // keeps it off limits for further eviction
+ given++; // this was an exact match so a full ++ here
+ if ( given == needed ) {
+ break search;
+ }
+ continue;
+ }
+
+ // May be able to fix this by evicting multiple shares but let's do a full search first. Save the
+ // candidate shares for examination later.
+ if ( m.getShareOrder() >= desiredOrder) {
+ logger.debug(methodName, nj.getId(), "Eligible share of order", s.getShareOrder(), "for job of order", desiredOrder, ":", s);
+ eligible.put(s, s);
+ }
+ }
+ }
+ }
+ }
+ // here after breaking from search, we need to remove donated shares
+ return given;
+ }
+
+ /**
+ * This routine tries to find enough process that can be coopted from "rich" users for jobs that deserved
+ * shares but couldn't get them because of fragmentation.
+ *
+ * @param j This is the job we are trying to find shrares for.
+ * @param needed This is the number of processes we need for job j.
+ * @param users_by_wealth This is all the users who can donate, ordered by wealth.
+ * @param jobs_by_user This is all the candidate jobs owned by the user. Note that this is not necessarily
+ * ALL the user's jobs, we will have culled everything that makes no sense to
+ * take from in the caller.
+ *
+ * @return THe number of processes recovered.
+ */
+ int takeFromTheRichA(IRmJob nj, int needed,
+ TreeMap<User, User> users_by_wealth,
+ HashMap<User, TreeMap<IRmJob, IRmJob>> jobs_by_user)
+ {
+ String methodName = "takeFromTheRich";
int given = 0;
logger.debug(methodName, nj.getId(), "needed[", needed, "]");
@@ -1543,7 +1621,7 @@ public class NodepoolScheduler
TreeMap<IRmJob, IRmJob> job_set = new TreeMap<IRmJob, IRmJob>(new JobByShareSorter()); // the collection of rich users jobs to take from
Map<Share, Share> shares = new TreeMap<Share, Share>(new FinalEvictionSorter());
Map<Share, Share> removed = new HashMap<Share, Share>();
-
+
List<User> allUsers = new ArrayList<User>(); // for debug
for ( User next_user : users_by_wealth.keySet() ) {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java?rev=1455662&r1=1455661&r2=1455662&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java Tue Mar 12 18:23:00 2013
@@ -303,16 +303,20 @@ public class Scheduler
* We only get one such name, so we give up the search if we find
* it.
*/
+ static String cached_domain = null;
private String getDomainName()
{
String methodName = "getDomainName";
+
+ if ( cached_domain != null ) return cached_domain;
try {
NodeIdentity ni = new NodeIdentity();
for ( IIdentity id : ni.getNodeIdentities()) {
String n = id.getName();
int ndx = n.indexOf(".");
if ( ndx > 0 ) {
- return n.substring(ndx + 1);
+ cached_domain = n.substring(ndx + 1);
+ return cached_domain;
}
}
} catch (Exception e) {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ApiHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ApiHandler.java?rev=1455662&r1=1455661&r2=1455662&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ApiHandler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ApiHandler.java Tue Mar 12 18:23:00 2013
@@ -18,6 +18,7 @@
*/
package org.apache.uima.ducc.sm;
+import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.transport.event.ServiceModifyEvent;
import org.apache.uima.ducc.transport.event.ServiceStartEvent;
import org.apache.uima.ducc.transport.event.ServiceStopEvent;
@@ -38,7 +39,7 @@ class ApiHandler
*
*/
private static final long serialVersionUID = 1L;
- ServiceVerb cmd;
+ UiOption cmd;
ServiceHandler serviceHandler;
long friendly;
@@ -50,7 +51,7 @@ class ApiHandler
ApiHandler(ServiceUnregisterEvent event, ServiceHandler serviceHandler)
{
- this.cmd = ServiceVerb.Unregister;
+ this.cmd = UiOption.Unregister;
this.friendly = event.getFriendly();
this.endpoint = event.getEndpoint();
this.serviceHandler = serviceHandler;
@@ -58,7 +59,7 @@ class ApiHandler
ApiHandler(ServiceStartEvent event, ServiceHandler serviceHandler)
{
- this.cmd = ServiceVerb.Start;
+ this.cmd = UiOption.Start;
this.friendly = event.getFriendly();
this.endpoint = event.getEndpoint();
this.instances = event.getInstances();
@@ -68,7 +69,7 @@ class ApiHandler
ApiHandler(ServiceStopEvent event, ServiceHandler serviceHandler)
{
- this.cmd = ServiceVerb.Stop;
+ this.cmd = UiOption.Stop;
this.friendly = event.getFriendly();
this.endpoint = event.getEndpoint();
this.instances = event.getInstances();
@@ -78,7 +79,7 @@ class ApiHandler
ApiHandler(ServiceModifyEvent event, ServiceHandler serviceHandler)
{
- this.cmd = ServiceVerb.Modify;
+ this.cmd = UiOption.Modify;
this.friendly = event.getFriendly();
this.endpoint = event.getEndpoint();
this.instances = event.getInstances();