Repository: ambari Updated Branches: refs/heads/branch-2.5 ebaa0ea79 -> dc566c6cc
AMBARI-19261 : AMS cannot start after NN HA is enabled due to hbase.rootdir pointing to Standby NN. UpgradeCatalog changes(avijayan) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dc566c6c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dc566c6c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dc566c6c Branch: refs/heads/branch-2.5 Commit: dc566c6cc3790761a3abe5e7fe173c1f9ea31f1b Parents: ebaa0ea Author: Aravindan Vijayan <avija...@hortonworks.com> Authored: Wed Dec 28 09:34:19 2016 -0800 Committer: Aravindan Vijayan <avija...@hortonworks.com> Committed: Wed Dec 28 09:34:19 2016 -0800 ---------------------------------------------------------------------- .../server/upgrade/UpgradeCatalog250.java | 29 ++++++++ .../server/upgrade/UpgradeCatalog250Test.java | 72 ++++++++++++++++++++ 2 files changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/dc566c6c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java index 59988ea..38c7537 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java @@ -57,6 +57,10 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog { protected static final String GROUPS_TABLE = "groups"; protected static final String GROUP_TYPE_COL = "group_type"; private static final String AMS_ENV = "ams-env"; + private static final String AMS_SITE = "ams-site"; + private static final String AMS_MODE = "timeline.metrics.service.operation.mode"; + private static final String AMS_HBASE_SITE = "ams-hbase-site"; + private static final String HBASE_ROOTDIR = "hbase.rootdir"; private static final String HADOOP_ENV = "hadoop-env"; private static final String KAFKA_BROKER = "kafka-broker"; private static final String KAFKA_TIMELINE_METRICS_HOST = "kafka.timeline.metrics.host"; @@ -191,6 +195,31 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog { updateConfigurationPropertiesForCluster(cluster, AMS_ENV, newProperties, true, true); } + + boolean isDistributed = false; + Config amsSite = cluster.getDesiredConfigByType(AMS_SITE); + if (amsSite != null) { + if ("distributed".equals(amsSite.getProperties().get(AMS_MODE))) { + isDistributed = true; + } + } + + if (isDistributed) { + Config amsHbaseSite = cluster.getDesiredConfigByType(AMS_HBASE_SITE); + if (amsHbaseSite != null) { + Map<String, String> amsHbaseSiteProperties = amsHbaseSite.getProperties(); + String rootDir = amsHbaseSiteProperties.get(HBASE_ROOTDIR); + if (StringUtils.isNotEmpty(rootDir) && rootDir.startsWith("hdfs://")) { + int indexOfSlash = rootDir.indexOf("/", 7); + Map<String, String> newProperties = new HashMap<>(); + String newRootdir = rootDir.substring(indexOfSlash); + newProperties.put(HBASE_ROOTDIR, newRootdir); + LOG.info("Changing ams-hbase-site rootdir to " + newRootdir); + updateConfigurationPropertiesForCluster(cluster, AMS_HBASE_SITE, newProperties, true, true); + } + } + } + } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/dc566c6c/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java index bb46fa6..370588a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java @@ -392,6 +392,78 @@ public class UpgradeCatalog250Test { assertTrue(Maps.difference(newPropertiesAmsEnv, updatedProperties).areEqual()); } + @Test + public void testAmsHbaseSiteUpdateConfigs() throws Exception { + + Map<String, String> newProperties = new HashMap<String, String>() { + { + put("hbase.rootdir", "/user/ams/hbase"); + } + }; + + Map<String, String> oldProperties = new HashMap<String, String>() { + { + put("hbase.rootdir", "hdfs://namenodehost.domain.com:8020/user/ams/hbase"); + } + }; + + testAmsHbaseRootDir(oldProperties, newProperties); + + oldProperties = new HashMap<String, String>() { + { + put("hbase.rootdir", "hdfs://nameservice/user/ams/hbase"); + } + }; + + testAmsHbaseRootDir(oldProperties, newProperties); + + } + + private void testAmsHbaseRootDir(Map<String, String> oldProperties, Map<String, String> newProperties) throws AmbariException { + Map<String, String> amsSite = new HashMap<String, String>() { + { + put("timeline.metrics.service.operation.mode", "distributed"); + } + }; + EasyMockSupport easyMockSupport = new EasyMockSupport(); + + Config mockAmsHbaseSite = easyMockSupport.createNiceMock(Config.class); + Config mockAmsSite = easyMockSupport.createNiceMock(Config.class); + + reset(clusters, cluster); + expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ + put("normal", cluster); + }}).once(); + + expect(cluster.getDesiredConfigByType("ams-site")).andReturn(mockAmsSite).atLeastOnce(); + expect(mockAmsSite.getProperties()).andReturn(amsSite).anyTimes(); + expect(cluster.getDesiredConfigByType("ams-hbase-site")).andReturn(mockAmsHbaseSite).atLeastOnce(); + expect(mockAmsHbaseSite.getProperties()).andReturn(oldProperties).anyTimes(); + + replay(clusters, mockAmsHbaseSite, mockAmsSite, cluster); + + AmbariManagementControllerImpl controller = (AmbariManagementControllerImpl)createMockBuilder(AmbariManagementControllerImpl.class) + .addMockedMethod("createConfiguration") + .addMockedMethod("getClusters", new Class[] { }) + .addMockedMethod("createConfig") + .withConstructor(actionManager, clusters, injector) + .createNiceMock(); + + Injector injector2 = easyMockSupport.createNiceMock(Injector.class); + Capture<Map> propertiesCapture = EasyMock.newCapture(); + + expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); + expect(controller.getClusters()).andReturn(clusters).anyTimes(); + expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + anyObject(Map.class))).andReturn(config).once(); + + replay(controller, injector2); + new UpgradeCatalog250(injector2).updateAMSConfigs(); + easyMockSupport.verifyAll(); + + Map<String, String> updatedProperties = propertiesCapture.getValue(); + assertTrue(Maps.difference(newProperties, updatedProperties).areEqual()); + } @Test public void testKafkaUpdateConfigs() throws Exception{