Search in sources :

Example 6 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 7 with IteratorScope

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

Example 8 with IteratorScope

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

Example 9 with IteratorScope

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

Example 10 with IteratorScope

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

Aggregations

IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)42 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)17 EnumSet (java.util.EnumSet)13 TreeMap (java.util.TreeMap)10 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 Test (org.junit.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 Test (org.junit.jupiter.api.Test)2 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)2