use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class ReplicationIT method verifyReplicationTableConfig.
@Test
public void verifyReplicationTableConfig() throws AccumuloException, TableNotFoundException, AccumuloSecurityException {
try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
TableOperations tops = client.tableOperations();
Map<String, EnumSet<IteratorScope>> iterators = tops.listIterators(ReplicationTable.NAME);
// verify combiners are only iterators (no versioning)
assertEquals(1, iterators.size());
// look for combiner
assertTrue(iterators.containsKey(ReplicationTable.COMBINER_NAME));
assertTrue(iterators.get(ReplicationTable.COMBINER_NAME).containsAll(EnumSet.allOf(IteratorScope.class)));
for (IteratorScope scope : EnumSet.allOf(IteratorScope.class)) {
IteratorSetting is = tops.getIteratorSetting(ReplicationTable.NAME, ReplicationTable.COMBINER_NAME, scope);
assertEquals(30, is.getPriority());
assertEquals(StatusCombiner.class.getName(), is.getIteratorClass());
assertEquals(1, is.getOptions().size());
assertTrue(is.getOptions().containsKey("columns"));
String cols = is.getOptions().get("columns");
Column statusSectionCol = new Column(StatusSection.NAME);
Column workSectionCol = new Column(WorkSection.NAME);
assertEquals(ColumnSet.encodeColumns(statusSectionCol.getColumnFamily(), statusSectionCol.getColumnQualifier()) + "," + ColumnSet.encodeColumns(workSectionCol.getColumnFamily(), workSectionCol.getColumnQualifier()), cols);
}
boolean foundLocalityGroups = false;
boolean foundLocalityGroupDef1 = false;
boolean foundLocalityGroupDef2 = false;
boolean foundFormatter = false;
var joiner = Collectors.joining(",");
for (Entry<String, String> p : tops.getProperties(ReplicationTable.NAME)) {
String key = p.getKey();
String val = p.getValue();
// STATUS_LG_NAME, STATUS_LG_COLFAMS, WORK_LG_NAME, WORK_LG_COLFAMS
if (key.equals(Property.TABLE_FORMATTER_CLASS.getKey()) && val.equals(StatusFormatter.class.getName())) {
// look for formatter
foundFormatter = true;
} else if (key.equals(Property.TABLE_LOCALITY_GROUPS.getKey()) && val.equals(ReplicationTable.LOCALITY_GROUPS.keySet().stream().collect(joiner))) {
// look for locality groups enabled
foundLocalityGroups = true;
} else if (key.startsWith(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey())) {
// look for locality group column family definitions
if (key.equals(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey() + ReplicationTable.STATUS_LG_NAME) && val.equals(ReplicationTable.STATUS_LG_COLFAMS.stream().map(Text::toString).collect(joiner))) {
foundLocalityGroupDef1 = true;
} else if (key.equals(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey() + ReplicationTable.WORK_LG_NAME) && val.equals(ReplicationTable.WORK_LG_COLFAMS.stream().map(Text::toString).collect(joiner))) {
foundLocalityGroupDef2 = true;
}
}
}
assertTrue(foundLocalityGroups);
assertTrue(foundLocalityGroupDef1);
assertTrue(foundLocalityGroupDef2);
assertTrue(foundFormatter);
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class IteratorConfigUtil 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;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NewTableConfiguration method attachIterator.
/**
* Configure iterator settings for a table prior to its creation.
*
* @param setting
* object specifying the properties of the iterator
* @param scopes
* enumerated set of iterator scopes
*
* @since 2.0.0
*
* @see TableOperations#attachIterator(String, IteratorSetting, EnumSet)
*/
public NewTableConfiguration attachIterator(IteratorSetting setting, EnumSet<IteratorScope> scopes) {
Objects.requireNonNull(setting, "setting cannot be null!");
Objects.requireNonNull(scopes, "scopes cannot be null!");
try {
TableOperationsHelper.checkIteratorConflicts(iteratorProps, setting, scopes);
} catch (AccumuloException e) {
throw new IllegalArgumentException("The specified IteratorSetting" + " conflicts with an iterator already defined on this NewTableConfiguration", e);
}
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()) {
iteratorProps.put(root + ".opt." + prop.getKey(), prop.getValue());
}
iteratorProps.put(root, setting.getPriority() + "," + setting.getIteratorClass());
// verify that the iteratorProps assigned and the properties do not share any keys.
checkDisjoint(properties, iteratorProps, "iterator");
}
return this;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class SetIterCommand method setTableProperties.
protected void setTableProperties(final CommandLine cl, final Shell shellState, final int priority, final Map<String, String> options, final String classname, final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException {
// remove empty values
final String tableName = OptUtil.getTableOpt(cl, shellState);
ScanCommand.ensureTserversCanLoadIterator(shellState, tableName, classname);
options.values().removeIf(v -> v == null || v.isEmpty());
final EnumSet<IteratorScope> scopes = EnumSet.noneOf(IteratorScope.class);
if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(mincScopeOpt.getOpt())) {
scopes.add(IteratorScope.minc);
}
if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(majcScopeOpt.getOpt())) {
scopes.add(IteratorScope.majc);
}
if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(scanScopeOpt.getOpt())) {
scopes.add(IteratorScope.scan);
}
if (scopes.isEmpty()) {
throw new IllegalArgumentException("You must select at least one scope to configure");
}
final IteratorSetting setting = new IteratorSetting(priority, name, classname, options);
shellState.getAccumuloClient().tableOperations().attachIterator(tableName, setting, scopes);
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method attachIterator.
@Override
public void attachIterator(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
checkIteratorConflicts(namespace, 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(namespace, root + ".opt." + prop.getKey(), prop.getValue());
}
this.setProperty(namespace, root, setting.getPriority() + "," + setting.getIteratorClass());
}
}
Aggregations