EdColeman commented on code in PR #2717:
URL: https://github.com/apache/accumulo/pull/2717#discussion_r877585988


##########
server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java:
##########
@@ -68,6 +69,52 @@ public static void setSystemProperty(ServerContext context, 
String property, Str
     context.getPropStore().putAll(SystemPropKey.of(context), Map.of(property, 
value));
   }
 
+  public static void setSystemProperties(ServerContext context, 
Map<String,String> propertiesMap) {
+    Map<String,String> checkedProperties = new HashMap<>();
+
+    for (Map.Entry<String,String> entry : propertiesMap.entrySet()) {
+      final var original = entry.getKey();
+      var property = entry.getKey();
+      var value = entry.getValue();
+
+      // Retrieve the replacement name for this property, if there is one.
+      // Do this before we check if the name is a valid zookeeper name.
+      property = DeprecatedPropertyUtil.getReplacementName(property,
+          (log, replacement) -> log
+              .warn("{} was deprecated and will be removed in a future 
release;"
+                  + " setting its replacement {} instead", original, 
replacement));
+
+      if (!Property.isValidZooPropertyKey(property)) {
+        IllegalArgumentException iae =
+            new IllegalArgumentException("Zookeeper property is not mutable: " 
+ property);
+        log.debug("Attempted to set zookeeper property.  It is not mutable", 
iae);
+        throw iae;
+      }
+
+      // Find the property taking prefix into account
+      Property foundProp = null;
+      for (Property prop : Property.values()) {
+        if (prop.getType() == PropertyType.PREFIX && 
property.startsWith(prop.getKey())
+            || prop.getKey().equals(property)) {
+          foundProp = prop;
+          break;
+        }
+      }
+
+      if ((foundProp == null || (foundProp.getType() != PropertyType.PREFIX
+          && !foundProp.getType().isValidFormat(value)))) {
+        IllegalArgumentException iae = new IllegalArgumentException(
+            "Ignoring property " + property + " it is either null or in an 
invalid format");
+        log.debug("Attempted to set zookeeper property.  Value is either null 
or invalid", iae);
+        throw iae;
+      }
+
+      checkedProperties.put(property, value);
+    }
+
+    context.getPropStore().putAll(SystemPropKey.of(context), 
checkedProperties);

Review Comment:
   See other comment concerning addOrUpdate instead of a replaceAll for set.  
replaceAll may be appropriate as a second, explicit method, but I think the 
ability to add or modify a subset should be available.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to