Search in sources :

Example 26 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableOperationsImpl method online.

@Override
public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
    checkArgument(tableName != null, "tableName is null");
    Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
    /**
     * ACCUMULO-4574 if table is already online return without executing fate operation.
     */
    TableState expectedState = Tables.getTableState(context.getInstance(), tableId, true);
    if (expectedState == TableState.ONLINE) {
        if (wait)
            waitForTableStateTransition(tableId, TableState.ONLINE);
        return;
    }
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_ONLINE, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
    if (wait)
        waitForTableStateTransition(tableId, TableState.ONLINE);
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 27 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableOperationsImpl method merge.

@Override
public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    checkArgument(tableName != null, "tableName is null");
    ByteBuffer EMPTY = ByteBuffer.allocate(0);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(UTF_8)), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_MERGE, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
}
Also used : HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Example 28 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project Gaffer by gchq.

the class RowIdAggregatorTest method testAggregatingMultiplePropertySetsAcrossRowIDRange.

private void testAggregatingMultiplePropertySetsAcrossRowIDRange(final AccumuloStore store, final AccumuloElementConverter elementConverter) throws StoreException, RangeFactoryException {
    String visibilityString = "public";
    BatchScanner scanner = null;
    try {
        // Create table
        // (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator).
        TableUtils.createTable(store);
        final Properties properties1 = new Properties();
        properties1.put(AccumuloPropertyNames.COUNT, 1);
        final Properties properties2 = new Properties();
        properties2.put(AccumuloPropertyNames.COUNT, 1);
        final Properties properties3 = new Properties();
        properties3.put(AccumuloPropertyNames.COUNT, 2);
        // Create edge
        final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("2").dest("1").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("B").dest("Z").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 1).property(AccumuloPropertyNames.PROP_2, 1).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 1).build();
        final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("3").dest("8").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        final Edge edge6 = new Edge.Builder().group("BasicEdge2").source("1").dest("5").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        final Edge edge7 = new Edge.Builder().group("BasicEdge2").source("2").dest("6").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        final Edge edge8 = new Edge.Builder().group("BasicEdge2").source("4").dest("8").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        final Edge edge9 = new Edge.Builder().group("BasicEdge2").source("5").dest("9").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
        // Accumulo key
        final Key key = elementConverter.getKeysFromEdge(edge).getFirst();
        final Key key2 = elementConverter.getKeysFromEdge(edge2).getFirst();
        final Key key3 = elementConverter.getKeysFromEdge(edge3).getFirst();
        final Key key4 = elementConverter.getKeysFromEdge(edge6).getFirst();
        final Key key5 = elementConverter.getKeysFromEdge(edge7).getFirst();
        final Key key6 = elementConverter.getKeysFromEdge(edge8).getFirst();
        final Key key7 = elementConverter.getKeysFromEdge(edge9).getFirst();
        // Accumulo values
        final Value value1 = elementConverter.getValueFromProperties(TestGroups.EDGE, properties1);
        final Value value2 = elementConverter.getValueFromProperties(TestGroups.EDGE, properties2);
        final Value value3 = elementConverter.getValueFromProperties(TestGroups.EDGE, properties3);
        final Value value4 = elementConverter.getValueFromProperties(TestGroups.EDGE_2, properties1);
        final Value value5 = elementConverter.getValueFromProperties(TestGroups.EDGE_2, properties2);
        // Create mutation
        final Mutation m1 = new Mutation(key.getRow());
        m1.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), value1);
        final Mutation m2 = new Mutation(key.getRow());
        m2.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), value2);
        final Mutation m3 = new Mutation(key.getRow());
        m3.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), value3);
        final Mutation m4 = new Mutation(key2.getRow());
        m4.put(key2.getColumnFamily(), key2.getColumnQualifier(), new ColumnVisibility(key2.getColumnVisibility()), key2.getTimestamp(), value1);
        final Mutation m5 = new Mutation(key.getRow());
        m5.put(key3.getColumnFamily(), key3.getColumnQualifier(), new ColumnVisibility(key3.getColumnVisibility()), key3.getTimestamp(), value1);
        final Mutation m6 = new Mutation(key4.getRow());
        m6.put(key4.getColumnFamily(), key4.getColumnQualifier(), new ColumnVisibility(key4.getColumnVisibility()), key4.getTimestamp(), value4);
        final Mutation m7 = new Mutation(key5.getRow());
        m7.put(key5.getColumnFamily(), key5.getColumnQualifier(), new ColumnVisibility(key5.getColumnVisibility()), key5.getTimestamp(), value5);
        final Mutation m8 = new Mutation(key6.getRow());
        m8.put(key6.getColumnFamily(), key6.getColumnQualifier(), new ColumnVisibility(key6.getColumnVisibility()), key6.getTimestamp(), value5);
        final Mutation m9 = new Mutation(key7.getRow());
        m9.put(key7.getColumnFamily(), key7.getColumnQualifier(), new ColumnVisibility(key7.getColumnVisibility()), key7.getTimestamp(), value5);
        // Write mutation
        final BatchWriterConfig writerConfig = new BatchWriterConfig();
        writerConfig.setMaxMemory(1000000L);
        writerConfig.setMaxLatency(1000L, TimeUnit.MILLISECONDS);
        writerConfig.setMaxWriteThreads(1);
        final BatchWriter writer = store.getConnection().createBatchWriter(store.getTableName(), writerConfig);
        writer.addMutation(m1);
        writer.addMutation(m2);
        writer.addMutation(m3);
        writer.addMutation(m4);
        writer.addMutation(m5);
        writer.addMutation(m6);
        writer.addMutation(m7);
        writer.addMutation(m8);
        writer.addMutation(m9);
        writer.close();
        // Read data back and check we get one merged element
        final Authorizations authorizations = new Authorizations(visibilityString);
        scanner = store.getConnection().createBatchScanner(store.getTableName(), authorizations, 1000);
        try {
            scanner.addScanIterator(store.getKeyPackage().getIteratorFactory().getRowIDAggregatorIteratorSetting(store, "BasicEdge2"));
        } catch (final IteratorSettingException e) {
            fail(e.getMessage());
        }
        final RangeFactory rangeF = store.getKeyPackage().getRangeFactory();
        final SummariseGroupOverRanges summariseGroupOverRanges = new SummariseGroupOverRanges.Builder().view(new View.Builder().edge("BasicEdge2").entity("BasicEntity").build()).build();
        final Range r = rangeF.getRangeFromPair(new Pair<>(new EntitySeed("1"), new EntitySeed("4")), summariseGroupOverRanges);
        final Range r2 = rangeF.getRangeFromPair(new Pair<>(new EntitySeed("5"), new EntitySeed("5")), summariseGroupOverRanges);
        scanner.setRanges(Arrays.asList(r, r2));
        final Iterator<Entry<Key, Value>> it = scanner.iterator();
        Entry<Key, Value> entry = it.next();
        Element readEdge = elementConverter.getFullElement(entry.getKey(), entry.getValue(), false);
        Edge expectedEdge = new Edge.Builder().group("BasicEdge2").source("4").dest("8").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 5).build();
        expectedEdge.putProperty(AccumuloPropertyNames.COUNT, 3);
        assertEquals(expectedEdge, readEdge);
        assertEquals(5, readEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
        assertEquals(3, readEdge.getProperty(AccumuloPropertyNames.COUNT));
        // Check we get the Result of the second provided range
        assertThat(it).hasNext();
        entry = it.next();
        readEdge = elementConverter.getFullElement(entry.getKey(), entry.getValue(), false);
        expectedEdge = new Edge.Builder().group("BasicEdge2").source("5").dest("9").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.COUNT, 1).build();
        assertEquals(expectedEdge, readEdge);
        // Check no additional rows are found. (For a table of this size we shouldn't see this)
        if (it.hasNext()) {
            fail("Additional row found.");
        }
    } catch (final AccumuloException | TableExistsException | TableNotFoundException e) {
        fail(this.getClass().getSimpleName() + " failed with exception: " + e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Properties(uk.gov.gchq.gaffer.data.element.Properties) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) RangeFactory(uk.gov.gchq.gaffer.accumulostore.key.RangeFactory) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) SummariseGroupOverRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.SummariseGroupOverRanges) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) Range(org.apache.accumulo.core.data.Range) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Value(org.apache.accumulo.core.data.Value) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key)

Example 29 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project Gaffer by gchq.

the class GetElementsWithinSetHandlerTest method setupGraph.

private static void setupGraph(final AccumuloStore store) {
    try {
        // Create table
        // (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator,
        // and sets the age off iterator to age data off after it is more than ageOffTimeInMilliseconds milliseconds old).
        TableUtils.createTable(store);
        final List<Element> data = new ArrayList<>();
        // Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
        final Entity entity = new Entity(TestGroups.ENTITY);
        entity.setVertex("A0");
        entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
        data.add(entity);
        for (int i = 1; i < 100; i++) {
            data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
            data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
            data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 3).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
            data.add(new Entity.Builder().group(TestGroups.ENTITY).vertex("A" + i).property(AccumuloPropertyNames.COUNT, i).build());
        }
        final User user = new User();
        addElements(data, user, store);
    } catch (final TableExistsException | StoreException e) {
        fail("Failed to set up graph in Accumulo with exception: " + e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) TableExistsException(org.apache.accumulo.core.client.TableExistsException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 30 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project Gaffer by gchq.

the class TableUtils method ensureTableExists.

/**
 * Ensures that the table exists, otherwise it creates it and sets it up to
 * receive Gaffer data
 *
 * @param store the accumulo store
 * @throws StoreException if a connection to accumulo could not be created or there is a failure to create a table/iterator
 */
public static void ensureTableExists(final AccumuloStore store) throws StoreException {
    final String tableName = store.getTableName();
    if (null == tableName) {
        throw new AccumuloRuntimeException("Table name is required.");
    }
    final Connector connector = store.getConnection();
    if (connector.tableOperations().exists(tableName)) {
        validateTable(store, tableName, connector);
    } else {
        try {
            TableUtils.createTable(store);
        } catch (final TableExistsException e) {
        // The method to create a table is synchronised, if you are using the same store only through one client in one JVM you shouldn't get here
        // Someone else got there first, never mind...
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloRuntimeException(uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Aggregations

TableExistsException (org.apache.accumulo.core.client.TableExistsException)32 AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)17 Connector (org.apache.accumulo.core.client.Connector)9 IOException (java.io.IOException)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)6 Mutation (org.apache.accumulo.core.data.Mutation)6 ByteBuffer (java.nio.ByteBuffer)5 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 Key (org.apache.accumulo.core.data.Key)4 Text (org.apache.hadoop.io.Text)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)3