Author: cwiklik Date: Thu Jan 28 18:43:55 2016 New Revision: 1727417 URL: http://svn.apache.org/viewvc?rev=1727417&view=rev Log: UIMA-4773 Refactored Agent and JP to use SIGTERM signal to quiesce and stop JP
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.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=1727417&r1=1727416&r2=1727417&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 Jan 28 18:43:55 2016 @@ -295,6 +295,104 @@ public class DuccCommandExecutor extends private void stopProcess(ICommandLine cmdLine, String[] cmd) throws Exception { String methodName = "stopProcess"; + + + 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 { + // NEW Code + logger.info(methodName, + ((ManagedProcess) super.managedProcess).getDuccId(), + ">>>>>>>>>>>>>>> Stopping Process:" + + ((ManagedProcess) managedProcess).getPid()); + ICommandLine cmdL; + if (Utils.isWindows()) { + cmdL = new NonJavaCommandLine("taskkill"); + cmdL.addArgument("/PID"); + } else { + cmdL = new NonJavaCommandLine("/bin/kill"); + cmdL.addArgument("-15"); + } + cmdL.addArgument(((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 Killer Timer Task 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); + + + } + } + + + } 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( @@ -569,6 +667,9 @@ public class DuccCommandExecutor extends ((ManagedProcess) super.managedProcess).getDuccId(), e, new Object[] {}); } + +*/ + } private void startProcess(ICommandLine cmdLine, String[] cmd,