Search in sources :

Example 31 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project YCSB by brianfrankcooper.

the class AccumuloTest method setup.

@BeforeClass
public static void setup() throws Exception {
    // Minicluster setup fails on Windows with an UnsatisfiedLinkError.
    // Skip if windows.
    assumeTrue(!isWindows());
    cluster = new MiniAccumuloCluster(workingDir.newFolder("accumulo").getAbsoluteFile(), "protectyaneck");
    LOG.debug("starting minicluster");
    cluster.start();
    LOG.debug("creating connection for admin operations.");
    // set up the table and user
    final Connector admin = cluster.getConnector("root", "protectyaneck");
    admin.tableOperations().create(CoreWorkload.TABLENAME_PROPERTY_DEFAULT);
    admin.securityOperations().createLocalUser("ycsb", new PasswordToken("protectyaneck"));
    admin.securityOperations().grantTablePermission("ycsb", CoreWorkload.TABLENAME_PROPERTY_DEFAULT, TablePermission.READ);
    admin.securityOperations().grantTablePermission("ycsb", CoreWorkload.TABLENAME_PROPERTY_DEFAULT, TablePermission.WRITE);
    // set properties the binding will read
    properties = new Properties();
    properties.setProperty("accumulo.zooKeepers", cluster.getZooKeepers());
    properties.setProperty("accumulo.instanceName", cluster.getInstanceName());
    properties.setProperty("accumulo.columnFamily", "family");
    properties.setProperty("accumulo.username", "ycsb");
    properties.setProperty("accumulo.password", "protectyaneck");
    // cut down the batch writer timeout so that writes will push through.
    properties.setProperty("accumulo.batchWriterMaxLatency", "4");
    // set these explicitly to the defaults at the time we're compiled, since they'll be inlined in our class.
    properties.setProperty(CoreWorkload.TABLENAME_PROPERTY, CoreWorkload.TABLENAME_PROPERTY_DEFAULT);
    properties.setProperty(CoreWorkload.FIELD_COUNT_PROPERTY, CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT);
    properties.setProperty(CoreWorkload.INSERT_ORDER_PROPERTY, "ordered");
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass)

Example 32 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project presto by prestodb.

the class TestIndexer method testMutationIndex.

@Test
public void testMutationIndex() throws Exception {
    Instance inst = new MockInstance();
    Connector conn = inst.getConnector("root", new PasswordToken(""));
    conn.tableOperations().create(table.getFullTableName());
    conn.tableOperations().create(table.getIndexTableName());
    conn.tableOperations().create(table.getMetricsTableName());
    for (IteratorSetting s : Indexer.getMetricIterators(table)) {
        conn.tableOperations().attachIterator(table.getMetricsTableName(), s);
    }
    Indexer indexer = new Indexer(conn, new Authorizations(), table, new BatchWriterConfig());
    indexer.index(m1);
    indexer.flush();
    Scanner scan = conn.createScanner(table.getIndexTableName(), new Authorizations());
    scan.setRange(new Range());
    Iterator<Entry<Key, Value>> iter = scan.iterator();
    assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "row1", "");
    assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "row1", "");
    assertKeyValuePair(iter.next(), M1_FNAME_VALUE, "cf_firstname", "row1", "");
    assertKeyValuePair(iter.next(), bytes("def"), "cf_arr", "row1", "");
    assertKeyValuePair(iter.next(), bytes("ghi"), "cf_arr", "row1", "");
    assertFalse(iter.hasNext());
    scan.close();
    scan = conn.createScanner(table.getMetricsTableName(), new Authorizations());
    scan.setRange(new Range());
    iter = scan.iterator();
    assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "___card___", "1");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___card___", "1");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___first_row___", "row1");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___last_row___", "row1");
    assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "___card___", "1");
    assertKeyValuePair(iter.next(), M1_FNAME_VALUE, "cf_firstname", "___card___", "1");
    assertKeyValuePair(iter.next(), bytes("def"), "cf_arr", "___card___", "1");
    assertKeyValuePair(iter.next(), bytes("ghi"), "cf_arr", "___card___", "1");
    assertFalse(iter.hasNext());
    scan.close();
    indexer.index(m2);
    indexer.close();
    scan = conn.createScanner(table.getIndexTableName(), new Authorizations());
    scan.setRange(new Range());
    iter = scan.iterator();
    assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "row1", "");
    assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "row2", "");
    assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "row1", "");
    assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "row2", "");
    assertKeyValuePair(iter.next(), M1_FNAME_VALUE, "cf_firstname", "row1", "");
    assertKeyValuePair(iter.next(), M2_FNAME_VALUE, "cf_firstname", "row2", "");
    assertKeyValuePair(iter.next(), bytes("def"), "cf_arr", "row1", "");
    assertKeyValuePair(iter.next(), bytes("ghi"), "cf_arr", "row1", "");
    assertKeyValuePair(iter.next(), bytes("ghi"), "cf_arr", "row2", "");
    assertKeyValuePair(iter.next(), bytes("mno"), "cf_arr", "row2", "");
    assertFalse(iter.hasNext());
    scan.close();
    scan = conn.createScanner(table.getMetricsTableName(), new Authorizations());
    scan.setRange(new Range());
    iter = scan.iterator();
    assertKeyValuePair(iter.next(), AGE_VALUE, "cf_age", "___card___", "2");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___card___", "2");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___first_row___", "row1");
    assertKeyValuePair(iter.next(), Indexer.METRICS_TABLE_ROW_ID.array(), "___rows___", "___last_row___", "row2");
    assertKeyValuePair(iter.next(), bytes("abc"), "cf_arr", "___card___", "2");
    assertKeyValuePair(iter.next(), M1_FNAME_VALUE, "cf_firstname", "___card___", "1");
    assertKeyValuePair(iter.next(), M2_FNAME_VALUE, "cf_firstname", "___card___", "1");
    assertKeyValuePair(iter.next(), bytes("def"), "cf_arr", "___card___", "1");
    assertKeyValuePair(iter.next(), bytes("ghi"), "cf_arr", "___card___", "2");
    assertKeyValuePair(iter.next(), bytes("mno"), "cf_arr", "___card___", "1");
    assertFalse(iter.hasNext());
    scan.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Authorizations(org.apache.accumulo.core.security.Authorizations) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Range(org.apache.accumulo.core.data.Range) Test(org.testng.annotations.Test)

Example 33 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken 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 34 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken 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

PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)34 Test (org.junit.Test)25 Connector (org.apache.accumulo.core.client.Connector)23 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)20 Authorizations (org.apache.accumulo.core.security.Authorizations)14 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10 Value (org.apache.accumulo.core.data.Value)10 Key (org.apache.accumulo.core.data.Key)9 Table (org.apache.hadoop.hive.metastore.api.Table)9 Text (org.apache.hadoop.io.Text)8 Instance (org.apache.accumulo.core.client.Instance)7 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)7 Mutation (org.apache.accumulo.core.data.Mutation)7 Range (org.apache.accumulo.core.data.Range)7 JobConf (org.apache.hadoop.mapred.JobConf)7 Entry (java.util.Map.Entry)6 Pair (org.apache.accumulo.core.util.Pair)6 AccumuloConnectionParameters (org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters)6 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)6 Properties (java.util.Properties)5