Browse Source

AMBARI-9036. Deploying Storm via a Blueprint without Ganglia fails. (rnettleton)

Bob Nettleton 10 năm trước cách đây
mục cha
commit
a49cf5858f

+ 31 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java

@@ -700,6 +700,34 @@ public class BlueprintConfigurationProcessor {
     }
   }
 
+  /**
+   * Extension of SingleHostTopologyUpdater that supports the
+   * notion of an optional service.  An example: the Storm
+   * service has config properties that require the location
+   * of the Ganglia server when Ganglia is deployed, but Storm
+   * should also start properly without Ganglia.
+   *
+   * This updater detects the case when the specified component
+   * is not found, and returns the original property value.
+   *
+   */
+  private static class OptionalSingleHostTopologyUpdater extends SingleHostTopologyUpdater {
+
+    public OptionalSingleHostTopologyUpdater(String component) {
+      super(component);
+    }
+
+    @Override
+    public String updateForClusterCreate(Map<String, ? extends HostGroup> hostGroups, String origValue, Map<String, Map<String, String>> properties, Stack stackDefinition) {
+      try {
+        return super.updateForClusterCreate(hostGroups, origValue, properties, stackDefinition);
+      } catch (IllegalArgumentException illegalArgumentException) {
+        // return the original value, since the optional component is not available in this cluster
+        return origValue;
+      }
+    }
+  }
+
   /**
    * Topology based updater which replaces the original host name of a database property with the host name
    * where the DB is deployed in the new cluster.  If an existing database is specified, the original property
@@ -1161,9 +1189,9 @@ public class BlueprintConfigurationProcessor {
 
     // STORM
     stormSiteMap.put("nimbus.host", new SingleHostTopologyUpdater("NIMBUS"));
-    stormSiteMap.put("worker.childopts", new SingleHostTopologyUpdater("GANGLIA_SERVER"));
-    stormSiteMap.put("supervisor.childopts", new SingleHostTopologyUpdater("GANGLIA_SERVER"));
-    stormSiteMap.put("nimbus.childopts", new SingleHostTopologyUpdater("GANGLIA_SERVER"));
+    stormSiteMap.put("worker.childopts", new OptionalSingleHostTopologyUpdater("GANGLIA_SERVER"));
+    stormSiteMap.put("supervisor.childopts", new OptionalSingleHostTopologyUpdater("GANGLIA_SERVER"));
+    stormSiteMap.put("nimbus.childopts", new OptionalSingleHostTopologyUpdater("GANGLIA_SERVER"));
     multiStormSiteMap.put("storm.zookeeper.servers",
         new YamlMultiValuePropertyDecorator(new MultipleHostTopologyUpdater("ZOOKEEPER_SERVER")));
 

+ 109 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java

@@ -1222,6 +1222,115 @@ public class BlueprintConfigurationProcessorTest {
 
   }
 
+  @Test
+  public void testStormConfigClusterUpdateWithoutGangliaServer() throws Exception {
+    final String expectedHostGroupName = "host_group_1";
+
+    EasyMockSupport mockSupport = new EasyMockSupport();
+
+    HostGroup mockHostGroupOne = mockSupport.createMock(HostGroup.class);
+    Stack mockStack = mockSupport.createMock(Stack.class);
+
+    // simulate the case where Ganglia is not available in the cluster
+    expect(mockHostGroupOne.getComponents()).andReturn(Collections.<String>emptySet()).atLeastOnce();
+    expect(mockStack.getCardinality("GANGLIA_SERVER")).andReturn(new Cardinality("1")).atLeastOnce();
+
+    mockSupport.replayAll();
+
+    Map<String, Map<String, String>> configProperties =
+      new HashMap<String, Map<String, String>>();
+
+    Map<String, String> stormSiteProperties =
+      new HashMap<String, String>();
+
+    configProperties.put("storm-site", stormSiteProperties);
+
+    stormSiteProperties.put("worker.childopts", "localhost");
+    stormSiteProperties.put("supervisor.childopts", "localhost");
+    stormSiteProperties.put("nimbus.childopts", "localhost");
+
+
+    // setup properties that include host information
+
+    BlueprintConfigurationProcessor configProcessor =
+      new BlueprintConfigurationProcessor(configProperties);
+
+    Map<String, HostGroup> mapOfHostGroups =
+      new HashMap<String, HostGroup>();
+    mapOfHostGroups.put(expectedHostGroupName, mockHostGroupOne);
+
+    // call top-level export method
+    configProcessor.doUpdateForClusterCreate(mapOfHostGroups, mockStack);
+
+    // verify that the server name is not replaced, since the GANGLIA_SERVER
+    // component is not available
+    assertEquals("worker startup settings not properly handled by cluster create",
+      "localhost", stormSiteProperties.get("worker.childopts"));
+
+    assertEquals("supervisor startup settings not properly handled by cluster create",
+      "localhost", stormSiteProperties.get("supervisor.childopts"));
+
+    assertEquals("nimbus startup settings not properly handled by cluster create",
+      "localhost", stormSiteProperties.get("nimbus.childopts"));
+
+    mockSupport.verifyAll();
+  }
+
+  @Test
+  public void testStormConfigClusterUpdateWithGangliaServer() throws Exception {
+    final String expectedHostName = "c6401.apache.ambari.org";
+    final String expectedHostGroupName = "host_group_1";
+
+    EasyMockSupport mockSupport = new EasyMockSupport();
+
+    HostGroup mockHostGroupOne = mockSupport.createMock(HostGroup.class);
+    Stack mockStack = mockSupport.createMock(Stack.class);
+
+    expect(mockHostGroupOne.getHostInfo()).andReturn(Arrays.asList(expectedHostName, "serverTwo")).atLeastOnce();
+    // simulate the case where Ganglia is available in the cluster
+    expect(mockHostGroupOne.getComponents()).andReturn(Collections.singleton("GANGLIA_SERVER")).atLeastOnce();
+
+    mockSupport.replayAll();
+
+    Map<String, Map<String, String>> configProperties =
+      new HashMap<String, Map<String, String>>();
+
+    Map<String, String> stormSiteProperties =
+      new HashMap<String, String>();
+
+    configProperties.put("storm-site", stormSiteProperties);
+
+    stormSiteProperties.put("worker.childopts", "localhost");
+    stormSiteProperties.put("supervisor.childopts", "localhost");
+    stormSiteProperties.put("nimbus.childopts", "localhost");
+
+
+    // setup properties that include host information
+
+    BlueprintConfigurationProcessor configProcessor =
+      new BlueprintConfigurationProcessor(configProperties);
+
+    Map<String, HostGroup> mapOfHostGroups =
+      new HashMap<String, HostGroup>();
+    mapOfHostGroups.put(expectedHostGroupName, mockHostGroupOne);
+
+    // call top-level export method
+    configProcessor.doUpdateForClusterCreate(mapOfHostGroups, mockStack);
+
+    // verify that the server name is not replaced, since the GANGLIA_SERVER
+    // component is not available
+    assertEquals("worker startup settings not properly handled by cluster create",
+      expectedHostName, stormSiteProperties.get("worker.childopts"));
+
+    assertEquals("supervisor startup settings not properly handled by cluster create",
+      expectedHostName, stormSiteProperties.get("supervisor.childopts"));
+
+    assertEquals("nimbus startup settings not properly handled by cluster create",
+      expectedHostName, stormSiteProperties.get("nimbus.childopts"));
+
+    mockSupport.verifyAll();
+  }
+
   @Test
   public void testDoUpdateForClusterWithNameNodeHAEnabled() throws Exception {
     final String expectedNameService = "mynameservice";