Search in sources :

Example 11 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.Test)

Example 12 with IteratorScope

use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.

the class NamespaceOperationsHelper method listIterators.

@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
    if (!exists(namespace))
        throw new NamespaceNotFoundException(null, namespace, null);
    Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
    for (Entry<String, String> property : this.getProperties(namespace)) {
        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) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 13 with IteratorScope

use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.

the class NamespaceOperationsHelper method checkIteratorConflicts.

@Override
public void checkIteratorConflicts(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException {
    if (!exists(namespace))
        throw new NamespaceNotFoundException(null, namespace, null);
    for (IteratorScope scope : scopes) {
        String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
        String nameStr = String.format("%s.%s", scopeStr, setting.getName());
        String optStr = String.format("%s.opt.", nameStr);
        Map<String, String> optionConflicts = new TreeMap<>();
        for (Entry<String, String> property : this.getProperties(namespace)) {
            if (property.getKey().startsWith(scopeStr)) {
                if (property.getKey().equals(nameStr))
                    throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue()));
                if (property.getKey().startsWith(optStr))
                    optionConflicts.put(property.getKey(), property.getValue());
                if (property.getKey().contains(".opt."))
                    continue;
                String[] parts = property.getValue().split(",");
                if (parts.length != 2)
                    throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
                try {
                    if (Integer.parseInt(parts[0]) == setting.getPriority())
                        throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
                } catch (NumberFormatException e) {
                    throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
                }
            }
        }
        if (!optionConflicts.isEmpty())
            throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TreeMap(java.util.TreeMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 14 with IteratorScope

use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.

the class NamespaceOperationsHelper method checkIteratorConflicts.

@Override
public void checkIteratorConflicts(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException {
    if (!exists(namespace))
        throw new NamespaceNotFoundException(null, namespace, null);
    for (IteratorScope scope : scopes) {
        String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
        String nameStr = String.format("%s.%s", scopeStr, setting.getName());
        String optStr = String.format("%s.opt.", nameStr);
        Map<String, String> optionConflicts = new TreeMap<>();
        for (Entry<String, String> property : this.getProperties(namespace)) {
            if (property.getKey().startsWith(scopeStr)) {
                if (property.getKey().equals(nameStr))
                    throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue()));
                if (property.getKey().startsWith(optStr))
                    optionConflicts.put(property.getKey(), property.getValue());
                if (property.getKey().contains(".opt."))
                    continue;
                String[] parts = property.getValue().split(",");
                if (parts.length != 2)
                    throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
                try {
                    if (Integer.parseInt(parts[0]) == setting.getPriority())
                        throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
                } catch (NumberFormatException e) {
                    throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
                }
            }
        }
        if (optionConflicts.size() > 0)
            throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TreeMap(java.util.TreeMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 15 with IteratorScope

use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.

the class NamespaceOperationsHelper method listIterators.

@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
    if (!exists(namespace))
        throw new NamespaceNotFoundException(null, namespace, null);
    Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
    for (Entry<String, String> property : this.getProperties(namespace)) {
        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) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

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