@Test public void testRangerHbasePluginProperertiesUpdateConfigs() throws Exception{ Map<String, String> oldRangerHbasePluginPropererties = new HashMap<String, String>() { { put("policy_user", "ambari-qa"); } }; Map<String, String> newRangerHbasePluginPropererties = new HashMap<String, String>() { { put("policy_user", "cstm-user"); } }; Map<String, String> hadoopEnvProperties = new HashMap<String, String>() { { put("smokeuser", "cstm-user"); } }; 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 = new HashMap<>(); services.put("HBASE", service); services.put("RANGER", service); Config mockRangerHbasePluginPropererties = easyMockSupport.createNiceMock(Config.class); Config mockHadoopEnv = easyMockSupport.createNiceMock(Config.class); expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", cluster); }}).anyTimes(); expect(cluster.getServices()).andReturn(services).once(); expect(cluster.getDesiredConfigByType("cluster-env")).andReturn(mockHadoopEnv).atLeastOnce(); expect(cluster.getDesiredConfigByType("ranger-hbase-plugin-properties")).andReturn(mockRangerHbasePluginPropererties).atLeastOnce(); expect(mockRangerHbasePluginPropererties.getProperties()).andReturn(oldRangerHbasePluginPropererties).anyTimes(); expect(mockHadoopEnv.getProperties()).andReturn(hadoopEnvProperties).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, mockRangerHbasePluginPropererties, mockHadoopEnv, 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).updateRangerHbasePluginProperties(); easyMockSupport.verifyAll(); Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newRangerHbasePluginPropererties, updatedProperties).areEqual()); }
protected void updateRangerHbasePluginProperties() 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("HBASE") && installedServices.contains("RANGER")) { Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); Config clusterEnv = cluster.getDesiredConfigByType("cluster-env"); if (rangerHbasePluginProperties != null && clusterEnv != null) { String smokeUserName = clusterEnv.getProperties().get("smokeuser"); String policyUser = rangerHbasePluginProperties.getProperties().get("policy_user"); if (policyUser != null && smokeUserName != null && !policyUser.equals(smokeUserName) && policyUser.equals("ambari-qa")) { updateConfigurationProperties("ranger-hbase-plugin-properties", Collections.singletonMap("policy_user", smokeUserName), true, false); } } } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateRangerHbasePluginProperties() 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("HBASE") && installedServices.contains("RANGER")) { Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); Config clusterEnv = cluster.getDesiredConfigByType("cluster-env"); if (rangerHbasePluginProperties != null && clusterEnv != null) { String smokeUserName = clusterEnv.getProperties().get("smokeuser"); String policyUser = rangerHbasePluginProperties.getProperties().get("policy_user"); if (policyUser != null && smokeUserName != null && !policyUser.equals(smokeUserName) && policyUser.equals("ambari-qa")) { updateConfigurationProperties("ranger-hbase-plugin-properties", Collections.singletonMap("policy_user", smokeUserName), true, false); } } } } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateRangerHbasePluginProperties() 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("HBASE") && installedServices.contains("RANGER")) { Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); Config clusterEnv = cluster.getDesiredConfigByType("cluster-env"); if (rangerHbasePluginProperties != null && clusterEnv != null) { String smokeUserName = clusterEnv.getProperties().get("smokeuser"); String policyUser = rangerHbasePluginProperties.getProperties().get("policy_user"); if (policyUser != null && smokeUserName != null && !policyUser.equals(smokeUserName) && policyUser.equals("ambari-qa")) { updateConfigurationProperties("ranger-hbase-plugin-properties", Collections.singletonMap("policy_user", smokeUserName), true, false); } } } } } } } @Inject  UpgradeCatalog240(Injector injector); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateRangerHbasePluginProperties() 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("HBASE") && installedServices.contains("RANGER")) { Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); Config clusterEnv = cluster.getDesiredConfigByType("cluster-env"); if (rangerHbasePluginProperties != null && clusterEnv != null) { String smokeUserName = clusterEnv.getProperties().get("smokeuser"); String policyUser = rangerHbasePluginProperties.getProperties().get("policy_user"); if (policyUser != null && smokeUserName != null && !policyUser.equals(smokeUserName) && policyUser.equals("ambari-qa")) { updateConfigurationProperties("ranger-hbase-plugin-properties", Collections.singletonMap("policy_user", smokeUserName), true, false); } } } } } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateRangerHbasePluginProperties() 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("HBASE") && installedServices.contains("RANGER")) { Config rangerHbasePluginProperties = cluster.getDesiredConfigByType("ranger-hbase-plugin-properties"); Config clusterEnv = cluster.getDesiredConfigByType("cluster-env"); if (rangerHbasePluginProperties != null && clusterEnv != null) { String smokeUserName = clusterEnv.getProperties().get("smokeuser"); String policyUser = rangerHbasePluginProperties.getProperties().get("policy_user"); if (policyUser != null && smokeUserName != null && !policyUser.equals(smokeUserName) && policyUser.equals("ambari-qa")) { updateConfigurationProperties("ranger-hbase-plugin-properties", Collections.singletonMap("policy_user", smokeUserName), 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; }