Search in sources :

Example 46 with ZooKeeperInstance

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

the class TestHiveAccumuloTableInputFormat method testConfigureAccumuloInputFormatWithAuthorizations.

@Test
public void testConfigureAccumuloInputFormatWithAuthorizations() throws Exception {
    AccumuloConnectionParameters accumuloParams = new AccumuloConnectionParameters(conf);
    conf.set(AccumuloSerDeParameters.AUTHORIZATIONS_KEY, "foo,bar");
    ColumnMapper columnMapper = new ColumnMapper(conf.get(AccumuloSerDeParameters.COLUMN_MAPPINGS), conf.get(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE), columnNames, columnTypes);
    Set<Pair<Text, Text>> cfCqPairs = inputformat.getPairCollection(columnMapper.getColumnMappings());
    List<IteratorSetting> iterators = Collections.emptyList();
    Set<Range> ranges = Collections.singleton(new Range());
    String instanceName = "realInstance";
    String zookeepers = "host1:2181,host2:2181,host3:2181";
    ZooKeeperInstance zkInstance = Mockito.mock(ZooKeeperInstance.class);
    HiveAccumuloTableInputFormat mockInputFormat = Mockito.mock(HiveAccumuloTableInputFormat.class);
    HiveAccumuloHelper helper = Mockito.mock(HiveAccumuloHelper.class);
    // Stub out the ZKI mock
    Mockito.when(zkInstance.getInstanceName()).thenReturn(instanceName);
    Mockito.when(zkInstance.getZooKeepers()).thenReturn(zookeepers);
    // Stub out a mocked Helper instance
    Mockito.when(mockInputFormat.getHelper()).thenReturn(helper);
    // Call out to the real configure method
    Mockito.doCallRealMethod().when(mockInputFormat).configure(conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);
    // Also compute the correct cf:cq pairs so we can assert the right argument was passed
    Mockito.doCallRealMethod().when(mockInputFormat).getPairCollection(columnMapper.getColumnMappings());
    mockInputFormat.configure(conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);
    // Verify that the correct methods are invoked on AccumuloInputFormat
    Mockito.verify(helper).setInputFormatZooKeeperInstance(conf, instanceName, zookeepers, false);
    Mockito.verify(helper).setInputFormatConnectorInfo(conf, USER, new PasswordToken(PASS));
    Mockito.verify(mockInputFormat).setInputTableName(conf, TEST_TABLE);
    Mockito.verify(mockInputFormat).setScanAuthorizations(conf, new Authorizations("foo,bar"));
    Mockito.verify(mockInputFormat).addIterators(conf, iterators);
    Mockito.verify(mockInputFormat).setRanges(conf, ranges);
    Mockito.verify(mockInputFormat).fetchColumns(conf, cfCqPairs);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Range(org.apache.accumulo.core.data.Range) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) HiveAccumuloHelper(org.apache.hadoop.hive.accumulo.HiveAccumuloHelper) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) AccumuloConnectionParameters(org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters) ColumnMapper(org.apache.hadoop.hive.accumulo.columns.ColumnMapper) Pair(org.apache.accumulo.core.util.Pair) Test(org.junit.Test)

Example 47 with ZooKeeperInstance

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

the class AccumuloConnectionParameters method getInstance.

public Instance getInstance() {
    String instanceName = getAccumuloInstanceName();
    // Fail with a good message
    if (null == instanceName) {
        throw new IllegalArgumentException("Accumulo instance name must be provided in hiveconf using " + INSTANCE_NAME);
    }
    if (useMockInstance()) {
        return new MockInstance(instanceName);
    }
    String zookeepers = getZooKeepers();
    // Fail with a good message
    if (null == zookeepers) {
        throw new IllegalArgumentException("ZooKeeper quorum string must be provided in hiveconf using " + ZOOKEEPERS);
    }
    ClientConfiguration clientConf = ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers).withSasl(useSasl());
    return new ZooKeeperInstance(clientConf);
}
Also used : MockInstance(org.apache.accumulo.core.client.mock.MockInstance) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 48 with ZooKeeperInstance

use of org.apache.accumulo.core.client.ZooKeeperInstance in project YCSB by brianfrankcooper.

the class AccumuloClient method init.

@Override
public void init() throws DBException {
    colFam = new Text(getProperties().getProperty("accumulo.columnFamily"));
    colFamBytes = colFam.toString().getBytes(UTF_8);
    inst = new ZooKeeperInstance(new ClientConfiguration().withInstance(getProperties().getProperty("accumulo.instanceName")).withZkHosts(getProperties().getProperty("accumulo.zooKeepers")));
    try {
        String principal = getProperties().getProperty("accumulo.username");
        AuthenticationToken token = new PasswordToken(getProperties().getProperty("accumulo.password"));
        connector = inst.getConnector(principal, token);
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new DBException(e);
    }
    if (!(getProperties().getProperty("accumulo.pcFlag", "none").equals("none"))) {
        System.err.println("Sorry, the ZK based producer/consumer implementation has been removed. " + "Please see YCSB issue #416 for work on adding a general solution to coordinated work.");
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) DBException(site.ycsb.DBException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) Text(org.apache.hadoop.io.Text) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 49 with ZooKeeperInstance

use of org.apache.accumulo.core.client.ZooKeeperInstance in project apex-malhar by apache.

the class AccumuloStore method connect.

@Override
public void connect() throws IOException {
    Instance instance = null;
    instance = new ZooKeeperInstance(instanceName, zookeeperHost);
    try {
        PasswordToken t = new PasswordToken(password.getBytes());
        connector = instance.getConnector(userName, t);
    } catch (AccumuloException e) {
        logger.error("error connecting to accumulo", e);
        DTThrowable.rethrow(e);
    } catch (AccumuloSecurityException e) {
        logger.error("error connecting to accumulo", e);
        DTThrowable.rethrow(e);
    }
    BatchWriterConfig config = new BatchWriterConfig();
    config.setMaxMemory(memoryLimit);
    config.setMaxWriteThreads(numThreads);
    try {
        batchwriter = connector.createBatchWriter(tableName, config);
    } catch (TableNotFoundException e) {
        logger.error("table not found", e);
        DTThrowable.rethrow(e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 50 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
 */
public 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)

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