Search in sources :

Example 31 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class AccumuloOutputFormatIT method testMR.

@Test
public void testMR() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        String instanceName = getCluster().getInstanceName();
        String table1 = instanceName + "_t1";
        String table2 = instanceName + "_t2";
        c.tableOperations().create(table1);
        c.tableOperations().create(table2);
        BatchWriter bw = c.createBatchWriter(table1);
        for (int i = 0; i < 100; i++) {
            Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
            m.put("", "", String.format("%09x", i));
            bw.addMutation(m);
        }
        bw.close();
        MRTester.main(new String[] { "root", ROOT_PASSWORD, table1, table2, instanceName, getCluster().getZooKeepers() });
        assertNull(e1);
        try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            assertTrue(iter.hasNext());
            Entry<Key, Value> entry = iter.next();
            assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
            assertFalse(iter.hasNext());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 32 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class AccumuloOutputFormatIT method testMR.

@Test
public void testMR() throws Exception {
    String[] tableNames = getUniqueNames(2);
    String table1 = tableNames[0];
    String table2 = tableNames[1];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(table1);
        c.tableOperations().create(table2);
        BatchWriter bw = c.createBatchWriter(table1);
        for (int i = 0; i < 100; i++) {
            Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
            m.put("", "", String.format("%09x", i));
            bw.addMutation(m);
        }
        bw.close();
        MRTester.main(new String[] { table1, table2 });
        assertNull(e1);
        try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            assertTrue(iter.hasNext());
            Entry<Key, Value> entry = iter.next();
            assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
            assertFalse(iter.hasNext());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 33 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class TokenFileIT method testMR.

@Test
public void testMR() throws Exception {
    String[] tableNames = getUniqueNames(2);
    String table1 = tableNames[0];
    String table2 = tableNames[1];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(table1);
        c.tableOperations().create(table2);
        BatchWriter bw = c.createBatchWriter(table1);
        for (int i = 0; i < 100; i++) {
            Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
            m.put("", "", String.format("%09x", i));
            bw.addMutation(m);
        }
        bw.close();
        File tf = folder.newFile("client.properties");
        try (PrintStream out = new PrintStream(tf)) {
            getClientInfo().getProperties().store(out, "Credentials for " + getClass().getName());
        }
        MRTokenFileTester.main(new String[] { tf.getAbsolutePath(), table1, table2 });
        assertNull(e1);
        try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            assertTrue(iter.hasNext());
            Entry<Key, Value> entry = iter.next();
            assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
            assertFalse(iter.hasNext());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PrintStream(java.io.PrintStream) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) File(java.io.File) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 34 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class MultiTableInputFormatTest method testManyTables.

@Test
public void testManyTables() throws Exception {
    JobConf job = new JobConf();
    Properties clientProps = org.apache.accumulo.hadoop.mapreduce.AccumuloInputFormatTest.setupClientProperties();
    // if auths are not set client will try to get from server, we dont want that here
    Authorizations auths = Authorizations.EMPTY;
    // set the client properties once then loop over tables
    InputFormatBuilder.TableParams<JobConf> opts = AccumuloInputFormat.configure().clientProperties(clientProps);
    for (int i = 0; i < 10_000; i++) {
        List<Range> ranges = singletonList(new Range("a" + i, "b" + i));
        Set<Column> cols = singleton(new Column(new Text("CF" + i), new Text("CQ" + i)));
        IteratorSetting iter = new IteratorSetting(50, "iter" + i, "iterclass" + i);
        opts.table("table" + i).auths(auths).ranges(ranges).fetchColumns(cols).addIterator(iter);
    }
    opts.store(job);
    // verify
    Map<String, InputTableConfig> configs = InputConfigurator.getInputTableConfigs(CLASS, job);
    assertEquals(10_000, configs.size());
    // create objects to test against
    for (int i = 0; i < 10_000; i++) {
        InputTableConfig t = new InputTableConfig();
        List<Range> ranges = singletonList(new Range("a" + i, "b" + i));
        Set<Column> cols = singleton(new Column(new Text("CF" + i), new Text("CQ" + i)));
        IteratorSetting iter = new IteratorSetting(50, "iter" + i, "iterclass" + i);
        t.setScanAuths(auths).setRanges(ranges).fetchColumns(cols).addIterator(iter);
        assertEquals(t, configs.get("table" + i));
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) InputFormatBuilder(org.apache.accumulo.hadoop.mapreduce.InputFormatBuilder) Text(org.apache.hadoop.io.Text) Properties(java.util.Properties) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) InputTableConfig(org.apache.accumulo.hadoopImpl.mapreduce.InputTableConfig) Column(org.apache.accumulo.core.client.IteratorSetting.Column) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 35 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class MultiTableInputFormatTest method testStoreTables.

/**
 * Verify {@link InputTableConfig} objects get correctly serialized in the JobContext.
 */
@Test
public void testStoreTables() throws Exception {
    String table1Name = testName.getMethodName() + "1";
    String table2Name = testName.getMethodName() + "2";
    Job job = Job.getInstance();
    Properties clientProps = org.apache.accumulo.hadoop.mapreduce.AccumuloInputFormatTest.setupClientProperties();
    List<Range> ranges = singletonList(new Range("a", "b"));
    Set<IteratorSetting.Column> cols = singleton(new IteratorSetting.Column(new Text("CF1"), new Text("CQ1")));
    IteratorSetting iter1 = new IteratorSetting(50, "iter1", "iterclass1");
    IteratorSetting iter2 = new IteratorSetting(60, "iter2", "iterclass2");
    List<IteratorSetting> allIters = new ArrayList<>();
    allIters.add(iter1);
    allIters.add(iter2);
    // if auths are not set client will try to get from server, we dont want that here
    Authorizations auths = Authorizations.EMPTY;
    // @formatter:off
    AccumuloInputFormat.configure().clientProperties(clientProps).table(table1Name).auths(auths).ranges(ranges).fetchColumns(cols).addIterator(iter1).addIterator(iter2).localIterators(true).offlineScan(// end table 1
    true).table(table2Name).auths(auths).ranges(ranges).fetchColumns(cols).addIterator(// end
    iter2).store(job);
    // @formatter:on
    InputTableConfig table1 = new InputTableConfig();
    table1.setScanAuths(auths).setRanges(ranges).fetchColumns(cols).setUseLocalIterators(true).setOfflineScan(true);
    allIters.forEach(table1::addIterator);
    InputTableConfig table2 = new InputTableConfig();
    table2.setScanAuths(auths).setRanges(ranges).fetchColumns(cols).addIterator(iter2);
    Configuration jc = job.getConfiguration();
    assertEquals(table1, InputConfigurator.getInputTableConfig(CLASS, jc, table1Name));
    assertEquals(table2, InputConfigurator.getInputTableConfig(CLASS, jc, table2Name));
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Properties(java.util.Properties) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) InputTableConfig(org.apache.accumulo.hadoopImpl.mapreduce.InputTableConfig) Column(org.apache.accumulo.core.client.IteratorSetting.Column) Column(org.apache.accumulo.core.client.IteratorSetting.Column) Job(org.apache.hadoop.mapreduce.Job) Test(org.junit.Test)

Aggregations

Authorizations (org.apache.accumulo.core.security.Authorizations)242 Test (org.junit.Test)118 Scanner (org.apache.accumulo.core.client.Scanner)117 Key (org.apache.accumulo.core.data.Key)113 Value (org.apache.accumulo.core.data.Value)112 Text (org.apache.hadoop.io.Text)97 Mutation (org.apache.accumulo.core.data.Mutation)74 BatchWriter (org.apache.accumulo.core.client.BatchWriter)70 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)68 Range (org.apache.accumulo.core.data.Range)59 Map (java.util.Map)53 Entry (java.util.Map.Entry)47 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)39 Connector (org.apache.accumulo.core.client.Connector)34 ArrayList (java.util.ArrayList)31 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)30 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)29 AccumuloException (org.apache.accumulo.core.client.AccumuloException)28 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)26 Configuration (org.apache.hadoop.conf.Configuration)24