use of org.apache.accumulo.core.client.MutationsRejectedException in project accumulo by apache.
the class PermissionsIT method testMissingTablePermission.
private void testMissingTablePermission(Connector test_user_conn, ClusterUser testUser, TablePermission perm, String tableName) throws Exception {
BatchWriter writer;
Mutation m;
log.debug("Confirming that the lack of the {} permission properly restricts the user", perm);
// test permission prior to granting it
switch(perm) {
case READ:
try (Scanner scanner = test_user_conn.createScanner(tableName, Authorizations.EMPTY)) {
int i = 0;
for (Entry<Key, Value> entry : scanner) i += 1 + entry.getKey().getRowData().length();
if (i != 0) {
throw new IllegalStateException("Should NOT be able to read from the table");
}
} catch (RuntimeException e) {
AccumuloSecurityException se = (AccumuloSecurityException) e.getCause();
if (se.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw se;
}
break;
case WRITE:
try {
writer = test_user_conn.createBatchWriter(tableName, new BatchWriterConfig());
m = new Mutation(new Text("row"));
m.put(new Text("a"), new Text("b"), new Value("c".getBytes()));
writer.addMutation(m);
try {
writer.close();
} catch (MutationsRejectedException e1) {
if (e1.getSecurityErrorCodes().size() > 0)
throw new AccumuloSecurityException(test_user_conn.whoami(), org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode.PERMISSION_DENIED, e1);
}
throw new IllegalStateException("Should NOT be able to write to a table");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw e;
}
break;
case BULK_IMPORT:
// test for bulk import permission would go here
break;
case ALTER_TABLE:
Map<String, Set<Text>> groups = new HashMap<>();
groups.put("tgroup", new HashSet<>(Arrays.asList(new Text("t1"), new Text("t2"))));
try {
test_user_conn.tableOperations().setLocalityGroups(tableName, groups);
throw new IllegalStateException("User should not be able to set locality groups");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw e;
}
break;
case DROP_TABLE:
try {
test_user_conn.tableOperations().delete(tableName);
throw new IllegalStateException("User should not be able delete the table");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw e;
}
break;
case GRANT:
try {
test_user_conn.securityOperations().grantTablePermission(getAdminPrincipal(), tableName, TablePermission.GRANT);
throw new IllegalStateException("User should not be able grant permissions");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw e;
}
break;
case GET_SUMMARIES:
try {
test_user_conn.tableOperations().summaries(tableName).retrieve();
throw new IllegalStateException("User should not be able to get table summaries");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
throw e;
}
break;
default:
throw new IllegalArgumentException("Unrecognized table Permission: " + perm);
}
}
use of org.apache.accumulo.core.client.MutationsRejectedException 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.client.MutationsRejectedException in project accumulo-examples by apache.
the class RandomBatchWriter method main.
/**
* Writes a specified number of entries to Accumulo using a {@link BatchWriter}.
*/
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
Opts opts = new Opts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
opts.parseArgs(RandomBatchWriter.class.getName(), args, bwOpts);
if ((opts.max - opts.min) < 1L * opts.num) {
// right-side multiplied by 1L to convert to long in a way that doesn't trigger FindBugs
System.err.println(String.format("You must specify a min and a max that allow for at least num possible values. " + "For example, you requested %d rows, but a min of %d and a max of %d (exclusive), which only allows for %d rows.", opts.num, opts.min, opts.max, (opts.max - opts.min)));
System.exit(1);
}
Random r;
if (opts.seed == null)
r = new Random();
else {
r = new Random(opts.seed);
}
Connector connector = opts.getConnector();
BatchWriter bw = connector.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
// reuse the ColumnVisibility object to improve performance
ColumnVisibility cv = opts.visiblity;
// Generate num unique row ids in the given range
HashSet<Long> rowids = new HashSet<>(opts.num);
while (rowids.size() < opts.num) {
rowids.add((abs(r.nextLong()) % (opts.max - opts.min)) + opts.min);
}
for (long rowid : rowids) {
Mutation m = createMutation(rowid, opts.size, cv);
bw.addMutation(m);
}
try {
bw.close();
} catch (MutationsRejectedException e) {
if (e.getSecurityErrorCodes().size() > 0) {
HashMap<String, Set<SecurityErrorCode>> tables = new HashMap<>();
for (Entry<TabletId, Set<SecurityErrorCode>> ke : e.getSecurityErrorCodes().entrySet()) {
String tableId = ke.getKey().getTableId().toString();
Set<SecurityErrorCode> secCodes = tables.get(tableId);
if (secCodes == null) {
secCodes = new HashSet<>();
tables.put(tableId, secCodes);
}
secCodes.addAll(ke.getValue());
}
System.err.println("ERROR : Not authorized to write to tables : " + tables);
}
if (e.getConstraintViolationSummaries().size() > 0) {
System.err.println("ERROR : Constraint violations occurred : " + e.getConstraintViolationSummaries());
}
System.exit(1);
}
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project teiid by teiid.
the class AccumuloUpdateExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
if (this.command instanceof Insert) {
Insert insert = (Insert) this.command;
performInsert(insert);
} else if (this.command instanceof Update) {
Update update = (Update) this.command;
performUpdate(update);
} else if (this.command instanceof Delete) {
Delete delete = (Delete) this.command;
performDelete(delete);
}
} catch (MutationsRejectedException e) {
throw new TranslatorException(e);
} catch (TableNotFoundException e) {
throw new TranslatorException(e);
}
}
use of org.apache.accumulo.core.client.MutationsRejectedException in project accumulo by apache.
the class TabletServerBatchWriter method checkForFailures.
private void checkForFailures() throws MutationsRejectedException {
if (somethingFailed) {
List<ConstraintViolationSummary> cvsList = violations.asList();
HashMap<TabletId, Set<org.apache.accumulo.core.client.security.SecurityErrorCode>> af = new HashMap<>();
for (Entry<KeyExtent, Set<SecurityErrorCode>> entry : authorizationFailures.entrySet()) {
HashSet<org.apache.accumulo.core.client.security.SecurityErrorCode> codes = new HashSet<>();
for (SecurityErrorCode sce : entry.getValue()) {
codes.add(org.apache.accumulo.core.client.security.SecurityErrorCode.valueOf(sce.name()));
}
af.put(new TabletIdImpl(entry.getKey()), codes);
}
throw new MutationsRejectedException(context.getInstance(), cvsList, af, serverSideErrors, unknownErrors, lastUnknownError);
}
}
Aggregations