diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java index 07958dd0ed0..cdab20c3908 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java @@ -33,6 +33,7 @@ import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil; +import org.apache.accumulo.core.iteratorsImpl.IteratorProperty; public abstract class NamespaceOperationsHelper implements NamespaceOperations { @@ -92,29 +93,25 @@ public IteratorSetting getIteratorSetting(String namespace, String name, Iterato if (!exists(namespace)) { throw new NamespaceNotFoundException(null, namespace, null); } - int priority = -1; - String classname = null; - Map settings = new HashMap<>(); - - String root = - String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name); - String opt = root + ".opt."; - for (Entry property : this.getProperties(namespace)) { - if (property.getKey().equals(root)) { - String[] parts = property.getValue().split(","); - if (parts.length != 2) { - throw new AccumuloException("Bad value for iterator setting: " + property.getValue()); - } - priority = Integer.parseInt(parts[0]); - classname = parts[1]; - } else if (property.getKey().startsWith(opt)) { - settings.put(property.getKey().substring(opt.length()), property.getValue()); + IteratorProperty base = null; + Map options = new HashMap<>(); + for (var prop : this.getConfiguration(namespace).entrySet()) { + IteratorProperty iterProp = IteratorProperty.parse(prop); + if (iterProp == null || iterProp.getScope() != scope || !iterProp.getName().equals(name)) { + continue; + } + if (iterProp.isOption()) { + options.put(iterProp.getOptionKey(), iterProp.getOptionValue()); + } else { + base = iterProp; } } - if (priority <= 0 || classname == null) { + if (base == null) { return null; } - return new IteratorSetting(priority, name, classname, settings); + IteratorSetting setting = base.toSetting(); + options.forEach(setting::addOption); + return setting; } @Override @@ -124,18 +121,13 @@ public Map> listIterators(String namespace) throw new NamespaceNotFoundException(null, namespace, null); } Map> result = new TreeMap<>(); - for (Entry property : this.getProperties(namespace)) { - String name = property.getKey(); - String[] parts = name.split("\\."); - if (parts.length == 4) { - if (parts[0].equals("table") && parts[1].equals("iterator")) { - IteratorScope scope = IteratorScope.valueOf(parts[2]); - if (!result.containsKey(parts[3])) { - result.put(parts[3], EnumSet.noneOf(IteratorScope.class)); - } - result.get(parts[3]).add(scope); - } + for (var prop : this.getConfiguration(namespace).entrySet()) { + IteratorProperty iterProp = IteratorProperty.parse(prop); + if (iterProp == null || iterProp.isOption()) { + continue; } + result.computeIfAbsent(iterProp.getName(), k -> EnumSet.noneOf(IteratorScope.class)) + .add(iterProp.getScope()); } return result; } diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java index 70a43b0e314..19464c64468 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java @@ -36,6 +36,7 @@ import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil; +import org.apache.accumulo.core.iteratorsImpl.IteratorProperty; public abstract class TableOperationsHelper implements TableOperations { @@ -84,34 +85,30 @@ public void removeIterator(String tableName, String name, EnumSet @Override public IteratorSetting getIteratorSetting(String tableName, String name, IteratorScope scope) - throws AccumuloSecurityException, AccumuloException, TableNotFoundException { + throws AccumuloException, TableNotFoundException { EXISTING_TABLE_NAME.validate(tableName); checkArgument(name != null, "name is null"); checkArgument(scope != null, "scope is null"); - int priority = -1; - String classname = null; - Map settings = new HashMap<>(); - - String root = - String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name); - String opt = root + ".opt."; - for (Entry property : this.getProperties(tableName)) { - if (property.getKey().equals(root)) { - String[] parts = property.getValue().split(","); - if (parts.length != 2) { - throw new AccumuloException("Bad value for iterator setting: " + property.getValue()); - } - priority = Integer.parseInt(parts[0]); - classname = parts[1]; - } else if (property.getKey().startsWith(opt)) { - settings.put(property.getKey().substring(opt.length()), property.getValue()); + IteratorProperty base = null; + Map options = new HashMap<>(); + for (var prop : this.getConfiguration(tableName).entrySet()) { + IteratorProperty iterProp = IteratorProperty.parse(prop); + if (iterProp == null || iterProp.getScope() != scope || !iterProp.getName().equals(name)) { + continue; + } + if (iterProp.isOption()) { + options.put(iterProp.getOptionKey(), iterProp.getOptionValue()); + } else { + base = iterProp; } } - if (priority <= 0 || classname == null) { + if (base == null) { return null; } - return new IteratorSetting(priority, name, classname, settings); + IteratorSetting setting = base.toSetting(); + options.forEach(setting::addOption); + return setting; } @Override @@ -120,18 +117,13 @@ public Map> listIterators(String tableName) EXISTING_TABLE_NAME.validate(tableName); Map> result = new TreeMap<>(); - for (Entry property : this.getProperties(tableName)) { - String name = property.getKey(); - String[] parts = name.split("\\."); - if (parts.length == 4) { - if (parts[0].equals("table") && parts[1].equals("iterator")) { - IteratorScope scope = IteratorScope.valueOf(parts[2]); - if (!result.containsKey(parts[3])) { - result.put(parts[3], EnumSet.noneOf(IteratorScope.class)); - } - result.get(parts[3]).add(scope); - } + for (var prop : this.getConfiguration(tableName).entrySet()) { + IteratorProperty iterProp = IteratorProperty.parse(prop); + if (iterProp == null || iterProp.isOption()) { + continue; } + result.computeIfAbsent(iterProp.getName(), k -> EnumSet.noneOf(IteratorScope.class)) + .add(iterProp.getScope()); } return result; } diff --git a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java index 20120b4b6c5..88ffdcd8174 100644 --- a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java +++ b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java @@ -113,9 +113,7 @@ public IteratorSetting toSetting() { } private static void check(boolean b, String property, String value) { - if (!b) { - throw new IllegalArgumentException("Illegal iterator property: " + property + "=" + value); - } + Preconditions.checkArgument(b, "Illegal iterator property: %s=%s", property, value); } @Override @@ -140,19 +138,26 @@ public static IteratorProperty parse(String property, String value) { return null; } - String[] iterPropParts = property.split("\\."); + String[] iterPropParts = property.split("\\.", -1); check(iterPropParts.length == 4 || iterPropParts.length == 6, property, value); IteratorUtil.IteratorScope scope = IteratorUtil.IteratorScope.valueOf(iterPropParts[2]); String iterName = iterPropParts[3]; + check(!iterName.isEmpty(), property, value); if (iterPropParts.length == 4) { - String[] valTokens = value.split(","); + String[] valTokens = value.split(",", -1); check(valTokens.length == 2, property, value); - return new IteratorProperty(iterName, scope, Integer.parseInt(valTokens[0]), valTokens[1], - property, value); + String prioStr = valTokens[0]; + String className = valTokens[1]; + check(!className.isEmpty(), property, value); + int priority = Integer.parseInt(prioStr); + check(priority > 0, property, value); + return new IteratorProperty(iterName, scope, priority, className, property, value); } else if (iterPropParts.length == 6) { check(iterPropParts[4].equals("opt"), property, value); - return new IteratorProperty(iterName, scope, iterPropParts[5], value, property, value); + String optionName = iterPropParts[5]; + check(!optionName.isEmpty(), property, value); + return new IteratorProperty(iterName, scope, optionName, value, property, value); } else { throw new IllegalArgumentException("Illegal iterator property: " + property + "=" + value); }