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 2016/03/27 21:06:58 UTC

svn commit: r1736808 - in /uima/sandbox/uima-ducc/trunk: uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/

Author: cwiklik
Date: Sun Mar 27 19:06:58 2016
New Revision: 1736808

URL: http://svn.apache.org/viewvc?rev=1736808&view=rev
Log:
UIMA-4878 set process state to Stopped only when it exits 

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/CommandExecutor.java
    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-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessComponent.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/CommandExecutor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/CommandExecutor.java?rev=1736808&r1=1736807&r2=1736808&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/CommandExecutor.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/CommandExecutor.java Sun Mar 27 19:06:58 2016
@@ -72,11 +72,10 @@ public abstract class CommandExecutor im
 		    boolean isAPorJD = ((ManagedProcess) managedProcess).isJd() ||
 			((ManagedProcess) managedProcess).getDuccProcess().getProcessType().equals(ProcessType.Pop);
 
-		    // JDs and APs don't report internal status to the agent (initializing or running) so assume these start and enter Running state
+		    // JDs and APs dond't report internal status to the agent (initializing or running) so assume these start and enter Running state
 		    if (isAPorJD && !((ManagedProcess) managedProcess).getDuccProcess().getProcessState().equals(ProcessState.Stopped)) {
 			((ManagedProcess) managedProcess).getDuccProcess().setProcessState(ProcessState.Running);
 		    }
-					
 		    try {
 			synchronized(this) {
 			    // wait for 5 seconds before starting the camel route

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=1736808&r1=1736807&r2=1736808&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 Sun Mar 27 19:06:58 2016
@@ -393,293 +393,14 @@ public class DuccCommandExecutor extends
 					.getProcessState());
 			    doExec(new ProcessBuilder(cmd), cmd, true);
 
-
 			}
 		    }
 
-
 		} catch (Exception e) { // InterruptedException, ExecutionException
 		    logger.error(methodName,
 				 ((ManagedProcess) super.managedProcess).getDuccId(), e,
 				 new Object[] {});
 		}
-/*
-		Future<?> future = ((ManagedProcess) managedProcess).getFuture();
-		if (future == null) {
-			throw new Exception(
-					"Future Object not Found. Unable to Stop Process with PID:"
-							+ ((ManagedProcess) managedProcess).getPid());
-		}
-		// for stop to work, PID must be provided
-		if (((ManagedProcess) managedProcess).getDuccProcess().getPID() == null
-				|| ((ManagedProcess) managedProcess).getDuccProcess().getPID()
-						.trim().length() == 0) {
-			throw new Exception(
-					"Process Stop Command Failed. PID not provided.");
-		}
-		long maxTimeToWaitForProcessToStop = 60000; // default 1 minute
-		if (super.agent.configurationFactory.processStopTimeout != null) {
-			maxTimeToWaitForProcessToStop = Long
-					.valueOf(super.agent.configurationFactory.processStopTimeout);
-		}
-		try {
-			// if the process is marked for death or still initializing or it is
-			// JD, kill it
-			if (((ManagedProcess) managedProcess).doKill()
-                                                    					|| ((ManagedProcess) managedProcess).getDuccProcess()
-							.getProcessType().equals(ProcessType.Service)
-					|| ((ManagedProcess) managedProcess).getDuccProcess()
-							.getProcessType().equals(ProcessType.Pop)
-					|| ((ManagedProcess) managedProcess).getDuccProcess()
-							.getProcessState()
-							.equals(ProcessState.Initializing)
-					|| ((ManagedProcess) managedProcess).getDuccProcess()
-							.getProcessState().equals(ProcessState.Starting)
-					|| ((ManagedProcess) managedProcess).getDuccProcess()
-							.getProcessState()
-							.equals(ProcessState.FailedInitialization)) {
-				logger.info(methodName,
-						((ManagedProcess) super.managedProcess).getDuccId(),
-						">>>>>>>>>>>>>>> Killing Process:"
-								+ ((ManagedProcess) managedProcess).getPid());
-
-				if (((ManagedProcess) managedProcess).getDuccProcess()
-						.getProcessType().equals(ProcessType.Service)
-						|| ((ManagedProcess) managedProcess).getDuccProcess()
-								.getProcessType().equals(ProcessType.Pop)) {
-					ICommandLine cmdL;
-					if (Utils.isWindows()) {
-						cmdL = new NonJavaCommandLine("taskkill");
-						cmdL.addArgument("/PID");
-					} else {
-						cmdL = new NonJavaCommandLine("/bin/kill");
-						cmdL.addArgument("-15");
-						// if ( ((ManagedProcess) managedProcess).isJd() ) {
-						// // kill JD hard.
-						// cmdL.addArgument("-9");
-						// } else {
-						// cmdL.addArgument("-15");
-						// }
-					}
-					cmdL.addArgument(((ManagedProcess) managedProcess)
-							.getDuccProcess().getPID());
-
-					// String[] sigTermCmdLine = new String[]
-					// {"/bin/kill","-15",((ManagedProcess)
-					// managedProcess).getDuccProcess().getPID()};
-					String[] sigTermCmdLine = getDeployableCommandLine(cmdL,
-							new HashMap<String, String>());
-					doExec(new ProcessBuilder(sigTermCmdLine), sigTermCmdLine,
-							true);
-
-				    try {
-						logger.info(methodName,
-								((ManagedProcess) super.managedProcess)
-										.getDuccId(),
-								"------------ Agent Starting Timer For Process with PID:"
-										+ ((ManagedProcess) managedProcess)
-												.getDuccProcess().getPID()
-										+ " Process State: "
-										+ ((ManagedProcess) managedProcess)
-												.getDuccProcess()
-												.getProcessState());
-						future.get(maxTimeToWaitForProcessToStop,
-								TimeUnit.MILLISECONDS);
-
-				    } catch(TimeoutException te) {
-				    	if (((ManagedProcess) super.managedProcess)
-								.getDuccProcess().getProcessState()
-								.equals(ProcessState.Running)) {
-				    		
-					    	logger.info(
-									methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									"------------ Agent Timed-out Waiting for Process with PID:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " to Stop. Process State:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState()
-											+ " .Process did not stop in allotted time of "
-											+ maxTimeToWaitForProcessToStop
-											+ " millis");
-							logger.info(methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									">>>>>>>>>>>>>>> Killing Process:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " .Process State:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState());
-							doExec(new ProcessBuilder(cmd), cmd, true);
-
-
-				    	}
-				    }
-				} else {
-					doExec(new ProcessBuilder(cmd), cmd, true);
-				}
-				// doExec(new ProcessBuilder(cmd), cmd, true);
-			} else { // send stop request to quiesce the service
-				Map<String, Object> msgHeader = new HashMap<String, Object>();
-				// Add PID to the header. Receiving process has a PID filter in
-				// its router
-				// to determine if the stop message is destined for it.
-				msgHeader.put(DuccExchange.ProcessPID,
-						((ManagedProcess) managedProcess).getPid());
-				msgHeader.put(DuccExchange.DUCCNODEIP,
-						((ManagedProcess) managedProcess).getDuccProcess()
-								.getNodeIdentity().getIp());
-				logger.info(methodName,
-						((ManagedProcess) super.managedProcess).getDuccId(),
-						"Agent Sending Stop request to remote process with PID:"
-								+ ((ManagedProcess) managedProcess).getPid()
-								+ " On Node:"
-								+ ((ManagedProcess) managedProcess)
-										.getDuccProcess().getNodeIdentity()
-										.getIp());
-				try {
-					// Use either Mina (socket) or jms to communicate with an
-					// agent
-					if (((ManagedProcess) managedProcess).getSocketEndpoint() != null) {
-
-						logger.info(
-								methodName,
-								null,
-								"Agent Sending <<STOP>> to Endpoint:"
-										+ ((ManagedProcess) managedProcess)
-												.getSocketEndpoint());
-						// socket transport
-						super.agent
-								.getEventDispatcherForRemoteProcess()
-								.dispatch(
-										new ProcessStopDuccEvent(
-												new HashMap<DuccId, IDuccProcess>()),
-										((ManagedProcess) managedProcess)
-												.getSocketEndpoint(), msgHeader);
-
-					} else {
-						// jms transport
-						super.agent
-								.getEventDispatcherForRemoteProcess()
-								.dispatch(
-										new ProcessStopDuccEvent(
-												new HashMap<DuccId, IDuccProcess>()),
-										msgHeader);
-					}
-				} catch (Exception ex) {
-					logger.error(
-							methodName,
-							((ManagedProcess) super.managedProcess).getDuccId(),
-							ex, new Object[] {});
-				} finally {
-					logger.info(
-							methodName,
-							((ManagedProcess) super.managedProcess).getDuccId(),
-							"------------ Agent Dispatched STOP Request to Process with PID:"
-									+ ((ManagedProcess) managedProcess)
-											.getDuccProcess().getPID()
-									+ " Process State: "
-									+ ((ManagedProcess) managedProcess)
-											.getDuccProcess().getProcessState()
-									+ " Waiting for Process to Stop. Timout Value:"
-									+ maxTimeToWaitForProcessToStop + " millis");
-					try {
-						// Start Kill timer only if process is still running
-						if (((ManagedProcess) super.managedProcess)
-								.getDuccProcess().getProcessState()
-								.equals(ProcessState.Running)) {
-							// the following call will block!!! Waits for
-							// process to stop on its own. If it doesnt stop,
-							// kills it hard.
-							// The exact time the service is allotted for
-							// stopping is defined in ducc.properties
-							logger.info(methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									"------------ Agent Starting Timer For Process with PID:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " Process State: "
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState());
-							future.get(maxTimeToWaitForProcessToStop,
-									TimeUnit.MILLISECONDS);
-						} else {
-							logger.info(methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									"------------ Agent Dispatched STOP Request to Process with PID:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " Process State: "
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState()
-											+ " .Process Not In Running State");
-						}
-
-					} catch (TimeoutException tex) { // on time out kill the
-														// process
-						if (((ManagedProcess) super.managedProcess)
-								.getDuccProcess().getProcessState()
-								.equals(ProcessState.Running)
-								|| ((ManagedProcess) super.managedProcess)
-										.getDuccProcess().getProcessState()
-										.equals(ProcessState.Stopping)) {
-							logger.info(
-									methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									"------------ Agent Timed-out Waiting for Process with PID:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " to Stop. Process State:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState()
-											+ " .Process did not stop in allotted time of "
-											+ maxTimeToWaitForProcessToStop
-											+ " millis");
-							logger.info(methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									">>>>>>>>>>>>>>> Killing Process:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " .Process State:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState());
-							doExec(new ProcessBuilder(cmd), cmd, true);
-						} else {
-							logger.info(
-									methodName,
-									((ManagedProcess) super.managedProcess)
-											.getDuccId(),
-									"------------ Agent Timed-out Waiting for Process with PID:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess().getPID()
-											+ " to Stop but the process is not in a running state. Process State:"
-											+ ((ManagedProcess) managedProcess)
-													.getDuccProcess()
-													.getProcessState());
-						}
-					}
-				}
-			}
-		} catch (Exception e) { // InterruptedException, ExecutionException
-			logger.error(methodName,
-					((ManagedProcess) super.managedProcess).getDuccId(), e,
-					new Object[] {});
-		}
-
-*/
 
 	}
 
@@ -871,8 +592,6 @@ public class DuccCommandExecutor extends
 			    } 
 
 
-			    //				((ManagedProcess) managedProcess).getDuccProcess()
-			    //			.setProcessState(ProcessState.Stopped);
 				if (((ManagedProcess) super.managedProcess).doKill()) { // killed
 																		// by
 																		// agent/ducc
@@ -887,7 +606,8 @@ public class DuccCommandExecutor extends
 									ReasonForStoppingProcess.Other.toString());
 				}
 
-			} else if (!((ManagedProcess) managedProcess).getDuccProcess()
+			} else if ( !isKillCommand(cmdLine) &&
+                                        !((ManagedProcess) managedProcess).getDuccProcess()
 					.getProcessState()
 					.equals(ProcessState.InitializationTimeout)
 					&& !((ManagedProcess) managedProcess).getDuccProcess()

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java?rev=1736808&r1=1736807&r2=1736808&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java Sun Mar 27 19:06:58 2016
@@ -369,7 +369,7 @@ public class ManagedProcess implements P
 		String reason = getDuccProcess().getReasonForStoppingProcess();
 
 		ProcessState pstate = getDuccProcess().getProcessState();
-        boolean initError = (reason != null && (reason
+                boolean initError = (reason != null && (reason
 				.equals(ReasonForStoppingProcess.FailedInitialization
 						.toString()) || reason
 				.equals(ReasonForStoppingProcess.InitializationTimeout
@@ -379,10 +379,11 @@ public class ManagedProcess implements P
 				// if the process is to be killed due to init problems, set the
 				// state to Stopped
 				(reason != null && initError ) ) {
-			getDuccProcess().setProcessState(ProcessState.Stopped);
+		    //getDuccProcess().setProcessState(ProcessState.Stopped);
 			if ( !initError && ( exitcode - 128 == 9 || exitcode - 128 == 15 ) ) {  // killed with -9?
 				getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
 			}
+
 		} else {
 			// Process has terminated. Determine why the process terminated.
 			log("ManagedProcess.drainProcessStreams", "Ducc Process with PID:"

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessComponent.java?rev=1736808&r1=1736807&r2=1736808&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessComponent.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessComponent.java Sun Mar 27 19:06:58 2016
@@ -359,13 +359,12 @@ implements IJobProcessor{
 			return;  // already stopping - nothing to do
 		}
 
-		System.out.println("... JobProcessComponent - Stopping Service Adapter");
 	    try {
 	    	if ( workerThreadCount != null ) {
 	        	// block until all worker threads exit run()
 	        	workerThreadCount.await();
 	    	}
-        	
+		System.out.println("... JobProcessComponent - All Worker Threads Exited run()");
 			// 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
@@ -378,7 +377,6 @@ implements IJobProcessor{
 	    		tpe.shutdown();
 	    		tpe.awaitTermination(0, TimeUnit.MILLISECONDS);
 	    	}
-
         	if ( agent != null) {
             	agent.stop();
         	}
@@ -389,7 +387,7 @@ implements IJobProcessor{
 	    	try {
 		    	super.stop();
 	    	} catch( Exception ee) {}
-	    	System.exit(0);
+	    	Runtime.getRuntime().halt(0);
 	    }
 	}