Search in sources :

Example 86 with TableNotFoundException

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

the class AccumuloParentMetadataRepository method writeMetadata.

private void writeMetadata(final MergeParentMetadata metadata) throws MergerException {
    BatchWriter writer = null;
    try {
        // Write each result.
        final List<Mutation> mutations = makeWriteMetadataMutations(metadata);
        writer = connector.createBatchWriter(mergeParentMetadataTableName, new BatchWriterConfig());
        writer.addMutations(mutations);
    } catch (final AccumuloException | TableNotFoundException e) {
        throw new MergerException("Unable to set MergeParentMetadata in Accumulo", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new MergerException("Could not add results to a MergeParentMetadata table because some of the mutations were rejected.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MergerException(org.apache.rya.export.api.MergerException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 87 with TableNotFoundException

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

the class AccumuloParentMetadataRepository method getMetadataFromTable.

private MergeParentMetadata getMetadataFromTable() throws ParentMetadataDoesNotExistException {
    try {
        // Create an Accumulo scanner that iterates through the metadata entries.
        final Scanner scanner = connector.createScanner(mergeParentMetadataTableName, new Authorizations());
        final Iterator<Entry<Key, Value>> entries = scanner.iterator();
        // No metadata has been stored in the table yet.
        if (!entries.hasNext()) {
            throw new ParentMetadataDoesNotExistException("Could not find any MergeParentMetadata metadata in the table named: " + mergeParentMetadataTableName);
        }
        // Fetch the metadata from the entries.
        String ryaInstanceName = null;
        Date timestamp = null;
        Date filterTimestamp = null;
        Long parentTimeOffset = null;
        while (entries.hasNext()) {
            final Entry<Key, Value> entry = entries.next();
            final Text columnQualifier = entry.getKey().getColumnQualifier();
            final byte[] value = entry.getValue().get();
            if (columnQualifier.equals(MERGE_PARENT_METADATA_RYA_INSTANCE_NAME)) {
                ryaInstanceName = STRING_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_TIMESTAMP)) {
                timestamp = DATE_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_FILTER_TIMESTAMP)) {
                filterTimestamp = DATE_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_PARENT_TIME_OFFSET)) {
                parentTimeOffset = LONG_LEXICODER.decode(value);
            }
        }
        return new MergeParentMetadata(ryaInstanceName, timestamp, filterTimestamp, parentTimeOffset);
    } catch (final TableNotFoundException e) {
        throw new ParentMetadataDoesNotExistException("Could not add results to a MergeParentMetadata because the MergeParentMetadata table does not exist.", e);
    } catch (final Exception e) {
        throw new ParentMetadataDoesNotExistException("Error occurred while getting merge parent metadata.", e);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) Text(org.apache.hadoop.io.Text) Date(java.util.Date) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ParentMetadataExistsException(org.apache.rya.export.api.metadata.ParentMetadataExistsException) 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) MergerException(org.apache.rya.export.api.MergerException) ParentMetadataDoesNotExistException(org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) ParentMetadataDoesNotExistException(org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException) Key(org.apache.accumulo.core.data.Key)

Example 88 with TableNotFoundException

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

the class IndexWritingToolTest method testIndexWrite.

@Test
public void testIndexWrite() {
    Connector accCon = null;
    Instance inst;
    String[] args = new String[7];
    args[0] = "src/test/resources/ResultsFile1.txt";
    args[1] = "src/test/resources/testQuery.txt";
    args[2] = "instance";
    args[3] = "mock";
    args[4] = "user";
    args[5] = "password";
    args[6] = "table";
    String query = null;
    try {
        query = FileUtils.readFileToString(new File(args[1]));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    try {
        inst = new MockInstance(args[2]);
        accCon = inst.getConnector(args[4], args[5].getBytes());
        if (accCon.tableOperations().exists(args[6])) {
            accCon.tableOperations().delete(args[6]);
        }
        accCon.tableOperations().create(args[6]);
    } catch (AccumuloException e) {
        e.printStackTrace();
    } catch (AccumuloSecurityException e) {
        e.printStackTrace();
    } catch (TableExistsException e) {
        e.printStackTrace();
    } catch (TableNotFoundException e) {
        e.printStackTrace();
    }
    int result = 5;
    try {
        result = ToolRunner.run(new IndexWritingTool(), args);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertEquals(0, result);
    Scanner scan = null;
    try {
        scan = accCon.createScanner("table", new Authorizations());
    } catch (TableNotFoundException e) {
        e.printStackTrace();
    }
    scan.setRange(new Range());
    int count = 0;
    for (Map.Entry<Key, Value> entry : scan) {
        String[] k = entry.getKey().getRow().toString().split("\u0000");
        String[] c = entry.getKey().getColumnFamily().toString().split("\u0000");
        if (count == 0) {
            Assert.assertEquals(k[0], "person10");
            Assert.assertEquals(k[1], "person8");
            Assert.assertEquals(k[2], "person9");
            Assert.assertEquals(c[0], "z");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "y");
        } else if (count == 2) {
            Assert.assertEquals(k[0], "person2");
            Assert.assertEquals(k[1], "person1");
            Assert.assertEquals(k[2], "person3");
            Assert.assertEquals(c[0], "y");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "z");
        } else if (count == 5) {
            Assert.assertEquals(k[0], "person3");
            Assert.assertEquals(k[1], "person2");
            Assert.assertEquals(k[2], "person4");
            Assert.assertEquals(c[0], "y");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "z");
        } else if (count == 9) {
            Assert.assertEquals(k[0], "person5");
            Assert.assertEquals(k[1], "person3");
            Assert.assertEquals(k[2], "person4");
            Assert.assertEquals(c[0], "z");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "y");
        } else if (count == 13) {
            Assert.assertEquals(k[0], "person6");
            Assert.assertEquals(k[1], "person5");
            Assert.assertEquals(k[2], "person4");
            Assert.assertEquals(c[0], "z");
            Assert.assertEquals(c[1], "y");
            Assert.assertEquals(c[2], "x");
        } else if (count == 17) {
            Assert.assertEquals(k[0], "person7");
            Assert.assertEquals(k[1], "person6");
            Assert.assertEquals(k[2], "person8");
            Assert.assertEquals(c[0], "y");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "z");
        } else if (count == 21) {
            Assert.assertEquals(k[0], "person9");
            Assert.assertEquals(k[1], "person7");
            Assert.assertEquals(k[2], "person8");
            Assert.assertEquals(c[0], "z");
            Assert.assertEquals(c[1], "x");
            Assert.assertEquals(c[2], "y");
        } else if (count == 24) {
            Assert.assertEquals(query, entry.getValue().toString());
            String[] varOrders = entry.getKey().getColumnQualifier().toString().split("\u0000");
            Assert.assertEquals(3, varOrders.length);
            Assert.assertEquals(varOrders[0], "z;y;x");
            Assert.assertEquals(varOrders[1], "y;x;z");
            Assert.assertEquals(varOrders[2], "z;x;y");
        } else {
            Assert.assertTrue(k[0].startsWith("person"));
            Assert.assertTrue(k[1].startsWith("person"));
            Assert.assertTrue(k[2].startsWith("person"));
        }
        count++;
    }
    Assert.assertEquals(25, count);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) TableExistsException(org.apache.accumulo.core.client.TableExistsException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) File(java.io.File) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 89 with TableNotFoundException

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

the class IndexWritingToolTest method testIndexWrite2.

@Test
public void testIndexWrite2() {
    Connector accCon = null;
    Instance inst;
    String[] args = new String[7];
    args[0] = "src/test/resources/ResultsFile1.txt";
    args[1] = "src/test/resources/testQuery2.txt";
    args[2] = "instance";
    args[3] = "mock";
    args[4] = "user";
    args[5] = "password";
    args[6] = "table";
    String query = null;
    try {
        query = FileUtils.readFileToString(new File(args[1]));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    try {
        inst = new MockInstance(args[2]);
        accCon = inst.getConnector(args[4], args[5].getBytes());
        if (accCon.tableOperations().exists(args[6])) {
            accCon.tableOperations().delete(args[6]);
        }
        accCon.tableOperations().create(args[6]);
    } catch (AccumuloException e) {
        e.printStackTrace();
    } catch (AccumuloSecurityException e) {
        e.printStackTrace();
    } catch (TableExistsException e) {
        e.printStackTrace();
    } catch (TableNotFoundException e) {
        e.printStackTrace();
    }
    int result = 5;
    try {
        result = ToolRunner.run(new IndexWritingTool(), args);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertEquals(0, result);
    Scanner scan = null;
    try {
        scan = accCon.createScanner("table", new Authorizations());
    } catch (TableNotFoundException e) {
        e.printStackTrace();
    }
    scan.setRange(new Range());
    int count = 0;
    for (Map.Entry<Key, Value> entry : scan) {
        String[] k = entry.getKey().getRow().toString().split("\u0000");
        String[] c = entry.getKey().getColumnFamily().toString().split("\u0000");
        if (count == 0) {
            Assert.assertEquals(k[0], "person1");
            Assert.assertEquals(k[1], "person2");
            Assert.assertEquals(k[2], "person3");
            Assert.assertEquals(c[0], "x");
            Assert.assertEquals(c[1], "y");
            Assert.assertEquals(c[2], "z");
        } else if (count == 2) {
            Assert.assertEquals(k[0], "person3");
            Assert.assertEquals(k[1], "person4");
            Assert.assertEquals(k[2], "person5");
            Assert.assertEquals(c[0], "x");
            Assert.assertEquals(c[1], "y");
            Assert.assertEquals(c[2], "z");
        } else if (count == 5) {
            Assert.assertEquals(k[0], "person6");
            Assert.assertEquals(k[1], "person7");
            Assert.assertEquals(k[2], "person8");
            Assert.assertEquals(c[0], "x");
            Assert.assertEquals(c[1], "y");
            Assert.assertEquals(c[2], "z");
        }
        count++;
        System.out.println(count);
    }
    Assert.assertEquals(9, count);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) TableExistsException(org.apache.accumulo.core.client.TableExistsException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) File(java.io.File) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 90 with TableNotFoundException

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

the class AccumuloRyaUtils method getScanner.

/**
 * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}.
 * @param tablename the name of the table to scan.
 * @param config the {@link Configuration}.
 * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
 * {@code false} otherwise.
 * @return the {@link Scanner} for the table.
 * @throws IOException
 */
public static Scanner getScanner(final String tableName, final Configuration config, final boolean shouldAddCommonIterators) throws IOException {
    try {
        final String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE);
        final String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS);
        Instance instance;
        if (ConfigUtils.useMockInstance(config)) {
            instance = new MockInstance(instanceName);
        } else {
            instance = new ZooKeeperInstance(new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
        }
        final String username = ConfigUtils.getUsername(config);
        final String password = ConfigUtils.getPassword(config);
        final Connector connector = instance.getConnector(username, new PasswordToken(password));
        final Authorizations auths = ConfigUtils.getAuthorizations(config);
        final Scanner scanner = connector.createScanner(tableName, auths);
        if (shouldAddCommonIterators) {
            AccumuloRyaUtils.addCommonScannerIteratorsTo(scanner);
        }
        return scanner;
    } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
        log.error("Error connecting to " + tableName);
        throw new IOException(e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Authorizations(org.apache.accumulo.core.security.Authorizations) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Aggregations

TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)160 AccumuloException (org.apache.accumulo.core.client.AccumuloException)100 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)89 Text (org.apache.hadoop.io.Text)51 Value (org.apache.accumulo.core.data.Value)46 Key (org.apache.accumulo.core.data.Key)42 Scanner (org.apache.accumulo.core.client.Scanner)36 IOException (java.io.IOException)34 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 Connector (org.apache.accumulo.core.client.Connector)30 Mutation (org.apache.accumulo.core.data.Mutation)29 Range (org.apache.accumulo.core.data.Range)28 Authorizations (org.apache.accumulo.core.security.Authorizations)26 ArrayList (java.util.ArrayList)25 Entry (java.util.Map.Entry)25 TableExistsException (org.apache.accumulo.core.client.TableExistsException)25 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)23 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)23 HashMap (java.util.HashMap)19