UpgradeCatalog222 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); Config atlasConfig = cluster.getDesiredConfigByType(ATLAS_APPLICATION_PROPERTIES_CONFIG); StackId stackId = cluster.getCurrentStackVersion(); boolean isStackNotLess23 = (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.3") >= 0); List<ServiceComponentHost> atlasHost = cluster.getServiceComponentHosts("ATLAS", "ATLAS_SERVER"); Map<String, String> updates = new HashMap<String, String>(); if (isStackNotLess23 && atlasHost.size() != 0 && hiveSiteConfig != null) { updates.put(ATLAS_HOOK_HIVE_MINTHREADS_PROPERTY, "1"); updates.put(ATLAS_HOOK_HIVE_MAXTHREADS_PROPERTY, "1"); updates.put(ATLAS_CLUSTER_NAME_PROPERTY, "primary"); if (atlasConfig != null && atlasConfig.getProperties().containsKey(ATLAS_ENABLETLS_PROPERTY)) { String atlasEnableTLSProperty = atlasConfig.getProperties().get(ATLAS_ENABLETLS_PROPERTY); String atlasScheme = "http"; String atlasServerHttpPortProperty = atlasConfig.getProperties().get(ATLAS_SERVER_HTTP_PORT_PROPERTY); if (atlasEnableTLSProperty.toLowerCase().equals("true")) { atlasServerHttpPortProperty = atlasConfig.getProperties().get(ATLAS_SERVER_HTTPS_PORT_PROPERTY); atlasScheme = "https"; } updates.put(ATLAS_REST_ADDRESS_PROPERTY, String.format("%s: } updateConfigurationPropertiesForCluster(cluster, HIVE_SITE_CONFIG, updates, false, false); } } } @Inject  UpgradeCatalog222(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_MINUTE_TABLE_TTL_PROPERTY; static final String AMS_WEBAPP_ADDRESS_PROPERTY; static final String HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD_PROPERTY; static final String HBASE_RPC_TIMEOUT_PROPERTY; static final String PHOENIX_QUERY_TIMEOUT_PROPERTY; static final String PHOENIX_QUERY_KEEPALIVE_PROPERTY; static final String TIMELINE_METRICS_CLUSTER_AGGREGATOR_INTERPOLATION_ENABLED; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String AMS_SERVICE_NAME; static final String AMS_COLLECTOR_COMPONENT_NAME; final static String HBASE_SITE_HBASE_COPROCESSOR_MASTER_CLASSES; final static String HBASE_SITE_HBASE_COPROCESSOR_REGION_CLASSES; final static String HBASE_SITE_HBASE_COPROCESSOR_REGIONSERVER_CLASSES; }
@Test public void testHiveSiteUpdateConfigs() throws AmbariException { 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 Config hiveSiteConfigs = easyMockSupport.createNiceMock(Config.class); final Config AtlasSiteConfigs = easyMockSupport.createNiceMock(Config.class); final ServiceComponentHost atlasHost = easyMockSupport.createNiceMock(ServiceComponentHost.class); final List<ServiceComponentHost> atlasHosts = new ArrayList<>(); atlasHosts.add(atlasHost); StackId stackId = new StackId("HDP","2.3"); final Map<String, String> propertiesAtlasSiteConfigs = new HashMap<String, String>() {{ put("atlas.enableTLS", "true"); put("atlas.server.https.port", "21443"); }}; 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(ServiceComponentHost.class).toInstance(atlasHost); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); expect(mockClusterExpected.getCurrentStackVersion()).andReturn(stackId).once(); expect(mockClusterExpected.getServiceComponentHosts("ATLAS", "ATLAS_SERVER")).andReturn(atlasHosts).once(); expect(atlasHost.getHostName()).andReturn("c6401").once(); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(hiveSiteConfigs).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("application-properties")).andReturn(AtlasSiteConfigs).anyTimes(); expect(AtlasSiteConfigs.getProperties()).andReturn(propertiesAtlasSiteConfigs).anyTimes(); UpgradeCatalog222 upgradeCatalog222 = createMockBuilder(UpgradeCatalog222.class) .withConstructor(Injector.class) .withArgs(mockInjector) .addMockedMethod("updateConfigurationPropertiesForCluster", Cluster.class, String.class, Map.class, boolean.class, boolean.class) .createMock(); Map<String, String> expectedUpdates = new HashMap<>(); expectedUpdates.put("atlas.hook.hive.minThreads", "1"); expectedUpdates.put("atlas.hook.hive.maxThreads", "1"); expectedUpdates.put("atlas.cluster.name", "primary"); expectedUpdates.put("atlas.rest.address", "https: upgradeCatalog222.updateConfigurationPropertiesForCluster(mockClusterExpected, "hive-site", expectedUpdates, false, false); expectLastCall().once(); easyMockSupport.replayAll(); replay(upgradeCatalog222); upgradeCatalog222.updateHiveConfig(); easyMockSupport.verifyAll(); }