@Test public void TestRangerSitePropertyConversion() throws Exception{ EasyMockSupport easyMockSupport = new EasyMockSupport(); final String clusterName = "c1"; final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster cluster = easyMockSupport.createStrictMock(Cluster.class); final Config config = easyMockSupport.createNiceMock(Config.class); final Map<String,Cluster> clusters = new HashMap<String,Cluster>(){{ put(clusterName, cluster); }}; final Map<String,String> properties = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "test123"); put("HTTPS_KEYSTORE_FILE", "test123"); put("HTTPS_KEYSTORE_PASS", "test123"); put("HTTPS_KEY_ALIAS", "test123"); put("HTTPS_SERVICE_PORT", "test123"); put("HTTP_ENABLED", "test123"); put("HTTP_SERVICE_PORT", "test123"); }}; final Map<String, String> expectedPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTP_SERVICE_PORT", "http.service.port"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); }}; final Map<String,String> convertedProperties = new HashMap<>(); final Set<String> removedProperties = new HashSet<>(); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(Clusters.class).toInstance(mockClusters); bind(ConfigHelper.class).toInstance(mockConfigHelper); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); UpgradeCatalog210 upgradeCatalog210 = new UpgradeCatalog210(mockInjector) { @Override protected void updateConfigurationPropertiesForCluster(Cluster cluster, String configType, Map<String, String> properties, boolean updateIfExists, boolean createNewConfigType) throws AmbariException { convertedProperties.putAll(properties); } @Override protected void removeConfigurationPropertiesFromCluster(Cluster cluster, String configType, Set<String> removePropertiesList) throws AmbariException { removedProperties.addAll(removePropertiesList); } }; expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).atLeastOnce(); expect(mockClusters.getClusters()).andReturn(clusters).atLeastOnce(); expect(config.getProperties()).andReturn(properties).atLeastOnce(); expect(cluster.getDesiredConfigByType("ranger-site")).andReturn(config).atLeastOnce(); replay(mockAmbariManagementController, mockClusters, cluster, config); upgradeCatalog210.updateRangerSiteConfigs(); for (Map.Entry<String,String> propertyEntry: expectedPropertyMap.entrySet()){ String oldKey = propertyEntry.getKey(); String newKey = propertyEntry.getValue(); assertTrue(String.format("Old property %s doesn't migrated to new name %s", oldKey, newKey), convertedProperties.containsKey(newKey)); assertTrue(String.format("Property value %s doesn't preserved after renaming: %s",properties.get(oldKey), convertedProperties.get(newKey)), convertedProperties.get(newKey).equals(properties.get(oldKey))); assertTrue(String.format("Old property %s doesn't removed after renaming", oldKey), removedProperties.contains(oldKey)); } }
protected void updateRangerSiteConfigs() throws AmbariException{ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, String> rangerPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); put("HTTP_SERVICE_PORT", "http.service.port"); }}; if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config rangerSite = cluster.getDesiredConfigByType(RANGER_SITE_CONFIG); Map<String, String> rangerSiteProperties; Map<String, String> convertedRangerSiteProperties = new HashMap<>(); Set<String> oldPropertiesList = new HashSet<>(); if (rangerSite != null) { rangerSiteProperties = rangerSite.getProperties(); for (Map.Entry<String, String> mapEntry: rangerPropertyMap.entrySet()) { String oldKey = mapEntry.getKey(); String newKey = mapEntry.getValue(); if (rangerSiteProperties.containsKey(oldKey)) { convertedRangerSiteProperties.put(newKey, rangerSiteProperties.get(oldKey)); oldPropertiesList.add(oldKey); } } } updateConfigurationPropertiesForCluster(cluster, RANGER_SITE_CONFIG, convertedRangerSiteProperties, true, false); removeConfigurationPropertiesFromCluster(cluster, RANGER_SITE_CONFIG, oldPropertiesList); } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerSiteConfigs() throws AmbariException{ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, String> rangerPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); put("HTTP_SERVICE_PORT", "http.service.port"); }}; if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config rangerSite = cluster.getDesiredConfigByType(RANGER_SITE_CONFIG); Map<String, String> rangerSiteProperties; Map<String, String> convertedRangerSiteProperties = new HashMap<>(); Set<String> oldPropertiesList = new HashSet<>(); if (rangerSite != null) { rangerSiteProperties = rangerSite.getProperties(); for (Map.Entry<String, String> mapEntry: rangerPropertyMap.entrySet()) { String oldKey = mapEntry.getKey(); String newKey = mapEntry.getValue(); if (rangerSiteProperties.containsKey(oldKey)) { convertedRangerSiteProperties.put(newKey, rangerSiteProperties.get(oldKey)); oldPropertiesList.add(oldKey); } } } updateConfigurationPropertiesForCluster(cluster, RANGER_SITE_CONFIG, convertedRangerSiteProperties, true, false); removeConfigurationPropertiesFromCluster(cluster, RANGER_SITE_CONFIG, oldPropertiesList); } } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerSiteConfigs() throws AmbariException{ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, String> rangerPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); put("HTTP_SERVICE_PORT", "http.service.port"); }}; if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config rangerSite = cluster.getDesiredConfigByType(RANGER_SITE_CONFIG); Map<String, String> rangerSiteProperties; Map<String, String> convertedRangerSiteProperties = new HashMap<>(); Set<String> oldPropertiesList = new HashSet<>(); if (rangerSite != null) { rangerSiteProperties = rangerSite.getProperties(); for (Map.Entry<String, String> mapEntry: rangerPropertyMap.entrySet()) { String oldKey = mapEntry.getKey(); String newKey = mapEntry.getValue(); if (rangerSiteProperties.containsKey(oldKey)) { convertedRangerSiteProperties.put(newKey, rangerSiteProperties.get(oldKey)); oldPropertiesList.add(oldKey); } } } updateConfigurationPropertiesForCluster(cluster, RANGER_SITE_CONFIG, convertedRangerSiteProperties, true, false); removeConfigurationPropertiesFromCluster(cluster, RANGER_SITE_CONFIG, oldPropertiesList); } } } } @Inject  UpgradeCatalog210(Injector injector); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerSiteConfigs() throws AmbariException{ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, String> rangerPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); put("HTTP_SERVICE_PORT", "http.service.port"); }}; if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config rangerSite = cluster.getDesiredConfigByType(RANGER_SITE_CONFIG); Map<String, String> rangerSiteProperties; Map<String, String> convertedRangerSiteProperties = new HashMap<>(); Set<String> oldPropertiesList = new HashSet<>(); if (rangerSite != null) { rangerSiteProperties = rangerSite.getProperties(); for (Map.Entry<String, String> mapEntry: rangerPropertyMap.entrySet()) { String oldKey = mapEntry.getKey(); String newKey = mapEntry.getValue(); if (rangerSiteProperties.containsKey(oldKey)) { convertedRangerSiteProperties.put(newKey, rangerSiteProperties.get(oldKey)); oldPropertiesList.add(oldKey); } } } updateConfigurationPropertiesForCluster(cluster, RANGER_SITE_CONFIG, convertedRangerSiteProperties, true, false); removeConfigurationPropertiesFromCluster(cluster, RANGER_SITE_CONFIG, oldPropertiesList); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateRangerSiteConfigs() throws AmbariException{ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, String> rangerPropertyMap = new HashMap<String, String>() {{ put("HTTPS_CLIENT_AUTH", "https.attrib.clientAuth"); put("HTTPS_KEYSTORE_FILE", "https.attrib.keystoreFile"); put("HTTPS_KEYSTORE_PASS", "https.attrib.keystorePass"); put("HTTPS_KEY_ALIAS", "https.attrib.keyAlias"); put("HTTPS_SERVICE_PORT", "https.service.port"); put("HTTP_ENABLED", "http.enabled"); put("HTTP_SERVICE_PORT", "http.service.port"); }}; if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config rangerSite = cluster.getDesiredConfigByType(RANGER_SITE_CONFIG); Map<String, String> rangerSiteProperties; Map<String, String> convertedRangerSiteProperties = new HashMap<>(); Set<String> oldPropertiesList = new HashSet<>(); if (rangerSite != null) { rangerSiteProperties = rangerSite.getProperties(); for (Map.Entry<String, String> mapEntry: rangerPropertyMap.entrySet()) { String oldKey = mapEntry.getKey(); String newKey = mapEntry.getValue(); if (rangerSiteProperties.containsKey(oldKey)) { convertedRangerSiteProperties.put(newKey, rangerSiteProperties.get(oldKey)); oldPropertiesList.add(oldKey); } } } updateConfigurationPropertiesForCluster(cluster, RANGER_SITE_CONFIG, convertedRangerSiteProperties, true, false); removeConfigurationPropertiesFromCluster(cluster, RANGER_SITE_CONFIG, oldPropertiesList); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }