UpgradeCatalog220 extends AbstractUpgradeCatalog { protected void updateStormConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values()) { Config stormSiteProps = cluster.getDesiredConfigByType(STORM_SITE); if (stormSiteProps != null) { Map<String, String> updates = new HashMap<>(); String nimbusMonitorFreqSecs = stormSiteProps.getProperties().get(NIMBS_MONITOR_FREQ_SECS_PROPERTY); if (nimbusMonitorFreqSecs != null && nimbusMonitorFreqSecs.equals("10")) { updates.put(NIMBS_MONITOR_FREQ_SECS_PROPERTY, "120"); } Service amsService = null; try { amsService = cluster.getService("AMBARI_METRICS"); } catch(AmbariException ambariException) { LOG.info("AMBARI_METRICS service not found in cluster while updating storm-site properties"); } String metricsReporter = stormSiteProps.getProperties().get(STORM_METRICS_REPORTER); if (amsService != null && StringUtils.isEmpty(metricsReporter)) { updates.put(STORM_METRICS_REPORTER, "org.apache.hadoop.metrics2.sink.storm.StormTimelineMetricsReporter"); } updateConfigurationPropertiesForCluster(cluster, STORM_SITE, updates, true, false); } } } @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 testUpdateStormSiteConfigs() throws Exception { 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 Map<String, String> propertiesStormSite = new HashMap<String, String>() { { put("nimbus.monitor.freq.secs", "10"); put("metrics.reporter.register", "org.apache.hadoop.metrics2.sink.storm.StormTimelineMetricsReporter"); } }; final Config mockStormSite = easyMockSupport.createNiceMock(Config.class); expect(mockStormSite.getProperties()).andReturn(propertiesStormSite).once(); 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(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); }}).once(); expect(mockClusterExpected.getDesiredConfigByType("storm-site")).andReturn(mockStormSite).atLeastOnce(); expect(mockStormSite.getProperties()).andReturn(propertiesStormSite).atLeastOnce(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog220.class).updateStormConfigs(); easyMockSupport.verifyAll(); }