UpgradeCatalog221 extends AbstractUpgradeCatalog { protected void updateAMSConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config amsEnv = cluster.getDesiredConfigByType(AMS_ENV); if (amsEnv != null) { Map<String, String> amsEnvProperties = amsEnv.getProperties(); String content = amsEnvProperties.get("content"); Map<String, String> newProperties = new HashMap<>(); newProperties.put("content", updateAmsEnvContent(content)); updateConfigurationPropertiesForCluster(cluster, AMS_ENV, newProperties, true, true); } String znodeParent = null; Config amsHbaseSecuritySite = cluster.getDesiredConfigByType(AMS_HBASE_SECURITY_SITE); if (amsHbaseSecuritySite != null) { Map<String, String> amsHbaseSecuritySiteProperties = amsHbaseSecuritySite.getProperties(); znodeParent = amsHbaseSecuritySiteProperties.get(ZK_ZNODE_PARENT); LOG.info("Removing config zookeeper.znode.parent from ams-hbase-security-site"); removeConfigurationPropertiesFromCluster(cluster, AMS_HBASE_SECURITY_SITE, Collections.singleton(ZK_ZNODE_PARENT)); } Config amsHbaseSite = cluster.getDesiredConfigByType(AMS_HBASE_SITE); if (amsHbaseSite != null) { Map<String, String> amsHbaseSiteProperties = amsHbaseSite.getProperties(); Map<String, String> newProperties = new HashMap<>(); if (!amsHbaseSiteProperties.containsKey(ZK_ZNODE_PARENT)) { if (StringUtils.isEmpty(znodeParent) || "/hbase".equals(znodeParent)) { boolean isSecurityEnabled = false; Config clusterEnv = cluster.getDesiredConfigByType(CLUSTER_ENV); if (clusterEnv != null) { Map<String,String> clusterEnvProperties = clusterEnv.getProperties(); if (clusterEnvProperties.containsKey(SECURITY_ENABLED)) { isSecurityEnabled = Boolean.valueOf(clusterEnvProperties.get(SECURITY_ENABLED)); } } znodeParent = "/ams-hbase-" + (isSecurityEnabled ? "secure" : "unsecure"); } LOG.info("Adding config zookeeper.znode.parent=" + znodeParent + " to ams-hbase-site"); newProperties.put(ZK_ZNODE_PARENT, znodeParent); } boolean isDistributed = false; Config amsSite = cluster.getDesiredConfigByType(AMS_SITE); if (amsSite != null) { if ("distributed".equals(amsSite.getProperties().get(AMS_MODE))) { isDistributed = true; } } if (amsHbaseSiteProperties.containsKey(ZK_CLIENT_PORT) && (isDistributed || amsHbaseSiteProperties.get(ZK_CLIENT_PORT).equals("61181"))) { String newValue = "{{zookeeper_clientPort}}"; LOG.info("Replacing value of " + ZK_CLIENT_PORT + " from " + amsHbaseSiteProperties.get(ZK_CLIENT_PORT) + " to " + newValue + " in ams-hbase-site"); newProperties.put(ZK_CLIENT_PORT, newValue); } if (!amsHbaseSiteProperties.containsKey(ZK_TICK_TIME)) { LOG.info("Adding config " + ZK_TICK_TIME + " to ams-hbase-site"); newProperties.put(ZK_TICK_TIME, "6000"); } updateConfigurationPropertiesForCluster(cluster, AMS_HBASE_SITE, newProperties, true, true); } Config amsHbaseEnv = cluster.getDesiredConfigByType(AMS_HBASE_ENV); if (amsHbaseEnv != null) { Map<String, String> amsHbaseEnvProperties = amsHbaseEnv.getProperties(); String content = amsHbaseEnvProperties.get("content"); Map<String, String> newProperties = new HashMap<>(); newProperties.put("content", updateAmsHbaseEnvContent(content)); updateConfigurationPropertiesForCluster(cluster, AMS_HBASE_ENV, newProperties, true, true); } } } } } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testUpdateAmsHbaseSecuritySiteConfigs() throws Exception{ Map<String, String> oldPropertiesAmsHbaseSecuritySite = new HashMap<String, String>() { { put("zookeeper.znode.parent", "/ams-hbase-secure"); } }; Map<String, String> newPropertiesAmsHbaseSecuritySite = new HashMap<>(); EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockAmsHbaseSecuritySite = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).once(); expect(cluster.getDesiredConfigByType("ams-hbase-security-site")).andReturn(mockAmsHbaseSecuritySite).atLeastOnce(); expect(mockAmsHbaseSecuritySite.getProperties()).andReturn(oldPropertiesAmsHbaseSecuritySite).times(2); Injector injector = easyMockSupport.createNiceMock(Injector.class); expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes(); expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes(); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes(); replay(injector, clusters, mockAmsHbaseSecuritySite, cluster); AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class) .addMockedMethod("createConfiguration") .addMockedMethod("getClusters", new Class[] { }) .addMockedMethod("createConfig") .withConstructor(createNiceMock(ActionManager.class), clusters, injector) .createNiceMock(); Injector injector2 = easyMockSupport.createNiceMock(Injector.class); Capture<Map<String, String>> 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(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once(); replay(controller, injector2); new UpgradeCatalog221(injector2).updateAMSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesAmsHbaseSecuritySite, updatedProperties).areEqual()); }