UpgradeCatalog240 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) { String content = amsEnv.getProperties().get("content"); if (content != null && !content.contains("AMS_INSTANCE_NAME")) { String newContent = content + "\n # AMS instance name\n" + "export AMS_INSTANCE_NAME={{hostname}}\n"; updateConfigurationProperties("ams-env", Collections.singletonMap("content", newContent), true, true); } } Config amsHBaseEnv = cluster.getDesiredConfigByType("ams-hbase-env"); if (amsHBaseEnv != null) { String content = amsHBaseEnv.getProperties().get("content"); Map<String, String> newProperties = new HashMap<>(); if (content != null && !content.contains("HBASE_HOME=")) { String newContent = content + "\n # Explicitly Setting HBASE_HOME for AMS HBase so that there is no conflict\n" + "export HBASE_HOME={{ams_hbase_home_dir}}\n"; newProperties.put("content", newContent); } updateConfigurationPropertiesForCluster(cluster, "ams-hbase-env", newProperties, true, true); } Config amsSite = cluster.getDesiredConfigByType(AMS_SITE); if (amsSite != null) { String metadataFilters = amsSite.getProperties().get("timeline.metrics.service.metadata.filters"); if (StringUtils.isEmpty(metadataFilters) || !metadataFilters.contains("ContainerResource")) { updateConfigurationProperties("ams-site", Collections.singletonMap("timeline.metrics.service.metadata.filters", "ContainerResource"), true, false); } Map<String, String> amsSiteProperties = amsSite.getProperties(); Map<String, String> newProperties = new HashMap<>(); if (!amsSiteProperties.containsKey(TIMELINE_METRICS_SINK_COLLECTION_PERIOD) || "60".equals(amsSiteProperties.get(TIMELINE_METRICS_SINK_COLLECTION_PERIOD))) { newProperties.put(TIMELINE_METRICS_SINK_COLLECTION_PERIOD, "10"); LOG.info("Setting value of " + TIMELINE_METRICS_SINK_COLLECTION_PERIOD + " : 10"); } if (amsSiteProperties.containsKey(PRECISION_TABLE_TTL_PROPERTY) && !amsSiteProperties.get(PRECISION_TABLE_TTL_PROPERTY).equals("86400")) { newProperties.put(PRECISION_TABLE_TTL_PROPERTY, String.valueOf(86400)); LOG.info("Setting value of " + PRECISION_TABLE_TTL_PROPERTY + " : " + 86400); } if (amsSiteProperties.containsKey(CLUSTER_SECOND_TABLE_TTL_PROPERTY) && !amsSiteProperties.get(CLUSTER_SECOND_TABLE_TTL_PROPERTY).equals("259200")) { newProperties.put(CLUSTER_SECOND_TABLE_TTL_PROPERTY, String.valueOf(259200)); LOG.info("Setting value of " + CLUSTER_SECOND_TABLE_TTL_PROPERTY + " : " + 259200); } updateConfigurationPropertiesForCluster(cluster, AMS_SITE, newProperties, true, true); } Config amsGrafanaIni = cluster.getDesiredConfigByType("ams-grafana-ini"); if (amsGrafanaIni != null) { Map<String, String> amsGrafanaIniProperties = amsGrafanaIni.getProperties(); String content = amsGrafanaIniProperties.get("content"); Map<String, String> newProperties = new HashMap<>(); newProperties.put("content", updateAmsGrafanaIni(content)); updateConfigurationPropertiesForCluster(cluster, "ams-grafana-ini", 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<>(); if (amsHbaseSiteProperties.containsKey(HBASE_RPC_TIMEOUT_PROPERTY) && "30000".equals(amsHbaseSiteProperties.get(HBASE_RPC_TIMEOUT_PROPERTY))) { newProperties.put(HBASE_RPC_TIMEOUT_PROPERTY, String.valueOf(300000)); } if(amsHbaseSiteProperties.containsKey(AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY) && "true".equals(amsHbaseSiteProperties.get(AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY))) { LOG.info("Disabling " + AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY); newProperties.put(AMS_HBASE_SITE_NORMALIZER_ENABLED_PROPERTY, String.valueOf(false)); } updateConfigurationPropertiesForCluster(cluster, AMS_HBASE_SITE, newProperties, true, true); } } } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }
@Test public void testAmsHbaseEnvUpdateConfigs() throws Exception{ Map<String, String> oldPropertiesAmsHbaseEnv = new HashMap<String, String>() { { put("content", "some_content"); } }; Map<String, String> newPropertiesAmsHbaseEnv = new HashMap<String, String>() { { put("content", "some_content"+ "\n # Explicitly Setting HBASE_HOME for AMS HBase so that there is no conflict\n" + "export HBASE_HOME={{ams_hbase_home_dir}}\n"); } }; EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); Config mockAmsHbaseEnv = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).once(); expect(cluster.getDesiredConfigByType("ams-hbase-env")).andReturn(mockAmsHbaseEnv).atLeastOnce(); expect(mockAmsHbaseEnv.getProperties()).andReturn(oldPropertiesAmsHbaseEnv).anyTimes(); 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, mockAmsHbaseEnv, 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 UpgradeCatalog240(injector2).updateAMSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesAmsHbaseEnv, updatedProperties).areEqual()); }
@Test public void testAmsSiteUpdateConfigs() throws Exception{ Map<String, String> oldPropertiesAmsSite = new HashMap<String, String>() { { put("timeline.metrics.sink.collection.period", "60"); put("timeline.metrics.host.aggregator.ttl", "86400"); put("timeline.metrics.cluster.aggregator.second.ttl", "604800"); } }; Map<String, String> newPropertiesAmsSite = new HashMap<String, String>() { { put("timeline.metrics.sink.collection.period", "10"); put("timeline.metrics.host.aggregator.ttl", "86400"); put("timeline.metrics.cluster.aggregator.second.ttl", "259200"); } }; 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).anyTimes(); 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 UpgradeCatalog240(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("hbase.rpc.timeout", "30000"); put("hbase.normalizer.enabled", String.valueOf(true)); } }; Map<String, String> newPropertiesAmsHbaseSite = new HashMap<String, String>() { { put("hbase.rpc.timeout", "300000"); put("hbase.normalizer.enabled", String.valueOf(false)); } }; 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).anyTimes(); 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 UpgradeCatalog240(injector2).updateAMSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesAmsHbaseSite, updatedProperties).areEqual()); }