You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2018/02/09 15:16:19 UTC

svn commit: r1823666 - in /uima/uima-ducc/trunk: uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/ uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ uima-ducc-container/src/main/java/org/apache/uima/ducc/cont...

Author: burn
Date: Fri Feb  9 15:16:19 2018
New Revision: 1823666

URL: http://svn.apache.org/viewvc?rev=1823666&view=rev
Log:
UIMA-5551 Simplify pull-service configuration by replacing the config file with explicit -Ds

Removed:
    uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/ConfigurationProperties.java
Modified:
    uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/DuccServiceDriver.java
    uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ServiceDriver.java
    uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/HttpTaskTransportHandler.java
    uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/iface/TaskTransportHandler.java
    uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/DuccHttpClient.java

Modified: uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/DuccServiceDriver.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/DuccServiceDriver.java?rev=1823666&r1=1823665&r2=1823666&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/DuccServiceDriver.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/DuccServiceDriver.java Fri Feb  9 15:16:19 2018
@@ -90,7 +90,7 @@ public class DuccServiceDriver implement
 			protocolHandler.stop();
 		}
 	}
-	public void initialize(Properties properties) throws DriverException {
+	public String initialize(Properties properties) throws DriverException {
 		if ( TransportType.HTTP.equals(transportType)) {
 			transport = 
 					Transports.newHttpTransport();
@@ -101,10 +101,7 @@ public class DuccServiceDriver implement
 				protocolHandler.initialize(properties);
 				logger.log(Level.INFO, "Initializing transport ...");
 				transport.setTaskProtocolHandler(protocolHandler);
-				transport.initialize(properties);
-				
-				start();
-			
+				return transport.initialize(properties);
 			} catch( TaskProtocolException e) {
 				throw new DriverException(e);
 			} catch( TaskTransportException e) {
@@ -113,6 +110,7 @@ public class DuccServiceDriver implement
 				throw new DriverException(e);
 			}
 		}
+    return null;
 	}
 	public void test() throws Exception {
 		AtomicInteger IdGenerator =
@@ -160,7 +158,7 @@ public class DuccServiceDriver implement
 			ServiceDriver driver = DuccServiceDriver.getInstance();
 			driver.setTaskAllocator(taskAllocator);
 			driver.initialize(properties);
-			//driver.start();
+			driver.start();
 		//	((DuccServiceDriver)driver).test();
 				
 		} catch( Exception e) {

Modified: uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ServiceDriver.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ServiceDriver.java?rev=1823666&r1=1823665&r2=1823666&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ServiceDriver.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/iface/ServiceDriver.java Fri Feb  9 15:16:19 2018
@@ -29,10 +29,8 @@ public interface ServiceDriver extends L
 	public static String Application = "driver.application.name";
 	public static String Port = "driver.server.port";
 	public static String MaxThreads = "driver.server.max.threads";
-	public static String Registry = "registry";
-	// Perhaps should move all these keys into the shared ConfigurationProperties?
 
-	public void initialize(Properties props) throws DriverException;
+	public String initialize(Properties props) throws DriverException;
 	public TaskAllocatorCallbackListener getTaskAllocator();
 	public void setTaskAllocator(TaskAllocatorCallbackListener taskAllocator);
 }

Modified: uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/HttpTaskTransportHandler.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/HttpTaskTransportHandler.java?rev=1823666&r1=1823665&r2=1823666&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/HttpTaskTransportHandler.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/HttpTaskTransportHandler.java Fri Feb  9 15:16:19 2018
@@ -32,8 +32,6 @@ import org.apache.uima.UIMAFramework;
 import org.apache.uima.ducc.common.utils.XStreamUtils;
 import org.apache.uima.ducc.container.net.iface.IMetaCasTransaction;
 import org.apache.uima.ducc.container.net.iface.IMetaCasTransaction.Direction;
-import org.apache.uima.ducc.container.sd.ServiceRegistry;
-import org.apache.uima.ducc.container.sd.ServiceRegistry_impl;
 import org.apache.uima.ducc.container.sd.iface.ServiceDriver;
 import org.apache.uima.ducc.container.sd.task.error.TaskProtocolException;
 import org.apache.uima.ducc.container.sd.task.iface.TaskProtocolHandler;
@@ -90,7 +88,7 @@ public class HttpTaskTransportHandler im
 		}
 	}
 
-  public Server createServer(int httpPort, int maxThreads, String app, TaskProtocolHandler handler, String registryAddr) 
+  public Server createServer(int httpPort, int maxThreads, String app, TaskProtocolHandler handler) 
           throws Exception {
 
 		// Server thread pool
@@ -117,40 +115,17 @@ public class HttpTaskTransportHandler im
 
 		context.addServlet(new ServletHolder(new TaskHandlerServlet(handler)), "/"+app);
 
-    // Establish the URL we could register for our customers
-    String taskUrl = server.getURI().toString();
-    if (taskUrl.endsWith("/")) {
-      taskUrl = taskUrl.substring(0, taskUrl.length() - 1);
-    }
-    taskUrl += ":" + httpPort + "/" + app;
-    logger.log(Level.INFO, "Service Driver URL: " + taskUrl); // e.g. http://localhost:8888/test");
-
-    // Register the task allocator's URL if a registry is specified
-    // The type of registry is determined by the registry class.
-    
-    String taskServerName = app;   // why not?
-    if (registryAddr != null) {
-      ServiceRegistry registry = ServiceRegistry_impl.getInstance();
-      if (registry.initialize(registryAddr)) {
-        registry.register(taskServerName, taskUrl, "");   // Will also create a shutdown hook to unregister
-        logger.log(Level.INFO,"Registered: " + taskServerName);
-      }
-    } else {
-      logger.log(Level.WARNING, "Registration skipped - registry=" + registryAddr + " server="+taskServerName);
-    }
-
 		return server;
 	}
 
 	@Override
-	public void initialize(Properties properties) throws TaskTransportException {
+	public String initialize(Properties properties) throws TaskTransportException {
 		// TODO Auto-generated method stub
 		// Max cores
     int cores = Runtime.getRuntime().availableProcessors();
     String portString = (String) properties.get(ServiceDriver.Port);
     String maxThreadsString = (String) properties.get(ServiceDriver.MaxThreads);
     String appName = (String) properties.get(ServiceDriver.Application);
-    String registry = (String) properties.get(ServiceDriver.Registry);    // optional
 
 		int maxThreads = cores;
 		int httpPort = -1;
@@ -180,11 +155,20 @@ public class HttpTaskTransportHandler im
 		}
 		try {
 			// create and initialize Jetty Server
-			server = createServer(httpPort, maxThreads, appName, taskProtocolHandler, registry);
+			server = createServer(httpPort, maxThreads, appName, taskProtocolHandler);
 		} catch (Exception e) {
 			throw new TaskTransportException(e);
 		}
-
+    
+		// Establish the URL we could register for our customers
+    String taskUrl = server.getURI().toString();
+    if (taskUrl.endsWith("/")) {
+      taskUrl = taskUrl.substring(0, taskUrl.length() - 1);
+    }
+    taskUrl += ":" + httpPort + "/" + appName;
+    logger.log(Level.INFO, "Service Driver URL: " + taskUrl); // e.g. http://localhost:8888/test");
+    
+    return taskUrl;
 	}
 
 

Modified: uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/iface/TaskTransportHandler.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/iface/TaskTransportHandler.java?rev=1823666&r1=1823665&r2=1823666&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/iface/TaskTransportHandler.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/sd/task/transport/iface/TaskTransportHandler.java Fri Feb  9 15:16:19 2018
@@ -27,6 +27,6 @@ import org.apache.uima.ducc.container.sd
 
 public interface TaskTransportHandler extends Lifecycle {
 	
-	public void initialize(Properties properties) throws TaskTransportException;
+	public String initialize(Properties properties) throws TaskTransportException;
 	public void setTaskProtocolHandler(TaskProtocolHandler taskProtocolHandler);
 }

Modified: uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/DuccHttpClient.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/DuccHttpClient.java?rev=1823666&r1=1823665&r2=1823666&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/DuccHttpClient.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/DuccHttpClient.java Fri Feb  9 15:16:19 2018
@@ -51,12 +51,13 @@ import org.apache.uima.ducc.container.ne
 import org.apache.uima.ducc.container.net.impl.MetaCasTransaction;
 import org.apache.uima.ducc.container.net.impl.PerformanceMetrics;
 import org.apache.uima.ducc.container.net.impl.TransactionId;
-import org.apache.uima.ducc.container.sd.ConfigurationProperties;
 import org.apache.uima.ducc.container.sd.ServiceRegistry;
 import org.apache.uima.ducc.container.sd.ServiceRegistry_impl;
-import org.apache.uima.ducc.container.sd.iface.ServiceDriver;
 
 public class DuccHttpClient {
+  private final static String REGISTERED_DRIVER = "ducc.deploy.service.driver";
+  private final static String SERVICE_TYPE      = "ducc.deploy.service.type";
+  
 	private DuccLogger logger = new DuccLogger(DuccHttpClient.class);
 	private JobProcessComponent duccComponent;
 	private BasicConnPool connPool = null;
@@ -73,7 +74,6 @@ public class DuccHttpClient {
 	private int ClientMaxConnectionsPerHostPort = 0;
   private ServiceRegistry registry = null;
   private String taskServerName;
-  private Properties config = null;
 	
   public DuccHttpClient(JobProcessComponent duccComponent) {
     this.duccComponent = duccComponent;
@@ -97,23 +97,30 @@ public class DuccHttpClient {
 	  return address;
 	}
 	
+	// If the client URL has been provided use it (JD/JP case)
+	// Otherwise look it up in the registry using the entry in -Dducc.deploy.service.driver
+	// which must specify: <registry-location>?<registry-entry>
 	public void initialize(String jdUrl) throws Exception {
 
 	  // If not specified get the url from the registry
 	  if (jdUrl == null || jdUrl.isEmpty()) {
-	    config = ConfigurationProperties.getProperties();    // Holds registry details AND service.type
-	    String registryLocn = config.getProperty(ServiceDriver.Registry);
-	    taskServerName = config.getProperty(ServiceDriver.Application);
-	    if (registryLocn != null && taskServerName != null) {
-	      registry = ServiceRegistry_impl.getInstance();
-	      if (!registry.initialize(registryLocn)) {
-	        registry = null;
+	    String registryAddr = null;
+	    String registryUri = System.getProperty(REGISTERED_DRIVER);
+	    if (registryUri != null) {
+	      String[] parts = registryUri.split("\\?", 2);
+	      if (parts.length == 2) {
+	        registryAddr = parts[0];
+	        taskServerName = parts[1];
 	      }
-	    } 
-	    if (registry == null) {
-	      throw new RuntimeException("Failed to connect to registry at "+registryLocn+" to locate server "+taskServerName);
 	    }
-	    logger.info("initialize", null, "Using registry at", registryLocn, "to locate server", taskServerName);
+	    if (registryAddr == null) {
+	      throw new RuntimeException("Missing or invalid system property " + REGISTERED_DRIVER + ": " + registryUri);
+      }
+	    registry = ServiceRegistry_impl.getInstance();
+	    if (!registry.initialize(registryAddr)) {
+	      throw new RuntimeException("Failed to connect to registry at "+registryAddr+" to locate server "+taskServerName);
+	    }
+	    logger.info("initialize", null, "Using registry at", registryAddr, "to locate server", taskServerName);
 	    jdUrl = getJdUrl();
 	  }
 	  this.jdUrl = jdUrl;
@@ -205,9 +212,9 @@ public class DuccHttpClient {
 		return nn;
 	}
 	private String getProcessName() {
-	  String pn = System.getenv(IDuccUser.EnvironmentVariable.DUCC_ID_PROCESS.value());
-	  if (config != null && config.containsKey("service.type")) {
-	    pn = config.getProperty("service.type");  // Indicates the type of service request
+	  String pn = System.getProperty(SERVICE_TYPE);  // Indicates the type of service request
+	  if (pn == null) {   // JP's use the ID set by the agent
+	    pn = System.getenv(IDuccUser.EnvironmentVariable.DUCC_ID_PROCESS.value());
 	  }
 		return pn;
 	}