use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class ConditionalWriterIT method testBatch.
@Test
public void testBatch() throws Exception {
Connector conn = getConnector();
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
conn.securityOperations().changeUserAuthorizations(getAdminPrincipal(), new Authorizations("A", "B"));
ColumnVisibility cvab = new ColumnVisibility("A|B");
ArrayList<ConditionalMutation> mutations = new ArrayList<>();
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvab));
cm0.put("name", "last", cvab, "doe");
cm0.put("name", "first", cvab, "john");
cm0.put("tx", "seq", cvab, "1");
mutations.add(cm0);
ConditionalMutation cm1 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvab));
cm1.put("name", "last", cvab, "doe");
cm1.put("name", "first", cvab, "jane");
cm1.put("tx", "seq", cvab, "1");
mutations.add(cm1);
ConditionalMutation cm2 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvab));
cm2.put("name", "last", cvab, "doe");
cm2.put("name", "first", cvab, "jack");
cm2.put("tx", "seq", cvab, "1");
mutations.add(cm2);
try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(new Authorizations("A")));
Scanner scanner = conn.createScanner(tableName, new Authorizations("A"))) {
Iterator<Result> results = cw.write(mutations.iterator());
int count = 0;
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
count++;
}
Assert.assertEquals(3, count);
scanner.fetchColumn(new Text("tx"), new Text("seq"));
for (String row : new String[] { "99006", "59056", "19059" }) {
scanner.setRange(new Range(row));
Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("1", entry.getValue().toString());
}
TreeSet<Text> splits = new TreeSet<>();
splits.add(new Text("7"));
splits.add(new Text("3"));
conn.tableOperations().addSplits(tableName, splits);
mutations.clear();
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvab).setValue("1"));
cm3.put("name", "last", cvab, "Doe");
cm3.put("tx", "seq", cvab, "2");
mutations.add(cm3);
ConditionalMutation cm4 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvab));
cm4.put("name", "last", cvab, "Doe");
cm4.put("tx", "seq", cvab, "1");
mutations.add(cm4);
ConditionalMutation cm5 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvab).setValue("2"));
cm5.put("name", "last", cvab, "Doe");
cm5.put("tx", "seq", cvab, "3");
mutations.add(cm5);
results = cw.write(mutations.iterator());
int accepted = 0;
int rejected = 0;
while (results.hasNext()) {
Result result = results.next();
if (new String(result.getMutation().getRow()).equals("99006")) {
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
accepted++;
} else {
Assert.assertEquals(Status.REJECTED, result.getStatus());
rejected++;
}
}
Assert.assertEquals("Expected only one accepted conditional mutation", 1, accepted);
Assert.assertEquals("Expected two rejected conditional mutations", 2, rejected);
for (String row : new String[] { "59056", "19059" }) {
scanner.setRange(new Range(row));
Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("1", entry.getValue().toString());
}
scanner.setRange(new Range("99006"));
Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("2", entry.getValue().toString());
scanner.clearColumns();
scanner.fetchColumn(new Text("name"), new Text("last"));
entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("Doe", entry.getValue().toString());
}
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.
the class CountIT method setupInstance.
@Before
public void setupInstance() throws Exception {
tableName = getUniqueNames(1)[0];
conn = getConnector();
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
ColumnVisibility cv = new ColumnVisibility();
// / has 1 dir
// /local has 2 dirs 1 file
// /local/user1 has 2 files
bw.addMutation(Ingest.buildMutation(cv, "/local", true, false, true, 272, 12345, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/user1", true, false, true, 272, 12345, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/user2", true, false, true, 272, 12345, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 12345, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 23456, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/user1/file1", false, false, false, 2024, 12345, null));
bw.addMutation(Ingest.buildMutation(cv, "/local/user1/file2", false, false, false, 1028, 23456, null));
bw.close();
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.
the class ChunkInputFormatIT method testInfoWithoutChunks.
@Test
public void testInfoWithoutChunks() throws Exception {
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
for (Entry<Key, Value> e : baddata) {
Key k = e.getKey();
Mutation m = new Mutation(k.getRow());
m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp(), e.getValue());
bw.addMutation(m);
}
bw.close();
assertEquals(0, CIFTester.main(tableName, CIFTester.TestBadData.class.getName()));
assertEquals(1, assertionErrors.get(tableName).size());
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.
the class ChunkInputStreamIT method testWithAccumulo.
@Test
public void testWithAccumulo() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException {
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
for (Entry<Key, Value> e : data) {
Key k = e.getKey();
Mutation m = new Mutation(k.getRow());
m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), e.getValue());
bw.addMutation(m);
}
bw.close();
Scanner scan = conn.createScanner(tableName, AUTHS);
ChunkInputStream cis = new ChunkInputStream();
byte[] b = new byte[20];
int read;
PeekingIterator<Entry<Key, Value>> pi = new PeekingIterator<>(scan.iterator());
cis.setSource(pi);
assertEquals(read = cis.read(b), 8);
assertEquals(new String(b, 0, read), "asdfjkl;");
assertEquals(read = cis.read(b), -1);
cis.setSource(pi);
assertEquals(read = cis.read(b), 10);
assertEquals(new String(b, 0, read), "qwertyuiop");
assertEquals(read = cis.read(b), -1);
assertEquals(cis.getVisibilities().toString(), "[A&B, B&C, D]");
cis.close();
cis.setSource(pi);
assertEquals(read = cis.read(b), 16);
assertEquals(new String(b, 0, read), "asdfjkl;asdfjkl;");
assertEquals(read = cis.read(b), -1);
assertEquals(cis.getVisibilities().toString(), "[A&B]");
cis.close();
cis.setSource(pi);
assertEquals(read = cis.read(b), -1);
cis.close();
cis.setSource(pi);
assertEquals(read = cis.read(b), 8);
assertEquals(new String(b, 0, read), "asdfjkl;");
assertEquals(read = cis.read(b), -1);
cis.close();
assertFalse(pi.hasNext());
}
use of org.apache.accumulo.core.security.ColumnVisibility in project presto by prestodb.
the class Indexer method index.
/**
* Index the given mutation, adding mutations to the index and metrics table
* <p>
* Like typical use of a BatchWriter, this method does not flush mutations to the underlying index table.
* For higher throughput the modifications to the metrics table are tracked in memory and added to the metrics table when the indexer is flushed or closed.
*
* @param mutation Mutation to index
*/
public void index(Mutation mutation) {
// Increment the cardinality for the number of rows in the table
metrics.get(METRICS_TABLE_ROW_COUNT).incrementAndGet();
// Set the first and last row values of the table based on existing row IDs
if (firstRow == null || byteArrayComparator.compare(mutation.getRow(), firstRow) < 0) {
firstRow = mutation.getRow();
}
if (lastRow == null || byteArrayComparator.compare(mutation.getRow(), lastRow) > 0) {
lastRow = mutation.getRow();
}
// For each column update in this mutation
for (ColumnUpdate columnUpdate : mutation.getUpdates()) {
// Get the column qualifiers we want to index for this column family (if any)
ByteBuffer family = wrap(columnUpdate.getColumnFamily());
Collection<ByteBuffer> indexQualifiers = indexColumns.get(family);
// If we have column qualifiers we want to index for this column family
if (indexQualifiers != null) {
// Check if we want to index this particular qualifier
ByteBuffer qualifier = wrap(columnUpdate.getColumnQualifier());
if (indexQualifiers.contains(qualifier)) {
// If so, create a mutation using the following mapping:
// Row ID = column value
// Column Family = columnqualifier_columnfamily
// Column Qualifier = row ID
// Value = empty
ByteBuffer indexFamily = getIndexColumnFamily(columnUpdate.getColumnFamily(), columnUpdate.getColumnQualifier());
Type type = indexColumnTypes.get(family).get(qualifier);
ColumnVisibility visibility = new ColumnVisibility(columnUpdate.getColumnVisibility());
// If this is an array type, then index each individual element in the array
if (Types.isArrayType(type)) {
Type elementType = Types.getElementType(type);
List<?> elements = serializer.decode(type, columnUpdate.getValue());
for (Object element : elements) {
addIndexMutation(wrap(serializer.encode(elementType, element)), indexFamily, visibility, mutation.getRow());
}
} else {
addIndexMutation(wrap(columnUpdate.getValue()), indexFamily, visibility, mutation.getRow());
}
}
}
}
}
Aggregations