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());
}
}
}
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());
}
}
}
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());
}
}
}
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));
}
}
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));
}
Aggregations