Search in sources :

Example 31 with IteratorScope

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);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) EnumSet(java.util.EnumSet) Text(org.apache.hadoop.io.Text) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Column(org.apache.accumulo.core.client.IteratorSetting.Column) StatusCombiner(org.apache.accumulo.server.replication.StatusCombiner) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.jupiter.api.Test)

Example 32 with IteratorScope

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;
}
Also used : IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TreeMap(java.util.TreeMap) DefaultKeySizeConstraint(org.apache.accumulo.core.data.constraints.DefaultKeySizeConstraint)

Example 33 with IteratorScope

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

Example 34 with IteratorScope

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

Example 35 with IteratorScope

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

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