Search in sources :

Example 1 with ScanResult

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

the class ProxyServer method nextK.

@Override
public ScanResult nextK(String scanner, int k) throws NoMoreEntriesException, UnknownScanner, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException {
    // fetch the scanner
    ScannerPlusIterator spi = getScanner(scanner);
    Iterator<Map.Entry<Key, Value>> batchScanner = spi.iterator;
    // synchronized to prevent race conditions
    synchronized (batchScanner) {
        ScanResult ret = new ScanResult();
        ret.setResults(new ArrayList<>());
        int numRead = 0;
        try {
            while (batchScanner.hasNext() && numRead < k) {
                Map.Entry<Key, Value> next = batchScanner.next();
                ret.addToResults(new KeyValue(Util.toThrift(next.getKey()), ByteBuffer.wrap(next.getValue().get())));
                numRead++;
            }
            ret.setMore(numRead == k);
        } catch (Exception ex) {
            closeScanner(scanner);
            throw new org.apache.accumulo.proxy.thrift.AccumuloSecurityException(ex.toString());
        }
        return ret;
    }
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) 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) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) Map(java.util.Map) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 2 with ScanResult

use of org.apache.accumulo.proxy.thrift.ScanResult 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 ScanResult

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

the class SimpleProxyBase method assertScan.

private void assertScan(String[][] expected, String table) throws Exception {
    String scid = client.createScanner(creds, table, new ScanOptions());
    ScanResult keyValues = client.nextK(scid, expected.length + 1);
    assertEquals("Saw " + keyValues.results, expected.length, keyValues.results.size());
    assertFalse(keyValues.more);
    for (int i = 0; i < keyValues.results.size(); i++) {
        checkKey(expected[i][0], expected[i][1], expected[i][2], expected[i][3], keyValues.results.get(i));
    }
    client.closeScanner(scid);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint)

Example 4 with ScanResult

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

the class TestProxyReadWrite method testVisibility.

@Test
public void testVisibility() throws Exception {
    Set<ByteBuffer> auths = new HashSet<>();
    auths.add(ByteBuffer.wrap("even".getBytes()));
    tpc.proxy().changeUserAuthorizations(userpass, "root", auths);
    int maxInserts = 10000;
    Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
    String format = "%1$05d";
    String writer = tpc.proxy().createWriter(userpass, testtable, null);
    for (int i = 0; i < maxInserts; i++) {
        if (i % 2 == 0)
            addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, "even", Util.randString(10));
        else
            addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, "odd", Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().update(writer, mutations);
            mutations.clear();
        }
    }
    tpc.proxy().flush(writer);
    tpc.proxy().closeWriter(writer);
    ScanOptions opts = new ScanOptions();
    opts.authorizations = auths;
    String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
    int i = 0;
    boolean hasNext = true;
    int k = 1000;
    int numRead = 0;
    while (hasNext) {
        ScanResult kvList = tpc.proxy().nextK(cookie, k);
        for (KeyValue kv : kvList.getResults()) {
            assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
            i += 2;
            numRead++;
        }
        hasNext = kvList.isMore();
    }
    assertEquals(maxInserts / 2, numRead);
}
Also used : ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) HashMap(java.util.HashMap) List(java.util.List) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) ByteBuffer(java.nio.ByteBuffer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ScanResult

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

the class TestProxyReadWrite method readWriteBatchOneShotWithFullColumn.

/**
 * Insert 100000 cells which have as the row [0..99999] (padded with zeros). Set a columnFamily + columnQualififer so only the entries with specified column
 * come back (there should be 50,000)
 */
@Test
public void readWriteBatchOneShotWithFullColumn() 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 % 2), "cq" + (i % 2), Util.randString(10));
        if (i % 1000 == 0 || i == maxInserts - 1) {
            tpc.proxy().updateAndFlush(userpass, testtable, mutations);
            mutations.clear();
        }
    }
    BatchScanOptions options = new BatchScanOptions();
    ScanColumn sc = new ScanColumn();
    sc.colFamily = ByteBuffer.wrap("cf0".getBytes());
    sc.colQualifier = ByteBuffer.wrap("cq0".getBytes());
    options.columns = Collections.singletonList(sc);
    String cookie = tpc.proxy().createBatchScanner(userpass, testtable, options);
    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) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) List(java.util.List) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)16 ByteBuffer (java.nio.ByteBuffer)13 HashMap (java.util.HashMap)12 List (java.util.List)12 Test (org.junit.Test)11 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)10 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)8 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)8 Key (org.apache.accumulo.proxy.thrift.Key)5 ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)3 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)3 Range (org.apache.accumulo.proxy.thrift.Range)3 ScanColumn (org.apache.accumulo.proxy.thrift.ScanColumn)3 Value (org.apache.accumulo.core.data.Value)2 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1