UpgradeCatalog220 extends AbstractUpgradeCatalog { protected void updateHiveConfig() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values()) { Config hiveSiteConfig = cluster.getDesiredConfigByType(HIVE_SITE_CONFIG); if (hiveSiteConfig != null) { String hiveServer2OperationLogLocation = hiveSiteConfig.getProperties().get(HIVE_SERVER2_OPERATION_LOG_LOCATION_PROPERTY); if (hiveServer2OperationLogLocation != null && hiveServer2OperationLogLocation.equals("${system:java.io.tmpdir}/${system:user.name}/operation_logs")) { Map<String, String> updates = Collections.singletonMap(HIVE_SERVER2_OPERATION_LOG_LOCATION_PROPERTY, "/tmp/hive/operation_logs"); updateConfigurationPropertiesForCluster(cluster, HIVE_SITE_CONFIG, updates, true, false); } } StackId stackId = cluster.getCurrentStackVersion(); boolean isStackNotLess23 = (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.3") >= 0); Config hiveEnvConfig = cluster.getDesiredConfigByType(HIVE_ENV_CONFIG); if (hiveEnvConfig != null) { Map<String, String> hiveEnvProps = new HashMap<String, String>(); String content = hiveEnvConfig.getProperties().get(CONTENT_PROPERTY); if(content != null) { if(isStackNotLess23) { content = updateHiveEnvContentHDP23(content); } else { content = updateHiveEnvContent(content); } hiveEnvProps.put(CONTENT_PROPERTY, content); updateConfigurationPropertiesForCluster(cluster, HIVE_ENV_CONFIG, hiveEnvProps, true, true); } } } } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); static final String UPGRADE_PACKAGE_COL; static final String UPGRADE_TYPE_COL; static final String REPO_VERSION_TABLE; }
@Test public void testUpdateHiveConfig() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final Map<String, String> propertiesHiveSite = new HashMap<String, String>() {{ put("hive.server2.logging.operation.log.location", "${system:java.io.tmpdir}/${system:user.name}/operation_logs"); }}; final Map<String, String> propertiesHiveSiteExpected = new HashMap<String, String>() {{ put("hive.server2.logging.operation.log.location", "/tmp/hive/operation_logs"); }}; final Map<String, String> propertiesHiveEnv = new HashMap<String, String>() {{ put("content", "test content"); }}; final Config hiveSiteConf = easyMockSupport.createNiceMock(Config.class); final Config hiveEnvConf = easyMockSupport.createNiceMock(Config.class); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(Clusters.class).toInstance(mockClusters); bind(EntityManager.class).toInstance(entityManager); 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); }}).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(hiveSiteConf).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(hiveEnvConf).atLeastOnce(); expect(hiveSiteConf.getProperties()).andReturn(propertiesHiveSite).once(); expect(hiveEnvConf.getProperties()).andReturn(propertiesHiveEnv).once(); UpgradeCatalog220 upgradeCatalog220 = createMockBuilder(UpgradeCatalog220.class) .withConstructor(Injector.class) .withArgs(mockInjector) .addMockedMethod("updateConfigurationPropertiesForCluster", Cluster.class, String.class, Map.class, boolean.class, boolean.class) .createMock(); upgradeCatalog220.updateConfigurationPropertiesForCluster(mockClusterExpected, "hive-site", propertiesHiveSiteExpected, true, false); expectLastCall().once(); upgradeCatalog220.updateConfigurationPropertiesForCluster(mockClusterExpected, "hive-env", propertiesHiveEnv, true, true); expectLastCall().once(); easyMockSupport.replayAll(); replay(upgradeCatalog220); upgradeCatalog220.updateHiveConfig(); easyMockSupport.verifyAll(); }