UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void removeHiveOozieDBConnectionConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Map<String, Cluster> clusterMap = getCheckedClusterMap(ambariManagementController.getClusters()); for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV_CONFIG); if(oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); Set<String> removePropertiesSet = new HashSet<>(); if (oozieEnvProperties.containsKey("oozie_derby_database")) { LOG.info("Removing property oozie_derby_database from " + OOZIE_ENV_CONFIG); removePropertiesSet.add("oozie_derby_database"); } if (oozieEnvProperties.containsKey("oozie_hostname")) { LOG.info("Removing property oozie_hostname from " + OOZIE_ENV_CONFIG); removePropertiesSet.add("oozie_hostname"); } if (!removePropertiesSet.isEmpty()) { removeConfigurationPropertiesFromCluster(cluster, OOZIE_ENV_CONFIG, removePropertiesSet); } } Config hiveEnv = cluster.getDesiredConfigByType(HIVE_ENV_CONFIG); if(hiveEnv != null) { Map<String, String> hiveEnvProperties = hiveEnv.getProperties(); if (hiveEnvProperties.containsKey("hive_hostname")) { LOG.info("Removing property hive_hostname from " + HIVE_ENV_CONFIG); removeConfigurationPropertiesFromCluster(cluster, HIVE_ENV_CONFIG, Collections.singleton("hive_hostname")); } } } } @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; }
@Test public void testRemoveHiveOozieDBConnectionConfigs() 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 mockOozieEnv = easyMockSupport.createNiceMock(Config.class); final Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedOozieEnv = new HashMap<String, String>(); propertiesExpectedOozieEnv.put("oozie_derby_database", "Derby"); propertiesExpectedOozieEnv.put("property", "value"); final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>(); propertiesExpectedHiveEnv.put("hive_hostname", "hostname"); final Injector mockInjector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { binder.bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); binder.bind(ConfigHelper.class).toInstance(mockConfigHelper); binder.bind(Clusters.class).toInstance(mockClusters); binder.bind(EntityManager.class).toInstance(entityManager); binder.bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); binder.bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class)); binder.bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); binder.bind(HookService.class).toInstance(createMock(HookService.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).once(); expect(mockClusterExpected.getDesiredConfigByType("oozie-env")).andReturn(mockOozieEnv).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce(); expect(mockOozieEnv.getProperties()).andReturn(propertiesExpectedOozieEnv).anyTimes(); expect(mockHiveEnv.getProperties()).andReturn(propertiesExpectedHiveEnv).anyTimes(); Capture<Map<String, String>> oozieCapture = newCapture(); Capture<Map<String, String>> hiveCapture = newCapture(); expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("oozie-env"), capture(oozieCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("hive-env"), capture(hiveCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog240.class).removeHiveOozieDBConnectionConfigs(); easyMockSupport.verifyAll(); assertEquals("value", oozieCapture.getValue().get("property")); assertNull(oozieCapture.getValue().get("oozie_derby_database")); assertNull(oozieCapture.getValue().get("oozie_hostname")); assertNull(hiveCapture.getValue().get("hive_hostname")); }