UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void updateStormConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance( AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { if(cluster.getDesiredConfigByType("cluster-env") != null && cluster.getDesiredConfigByType("cluster-env").getProperties().get("security_enabled").equals("true") && cluster.getDesiredConfigByType("storm-site") != null ) { Map<String, String> newStormProps = new HashMap<String, String>(); if (!cluster.getDesiredConfigByType("storm-site").getProperties().containsKey("java.security.auth.login.config")) { newStormProps.put("java.security.auth.login.config", "{{conf_dir}}/storm_jaas.conf"); } if (!cluster.getDesiredConfigByType("storm-site").getProperties().containsKey("nimbus.admins")) { newStormProps.put("nimbus.admins", "['{{storm_user}}']"); } if (!cluster.getDesiredConfigByType("storm-site").getProperties().containsKey("nimbus.supervisors.users")) { newStormProps.put("nimbus.supervisors.users", "['{{storm_user}}']"); } if (!cluster.getDesiredConfigByType("storm-site").getProperties().containsKey("storm.zookeeper.superACL")) { newStormProps.put("storm.zookeeper.superACL", "sasl:{{storm_bare_jaas_principal}}"); } if (!cluster.getDesiredConfigByType("storm-site").getProperties().containsKey("ui.filter.params")) { newStormProps.put("ui.filter.params", "{'type': 'kerberos', 'kerberos.principal': '{{storm_ui_jaas_principal}}', 'kerberos.keytab': '{{storm_ui_keytab_path}}', 'kerberos.name.rules': 'DEFAULT'}"); } updateConfigurationPropertiesForCluster(cluster, "storm-site", newStormProps, false, true); } } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }
@Test public void testUpdateStormConfiguration() 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 Config mockClusterEnv = easyMockSupport.createNiceMock(Config.class); final Config mockStormSite = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedClusterEnv = new HashMap<String, String>(); propertiesExpectedClusterEnv.put("security_enabled", "true"); final Map<String, String> propertiesExpectedStormSite = new HashMap<String, String>(); 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(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("cluster-env")).andReturn(mockClusterEnv).atLeastOnce(); expect(mockClusterExpected.getDesiredConfigByType("storm-site")).andReturn(mockStormSite).atLeastOnce(); expect(mockClusterEnv.getProperties()).andReturn(propertiesExpectedClusterEnv).anyTimes(); expect(mockStormSite.getProperties()).andReturn(propertiesExpectedStormSite).anyTimes(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog210.class).updateStormConfigs(); easyMockSupport.verifyAll(); }