UpgradeCatalog222 extends AbstractUpgradeCatalog { protected void updateZookeeperConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Map<String, Cluster> clusterMap = getCheckedClusterMap(ambariManagementController.getClusters()); for (final Cluster cluster : clusterMap.values()) { Config zooEnv = cluster.getDesiredConfigByType("zookeeper-env"); if (zooEnv != null && zooEnv.getProperties().containsKey("zk_server_heapsize")) { String heapSizeValue = zooEnv.getProperties().get("zk_server_heapsize"); if(!heapSizeValue.endsWith("m")) { Map<String, String> updates = new HashMap<String, String>(); updates.put("zk_server_heapsize", heapSizeValue+"m"); updateConfigurationPropertiesForCluster(cluster, "zookeeper-env", updates, true, 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 testUpdateZookeeperConfigs() 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 Config zookeeperEnv = easyMockSupport.createNiceMock(Config.class); expect(zookeeperEnv.getProperties()).andReturn(new HashMap<String, String>(){{ put("zk_server_heapsize", "1024"); }} ).anyTimes(); 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("zookeeper-env")).andReturn(zookeeperEnv).atLeastOnce(); 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("zk_server_heapsize", "1024m"); upgradeCatalog222.updateConfigurationPropertiesForCluster(mockClusterExpected, "zookeeper-env", expectedUpdates, true, false); expectLastCall().once(); easyMockSupport.replayAll(); replay(upgradeCatalog222); upgradeCatalog222.updateZookeeperConfigs(); easyMockSupport.verifyAll(); }