Search in sources :

Example 51 with ZooKeeperInstance

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

the class RFileReaderRDD method getPartitions.

@Override
public Partition[] getPartitions() {
    // Get connection
    final Connector connector;
    try {
        final Instance instance = new ZooKeeperInstance(instanceName, zookeepers);
        connector = instance.getConnector(user, new PasswordToken(password));
    } catch (final AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException("Exception connecting to Accumulo", e);
    }
    LOGGER.info("Obtained connection to instance {} as user {}", instanceName, user);
    try {
        // Check user has access
        if (!checkAccess(connector, user, tableName)) {
            throw new RuntimeException("User " + user + " does not have access to table " + tableName);
        }
        LOGGER.info("Confirmed user {} has access to table {}", user, tableName);
        // Get id and split points for table
        final String tableId = connector.tableOperations().tableIdMap().get(tableName);
        final int numTablets = connector.tableOperations().listSplits(tableName).size() + 1;
        LOGGER.info("Table {} has id {} and {} tablets", tableName, tableId, numTablets);
        // Create map from tablet name to information about that tablet, including location of the RFiles
        final Map<String, AccumuloTablet> tabletNameToInfo = createTabletMap(connector, user, tableId);
        // Create array of partitions
        final Partition[] partitions = new Partition[tabletNameToInfo.size()];
        for (final AccumuloTablet accumuloTablet : tabletNameToInfo.values()) {
            partitions[accumuloTablet.index()] = accumuloTablet;
        }
        LOGGER.info("Returning {} partitions", partitions.length);
        return partitions;
    } catch (final TableNotFoundException | AccumuloSecurityException | AccumuloException e) {
        throw new RuntimeException("Exception creating partitions", e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Partition(org.apache.spark.Partition) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 52 with ZooKeeperInstance

use of org.apache.accumulo.core.client.ZooKeeperInstance 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) throws GoraException {
    super.initialize(keyClass, persistentClass, properties);
    try {
        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 {
            encoder = (Encoder) getClass().getClassLoader().loadClass(mapping.encoder).getDeclaredConstructor().newInstance();
        }
        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 (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException | AccumuloException | AccumuloSecurityException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
        throw new GoraException(e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) GoraException(org.apache.gora.util.GoraException) 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

ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)52 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)35 Instance (org.apache.accumulo.core.client.Instance)24 Connector (org.apache.accumulo.core.client.Connector)17 AccumuloException (org.apache.accumulo.core.client.AccumuloException)15 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)15 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 IOException (java.io.IOException)8 Test (org.junit.Test)8 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)7 Range (org.apache.accumulo.core.data.Range)6 ArrayList (java.util.ArrayList)5 MiniAccumuloCluster (org.apache.accumulo.minicluster.MiniAccumuloCluster)5 Text (org.apache.hadoop.io.Text)5 File (java.io.File)4 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)4 Pair (org.apache.accumulo.core.util.Pair)4 AccumuloConnectionParameters (org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters)4