Search in sources :

Example 1 with WriterOptions

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

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

the class SimpleProxyBase method tableNotFound.

@Test
public void tableNotFound() throws Exception {
    final String doesNotExist = "doesNotExists";
    try {
        client.addConstraint(creds, doesNotExist, NumericValueConstraint.class.getName());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.addSplits(creds, doesNotExist, Collections.<ByteBuffer>emptySet());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "200"));
    try {
        client.attachIterator(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.cancelCompaction(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.checkIteratorConflicts(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.clearLocatorCache(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        final String TABLE_TEST = getUniqueNames(1)[0];
        client.cloneTable(creds, doesNotExist, TABLE_TEST, false, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.compactTable(creds, doesNotExist, null, null, null, true, false, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createBatchScanner(creds, doesNotExist, new BatchScanOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createScanner(creds, doesNotExist, new ScanOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createWriter(creds, doesNotExist, new WriterOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.deleteRows(creds, doesNotExist, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.deleteTable(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.exportTable(creds, doesNotExist, "/tmp");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.flushTable(creds, doesNotExist, null, null, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getIteratorSetting(creds, doesNotExist, "foo", IteratorScope.SCAN);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getLocalityGroups(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getMaxRow(creds, doesNotExist, Collections.<ByteBuffer>emptySet(), null, false, null, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getTableProperties(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.grantTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.hasTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        MiniAccumuloClusterImpl cluster = SharedMiniClusterBase.getCluster();
        Path base = cluster.getTemporaryPath();
        Path importDir = new Path(base, "importDir");
        Path failuresDir = new Path(base, "failuresDir");
        assertTrue(cluster.getFileSystem().mkdirs(importDir));
        assertTrue(cluster.getFileSystem().mkdirs(failuresDir));
        client.importDirectory(creds, doesNotExist, importDir.toString(), failuresDir.toString(), true);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.listConstraints(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.listSplits(creds, doesNotExist, 10000);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.mergeTablets(creds, doesNotExist, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.offlineTable(creds, doesNotExist, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.onlineTable(creds, doesNotExist, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeConstraint(creds, doesNotExist, 0);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeIterator(creds, doesNotExist, "name", EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.renameTable(creds, doesNotExist, "someTableName");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.revokeTablePermission(creds, "root", doesNotExist, TablePermission.ALTER_TABLE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.setTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey(), "0");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.splitRangeByTablets(creds, doesNotExist, client.getRowRange(ByteBuffer.wrap("row".getBytes(UTF_8))), 10);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.updateAndFlush(creds, doesNotExist, new HashMap<ByteBuffer, List<ColumnUpdate>>());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getDiskUsage(creds, Collections.singleton(doesNotExist));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.testTableClassLoad(creds, doesNotExist, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createConditionalWriter(creds, doesNotExist, new ConditionalWriterOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
}
Also used : Path(org.apache.hadoop.fs.Path) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) ByteBuffer(java.nio.ByteBuffer) TableNotFoundException(org.apache.accumulo.proxy.thrift.TableNotFoundException) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) ScanOptions(org.apache.accumulo.proxy.thrift.ScanOptions) BatchScanOptions(org.apache.accumulo.proxy.thrift.BatchScanOptions) ArrayList(java.util.ArrayList) List(java.util.List) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) VersioningIterator(org.apache.accumulo.core.iterators.user.VersioningIterator) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) SlowIterator(org.apache.accumulo.test.functional.SlowIterator) Test(org.junit.Test)

Example 3 with WriterOptions

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

the class ProxyDurabilityIT method testDurability.

@Test
public void testDurability() throws Exception {
    Connector c = getConnector();
    Properties props = new Properties();
    // Avoid issues with locally installed client configuration files with custom properties
    File emptyFile = Files.createTempFile(null, null).toFile();
    emptyFile.deleteOnExit();
    props.put("instance", c.getInstance().getInstanceName());
    props.put("zookeepers", c.getInstance().getZooKeepers());
    props.put("tokenClass", PasswordToken.class.getName());
    props.put("clientConfigurationFile", emptyFile.toString());
    TJSONProtocol.Factory protocol = new TJSONProtocol.Factory();
    int proxyPort = PortUtils.getRandomFreePort();
    final TServer proxyServer = Proxy.createProxyServer(HostAndPort.fromParts("localhost", proxyPort), protocol, props).server;
    while (!proxyServer.isServing()) sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    Client client = new TestProxyClient("localhost", proxyPort, protocol).proxy();
    Map<String, String> properties = new TreeMap<>();
    properties.put("password", ROOT_PASSWORD);
    ByteBuffer login = client.login("root", properties);
    String tableName = getUniqueNames(1)[0];
    client.createTable(login, tableName, true, TimeType.MILLIS);
    assertTrue(c.tableOperations().exists(tableName));
    WriterOptions options = new WriterOptions();
    options.setDurability(Durability.NONE);
    String writer = client.createWriter(login, tableName, options);
    Map<ByteBuffer, List<ColumnUpdate>> cells = new TreeMap<>();
    ColumnUpdate column = new ColumnUpdate(bytes("cf"), bytes("cq"));
    column.setValue("value".getBytes());
    cells.put(bytes("row"), Collections.singletonList(column));
    client.update(writer, cells);
    client.closeWriter(writer);
    assertEquals(1, count(tableName));
    restartTServer();
    assertEquals(0, count(tableName));
    ConditionalWriterOptions cfg = new ConditionalWriterOptions();
    cfg.setDurability(Durability.SYNC);
    String cwriter = client.createConditionalWriter(login, tableName, cfg);
    ConditionalUpdates updates = new ConditionalUpdates();
    updates.addToConditions(new Condition(new Column(bytes("cf"), bytes("cq"), bytes(""))));
    updates.addToUpdates(column);
    Map<ByteBuffer, ConditionalStatus> status = client.updateRowsConditionally(cwriter, Collections.singletonMap(bytes("row"), updates));
    assertEquals(ConditionalStatus.ACCEPTED, status.get(bytes("row")));
    assertEquals(1, count(tableName));
    restartTServer();
    assertEquals(1, count(tableName));
    proxyServer.stop();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) TServer(org.apache.thrift.server.TServer) Properties(java.util.Properties) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) ConditionalUpdates(org.apache.accumulo.proxy.thrift.ConditionalUpdates) Column(org.apache.accumulo.proxy.thrift.Column) List(java.util.List) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) Condition(org.apache.accumulo.proxy.thrift.Condition) TreeMap(java.util.TreeMap) ByteBuffer(java.nio.ByteBuffer) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) ConditionalStatus(org.apache.accumulo.proxy.thrift.ConditionalStatus) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with WriterOptions

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

the class SimpleProxyBase method testBatchWriter.

@Test
public void testBatchWriter() throws Exception {
    client.addConstraint(creds, tableName, NumericValueConstraint.class.getName());
    // zookeeper propagation time
    sleepUninterruptibly(ZOOKEEPER_PROPAGATION_TIME, TimeUnit.MILLISECONDS);
    // Take the table offline and online to force a config update
    client.offlineTable(creds, tableName, true);
    client.onlineTable(creds, tableName, true);
    WriterOptions writerOptions = new WriterOptions();
    writerOptions.setLatencyMs(10000);
    writerOptions.setMaxMemory(2);
    writerOptions.setThreads(1);
    writerOptions.setTimeoutMs(100000);
    Map<String, Integer> constraints = client.listConstraints(creds, tableName);
    while (!constraints.containsKey(NumericValueConstraint.class.getName())) {
        log.info("Constraints don't contain NumericValueConstraint");
        Thread.sleep(2000);
        constraints = client.listConstraints(creds, tableName);
    }
    boolean success = false;
    for (int i = 0; i < 15; i++) {
        String batchWriter = client.createWriter(creds, tableName, writerOptions);
        client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
        client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
        try {
            client.flush(batchWriter);
            log.debug("Constraint failed to fire. Waiting and retrying");
            Thread.sleep(5000);
            continue;
        } catch (MutationsRejectedException ex) {
        }
        try {
            client.closeWriter(batchWriter);
            log.debug("Constraint failed to fire. Waiting and retrying");
            Thread.sleep(5000);
            continue;
        } catch (MutationsRejectedException e) {
        }
        success = true;
        break;
    }
    if (!success) {
        fail("constraint did not fire");
    }
    client.removeConstraint(creds, tableName, 2);
    // Take the table offline and online to force a config update
    client.offlineTable(creds, tableName, true);
    client.onlineTable(creds, tableName, true);
    constraints = client.listConstraints(creds, tableName);
    while (constraints.containsKey(NumericValueConstraint.class.getName())) {
        log.info("Constraints still contains NumericValueConstraint");
        Thread.sleep(2000);
        constraints = client.listConstraints(creds, tableName);
    }
    assertScan(new String[][] {}, tableName);
    sleepUninterruptibly(ZOOKEEPER_PROPAGATION_TIME, TimeUnit.MILLISECONDS);
    writerOptions = new WriterOptions();
    writerOptions.setLatencyMs(10000);
    writerOptions.setMaxMemory(3000);
    writerOptions.setThreads(1);
    writerOptions.setTimeoutMs(100000);
    success = false;
    for (int i = 0; i < 15; i++) {
        try {
            String batchWriter = client.createWriter(creds, tableName, writerOptions);
            client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
            client.flush(batchWriter);
            client.closeWriter(batchWriter);
            success = true;
            break;
        } catch (MutationsRejectedException e) {
            log.info("Mutations were rejected, assuming constraint is still active", e);
            Thread.sleep(5000);
        }
    }
    if (!success) {
        fail("Failed to successfully write data after constraint was removed");
    }
    assertScan(new String[][] { { "row1", "cf", "cq", "x" } }, tableName);
    client.deleteTable(creds, tableName);
}
Also used : ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) MutationsRejectedException(org.apache.accumulo.proxy.thrift.MutationsRejectedException) Test(org.junit.Test)

Aggregations

WriterOptions (org.apache.accumulo.proxy.thrift.WriterOptions)4 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)3 List (java.util.List)3 ConditionalWriterOptions (org.apache.accumulo.proxy.thrift.ConditionalWriterOptions)3 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)2 ColumnUpdate (org.apache.accumulo.proxy.thrift.ColumnUpdate)2 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)2 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 ClusterUser (org.apache.accumulo.cluster.ClusterUser)1 Connector (org.apache.accumulo.core.client.Connector)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)1 VersioningIterator (org.apache.accumulo.core.iterators.user.VersioningIterator)1 UGIAssumingTransport (org.apache.accumulo.core.rpc.UGIAssumingTransport)1