UpgradeCatalog220 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 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); } 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); } Config amsSite = cluster.getDesiredConfigByType(AMS_SITE); if (amsSite != null) { Map<String, String> currentAmsSiteProperties = amsSite.getProperties(); Map<String, String> newProperties = new HashMap<>(); if(currentAmsSiteProperties.containsKey("timeline.metrics.service.default.result.limit") && currentAmsSiteProperties.get("timeline.metrics.service.default.result.limit").equals(String.valueOf(5760))) { LOG.info("Updating timeline.metrics.service.default.result.limit to 15840"); newProperties.put("timeline.metrics.service.default.result.limit", String.valueOf(15840)); } newProperties.put("timeline.metrics.cluster.aggregator.second.interval", String.valueOf(120)); newProperties.put("timeline.metrics.cluster.aggregator.minute.interval", String.valueOf(300)); newProperties.put("timeline.metrics.host.aggregator.minute.interval", String.valueOf(300)); newProperties.put("timeline.metrics.cluster.aggregator.second.ttl", String.valueOf(2592000)); newProperties.put("timeline.metrics.cluster.aggregator.minute.ttl", String.valueOf(7776000)); newProperties.put("timeline.metrics.cluster.aggregator.second.checkpointCutOffMultiplier", String.valueOf(2)); newProperties.put("timeline.metrics.cluster.aggregator.second.disabled", String.valueOf(false)); newProperties.put(TIMELINE_METRICS_HBASE_FIFO_COMPACTION_ENABLED, String.valueOf(true)); updateConfigurationPropertiesForCluster(cluster, AMS_SITE, newProperties, true, true); } Config amsHbaseSite = cluster.getDesiredConfigByType(AMS_HBASE_SITE); if (amsHbaseSite != null) { Map<String, String> amsHbaseSiteProperties = amsHbaseSite.getProperties(); Map<String, String> newProperties = new HashMap<>(); String zkTimeout = amsHbaseSiteProperties.get(AMS_HBASE_SITE_ZK_TIMEOUT_PROPERTY); if ("20000".equals(zkTimeout)) { newProperties.put(AMS_HBASE_SITE_ZK_TIMEOUT_PROPERTY, "120000"); } if(!amsHbaseSiteProperties.containsKey(AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY)) { LOG.info("Enabling " + AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY); newProperties.put(AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY, String.valueOf(true)); } if(!amsHbaseSiteProperties.containsKey(AMS_HBASE_SITE_NORMALIZER_PERIOD_PROPERTY)) { LOG.info("Updating " + AMS_HBASE_SITE_NORMALIZER_PERIOD_PROPERTY); newProperties.put(AMS_HBASE_SITE_NORMALIZER_PERIOD_PROPERTY, String.valueOf(600000)); } if(!amsHbaseSiteProperties.containsKey(AMS_HBASE_SITE_NORMALIZER_CLASS_PROPERTY)) { LOG.info("Updating " + AMS_HBASE_SITE_NORMALIZER_CLASS_PROPERTY); newProperties.put(AMS_HBASE_SITE_NORMALIZER_CLASS_PROPERTY, "org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer"); } updateConfigurationPropertiesForCluster(cluster, AMS_HBASE_SITE, newProperties, true, true); } } } } } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); static final String UPGRADE_PACKAGE_COL; static final String UPGRADE_TYPE_COL; static final String REPO_VERSION_TABLE; }
@Test public void testAmsSiteUpdateConfigs() throws Exception{ Map<String, String> oldPropertiesAmsSite = new HashMap<String, String>() { { put("timeline.metrics.service.default.result.limit", String.valueOf(5760)); put("timeline.metrics.cluster.aggregator.minute.interval", String.valueOf(1000)); put("timeline.metrics.host.aggregator.minute.interval", String.valueOf(1000)); put("timeline.metrics.cluster.aggregator.minute.ttl", String.valueOf(1000)); } }; Map<String, String> newPropertiesAmsSite = new HashMap<String, String>() { { put("timeline.metrics.service.default.result.limit", String.valueOf(15840)); put("timeline.metrics.cluster.aggregator.second.interval", String.valueOf(120)); put("timeline.metrics.cluster.aggregator.minute.interval", String.valueOf(300)); put("timeline.metrics.host.aggregator.minute.interval", String.valueOf(300)); put("timeline.metrics.cluster.aggregator.second.ttl", String.valueOf(2592000)); put("timeline.metrics.cluster.aggregator.minute.ttl", String.valueOf(7776000)); put("timeline.metrics.cluster.aggregator.second.checkpointCutOffMultiplier", String.valueOf(2)); put("timeline.metrics.cluster.aggregator.second.disabled", String.valueOf(false)); put("timeline.metrics.hbase.fifo.compaction.enabled", String.valueOf(true)); } }; EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockAmsSite = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).once(); expect(cluster.getDesiredConfigByType("ams-site")).andReturn(mockAmsSite).atLeastOnce(); expect(mockAmsSite.getProperties()).andReturn(oldPropertiesAmsSite).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, mockAmsSite, 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 UpgradeCatalog220(injector2).updateAMSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesAmsSite, updatedProperties).areEqual()); }
@Test public void testAmsHbaseSiteUpdateConfigs() throws Exception{ Map<String, String> oldPropertiesAmsHbaseSite = new HashMap<String, String>() { { put("zookeeper.session.timeout.localHBaseCluster", String.valueOf(20000)); } }; Map<String, String> newPropertiesAmsSite = new HashMap<String, String>() { { put("zookeeper.session.timeout.localHBaseCluster", String.valueOf(120000)); put("hbase.normalizer.enabled", String.valueOf(true)); put("hbase.normalizer.period", String.valueOf(600000)); put("hbase.master.normalizer.class", "org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer"); } }; EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockAmsHbaseSite = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).once(); expect(cluster.getDesiredConfigByType("ams-hbase-site")).andReturn(mockAmsHbaseSite).atLeastOnce(); expect(mockAmsHbaseSite.getProperties()).andReturn(oldPropertiesAmsHbaseSite).atLeastOnce(); 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, mockAmsHbaseSite, 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 UpgradeCatalog220(injector2).updateAMSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesAmsSite, updatedProperties).areEqual()); }