Search in sources :

Example 16 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException 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)

Example 17 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.

the class AccumuloTableManager method setLocalityGroups.

public void setLocalityGroups(String tableName, Map<String, Set<Text>> groups) {
    if (groups.isEmpty()) {
        return;
    }
    try {
        connector.tableOperations().setLocalityGroups(tableName, groups);
        LOG.debug("Set locality groups for %s to %s", tableName, groups);
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set locality groups", e);
    } catch (TableNotFoundException e) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set locality groups, table does not exist", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 18 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.

the class AccumuloTableManager method setIterator.

public void setIterator(String table, IteratorSetting setting) {
    try {
        // Remove any existing iterator settings of the same name, if applicable
        Map<String, EnumSet<IteratorScope>> iterators = connector.tableOperations().listIterators(table);
        if (iterators.containsKey(setting.getName())) {
            connector.tableOperations().removeIterator(table, setting.getName(), iterators.get(setting.getName()));
        }
        connector.tableOperations().attachIterator(table, setting);
    } catch (AccumuloSecurityException | AccumuloException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set iterator on table " + table, e);
    } catch (TableNotFoundException e) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set iterator, table does not exist", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) EnumSet(java.util.EnumSet) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 19 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException in project presto by prestodb.

the class AccumuloQueryRunner method getAccumuloConnector.

/**
     * Gets the AccumuloConnector singleton, starting the MiniAccumuloCluster on initialization.
     * This singleton instance is required so all test cases access the same MiniAccumuloCluster.
     *
     * @return Accumulo connector
     */
private static Connector getAccumuloConnector() {
    if (connector != null) {
        return connector;
    }
    try {
        MiniAccumuloCluster accumulo = createMiniAccumuloCluster();
        Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
        connector = instance.getConnector(MAC_USER, new PasswordToken(MAC_PASSWORD));
        LOG.info("Connection to MAC instance %s at %s established, user %s password %s", accumulo.getInstanceName(), accumulo.getZooKeepers(), MAC_USER, MAC_PASSWORD);
        return connector;
    } catch (AccumuloException | AccumuloSecurityException | InterruptedException | IOException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to get connector to Accumulo", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 20 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException in project gora by apache.

the class AccumuloStore method initialize.

/**
   * Initialize the data store by reading the credentials, setting the client's properties up and
   * reading the mapping file. Initialize is called when then the call to
   * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
   *
   * @param keyClass
   * @param persistentClass
   * @param properties
   */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
    try {
        super.initialize(keyClass, persistentClass, properties);
        String mock = DataStoreFactory.findProperty(properties, this, MOCK_PROPERTY, null);
        String mappingFile = DataStoreFactory.getMappingFile(properties, this, DEFAULT_MAPPING_FILE);
        String user = DataStoreFactory.findProperty(properties, this, USERNAME_PROPERTY, null);
        String password = DataStoreFactory.findProperty(properties, this, PASSWORD_PROPERTY, null);
        mapping = readMapping(mappingFile);
        if (mapping.encoder == null || "".equals(mapping.encoder)) {
            encoder = new BinaryEncoder();
        } else {
            try {
                encoder = (Encoder) getClass().getClassLoader().loadClass(mapping.encoder).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new IOException(e);
            }
        }
        try {
            AuthenticationToken token = new PasswordToken(password);
            if (mock == null || !mock.equals("true")) {
                String instance = DataStoreFactory.findProperty(properties, this, INSTANCE_NAME_PROPERTY, null);
                String zookeepers = DataStoreFactory.findProperty(properties, this, ZOOKEEPERS_NAME_PROPERTY, null);
                conn = new ZooKeeperInstance(instance, zookeepers).getConnector(user, token);
            } else {
                conn = new MockInstance().getConnector(user, token);
            }
            credentials = new Credentials(user, token);
            if (autoCreateSchema && !schemaExists())
                createSchema();
        } catch (AccumuloException | AccumuloSecurityException e) {
            throw new IOException(e);
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) BinaryEncoder(org.apache.gora.accumulo.encoders.BinaryEncoder) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Aggregations

AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)15 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)14 IOException (java.io.IOException)7 Entry (java.util.Map.Entry)7 BatchWriter (org.apache.accumulo.core.client.BatchWriter)7 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)7 Key (org.apache.accumulo.core.data.Key)7 Mutation (org.apache.accumulo.core.data.Mutation)7 Value (org.apache.accumulo.core.data.Value)7 Authorizations (org.apache.accumulo.core.security.Authorizations)7 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)7 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 Scanner (org.apache.accumulo.core.client.Scanner)6 Text (org.apache.hadoop.io.Text)6 IteratorSettingBuilder (uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)6 Connector (org.apache.accumulo.core.client.Connector)5 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)4