Search in sources :

Example 1 with IteratorSetting

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

the class SimpleProxyBase method attachIteratorsWithScans.

@Test
public void attachIteratorsWithScans() throws Exception {
    if (client.tableExists(creds, "slow")) {
        client.deleteTable(creds, "slow");
    }
    // create a table that's very slow, so we can look for scans
    client.createTable(creds, "slow", true, TimeType.MILLIS);
    IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "250"));
    client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
    // Should take 10 seconds to read every record
    for (int i = 0; i < 40; i++) {
        client.updateAndFlush(creds, "slow", mutation("row" + i, "cf", "cq", "value"));
    }
    // scan
    Thread t = new Thread() {

        @Override
        public void run() {
            String scanner;
            TestProxyClient proxyClient2 = null;
            try {
                if (isKerberosEnabled()) {
                    UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
                    proxyClient2 = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
                } else {
                    proxyClient2 = new TestProxyClient(hostname, proxyPort, factory);
                }
                Client client2 = proxyClient2.proxy();
                scanner = client2.createScanner(creds, "slow", null);
                client2.nextK(scanner, 10);
                client2.closeScanner(scanner);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (null != proxyClient2) {
                    proxyClient2.close();
                }
            }
        }
    };
    t.start();
    // look for the scan many times
    List<ActiveScan> scans = new ArrayList<>();
    for (int i = 0; i < 100 && scans.isEmpty(); i++) {
        for (String tserver : client.getTabletServers(creds)) {
            List<ActiveScan> scansForServer = client.getActiveScans(creds, tserver);
            for (ActiveScan scan : scansForServer) {
                if (clientPrincipal.equals(scan.getUser())) {
                    scans.add(scan);
                }
            }
            if (!scans.isEmpty())
                break;
            sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        }
    }
    t.join();
    assertFalse("Expected to find scans, but found none", scans.isEmpty());
    boolean found = false;
    Map<String, String> map = null;
    for (int i = 0; i < scans.size() && !found; i++) {
        ActiveScan scan = scans.get(i);
        if (clientPrincipal.equals(scan.getUser())) {
            assertTrue(ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
            assertEquals(ScanType.SINGLE, scan.getType());
            assertEquals("slow", scan.getTable());
            map = client.tableIdMap(creds);
            assertEquals(map.get("slow"), scan.getExtent().tableId);
            assertTrue(scan.getExtent().endRow == null);
            assertTrue(scan.getExtent().prevEndRow == null);
            found = true;
        }
    }
    assertTrue("Could not find a scan against the 'slow' table", found);
}
Also used : ActiveScan(org.apache.accumulo.proxy.thrift.ActiveScan) ArrayList(java.util.ArrayList) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) TableNotFoundException(org.apache.accumulo.proxy.thrift.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.proxy.thrift.MutationsRejectedException) NamespaceNotEmptyException(org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.proxy.thrift.AccumuloSecurityException) TException(org.apache.thrift.TException) NamespaceExistsException(org.apache.accumulo.proxy.thrift.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.proxy.thrift.NamespaceNotFoundException) TApplicationException(org.apache.thrift.TApplicationException) TableExistsException(org.apache.accumulo.proxy.thrift.TableExistsException) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) SlowIterator(org.apache.accumulo.test.functional.SlowIterator) Test(org.junit.Test)

Example 2 with IteratorSetting

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

the class SimpleProxyBase method namespaceNotFound.

@Test
public void namespaceNotFound() throws Exception {
    final String doesNotExist = "doesNotExists";
    try {
        client.deleteNamespace(creds, doesNotExist);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.renameNamespace(creds, doesNotExist, "abcdefg");
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.setNamespaceProperty(creds, doesNotExist, "table.compaction.major.ratio", "4");
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.removeNamespaceProperty(creds, doesNotExist, "table.compaction.major.ratio");
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.getNamespaceProperties(creds, doesNotExist);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(), Collections.emptyMap());
        client.attachNamespaceIterator(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.removeNamespaceIterator(creds, doesNotExist, "DebugTheThings", EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.getNamespaceIteratorSetting(creds, doesNotExist, "DebugTheThings", IteratorScope.SCAN);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.listNamespaceIterators(creds, doesNotExist);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(), Collections.emptyMap());
        client.checkNamespaceIteratorConflicts(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.addNamespaceConstraint(creds, doesNotExist, MaxMutationSize.class.getName());
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.removeNamespaceConstraint(creds, doesNotExist, 1);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.listNamespaceConstraints(creds, doesNotExist);
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
    try {
        client.testNamespaceClassLoad(creds, doesNotExist, DebugIterator.class.getName(), SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (NamespaceNotFoundException ex) {
    }
}
Also used : DebugIterator(org.apache.accumulo.core.iterators.DebugIterator) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) MaxMutationSize(org.apache.accumulo.test.constraints.MaxMutationSize) NamespaceNotFoundException(org.apache.accumulo.proxy.thrift.NamespaceNotFoundException) Test(org.junit.Test)

Example 3 with IteratorSetting

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

the class SimpleProxyBase method testConditionalWriter.

@Test
public void testConditionalWriter() throws Exception {
    log.debug("Adding constraint {} to {}", tableName, NumericValueConstraint.class.getName());
    client.addConstraint(creds, tableName, NumericValueConstraint.class.getName());
    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);
    while (!client.listConstraints(creds, tableName).containsKey(NumericValueConstraint.class.getName())) {
        log.info("Failed to see constraint");
        Thread.sleep(1000);
    }
    String cwid = client.createConditionalWriter(creds, tableName, new ConditionalWriterOptions());
    Map<ByteBuffer, ConditionalUpdates> updates = new HashMap<>();
    updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", 10, "1"), newColUpdate("data", "img", "73435435"))));
    Map<ByteBuffer, ConditionalStatus> results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
    assertScan(new String[][] { { "00345", "data", "img", "73435435" }, { "00345", "meta", "seq", "1" } }, tableName);
    // test not setting values on conditions
    updates.clear();
    updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", "2"))));
    updates.put(s2bb("00346"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", "1"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(2, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00345")));
    assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00346")));
    assertScan(new String[][] { { "00345", "data", "img", "73435435" }, { "00345", "meta", "seq", "1" }, { "00346", "meta", "seq", "1" } }, tableName);
    // test setting values on conditions
    updates.clear();
    updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", "1")), Arrays.asList(newColUpdate("meta", "seq", 20, "2"), newColUpdate("data", "img", "567890"))));
    updates.put(s2bb("00346"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", "2")), Arrays.asList(newColUpdate("meta", "seq", "3"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(2, results.size());
    assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00346")));
    assertScan(new String[][] { { "00345", "data", "img", "567890" }, { "00345", "meta", "seq", "2" }, { "00346", "meta", "seq", "1" } }, tableName);
    // test setting timestamp on condition to a non-existant version
    updates.clear();
    updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", 10, "2")), Arrays.asList(newColUpdate("meta", "seq", 30, "3"), newColUpdate("data", "img", "1234567890"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00345")));
    assertScan(new String[][] { { "00345", "data", "img", "567890" }, { "00345", "meta", "seq", "2" }, { "00346", "meta", "seq", "1" } }, tableName);
    // test setting timestamp to an existing version
    updates.clear();
    updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", 20, "2")), Arrays.asList(newColUpdate("meta", "seq", 30, "3"), newColUpdate("data", "img", "1234567890"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" } }, tableName);
    // run test w/ condition that has iterators
    // following should fail w/o iterator
    client.updateAndFlush(creds, tableName, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
    client.updateAndFlush(creds, tableName, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
    client.updateAndFlush(creds, tableName, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
    updates.clear();
    updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "count", "3")), Arrays.asList(newColUpdate("data", "img", "1234567890"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" } }, tableName);
    // following test w/ iterator setup should succeed
    Condition iterCond = newCondition("data", "count", "3");
    Map<String, String> props = new HashMap<>();
    props.put("type", "STRING");
    props.put("columns", "data:count");
    IteratorSetting is = new IteratorSetting(1, "sumc", SummingCombiner.class.getName(), props);
    iterCond.setIterators(Arrays.asList(is));
    updates.clear();
    updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(iterCond), Arrays.asList(newColUpdate("data", "img", "1234567890"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00347")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" }, { "00347", "data", "img", "1234567890" } }, tableName);
    ConditionalStatus status = null;
    for (int i = 0; i < 30; i++) {
        // test a mutation that violated a constraint
        updates.clear();
        updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890")), Arrays.asList(newColUpdate("data", "count", "A"))));
        results = client.updateRowsConditionally(cwid, updates);
        assertEquals(1, results.size());
        status = results.get(s2bb("00347"));
        if (ConditionalStatus.VIOLATED != status) {
            log.info("ConditionalUpdate was not rejected by server due to table constraint. Sleeping and retrying");
            Thread.sleep(5000);
            continue;
        }
        assertEquals(ConditionalStatus.VIOLATED, status);
        break;
    }
    // Final check to make sure we succeeded and didn't exceed the retries
    assertEquals(ConditionalStatus.VIOLATED, status);
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" }, { "00347", "data", "img", "1234567890" } }, tableName);
    // run test with two conditions
    // both conditions should fail
    updates.clear();
    updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "565"), newCondition("data", "count", "2")), Arrays.asList(newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" }, { "00347", "data", "img", "1234567890" } }, tableName);
    // one condition should fail
    updates.clear();
    updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890"), newCondition("data", "count", "2")), Arrays.asList(newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" }, { "00347", "data", "img", "1234567890" } }, tableName);
    // one condition should fail
    updates.clear();
    updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "565"), newCondition("data", "count", "1")), Arrays.asList(newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
    results = client.updateRowsConditionally(cwid, updates);
    assertEquals(1, results.size());
    assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "1" }, { "00347", "data", "img", "1234567890" } }, tableName);
    // both conditions should succeed
    ConditionalStatus result = client.updateRowConditionally(creds, tableName, s2bb("00347"), new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890"), newCondition("data", "count", "1")), Arrays.asList(newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
    assertEquals(ConditionalStatus.ACCEPTED, result);
    assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "3" }, { "00347", "data", "img", "0987654321" } }, tableName);
    client.closeConditionalWriter(cwid);
    try {
        client.updateRowsConditionally(cwid, updates);
        fail("conditional writer not closed");
    } catch (UnknownWriter uk) {
    }
    String principal;
    ClusterUser cwuser = null;
    if (isKerberosEnabled()) {
        cwuser = getKdc().getClientPrincipal(1);
        principal = cwuser.getPrincipal();
        client.createLocalUser(creds, principal, s2bb("unused"));
    } else {
        principal = "cwuser";
        // run test with colvis
        client.createLocalUser(creds, principal, s2bb("bestpasswordever"));
    }
    client.changeUserAuthorizations(creds, principal, Collections.singleton(s2bb("A")));
    client.grantTablePermission(creds, principal, tableName, TablePermission.WRITE);
    client.grantTablePermission(creds, principal, tableName, TablePermission.READ);
    TestProxyClient cwuserProxyClient = null;
    Client origClient = null;
    Map<String, String> cwProperties;
    if (isKerberosEnabled()) {
        UserGroupInformation.loginUserFromKeytab(cwuser.getPrincipal(), cwuser.getKeytab().getAbsolutePath());
        final UserGroupInformation cwuserUgi = UserGroupInformation.getCurrentUser();
        // Re-login in and make a new connection. Can't use the previous one
        cwuserProxyClient = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, cwuserUgi);
        origClient = client;
        client = cwuserProxyClient.proxy();
        cwProperties = Collections.emptyMap();
    } else {
        cwProperties = Collections.singletonMap("password", "bestpasswordever");
    }
    try {
        ByteBuffer cwCreds = client.login(principal, cwProperties);
        cwid = client.createConditionalWriter(cwCreds, tableName, new ConditionalWriterOptions().setAuthorizations(Collections.singleton(s2bb("A"))));
        updates.clear();
        updates.put(s2bb("00348"), new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("A")))), Arrays.asList(newColUpdate("data", "seq", "1"), newColUpdate("data", "c", "1").setColVisibility(s2bb("A")))));
        updates.put(s2bb("00349"), new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("B")))), Arrays.asList(newColUpdate("data", "seq", "1"))));
        results = client.updateRowsConditionally(cwid, updates);
        assertEquals(2, results.size());
        assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00348")));
        assertEquals(ConditionalStatus.INVISIBLE_VISIBILITY, results.get(s2bb("00349")));
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
            client = origClient;
        }
        // Verify that the original user can't see the updates with visibilities set
        assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "3" }, { "00347", "data", "img", "0987654321" }, { "00348", "data", "seq", "1" } }, tableName);
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(cwuser.getPrincipal(), cwuser.getKeytab().getAbsolutePath());
            client = cwuserProxyClient.proxy();
        }
        updates.clear();
        updates.clear();
        updates.put(s2bb("00348"), new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("A"))).setValue(s2bb("0"))), Arrays.asList(newColUpdate("data", "seq", "2"), newColUpdate("data", "c", "2").setColVisibility(s2bb("A")))));
        results = client.updateRowsConditionally(cwid, updates);
        assertEquals(1, results.size());
        assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00348")));
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
            client = origClient;
        }
        // Same results as the original user
        assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "3" }, { "00347", "data", "img", "0987654321" }, { "00348", "data", "seq", "1" } }, tableName);
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(cwuser.getPrincipal(), cwuser.getKeytab().getAbsolutePath());
            client = cwuserProxyClient.proxy();
        }
        updates.clear();
        updates.put(s2bb("00348"), new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("A"))).setValue(s2bb("1"))), Arrays.asList(newColUpdate("data", "seq", "2"), newColUpdate("data", "c", "2").setColVisibility(s2bb("A")))));
        results = client.updateRowsConditionally(cwid, updates);
        assertEquals(1, results.size());
        assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00348")));
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
            client = origClient;
        }
        assertScan(new String[][] { { "00345", "data", "img", "1234567890" }, { "00345", "meta", "seq", "3" }, { "00346", "meta", "seq", "1" }, { "00347", "data", "count", "3" }, { "00347", "data", "img", "0987654321" }, { "00348", "data", "seq", "2" } }, tableName);
        if (isKerberosEnabled()) {
            UserGroupInformation.loginUserFromKeytab(cwuser.getPrincipal(), cwuser.getKeytab().getAbsolutePath());
            client = cwuserProxyClient.proxy();
        }
        client.closeConditionalWriter(cwid);
        try {
            client.updateRowsConditionally(cwid, updates);
            fail("conditional writer not closed");
        } catch (UnknownWriter uk) {
        }
    } finally {
        if (isKerberosEnabled()) {
            // Close the other client
            if (null != cwuserProxyClient) {
                cwuserProxyClient.close();
            }
            UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
            // Re-login and restore the original client
            client = origClient;
        }
        client.dropLocalUser(creds, principal);
    }
}
Also used : Condition(org.apache.accumulo.proxy.thrift.Condition) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) UnknownWriter(org.apache.accumulo.proxy.thrift.UnknownWriter) ConditionalUpdates(org.apache.accumulo.proxy.thrift.ConditionalUpdates) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) Column(org.apache.accumulo.proxy.thrift.Column) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) ConditionalStatus(org.apache.accumulo.proxy.thrift.ConditionalStatus) SummingCombiner(org.apache.accumulo.core.iterators.user.SummingCombiner) ClusterUser(org.apache.accumulo.cluster.ClusterUser) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 4 with IteratorSetting

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

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

the class SimpleProxyBase method namespaceOperations.

@Test
public void namespaceOperations() throws Exception {
    // default namespace and accumulo namespace
    assertEquals("System namespace is wrong", client.systemNamespace(), Namespace.ACCUMULO);
    assertEquals("Default namespace is wrong", client.defaultNamespace(), Namespace.DEFAULT);
    // namespace existance and namespace listing
    assertTrue("Namespace created during setup should exist", client.namespaceExists(creds, namespaceName));
    assertTrue("Namespace listing should contain namespace created during setup", client.listNamespaces(creds).contains(namespaceName));
    // create new namespace
    String newNamespace = "foobar";
    client.createNamespace(creds, newNamespace);
    assertTrue("Namespace just created should exist", client.namespaceExists(creds, newNamespace));
    assertTrue("Namespace listing should contain just created", client.listNamespaces(creds).contains(newNamespace));
    // rename the namespace
    String renamedNamespace = "foobar_renamed";
    client.renameNamespace(creds, newNamespace, renamedNamespace);
    assertTrue("Renamed namespace should exist", client.namespaceExists(creds, renamedNamespace));
    assertTrue("Namespace listing should contain renamed namespace", client.listNamespaces(creds).contains(renamedNamespace));
    assertFalse("Original namespace should no longer exist", client.namespaceExists(creds, newNamespace));
    assertFalse("Namespace listing should no longer contain original namespace", client.listNamespaces(creds).contains(newNamespace));
    // delete the namespace
    client.deleteNamespace(creds, renamedNamespace);
    assertFalse("Renamed namespace should no longer exist", client.namespaceExists(creds, renamedNamespace));
    assertFalse("Namespace listing should no longer contain renamed namespace", client.listNamespaces(creds).contains(renamedNamespace));
    // namespace properties
    Map<String, String> cfg = client.getNamespaceProperties(creds, namespaceName);
    String defaultProp = cfg.get("table.compaction.major.ratio");
    // let's make sure we are setting this value to something different than default...
    assertNotEquals(defaultProp, "10");
    client.setNamespaceProperty(creds, namespaceName, "table.compaction.major.ratio", "10");
    for (int i = 0; i < 5; i++) {
        cfg = client.getNamespaceProperties(creds, namespaceName);
        if ("10".equals(cfg.get("table.compaction.major.ratio"))) {
            break;
        }
        sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    }
    assertTrue("Namespace should contain table.compaction.major.ratio property", client.getNamespaceProperties(creds, namespaceName).containsKey("table.compaction.major.ratio"));
    assertEquals("Namespace property table.compaction.major.ratio property should equal 10", client.getNamespaceProperties(creds, namespaceName).get("table.compaction.major.ratio"), "10");
    client.removeNamespaceProperty(creds, namespaceName, "table.compaction.major.ratio");
    for (int i = 0; i < 5; i++) {
        cfg = client.getNamespaceProperties(creds, namespaceName);
        if (!defaultProp.equals(cfg.get("table.compaction.major.ratio"))) {
            break;
        }
        sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    }
    assertEquals("Namespace should have default value for table.compaction.major.ratio", defaultProp, cfg.get("table.compaction.major.ratio"));
    // namespace ID map
    assertTrue("Namespace ID map should contain accumulo", client.namespaceIdMap(creds).containsKey("accumulo"));
    assertTrue("Namespace ID map should contain namespace created during setup", client.namespaceIdMap(creds).containsKey(namespaceName));
    // namespace iterators
    IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(), Collections.emptyMap());
    client.attachNamespaceIterator(creds, namespaceName, setting, EnumSet.of(IteratorScope.SCAN));
    assertEquals("Wrong iterator setting returned", setting, client.getNamespaceIteratorSetting(creds, namespaceName, "DebugTheThings", IteratorScope.SCAN));
    assertTrue("Namespace iterator settings should contain iterator just added", client.listNamespaceIterators(creds, namespaceName).containsKey("DebugTheThings"));
    assertEquals("Namespace iterator listing should contain iterator scope just added", EnumSet.of(IteratorScope.SCAN), client.listNamespaceIterators(creds, namespaceName).get("DebugTheThings"));
    client.checkNamespaceIteratorConflicts(creds, namespaceName, setting, EnumSet.of(IteratorScope.MAJC));
    client.removeNamespaceIterator(creds, namespaceName, "DebugTheThings", EnumSet.of(IteratorScope.SCAN));
    assertFalse("Namespace iterator settings should contain iterator just added", client.listNamespaceIterators(creds, namespaceName).containsKey("DebugTheThings"));
    // namespace constraints
    int id = client.addNamespaceConstraint(creds, namespaceName, MaxMutationSize.class.getName());
    assertTrue("Namespace should contain max mutation size constraint", client.listNamespaceConstraints(creds, namespaceName).containsKey(MaxMutationSize.class.getName()));
    assertEquals("Namespace max mutation size constraint id is wrong", id, (int) client.listNamespaceConstraints(creds, namespaceName).get(MaxMutationSize.class.getName()));
    client.removeNamespaceConstraint(creds, namespaceName, id);
    assertFalse("Namespace should no longer contain max mutation size constraint", client.listNamespaceConstraints(creds, namespaceName).containsKey(MaxMutationSize.class.getName()));
    // namespace class load
    assertTrue("Namespace class load should work", client.testNamespaceClassLoad(creds, namespaceName, DebugIterator.class.getName(), SortedKeyValueIterator.class.getName()));
    assertFalse("Namespace class load should not work", client.testNamespaceClassLoad(creds, namespaceName, "foo.bar", SortedKeyValueIterator.class.getName()));
}
Also used : DebugIterator(org.apache.accumulo.core.iterators.DebugIterator) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) MaxMutationSize(org.apache.accumulo.test.constraints.MaxMutationSize) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) Test(org.junit.Test)

Aggregations

IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)14 Test (org.junit.Test)14 IteratorScope (org.apache.accumulo.proxy.thrift.IteratorScope)9 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 List (java.util.List)4 DebugIterator (org.apache.accumulo.core.iterators.DebugIterator)4 BatchScanOptions (org.apache.accumulo.proxy.thrift.BatchScanOptions)4 NamespaceNotFoundException (org.apache.accumulo.proxy.thrift.NamespaceNotFoundException)4 ScanOptions (org.apache.accumulo.proxy.thrift.ScanOptions)4 TableNotFoundException (org.apache.accumulo.proxy.thrift.TableNotFoundException)4 ArrayList (java.util.ArrayList)3 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)3 AccumuloSecurityException (org.apache.accumulo.proxy.thrift.AccumuloSecurityException)3 KeyValue (org.apache.accumulo.proxy.thrift.KeyValue)3 MutationsRejectedException (org.apache.accumulo.proxy.thrift.MutationsRejectedException)3 NamespaceExistsException (org.apache.accumulo.proxy.thrift.NamespaceExistsException)3 NamespaceNotEmptyException (org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException)3 ScanResult (org.apache.accumulo.proxy.thrift.ScanResult)3