use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class StatusCombinerMacIT method testCombinerSetOnMetadata.
@Test
public void testCombinerSetOnMetadata() throws Exception {
TableOperations tops = getConnector().tableOperations();
Map<String, EnumSet<IteratorScope>> iterators = tops.listIterators(MetadataTable.NAME);
Assert.assertTrue(iterators.containsKey(ReplicationTableUtil.COMBINER_NAME));
EnumSet<IteratorScope> scopes = iterators.get(ReplicationTableUtil.COMBINER_NAME);
Assert.assertEquals(3, scopes.size());
Assert.assertTrue(scopes.contains(IteratorScope.scan));
Assert.assertTrue(scopes.contains(IteratorScope.minc));
Assert.assertTrue(scopes.contains(IteratorScope.majc));
Iterable<Entry<String, String>> propIter = tops.getProperties(MetadataTable.NAME);
HashMap<String, String> properties = new HashMap<>();
for (Entry<String, String> entry : propIter) {
properties.put(entry.getKey(), entry.getValue());
}
for (IteratorScope scope : scopes) {
String key = Property.TABLE_ITERATOR_PREFIX.getKey() + scope.name() + "." + ReplicationTableUtil.COMBINER_NAME + ".opt.columns";
Assert.assertTrue("Properties did not contain key : " + key, properties.containsKey(key));
Assert.assertEquals(MetadataSchema.ReplicationSection.COLF.toString(), properties.get(key));
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class SetIterCommand method setNamespaceProperties.
protected void setNamespaceProperties(final CommandLine cl, final Shell shellState, final int priority, final Map<String, String> options, final String classname, final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException, NamespaceNotFoundException {
// remove empty values
final String namespace = OptUtil.getNamespaceOpt(cl, shellState);
if (!shellState.getConnector().namespaceOperations().testClassLoad(namespace, classname, SortedKeyValueIterator.class.getName())) {
throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + classname + " as type " + SortedKeyValueIterator.class.getName());
}
final String aggregatorClass = options.get("aggregatorClass");
@SuppressWarnings("deprecation") String deprecatedAggregatorClassName = org.apache.accumulo.core.iterators.aggregation.Aggregator.class.getName();
if (aggregatorClass != null && !shellState.getConnector().namespaceOperations().testClassLoad(namespace, aggregatorClass, deprecatedAggregatorClassName)) {
throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + aggregatorClass + " as type " + deprecatedAggregatorClassName);
}
for (Iterator<Entry<String, String>> i = options.entrySet().iterator(); i.hasNext(); ) {
final Entry<String, String> entry = i.next();
if (entry.getValue() == null || entry.getValue().isEmpty()) {
i.remove();
}
}
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.getConnector().namespaceOperations().attachIterator(namespace, setting, scopes);
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class ListIterCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty();
boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt());
final Map<String, EnumSet<IteratorScope>> iterators;
if (namespaces) {
iterators = shellState.getConnector().namespaceOperations().listIterators(OptUtil.getNamespaceOpt(cl, shellState));
} else if (tables) {
iterators = shellState.getConnector().tableOperations().listIterators(OptUtil.getTableOpt(cl, shellState));
} else {
throw new IllegalArgumentException("No table or namespace specified");
}
if (cl.hasOption(nameOpt.getOpt())) {
final String name = cl.getOptionValue(nameOpt.getOpt());
if (!iterators.containsKey(name)) {
Shell.log.warn("no iterators found that match your criteria");
return 0;
}
final EnumSet<IteratorScope> scopes = iterators.get(name);
iterators.clear();
iterators.put(name, scopes);
}
final boolean allScopes = cl.hasOption(allScopesOpt.getOpt());
Set<IteratorScope> desiredScopes = new HashSet<>();
for (IteratorScope scope : IteratorScope.values()) {
if (allScopes || cl.hasOption(scopeOpts.get(scope).getOpt()))
desiredScopes.add(scope);
}
if (desiredScopes.isEmpty()) {
throw new IllegalArgumentException("You must select at least one scope to configure");
}
final StringBuilder sb = new StringBuilder("-\n");
for (Entry<String, EnumSet<IteratorScope>> entry : iterators.entrySet()) {
final String name = entry.getKey();
final EnumSet<IteratorScope> scopes = entry.getValue();
for (IteratorScope scope : scopes) {
if (desiredScopes.contains(scope)) {
IteratorSetting setting;
if (namespaces) {
setting = shellState.getConnector().namespaceOperations().getIteratorSetting(OptUtil.getNamespaceOpt(cl, shellState), name, scope);
} else if (tables) {
setting = shellState.getConnector().tableOperations().getIteratorSetting(OptUtil.getTableOpt(cl, shellState), name, scope);
} else {
throw new IllegalArgumentException("No table or namespace specified");
}
sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope).append(" scope options:\n");
sb.append("- ").append("iteratorPriority").append(" = ").append(setting.getPriority()).append("\n");
sb.append("- ").append("iteratorClassName").append(" = ").append(setting.getIteratorClass()).append("\n");
for (Entry<String, String> optEntry : setting.getOptions().entrySet()) {
sb.append("- ").append(optEntry.getKey()).append(" = ").append(optEntry.getValue()).append("\n");
}
}
}
}
sb.append("-");
shellState.getReader().println(sb.toString());
return 0;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class MockNamespacesTest method testNamespaceIterators.
/**
* This tests adding iterators to a namespace, listing them, and removing them
*/
@Test
public void testNamespaceIterators() throws Exception {
String namespace = "iterator";
String tableName = namespace + ".table";
String iter = "thing";
conn.namespaceOperations().create(namespace);
conn.tableOperations().create(tableName);
IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
HashSet<IteratorScope> scope = new HashSet<>();
scope.add(IteratorScope.scan);
conn.namespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m = new Mutation("r");
m.put("a", "b", new Value("abcde".getBytes(UTF_8)));
bw.addMutation(m);
bw.flush();
Scanner s = conn.createScanner(tableName, Authorizations.EMPTY);
System.out.println(s.iterator().next());
// do scanners work correctly in mock?
// assertTrue(!s.iterator().hasNext());
assertTrue(conn.namespaceOperations().listIterators(namespace).containsKey(iter));
conn.namespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
}
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.size() == 0)
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];
// extraneous spacing in the iterator profile argument list causing the parser to read a scope 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);
}
// handle case where only the profile is supplied. Use all scopes by default if no scope args 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;
}
Aggregations