@Test public void testUpdateRangerHiveConfigs() 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 mockRangerPlugin = easyMockSupport.createNiceMock(Config.class); final Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class); final Config mockHiveServer = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedRangerPlugin = new HashMap<String, String>(); propertiesExpectedRangerPlugin.put("ranger-hive-plugin-enabled", "yes"); final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>(); final Map<String, String> propertiesExpectedHiveServer2 = new HashMap<String, String>(); 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("ranger-hive-plugin-properties")).andReturn(mockRangerPlugin).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hiveserver2-site")).andReturn(mockHiveServer).atLeastOnce(); expect(mockRangerPlugin.getProperties()).andReturn(propertiesExpectedRangerPlugin).anyTimes(); expect(mockHiveEnv.getProperties()).andReturn(propertiesExpectedHiveEnv).anyTimes(); expect(mockHiveServer.getProperties()).andReturn(propertiesExpectedHiveServer2).anyTimes(); ServiceConfigVersionResponse r = null; expect(mockClusterExpected.getConfig(anyObject(String.class), anyObject(String.class))). andReturn(mockHiveServer).anyTimes(); expect(mockClusterExpected.addDesiredConfig("ambari-upgrade", Collections.singleton(mockHiveServer), "Updated hive-env during Ambari Upgrade from 2.0.0 to 2.1.0.")). andReturn(r).times(1); expect(mockClusterExpected.addDesiredConfig("ambari-upgrade", Collections.singleton(mockHiveServer), "Updated hiveserver2-site during Ambari Upgrade from 2.0.0 to 2.1.0.")). andReturn(r).times(1); expect(mockClusterExpected.addDesiredConfig("ambari-upgrade", Collections.singleton(mockHiveServer), "Updated ranger-hive-plugin-properties during Ambari Upgrade from 2.0.0 to 2.1.0.")). andReturn(r).times(1); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog210.class).updateRangerHiveConfigs(); easyMockSupport.verifyAll(); }
protected void updateRangerHiveConfigs() 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 RangerHiveConfig = cluster.getDesiredConfigByType("ranger-hive-plugin-properties"); if (RangerHiveConfig != null && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled") && cluster.getDesiredConfigByType("hive-env") != null) { Map<String, String> newHiveEnvProperties = new HashMap<String, String>(); Map<String, String> newHiveServerProperties = new HashMap<String, String>(); Set<String> removeRangerHiveProperties = new HashSet<String>(); removeRangerHiveProperties.add("ranger-hive-plugin-enabled"); if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) { newHiveEnvProperties.put("hive_security_authorization", "Ranger"); newHiveServerProperties.put("hive.security.authorization.enabled", "true"); } boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization"); updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true); updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true); removeConfigurationPropertiesFromCluster(cluster, "ranger-hive-plugin-properties", removeRangerHiveProperties); } } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerHiveConfigs() 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 RangerHiveConfig = cluster.getDesiredConfigByType("ranger-hive-plugin-properties"); if (RangerHiveConfig != null && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled") && cluster.getDesiredConfigByType("hive-env") != null) { Map<String, String> newHiveEnvProperties = new HashMap<String, String>(); Map<String, String> newHiveServerProperties = new HashMap<String, String>(); Set<String> removeRangerHiveProperties = new HashSet<String>(); removeRangerHiveProperties.add("ranger-hive-plugin-enabled"); if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) { newHiveEnvProperties.put("hive_security_authorization", "Ranger"); newHiveServerProperties.put("hive.security.authorization.enabled", "true"); } boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization"); updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true); updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true); removeConfigurationPropertiesFromCluster(cluster, "ranger-hive-plugin-properties", removeRangerHiveProperties); } } } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerHiveConfigs() 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 RangerHiveConfig = cluster.getDesiredConfigByType("ranger-hive-plugin-properties"); if (RangerHiveConfig != null && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled") && cluster.getDesiredConfigByType("hive-env") != null) { Map<String, String> newHiveEnvProperties = new HashMap<String, String>(); Map<String, String> newHiveServerProperties = new HashMap<String, String>(); Set<String> removeRangerHiveProperties = new HashSet<String>(); removeRangerHiveProperties.add("ranger-hive-plugin-enabled"); if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) { newHiveEnvProperties.put("hive_security_authorization", "Ranger"); newHiveServerProperties.put("hive.security.authorization.enabled", "true"); } boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization"); updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true); updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true); removeConfigurationPropertiesFromCluster(cluster, "ranger-hive-plugin-properties", removeRangerHiveProperties); } } } } } @Inject  UpgradeCatalog210(Injector injector); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerHiveConfigs() 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 RangerHiveConfig = cluster.getDesiredConfigByType("ranger-hive-plugin-properties"); if (RangerHiveConfig != null && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled") && cluster.getDesiredConfigByType("hive-env") != null) { Map<String, String> newHiveEnvProperties = new HashMap<String, String>(); Map<String, String> newHiveServerProperties = new HashMap<String, String>(); Set<String> removeRangerHiveProperties = new HashSet<String>(); removeRangerHiveProperties.add("ranger-hive-plugin-enabled"); if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) { newHiveEnvProperties.put("hive_security_authorization", "Ranger"); newHiveServerProperties.put("hive.security.authorization.enabled", "true"); } boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization"); updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true); updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true); removeConfigurationPropertiesFromCluster(cluster, "ranger-hive-plugin-properties", removeRangerHiveProperties); } } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerHiveConfigs() 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 RangerHiveConfig = cluster.getDesiredConfigByType("ranger-hive-plugin-properties"); if (RangerHiveConfig != null && RangerHiveConfig.getProperties().containsKey("ranger-hive-plugin-enabled") && cluster.getDesiredConfigByType("hive-env") != null) { Map<String, String> newHiveEnvProperties = new HashMap<String, String>(); Map<String, String> newHiveServerProperties = new HashMap<String, String>(); Set<String> removeRangerHiveProperties = new HashSet<String>(); removeRangerHiveProperties.add("ranger-hive-plugin-enabled"); if (RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled") != null && RangerHiveConfig.getProperties().get("ranger-hive-plugin-enabled").equalsIgnoreCase("yes")) { newHiveEnvProperties.put("hive_security_authorization", "Ranger"); newHiveServerProperties.put("hive.security.authorization.enabled", "true"); } boolean updateProperty = cluster.getDesiredConfigByType("hive-env").getProperties().containsKey("hive_security_authorization"); updateConfigurationPropertiesForCluster(cluster, "hive-env", newHiveEnvProperties, updateProperty, true); updateConfigurationPropertiesForCluster(cluster, "hiveserver2-site", newHiveServerProperties, updateProperty, true); removeConfigurationPropertiesFromCluster(cluster, "ranger-hive-plugin-properties", removeRangerHiveProperties); } } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }