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 2015/01/05 20:18:25 UTC

svn commit: r1649616 - in /uima/sandbox/uima-ducc/trunk: src/main/admin/ uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/ uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/schedu...

Author: challngr
Date: Mon Jan  5 19:18:25 2015
New Revision: 1649616

URL: http://svn.apache.org/r1649616
Log:
UIMA-4142 Dynamic Scheduler reconfiguration

Added:
    uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure   (with props)
Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/AbstractDuccComponent.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/JobManagerConverter.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ResourceManagerComponent.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/ISchedulerMain.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodePool.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java

Added: uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure?rev=1649616&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure (added)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure Mon Jan  5 19:18:25 2015
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# -----------------------------------------------------------------------
+# 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.
+# -----------------------------------------------------------------------
+
+
+import os
+import sys
+
+from ducc_util  import DuccUtil
+
+class DuccRmReconfigure(DuccUtil):
+
+    def usage(self, msg):
+        if ( msg != None ):
+            print msg
+
+        print 'Usage:'
+        print '   rm_reconfigure'
+        print ''
+        print 'Notes:'
+        print '    This forces the RM to stop scheduling, reread its configuration, and restart the scheduler.'
+        print 'This is the equivalent of stopping RM, waiting for it to quiesce, and restarting RM.'
+        sys.exit(1)
+    
+    def main(self, args):
+
+        print 'Reconfiguring RM'
+        DUCC_JVM_OPTS = ' -Dducc.deploy.configuration=' + self.DUCC_HOME + "/resources/ducc.properties "
+        DUCC_JVM_OPTS = DUCC_JVM_OPTS + ' -DDUCC_HOME=' + self.DUCC_HOME
+        DUCC_JVM_OPTS = DUCC_JVM_OPTS + ' -Dducc.head=' + self.ducc_properties.get('ducc.head')
+
+        self.spawn(self.java(), DUCC_JVM_OPTS, 'org.apache.uima.ducc.common.main.DuccRmAdmin', '--reconfigure')
+        return
+
+if __name__ == "__main__":
+    np = DuccRmReconfigure()
+    np.main(sys.argv[1:])
+
+    

Propchange: uima/sandbox/uima-ducc/trunk/src/main/admin/rm_reconfigure
------------------------------------------------------------------------------
    svn:executable = *

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/AbstractDuccComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/AbstractDuccComponent.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/AbstractDuccComponent.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/component/AbstractDuccComponent.java Mon Jan  5 19:18:25 2015
@@ -143,6 +143,20 @@ public abstract class AbstractDuccCompon
     composeBrokerUrl();
   }
 
+  public void reloadProperties(String componentProperties) throws Exception {
+    DuccProperties duccProperties = new DuccProperties();
+    duccProperties.load((String) System.getProperty(componentProperties));
+    Properties sysprops = System.getProperties();
+    for (Map.Entry<Object, Object> entry : duccProperties.entrySet()) {
+        String key = ((String) entry.getKey()).trim();
+        sysprops.remove(key);
+    }
+    // resolve any placeholders
+    enrichSystemPropertiesWith(duccProperties);
+    // Compose Broker URL from parts defined in ducc.properties
+    composeBrokerUrl();
+  }
+
   /**
    * Resolve any placeholders in property values in provided DuccProperties
    * Adjust the *endpoint ones before copying to the System properties

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/JobManagerConverter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/JobManagerConverter.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/JobManagerConverter.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/JobManagerConverter.java Mon Jan  5 19:18:25 2015
@@ -683,10 +683,20 @@ public class JobManagerConverter
         }
 
         // The init file is read and configured ?
-        if ( ! scheduler.isInitialized() ) return;
-        
+        if ( ! scheduler.isInitialized() ) return;   // handle race, OR pub comes in while RM is (re)configuring itself
+
+        if ( scheduler.mustRecover() ) {             // UIMA-4142 reconfig happened. 
+            // must do this independently of isInitialized() since reinit could happen fully between OR pubs
+            localMap = new DuccWorkMap();            // as if RM had been booted
+            lastJobManagerUpdate = new JobManagerUpdate();
+            refusedJobs.clear();
+            first_or_state = true;
+        }
+
         if ( first_or_state ) {
             first_or_state = false;
+            scheduler.setRecovery(false);
+
             if ( ! recoverFromOrchestrator(jobMap) ) {
                 logger.info(methodName, null, "There are no active jobs in map so can't build up state. Waiting for init stability.");
                 return;
@@ -700,7 +710,7 @@ public class JobManagerConverter
 
         // scheduler is readied either by fast-recovery, or by init stability
         if ( !scheduler.ready() ) {
-            logger.info(methodName, null, "Orchestrator event is discarded: waiting for init stability.");
+            logger.info(methodName, null, "Orchestrator event is discarded: scheduler is waiting for init stability or is paused for reconfig..");
             return;
         }
 

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ResourceManagerComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ResourceManagerComponent.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ResourceManagerComponent.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/ResourceManagerComponent.java Mon Jan  5 19:18:25 2015
@@ -77,7 +77,7 @@ public class ResourceManagerComponent
 
     public ResourceManagerComponent(CamelContext context) {
         super("ResourceManager", context);
-        this.scheduler = new Scheduler();
+        this.scheduler = new Scheduler(this);          // UIMA-4142 pass 'this' in so we can reconfig (reread ducc.properties)
     }
     
     public ISchedulerMain getScheduler()

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/ISchedulerMain.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/ISchedulerMain.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/ISchedulerMain.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/ISchedulerMain.java Mon Jan  5 19:18:25 2015
@@ -68,7 +68,9 @@ public interface ISchedulerMain
     //    has the scheduler read it's config files and initialized structures?
     //    has the scheduler discovered enough resources that it can schedule work?
     boolean isInitialized();              // has scheduler read all it's config and set up its strucures?
-    boolean ready();                    // have enough resources checked in so scheduler can schedule work?
+    boolean ready();                      // have enough resources checked in so scheduler can schedule work?
+    boolean mustRecover();                // UIMA-4142 RM was reconfigured so must recover from OR
+    void    setRecovery(boolean r);       // UIMA-4142 signal RM that the outer layer has completed recovery
 
     // once both initialized() and ready() occur, the RM scaffolding will enable scheduling by calling start
     void start();

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodePool.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodePool.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodePool.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodePool.java Mon Jan  5 19:18:25 2015
@@ -110,7 +110,7 @@ class NodePool
         if ( nodes == null ) {            // unlikely, but not illegal
             this.subpoolNames = new HashMap<String, String>();
             logger.warn(methodName, null, "Nodepool", id, ": no nodes in node list");
-        }
+        } 
         this.evictionPolicy = ep;
         this.depth = depth;
         this.order = order;
@@ -224,6 +224,20 @@ class NodePool
     }
 
     /**
+     * Return nodes varied off for me and my kids.
+     * UIMA-4142, RM reconfiguration
+     */
+    Map<Node, Machine> getOfflineMachines()
+    {
+        @SuppressWarnings("unchecked")
+		Map<Node, Machine> ret = (Map<Node, Machine>) offlineMachines.clone();
+        for (NodePool np : children.values()) {
+            ret.putAll(np.getOfflineMachines());
+        }
+        return ret;
+    }
+
+    /**
      * Non-recursive machine count.
      */
     int countLocalMachines()
@@ -343,7 +357,39 @@ class NodePool
     }
 
     /**
-     * Interrogate whether work assigned to the indicated rc could end up in this np or its children.
+     * Helper for compatibleNodepool(), recurses down children.
+     * UIMA-4142
+     */
+    private boolean isCompatibleNodepool(Policy p, ResourceClass rc)
+    {
+        if ( allClasses.containsKey(rc) ) return true;
+        for (NodePool np : children.values()) {
+            if ( np.isCompatibleNodepool(p, rc) ) return true;
+        }      
+        return false;
+    }
+
+    /**
+     * Helper for compatibleNodepool(), find the top of the heirarchy.
+     * UIMA-4142
+     */
+    NodePool findTopOfHeirarchy()
+    {
+        NodePool ret = this;
+        while (ret.getParent() != null) {
+            ret = ret.getParent();
+        }
+        return ret;
+    }
+
+    /**
+     * Interrogate whether work assigned to the indicated rc could end up here.  
+     *
+     * If it's a fair-share allocation, we need to interrogate 'me', my children, and 
+     * my ancestors.
+     *
+     * If it's something else, it must reside reight here.
+     *
      * This is called during recovery; a change to the class or np config can cause incompatibilities
      * with previously scheduled work after a restart.
      *
@@ -357,10 +403,8 @@ class NodePool
     {
         switch ( p ) {
             case FAIR_SHARE:
-                if ( allClasses.containsKey(rc) ) return true;
-                for (NodePool np : children.values()) {
-                    if ( np.compatibleNodepool(p, rc) ) return true;
-                }
+                NodePool top = findTopOfHeirarchy();
+                return top.isCompatibleNodepool(p, rc);
             case FIXED_SHARE:
             case RESERVE:
                 if ( allClasses.containsKey(rc) ) return true;

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/NodepoolScheduler.java Mon Jan  5 19:18:25 2015
@@ -1055,7 +1055,7 @@ public class NodepoolScheduler
         logger.trace(methodName, null, "Exit : needyJobs.size =", needyJobs.size());
     }
 
-    private static int stop_here_dx = 0;
+    // private static int stop_here_dx = 0;
     protected void traverseNodepoolsForExpansion(NodePool np, ArrayList<ResourceClass> rcs)
     {
     	String methodName = "traverseNodepoolsForExpansion";
@@ -1066,13 +1066,13 @@ public class NodepoolScheduler
             traverseNodepoolsForExpansion(subpool, rcs);
         }
 
-        logger.info(methodName, null, "--- stop_here_dx", stop_here_dx);
-        if ( stop_here_dx == 13 ) {
-            @SuppressWarnings("unused")
-			int stophere;
-            stophere=1;
-        }
-        stop_here_dx++;
+        // logger.info(methodName, null, "--- stop_here_dx", stop_here_dx);
+        // if ( stop_here_dx == 13 ) {
+        //     @SuppressWarnings("unused")
+		// 	int stophere;
+        //     stophere=1;
+        // }
+        // stop_here_dx++;
 
         // fall through at leaves
         
@@ -1106,7 +1106,7 @@ public class NodepoolScheduler
      * Counts are established.  We strictly honor them inside each job and evict where the count is 
      * less than the currently allocated shares, and add where it is greater.
      */
-    static int stophere = 0;
+    //static int stophere = 0;
     protected void whatOfFairShare(ArrayList<ResourceClass> rcs)
     {
     	String methodName = "whatOfFairShare";
@@ -1133,12 +1133,12 @@ public class NodepoolScheduler
         }
 
         //traverseNodepoolsForEviction(globalNodepool, eligible);
-        logger.trace(methodName, null, "Machine occupancy before expansion", stophere++);
-        if ( stophere == 7 ) {
-            @SuppressWarnings("unused")
-			int stophere;
-            stophere = 1 ;
-        }
+        // logger.trace(methodName, null, "Machine occupancy before expansion", stophere++);
+        // if ( stophere == 7 ) {
+        //     @SuppressWarnings("unused")
+		// 	int stophere;
+        //     stophere = 1 ;
+        // }
         traverseNodepoolsForExpansion(globalNodepool, eligible);
     }
 

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java?rev=1649616&r1=1649615&r2=1649616&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-rm/src/main/java/org/apache/uima/ducc/rm/scheduler/Scheduler.java Mon Jan  5 19:18:25 2015
@@ -32,6 +32,7 @@ import org.apache.uima.ducc.common.NodeI
 import org.apache.uima.ducc.common.Pair;
 import org.apache.uima.ducc.common.admin.event.RmAdminQLoadReply;
 import org.apache.uima.ducc.common.admin.event.RmAdminQOccupancyReply;
+import org.apache.uima.ducc.common.component.AbstractDuccComponent;
 import org.apache.uima.ducc.common.utils.DuccLogger;
 import org.apache.uima.ducc.common.utils.DuccProperties;
 import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
@@ -64,7 +65,8 @@ public class Scheduler
     NodeConfiguration configuration = null;                               // UIMA-4142 make it global
     
     String defaultDomain = null;                                          // UIMA-4142
-    
+    boolean needRecovery = false;                                         // UIMA-4142 tell outer layer that recovery is required
+    AbstractDuccComponent baseComponent;                                  // UIMA-4142, pass in the base for reconfig - reread ducc.properties
     NodePool[] nodepools;                                                 // top-level nodepools
     int max_order = 0;
 
@@ -148,8 +150,9 @@ public class Scheduler
     final static String rmversion_string = null;
 
     boolean initialized = false;           // we refuse nodeupdates until this is true
-    public Scheduler()
+    public Scheduler(AbstractDuccComponent baseComponent)
     {
+        this.baseComponent = baseComponent;                // UIMA-4142, pass in the base for reconfig
     }
 
     public synchronized void init()
@@ -255,9 +258,71 @@ public class Scheduler
         initialized = true;
     }
 
-    public synchronized String reconfigure()          // UIMA-4142
+    public String reconfigure()          // UIMA-4142
+    {
+        String methodName = "reconfigure";
+
+        logger.info(methodName, null, "Reconfiguration starts.");
+
+        setInitialized(false);           // stop receipt of OR and Agent publications
+
+        HashMap<Node, Machine> offlineMachines                   = new HashMap<Node, Machine>();
+        for (NodePool np : nodepools) {
+            offlineMachines.putAll(np.getOfflineMachines());            
+        }
+
+        // (be careful, don't use the value, that must be discarded as it points to the OLD np)
+        List<String> offlineHostnames = new ArrayList<String>();
+        for ( Machine m : offlineMachines.values()) {
+        	logger.info(methodName, null, "Saving offline status of", m.getId());
+            offlineHostnames.add(m.getId());
+        }
+        offlineMachines = null;
+
+        this.configuration = null;
+        this.defaultDomain = null;
+        this.nodepools = null;
+        this.max_order = 0;
+        this.busyShares.clear();
+        this.vacatedShares.clear();
+        this.incomingJobs.clear();
+        this.recoveredJobs.clear();
+        this.initializedJobs.clear();
+        this.deadNodes.clear();
+        this.nodepoolsByNode.clear();
+        this.shortToLongNode.clear();
+        this.users.clear();
+        this.allJobs.clear();
+        this.resourceClasses.clear();
+        this.resourceClassesByName.clear();
+
+        try {
+            baseComponent.reloadProperties("ducc.deploy.configuration");
+            init();
+
+            if ( offlineHostnames.size() > 0 ) {
+                String[] offline = offlineHostnames.toArray(new String[offlineHostnames.size()]);
+                varyoff(offline);
+            }
+        } catch ( Throwable t ) {
+        	// TODO do something?  What?  If this fails its pretty awful.
+        }
+        
+        setRecovery(true);               // signal to outer layer that full recovery is needed
+        setInitialized(true);            // resume receipt of publications
+        logger.info(methodName, null, "Reconfiguration complete.");
+
+        return "Reconfiguration complete.";
+    }
+
+    public synchronized void setRecovery(boolean v)
+    {
+        this.needRecovery = v;
+    }
+
+    public synchronized boolean mustRecover()
     {
-    	return "Reconfigure not implemented.";
+        return this.needRecovery;
     }
 
     public synchronized boolean isInitialized()
@@ -265,6 +330,11 @@ public class Scheduler
         return initialized;
     }
 
+    public synchronized void setInitialized(boolean v)
+    {
+        this.initialized = v;
+    }
+
     public Machine getMachine(Node n)
     {
         return getMachine(n.getNodeIdentity());
@@ -545,6 +615,7 @@ public class Scheduler
             @SuppressWarnings("unchecked")
 			Class<IScheduler> cl = (Class<IScheduler>) Class.forName(schedImplName);
             for ( int i = 0; i < nps.length; i++ ) {
+                logger.info(methodName, null, "Rebuilding", schedImplName, "for top level nodepool", nps[i].get("name"));
                 schedulers[i] = (IScheduler) cl.newInstance();
                 schedulers[i].setEvictionPolicy(evictionPolicy);
             }
@@ -746,6 +817,7 @@ public class Scheduler
     	String methodName = "handleDeadNodes";
     	
         if ( ! isInitialized() ) {
+            logger.info(methodName, null, "Waiting for (re)initialization.");
             return;
         }
 
@@ -794,6 +866,7 @@ public class Scheduler
         }
 
         if ( ! isInitialized() ) {
+            logger.info(methodName, null, "Waiting for (re)initialization.");
             return null;
         }
 
@@ -1006,7 +1079,7 @@ public class Scheduler
         logger.info(methodName, null, "Map", longname, "to", np.getId());
         nodepoolsByNode.put(longname, np);
 
-        if ( ndx >=0 ) {
+        if ( ndx >= 0 ) {
             shortname = longname.substring(0, ndx);
             nodepoolsByNode.put(shortname, np);
             shortToLongNode.put(shortname, longname);
@@ -1035,6 +1108,12 @@ public class Scheduler
     private int total_arrivals = 0;
     public synchronized void nodeArrives(Node node)
     {        
+        String methodName = "nodeArrives";
+        if ( ! isInitialized() ) {
+            logger.info(methodName, null, "Waiting for (re)initialization; node = " + node.getNodeIdentity().getName());
+            return;
+        }
+
     	// String methodName = "nodeArrives";
         // The first block insures the node is in the scheduler's records as soon as possible