Search in sources :

Example 1 with AccumuloRuntimeException

use of uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException 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.getProperties().getTable();
    if (null == tableName) {
        throw new AccumuloRuntimeException("Table name is required.");
    }
    final Connector connector = store.getConnection();
    if (!connector.tableOperations().exists(tableName)) {
        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)

Example 2 with AccumuloRuntimeException

use of uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException in project Gaffer by gchq.

the class TableUtils method createTable.

/**
     * Creates a table for Gaffer data and enables the correct Bloom filter;
     * removes the versioning iterator and adds an aggregator Iterator the
     * {@link org.apache.accumulo.core.iterators.user.AgeOffFilter} for the
     * specified time period.
     *
     * @param store the accumulo store
     * @throws StoreException       failure to create accumulo connection or add iterator settings
     * @throws TableExistsException failure to create table
     */
public static synchronized void createTable(final AccumuloStore store) throws StoreException, TableExistsException {
    // Create table
    final String tableName = store.getProperties().getTable();
    if (null == tableName) {
        throw new AccumuloRuntimeException("Table name is required.");
    }
    final Connector connector = store.getConnection();
    if (connector.tableOperations().exists(tableName)) {
        LOGGER.info("Table {} exists, not creating", tableName);
        return;
    }
    try {
        LOGGER.info("Creating table {} as user {}", tableName, connector.whoami());
        connector.tableOperations().create(tableName);
        final String repFactor = store.getProperties().getTableFileReplicationFactor();
        if (null != repFactor) {
            LOGGER.info("Table file replication set to {} on table {}", repFactor, tableName);
            connector.tableOperations().setProperty(tableName, Property.TABLE_FILE_REPLICATION.getKey(), repFactor);
        }
        // Enable Bloom filters using ElementFunctor
        LOGGER.info("Enabling Bloom filter on table {}", tableName);
        connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ENABLED.getKey(), "true");
        connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_KEY_FUNCTOR.getKey(), store.getKeyPackage().getKeyFunctor().getClass().getName());
        // Remove versioning iterator from table for all scopes
        LOGGER.info("Removing versioning iterator from table {}", tableName);
        final EnumSet<IteratorScope> iteratorScopes = EnumSet.allOf(IteratorScope.class);
        connector.tableOperations().removeIterator(tableName, "vers", iteratorScopes);
        if (store.getSchema().hasAggregators()) {
            // Add Combiner iterator to table for all scopes
            LOGGER.info("Adding Aggregator iterator to table {} for all scopes", tableName);
            connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getAggregatorIteratorSetting(store));
        } else {
            LOGGER.info("Aggregator iterator has not been added to table {}", tableName);
        }
        if (store.getProperties().getEnableValidatorIterator()) {
            // Add validator iterator to table for all scopes
            LOGGER.info("Adding Validator iterator to table {} for all scopes", tableName);
            connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getValidatorIteratorSetting(store));
        } else {
            LOGGER.info("Validator iterator has not been added to table {}", tableName);
        }
    } catch (AccumuloSecurityException | TableNotFoundException | AccumuloException | IteratorSettingException e) {
        throw new StoreException(e.getMessage(), e);
    }
    setLocalityGroups(store);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloRuntimeException(uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)2 AccumuloRuntimeException (uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)1 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1