use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class TestRandomDeletes method scrambleDeleteHalfAndCheck.
private static long scrambleDeleteHalfAndCheck(ClientOnDefaultTable opts, ScannerOpts scanOpts, BatchWriterOpts bwOpts, String tableName, Set<RowColumn> rows) throws Exception {
int result = 0;
ArrayList<RowColumn> entries = new ArrayList<>(rows);
java.util.Collections.shuffle(entries);
Connector connector = opts.getConnector();
BatchWriter mutations = connector.createBatchWriter(tableName, bwOpts.getBatchWriterConfig());
for (int i = 0; i < (entries.size() + 1) / 2; i++) {
RowColumn rc = entries.get(i);
Mutation m = new Mutation(rc.row);
m.putDelete(new Text(rc.column.columnFamily), new Text(rc.column.columnQualifier), new ColumnVisibility(rc.column.getColumnVisibility()), rc.timestamp + 1);
mutations.addMutation(m);
rows.remove(rc);
result++;
}
mutations.close();
Set<RowColumn> current = scanAll(opts, scanOpts, tableName);
current.removeAll(rows);
if (current.size() > 0) {
throw new RuntimeException(current.size() + " records not deleted");
}
return result;
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class MockTableOperations method importDirectory.
@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
long time = System.currentTimeMillis();
MockTable table = acu.tables.get(tableName);
if (table == null) {
throw new TableNotFoundException(null, tableName, "The table was not found");
}
Path importPath = new Path(dir);
Path failurePath = new Path(failureDir);
FileSystem fs = acu.getFileSystem();
// directories are directories
if (fs.isFile(importPath)) {
throw new IOException("Import path must be a directory.");
}
if (fs.isFile(failurePath)) {
throw new IOException("Failure path must be a directory.");
}
// failures are writable
Path createPath = failurePath.suffix("/.createFile");
FSDataOutputStream createStream = null;
try {
createStream = fs.create(createPath);
} catch (IOException e) {
throw new IOException("Error path is not writable.");
} finally {
if (createStream != null) {
createStream.close();
}
}
fs.delete(createPath, false);
// failures are empty
FileStatus[] failureChildStats = fs.listStatus(failurePath);
if (failureChildStats.length > 0) {
throw new IOException("Error path must be empty.");
}
/*
* Begin the import - iterate the files in the path
*/
for (FileStatus importStatus : fs.listStatus(importPath)) {
try {
FileSKVIterator importIterator = FileOperations.getInstance().newReaderBuilder().forFile(importStatus.getPath().toString(), fs, fs.getConf()).withTableConfiguration(DefaultConfiguration.getInstance()).seekToBeginning().build();
while (importIterator.hasTop()) {
Key key = importIterator.getTopKey();
Value value = importIterator.getTopValue();
if (setTime) {
key.setTimestamp(time);
}
Mutation mutation = new Mutation(key.getRow());
if (!key.isDeleted()) {
mutation.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), key.getTimestamp(), value);
} else {
mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), key.getTimestamp());
}
table.addMutation(mutation);
importIterator.next();
}
} catch (Exception e) {
FSDataOutputStream failureWriter = null;
DataInputStream failureReader = null;
try {
failureWriter = fs.create(failurePath.suffix("/" + importStatus.getPath().getName()));
failureReader = fs.open(importStatus.getPath());
int read = 0;
byte[] buffer = new byte[1024];
while (-1 != (read = failureReader.read(buffer))) {
failureWriter.write(buffer, 0, read);
}
} finally {
if (failureReader != null)
failureReader.close();
if (failureWriter != null)
failureWriter.close();
}
}
fs.delete(importStatus.getPath(), true);
}
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class MockTableOperationsTest method prepareTestFiles.
private ImportTestFilesAndData prepareTestFiles() throws Throwable {
Configuration defaultConf = new Configuration();
Path tempFile = new Path("target/accumulo-test/import/sample.rf");
Path failures = new Path("target/accumulo-test/failures/");
FileSystem fs = FileSystem.get(new URI("file:///"), defaultConf);
fs.deleteOnExit(tempFile);
fs.deleteOnExit(failures);
fs.delete(failures, true);
fs.delete(tempFile, true);
fs.mkdirs(failures);
fs.mkdirs(tempFile.getParent());
FileSKVWriter writer = FileOperations.getInstance().newWriterBuilder().forFile(tempFile.toString(), fs, defaultConf).withTableConfiguration(DefaultConfiguration.getInstance()).build();
writer.startDefaultLocalityGroup();
List<Pair<Key, Value>> keyVals = new ArrayList<>();
for (int i = 0; i < 5; i++) {
keyVals.add(new Pair<>(new Key("a" + i, "b" + i, "c" + i, new ColumnVisibility(""), 1000l + i), new Value(Integer.toString(i).getBytes())));
}
for (Pair<Key, Value> keyVal : keyVals) {
writer.append(keyVal.getFirst(), keyVal.getSecond());
}
writer.close();
ImportTestFilesAndData files = new ImportTestFilesAndData();
files.failurePath = failures;
files.importPath = tempFile.getParent();
files.keyVals = keyVals;
return files;
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class MiniAccumuloClusterTest method test.
@Test(timeout = 30000)
public void test() throws Exception {
Connector conn = accumulo.getConnector("root", "superSecret");
conn.tableOperations().create("table1", new NewTableConfiguration());
conn.securityOperations().createLocalUser("user1", new PasswordToken("pass1"));
conn.securityOperations().changeUserAuthorizations("user1", new Authorizations("A", "B"));
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.WRITE);
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.READ);
IteratorSetting is = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(is, LongCombiner.Type.STRING);
SummingCombiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("META", "COUNT")));
conn.tableOperations().attachIterator("table1", is);
Connector uconn = accumulo.getConnector("user1", "pass1");
BatchWriter bw = uconn.createBatchWriter("table1", new BatchWriterConfig());
UUID uuid = UUID.randomUUID();
Mutation m = new Mutation(uuid.toString());
m.put("META", "SIZE", new ColumnVisibility("A|B"), "8");
m.put("META", "CRC", new ColumnVisibility("A|B"), "456");
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("DATA", "IMG", new ColumnVisibility("A&B"), "ABCDEFGH");
bw.addMutation(m);
bw.flush();
m = new Mutation(uuid.toString());
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("META", "CRC", new ColumnVisibility("A|B"), "123");
bw.addMutation(m);
bw.close();
int count = 0;
Scanner scanner = uconn.createScanner("table1", new Authorizations("A"));
for (Entry<Key, Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("COUNT")) {
Assert.assertEquals("2", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("SIZE")) {
Assert.assertEquals("8", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("CRC")) {
Assert.assertEquals("123", entry.getValue().toString());
} else {
Assert.assertTrue(false);
}
count++;
}
Assert.assertEquals(3, count);
count = 0;
scanner = uconn.createScanner("table1", new Authorizations("A", "B"));
for (Entry<Key, Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("IMG")) {
Assert.assertEquals("ABCDEFGH", entry.getValue().toString());
}
count++;
}
Assert.assertEquals(4, count);
conn.tableOperations().delete("table1");
}
use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.
the class ProxyServer method getCahcedCV.
private static ColumnVisibility getCahcedCV(HashMap<Text, ColumnVisibility> vizMap, byte[] cv) {
ColumnVisibility viz;
Text vizText = new Text(cv);
viz = vizMap.get(vizText);
if (viz == null) {
vizMap.put(vizText, viz = new ColumnVisibility(vizText));
}
return viz;
}
Aggregations