You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2017/10/30 15:55:59 UTC
ambari git commit: AMBARI-22200. Provide a function in Configuration
class to reload the properties file for new custom properties (Yussuf Shaikh
via ncole)
Repository: ambari
Updated Branches:
refs/heads/branch-feature-AMBARI-21674 6b7a7a706 -> c839dbfe4
AMBARI-22200. Provide a function in Configuration class to reload the properties file for new custom properties (Yussuf Shaikh via ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c839dbfe
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c839dbfe
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c839dbfe
Branch: refs/heads/branch-feature-AMBARI-21674
Commit: c839dbfe4636b81e0ba0fc5d1531a987aafe8013
Parents: 6b7a7a7
Author: Nate Cole <nc...@hortonworks.com>
Authored: Mon Oct 30 11:55:53 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Mon Oct 30 11:55:53 2017 -0400
----------------------------------------------------------------------
.../server/configuration/Configuration.java | 19 +++++++++++++++++++
.../server/configuration/ConfigurationTest.java | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/c839dbfe/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 3b2baad..bf254f8 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
@@ -3031,6 +3031,25 @@ public class Configuration {
}
/**
+ * Get the property value for the given key. If the value is not
+ * found then reload the properties and get the property value
+ * for the given key.
+ *
+ * @return the property value
+ */
+ public String getPropertyForced(String key) {
+ String returnValue = properties.getProperty(key);
+ if (returnValue == null) {
+ Properties properties = readConfigFile();
+ returnValue = properties.getProperty(key);
+ if (returnValue != null) {
+ this.properties = properties;
+ }
+ }
+ return returnValue;
+ }
+
+ /**
* Gets a copy of all of the configuration properties that back this
* {@link Configuration} instance.
*
http://git-wip-us.apache.org/repos/asf/ambari/blob/c839dbfe/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 1b8de79..e47fcd2 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
@@ -300,6 +300,25 @@ public class ConfigurationTest {
}
@Test
+ public void testGetPropertyForced() throws Exception {
+ final Properties ambariProperties = new Properties();
+ ambariProperties.setProperty("name", "value");
+ final Configuration conf = new Configuration();
+
+ mockStatic(Configuration.class);
+ Method[] methods = MemberMatcher.methods(Configuration.class, "readConfigFile");
+ PowerMock.expectPrivate(Configuration.class, methods[0]).andReturn(ambariProperties);
+ replayAll();
+
+ String returnValue = conf.getPropertyForced("name");
+ verifyAll();
+ Assert.assertEquals("value", returnValue);
+
+ Properties configProps = conf.getProperties();
+ Assert.assertEquals("value", configProps.getProperty("name"));
+ }
+
+ @Test
public void testGetAmbariBlacklistFile() {
Properties ambariProperties = new Properties();
Configuration conf = new Configuration(ambariProperties);