use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NewTableConfigurationIT method testPreconfiguredIteratorWithDefaultIterator2.
/**
* Test pre-configuring iterator with default iterator. Configure IteratorSetting values into
* method call.
*/
@Test
public void testPreconfiguredIteratorWithDefaultIterator2() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
ntc.attachIterator(setting);
client.tableOperations().create(tableName, ntc);
Map<String, EnumSet<IteratorScope>> iteratorList = client.tableOperations().listIterators(tableName);
// should count the created iterator plus the default iterator
assertEquals(2, iteratorList.size());
verifyIterators(client, tableName, new String[] { "table.iterator.scan.someName=10,foo.bar" }, true);
client.tableOperations().removeIterator(tableName, "someName", EnumSet.allOf(IteratorScope.class));
verifyIterators(client, tableName, new String[] {}, true);
Map<String, EnumSet<IteratorScope>> iteratorList2 = client.tableOperations().listIterators(tableName);
assertEquals(1, iteratorList2.size());
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
if (!exists(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);
}
}
}
return result;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method checkIteratorConflicts.
@Override
public void checkIteratorConflicts(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException {
if (!exists(namespace))
throw new NamespaceNotFoundException(null, namespace, null);
for (IteratorScope scope : scopes) {
String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
String nameStr = String.format("%s.%s", scopeStr, setting.getName());
String optStr = String.format("%s.opt.", nameStr);
Map<String, String> optionConflicts = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(namespace)) {
if (property.getKey().startsWith(scopeStr)) {
if (property.getKey().equals(nameStr))
throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue()));
if (property.getKey().startsWith(optStr))
optionConflicts.put(property.getKey(), property.getValue());
if (property.getKey().contains(".opt."))
continue;
String[] parts = property.getValue().split(",");
if (parts.length != 2)
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
try {
if (Integer.parseInt(parts[0]) == setting.getPriority())
throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
} catch (NumberFormatException e) {
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
}
}
}
if (!optionConflicts.isEmpty())
throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method checkIteratorConflicts.
@Override
public void checkIteratorConflicts(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException {
if (!exists(namespace))
throw new NamespaceNotFoundException(null, namespace, null);
for (IteratorScope scope : scopes) {
String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
String nameStr = String.format("%s.%s", scopeStr, setting.getName());
String optStr = String.format("%s.opt.", nameStr);
Map<String, String> optionConflicts = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(namespace)) {
if (property.getKey().startsWith(scopeStr)) {
if (property.getKey().equals(nameStr))
throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue()));
if (property.getKey().startsWith(optStr))
optionConflicts.put(property.getKey(), property.getValue());
if (property.getKey().contains(".opt."))
continue;
String[] parts = property.getValue().split(",");
if (parts.length != 2)
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
try {
if (Integer.parseInt(parts[0]) == setting.getPriority())
throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
} catch (NumberFormatException e) {
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
}
}
}
if (optionConflicts.size() > 0)
throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
if (!exists(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);
}
}
}
return result;
}
Aggregations