UpgradeCatalog212 extends AbstractUpgradeCatalog { protected void updateHiveConfigs() 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()) { String content = null; Boolean isHiveSitePresent = cluster.getDesiredConfigByType(HIVE_SITE) != null; StackId stackId = cluster.getCurrentStackVersion(); Boolean isStackNotLess22 = (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0); if (cluster.getDesiredConfigByType(HIVE_ENV) != null && isStackNotLess22) { Map<String, String> hiveEnvProps = new HashMap<String, String>(); content = cluster.getDesiredConfigByType(HIVE_ENV).getProperties().get("content"); if(content != null) { content = updateHiveEnvContent(content); hiveEnvProps.put("content", content); } updateConfigurationPropertiesForCluster(cluster, HIVE_ENV, hiveEnvProps, true, true); } if (isHiveSitePresent && isStackNotLess22) { Set<String> hiveSiteRemoveProps = new HashSet<String>(); hiveSiteRemoveProps.add("hive.heapsize"); hiveSiteRemoveProps.add("hive.optimize.mapjoin.mapreduce"); hiveSiteRemoveProps.add("hive.server2.enable.impersonation"); hiveSiteRemoveProps.add("hive.auto.convert.sortmerge.join.noconditionaltask"); updateConfigurationPropertiesForCluster(cluster, HIVE_SITE, new HashMap<String, String>(), hiveSiteRemoveProps, false, true); } } } } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testUpdateHiveConfigs() throws Exception { setupIoCContext(); 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 mockHiveEnv = easyMockSupport.createNiceMock(Config.class); final Config mockHiveSite = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedHiveEnv = new HashMap<String, String>(); final Map<String, String> propertiesExpectedHiveSite = new HashMap<String, String>() {{ put("hive.heapsize", "512"); put("hive.server2.custom.authentication.class", ""); }}; 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("hive-site")).andReturn(mockHiveSite).atLeastOnce(); expect(mockHiveSite.getProperties()).andReturn(propertiesExpectedHiveSite).atLeastOnce(); StackId stackId = new StackId("HDP-2.2"); expect(mockClusterExpected.getCurrentStackVersion()).andReturn(stackId).atLeastOnce(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog212.class).updateHiveConfigs(); easyMockSupport.verifyAll(); }