use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class ScanIdIT method generateSampleData.
/**
* Generate some sample data using random row id to distribute across splits.
* <p>
* The primary goal is to determine that each scanner is assigned a unique scan id. This test does check that the count value for fam1 increases if a scanner
* reads multiple value, but this is secondary consideration for this test, that is included for completeness.
*
* @param connector
* Accumulo connector Accumulo connector to test cluster or MAC instance.
*/
private void generateSampleData(Connector connector, final String tablename) {
try {
BatchWriter bw = connector.createBatchWriter(tablename, new BatchWriterConfig());
ColumnVisibility vis = new ColumnVisibility("public");
for (int i = 0; i < NUM_DATA_ROWS; i++) {
Text rowId = new Text(String.format("%d", ((random.nextInt(10) * 100) + i)));
Mutation m = new Mutation(rowId);
m.put(new Text("fam1"), new Text("count"), new Value(Integer.toString(i).getBytes(UTF_8)));
m.put(new Text("fam1"), new Text("positive"), vis, new Value(Integer.toString(NUM_DATA_ROWS - i).getBytes(UTF_8)));
m.put(new Text("fam1"), new Text("negative"), vis, new Value(Integer.toString(i - NUM_DATA_ROWS).getBytes(UTF_8)));
log.trace("Added row {}", rowId);
bw.addMutation(m);
}
bw.close();
} catch (TableNotFoundException | MutationsRejectedException ex) {
throw new IllegalStateException("Initialization failed. Could not create test data", ex);
}
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class VisibilityIT method mputDelete.
private void mputDelete(Mutation m, String cf, String cq, String cv) {
ColumnVisibility le = new ColumnVisibility(cv.getBytes(UTF_8));
m.putDelete(new Text(cf), new Text(cq), le);
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class VisibilityIT method mput.
private void mput(Mutation m, String cf, String cq, String cv, String val) {
ColumnVisibility le = new ColumnVisibility(cv.getBytes(UTF_8));
m.put(new Text(cf), new Text(cq), le, new Value(val.getBytes(UTF_8)));
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.
the class ReadWriteExample method createEntries.
private void createEntries(Opts opts) throws Exception {
if (opts.createEntries || opts.deleteEntries) {
BatchWriterConfig cfg = new BatchWriterConfig();
cfg.setDurability(opts.durability);
BatchWriter writer = conn.createBatchWriter(opts.getTableName(), cfg);
ColumnVisibility cv = new ColumnVisibility(opts.auths.toString().replace(',', '|'));
Text cf = new Text("datatypes");
Text cq = new Text("xml");
byte[] row = { 'h', 'e', 'l', 'l', 'o', '\0' };
byte[] value = { 'w', 'o', 'r', 'l', 'd', '\0' };
for (int i = 0; i < 10; i++) {
row[row.length - 1] = (byte) i;
Mutation m = new Mutation(new Text(row));
if (opts.deleteEntries) {
m.putDelete(cf, cq, cv);
}
if (opts.createEntries) {
value[value.length - 1] = (byte) i;
m.put(cf, cq, cv, new Value(value));
}
writer.addMutation(m);
}
writer.close();
}
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.
the class CountIT method test.
@Test
public void test() throws Exception {
Scanner scanner = conn.createScanner(tableName, new Authorizations());
scanner.fetchColumn(new Text("dir"), new Text("counts"));
assertFalse(scanner.iterator().hasNext());
ScannerOpts scanOpts = new ScannerOpts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
fc.run();
ArrayList<Pair<String, String>> expected = new ArrayList<>();
expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));
int i = 0;
for (Entry<Key, Value> e : scanner) {
assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
assertEquals(e.getValue().toString(), expected.get(i).getSecond());
i++;
}
assertEquals(i, expected.size());
}
Aggregations