Explorar o código

AMBARI-17760 Ambari should perform service check only healthy hosts (dsen)

Dmytro Sen %!s(int64=9) %!d(string=hai) anos
pai
achega
ab9b37abe5

+ 9 - 5
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java

@@ -520,17 +520,21 @@ public class AmbariCustomCommandExecutionHelper {
       Map<String, ServiceComponent> serviceComponents =
               cluster.getService(serviceName).getServiceComponents();
 
+      // Filter components without any HOST
+      Iterator<String> serviceComponentNameIterator = serviceComponents.keySet().iterator();
+      while (serviceComponentNameIterator.hasNext()){
+        String componentToCheck = serviceComponentNameIterator.next();
+         if (serviceComponents.get(componentToCheck).getServiceComponentHosts().isEmpty()){
+           serviceComponentNameIterator.remove();
+         }
+      }
+
       if (serviceComponents.isEmpty()) {
         throw new AmbariException("Components not found, service = "
             + serviceName + ", cluster = " + clusterName);
       }
 
       ServiceComponent serviceComponent = serviceComponents.values().iterator().next();
-      if (serviceComponent.getServiceComponentHosts().isEmpty()) {
-        throw new AmbariException("Hosts not found, component="
-            + serviceComponent.getName() + ", service = "
-            + serviceName + ", cluster = " + clusterName);
-      }
 
       serviceHostComponents = serviceComponent.getServiceComponentHosts();
       candidateHosts = serviceHostComponents.keySet();

+ 33 - 6
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java

@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -376,6 +377,23 @@ public class AmbariCustomCommandExecutionHelperTest {
     Assert.fail("Expected an exception since there are no hosts which can run the ZK service check");
   }
 
+  @Test(expected = AmbariException.class)
+  public void testServiceCheckComponentWithEmptyHosts() throws Exception {
+
+    AmbariCustomCommandExecutionHelper ambariCustomCommandExecutionHelper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
+
+    List<RequestResourceFilter> requestResourceFilter = new ArrayList<RequestResourceFilter>() {{
+      add(new RequestResourceFilter("FLUME", null, null));
+    }};
+    ActionExecutionContext actionExecutionContext = new ActionExecutionContext("c1", "SERVICE_CHECK", requestResourceFilter);
+    Stage stage = EasyMock.niceMock(Stage.class);
+
+    ambariCustomCommandExecutionHelper.addExecutionCommandsToStage(actionExecutionContext, stage, new HashMap<String, String>());
+
+    Assert.fail("Expected an exception since there are no hosts which can run the Flume service check");
+  }
+
+
   @Test
   public void testIsTopologyRefreshRequired() throws Exception {
     AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
@@ -418,14 +436,19 @@ public class AmbariCustomCommandExecutionHelperTest {
   }
 
   private void createClusterFixture(String clusterName, String stackVersion, String hostPrefix) throws AmbariException, AuthorizationException {
+    String hostC6401 = hostPrefix + "-c6401";
+    String hostC6402 = hostPrefix + "-c6402";
+
     createCluster(clusterName, stackVersion);
-    addHost(hostPrefix + "-c6401", clusterName);
-    addHost(hostPrefix + "-c6402", clusterName);
+
+    addHost(hostC6401, clusterName);
+    addHost(hostC6402, clusterName);
 
     clusters.getCluster(clusterName);
     createService(clusterName, "YARN", null);
     createService(clusterName, "GANGLIA", null);
     createService(clusterName, "ZOOKEEPER", null);
+    createService(clusterName, "FLUME", null);
 
     createServiceComponent(clusterName, "YARN", "RESOURCEMANAGER", State.INIT);
     createServiceComponent(clusterName, "YARN", "NODEMANAGER", State.INIT);
@@ -433,10 +456,14 @@ public class AmbariCustomCommandExecutionHelperTest {
     createServiceComponent(clusterName, "GANGLIA", "GANGLIA_MONITOR", State.INIT);
     createServiceComponent(clusterName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", State.INIT);
 
-    createServiceComponentHost(clusterName, "YARN", "RESOURCEMANAGER", hostPrefix + "-c6401", null);
-    createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostPrefix + "-c6401", null);
-    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_SERVER", hostPrefix + "-c6401", State.INIT);
-    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_MONITOR", hostPrefix + "-c6401", State.INIT);
+    // this component should be not installed on any host
+    createServiceComponent(clusterName, "FLUME", "FLUME_HANDLER", State.INIT);
+
+
+    createServiceComponentHost(clusterName, "YARN", "RESOURCEMANAGER", hostC6401, null);
+    createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostC6401, null);
+    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_SERVER", hostC6401, State.INIT);
+    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_MONITOR", hostC6401, State.INIT);
 
     createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostPrefix + "-c6402", null);
     createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_MONITOR", hostPrefix + "-c6402", State.INIT);