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