Updated Branches: refs/heads/trunk a84161762 -> bb280dfdc
AMBARI-3117. Support dynamic changes of ambari.properties in api. (odiachenko) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/bb280dfd Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/bb280dfd Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/bb280dfd Branch: refs/heads/trunk Commit: bb280dfdc8a79832d5196498c412b020e4b2e15f Parents: a841617 Author: Oleksandr Diachenko <[email protected]> Authored: Thu Sep 5 23:57:28 2013 +0300 Committer: Oleksandr Diachenko <[email protected]> Committed: Thu Sep 5 23:57:28 2013 +0300 ---------------------------------------------------------------------- .../server/configuration/Configuration.java | 12 +++++++++ .../controller/RootServiceResponseFactory.java | 2 +- .../server/configuration/ConfigurationTest.java | 28 +++++++++++++++++++- .../RootServiceResponseFactoryTest.java | 4 +-- 4 files changed, 42 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/bb280dfd/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java index 4f9955d..e5d736a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java @@ -433,6 +433,7 @@ public class Configuration { // load the properties try { properties.load(inputStream); + inputStream.close(); } catch (FileNotFoundException fnf) { LOG.info("No configuration file " + CONFIG_FILE + " found in classpath.", fnf); } catch (IOException ie) { @@ -793,4 +794,15 @@ public class Configuration { return customDbProperties; } + public Map<String, String> getAmbariProperties() { + + Properties properties = readConfigFile(); + Map<String, String> ambariPropertiesMap = new HashMap<String, String>(); + + for(String key : properties.stringPropertyNames()) { + ambariPropertiesMap.put(key, properties.getProperty(key)); + } + return ambariPropertiesMap; + } + } http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/bb280dfd/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java index 42bcfbe..e5c5ca8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java @@ -151,7 +151,7 @@ public class RootServiceResponseFactory extends switch (component) { case AMBARI_SERVER: - response = configs.getConfigsMap(); + response = configs.getAmbariProperties(); break; default: http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/bb280dfd/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java index 466cd30..73552f3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java @@ -31,14 +31,26 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import static org.mockito.Mockito.*; -import static org.mockito.Matchers.*; +import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replayAll; +import static org.powermock.api.easymock.PowerMock.verifyAll; import java.io.File; import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Map; import java.util.Properties; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Configuration.class }) public class ConfigurationTest { private Injector injector; @@ -194,6 +206,20 @@ public class ConfigurationTest { Configuration conf = new Configuration(ambariProperties); Assert.assertEquals(conf.getLocalDatabaseUrl(), Configuration.JDBC_LOCAL_URL.concat("ambaritestdatabase")); } + + @Test + public void testGetAmbariProperties() throws Exception { + Properties ambariProperties = new Properties(); + ambariProperties.setProperty("name", "value"); + Configuration conf = new Configuration(ambariProperties); + mockStatic(Configuration.class); + Method[] methods = MemberMatcher.methods(Configuration.class, "readConfigFile"); + PowerMock.expectPrivate(Configuration.class, methods[0]).andReturn(ambariProperties); + replayAll(); + Map<String, String> props = conf.getAmbariProperties(); + verifyAll(); + Assert.assertEquals("value", props.get("name")); + } @Rule public ExpectedException exception = ExpectedException.none(); http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/bb280dfd/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java index b7d0a29..e3575e1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java @@ -146,7 +146,7 @@ public class RootServiceResponseFactoryTest { assertTrue(rootServiceComponents .contains(new RootServiceComponentResponse(component.name(), ambariMetaInfo.getServerVersion(), - configs.getConfigsMap()))); + configs.getAmbariProperties()))); else assertTrue(rootServiceComponents .contains(new RootServiceComponentResponse(component.name(), @@ -165,7 +165,7 @@ public class RootServiceResponseFactoryTest { assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse( RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name(), ambariMetaInfo.getServerVersion(), - configs.getConfigsMap()))); + configs.getAmbariProperties()))); // Request existent service name, and component, not belongs to requested service request =
