Search in sources :

Example 1 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class TableOperationsIT method createMergeClonedTable.

@Test
public void createMergeClonedTable() throws Exception {
    String[] names = getUniqueNames(2);
    String originalTable = names[0];
    TableOperations tops = connector.tableOperations();
    TreeSet<Text> splits = Sets.newTreeSet(Arrays.asList(new Text("a"), new Text("b"), new Text("c"), new Text("d")));
    tops.create(originalTable);
    tops.addSplits(originalTable, splits);
    BatchWriter bw = connector.createBatchWriter(originalTable, new BatchWriterConfig());
    for (Text row : splits) {
        Mutation m = new Mutation(row);
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                m.put(Integer.toString(i), Integer.toString(j), Integer.toString(i + j));
            }
        }
        bw.addMutation(m);
    }
    bw.close();
    String clonedTable = names[1];
    tops.clone(originalTable, clonedTable, true, null, null);
    tops.merge(clonedTable, null, new Text("b"));
    Map<String, Integer> rowCounts = new HashMap<>();
    try (Scanner s = connector.createScanner(clonedTable, new Authorizations())) {
        for (Entry<Key, Value> entry : s) {
            final Key key = entry.getKey();
            String row = key.getRow().toString();
            String cf = key.getColumnFamily().toString(), cq = key.getColumnQualifier().toString();
            String value = entry.getValue().toString();
            if (rowCounts.containsKey(row)) {
                rowCounts.put(row, rowCounts.get(row) + 1);
            } else {
                rowCounts.put(row, 1);
            }
            Assert.assertEquals(Integer.parseInt(cf) + Integer.parseInt(cq), Integer.parseInt(value));
        }
    }
    Collection<Text> clonedSplits = tops.listSplits(clonedTable);
    Set<Text> expectedSplits = Sets.newHashSet(new Text("b"), new Text("c"), new Text("d"));
    for (Text clonedSplit : clonedSplits) {
        Assert.assertTrue("Encountered unexpected split on the cloned table: " + clonedSplit, expectedSplits.remove(clonedSplit));
    }
    Assert.assertTrue("Did not find all expected splits on the cloned table: " + expectedSplits, expectedSplits.isEmpty());
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) DefaultKeySizeConstraint(org.apache.accumulo.core.constraints.DefaultKeySizeConstraint) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Example 2 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class CleanUpIT method run.

@Test
public void run() throws Exception {
    String tableName = getUniqueNames(1)[0];
    getConnector().tableOperations().create(tableName);
    BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", 1, "5");
    bw.addMutation(m1);
    bw.flush();
    try (Scanner scanner = getConnector().createScanner(tableName, new Authorizations())) {
        int count = 0;
        for (Entry<Key, Value> entry : scanner) {
            count++;
            if (!entry.getValue().toString().equals("5")) {
                Assert.fail("Unexpected value " + entry.getValue());
            }
        }
        Assert.assertEquals("Unexpected count", 1, count);
        int threadCount = countThreads();
        if (threadCount < 2) {
            printThreadNames();
            Assert.fail("Not seeing expected threads. Saw " + threadCount);
        }
        CleanUp.shutdownNow();
        Mutation m2 = new Mutation("r2");
        m2.put("cf1", "cq1", 1, "6");
        try {
            bw.addMutation(m1);
            bw.flush();
            Assert.fail("batch writer did not fail");
        } catch (Exception e) {
        }
        try {
            // expect this to fail also, want to clean up batch writer threads
            bw.close();
            Assert.fail("batch writer close not fail");
        } catch (Exception e) {
        }
        try {
            count = 0;
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            while (iter.hasNext()) {
                iter.next();
                count++;
            }
            Assert.fail("scanner did not fail");
        } catch (Exception e) {
        }
        threadCount = countThreads();
        if (threadCount > 0) {
            printThreadNames();
            Assert.fail("Threads did not go away. Saw " + threadCount);
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 3 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class VerifyIngest method verifyIngest.

public static void verifyIngest(Connector connector, Opts opts, ScannerOpts scanOpts) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    byte[][] bytevals = TestIngest.generateValues(opts.dataSize);
    Authorizations labelAuths = new Authorizations("L1", "L2", "G1", "GROUP2");
    connector.securityOperations().changeUserAuthorizations(opts.getPrincipal(), labelAuths);
    int expectedRow = opts.startRow;
    int expectedCol = 0;
    int recsRead = 0;
    long bytesRead = 0;
    long t1 = System.currentTimeMillis();
    byte[] randomValue = new byte[opts.dataSize];
    Random random = new Random();
    Key endKey = new Key(new Text("row_" + String.format("%010d", opts.rows + opts.startRow)));
    int errors = 0;
    while (expectedRow < (opts.rows + opts.startRow)) {
        if (opts.useGet) {
            Text rowKey = new Text("row_" + String.format("%010d", expectedRow + opts.startRow));
            Text colf = new Text(opts.columnFamily);
            Text colq = new Text("col_" + String.format("%07d", expectedCol));
            try (Scanner scanner = connector.createScanner("test_ingest", labelAuths)) {
                scanner.setBatchSize(1);
                Key startKey = new Key(rowKey, colf, colq);
                Range range = new Range(startKey, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL));
                scanner.setRange(range);
                // t.get(rowKey, column);
                byte[] val = null;
                Iterator<Entry<Key, Value>> iter = scanner.iterator();
                if (iter.hasNext()) {
                    val = iter.next().getValue().get();
                }
                byte[] ev;
                if (opts.random != null) {
                    ev = TestIngest.genRandomValue(random, randomValue, opts.random, expectedRow, expectedCol);
                } else {
                    ev = bytevals[expectedCol % bytevals.length];
                }
                if (val == null) {
                    log.error("Did not find {} {} {}", rowKey, colf, colq);
                    errors++;
                } else {
                    recsRead++;
                    bytesRead += val.length;
                    Value value = new Value(val);
                    if (value.compareTo(ev) != 0) {
                        log.error("unexpected value  ({} {} {} : saw {} expected {}", rowKey, colf, colq, value, new Value(ev));
                        errors++;
                    }
                }
                expectedCol++;
                if (expectedCol >= opts.cols) {
                    expectedCol = 0;
                    expectedRow++;
                }
            }
        } else {
            Key startKey = new Key(new Text("row_" + String.format("%010d", expectedRow)));
            try (Scanner scanner = connector.createScanner(opts.getTableName(), labelAuths)) {
                scanner.setBatchSize(scanOpts.scanBatchSize);
                scanner.setRange(new Range(startKey, endKey));
                for (int j = 0; j < opts.cols; j++) {
                    scanner.fetchColumn(new Text(opts.columnFamily), new Text("col_" + String.format("%07d", j)));
                }
                int recsReadBefore = recsRead;
                for (Entry<Key, Value> entry : scanner) {
                    recsRead++;
                    bytesRead += entry.getKey().getLength();
                    bytesRead += entry.getValue().getSize();
                    int rowNum = getRow(entry.getKey());
                    int colNum = getCol(entry.getKey());
                    if (rowNum != expectedRow) {
                        log.error("rowNum != expectedRow   {} != {}", rowNum, expectedRow);
                        errors++;
                        expectedRow = rowNum;
                    }
                    if (colNum != expectedCol) {
                        log.error("colNum != expectedCol  {} != {}  rowNum : {}", colNum, expectedCol, rowNum);
                        errors++;
                    }
                    if (expectedRow >= (opts.rows + opts.startRow)) {
                        log.error("expectedRow ({}) >= (ingestArgs.rows + ingestArgs.startRow)  ({}), get batch returned data passed end key", expectedRow, (opts.rows + opts.startRow));
                        errors++;
                        break;
                    }
                    byte[] value;
                    if (opts.random != null) {
                        value = TestIngest.genRandomValue(random, randomValue, opts.random, expectedRow, colNum);
                    } else {
                        value = bytevals[colNum % bytevals.length];
                    }
                    if (entry.getValue().compareTo(value) != 0) {
                        log.error("unexpected value, rowNum : {} colNum : {}", rowNum, colNum);
                        log.error(" saw = {} expected = {}", new String(entry.getValue().get()), new String(value));
                        errors++;
                    }
                    if (opts.timestamp >= 0 && entry.getKey().getTimestamp() != opts.timestamp) {
                        log.error("unexpected timestamp {}, rowNum : {} colNum : {}", entry.getKey().getTimestamp(), rowNum, colNum);
                        errors++;
                    }
                    expectedCol++;
                    if (expectedCol >= opts.cols) {
                        expectedCol = 0;
                        expectedRow++;
                    }
                }
                if (recsRead == recsReadBefore) {
                    log.warn("Scan returned nothing, breaking...");
                    break;
                }
            }
        }
    }
    long t2 = System.currentTimeMillis();
    if (errors > 0) {
        throw new AccumuloException("saw " + errors + " errors ");
    }
    if (expectedRow != (opts.rows + opts.startRow)) {
        throw new AccumuloException("Did not read expected number of rows. Saw " + (expectedRow - opts.startRow) + " expected " + opts.rows);
    } else {
        System.out.printf("%,12d records read | %,8d records/sec | %,12d bytes read | %,8d bytes/sec | %6.3f secs   %n", recsRead, (int) ((recsRead) / ((t2 - t1) / 1000.0)), bytesRead, (int) (bytesRead / ((t2 - t1) / 1000.0)), (t2 - t1) / 1000.0);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Entry(java.util.Map.Entry) Random(java.util.Random) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 4 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class ProxyServer method createScanner.

@Override
public String createScanner(ByteBuffer login, String tableName, ScanOptions opts) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
    try {
        Connector connector = getConnector(login);
        Authorizations auth;
        if (opts != null && opts.isSetAuthorizations()) {
            auth = getAuthorizations(opts.authorizations);
        } else {
            auth = connector.securityOperations().getUserAuthorizations(connector.whoami());
        }
        Scanner scanner = connector.createScanner(tableName, auth);
        if (opts != null) {
            if (opts.iterators != null) {
                for (org.apache.accumulo.proxy.thrift.IteratorSetting iter : opts.iterators) {
                    IteratorSetting is = new IteratorSetting(iter.getPriority(), iter.getName(), iter.getIteratorClass(), iter.getProperties());
                    scanner.addScanIterator(is);
                }
            }
            org.apache.accumulo.proxy.thrift.Range prange = opts.range;
            if (prange != null) {
                Range range = new Range(Util.fromThrift(prange.getStart()), prange.startInclusive, Util.fromThrift(prange.getStop()), prange.stopInclusive);
                scanner.setRange(range);
            }
            if (opts.columns != null) {
                for (ScanColumn col : opts.columns) {
                    if (col.isSetColQualifier())
                        scanner.fetchColumn(ByteBufferUtil.toText(col.colFamily), ByteBufferUtil.toText(col.colQualifier));
                    else
                        scanner.fetchColumnFamily(ByteBufferUtil.toText(col.colFamily));
                }
            }
        }
        UUID uuid = UUID.randomUUID();
        ScannerPlusIterator spi = new ScannerPlusIterator();
        spi.scanner = scanner;
        spi.iterator = scanner.iterator();
        scannerCache.put(uuid, spi);
        return uuid.toString();
    } catch (Exception e) {
        handleExceptionTNF(e);
        return null;
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) UnknownScanner(org.apache.accumulo.proxy.thrift.UnknownScanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) UUID(java.util.UUID)

Example 5 with Authorizations

use of org.apache.accumulo.core.security.Authorizations in project accumulo by apache.

the class MaxRowCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
    final Range range = getRange(cl, interpeter);
    final Authorizations auths = getAuths(cl, shellState);
    final Text startRow = range.getStartKey() == null ? null : range.getStartKey().getRow();
    final Text endRow = range.getEndKey() == null ? null : range.getEndKey().getRow();
    try {
        final Text max = shellState.getConnector().tableOperations().getMaxRow(tableName, auths, startRow, range.isStartKeyInclusive(), endRow, range.isEndKeyInclusive());
        if (max != null) {
            shellState.getReader().println(max.toString());
        }
    } catch (Exception e) {
        log.debug("Could not get shell state.", e);
    }
    return 0;
}
Also used : ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range)

Aggregations

Authorizations (org.apache.accumulo.core.security.Authorizations)221 Test (org.junit.Test)115 Scanner (org.apache.accumulo.core.client.Scanner)108 Key (org.apache.accumulo.core.data.Key)107 Value (org.apache.accumulo.core.data.Value)107 Text (org.apache.hadoop.io.Text)89 Mutation (org.apache.accumulo.core.data.Mutation)71 BatchWriter (org.apache.accumulo.core.client.BatchWriter)68 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)63 Connector (org.apache.accumulo.core.client.Connector)59 Range (org.apache.accumulo.core.data.Range)54 Map (java.util.Map)52 Entry (java.util.Map.Entry)41 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)39 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)35 ArrayList (java.util.ArrayList)30 AccumuloException (org.apache.accumulo.core.client.AccumuloException)30 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)30 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)29 IOException (java.io.IOException)19