UpgradeCatalog220 extends AbstractUpgradeCatalog { protected void updateFlumeEnvConfig() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values()) { Config flumeEnvConfig = cluster.getDesiredConfigByType(FLUME_ENV_CONFIG); if (flumeEnvConfig != null) { String content = flumeEnvConfig.getProperties().get(CONTENT_PROPERTY); if (content != null && !content.contains("/usr/lib/flume/lib/ambari-metrics-flume-sink.jar")) { String newPartOfContent = "\n\n" + "# Note that the Flume conf directory is always included in the classpath.\n" + "# Add flume sink to classpath\n" + "if [ -e \"/usr/lib/flume/lib/ambari-metrics-flume-sink.jar\" ]; then\n" + " export FLUME_CLASSPATH=$FLUME_CLASSPATH:/usr/lib/flume/lib/ambari-metrics-flume-sink.jar\n" + "fi\n"; content += newPartOfContent; Map<String, String> updates = Collections.singletonMap(CONTENT_PROPERTY, content); updateConfigurationPropertiesForCluster(cluster, FLUME_ENV_CONFIG, 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 testUpdateFlumeEnvConfig() 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 Map<String, String> propertiesFlumeEnv = new HashMap<String, String>() { { put("content", "test"); } }; final Config mockFlumeEnv = easyMockSupport.createNiceMock(Config.class); expect(mockFlumeEnv.getProperties()).andReturn(propertiesFlumeEnv).once(); 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("flume-env")).andReturn(mockFlumeEnv).atLeastOnce(); expect(mockFlumeEnv.getProperties()).andReturn(propertiesFlumeEnv).atLeastOnce(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog220.class).updateFlumeEnvConfig(); easyMockSupport.verifyAll(); }