Search in sources :

Example 21 with IteratorScope

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.getAccumuloClient().namespaceOperations().testClassLoad(namespace, classname, SortedKeyValueIterator.class.getName())) {
        throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + classname + " as type " + SortedKeyValueIterator.class.getName());
    }
    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().namespaceOperations().attachIterator(namespace, setting, scopes);
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ShellCommandException(org.apache.accumulo.shell.ShellCommandException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)

Example 22 with IteratorScope

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 {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        TableOperations tops = client.tableOperations();
        Map<String, EnumSet<IteratorScope>> iterators = tops.listIterators(MetadataTable.NAME);
        assertTrue(iterators.containsKey(ReplicationTableUtil.COMBINER_NAME));
        EnumSet<IteratorScope> scopes = iterators.get(ReplicationTableUtil.COMBINER_NAME);
        assertEquals(3, scopes.size());
        assertTrue(scopes.contains(IteratorScope.scan));
        assertTrue(scopes.contains(IteratorScope.minc));
        assertTrue(scopes.contains(IteratorScope.majc));
        Map<String, String> config = tops.getConfiguration(MetadataTable.NAME);
        Map<String, String> properties = Map.copyOf(config);
        for (IteratorScope scope : scopes) {
            String key = Property.TABLE_ITERATOR_PREFIX.getKey() + scope.name() + "." + ReplicationTableUtil.COMBINER_NAME + ".opt.columns";
            assertTrue(properties.containsKey(key), "Properties did not contain key : " + key);
            assertEquals(ReplicationSection.COLF.toString(), properties.get(key));
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) EnumSet(java.util.EnumSet) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.jupiter.api.Test)

Example 23 with IteratorScope

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;
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)

Example 24 with IteratorScope

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.getAccumuloClient().namespaceOperations().listIterators(OptUtil.getNamespaceOpt(cl, shellState));
    } else if (tables) {
        iterators = shellState.getAccumuloClient().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.getAccumuloClient().namespaceOperations().getIteratorSetting(OptUtil.getNamespaceOpt(cl, shellState), name, scope);
                } else if (tables) {
                    setting = shellState.getAccumuloClient().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.getWriter().println(sb);
    return 0;
}
Also used : EnumSet(java.util.EnumSet) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashSet(java.util.HashSet)

Example 25 with IteratorScope

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());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) EnumSet(java.util.EnumSet) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.jupiter.api.Test)

Aggregations

IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)48 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)18 EnumSet (java.util.EnumSet)13 TreeMap (java.util.TreeMap)11 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)4 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)4 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)4 HashSet (java.util.HashSet)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 KeepCountOnlyUidAggregator (datawave.ingest.table.aggregator.KeepCountOnlyUidAggregator)2 ShardIndexKeyFunctor (datawave.ingest.table.bloomfilter.ShardIndexKeyFunctor)2 Map (java.util.Map)2 Column (org.apache.accumulo.core.client.IteratorSetting.Column)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)2 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)2 Range (org.apache.accumulo.core.data.Range)2