UpgradeCatalog220 extends AbstractUpgradeCatalog { protected void updateZookeeperLog4j() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); for (final Cluster cluster : getCheckedClusterMap(ambariManagementController.getClusters()).values()) { Config zookeeperLog4jConfig = cluster.getDesiredConfigByType(ZOOKEEPER_LOG4J_CONFIG); if (zookeeperLog4jConfig != null) { String content = zookeeperLog4jConfig.getProperties().get(CONTENT_PROPERTY); if (content != null) { content = content.replaceAll("[\n^]\\s*log4j\\.rootLogger\\s*=\\s*INFO\\s*,\\s*CONSOLE", "\nlog4j.rootLogger=INFO, ROLLINGFILE"); Map<String, String> updates = Collections.singletonMap(CONTENT_PROPERTY, content); updateConfigurationPropertiesForCluster(cluster, ZOOKEEPER_LOG4J_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 testUpdateZookeeperLog4jConfig() 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> propertiesZookeeperLog4j = new HashMap<String, String>() { { put("content", "log4j.rootLogger=INFO, CONSOLE"); } }; final Config mockZookeeperLog4j = easyMockSupport.createNiceMock(Config.class); expect(mockZookeeperLog4j.getProperties()).andReturn(propertiesZookeeperLog4j).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("zookeeper-log4j")).andReturn(mockZookeeperLog4j).atLeastOnce(); expect(mockZookeeperLog4j.getProperties()).andReturn(propertiesZookeeperLog4j).atLeastOnce(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog220.class).updateZookeeperLog4j(); easyMockSupport.verifyAll(); }