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 2017/10/13 13:17:03 UTC

svn commit: r1812127 - in /uima/uima-ducc/trunk: uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/ uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/

Author: cwiklik
Date: Fri Oct 13 13:17:03 2017
New Revision: 1812127

URL: http://svn.apache.org/viewvc?rev=1812127&view=rev
Log:
UIMA-5611 added defunct process detector. It launches a ps command and scrapes the output. When detected the process state is changed to Stopped and reason is set to Defunct.

Added:
    uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java   (with props)
Modified:
    uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
    uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccProcess.java

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java?rev=1812127&r1=1812126&r2=1812127&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java Fri Oct 13 13:17:03 2017
@@ -51,6 +51,7 @@ import org.apache.uima.ducc.agent.config
 import org.apache.uima.ducc.agent.event.AgentEventListener;
 import org.apache.uima.ducc.agent.event.ProcessLifecycleObserver;
 import org.apache.uima.ducc.agent.launcher.CGroupsManager;
+import org.apache.uima.ducc.agent.launcher.DefunctProcessDetector;
 import org.apache.uima.ducc.agent.launcher.Launcher;
 import org.apache.uima.ducc.agent.launcher.ManagedProcess;
 import org.apache.uima.ducc.agent.launcher.ManagedProcess.StopPriority;
@@ -176,6 +177,8 @@ public class NodeAgent extends AbstractD
 
   public int numProcessors=0;
 
+  ExecutorService defunctDetectorExecutor = 
+		  Executors.newCachedThreadPool();
   private AgentEventListener eventListener;
 
   //  indicates whether or not this agent received at least one publication
@@ -1486,7 +1489,17 @@ public class NodeAgent extends AbstractD
           String pid = deployedProcess.getDuccProcess().getPID();
           processFound = true;
           if (deployedProcess.isStopping()) {
+            if ( isProcessRunning(deployedProcess.getDuccProcess())) {
+                logger.info(methodName, null, "....Checking if Proces with PID:" + process.getPID()+" is Defunct");
+
+            	// spin a thread where we check if the process is defunct. If true,
+            	// the process state is changed to Stopped and reason set to 'defunct'.
+            	// Next inventory publication will include this new state and the OR
+            	// can terminate a job.
+            	defunctDetectorExecutor.execute(new DefunctProcessDetector(deployedProcess, logger));
+            }
             logger.info(methodName, null, "....Process Already Stopping PID:" + process.getPID()+" Returning");
+            
             break; // this process is already in stopping state
           }
           logger.info(methodName, null, "....Undeploying Process - DuccId:" + process.getDuccId()

Added: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java?rev=1812127&view=auto
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java (added)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java Fri Oct 13 13:17:03 2017
@@ -0,0 +1,110 @@
+/*
+ * 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.agent.launcher;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.apache.uima.ducc.common.NodeIdentity;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.common.utils.id.DuccIdFactory;
+import org.apache.uima.ducc.transport.event.common.DuccProcess;
+import org.apache.uima.ducc.transport.event.common.IDuccProcess;
+import org.apache.uima.ducc.transport.event.common.IDuccProcess.ReasonForStoppingProcess;
+import org.apache.uima.ducc.transport.event.common.IProcessState.ProcessState;
+
+public class DefunctProcessDetector implements Runnable {
+	ManagedProcess childProcess;
+	DuccLogger logger;
+	public DefunctProcessDetector(ManagedProcess process, DuccLogger logger) {
+		childProcess = process;
+		this.logger = logger;
+	}
+	private  boolean isDefunctProcess(String pid) throws Exception {
+		boolean zombie = false;
+		InputStreamReader in = null;
+		String[] command = {
+				"/bin/ps",
+				"-ef",
+				pid};
+		try {
+			ProcessBuilder pb = new ProcessBuilder();
+			pb.command(command);
+
+			pb.redirectErrorStream(true);
+			java.lang.Process childProcess = pb.start();
+			in = new InputStreamReader(childProcess.getInputStream());
+			BufferedReader reader = new BufferedReader(in);
+			String line = null;
+			while ((line = reader.readLine()) != null) {
+				// the ps line will have string <defunct> if the 
+				// process is a zombie
+				zombie = (line.indexOf("defunct") > 0);
+				if ( zombie ) {
+					break;
+				}
+			}
+		} catch (Exception e) {
+			throw e;
+		} finally {
+			if (in != null) {
+				try {
+					in.close();
+				} catch (Exception e) {
+				}
+			}
+		}
+		return zombie;
+	}
+
+	public void run() {
+		try {
+			if (isDefunctProcess(childProcess.getPid())) {
+				logger.info("DefunctProcessDetector.run()", childProcess.getDuccProcess().getDuccId(), "Process with PID:"+childProcess.getPid()+" Is Defunct - Changing State to Stopped");
+				childProcess.getDuccProcess().setProcessState(ProcessState.Stopped);
+				childProcess.getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.Defunct.name());
+			} else {
+				logger.info("DefunctProcessDetector.run()", childProcess.getDuccProcess().getDuccId(), "Process with PID:"+childProcess.getPid()+" Not Defunct");
+
+			}
+		} catch( Exception e) {
+			logger.error("DefunctProcessDetector.run()", childProcess.getDuccProcess().getDuccId(), e);
+		}
+		
+	}
+	public static void main(String[] args) {
+		try {
+			DuccLogger logger = new DuccLogger(DefunctProcessDetector.class);
+			DuccIdFactory factory = new DuccIdFactory();
+			DuccId duccId = factory.next();
+			NodeIdentity nid = new NodeIdentity();
+			IDuccProcess process = new DuccProcess(duccId, nid);
+			ManagedProcess p = new ManagedProcess(process, null);
+			process.setProcessState(ProcessState.Initializing);
+			process.setPID(args[0]);
+			p.setPid(args[0]);
+			DefunctProcessDetector detector = new DefunctProcessDetector(p, logger);
+			detector.run();
+		} catch( Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+}

Propchange: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DefunctProcessDetector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccProcess.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccProcess.java?rev=1812127&r1=1812126&r2=1812127&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccProcess.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccProcess.java Fri Oct 13 13:17:03 2017
@@ -123,6 +123,7 @@ public interface IDuccProcess extends Se
 		KilledByDucc,
 		CommandLineMissing,
 		Unexplained,
+		Defunct,
 		Other
 	}