Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -92,29 +93,26 @@ public IteratorSetting getIteratorSetting(String namespace, String name, Iterato
if (!exists(namespace)) {
throw new NamespaceNotFoundException(null, namespace, null);
}
int priority = -1;
String classname = null;
Map<String,String> settings = new HashMap<>();

String root =
String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
String opt = root + ".opt.";
for (Entry<String,String> 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());
Map<String,String> properties = Map.copyOf(this.getConfiguration(namespace));
IteratorProperty base = null;
Map<String,String> options = new HashMap<>();
for (Entry<String,String> entry : properties.entrySet()) {
IteratorProperty iterProp = IteratorProperty.parse(entry);
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
Expand All @@ -124,18 +122,14 @@ public Map<String,EnumSet<IteratorScope>> listIterators(String namespace)
throw new NamespaceNotFoundException(null, namespace, null);
}
Map<String,EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String,String> 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);
}
Map<String,String> properties = Map.copyOf(this.getConfiguration(namespace));
for (Entry<String,String> entry : properties.entrySet()) {
IteratorProperty iterProp = IteratorProperty.parse(entry);
if (iterProp == null || iterProp.isOption()) {
continue;
}
result.computeIfAbsent(iterProp.getName(), k -> EnumSet.noneOf(IteratorScope.class))
.add(iterProp.getScope());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -84,34 +85,31 @@ public void removeIterator(String tableName, String name, EnumSet<IteratorScope>

@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<String,String> settings = new HashMap<>();

String root =
String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
String opt = root + ".opt.";
for (Entry<String,String> 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());
Map<String,String> properties = Map.copyOf(this.getConfiguration(tableName));
IteratorProperty base = null;
Map<String,String> options = new HashMap<>();
for (Entry<String,String> entry : properties.entrySet()) {
IteratorProperty iterProp = IteratorProperty.parse(entry);
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
Expand All @@ -120,18 +118,14 @@ public Map<String,EnumSet<IteratorScope>> listIterators(String tableName)
EXISTING_TABLE_NAME.validate(tableName);

Map<String,EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String,String> 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);
}
Map<String,String> properties = Map.copyOf(this.getConfiguration(tableName));
for (Entry<String,String> entry : properties.entrySet()) {
IteratorProperty iterProp = IteratorProperty.parse(entry);
if (iterProp == null || iterProp.isOption()) {
continue;
}
result.computeIfAbsent(iterProp.getName(), k -> EnumSet.noneOf(IteratorScope.class))
.add(iterProp.getScope());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Loading