use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class RyaAccumuloSailFactory method getSail.
@Override
public Sail getSail(final SailImplConfig config) throws SailConfigException {
try {
final RdfCloudTripleStore store = new RdfCloudTripleStore();
final RyaAccumuloSailConfig cbconfig = (RyaAccumuloSailConfig) config;
final String instanceName = cbconfig.getInstance();
final String zooKeepers = cbconfig.getZookeepers();
Instance i;
if (cbconfig.isMock()) {
i = new MockInstance(instanceName);
} else {
i = new ZooKeeperInstance(instanceName, zooKeepers);
}
final String user = cbconfig.getUser();
final String pass = cbconfig.getPassword();
final Connector connector = i.getConnector(user, new PasswordToken(pass));
final AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
crdfdao.setConnector(connector);
final AccumuloRdfConfiguration conf = cbconfig.toRdfConfiguation();
ConfigUtils.setIndexers(conf);
conf.setDisplayQueryPlan(true);
crdfdao.setConf(conf);
crdfdao.init();
store.setRyaDAO(crdfdao);
return store;
} catch (RyaDAOException | AccumuloException | AccumuloSecurityException e) {
throw new SailConfigException(e);
}
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class AccumuloLoadStatementsFile method loadStatements.
@Override
public void loadStatements(final String ryaInstanceName, final Path statementsFile, final RDFFormat format) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(statementsFile);
requireNonNull(format);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
Sail sail = null;
SailRepository sailRepo = null;
SailRepositoryConnection sailRepoConn = null;
try {
// Get a Sail object that is connected to the Rya instance.
final AccumuloRdfConfiguration ryaConf = getAccumuloConnectionDetails().buildAccumuloRdfConfiguration(ryaInstanceName);
// RYA-327 should address this hardcoded value.
ryaConf.setFlush(false);
sail = RyaSailFactory.getInstance(ryaConf);
// Load the file.
sailRepo = new SailRepository(sail);
sailRepoConn = sailRepo.getConnection();
sailRepoConn.add(statementsFile.toFile(), null, format);
} catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
log.warn("Exception while loading:", e);
throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the load to fail.", e);
} catch (final RepositoryException | RDFParseException | UnsupportedRDFormatException | IOException e) {
log.warn("Exception while loading:", e);
throw new RyaClientException("A problem processing the RDF file has caused the load into Rya instance named " + ryaInstanceName + "to fail.", e);
} finally {
// Shut it all down.
if (sailRepoConn != null) {
try {
sailRepoConn.close();
} catch (final RepositoryException e) {
log.warn("Couldn't close the SailRepoConnection that is attached to the Rya instance.", e);
}
}
if (sailRepo != null) {
try {
sailRepo.shutDown();
} catch (final RepositoryException e) {
log.warn("Couldn't shut down the SailRepository that is attached to the Rya instance.", e);
}
}
if (sail != null) {
try {
sail.shutDown();
} catch (final SailException e) {
log.warn("Couldn't shut down the Sail that is attached to the Rya instance.", e);
}
}
}
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class CopyToolTest method testCopyTool.
@Test
public void testCopyTool() throws Exception {
final RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("coach", "called", "timeout", LAST_MONTH);
final RyaStatement ryaStatementShouldCopy1 = createRyaStatement("bob", "catches", "ball", YESTERDAY);
final RyaStatement ryaStatementShouldCopy2 = createRyaStatement("bill", "talks to", "john", YESTERDAY);
final RyaStatement ryaStatementShouldCopy3 = createRyaStatement("susan", "eats", "burgers", TODAY);
final RyaStatement ryaStatementShouldCopy4 = createRyaStatement("ronnie", "plays", "guitar", TODAY);
final RyaStatement ryaStatementDoesNotExist1 = createRyaStatement("nobody", "was", "here", LAST_MONTH);
final RyaStatement ryaStatementDoesNotExist2 = createRyaStatement("statement", "not", "found", YESTERDAY);
final RyaStatement ryaStatementDoesNotExist3 = createRyaStatement("key", "does not", "exist", TODAY);
// This statement was modified by the child to change the column visibility.
// The parent should combine the child's visibility with its visibility.
final RyaStatement ryaStatementVisibilityDifferent = createRyaStatement("I", "see", "you", YESTERDAY);
ryaStatementVisibilityDifferent.setColumnVisibility(PARENT_COLUMN_VISIBILITY.getExpression());
// Setup initial parent instance with 7 rows
// This is the state of the parent data (as it is today) before merging occurs which will use the specified start time of yesterday.
// Process should NOT copy statement
parentDao.add(ryaStatementOutOfTimeRange);
// Process should copy statement
parentDao.add(ryaStatementShouldCopy1);
// Process should copy statement
parentDao.add(ryaStatementShouldCopy2);
// Process should copy statement
parentDao.add(ryaStatementShouldCopy3);
// Process should copy statement
parentDao.add(ryaStatementShouldCopy4);
// Process should copy and update statement
parentDao.add(ryaStatementVisibilityDifferent);
AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig);
// AccumuloRyaUtils.printTable(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig);
log.info("Starting copy tool. Copying all data after the specified start time: " + YESTERDAY);
isImporting = false;
copyToolRun(YESTERDAY);
// Copy Tool made child instance so hook the tables and dao into the driver.
final String childUser = accumuloDualInstanceDriver.getChildUser();
final Connector childConnector = ConfigUtils.getConnector(childConfig);
accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setConnector(childConnector);
accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpTables();
accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpDao();
childDao = accumuloDualInstanceDriver.getChildDao();
// Update child config to include changes made from copy process
final SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps();
Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH);
childSecOps.changeUserAuthorizations(childUser, newChildAuths);
final String childAuthString = newChildAuths.toString();
final List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP);
childConfig.set(MRUtils.AC_AUTH_PROP, childAuthString);
for (final String key : duplicateKeys) {
childConfig.set(key, childAuthString);
}
AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX, childConfig);
AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX, childConfig);
AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig);
final Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig);
final Iterator<Entry<Key, Value>> iterator = scanner.iterator();
int count = 0;
while (iterator.hasNext()) {
iterator.next();
count++;
}
// Make sure we have all of them in the parent.
assertEquals(5, count);
assertStatementInChild("Child included statement that was out of time range", 0, ryaStatementOutOfTimeRange);
assertStatementInChild("Child missing statement 1 that was in parent", 1, ryaStatementShouldCopy1);
assertStatementInChild("Child missing statement 2 that was in parent", 1, ryaStatementShouldCopy2);
assertStatementInChild("Child missing statement 3 that was in parent", 1, ryaStatementShouldCopy3);
assertStatementInChild("Child missing statement 4 that was in parent", 1, ryaStatementShouldCopy4);
assertStatementInChild("Child included statement 1 that was not in parent", 0, ryaStatementDoesNotExist1);
assertStatementInChild("Child included statement 2 that was not in parent", 0, ryaStatementDoesNotExist2);
assertStatementInChild("Child included statement 3 that was not in parent", 0, ryaStatementDoesNotExist3);
// Check that it can be queried with child's visibility
assertStatementInChild("Child missing statement with child visibility", 1, ryaStatementVisibilityDifferent);
// Check that it can be queried with parent's visibility
childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, PARENT_AUTH);
final SecurityOperations secOps = IS_MOCK ? accumuloDualInstanceDriver.getChildSecOps() : childSecOps;
newChildAuths = AccumuloRyaUtils.addUserAuths(accumuloDualInstanceDriver.getChildUser(), secOps, PARENT_AUTH);
secOps.changeUserAuthorizations(accumuloDualInstanceDriver.getChildUser(), newChildAuths);
assertStatementInChild("Child missing statement with parent visibility", 1, ryaStatementVisibilityDifferent);
// Check that it can NOT be queried with some other visibility
childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "bad_auth");
final CloseableIteration<RyaStatement, RyaDAOException> iter = childDao.getQueryEngine().query(ryaStatementVisibilityDifferent, childConfig);
count = 0;
try {
while (iter.hasNext()) {
iter.next();
count++;
}
} catch (final Exception e) {
// Expected
if (!(e.getCause() instanceof AccumuloSecurityException)) {
fail();
}
}
iter.close();
assertEquals(0, count);
// reset auth
childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, childAuthString);
log.info("DONE");
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class RulesetCopyIT method testRulesetCopyTool.
@Test
public void testRulesetCopyTool() throws Exception {
// Should be copied and are involved in the solution:
final RyaStatement[] solutionStatements = { statement("test:FullProfessor1", "rdf:type", "test:FullProfessor"), statement("test:GraduateStudent1", "test:advisor", "test:FullProfessor1"), statement("test:FullProfessor1", "test:telephone", literal("123-456-7890")), statement("test:University1", "test:telephone", literal("555")), statement("test:FullProfessor1", "test:worksFor", "test:University1"), statement("test:FullProfessor1", "test:hired", literal("2001-01-01T04:01:02.000Z", XMLSchema.DATETIME)), statement("test:University1", "geo:asWKT", literal("Point(-77.03524 38.889468)", new URIImpl("http://www.opengis.net/ont/geosparql#wktLiteral"))) };
// These aren't solutions but should be copied:
final RyaStatement[] copyStatements = { statement("test:FullProfessor2", "rdf:type", "test:FullProfessor"), statement("test:GraduateStudent1", "test:advisor", "test:AssistantProfessor1"), statement("test:GraduateStudent1", "test:telephone", literal("555-123-4567")), statement("test:FullProfessor1", "test:telephone", literal("567-8901")), statement("test:University1", "test:telephone", literal("800-123-4567")) };
// Should not be copied:
final RyaStatement[] irrelevantStatements = { statement("test:GraduateStudent2", "test:advisor", "test:FullProfessor1"), statement("test:UndergraduateStudent1", "rdf:type", "test:UndergraduateStudent"), statement("test:UndergraduateStudent2", "rdf:type", "test:UndergraduateStudent"), statement("test:GraduateStudent1", "rdf:type", "test:GraduateStudent"), statement("test:GraduateStudent1", "test:name", literal("GraduateStudent1")), statement("test:UndergraduateStudent2", "test:name", literal("UndergraduateStudent2")), statement("test:Course1", "test:name", literal("Course1")), statement("test:GraduateStudent1", "test:emailAddress", literal("GraduateStudent1@Department0.University0.edu")), statement("test:GraduateStudent1", "test:teachingAssistantOf", "test:Course1"), statement("test:GraduateStudent2", "test:undergraduateDegreeFrom", "test:University1"), statement("test:AssistantProfessor1", "test:teacherOf", "test:Course1"), statement("test:FullProfessor1", "test:telephone", literal("xxx-xxx-xxxx")), statement("test:University1", "test:telephone", literal("0000")), // If inferencing is disabled, these shouldn't matter:
statement("test:employs", "owl:inverseOf", "test:worksFor"), statement("test:University1", "test:employs", "test:FullProfessor2") };
final String query = QUERY_PREFIXES + "SELECT * {\n" + " test:GraduateStudent1 test:advisor ?person .\n" + " ?person rdf:type test:FullProfessor .\n" + " ?person test:telephone ?number .\n" + " ?person test:worksFor ?university .\n" + " FILTER regex(?number, \"...-...-....\")\n" + " ?university geo:asWKT ?place .\n" + " FILTER regex(?number, \"^[0-9]\")\n" + " ?university test:telephone ?universityNumber\n" + " FILTER regex(?universityNumber, \"^5\")\n" + // Would be good to test index functions, but indexing is unreliable (see RYA-72):
" ?person test:hired ?time .\n" + // + " FILTER(tempo:after(?time, '2000-01-01T01:01:03-08:00'))\n"
"}";
final int parentNamespaceCount = 2;
int childNamespaceCount = 0;
parentDao.addNamespace("ns1", "http://www.example.com/ns1#");
parentDao.addNamespace("ns2", "http://www.example.com/ns2#");
// Run the test
final AccumuloRyaDAO childDao = runRulesetCopyTest(solutionStatements, copyStatements, irrelevantStatements, query, 1, false);
// Verify namespaces were copied
final CloseableIteration<Namespace, RyaDAOException> nsIter = childDao.iterateNamespace();
while (nsIter.hasNext()) {
childNamespaceCount++;
nsIter.next();
}
Assert.assertEquals("Incorrect number of namespaces copied to child:", parentNamespaceCount, childNamespaceCount);
log.info("DONE");
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class TestUtils method assertStatementInInstance.
/**
* Checks if a {@link RyaStatement} is in the specified instance's DAO.
* @param description the description message for the statement.
* @param verifyResultCount the expected number of matches.
* @param matchStatement the {@link RyaStatement} to match.
* @param dao the {@link AccumuloRyaDAO}.
* @param config the {@link AccumuloRdfConfiguration} for the instance.
* @throws RyaDAOException
*/
public static void assertStatementInInstance(final String description, final int verifyResultCount, final RyaStatement matchStatement, final AccumuloRyaDAO dao, final AccumuloRdfConfiguration config) throws RyaDAOException {
final CloseableIteration<RyaStatement, RyaDAOException> iter = dao.getQueryEngine().query(matchStatement, config);
int count = 0;
while (iter.hasNext()) {
final RyaStatement statement = iter.next();
assertTrue(description + " - match subject: " + matchStatement, matchStatement.getSubject().equals(statement.getSubject()));
assertTrue(description + " - match predicate: " + matchStatement, matchStatement.getPredicate().equals(statement.getPredicate()));
assertTrue(description + " - match object match: " + matchStatement, matchStatement.getObject().equals(statement.getObject()));
count++;
}
iter.close();
assertEquals(description + " - Match Counts.", verifyResultCount, count);
}
Aggregations