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);
}
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);
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
Aggregations