You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2015/04/09 03:43:10 UTC

accumulo git commit: ACCUMULO-3417 Retrieve conf properties by name

Repository: accumulo
Updated Branches:
  refs/heads/master 4fd1cfdea -> 27f3b3088


ACCUMULO-3417 Retrieve conf properties by name


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/27f3b308
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/27f3b308
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/27f3b308

Branch: refs/heads/master
Commit: 27f3b3088b92c89d84c32072cfd2cbf52ad107f2
Parents: 4fd1cfd
Author: Christopher Tubbs <ct...@apache.org>
Authored: Wed Apr 8 21:42:05 2015 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Apr 8 21:42:05 2015 -0400

----------------------------------------------------------------------
 .../core/conf/AccumuloConfiguration.java        | 41 ++++++++++++++++++++
 .../core/conf/AccumuloConfigurationTest.java    | 17 ++++++++
 .../accumulo/server/conf/ZooConfiguration.java  |  6 +--
 3 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/27f3b308/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
index 6041620..14d68c2 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 
@@ -62,6 +63,29 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str
   }
 
   /**
+   * A filter that accepts properties whose keys are an exact match.
+   */
+  public static class MatchFilter implements PropertyFilter {
+
+    private String match;
+
+    /**
+     * Creates a new filter.
+     *
+     * @param match
+     *          prefix of property keys to accept
+     */
+    public MatchFilter(String match) {
+      this.match = match;
+    }
+
+    @Override
+    public boolean accept(String key) {
+      return Objects.equals(match, key);
+    }
+  }
+
+  /**
    * A filter that accepts properties whose keys begin with a prefix.
    */
   public static class PrefixFilter implements PropertyFilter {
@@ -89,6 +113,23 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str
   /**
    * Gets a property value from this configuration.
    *
+   * <p>
+   * Note: this is inefficient, but convenient on occasion. For retrieving multiple properties, use {@link #getProperties(Map, PropertyFilter)} with a custom
+   * filter.
+   *
+   * @param property
+   *          property to get
+   * @return property value
+   */
+  public String get(String property) {
+    Map<String,String> propMap = new HashMap<String,String>(1);
+    getProperties(propMap, new MatchFilter(property));
+    return propMap.get(property);
+  }
+
+  /**
+   * Gets a property value from this configuration.
+   *
    * @param property
    *          property to get
    * @return property value

http://git-wip-us.apache.org/repos/asf/accumulo/blob/27f3b308/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
index 0f0e5fc..efb080d 100644
--- a/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.core.conf;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
@@ -55,4 +56,20 @@ public class AccumuloConfigurationTest {
   public void testGetMemoryInBytesFailureCases2() throws Exception {
     AccumuloConfiguration.getMemoryInBytes("FooBar");
   }
+
+  @Test
+  public void testGetPropertyByString() {
+    AccumuloConfiguration c = AccumuloConfiguration.getDefaultConfiguration();
+    boolean found = false;
+    for (Property p : Property.values()) {
+      if (p.getType() != PropertyType.PREFIX) {
+        found = true;
+        // ensure checking by property and by key works the same
+        assertEquals(c.get(p), c.get(p.getKey()));
+        // ensure that getting by key returns the expected value
+        assertEquals(p.getDefaultValue(), c.get(p.getKey()));
+      }
+    }
+    assertTrue("test was a dud, and did nothing", found);
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/27f3b308/server/base/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java
index 69c9af8..a53350b 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java
@@ -65,7 +65,7 @@ public class ZooConfiguration extends AccumuloConfiguration {
     String value = null;
 
     if (Property.isValidZooPropertyKey(key)) {
-      value = get(key);
+      value = getRaw(key);
     }
 
     if (value == null || !property.getType().isValidFormat(value)) {
@@ -94,7 +94,7 @@ public class ZooConfiguration extends AccumuloConfiguration {
     }
   }
 
-  private String get(String key) {
+  private String getRaw(String key) {
     String zPath = ZooUtil.getRoot(instanceId) + Constants.ZCONFIG + "/" + key;
     byte[] v = propCache.get(zPath);
     String value = null;
@@ -111,7 +111,7 @@ public class ZooConfiguration extends AccumuloConfiguration {
     if (children != null) {
       for (String child : children) {
         if (child != null && filter.accept(child)) {
-          String value = get(child);
+          String value = getRaw(child);
           if (value != null)
             props.put(child, value);
         }