Search in sources :

Example 6 with ZooKeeperInstance

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

ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)7 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)7 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 Range (org.apache.accumulo.core.data.Range)4 Pair (org.apache.accumulo.core.util.Pair)4 AccumuloConnectionParameters (org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters)4 ColumnMapper (org.apache.hadoop.hive.accumulo.columns.ColumnMapper)4 Test (org.junit.Test)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)2 PrimitiveComparisonFilter (org.apache.hadoop.hive.accumulo.predicate.PrimitiveComparisonFilter)2 Equal (org.apache.hadoop.hive.accumulo.predicate.compare.Equal)2 GreaterThanOrEqual (org.apache.hadoop.hive.accumulo.predicate.compare.GreaterThanOrEqual)2 IntCompare (org.apache.hadoop.hive.accumulo.predicate.compare.IntCompare)2 StringCompare (org.apache.hadoop.hive.accumulo.predicate.compare.StringCompare)2 PrestoException (com.facebook.presto.spi.PrestoException)1 DBException (com.yahoo.ycsb.DBException)1