Search in sources :

Example 66 with MutationsRejectedException

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);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 67 with MutationsRejectedException

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);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 68 with MutationsRejectedException

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);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Set(java.util.Set) HashSet(java.util.HashSet) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) HashMap(java.util.HashMap) SecurityErrorCode(org.apache.accumulo.core.client.security.SecurityErrorCode) Entry(java.util.Map.Entry) Random(java.util.Random) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Mutation(org.apache.accumulo.core.data.Mutation) HashSet(java.util.HashSet) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 69 with MutationsRejectedException

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);
    }
}
Also used : Delete(org.teiid.language.Delete) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TranslatorException(org.teiid.translator.TranslatorException) Insert(org.teiid.language.Insert) Update(org.teiid.language.Update) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 70 with MutationsRejectedException

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);
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SecurityErrorCode(org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode) TabletIdImpl(org.apache.accumulo.core.data.impl.TabletIdImpl) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) TabletId(org.apache.accumulo.core.data.TabletId) HashSet(java.util.HashSet) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Aggregations

MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)91 Mutation (org.apache.accumulo.core.data.Mutation)62 BatchWriter (org.apache.accumulo.core.client.BatchWriter)52 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)31 Text (org.apache.hadoop.io.Text)31 Value (org.apache.accumulo.core.data.Value)30 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)23 Key (org.apache.accumulo.core.data.Key)21 IOException (java.io.IOException)20 HashMap (java.util.HashMap)15 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 ConstraintViolationSummary (org.apache.accumulo.core.data.ConstraintViolationSummary)10 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)9 Set (java.util.Set)8 Test (org.junit.Test)8 List (java.util.List)7 Entry (java.util.Map.Entry)7