Search in sources :

Example 1 with Key

use of org.apache.accumulo.proxy.thrift.Key in project accumulo by apache.

the class Util method toThrift.

public static Key toThrift(org.apache.accumulo.core.data.Key key) {
    Key pkey = new Key(ByteBuffer.wrap(key.getRow().getBytes()), ByteBuffer.wrap(key.getColumnFamily().getBytes()), ByteBuffer.wrap(key.getColumnQualifier().getBytes()), ByteBuffer.wrap(key.getColumnVisibility().getBytes()));
    pkey.setTimestamp(key.getTimestamp());
    return pkey;
}
Also used : Key(org.apache.accumulo.proxy.thrift.Key)

Example 2 with Key

use of org.apache.accumulo.proxy.thrift.Key in project accumulo by apache.

the class KerberosProxyIT method testProxyClient.

@Test
public void testProxyClient() throws Exception {
    ClusterUser rootUser = kdc.getRootUser();
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
    TSocket socket = new TSocket(hostname, proxyPort);
    log.info("Connecting to proxy with server primary '{}' running on {}", proxyPrimary, hostname);
    TSaslClientTransport transport = new TSaslClientTransport("GSSAPI", null, proxyPrimary, hostname, Collections.singletonMap("javax.security.sasl.qop", "auth"), null, socket);
    final UGIAssumingTransport ugiTransport = new UGIAssumingTransport(transport, ugi);
    // UGI transport will perform the doAs for us
    ugiTransport.open();
    AccumuloProxy.Client.Factory factory = new AccumuloProxy.Client.Factory();
    Client client = factory.getClient(new TCompactProtocol(ugiTransport), new TCompactProtocol(ugiTransport));
    // Will fail if the proxy can impersonate the client
    ByteBuffer login = client.login(rootUser.getPrincipal(), Collections.<String, String>emptyMap());
    // For all of the below actions, the proxy user doesn't have permission to do any of them, but the client user does.
    // The fact that any of them actually run tells us that impersonation is working.
    // Create a table
    String table = "table";
    if (!client.tableExists(login, table)) {
        client.createTable(login, table, true, TimeType.MILLIS);
    }
    // Write two records to the table
    String writer = client.createWriter(login, table, new WriterOptions());
    Map<ByteBuffer, List<ColumnUpdate>> updates = new HashMap<>();
    ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap("cf1".getBytes(UTF_8)), ByteBuffer.wrap("cq1".getBytes(UTF_8)));
    update.setValue(ByteBuffer.wrap("value1".getBytes(UTF_8)));
    updates.put(ByteBuffer.wrap("row1".getBytes(UTF_8)), Collections.singletonList(update));
    update = new ColumnUpdate(ByteBuffer.wrap("cf2".getBytes(UTF_8)), ByteBuffer.wrap("cq2".getBytes(UTF_8)));
    update.setValue(ByteBuffer.wrap("value2".getBytes(UTF_8)));
    updates.put(ByteBuffer.wrap("row2".getBytes(UTF_8)), Collections.singletonList(update));
    client.update(writer, updates);
    // Flush and close the writer
    client.flush(writer);
    client.closeWriter(writer);
    // Open a scanner to the table
    String scanner = client.createScanner(login, table, new ScanOptions());
    ScanResult results = client.nextK(scanner, 10);
    assertEquals(2, results.getResults().size());
    // Check the first key-value
    KeyValue kv = results.getResults().get(0);
    Key k = kv.key;
    ByteBuffer v = kv.value;
    assertEquals(ByteBuffer.wrap("row1".getBytes(UTF_8)), k.row);
    assertEquals(ByteBuffer.wrap("cf1".getBytes(UTF_8)), k.colFamily);
    assertEquals(ByteBuffer.wrap("cq1".getBytes(UTF_8)), k.colQualifier);
    assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility);
    assertEquals(ByteBuffer.wrap("value1".getBytes(UTF_8)), v);
    // And then the second
    kv = results.getResults().get(1);
    k = kv.key;
    v = kv.value;
    assertEquals(ByteBuffer.wrap("row2".getBytes(UTF_8)), k.row);
    assertEquals(ByteBuffer.wrap("cf2".getBytes(UTF_8)), k.colFamily);
    assertEquals(ByteBuffer.wrap("cq2".getBytes(UTF_8)), k.colQualifier);
    assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility);
    assertEquals(ByteBuffer.wrap("value2".getBytes(UTF_8)), v);
    // Close the scanner
    client.closeScanner(scanner);
    ugiTransport.close();
}
Also used : AccumuloProxy(org.apache.accumulo.proxy.thrift.AccumuloProxy) ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) HashMap(java.util.HashMap) LoggerFactory(org.slf4j.LoggerFactory) TSaslClientTransport(org.apache.thrift.transport.TSaslClientTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) ByteBuffer(java.nio.ByteBuffer) UGIAssumingTransport(org.apache.accumulo.core.rpc.UGIAssumingTransport) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) ClusterUser(org.apache.accumulo.cluster.ClusterUser) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) Key(org.apache.accumulo.proxy.thrift.Key) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.Test)

Example 3 with Key

use of org.apache.accumulo.proxy.thrift.Key in project accumulo by apache.

the class SimpleProxyBase method countFiles.

// scan metadata for file entries for the given table
private int countFiles(String table) throws Exception {
    Map<String, String> tableIdMap = client.tableIdMap(creds);
    String tableId = tableIdMap.get(table);
    Key start = new Key();
    start.row = s2bb(tableId + ";");
    Key end = new Key();
    end.row = s2bb(tableId + "<");
    end = client.getFollowing(end, PartialKey.ROW);
    ScanOptions opt = new ScanOptions();
    opt.range = new Range(start, true, end, false);
    opt.columns = Collections.singletonList(new ScanColumn(s2bb("file")));
    String scanner = client.createScanner(creds, MetadataTable.NAME, opt);
    int result = 0;
    while (true) {
        ScanResult more = client.nextK(scanner, 100);
        result += more.getResults().size();
        if (!more.more)
            break;
    }
    return result;
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) Range(org.apache.accumulo.proxy.thrift.Range) PartialKey(org.apache.accumulo.proxy.thrift.PartialKey) Key(org.apache.accumulo.proxy.thrift.Key) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint)

Example 4 with Key

use of org.apache.accumulo.proxy.thrift.Key in project accumulo by apache.

the class TestProxyClient method main.

public static void main(String[] args) throws Exception {
    TestProxyClient tpc = new TestProxyClient("localhost", 42424);
    String principal = "root";
    Map<String, String> props = new TreeMap<>();
    props.put("password", "secret");
    System.out.println("Logging in");
    ByteBuffer login = tpc.proxy.login(principal, props);
    System.out.println("Creating user: ");
    if (!tpc.proxy().listLocalUsers(login).contains("testuser")) {
        tpc.proxy().createLocalUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes(UTF_8)));
    }
    System.out.println("UserList: " + tpc.proxy().listLocalUsers(login));
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Deleting: ");
    String testTable = "testtableOMGOMGOMG";
    System.out.println("Creating: ");
    if (tpc.proxy().tableExists(login, testTable))
        tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    System.out.println("Listing: " + tpc.proxy().listTables(login));
    System.out.println("Writing: ");
    Date start = new Date();
    Date then = new Date();
    int maxInserts = 1000000;
    String format = "%1$05d";
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        if (i % 1000 == 0) {
            tpc.proxy().updateAndFlush(login, testTable, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().updateAndFlush(login, testTable, mutations);
    Date end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    tpc.proxy().deleteTable(login, testTable);
    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
    // Thread.sleep(1000);
    System.out.println("Writing async: ");
    start = new Date();
    then = new Date();
    mutations.clear();
    String writer = tpc.proxy().createWriter(login, testTable, null);
    for (int i = 0; i < maxInserts; i++) {
        String result = String.format(format, i);
        Key pkey = new Key();
        pkey.setRow(result.getBytes(UTF_8));
        ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(UTF_8)), ByteBuffer.wrap(("cq" + i).getBytes(UTF_8)));
        update.setValue(Util.randStringBuffer(10));
        mutations.put(ByteBuffer.wrap(result.getBytes(UTF_8)), Collections.singletonList(update));
        tpc.proxy().update(writer, mutations);
        mutations.clear();
    }
    end = new Date();
    System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
    start = end;
    System.out.println("Closing...");
    tpc.proxy().closeWriter(writer);
    end = new Date();
    System.out.println(" End of closing: " + (end.getTime() - start.getTime()));
    System.out.println("Reading: ");
    String regex = "cf1.*";
    IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
    RegExFilter.setRegexs(is, null, regex, null, null, false);
    String cookie = tpc.proxy().createScanner(login, testTable, null);
    int i = 0;
    start = new Date();
    then = new Date();
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        Date now = new Date();
        System.out.println(i + " " + (now.getTime() - then.getTime()));
        then = now;
        i += kvList.getResultsSize();
        // for (TKeyValue kv:kvList.getResults()) System.out.println(new Key(kv.getKey()));
        hasNext = kvList.isMore();
    }
    end = new Date();
    System.out.println("Total entries: " + i + " total time " + (end.getTime() - start.getTime()));
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) List(java.util.List) Key(org.apache.accumulo.proxy.thrift.Key)

Example 5 with Key

use of org.apache.accumulo.proxy.thrift.Key in project accumulo by apache.

the class TestProxyReadWrite method readWriteOneShotWithRange.

@Test
public void readWriteOneShotWithRange() throws Exception {
    int maxInserts = 100000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    for (int i = 0; i < maxInserts; i++) {
        addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    Key stop = new Key();
    stop.setRow("5".getBytes());
    ScanOptions opts = new ScanOptions();
    opts.range = new Range(null, false, stop, false);
    String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        i += kvList.getResultsSize();
        hasNext = kvList.isMore();
    }
    assertEquals(i, 50000);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) HashMap(java.util.HashMap) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) Range(org.apache.accumulo.proxy.thrift.Range) ByteBuffer(java.nio.ByteBuffer) Key(org.apache.accumulo.proxy.thrift.Key) Test(org.junit.Test)

Aggregations

Key (org.apache.accumulo.proxy.thrift.Key)6 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)5 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 List (java.util.List)4 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)3 Range (org.apache.accumulo.proxy.thrift.Range)3 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)3 Test (org.junit.Test)3 ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)2 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 ClusterUser (org.apache.accumulo.cluster.ClusterUser)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 UGIAssumingTransport (org.apache.accumulo.core.rpc.UGIAssumingTransport)1 AccumuloProxy (org.apache.accumulo.proxy.thrift.AccumuloProxy)1 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)1 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)1 PartialKey (org.apache.accumulo.proxy.thrift.PartialKey)1 ScanColumn (org.apache.accumulo.proxy.thrift.ScanColumn)1