use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class CreateTableCommand method attachIteratorToNewTable.
/**
* Add supplied iterator information to NewTableConfiguration object.
*
* Used in conjunction with createtable shell command to allow an iterator to be configured upon
* table creation.
*/
private NewTableConfiguration attachIteratorToNewTable(final CommandLine cl, final Shell shellState, NewTableConfiguration ntc) {
EnumSet<IteratorScope> scopeEnumSet;
IteratorSetting iteratorSetting;
if (shellState.iteratorProfiles.isEmpty())
throw new IllegalArgumentException("No shell iterator profiles have been created.");
String[] options = cl.getOptionValues(createTableOptIteratorProps.getOpt());
for (String profileInfo : options) {
String[] parts = profileInfo.split(":", 2);
String profileName = parts[0];
// as a profile.
try {
iteratorSetting = shellState.iteratorProfiles.get(profileName).get(0);
} catch (NullPointerException ex) {
throw new IllegalArgumentException("invalid iterator argument. Either" + " profile does not exist or unexpected spaces in argument list.", ex);
}
// are provided.
if (parts.length == 1) {
// add all scopes to enum set
scopeEnumSet = EnumSet.allOf(IteratorScope.class);
} else {
// user provided scope arguments exist, parse them
List<String> scopeArgs = Arrays.asList(parts[1].split(","));
// there are only three allowable scope values
if (scopeArgs.size() > 3)
throw new IllegalArgumentException("Too many scope arguments supplied");
// if 'all' is used, it should be the only scope provided
if (scopeArgs.contains("all")) {
if (scopeArgs.size() > 1)
throw new IllegalArgumentException("Cannot use 'all' in conjunction with other scopes");
scopeEnumSet = EnumSet.allOf(IteratorScope.class);
} else {
// 'all' is not involved, examine the scope arguments and populate iterator scope EnumSet
scopeEnumSet = validateScopes(scopeArgs);
}
}
ntc.attachIterator(iteratorSetting, scopeEnumSet);
}
return ntc;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class TableOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String tableName) throws AccumuloException, TableNotFoundException {
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);
}
}
}
return result;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class TableOperationsHelper method removeIterator.
@Override
public void removeIterator(String tableName, String name, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
EXISTING_TABLE_NAME.validate(tableName);
Map<String, String> copy = Map.copyOf(this.getConfiguration(tableName));
for (IteratorScope scope : scopes) {
String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
for (Entry<String, String> property : copy.entrySet()) {
if (property.getKey().equals(root) || property.getKey().startsWith(root + ".opt."))
this.removeProperty(tableName, property.getKey());
}
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class TableOperationsHelper method attachIterator.
@Override
public void attachIterator(String tableName, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
EXISTING_TABLE_NAME.validate(tableName);
checkArgument(setting != null, "setting is null");
checkArgument(scopes != null, "scopes is null");
checkIteratorConflicts(tableName, setting, scopes);
for (IteratorScope scope : scopes) {
String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), setting.getName());
for (Entry<String, String> prop : setting.getOptions().entrySet()) {
this.setProperty(tableName, root + ".opt." + prop.getKey(), prop.getValue());
}
this.setProperty(tableName, root, setting.getPriority() + "," + setting.getIteratorClass());
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class IterConfigUtil method generateInitialTableProperties.
/**
* Generate the initial (default) properties for a table
*
* @param limitVersion
* include a VersioningIterator at priority 20 that retains a single version of a given
* K/V pair.
* @return A map of Table properties
*/
public static Map<String, String> generateInitialTableProperties(boolean limitVersion) {
TreeMap<String, String> props = new TreeMap<>();
if (limitVersion) {
for (IteratorScope iterScope : IteratorScope.values()) {
props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers", "20," + VersioningIterator.class.getName());
props.put(Property.TABLE_ITERATOR_PREFIX + iterScope.name() + ".vers.opt.maxVersions", "1");
}
}
props.put(Property.TABLE_CONSTRAINT_PREFIX + "1", DefaultKeySizeConstraint.class.getName());
return props;
}
Aggregations