Browse Source

AMBARI-16786: hawq_standby_address_host property should be removed from configuration if HAWQSTANDBY component does not exist in BP (bhuvnesh2703)

Bhuvnesh Chaudhary 9 years ago
parent
commit
9a2943ba77

+ 40 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java

@@ -77,6 +77,9 @@ public class BlueprintConfigurationProcessor {
   private final static String HBASE_SITE_HBASE_COPROCESSOR_MASTER_CLASSES = "hbase.coprocessor.master.classes";
   private final static String HBASE_SITE_HBASE_COPROCESSOR_REGION_CLASSES = "hbase.coprocessor.region.classes";
 
+  private final static String HAWQ_SITE_HAWQ_STANDBY_ADDRESS_HOST = "hawq_standby_address_host";
+  private final static String HAWQSTANDBY = "HAWQSTANDBY";
+
   /**
    * Single host topology updaters
    */
@@ -187,7 +190,8 @@ public class BlueprintConfigurationProcessor {
   private static final PropertyFilter[] clusterUpdatePropertyFilters =
     { new DependencyEqualsFilter("hbase.security.authorization", "hbase-site", "true"),
       new DependencyNotEqualsFilter("hive.server2.authentication", "hive-site", "NONE"),
-      new HDFSNameNodeHAFilter() };
+      new HDFSNameNodeHAFilter(),
+      new HawqHAFilter() };
 
   private ClusterTopology clusterTopology;
 
@@ -3052,6 +3056,41 @@ public class BlueprintConfigurationProcessor {
     }
   }
 
+  /**
+   * Filter implementation that scans for HAWQ HA properties that should be
+   * removed/ignored when HAWQ HA is not enabled.
+   */
+  private static class HawqHAFilter implements PropertyFilter {
+
+    /**
+     * Set of HAWQ Property names that are only valid in a HA scenario.
+     */
+    private final Set<String> setOfHawqPropertyNamesNonHA =
+            Collections.unmodifiableSet( new HashSet<String>(Arrays.asList(HAWQ_SITE_HAWQ_STANDBY_ADDRESS_HOST)));
+
+
+    /**
+     *
+     * @param propertyName property name
+     * @param propertyValue property value
+     * @param configType config type that contains this property
+     * @param topology cluster topology instance
+     *
+     * @return true if the property should be included
+     *         false if the property should not be included
+     */
+    @Override
+    public boolean isPropertyIncluded(String propertyName, String propertyValue, String configType, ClusterTopology topology) {
+      int matchingGroupCount = topology.getHostGroupsForComponent(HAWQSTANDBY).size();
+      if (matchingGroupCount == 0) {
+        if (setOfHawqPropertyNamesNonHA.contains(propertyName)) {
+          return false;
+        }
+      }
+
+      return true;
+    }
+  }
 
 
 }

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

@@ -7212,6 +7212,38 @@ public class BlueprintConfigurationProcessorTest {
     assertEquals(createHostAddress(expectedHostNameNamenode, expectedPortNamenode) + "/hawq_default", hawqSite.get("hawq_dfs_url"));
   }
 
+  @Test
+  public void testHawqNonHaConfigClusterUpdate() throws Exception {
+    final String expectedHostNameHawqMaster = "c6401.apache.ambari.org";
+
+    Map<String, Map<String, String>> properties = new HashMap<String, Map<String, String>>();
+    Map<String, String> hawqSite = new HashMap<String, String>();
+    properties.put("hawq-site", hawqSite);
+
+    // setup properties that include host information
+    hawqSite.put("hawq_master_address_host", "localhost");
+    hawqSite.put("hawq_standby_address_host", "localhost");
+
+    Configuration clusterConfig = new Configuration(properties, Collections.<String, Map<String, Map<String, String>>>emptyMap());
+
+    //Host group which has HAWQMASTER
+    Collection<String> hgComponents1 = new HashSet<String>();
+    hgComponents1.add("HAWQMASTER");
+    TestHostGroup group1 = new TestHostGroup("group1", hgComponents1, Collections.singleton(expectedHostNameHawqMaster));
+
+    Collection<TestHostGroup> hostGroups = new HashSet<TestHostGroup>();
+    hostGroups.add(group1);
+
+    ClusterTopology topology = createClusterTopology(bp, clusterConfig, hostGroups);
+    BlueprintConfigurationProcessor updater = new BlueprintConfigurationProcessor(topology);
+
+    updater.doUpdateForClusterCreate();
+
+    assertEquals(expectedHostNameHawqMaster, hawqSite.get("hawq_master_address_host"));
+    assertFalse("hawq_standby_address_host should have been filtered out of this non-HAWQ HA configuration",
+            hawqSite.containsKey("hawq_standby_address_host"));
+  }
+
   @Test
   public void testDoUpdateForBlueprintExport_NonTopologyProperty__AtlasClusterName() throws Exception {
     Map<String, Map<String, String>> properties = new HashMap<String, Map<String, String>>();