Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 bf3ea3b42 -> ab9b37abe


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


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

Branch: refs/heads/branch-2.4
Commit: ab9b37abe5cce236710bdaa19752e1907ffa7436
Parents: bf3ea3b
Author: Dmytro Sen <[email protected]>
Authored: Mon Jul 18 15:25:36 2016 +0300
Committer: Dmytro Sen <[email protected]>
Committed: Mon Jul 18 15:26:21 2016 +0300

----------------------------------------------------------------------
 .../AmbariCustomCommandExecutionHelper.java     | 14 ++++---
 .../AmbariCustomCommandExecutionHelperTest.java | 39 +++++++++++++++++---
 2 files changed, 42 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ab9b37ab/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index e09630d..2174a64 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ 
b/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();

http://git-wip-us.apache.org/repos/asf/ambari/blob/ab9b37ab/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index a43667e..7a5f377 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ 
b/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);

Reply via email to