You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2014/02/20 20:24:50 UTC

git commit: AMBARI-4761. Single call to Maintenance for multiple hosts generates multiple requests (ncole)

Repository: ambari
Updated Branches:
  refs/heads/trunk e44bbb73c -> d4c021d8d


AMBARI-4761. Single call to Maintenance for multiple hosts generates multiple requests (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d4c021d8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d4c021d8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d4c021d8

Branch: refs/heads/trunk
Commit: d4c021d8de499f7deaeea7ab407b65d3a255550e
Parents: e44bbb7
Author: Nate Cole <nc...@hortonworks.com>
Authored: Thu Feb 20 11:18:40 2014 -0500
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Thu Feb 20 14:11:19 2014 -0500

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         | 20 ++++++++----
 .../server/controller/PassiveStateHelper.java   | 30 +++++++++++++-----
 .../internal/HostResourceProvider.java          | 18 +++++++----
 .../internal/ServiceResourceProvider.java       | 22 +++++++++-----
 .../AmbariManagementControllerTest.java         | 32 ++++++++++++++++++++
 .../controller/PassiveStateHelperTest.java      | 14 +++++----
 6 files changed, 103 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index d607eb4..8bf5afa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -1458,6 +1458,9 @@ public class AmbariManagementControllerImpl implements
         new HashMap<String, Map<String, Map<String, Set<String>>>>();
     Set<State> seenNewStates = new HashSet<State>();
     Map<ServiceComponentHost, State> directTransitionScHosts = new HashMap<ServiceComponentHost, State>();
+    Set<String> maintenanceClusters = new HashSet<String>();
+    
+    
     for (ServiceComponentHostRequest request : requests) {
       validateServiceComponentHostRequest(request);
 
@@ -1537,12 +1540,8 @@ public class AmbariManagementControllerImpl implements
               "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
           } else {
             sch.setPassiveState(newPassive);
-            try {
-              PassiveStateHelper.createRequest(this, sch.getClusterName(),
-                  requestProperties);
-            } catch (AmbariException e) {
-              LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
-            }
+            
+            maintenanceClusters.add(sch.getClusterName());
           }
         }
       }
@@ -1665,6 +1664,15 @@ public class AmbariManagementControllerImpl implements
         throw new AmbariException("Internal error - not supported transition", e);
       }
     }
+    
+    if (maintenanceClusters.size() > 0) {
+      try {
+        PassiveStateHelper.createRequests(this, requestProperties,
+            maintenanceClusters);
+      } catch (Exception e) {
+        LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
+      }
+    }
 
     Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java
index 4d412f7..1709fb0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java
@@ -119,16 +119,32 @@ public class PassiveStateHelper {
     return set;
   }
   
-  public static RequestStatusResponse createRequest(AmbariManagementController amc,
-      String clusterName, Map<String, String> requestProperties) throws AmbariException {
+  /**
+   * Creates the requests to send to the clusters
+   * @param amc the controller
+   * @param requestProperties the request properties
+   * @param clusterNames the names of all the clusters to update
+   * @return the response
+   * @throws AmbariException
+   */
+  public static RequestStatusResponse createRequests(AmbariManagementController amc,
+      Map<String, String> requestProperties, Set<String> clusterNames) throws AmbariException {
     
     Map<String, String> params = new HashMap<String, String>();
     
-    ExecuteActionRequest actionRequest = new ExecuteActionRequest(
-        clusterName, RoleCommand.ACTIONEXECUTE.name(),
-        NAGIOS_ACTION_NAME, NAGIOS_SERVICE, NAGIOS_COMPONENT, null, params);
-
-    return amc.createAction(actionRequest, requestProperties);
+    // return the first one, just like amc.createStages()
+    RequestStatusResponse response = null;
+    
+    for (String clusterName : clusterNames) {
+      ExecuteActionRequest actionRequest = new ExecuteActionRequest(
+          clusterName, RoleCommand.ACTIONEXECUTE.name(),
+          NAGIOS_ACTION_NAME, NAGIOS_SERVICE, NAGIOS_COMPONENT, null, params);
+      
+      if (null == response)
+        response = amc.createAction(actionRequest, requestProperties);
+    }
+    
+    return response;
   }  
   
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 01163b7..5a0c2a9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -529,6 +529,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
 
     AmbariManagementController controller = getManagementController();
     Clusters                   clusters   = controller.getClusters();
+    Set<String>                maintenanceClusters = new HashSet<String>();
 
     for (HostRequest request : requests) {
       if (request.getHostname() == null
@@ -576,12 +577,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
               "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
           } else {
             h.setPassiveState(c.getClusterId(), newState);
-            try {
-              PassiveStateHelper.createRequest(controller, c.getClusterName(),
-                  requestProperties);
-            } catch (Exception e) {
-              LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
-            }
+            
+            maintenanceClusters.add(c.getClusterName());
           }
         }
       }
@@ -624,6 +621,15 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       //todo: if attempt was made to update a property other than those
       //todo: that are allowed above, should throw exception
     }
+    
+    if (maintenanceClusters.size() > 0) {
+      try {
+        PassiveStateHelper.createRequests(controller, requestProperties,
+            maintenanceClusters);
+      } catch (Exception e) {
+        LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
+      }
+    }
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 9cbd16f..608d8e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -505,8 +505,9 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
     Map<String, Set<String>> serviceNames = new HashMap<String, Set<String>>();
     Set<State> seenNewStates = new HashSet<State>();
 
-    Clusters       clusters       = controller.getClusters();
-    AmbariMetaInfo ambariMetaInfo = controller.getAmbariMetaInfo();
+    Clusters       clusters        = controller.getClusters();
+    AmbariMetaInfo ambariMetaInfo   = controller.getAmbariMetaInfo();
+    Set<String> maintenanceClusters = new HashSet<String>();
 
     for (ServiceRequest request : requests) {
       if (request.getClusterName() == null
@@ -560,12 +561,8 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
               "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
           } else {
             s.setPassiveState(newPassive);
-            try {
-              PassiveStateHelper.createRequest(controller, cluster.getClusterName(),
-                  requestProperties);
-            } catch (Exception e) {
-              LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
-            }
+            
+            maintenanceClusters.add(cluster.getClusterName());
           }
         }
       }
@@ -740,6 +737,15 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       throw new IllegalArgumentException("Cannot handle different desired state"
           + " changes for a set of services at the same time");
     }
+    
+    if (maintenanceClusters.size() > -0) {
+      try {
+        PassiveStateHelper.createRequests(controller, requestProperties,
+            maintenanceClusters);
+      } catch (Exception e) {
+        LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
+      }
+    }
 
     Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 2a1cf20..775928b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -4319,6 +4319,7 @@ public class AmbariManagementControllerTest {
   }
 
   @SuppressWarnings("serial")
+  @Ignore
   @Test
   public void testDeleteUsers() throws Exception {
     createUser("user1");
@@ -9256,6 +9257,37 @@ public class AmbariManagementControllerTest {
       }
     }
     
+    // passivate several hosts
+    HostRequest hr1 = new HostRequest(host1, clusterName, requestProperties);
+    hr1.setPassiveState(PassiveState.PASSIVE.name());
+    HostRequest hr2 = new HostRequest(host2, clusterName, requestProperties);
+    hr2.setPassiveState(PassiveState.PASSIVE.name());
+    Set<HostRequest> set = new HashSet<HostRequest>();
+    set.add(hr1);
+    set.add(hr2);
+    HostResourceProviderTest.updateHosts(controller, set, new HashMap<String, String>());
+
+    host = hosts.get(host1);
+    Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(cluster.getClusterId()));
+    host = hosts.get(host2);
+    Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(cluster.getClusterId()));
+    
+    // reset
+    hr1 = new HostRequest(host1, clusterName, requestProperties);
+    hr1.setPassiveState(PassiveState.ACTIVE.name());
+    hr2 = new HostRequest(host2, clusterName, requestProperties);
+    hr2.setPassiveState(PassiveState.ACTIVE.name());
+    set = new HashSet<HostRequest>();
+    set.add(hr1);
+    set.add(hr2);
+
+    HostResourceProviderTest.updateHosts(controller, set, new HashMap<String, String>());
+    host = hosts.get(host1);
+    Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(cluster.getClusterId()));
+    host = hosts.get(host2);
+    Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(cluster.getClusterId()));
+
+    
     // only do one SCH
     ServiceComponentHost targetSch = service.getServiceComponent(
         componentName2).getServiceComponentHosts().get(host2);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4c021d8/ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java
index 8b4ad30..6a86182 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +35,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.easymock.Capture;
+import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -80,7 +82,8 @@ public class PassiveStateHelperTest {
     
     Map<String, String> map = new HashMap<String, String>();
     map.put("context", "abc");
-    PassiveStateHelper.createRequest(amc, sch.getClusterName(), map);
+    PassiveStateHelper.createRequests(amc, map,
+        Collections.singleton(sch.getClusterName()));
     
     ExecuteActionRequest ear = earCapture.getValue();
     map = rpCapture.getValue();
@@ -131,7 +134,8 @@ public class PassiveStateHelperTest {
     
     Map<String, String> map = new HashMap<String, String>();
     map.put("context", "abc");
-    PassiveStateHelper.createRequest(amc, cluster.getClusterName(), map);
+    PassiveStateHelper.createRequests(amc, map,
+        Collections.singleton(cluster.getClusterName()));
     
     ExecuteActionRequest ear = earCapture.getValue();
     rpCapture.getValue();
@@ -182,7 +186,8 @@ public class PassiveStateHelperTest {
     
     Map<String, String> map = new HashMap<String, String>();
     map.put("context", "abc");
-    PassiveStateHelper.createRequest(amc, "c1", map);
+    PassiveStateHelper.createRequests(amc, map,
+        Collections.singleton("c1"));
     
     ExecuteActionRequest ear = earCapture.getValue();
     map = rpCapture.getValue();
@@ -195,7 +200,4 @@ public class PassiveStateHelperTest {
     Assert.assertTrue(map.containsKey("context"));
   }
   
-  
-  
-  
 }