Search in sources :

Example 96 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility 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 97 with ColumnVisibility

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

the class VisibilityIT method mputDelete.

private void mputDelete(Mutation m, String cf, String cq, String cv) {
    ColumnVisibility le = new ColumnVisibility(cv.getBytes(UTF_8));
    m.putDelete(new Text(cf), new Text(cq), le);
}
Also used : Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility)

Example 98 with ColumnVisibility

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

the class VisibilityIT method mput.

private void mput(Mutation m, String cf, String cq, String cv, String val) {
    ColumnVisibility le = new ColumnVisibility(cv.getBytes(UTF_8));
    m.put(new Text(cf), new Text(cq), le, new Value(val.getBytes(UTF_8)));
}
Also used : Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility)

Example 99 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.

the class ReadWriteExample method createEntries.

private void createEntries(Opts opts) throws Exception {
    if (opts.createEntries || opts.deleteEntries) {
        BatchWriterConfig cfg = new BatchWriterConfig();
        cfg.setDurability(opts.durability);
        BatchWriter writer = conn.createBatchWriter(opts.getTableName(), cfg);
        ColumnVisibility cv = new ColumnVisibility(opts.auths.toString().replace(',', '|'));
        Text cf = new Text("datatypes");
        Text cq = new Text("xml");
        byte[] row = { 'h', 'e', 'l', 'l', 'o', '\0' };
        byte[] value = { 'w', 'o', 'r', 'l', 'd', '\0' };
        for (int i = 0; i < 10; i++) {
            row[row.length - 1] = (byte) i;
            Mutation m = new Mutation(new Text(row));
            if (opts.deleteEntries) {
                m.putDelete(cf, cq, cv);
            }
            if (opts.createEntries) {
                value[value.length - 1] = (byte) i;
                m.put(cf, cq, cv, new Value(value));
            }
            writer.addMutation(m);
        }
        writer.close();
    }
}
Also used : 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)

Example 100 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.

the class CountIT method test.

@Test
public void test() throws Exception {
    Scanner scanner = conn.createScanner(tableName, new Authorizations());
    scanner.fetchColumn(new Text("dir"), new Text("counts"));
    assertFalse(scanner.iterator().hasNext());
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
    fc.run();
    ArrayList<Pair<String, String>> expected = new ArrayList<>();
    expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
    expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
    expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
    expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));
    int i = 0;
    for (Entry<Key, Value> e : scanner) {
        assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
        assertEquals(e.getValue().toString(), expected.get(i).getSecond());
        i++;
    }
    assertEquals(i, expected.size());
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) Value(org.apache.accumulo.core.data.Value) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) Pair(org.apache.accumulo.core.util.Pair) Test(org.junit.Test)

Aggregations

ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)131 Mutation (org.apache.accumulo.core.data.Mutation)57 Text (org.apache.hadoop.io.Text)57 Value (org.apache.accumulo.core.data.Value)52 Key (org.apache.accumulo.core.data.Key)39 Test (org.junit.Test)37 BatchWriter (org.apache.accumulo.core.client.BatchWriter)28 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)20 Authorizations (org.apache.accumulo.core.security.Authorizations)17 ArrayList (java.util.ArrayList)16 Entry (java.util.Map.Entry)16 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 Scanner (org.apache.accumulo.core.client.Scanner)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)12 Configuration (org.apache.hadoop.conf.Configuration)12 Connector (org.apache.accumulo.core.client.Connector)10 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10 TMutation (org.apache.accumulo.core.data.thrift.TMutation)10 Element (uk.gov.gchq.gaffer.data.element.Element)9