Search in sources :

Example 16 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException 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 17 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException 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 18 with TableExistsException

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

the class EntityCentricIndex method setConf.

// initialization occurs in setConf because index is created using reflection
@Override
public void setConf(final Configuration conf) {
    if (conf instanceof AccumuloRdfConfiguration) {
        this.conf = (AccumuloRdfConfiguration) conf;
    } else {
        this.conf = new AccumuloRdfConfiguration(conf);
    }
    if (!isInit) {
        try {
            initInternal();
            isInit = true;
        } catch (final AccumuloException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final AccumuloSecurityException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final TableNotFoundException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final TableExistsException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final IOException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) 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 19 with TableExistsException

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

the class BaseCopyToolMapper method createTableIfNeeded.

private void createTableIfNeeded() throws IOException {
    try {
        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(childUser, childTableName, TablePermission.WRITE);
            log.info("Granted authorizations to table: " + childTableName);
        }
    } catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException)

Example 20 with TableExistsException

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

the class AccumuloRyaInstanceDetailsRepository method initialize.

@Override
public void initialize(final RyaDetails details) throws AlreadyInitializedException, RyaDetailsRepositoryException {
    // Preconditions.
    requireNonNull(details);
    if (!details.getRyaInstanceName().equals(instanceName)) {
        throw new RyaDetailsRepositoryException("The instance name that was in the provided 'details' does not match " + "the instance name that this repository is connected to. Make sure you're connected to the" + "correct Rya instance.");
    }
    if (isInitialized()) {
        throw new AlreadyInitializedException("The repository has already been initialized for the Rya instance named '" + instanceName + "'.");
    }
    // Create the table that hosts the details if it has not been created yet.
    final TableOperations tableOps = connector.tableOperations();
    if (!tableOps.exists(detailsTableName)) {
        try {
            tableOps.create(detailsTableName);
        } catch (AccumuloException | AccumuloSecurityException | TableExistsException e) {
            throw new RyaDetailsRepositoryException("Could not initialize the Rya instance details for the instance named '" + instanceName + "' because the the table that holds that information could not be created.");
        }
    }
    // Write the details to the table.
    BatchWriter writer = null;
    try {
        writer = connector.createBatchWriter(detailsTableName, new BatchWriterConfig());
        final byte[] bytes = serializer.serialize(details);
        final Mutation mutation = new Mutation(ROW_ID);
        mutation.put(COL_FAMILY, COL_QUALIFIER, new Value(bytes));
        writer.addMutation(mutation);
    } catch (final TableNotFoundException | MutationsRejectedException e) {
        throw new RyaDetailsRepositoryException("Could not initialize the Rya instance details for the instance named '" + instanceName + "'.", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new RyaDetailsRepositoryException("Could not initialize the Rya instance details for the instance named '" + instanceName + "'.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Value(org.apache.accumulo.core.data.Value) 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) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

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