This is an automated email from the ASF dual-hosted git repository.

dlmarion pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new fb3aeb9613 Provide getProperties method on Configuration that does not 
filter (#2834)
fb3aeb9613 is described below

commit fb3aeb961393023d6a652d3f51be2e42ec2d1134
Author: Dave Marion <dlmar...@apache.org>
AuthorDate: Mon Aug 8 11:14:53 2022 -0400

    Provide getProperties method on Configuration that does not filter (#2834)
    
    Added a getProperties method that can be used to retrieve properties
    using their name or to get all properties. The getProperties method
    which takes a filter is useful, but inefficient when you don't need a 
filter.
---
 .../core/clientImpl/ClientConfConverter.java        | 11 +++++++++++
 .../accumulo/core/conf/AccumuloConfiguration.java   | 21 +++++++++++++++++----
 .../accumulo/core/conf/ConfigurationCopy.java       | 14 ++++++++++++++
 .../accumulo/core/conf/DefaultConfiguration.java    | 14 ++++++++++++++
 .../accumulo/core/conf/SiteConfiguration.java       | 11 +++++++++++
 .../core/conf/AccumuloConfigurationTest.java        | 13 +++++++++++++
 .../accumulo/server/conf/ZooBasedConfiguration.java | 12 ++++++++++++
 .../server/conf/ServerConfigurationFactoryTest.java |  5 ++---
 8 files changed, 94 insertions(+), 7 deletions(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientConfConverter.java
 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientConfConverter.java
index f7792468bb..ae954a3d0e 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientConfConverter.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientConfConverter.java
@@ -202,6 +202,17 @@ public class ClientConfConverter {
         }
       }
 
+      @Override
+      public void getProperties(Map<String,String> props, String... 
properties) {
+        defaults.getProperties(props, properties);
+        for (String p : properties) {
+          String value = config.getString(p);
+          if (value != null) {
+            props.put(p, value);
+          }
+        }
+      }
+
       @Override
       public void getProperties(Map<String,String> props, Predicate<String> 
filter) {
         defaults.getProperties(props, filter);
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 dce79bcf98..af41a7a846 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
@@ -26,7 +26,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.OptionalInt;
 import java.util.TreeMap;
@@ -73,6 +72,7 @@ public abstract class AccumuloConfiguration implements 
Iterable<Entry<String,Str
    *
    * <p>
    * Note: this is inefficient, but convenient on occasion. For retrieving 
multiple properties, use
+   * {@link #getProperties(Map, String...)} if the property names are known or
    * {@link #getProperties(Map, Predicate)} with a custom filter.
    *
    * @param property
@@ -81,7 +81,7 @@ public abstract class AccumuloConfiguration implements 
Iterable<Entry<String,Str
    */
   public String get(String property) {
     Map<String,String> propMap = new HashMap<>(1);
-    getProperties(propMap, key -> Objects.equals(property, key));
+    getProperties(propMap, property);
     return propMap.get(property);
   }
 
@@ -119,11 +119,25 @@ public abstract class AccumuloConfiguration implements 
Iterable<Entry<String,Str
         : 
Stream.of(deprecated).filter(this::isPropertySet).findFirst().orElse(property);
   }
 
+  /**
+   * Returns property key/value pairs in this configuration and parent 
configuration.
+   *
+   * @param props
+   *          properties object to populate
+   * @param properties
+   *          property key/values to copy to the props map. Copies all 
properties if null.
+   */
+  public abstract void getProperties(Map<String,String> props, String... 
properties);
+
   /**
    * Returns property key/value pairs in this configuration. The pairs include 
those defined in this
    * configuration which pass the given filter, and those supplied from the 
parent configuration
    * which are not included from here.
    *
+   * <p>
+   * Note: this is inefficient for retrieving fully-qualified properties, use
+   * {@link #getProperties(Map, String...)} instead.
+   *
    * @param props
    *          properties object to populate
    * @param filter
@@ -139,9 +153,8 @@ public abstract class AccumuloConfiguration implements 
Iterable<Entry<String,Str
    */
   @Override
   public Iterator<Entry<String,String>> iterator() {
-    Predicate<String> all = x -> true;
     TreeMap<String,String> entries = new TreeMap<>();
-    getProperties(entries, all);
+    getProperties(entries);
     return entries.entrySet().iterator();
   }
 
diff --git 
a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java 
b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
index 221934c7c2..9f176e9bdf 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
@@ -75,6 +75,20 @@ public class ConfigurationCopy extends AccumuloConfiguration 
{
     return copy.get(property.getKey());
   }
 
+  @Override
+  public void getProperties(Map<String,String> props, String... properties) {
+    if (properties == null || properties.length == 0) {
+      props.putAll(copy);
+    } else {
+      for (String p : properties) {
+        String value = copy.get(p);
+        if (value != null) {
+          props.put(p, value);
+        }
+      }
+    }
+  }
+
   @Override
   public void getProperties(Map<String,String> props, Predicate<String> 
filter) {
     for (Entry<String,String> entry : copy.entrySet()) {
diff --git 
a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java 
b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
index 2c3abca0f1..9bdc617085 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
@@ -54,6 +54,20 @@ public class DefaultConfiguration extends 
AccumuloConfiguration {
     return resolvedProps.get(property.getKey());
   }
 
+  @Override
+  public void getProperties(Map<String,String> props, String... properties) {
+    if (properties == null || properties.length == 0) {
+      props.putAll(resolvedProps);
+    } else {
+      for (String p : properties) {
+        String value = resolvedProps.get(p);
+        if (value != null) {
+          props.put(p, value);
+        }
+      }
+    }
+  }
+
   @Override
   public void getProperties(Map<String,String> props, Predicate<String> 
filter) {
     resolvedProps.entrySet().stream().filter(p -> filter.test(p.getKey()))
diff --git 
a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java 
b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
index c20aab006b..bd6727164e 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
@@ -261,6 +261,17 @@ public class SiteConfiguration extends 
AccumuloConfiguration {
     return config.containsKey(prop.getKey()) || parent.isPropertySet(prop);
   }
 
+  @Override
+  public void getProperties(Map<String,String> props, String... properties) {
+    parent.getProperties(props, properties);
+    for (String p : properties) {
+      String value = config.get(p);
+      if (value != null) {
+        props.put(p, value);
+      }
+    }
+  }
+
   @Override
   public void getProperties(Map<String,String> props, Predicate<String> 
filter) {
     getProperties(props, filter, true);
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 9c829c35ab..d6a0cf927e 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
@@ -173,6 +173,19 @@ public class AccumuloConfigurationTest {
       return v;
     }
 
+    @Override
+    public void getProperties(Map<String,String> props, String... properties) {
+      if (parent != null) {
+        parent.getProperties(props, properties);
+      }
+      for (String p : properties) {
+        String value = props.get(p);
+        if (value != null) {
+          props.put(p, value);
+        }
+      }
+    }
+
     @Override
     public void getProperties(Map<String,String> output, Predicate<String> 
filter) {
       if (parent != null) {
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/conf/ZooBasedConfiguration.java
 
b/server/base/src/main/java/org/apache/accumulo/server/conf/ZooBasedConfiguration.java
index 15126c806a..1a6ae5077b 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/conf/ZooBasedConfiguration.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/conf/ZooBasedConfiguration.java
@@ -121,6 +121,18 @@ public class ZooBasedConfiguration extends 
AccumuloConfiguration {
     return null;
   }
 
+  @Override
+  public void getProperties(Map<String,String> props, String... properties) {
+    parent.getProperties(props, properties);
+    Map<String,String> theseProps = getSnapshot();
+    for (String p : properties) {
+      String value = theseProps.get(p);
+      if (value != null) {
+        props.put(p, value);
+      }
+    }
+  }
+
   @Override
   public void getProperties(final Map<String,String> props, final 
Predicate<String> filter) {
 
diff --git 
a/server/base/src/test/java/org/apache/accumulo/server/conf/ServerConfigurationFactoryTest.java
 
b/server/base/src/test/java/org/apache/accumulo/server/conf/ServerConfigurationFactoryTest.java
index 71e13cda8a..d1ed1671d0 100644
--- 
a/server/base/src/test/java/org/apache/accumulo/server/conf/ServerConfigurationFactoryTest.java
+++ 
b/server/base/src/test/java/org/apache/accumulo/server/conf/ServerConfigurationFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.accumulo.server.conf;
 
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
@@ -74,9 +75,7 @@ public class ServerConfigurationFactoryTest {
     propStore.registerAsListener(anyObject(), anyObject());
     expectLastCall().anyTimes();
 
-    sysConfig = createMock(SystemConfiguration.class);
-    sysConfig.getProperties(anyObject(), anyObject());
-    expectLastCall().anyTimes();
+    sysConfig = createNiceMock(SystemConfiguration.class);
 
     context = createMock(ServerContext.class);
     expect(context.getZooKeeperRoot()).andReturn("/accumulo/" + 
IID).anyTimes();

Reply via email to