UpgradeCatalog250 extends AbstractUpgradeCatalog { protected void updateHIVEInteractiveConfigs() 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()) { Config hiveInteractiveSite = cluster.getDesiredConfigByType(HIVE_INTERACTIVE_SITE); if (hiveInteractiveSite != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("hive.auto.convert.join.noconditionaltask.size", "1000000000"); String llapRpcPortString = hiveInteractiveSite.getProperties().get("hive.llap.daemon.rpc.port"); if (StringUtils.isNotBlank(llapRpcPortString)) { try { int llapRpcPort = Integer.parseInt(llapRpcPortString); if (llapRpcPort == 15001) { newProperties.put("hive.llap.daemon.rpc.port", "0"); LOG.info("Updating HSI hive.llap.daemon.rpc.port to: 0"); } } catch (NumberFormatException e) { LOG.warn("Unable to parse llap.rpc.port as integer: " + llapRpcPortString); } } updateConfigurationProperties(HIVE_INTERACTIVE_SITE, newProperties, true, true); } Config hiveInteractiveEnv = cluster.getDesiredConfigByType(HIVE_INTERACTIVE_ENV); Config hiveEnv = cluster.getDesiredConfigByType(HIVE_ENV); if (hiveInteractiveEnv != null) { String hsiHeapSize = "512"; if (hiveEnv != null) { if (hiveEnv.getProperties().containsKey("hive.heapsize")) { hsiHeapSize = hiveEnv.getProperties().get("hive.heapsize"); LOG.info("Updating HSI heap size to: " + hsiHeapSize); } } updateConfigurationProperties(HIVE_INTERACTIVE_ENV, Collections.singletonMap("hive_heapsize", hsiHeapSize), true, true); } } } } } @Inject  UpgradeCatalog250(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String COMPONENT_TABLE; static final String COMPONENT_VERSION_TABLE; static final String COMPONENT_VERSION_PK; static final String COMPONENT_VERSION_FK_COMPONENT; static final String COMPONENT_VERSION_FK_REPO_VERSION; }
@Test public void testUpdateHiveConfigs() throws Exception { reset(clusters, cluster); expect(clusters.getClusters()).andReturn(ImmutableMap.of("normal", cluster)).anyTimes(); EasyMockSupport easyMockSupport = new EasyMockSupport(); Injector injector2 = easyMockSupport.createNiceMock(Injector.class); AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class) .addMockedMethod("createConfiguration") .addMockedMethod("getClusters", new Class[]{}) .addMockedMethod("createConfig") .withConstructor(actionManager, clusters, injector) .createNiceMock(); expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); Map<String, String> oldHsiEnv = ImmutableMap.of( "llap_app_name", "llap0"); Map<String, String> expectedHsiEnv = ImmutableMap.of( "llap_app_name", "llap0", "hive_heapsize", "1082"); Map<String, String> oldHiveEnv = ImmutableMap.of( "hive.client.heapsize", "1024", "hive.heapsize", "1082", "hive.metastore.heapsize", "512", "hive_ambari_database", "MySQL"); Map<String, String> oldHiveIntSite = ImmutableMap.of( "hive.llap.daemon.rpc.port", "15001"); Map<String, String> expectedHiveIntSite = ImmutableMap.of( "hive.llap.daemon.rpc.port", "0", "hive.auto.convert.join.noconditionaltask.size", "1000000000"); Config mockHsiSite = easyMockSupport.createNiceMock(Config.class); expect(cluster.getDesiredConfigByType("hive-interactive-site")).andReturn(mockHsiSite).atLeastOnce(); expect(mockHsiSite.getProperties()).andReturn(oldHiveIntSite).anyTimes(); Capture<Map<String, String>> hsiSiteCapture = EasyMock.newCapture(); expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(hsiSiteCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Config mockHiveEnv = easyMockSupport.createNiceMock(Config.class); expect(cluster.getDesiredConfigByType("hive-env")).andReturn(mockHiveEnv).atLeastOnce(); expect(mockHiveEnv.getProperties()).andReturn(oldHiveEnv).anyTimes(); Config mockHsiEnv = easyMockSupport.createNiceMock(Config.class); expect(cluster.getDesiredConfigByType("hive-interactive-env")).andReturn(mockHsiEnv).atLeastOnce(); expect(mockHsiEnv.getProperties()).andReturn(oldHsiEnv).anyTimes(); Capture<Map<String, String>> hsiEnvCapture = EasyMock.newCapture(); expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(hsiEnvCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(clusters, cluster); replay(controller, injector2); replay(mockHsiEnv, mockHiveEnv, mockHsiSite); new UpgradeCatalog250(injector2).updateHIVEInteractiveConfigs(); easyMockSupport.verifyAll(); Map<String, String> updatedHsiSite = hsiSiteCapture.getValue(); assertTrue(Maps.difference(expectedHiveIntSite, updatedHsiSite).areEqual()); Map<String, String> updatedHsiEnv = hsiEnvCapture.getValue(); assertTrue(Maps.difference(expectedHsiEnv, updatedHsiEnv).areEqual()); }