Search in sources :

Example 1 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class ConcurrencyIT method runTest.

static void runTest(Connector c, String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException, Exception, InterruptedException {
    c.tableOperations().create(tableName);
    IteratorSetting is = new IteratorSetting(10, SlowIterator.class);
    SlowIterator.setSleepTime(is, 50);
    c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc, IteratorScope.majc));
    c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "1.0");
    BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
    for (int i = 0; i < 50; i++) {
        Mutation m = new Mutation(new Text(String.format("%06d", i)));
        m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(UTF_8)));
        bw.addMutation(m);
    }
    bw.flush();
    ScanTask st0 = new ScanTask(c, tableName, 300);
    st0.start();
    ScanTask st1 = new ScanTask(c, tableName, 100);
    st1.start();
    sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    c.tableOperations().flush(tableName, null, null, true);
    for (int i = 0; i < 50; i++) {
        Mutation m = new Mutation(new Text(String.format("%06d", i)));
        m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(UTF_8)));
        bw.addMutation(m);
    }
    bw.flush();
    ScanTask st2 = new ScanTask(c, tableName, 100);
    st2.start();
    st1.join();
    st2.join();
    if (st1.count != 50)
        throw new Exception("Thread 1 did not see 50, saw " + st1.count);
    if (st2.count != 50)
        throw new Exception("Thread 2 did not see 50, saw " + st2.count);
    ScanTask st3 = new ScanTask(c, tableName, 150);
    st3.start();
    sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    c.tableOperations().flush(tableName, null, null, false);
    st3.join();
    if (st3.count != 50)
        throw new Exception("Thread 3 did not see 50, saw " + st3.count);
    st0.join();
    if (st0.count != 50)
        throw new Exception("Thread 0 did not see 50, saw " + st0.count);
    bw.close();
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) 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) Mutation(org.apache.accumulo.core.data.Mutation) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 2 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class MockTableOperationsTest method testTableNotFound.

@Test
public void testTableNotFound() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    IteratorSetting setting = new IteratorSetting(100, "myvers", VersioningIterator.class);
    String t = "tableName";
    try {
        conn.tableOperations().attachIterator(t, setting);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().checkIteratorConflicts(t, setting, EnumSet.allOf(IteratorScope.class));
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().delete(t);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().getIteratorSetting(t, "myvers", IteratorScope.scan);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().getProperties(t);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().listSplits(t);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().listIterators(t);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().removeIterator(t, null, EnumSet.noneOf(IteratorScope.class));
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        conn.tableOperations().rename(t, t);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    conn.tableOperations().create(t);
    try {
        conn.tableOperations().create(t);
        Assert.fail();
    } catch (TableExistsException e) {
    }
    try {
        conn.tableOperations().rename(t, t);
        Assert.fail();
    } catch (TableExistsException e) {
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.Test)

Example 3 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableChangeStateIT method createData.

/**
 * Create the provided table and populate with some data using a batch writer. The table is scanned to ensure it was populated as expected.
 *
 * @param tableName
 *          the name of the table
 */
private void createData(final String tableName) {
    try {
        // create table.
        connector.tableOperations().create(tableName);
        BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
        // populate
        for (int i = 0; i < NUM_ROWS; i++) {
            Mutation m = new Mutation(new Text(String.format("%05d", i)));
            m.put(new Text("col" + Integer.toString((i % 3) + 1)), new Text("qual"), new Value("junk".getBytes(UTF_8)));
            bw.addMutation(m);
        }
        bw.close();
        long startTimestamp = System.nanoTime();
        try (Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY)) {
            int count = 0;
            for (Map.Entry<Key, Value> elt : scanner) {
                String expected = String.format("%05d", count);
                assert (elt.getKey().getRow().toString().equals(expected));
                count++;
            }
            log.trace("Scan time for {} rows {} ms", NUM_ROWS, TimeUnit.MILLISECONDS.convert((System.nanoTime() - startTimestamp), TimeUnit.NANOSECONDS));
            if (count != NUM_ROWS) {
                throw new IllegalStateException(String.format("Number of rows %1$d does not match expected %2$d", count, NUM_ROWS));
            }
        }
    } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException | TableExistsException ex) {
        throw new IllegalStateException("Create data failed with exception", ex);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key)

Example 4 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.

the class CopyTool method createTableIfNeeded.

/**
 * Creates the child table if it doesn't already exist.
 * @param childTableName the name of the child table.
 * @throws IOException
 */
public void createTableIfNeeded(final String childTableName) throws IOException {
    try {
        final Configuration childConfig = MergeToolMapper.getChildConfig(conf);
        final AccumuloRdfConfiguration childAccumuloRdfConfiguration = new AccumuloRdfConfiguration(childConfig);
        childAccumuloRdfConfiguration.setTablePrefix(childTablePrefix);
        final Connector childConnector = AccumuloRyaUtils.setupConnector(childAccumuloRdfConfiguration);
        if (!childConnector.tableOperations().exists(childTableName)) {
            log.info("Creating table: " + childTableName);
            childConnector.tableOperations().create(childTableName);
            log.info("Created table: " + childTableName);
            log.info("Granting authorizations to table: " + childTableName);
            childConnector.securityOperations().grantTablePermission(childUserName, childTableName, TablePermission.WRITE);
            log.info("Granted authorizations to table: " + childTableName);
        }
    } catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Configuration(org.apache.hadoop.conf.Configuration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 5 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.

the class MergeTool method createTempTableIfNeeded.

/**
 * Creates the temp child table if it doesn't already exist in the parent.
 * @param childTableName the name of the child table.
 * @throws IOException
 */
public void createTempTableIfNeeded(final String childTableName) throws IOException {
    try {
        final AccumuloRdfConfiguration accumuloRdfConfiguration = new AccumuloRdfConfiguration(conf);
        accumuloRdfConfiguration.setTablePrefix(childTablePrefix);
        final Connector connector = AccumuloRyaUtils.setupConnector(accumuloRdfConfiguration);
        if (!connector.tableOperations().exists(childTableName)) {
            log.info("Creating table: " + childTableName);
            connector.tableOperations().create(childTableName);
            log.info("Created table: " + childTableName);
            log.info("Granting authorizations to table: " + childTableName);
            final SecurityOperations secOps = connector.securityOperations();
            secOps.grantTablePermission(userName, childTableName, TablePermission.WRITE);
            log.info("Granted authorizations to table: " + childTableName);
            final Authorizations parentAuths = secOps.getUserAuthorizations(userName);
            // Add child authorizations so the temp parent table can be accessed.
            if (!parentAuths.equals(childAuthorizations)) {
                final List<String> childAuthList = findUniqueAuthsFromChild(parentAuths.toString(), childAuthorizations.toString());
                tempChildAuths = Joiner.on(",").join(childAuthList);
                log.info("Adding the authorization, \"" + tempChildAuths + "\", to the parent user, \"" + userName + "\"");
                final Authorizations newAuths = AccumuloRyaUtils.addUserAuths(userName, secOps, new Authorizations(tempChildAuths));
                secOps.changeUserAuthorizations(userName, newAuths);
            }
        }
    } catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Authorizations(org.apache.accumulo.core.security.Authorizations) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Aggregations

TableExistsException (org.apache.accumulo.core.client.TableExistsException)32 AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)17 Connector (org.apache.accumulo.core.client.Connector)9 IOException (java.io.IOException)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)6 Mutation (org.apache.accumulo.core.data.Mutation)6 ByteBuffer (java.nio.ByteBuffer)5 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 Key (org.apache.accumulo.core.data.Key)4 Text (org.apache.hadoop.io.Text)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)3