You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2014/02/26 20:32:33 UTC

svn commit: r1572212 - in /uima/sandbox/uima-ducc/trunk: uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java

Author: challngr
Date: Wed Feb 26 19:32:33 2014
New Revision: 1572212

URL: http://svn.apache.org/r1572212
Log:
UIMA-3405 Handle pinger with no service_ping_arguments specified.

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java?rev=1572212&r1=1572211&r2=1572212&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/AServicePing.java Wed Feb 26 19:32:33 2014
@@ -33,7 +33,8 @@ public abstract class AServicePing
     protected int total_failures = 0;           // current total run failures. usually monotonically increasing.
     protected int failure_max = 3;              // max allowed failures within any given window
 
-    protected int failure_window_size = 30;     // 30 minutes. overridden at first ping
+    protected int failure_window_period = 30;   // 30 minutes. overridden at first ping
+    protected int failure_window_size = failure_window_period;  // assume 1 ping per minute
     protected int monitor_rate = 1;             // ping rate, in minutes, min 1 used for calculations
 
     protected boolean log_enabled = false;
@@ -53,7 +54,7 @@ public abstract class AServicePing
      * @param endpoint This is the name of the service endpoint, as passed in
      *                 at service registration.
      */
-    public abstract void init(String arguments, String endpoint)  throws Exception;
+    public abstract void init(String arguments, String endpoint) throws Exception;
 
     /**
      * Called by the ping driver to initialize static information about the service and
@@ -77,6 +78,18 @@ public abstract class AServicePing
         throws Exception
     {
         this.initializationState = initState;
+
+        monitor_rate          = (Integer) initializationState.get("monitor-rate");        
+        service_id            = (Long)    initializationState.get("service-id") ;       
+        log_enabled           = (Boolean) initializationState.get("do-log");        
+        failure_max           = (Integer) initializationState.get("failure-max");        
+        failure_window_period = (Integer) initializationState.get("failure-window");
+
+        double  calls_per_minute = 60000.00 / monitor_rate;
+        failure_window_size = (int) ( ((double)failure_window_period) * calls_per_minute);
+
+        failure_window = new int[failure_window_size];
+        failure_cursor = 0;
         init(arguments, endpoint);
     }
 
@@ -193,20 +206,6 @@ public abstract class AServicePing
         String methodName = "isExcessiveFailures";
         boolean excessive_failures = false;
 
-        if ( failure_window == null ) {
-            // first time, init the failure analysis state from the static init properties
-            failure_window_size = (Integer) initializationState.get("failure-window");
-            failure_window = new int[failure_window_size];
-            failure_cursor = 0;
-        
-            monitor_rate = (Integer) initializationState.get("monitor-rate") / 60000;       // convert to minutes
-            if (monitor_rate <= 0 ) monitor_rate = 1;                                                // minimum 1 minute allowed
-        
-            service_id  = (Long) initializationState.get("service-id") ;       
-            log_enabled = (Boolean) initializationState.get("do-log");        
-            failure_max = (Integer) initializationState.get("failure-max");                                            
-        }
-
         // Calculate total instance failures within some configured window.  If we get a cluster
         // of failures, signal excessive failures so SM stops spawning new ones.
         int failures = (Integer) smState.get("run-failures");

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java?rev=1572212&r1=1572211&r2=1572212&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-sm/src/main/java/org/apache/uima/ducc/sm/ServicePingMain.java Wed Feb 26 19:32:33 2014
@@ -27,6 +27,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -56,13 +57,14 @@ public class ServicePingMain
     int error_count = 0;
 
     DuccProperties clioptions = new DuccProperties();
+    static final String None = "None";
 
     public ServicePingMain()
     {
     	clioptions.put("--class", clioptions);
     	clioptions.put("--endpoint", clioptions);
     	clioptions.put("--port", clioptions);
-    	clioptions.put("--arguments", clioptions);
+    	clioptions.put("--arguments", None);
     	clioptions.put("--initprops", clioptions);
     }
 
@@ -171,12 +173,20 @@ public class ServicePingMain
         }
 
         // Now make sure they all exist
-        for ( Object o : clioptions.keySet() ) {
+        ArrayList<String> toRemove = new ArrayList<String>();
+        for ( Object o : clioptions.keySet()) {
             String k = (String) o;
-            if ( clioptions.get(k) == clioptions ) {
+            Object v = clioptions.get(k);
+            if ( v == clioptions ) {
                 System.out.println("Missing argument: " + k);
                 System.exit(1);
             }
+            if ( v == None ) {             // optional arg, we want fetches to return null if it wasn't set 
+                toRemove.add(k);
+            }
+        }
+        for ( String k : toRemove ) {
+            clioptions.remove(k);
         }
     }
 
@@ -235,7 +245,7 @@ public class ServicePingMain
         }
         return ret;
     }
-
+    
     //
     // 1. Instantiate the pinger if possible.
     // 2. Read ducc.proeprties to find the ping interval
@@ -251,7 +261,7 @@ public class ServicePingMain
         IServiceStatistics default_statistics = new ServiceStatistics(false, false, "<N/A>");
 
         parseOptions(args);
-        String arguments = clioptions.getStringProperty("--arguments");
+        String arguments = clioptions.getProperty("--arguments");
         String pingClass = clioptions.getStringProperty("--class");
         String endpoint  = clioptions.getStringProperty("--endpoint");
         int port         = clioptions.getIntProperty   ("--port");