You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2014/09/13 01:53:34 UTC

[06/30] git commit: AMBARI-7242. Make Nagios client dependencies conditional on client service being deployed.

AMBARI-7242.  Make Nagios client dependencies conditional on client service being deployed.


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

Branch: refs/heads/branch-alerts-dev
Commit: 9d201f548b3cc77745e6a7616cc2e7be8920dbe1
Parents: d961ca0
Author: Robert Nettleton <rn...@hortonworks.com>
Authored: Thu Sep 11 16:10:27 2014 -0400
Committer: John Speidel <js...@hortonworks.com>
Committed: Thu Sep 11 16:12:09 2014 -0400

----------------------------------------------------------------------
 .../internal/BaseBlueprintProcessor.java        |  13 +-
 .../internal/BaseBlueprintProcessorTest.java    | 413 +++++++++++++++++++
 2 files changed, 425 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9d201f54/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
index 9c10ac1..5a99af8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
@@ -595,6 +595,11 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
       return version;
     }
 
+
+    Map<DependencyInfo, String> getDependencyConditionalServiceMap() {
+      return dependencyConditionalServiceMap;
+    }
+
     /**
      * Get services contained in the stack.
      *
@@ -842,13 +847,19 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
      * Register conditional dependencies.
      */
     //todo: This information should be specified in the stack definition.
-    private void registerConditionalDependencies() {
+    void registerConditionalDependencies() {
       Collection<DependencyInfo> nagiosDependencies = getDependenciesForComponent("NAGIOS_SERVER");
       for (DependencyInfo dependency : nagiosDependencies) {
         if (dependency.getComponentName().equals("HCAT")) {
           dependencyConditionalServiceMap.put(dependency, "HCATALOG");
         } else if (dependency.getComponentName().equals("OOZIE_CLIENT")) {
           dependencyConditionalServiceMap.put(dependency, "OOZIE");
+        } else if (dependency.getComponentName().equals("YARN_CLIENT")) {
+          dependencyConditionalServiceMap.put(dependency, "YARN");
+        } else if (dependency.getComponentName().equals("TEZ_CLIENT")) {
+          dependencyConditionalServiceMap.put(dependency, "TEZ");
+        } else if (dependency.getComponentName().equals("MAPREDUCE2_CLIENT")) {
+          dependencyConditionalServiceMap.put(dependency, "MAPREDUCE2");
         }
       }
       dbDependencyInfo.put("MYSQL_SERVER", "global/hive_database");

http://git-wip-us.apache.org/repos/asf/ambari/blob/9d201f54/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessorTest.java
new file mode 100644
index 0000000..ffe2ea0
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessorTest.java
@@ -0,0 +1,413 @@
+package org.apache.ambari.server.controller.internal;
+
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.StackServiceResponse;
+import org.apache.ambari.server.state.DependencyInfo;
+import org.easymock.EasyMockSupport;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+/**
+ * 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.
+ */
+
+public class BaseBlueprintProcessorTest {
+
+  @Before
+  public void setUp() throws Exception {
+    BaseBlueprintProcessor.stackInfo = null;
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependencies() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo hCatDependency = new TestDependencyInfo("WEBHCAT/HCAT");
+    final DependencyInfo yarnClientDependency = new TestDependencyInfo("YARN/YARN_CLIENT");
+    final DependencyInfo tezClientDependency = new TestDependencyInfo("TEZ/TEZ_CLIENT");
+    final DependencyInfo mapReduceTwoClientDependency = new TestDependencyInfo("YARN/MAPREDUCE2_CLIENT");
+    final DependencyInfo oozieClientDependency = new TestDependencyInfo("OOZIE/OOZIE_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(hCatDependency);
+            setOfDependencies.add(yarnClientDependency);
+            setOfDependencies.add(tezClientDependency);
+            setOfDependencies.add(mapReduceTwoClientDependency);
+            setOfDependencies.add(oozieClientDependency);
+
+            return setOfDependencies;
+          }
+
+            return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+                 0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+                 5, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for HCAT",
+                 "HCATALOG", testStack.getDependencyConditionalServiceMap().get(hCatDependency));
+    assertEquals("Incorrect service dependency for YARN_CLIENT",
+                 "YARN", testStack.getDependencyConditionalServiceMap().get(yarnClientDependency));
+    assertEquals("Incorrect service dependency for TEZ_CLIENT",
+                 "TEZ", testStack.getDependencyConditionalServiceMap().get(tezClientDependency));
+    assertEquals("Incorrect service dependency for MAPREDUCE2_CLIENT",
+                 "MAPREDUCE2", testStack.getDependencyConditionalServiceMap().get(mapReduceTwoClientDependency));
+    assertEquals("Incorrect service dependency for OOZIE_CLIENT",
+                 "OOZIE", testStack.getDependencyConditionalServiceMap().get(oozieClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependenciesNoHCAT() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo yarnClientDependency = new TestDependencyInfo("YARN/YARN_CLIENT");
+    final DependencyInfo tezClientDependency = new TestDependencyInfo("TEZ/TEZ_CLIENT");
+    final DependencyInfo mapReduceTwoClientDependency = new TestDependencyInfo("YARN/MAPREDUCE2_CLIENT");
+    final DependencyInfo oozieClientDependency = new TestDependencyInfo("OOZIE/OOZIE_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(yarnClientDependency);
+            setOfDependencies.add(tezClientDependency);
+            setOfDependencies.add(mapReduceTwoClientDependency);
+            setOfDependencies.add(oozieClientDependency);
+
+            return setOfDependencies;
+          }
+
+          return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+      0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+      4, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for YARN_CLIENT",
+      "YARN", testStack.getDependencyConditionalServiceMap().get(yarnClientDependency));
+    assertEquals("Incorrect service dependency for TEZ_CLIENT",
+      "TEZ", testStack.getDependencyConditionalServiceMap().get(tezClientDependency));
+    assertEquals("Incorrect service dependency for MAPREDUCE2_CLIENT",
+      "MAPREDUCE2", testStack.getDependencyConditionalServiceMap().get(mapReduceTwoClientDependency));
+    assertEquals("Incorrect service dependency for OOZIE_CLIENT",
+      "OOZIE", testStack.getDependencyConditionalServiceMap().get(oozieClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependenciesNoYarnClient() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo hCatDependency = new TestDependencyInfo("WEBHCAT/HCAT");
+    final DependencyInfo tezClientDependency = new TestDependencyInfo("TEZ/TEZ_CLIENT");
+    final DependencyInfo mapReduceTwoClientDependency = new TestDependencyInfo("YARN/MAPREDUCE2_CLIENT");
+    final DependencyInfo oozieClientDependency = new TestDependencyInfo("OOZIE/OOZIE_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(hCatDependency);
+            setOfDependencies.add(tezClientDependency);
+            setOfDependencies.add(mapReduceTwoClientDependency);
+            setOfDependencies.add(oozieClientDependency);
+
+            return setOfDependencies;
+          }
+
+          return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+      0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+      4, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for HCAT",
+      "HCATALOG", testStack.getDependencyConditionalServiceMap().get(hCatDependency));
+    assertEquals("Incorrect service dependency for TEZ_CLIENT",
+      "TEZ", testStack.getDependencyConditionalServiceMap().get(tezClientDependency));
+    assertEquals("Incorrect service dependency for MAPREDUCE2_CLIENT",
+      "MAPREDUCE2", testStack.getDependencyConditionalServiceMap().get(mapReduceTwoClientDependency));
+    assertEquals("Incorrect service dependency for OOZIE_CLIENT",
+      "OOZIE", testStack.getDependencyConditionalServiceMap().get(oozieClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependenciesNoTezClient() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo hCatDependency = new TestDependencyInfo("WEBHCAT/HCAT");
+    final DependencyInfo yarnClientDependency = new TestDependencyInfo("YARN/YARN_CLIENT");
+    final DependencyInfo mapReduceTwoClientDependency = new TestDependencyInfo("YARN/MAPREDUCE2_CLIENT");
+    final DependencyInfo oozieClientDependency = new TestDependencyInfo("OOZIE/OOZIE_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(hCatDependency);
+            setOfDependencies.add(yarnClientDependency);
+            setOfDependencies.add(mapReduceTwoClientDependency);
+            setOfDependencies.add(oozieClientDependency);
+
+            return setOfDependencies;
+          }
+
+          return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+      0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+      4, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for HCAT",
+      "HCATALOG", testStack.getDependencyConditionalServiceMap().get(hCatDependency));
+    assertEquals("Incorrect service dependency for YARN_CLIENT",
+      "YARN", testStack.getDependencyConditionalServiceMap().get(yarnClientDependency));
+    assertEquals("Incorrect service dependency for MAPREDUCE2_CLIENT",
+      "MAPREDUCE2", testStack.getDependencyConditionalServiceMap().get(mapReduceTwoClientDependency));
+    assertEquals("Incorrect service dependency for OOZIE_CLIENT",
+      "OOZIE", testStack.getDependencyConditionalServiceMap().get(oozieClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependenciesNoMapReduceClient() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo hCatDependency = new TestDependencyInfo("WEBHCAT/HCAT");
+    final DependencyInfo yarnClientDependency = new TestDependencyInfo("YARN/YARN_CLIENT");
+    final DependencyInfo tezClientDependency = new TestDependencyInfo("TEZ/TEZ_CLIENT");
+    final DependencyInfo oozieClientDependency = new TestDependencyInfo("OOZIE/OOZIE_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(hCatDependency);
+            setOfDependencies.add(yarnClientDependency);
+            setOfDependencies.add(tezClientDependency);
+            setOfDependencies.add(oozieClientDependency);
+
+            return setOfDependencies;
+          }
+
+          return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+      0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+      4, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for HCAT",
+      "HCATALOG", testStack.getDependencyConditionalServiceMap().get(hCatDependency));
+    assertEquals("Incorrect service dependency for YARN_CLIENT",
+      "YARN", testStack.getDependencyConditionalServiceMap().get(yarnClientDependency));
+    assertEquals("Incorrect service dependency for TEZ_CLIENT",
+      "TEZ", testStack.getDependencyConditionalServiceMap().get(tezClientDependency));
+    assertEquals("Incorrect service dependency for OOZIE_CLIENT",
+      "OOZIE", testStack.getDependencyConditionalServiceMap().get(oozieClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  @Test
+  public void testStackRegisterConditionalDependenciesNoOozieClient() throws Exception {
+    EasyMockSupport mockSupport = new EasyMockSupport();
+    AmbariManagementController mockMgmtController =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    // setup mock expectations
+    expect(mockMgmtController.getStackServices(isA(Set.class))).andReturn(Collections.<StackServiceResponse>emptySet());
+
+    // test dependencies
+    final DependencyInfo hCatDependency = new TestDependencyInfo("WEBHCAT/HCAT");
+    final DependencyInfo yarnClientDependency = new TestDependencyInfo("YARN/YARN_CLIENT");
+    final DependencyInfo tezClientDependency = new TestDependencyInfo("TEZ/TEZ_CLIENT");
+    final DependencyInfo mapReduceTwoClientDependency = new TestDependencyInfo("YARN/MAPREDUCE2_CLIENT");
+
+    mockSupport.replayAll();
+
+    // create stack for testing
+    BaseBlueprintProcessor.Stack testStack =
+      new BaseBlueprintProcessor.Stack("HDP", "2.1", mockMgmtController) {
+        @Override
+        public Collection<DependencyInfo> getDependenciesForComponent(String component) {
+          // simulate the dependencies in a given stack by overriding this method
+          if (component.equals("NAGIOS_SERVER")) {
+            Set<DependencyInfo> setOfDependencies = new HashSet<DependencyInfo>();
+
+            setOfDependencies.add(hCatDependency);
+            setOfDependencies.add(yarnClientDependency);
+            setOfDependencies.add(tezClientDependency);
+            setOfDependencies.add(mapReduceTwoClientDependency);
+
+            return setOfDependencies;
+          }
+
+          return Collections.emptySet();
+        }
+      };
+
+    assertEquals("Initial conditional dependency map should be empty",
+      0, testStack.getDependencyConditionalServiceMap().size());
+
+    testStack.registerConditionalDependencies();
+
+    assertEquals("Set of conditional service mappings is an incorrect size",
+      4, testStack.getDependencyConditionalServiceMap().size());
+
+    assertEquals("Incorrect service dependency for HCAT",
+      "HCATALOG", testStack.getDependencyConditionalServiceMap().get(hCatDependency));
+    assertEquals("Incorrect service dependency for YARN_CLIENT",
+      "YARN", testStack.getDependencyConditionalServiceMap().get(yarnClientDependency));
+    assertEquals("Incorrect service dependency for TEZ_CLIENT",
+      "TEZ", testStack.getDependencyConditionalServiceMap().get(tezClientDependency));
+    assertEquals("Incorrect service dependency for MAPREDUCE2_CLIENT",
+      "MAPREDUCE2", testStack.getDependencyConditionalServiceMap().get(mapReduceTwoClientDependency));
+
+    mockSupport.verifyAll();
+  }
+
+
+  /**
+   * Convenience class for easier setup/initialization of dependencies
+   * for unit testing.
+   */
+  private static class TestDependencyInfo extends DependencyInfo {
+    TestDependencyInfo(String dependencyName) {
+      setName(dependencyName);
+    }
+  }
+}
\ No newline at end of file