@Test public void testUpdateHDFSConfiguration() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final Config mockHdfsSite = easyMockSupport.createNiceMock(Config.class); final Config mockCoreSite = easyMockSupport.createStrictMock(Config.class); final Map<String, String> propertiesExpectedHdfs = new HashMap<String, String>(); final Map<String, String> propertiesExpectedCoreSite = new HashMap<String, String>(); propertiesExpectedHdfs.put("dfs.nameservices", "nncl1,nncl2"); propertiesExpectedHdfs.put("dfs.ha.namenodes.nncl2", "nn1,nn2"); propertiesExpectedCoreSite.put("fs.defaultFS", "hdfs: final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(ConfigHelper.class).toInstance(mockConfigHelper); bind(Clusters.class).toInstance(mockClusters); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).once(); expect(mockClusterExpected.getDesiredConfigByType("hadoop-env")).andReturn(null).once(); expect(mockClusterExpected.getDesiredConfigByType("hdfs-site")).andReturn(mockHdfsSite).atLeastOnce(); expect(mockClusterExpected.getHosts("HDFS", "NAMENODE")).andReturn( new HashSet<String>() {{ add("host1"); }}).atLeastOnce(); expect(mockHdfsSite.getProperties()).andReturn(propertiesExpectedHdfs).anyTimes(); expect(mockClusterExpected.getDesiredConfigByType("core-site")).andReturn(mockCoreSite).anyTimes(); expect(mockCoreSite.getProperties()).andReturn(propertiesExpectedCoreSite).anyTimes(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog210.class).updateHdfsConfigs(); easyMockSupport.verifyAll(); }
protected void updateHdfsConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance( AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); Map<String, String> prop = new HashMap<String, String>(); String content = null; if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { content = null; if (cluster.getDesiredConfigByType("hadoop-env") != null) { content = cluster.getDesiredConfigByType( "hadoop-env").getProperties().get("content"); } if (content != null) { content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\""; prop.put("content", content); updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false); } if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null && !cluster.getHosts("HDFS","NAMENODE").isEmpty()) { URI nameNodeRpc = null; String hostName = cluster.getHosts("HDFS","NAMENODE").iterator().next(); if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) { try { if (isNNHAEnabled(cluster)) { Set<String> removePropertiesSet = new HashSet<>(); removePropertiesSet.add("dfs.namenode.rpc-address"); removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG, removePropertiesSet); } else { nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS")); Map<String, String> hdfsProp = new HashMap<String, String>(); hdfsProp.put("dfs.namenode.rpc-address", hostName + ":" + nameNodeRpc.getPort()); updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp, false, false); } } catch (URISyntaxException e) { e.printStackTrace(); } } } } } } }
UpgradeCatalog210 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(); Map<String, String> prop = new HashMap<String, String>(); String content = null; if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { content = null; if (cluster.getDesiredConfigByType("hadoop-env") != null) { content = cluster.getDesiredConfigByType( "hadoop-env").getProperties().get("content"); } if (content != null) { content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\""; prop.put("content", content); updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false); } if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null && !cluster.getHosts("HDFS","NAMENODE").isEmpty()) { URI nameNodeRpc = null; String hostName = cluster.getHosts("HDFS","NAMENODE").iterator().next(); if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) { try { if (isNNHAEnabled(cluster)) { Set<String> removePropertiesSet = new HashSet<>(); removePropertiesSet.add("dfs.namenode.rpc-address"); removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG, removePropertiesSet); } else { nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS")); Map<String, String> hdfsProp = new HashMap<String, String>(); hdfsProp.put("dfs.namenode.rpc-address", hostName + ":" + nameNodeRpc.getPort()); updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp, false, false); } } catch (URISyntaxException e) { e.printStackTrace(); } } } } } } } }
UpgradeCatalog210 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(); Map<String, String> prop = new HashMap<String, String>(); String content = null; if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { content = null; if (cluster.getDesiredConfigByType("hadoop-env") != null) { content = cluster.getDesiredConfigByType( "hadoop-env").getProperties().get("content"); } if (content != null) { content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\""; prop.put("content", content); updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false); } if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null && !cluster.getHosts("HDFS","NAMENODE").isEmpty()) { URI nameNodeRpc = null; String hostName = cluster.getHosts("HDFS","NAMENODE").iterator().next(); if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) { try { if (isNNHAEnabled(cluster)) { Set<String> removePropertiesSet = new HashSet<>(); removePropertiesSet.add("dfs.namenode.rpc-address"); removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG, removePropertiesSet); } else { nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS")); Map<String, String> hdfsProp = new HashMap<String, String>(); hdfsProp.put("dfs.namenode.rpc-address", hostName + ":" + nameNodeRpc.getPort()); updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp, false, false); } } catch (URISyntaxException e) { e.printStackTrace(); } } } } } } } @Inject  UpgradeCatalog210(Injector injector); }
UpgradeCatalog210 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(); Map<String, String> prop = new HashMap<String, String>(); String content = null; if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { content = null; if (cluster.getDesiredConfigByType("hadoop-env") != null) { content = cluster.getDesiredConfigByType( "hadoop-env").getProperties().get("content"); } if (content != null) { content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\""; prop.put("content", content); updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false); } if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null && !cluster.getHosts("HDFS","NAMENODE").isEmpty()) { URI nameNodeRpc = null; String hostName = cluster.getHosts("HDFS","NAMENODE").iterator().next(); if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) { try { if (isNNHAEnabled(cluster)) { Set<String> removePropertiesSet = new HashSet<>(); removePropertiesSet.add("dfs.namenode.rpc-address"); removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG, removePropertiesSet); } else { nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS")); Map<String, String> hdfsProp = new HashMap<String, String>(); hdfsProp.put("dfs.namenode.rpc-address", hostName + ":" + nameNodeRpc.getPort()); updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp, false, false); } } catch (URISyntaxException e) { e.printStackTrace(); } } } } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog210 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(); Map<String, String> prop = new HashMap<String, String>(); String content = null; if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { content = null; if (cluster.getDesiredConfigByType("hadoop-env") != null) { content = cluster.getDesiredConfigByType( "hadoop-env").getProperties().get("content"); } if (content != null) { content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\""; prop.put("content", content); updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false); } if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null && !cluster.getHosts("HDFS","NAMENODE").isEmpty()) { URI nameNodeRpc = null; String hostName = cluster.getHosts("HDFS","NAMENODE").iterator().next(); if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) { try { if (isNNHAEnabled(cluster)) { Set<String> removePropertiesSet = new HashSet<>(); removePropertiesSet.add("dfs.namenode.rpc-address"); removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG, removePropertiesSet); } else { nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS")); Map<String, String> hdfsProp = new HashMap<String, String>(); hdfsProp.put("dfs.namenode.rpc-address", hostName + ":" + nameNodeRpc.getPort()); updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp, false, false); } } catch (URISyntaxException e) { e.printStackTrace(); } } } } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }