@Test public void testHdfsSiteUpdateConfigs2() throws Exception{ Map<String, String> oldPropertiesHdfsSite = new HashMap<String, String>() { { put("dfs.client.retry.policy.enabled", "true"); } }; Map<String, String> newPropertiesHdfsSite = new HashMap<String, String>() { { put("dfs.client.retry.policy.enabled", "false"); } }; EasyMockSupport easyMockSupport = new EasyMockSupport(); Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); final Service service = createStrictMock(Service.class); final Map<String, Service> services = Collections.singletonMap("HDFS", service); Config mockHdfsSite = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).anyTimes(); expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(mockHdfsSite).atLeastOnce(); expect(mockHdfsSite.getProperties()).andReturn(oldPropertiesHdfsSite).anyTimes(); expect(cluster.getServices()).andReturn(services).once(); 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, mockHdfsSite, 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).updateHDFSConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newPropertiesHdfsSite, updatedProperties).areEqual()); }
protected void updateHDFSConfigs() 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()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains("HDFS")) { Config hdfsSite = cluster.getDesiredConfigByType("hdfs-site"); if (hdfsSite != null) { String clientRetryPolicyEnabled = hdfsSite.getProperties().get("dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.client.retry.policy.enabled", "false"), true, false); } String nameservices = hdfsSite.getProperties().get("dfs.nameservices"); String int_nameservices = hdfsSite.getProperties().get("dfs.internal.nameservices"); if(int_nameservices == null && nameservices != null) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.internal.nameservices", nameservices), true, false); } } Config hadoopEnv = cluster.getDesiredConfigByType("hadoop-env"); if (hadoopEnv != null) { String keyServerPort = hadoopEnv.getProperties().get("keyserver_port"); if (null != keyServerPort && " ".equals(keyServerPort)) { updateConfigurationProperties("hadoop-env", Collections.singletonMap("keyserver_port", ""), true, false); } } } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateHDFSConfigs() 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()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains("HDFS")) { Config hdfsSite = cluster.getDesiredConfigByType("hdfs-site"); if (hdfsSite != null) { String clientRetryPolicyEnabled = hdfsSite.getProperties().get("dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.client.retry.policy.enabled", "false"), true, false); } String nameservices = hdfsSite.getProperties().get("dfs.nameservices"); String int_nameservices = hdfsSite.getProperties().get("dfs.internal.nameservices"); if(int_nameservices == null && nameservices != null) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.internal.nameservices", nameservices), true, false); } } Config hadoopEnv = cluster.getDesiredConfigByType("hadoop-env"); if (hadoopEnv != null) { String keyServerPort = hadoopEnv.getProperties().get("keyserver_port"); if (null != keyServerPort && " ".equals(keyServerPort)) { updateConfigurationProperties("hadoop-env", Collections.singletonMap("keyserver_port", ""), true, false); } } } } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateHDFSConfigs() 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()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains("HDFS")) { Config hdfsSite = cluster.getDesiredConfigByType("hdfs-site"); if (hdfsSite != null) { String clientRetryPolicyEnabled = hdfsSite.getProperties().get("dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.client.retry.policy.enabled", "false"), true, false); } String nameservices = hdfsSite.getProperties().get("dfs.nameservices"); String int_nameservices = hdfsSite.getProperties().get("dfs.internal.nameservices"); if(int_nameservices == null && nameservices != null) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.internal.nameservices", nameservices), true, false); } } Config hadoopEnv = cluster.getDesiredConfigByType("hadoop-env"); if (hadoopEnv != null) { String keyServerPort = hadoopEnv.getProperties().get("keyserver_port"); if (null != keyServerPort && " ".equals(keyServerPort)) { updateConfigurationProperties("hadoop-env", Collections.singletonMap("keyserver_port", ""), true, false); } } } } } } } @Inject  UpgradeCatalog240(Injector injector); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateHDFSConfigs() 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()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains("HDFS")) { Config hdfsSite = cluster.getDesiredConfigByType("hdfs-site"); if (hdfsSite != null) { String clientRetryPolicyEnabled = hdfsSite.getProperties().get("dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.client.retry.policy.enabled", "false"), true, false); } String nameservices = hdfsSite.getProperties().get("dfs.nameservices"); String int_nameservices = hdfsSite.getProperties().get("dfs.internal.nameservices"); if(int_nameservices == null && nameservices != null) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.internal.nameservices", nameservices), true, false); } } Config hadoopEnv = cluster.getDesiredConfigByType("hadoop-env"); if (hadoopEnv != null) { String keyServerPort = hadoopEnv.getProperties().get("keyserver_port"); if (null != keyServerPort && " ".equals(keyServerPort)) { updateConfigurationProperties("hadoop-env", Collections.singletonMap("keyserver_port", ""), true, false); } } } } } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateHDFSConfigs() 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()) { Set<String> installedServices = cluster.getServices().keySet(); if (installedServices.contains("HDFS")) { Config hdfsSite = cluster.getDesiredConfigByType("hdfs-site"); if (hdfsSite != null) { String clientRetryPolicyEnabled = hdfsSite.getProperties().get("dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.client.retry.policy.enabled", "false"), true, false); } String nameservices = hdfsSite.getProperties().get("dfs.nameservices"); String int_nameservices = hdfsSite.getProperties().get("dfs.internal.nameservices"); if(int_nameservices == null && nameservices != null) { updateConfigurationProperties("hdfs-site", Collections.singletonMap("dfs.internal.nameservices", nameservices), true, false); } } Config hadoopEnv = cluster.getDesiredConfigByType("hadoop-env"); if (hadoopEnv != null) { String keyServerPort = hadoopEnv.getProperties().get("keyserver_port"); if (null != keyServerPort && " ".equals(keyServerPort)) { updateConfigurationProperties("hadoop-env", Collections.singletonMap("keyserver_port", ""), true, false); } } } } } } } @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; }