You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2015/02/12 19:46:50 UTC
svn commit: r1659357 - in /uima/sandbox/uima-ducc/trunk:
uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/
uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/
uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configurati...
Author: cwiklik
Date: Thu Feb 12 18:46:50 2015
New Revision: 1659357
URL: http://svn.apache.org/r1659357
Log:
UIMA-4215 Added support for services running with classpath isolation
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java (with props)
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/ProcessManagerComponent.java
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java?rev=1659357&r1=1659356&r2=1659357&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java Thu Feb 12 18:46:50 2015
@@ -491,17 +491,23 @@ public class DuccCommandExecutor extends
case Job_Uima_AS_Process:
processType = "-UIMA-";
List<String> options = ((JavaCommandLine)cmdLine).getOptions();
- boolean ducc20JpProcess = false;
+ boolean isDucc20JpProcess = false;
+ boolean isDucc20ServiceProcess = false;
// determine if we are launching Ducc2.0 or Ducc1.+ JP
for( String option : options ) {
if ( option.indexOf(FlagsHelper.Name.JpType.pname()) > -1) {
- ducc20JpProcess = true;
- break;
+ isDucc20JpProcess = true;
+ }
+ if (option.indexOf("ducc.deploy.components=service") > -1) {
+ isDucc20ServiceProcess = true;
}
}
// Add main class and component type to the command line
- if ( ducc20JpProcess ) {
- ((JavaCommandLine)cmdLine).addOption("-Dducc.deploy.components=job-process");
+ if ( isDucc20JpProcess ) {
+ if ( !isDucc20ServiceProcess ) {
+ ((JavaCommandLine)cmdLine).addOption("-Dducc.deploy.components=job-process");
+ }
+
((JavaCommandLine)cmdLine).setClassName("org.apache.uima.ducc.user.common.main.DuccJobService");
} else {
((JavaCommandLine)cmdLine).addOption("-Dducc.deploy.components=uima-as");
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/ProcessManagerComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/ProcessManagerComponent.java?rev=1659357&r1=1659356&r2=1659357&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/ProcessManagerComponent.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-pm/src/main/java/org/apache/uima/ducc/pm/ProcessManagerComponent.java Thu Feb 12 18:46:50 2015
@@ -172,7 +172,9 @@ implements ProcessManager {
break;
case Service:
- //logger.info(methodName,null,"!!!!!!!!!!!!! GOT SERVICE");
+ ///logger.info(methodName,null,"!!!!!!!!!!!!! GOT SERVICE");
+ dcj.getCommandLine().addOption("-Dducc.deploy.components=service");
+
break;
default:
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java?rev=1659357&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java Thu Feb 12 18:46:50 2015
@@ -0,0 +1,250 @@
+/*
+ * 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.transport.configuration.service;
+
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.uima.ducc.common.component.AbstractDuccComponent;
+import org.apache.uima.ducc.common.component.IJobProcessor;
+import org.apache.uima.ducc.common.container.FlagsHelper;
+import org.apache.uima.ducc.common.main.DuccService;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.transport.configuration.jp.AgentSession;
+import org.apache.uima.ducc.transport.configuration.jp.JmxAEProcessInitMonitor;
+import org.apache.uima.ducc.transport.event.common.IProcessState.ProcessState;
+
+public class ServiceComponent extends AbstractDuccComponent implements
+ IJobProcessor {
+
+ private ServiceConfiguration configuration;
+ private AgentSession agent = null;
+ ScheduledThreadPoolExecutor executor = null;
+
+ private String jmxConnectString = "";
+ protected ProcessState currentState = ProcessState.Undefined;
+ protected ProcessState previousState = ProcessState.Undefined;
+ protected static DuccLogger logger;
+ protected String saxonJarPath;
+ protected String dd2SpringXslPath;
+ protected String dd;
+ private Object processorInstance = null;
+ private CountDownLatch exitLatch = new CountDownLatch(1);
+
+ public ServiceComponent(String componentName, CamelContext ctx,
+ ServiceConfiguration jpc) {
+ super(componentName, ctx);
+ this.configuration = jpc;
+ jmxConnectString = super.getProcessJmxUrl();
+
+ }
+
+ public void setProcessor(Object pc, String[] args) {
+ this.processorInstance = pc;
+ }
+
+ public void setState(ProcessState state) {
+ synchronized (currentState) {
+ if (currentState.name().equals(
+ ProcessState.FailedInitialization.name())) {
+ return;
+ }
+ if (!state.name().equals(currentState.name())) {
+ currentState = state;
+ agent.notify(currentState, super.getProcessJmxUrl());
+ }
+ }
+ }
+
+ protected void setDD(String dd) {
+ this.dd = dd;
+ }
+
+ public void setDd2SpringXslPath(String dd2SpringXslPath) {
+ this.dd2SpringXslPath = dd2SpringXslPath;
+ }
+
+ public void setSaxonJarPath(String saxonJarPath) {
+ this.saxonJarPath = saxonJarPath;
+ }
+
+ protected void setAgentSession(AgentSession session) {
+ agent = session;
+ }
+
+ public String getProcessJmxUrl() {
+ return jmxConnectString;
+ }
+
+ public DuccLogger getLogger() {
+ if (logger == null) {
+ logger = new DuccLogger(ServiceComponent.class);
+ }
+ return logger;
+ }
+
+ /**
+ * This method is called by super during ducc framework boot sequence. It
+ * creates all the internal components and worker threads and initiates
+ * processing. When threads exit, this method shuts down the components and
+ * returns.
+ */
+ public void start(DuccService service, String[] args) throws Exception {
+ super.start(service, args);
+
+ if (args == null || args.length == 0 || args[0] == null
+ || args[0].trim().length() == 0) {
+ logger.warn(
+ "start",
+ null,
+ "Missing Deployment Descriptor - Service Requires argument. Add DD for UIMA-AS job");
+ throw new RuntimeException(
+ "Missing Deployment Descriptor - Service Requires argument. Add DD for UIMA-AS job");
+ }
+ String processJmxUrl = super.getProcessJmxUrl();
+ // tell the agent that this process is initializing
+ agent.notify(ProcessState.Initializing, processJmxUrl);
+
+ try {
+ executor = new ScheduledThreadPoolExecutor(1);
+ executor.prestartAllCoreThreads();
+ // Instantiate a UIMA AS jmx monitor to poll for status of the AE.
+ // This monitor checks if the AE is initializing or ready.
+ JmxAEProcessInitMonitor monitor = new JmxAEProcessInitMonitor(agent);
+ /*
+ * This will execute the UimaAEJmxMonitor continuously for every 15
+ * seconds with an initial delay of 20 seconds. This monitor polls
+ * initialization status of AE deployed in UIMA AS.
+ */
+ executor.scheduleAtFixedRate(monitor, 20, 30, TimeUnit.SECONDS);
+ // the JobProcessConfiguration class already checked for
+ // existence of -DDucc.Job.Type
+ String jobType = System
+ .getProperty(FlagsHelper.Name.JpType.pname());
+
+ String[] jpArgs;
+ jpArgs = new String[] { "-dd", args[0], "-saxonURL", saxonJarPath,
+ "-xslt", dd2SpringXslPath };
+
+ Properties props = new Properties();
+ // Using java reflection, initialize instance of IProcessContainer
+ Method initMethod = processorInstance
+ .getClass()
+ .getSuperclass()
+ .getDeclaredMethod("initialize", Properties.class,
+ String[].class);
+ initMethod.invoke(processorInstance, props, jpArgs);
+
+ //getLogger().info("start", null, "Ducc JP JobType=" + jobType);
+
+ System.out.println("JMX Connect String:" + processJmxUrl);
+ // getLogger().info("start", null,
+ // "Starting "+scaleout+" Process Threads - JMX Connect String:"+
+ // processJmxUrl);
+
+ Method deployMethod = processorInstance.getClass().getSuperclass()
+ .getDeclaredMethod("deploy");
+ deployMethod.invoke(processorInstance);
+ System.out
+ .println(".... Deployed Processing Container - Initialization Successful - Thread "
+ + Thread.currentThread().getId());
+
+ // if initialization was successful, tell the agent that the JP is
+ // running
+ if (!currentState.equals(ProcessState.FailedInitialization)) {
+ // pipelines deployed and initialized. This process is Ready
+ currentState = ProcessState.Running;
+ // Update agent with the most up-to-date state of the pipeline
+ // all is well, so notify agent that this process is in Running
+ // state
+ agent.notify(currentState, processJmxUrl);
+ // SUCCESSFUL DEPLOY - Now wait until the agent sends stop
+ // request. Processing continues in UIMA-AS without DUCCs
+ // involvement.
+ // In this class stop() method, the latch will
+ // count down and allow the process to exit.
+ exitLatch.await();
+ }
+
+ } catch (Exception ee) {
+ ee.printStackTrace();
+ currentState = ProcessState.FailedInitialization;
+ getLogger()
+ .info("start", null,
+ ">>> Failed to Deploy UIMA Service. Check UIMA Log for Details");
+ agent.notify(ProcessState.FailedInitialization);
+ Runtime.getRuntime().halt(0); // hard stop. Initialization failed
+ }
+
+ }
+
+ public void setRunning() {
+ currentState = ProcessState.Running;
+ }
+
+ public boolean isRunning() {
+ return currentState.equals(ProcessState.Running);
+ }
+
+ public void stop() {
+ currentState = ProcessState.Stopping;
+ agent.notify(currentState);
+ if (super.isStopping()) {
+ return; // already stopping - nothing to do
+ }
+
+ System.out.println("... ServiceComponent - Stopping Service Adapter");
+ try {
+ exitLatch.countDown(); // count down the exit latch so this process can exit
+ // Stop executor. It was only needed to poll AE initialization
+ // status.
+ // Since deploy() completed
+ // the UIMA AS service either succeeded initializing or it failed.
+ // In
+ // either case we no longer
+ // need to poll for initialization status
+ if (executor != null) {
+ executor.shutdownNow();
+ }
+
+ if (agent != null) {
+ agent.stop();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+
+ try {
+
+ Method stopMethod = processorInstance.getClass()
+ .getSuperclass().getDeclaredMethod("stop");
+ stopMethod.invoke(processorInstance);
+
+ super.stop();
+ } catch (Exception ee) {
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java?rev=1659357&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java Thu Feb 12 18:46:50 2015
@@ -0,0 +1,290 @@
+/*
+ * 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.transport.configuration.service;
+
+import java.net.InetAddress;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.common.container.FlagsHelper;
+import org.apache.uima.ducc.common.utils.Utils;
+import org.apache.uima.ducc.transport.DuccExchange;
+import org.apache.uima.ducc.transport.DuccTransportConfiguration;
+import org.apache.uima.ducc.transport.agent.ProcessStateUpdate;
+import org.apache.uima.ducc.transport.configuration.jp.AgentSession;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+@Configuration
+@Import({ DuccTransportConfiguration.class, CommonConfiguration.class })
+public class ServiceConfiguration {
+ public static final String AGENT_ENDPOINT = "mina:tcp://localhost:";
+
+ @Autowired
+ DuccTransportConfiguration transport;
+ @Autowired
+ CommonConfiguration common;
+ ServiceComponent duccComponent = null;
+ CamelContext camelContext;
+ AgentSession agent = null;
+ // protected ProcessState currentState = ProcessState.Undefined;
+ // protected ProcessState previousState = ProcessState.Undefined;
+ RouteBuilder routeBuilder;
+ /**
+ * Creates Camel Router to handle incoming messages
+ *
+ * @param delegate
+ * - {@code AgentEventListener} to delegate messages to
+ *
+ * @return {@code RouteBuilder} instance
+ */
+ public synchronized RouteBuilder routeBuilderForIncomingRequests(
+ final String thisNodeIP, final ServiceEventListener delegate) {
+ return new RouteBuilder() {
+ // Custom filter to select messages that are targeted for this
+ // process. Checks the Node IP in a message to determine if
+ // this process is the target.
+ Predicate filter = new DuccProcessFilter(thisNodeIP);
+
+ public void configure() throws Exception {
+ System.out
+ .println("Service Wrapper Starting Request Channel on Endpoint:"
+ + common.managedServiceEndpoint);
+ onException(Exception.class).handled(true)
+ .process(new ErrorProcessor()).end();
+
+ from(common.managedServiceEndpoint)
+
+ .choice().when(filter).bean(delegate).end()
+ .setId(common.managedServiceEndpoint);
+
+ }
+ };
+ }
+
+ public class ErrorProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // the caused by exception is stored in a property on the exchange
+ Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
+ Throwable.class);
+ caused.printStackTrace();
+ }
+ }
+
+
+ private void checkPrereqs() {
+/*
+ boolean uimaAsJob = false;
+
+ if (null == System.getProperty(FlagsHelper.Name.JpType.pname())) { // "Ducc.Job.Type")
+ throw new RuntimeException("Missing Job Type. Add -D"
+ + FlagsHelper.Name.JpType.pname() + "=uima-as or "
+ + FlagsHelper.Name.JpType.pname()
+ + "=uima. Check your command line");
+ } else {
+ String jobType = System
+ .getProperty(FlagsHelper.Name.JpType.pname());
+ if (jobType.trim().equals("uima-as")) {
+ uimaAsJob = true;
+ } else if (!jobType.trim().equals("uima") && !jobType.trim().equals("custom")) {
+ throw new RuntimeException("Invalid value for -D"
+ + FlagsHelper.Name.JpType.pname()
+ + ". Expected uima-as,uima or custom, Instead it is "
+ + jobType);
+ }
+ }
+
+ if (null == System.getProperty(FlagsHelper.Name.JpDuccClasspath.pname())) {
+ throw new RuntimeException("Missing the -D"
+ + FlagsHelper.Name.JpDuccClasspath.pname() + "=XXXX property");
+ }
+ if (uimaAsJob && null == common.saxonJarPath) {
+ throw new RuntimeException(
+ "Missing saxon jar path. Check your ducc.properties");
+ }
+ if (uimaAsJob && null == common.dd2SpringXslPath) {
+ throw new RuntimeException(
+ "Missing dd2spring xsl path. Check your ducc.properties");
+ }
+ if (null == System.getProperty(FlagsHelper.Name.JdURL.pname())) {
+ throw new RuntimeException("Missing the -D"
+ + FlagsHelper.Name.JdURL.pname() + " property");
+ }
+*/
+ }
+
+ public String getUserContainerClassForJob(String key) {
+ if (key.equals("uima-as")) {
+ if (common.uimaASProcessContainerClass == null) {
+ // use default
+ return "org.apache.uima.ducc.user.jp.UimaASProcessContainer";
+ } else {
+ return common.uimaASProcessContainerClass;
+ }
+ } else {
+ if (common.uimaProcessContainerClass == null) {
+ // use default
+ return "org.apache.uima.ducc.user.jp.UimaProcessContainer";
+ } else {
+ return common.uimaProcessContainerClass;
+ }
+ }
+ }
+
+ @Bean
+ public ServiceComponent getServiceInstance() throws Exception {
+ try {
+ checkPrereqs();
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ try {
+
+ // Assume IP address provided from environment. In production this
+ // will be the actual node IP. In testing, the IP can be virtual
+ // when running multiple agents on the same node. The agent is
+ // responsible for providing the IP in this process environment.
+ String thisNodeIP = (System.getenv("IP") == null) ? InetAddress
+ .getLocalHost().getHostAddress() : System.getenv("IP");
+ camelContext = common.camelContext();
+
+ // custom processor class can be provided in the command line.
+ // Its not required. If not present, this code will assign one
+ // based on jobType
+ if ( System.getProperty(FlagsHelper.Name.JpProcessorClass.pname() ) == null ) {
+ String containerClass = "org.apache.uima.ducc.user.service.UimaASServiceContainer";
+ // Save the container class. This will be referenced from the
+ // DuccJobService.initialize()
+ System.setProperty(FlagsHelper.Name.JpProcessorClass.pname(),//"ducc.deploy.processor.class",
+ containerClass);
+ }
+
+ int serviceSocketPort = 0;
+ String agentSocketParams = "";
+ String jpSocketParams = "";
+ if (common.managedServiceEndpointParams != null) {
+ jpSocketParams = "?" + common.managedServiceEndpointParams;
+ }
+ if (common.managedProcessStateUpdateEndpointParams != null) {
+ agentSocketParams = "?"
+ + common.managedProcessStateUpdateEndpointParams;
+ }
+ // set up agent socket endpoint where this UIMA AS service will send
+ // state updates
+ if (common.managedProcessStateUpdateEndpointType != null
+ && common.managedProcessStateUpdateEndpointType
+ .equalsIgnoreCase("socket")) {
+ common.managedProcessStateUpdateEndpoint = AGENT_ENDPOINT
+ + System.getProperty(ProcessStateUpdate.ProcessStateUpdatePort)
+ + agentSocketParams;
+ }
+ // set up a socket endpoint where the UIMA AS service will receive
+ // events sent from its agent
+ if (common.managedServiceEndpointType != null
+ && common.managedServiceEndpointType
+ .equalsIgnoreCase("socket")) {
+ serviceSocketPort = Utils.findFreePort();
+ // service is on the same node as the agent
+ common.managedServiceEndpoint = AGENT_ENDPOINT
+ + serviceSocketPort + jpSocketParams;
+ }
+
+ DuccEventDispatcher eventDispatcher = transport
+ .duccEventDispatcher(
+ common.managedProcessStateUpdateEndpoint,
+ camelContext);
+
+ // Create Agent proxy which will be used to notify Agent
+ // of state changes.
+ agent = new AgentSession(eventDispatcher,
+ System.getenv("ProcessDuccId"),
+ common.managedServiceEndpoint);
+
+ System.out
+ .println("#######################################################");
+ System.out.println("## Agent Service State Update Endpoint:"
+ + common.managedProcessStateUpdateEndpoint + " ##");
+ System.out
+ .println("#######################################################");
+
+
+ duccComponent = new ServiceComponent("UimaProcess",
+ camelContext, this);
+
+ // jobProcessManager = new JobProcessManager();
+ duccComponent.setAgentSession(agent);
+ // duccComponent.setJobProcessManager(jobProcessManager);
+ duccComponent.setSaxonJarPath(common.saxonJarPath);
+ duccComponent.setDd2SpringXslPath(common.dd2SpringXslPath);
+
+ ServiceEventListener eventListener =
+ new ServiceEventListener(duccComponent);
+
+ routeBuilder = this.routeBuilderForIncomingRequests(thisNodeIP,
+ eventListener);
+
+ camelContext.addRoutes(routeBuilder);
+
+ return duccComponent;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+ private class DuccProcessFilter implements Predicate {
+ String thisNodeIP;
+
+ public DuccProcessFilter(final String thisNodeIP) {
+ this.thisNodeIP = thisNodeIP;
+ }
+
+ public synchronized boolean matches(Exchange exchange) {
+ // String methodName="DuccProcessFilter.matches";
+ boolean result = false;
+ try {
+ String pid = (String) exchange.getIn().getHeader(
+ DuccExchange.ProcessPID);
+ String targetIP = (String) exchange.getIn().getHeader(
+ DuccExchange.DUCCNODEIP);
+ // check if this message is targeting this process. Check if the
+ // process PID
+ // and the node match target process.
+ if (Utils.getPID().equals(pid) && thisNodeIP.equals(targetIP)) {
+ result = true;
+ System.out
+ .println(">>>>>>>>> Process Received a Message. Is Process target for message:"
+ + result + ". Target PID:" + pid);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceConfiguration.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java?rev=1659357&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java Thu Feb 12 18:46:50 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.transport.configuration.service;
+
+//import org.apache.uima.ducc.agent.deploy.ManagedService;
+import org.apache.camel.Body;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
+import org.apache.uima.ducc.transport.event.ProcessStopDuccEvent;
+import org.apache.uima.ducc.transport.event.delegate.DuccEventDelegateListener;
+
+
+public class ServiceEventListener implements DuccEventDelegateListener{
+ private ServiceComponent duccComponent;
+
+ public ServiceEventListener(ServiceComponent component) {
+ duccComponent = component;
+ }
+
+ public void setDuccEventDispatcher(DuccEventDispatcher eventDispatcher) {
+ }
+
+ public void onProcessStop(@Body ProcessStopDuccEvent event) {
+ duccComponent.stop();
+ }
+
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/service/ServiceEventListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java?rev=1659357&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java Thu Feb 12 18:46:50 2015
@@ -0,0 +1,115 @@
+/*
+ * 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.user.service;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.uima.adapter.jms.activemq.SpringContainerDeployer;
+import org.apache.uima.adapter.jms.service.UIMA_Service;
+import org.apache.uima.ducc.user.jp.DuccAbstractProcessContainer;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+/**
+ * This class is used to deploy DUCC UIMA-AS based services
+ *
+ */
+public class UimaASServiceContainer extends DuccAbstractProcessContainer
+implements ApplicationListener<ApplicationEvent> {
+ private static final Class<?> CLASS_NAME = UimaASServiceContainer.class;
+ // command line args
+ private String[] args = null;
+ // UIMA-AS service deployer
+ private SpringContainerDeployer serviceDeployer;
+
+ public volatile boolean initialized = false;
+ /**
+ * When true, DUCC will call deploy, process, and stop using the same
+ * thread. Otherwise, no such guarantee is provided.
+ *
+ */
+ public boolean useThreadAffinity() {
+ return false;
+ }
+ /**
+ * Generates Spring context file from provided deployment descriptor
+ * and deploys UIMA-AS service from it. Once deployed, the UIMA-AS
+ * service begins listening on its JMS queue and processes work.
+ *
+ */
+ protected void doDeploy() throws Exception {
+ UIMA_Service service = new UIMA_Service();
+ if ( args == null || args.length == 0 ) {
+ throw new RuntimeException("Unable to Deploy UIMA-AS service Due to Missing Deployment Descriptor ");
+ }
+ // parse command args and run dd2spring to generate spring context
+ // files from deployment descriptors
+
+ String[] contextFiles = service.initialize(args);
+ if (contextFiles == null) {
+ throw new Exception(
+ "Spring Context Files Not Generated. Unable to Launch Uima AS Service");
+ }
+
+ // Deploy components defined in Spring context files.
+ // !!!! NOTE:This method blocks until the container is fully
+ // initialized and all UIMA-AS components are successfully deployed
+ // or there is a failure.
+ serviceDeployer = service.deploy(contextFiles, this);
+
+ if (serviceDeployer == null || serviceDeployer.initializationFailed()) {
+ System.out
+ .println(">>> Failed to Deploy UIMA Service");
+ throw new ResourceInitializationException(new RuntimeException("Unable to deploy UIMA-AS service from "+args[0]));
+ } else {
+ System.out
+ .println(">>> Service Container Deployed Successfully");
+ }
+ }
+
+ protected int doInitialize(Properties p, String[] args) throws Exception {
+ this.args = args;
+ return 1; // default scaleout of 1
+ }
+
+ protected void doStop() throws Exception {
+ if (serviceDeployer != null) {
+ // Use top level controller to stop all components
+ serviceDeployer.getTopLevelController().stop();
+ }
+ }
+ /**
+ * This is just a stub and will not be called as UIMA-AS based
+ * service takes work items from its JMS queue directly.
+ *
+ */
+ protected List<Properties> doProcess(Object subject) throws Exception {
+ return null;
+ }
+
+ /**
+ * This is a callback method called by UIMA-AS during initialization
+ */
+ public void onApplicationEvent(ApplicationEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/service/UimaASServiceContainer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain