Author: challngr Date: Tue Feb 12 19:45:45 2013 New Revision: 1445326 URL: http://svn.apache.org/r1445326 Log: UIMA-2662 Accept --service_request_endpoint from CLI. If given, extract the endpoint from the DD and insure it matches.
Modified: 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/IServiceApi.java uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java 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=1445326&r1=1445325&r2=1445326&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 Feb 12 19:45:45 2013 @@ -620,11 +620,12 @@ public class DuccServiceApi return reply; } + /** * @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, Properties props) + void resolve_service_dependencies(String endpoint, DuccProperties props) { String deps = props.getProperty(RegistrationOption.ServiceDependency.decode()); deps = DuccUiUtilities.resolve_service_dependencies(endpoint, deps, jvmargs); @@ -633,6 +634,21 @@ public class DuccServiceApi } } + String extractEndpoint(DuccProperties service_props, String working_dir) + { + // 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); + + // No endpoint, resolve from the DD. + String dd = service_props.getStringProperty(RegistrationOption.ProcessDD.decode()); // will throw if can't find the prop + endpoint = DuccUiUtilities.getEndpoint(working_dir, dd, jvmargs); + if ( debug ) { + System.out.println("Service endpoint resolves to " + endpoint); + } + return endpoint; + } + /** * @param props Name of file in standard Java properies format with the service specification. * @return @@ -682,24 +698,14 @@ public class DuccServiceApi // String endpoint = service_props.getStringProperty(RegistrationOption.ServiceRequestEndpoint.decode(), null); if ( endpoint == null ) { // not custom ... must be uima-as (or fail) - - // 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); - - // No endpoint, resolve from the DD. - String dd = service_props.getStringProperty(RegistrationOption.ProcessDD.decode()); // will throw if can't find the prop - endpoint = DuccUiUtilities.getEndpoint(working_dir, dd, jvmargs); - if ( debug ) { - System.out.println("Service endpoint resolves to " + endpoint); - } + endpoint = extractEndpoint(service_props, working_dir); } else if ( endpoint.startsWith(ServiceType.Custom.decode()) ) { // must have a pinger specified if ( service_props.getProperty(RegistrationOption.ServicePingClass.decode()) == null ) { 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); @@ -707,6 +713,16 @@ public class DuccServiceApi // Infer the classpath String classpath = service_props.getStringProperty(RegistrationOption.ProcessClasspath.decode(), System.getProperty("java.class.path")); service_props.setProperty(RegistrationOption.ProcessClasspath.decode(), 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); + 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); } Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java?rev=1445326&r1=1445325&r2=1445326&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java Tue Feb 12 19:45:45 2013 @@ -215,20 +215,31 @@ public interface IServiceApi public static RegistrationOption encode(String value) { - if ( value.equals(Description.decode()) ) return Description; - if ( value.equals(ProcessDD.decode()) ) return ProcessDD; - if ( value.equals(ProcessMemorySize.decode()) ) return ProcessMemorySize; - if ( value.equals(ProcessClasspath.decode()) ) return ProcessClasspath; - if ( value.equals(ProcessJvmArgs.decode()) ) return ProcessJvmArgs; - if ( value.equals(ProcessEnvironment.decode()) ) return ProcessEnvironment; - if ( value.equals(ProcessFailuresLimit.decode()) ) return ProcessFailuresLimit; - if ( value.equals(SchedulingClass.decode()) ) return SchedulingClass; - if ( value.equals(WorkingDirectory.decode()) ) return WorkingDirectory; - if ( value.equals(LogDirectory.decode()) ) return LogDirectory; - if ( value.equals(ClasspathOrder.decode()) ) return ClasspathOrder; - if ( value.equals(Jvm.decode()) ) return Jvm; - if ( value.equals(ServiceDependency.decode()) ) return ServiceDependency; - if ( value.equals(ServiceLinger.decode()) ) return ServiceLinger; + if ( value.equals(ClasspathOrder.decode()) ) return ClasspathOrder; + if ( value.equals(Description.decode()) ) return Description; + + if ( value.equals(ProcessDD.decode()) ) return ProcessDD; + if ( value.equals(ProcessClasspath.decode()) ) return ProcessClasspath; + if ( value.equals(ProcessEnvironment.decode()) ) return ProcessEnvironment; + if ( value.equals(ProcessFailuresLimit.decode()) ) return ProcessFailuresLimit; + if ( value.equals(ProcessJvmArgs.decode()) ) return ProcessJvmArgs; + if ( value.equals(ProcessMemorySize.decode()) ) return ProcessMemorySize; + + if ( value.equals(SchedulingClass.decode()) ) return SchedulingClass; + if ( value.equals(ServiceRequestEndpoint.decode()) ) return ServiceRequestEndpoint; + + if ( value.equals(ServicePingClass.decode()) ) return ServicePingClass; + if ( value.equals(ServicePingClasspath.decode()) ) return ServicePingClasspath; + if ( value.equals(ServicePingTimeout.decode()) ) return ServicePingTimeout; + if ( value.equals(ServicePingDoLog.decode()) ) return ServicePingDoLog; + + if ( value.equals(WorkingDirectory.decode()) ) return WorkingDirectory; + if ( value.equals(LogDirectory.decode()) ) return LogDirectory; + if ( value.equals(Jvm.decode()) ) return Jvm; + + if ( value.equals(ServiceDependency.decode()) ) return ServiceDependency; + if ( value.equals(ServiceLinger.decode()) ) return ServiceLinger; + return Unknown; } Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java?rev=1445326&r1=1445325&r2=1445326&view=diff ============================================================================== --- uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java (original) +++ uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServiceHandler.java Tue Feb 12 19:45:45 2013 @@ -877,11 +877,20 @@ public class ServiceHandler ServiceReplyEvent register(DuccId id, String props_filename, String meta_filename, DuccProperties props, DuccProperties meta) { String methodName = "register"; - ServiceSet sset = new ServiceSet(id, props_filename, meta_filename, props, meta); - String key = sset.getKey(); - + String error = null; boolean must_deregister = false; + + ServiceSet sset = null; + try { + sset = new ServiceSet(id, props_filename, meta_filename, props, meta); + } catch (Throwable t) { + error = t.getMessage(); + return new ServiceReplyEvent(ServiceCode.NOTOK, t.getMessage(), "New Service", id); + } + + String key = sset.getKey(); + if (serviceStateHandler.getServiceByName(key) == null ) { try { props.store(new FileOutputStream(props_filename), "Service descriptor.");