Search in sources :

Example 76 with RyaDAOException

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);
    }
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SailConfigException(org.openrdf.sail.config.SailConfigException)

Example 77 with RyaDAOException

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);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) UnsupportedRDFormatException(org.openrdf.rio.UnsupportedRDFormatException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.openrdf.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) IOException(java.io.IOException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RDFParseException(org.openrdf.rio.RDFParseException)

Example 78 with RyaDAOException

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");
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaStatement(org.apache.rya.api.domain.RyaStatement) TestUtils.createRyaStatement(org.apache.rya.accumulo.mr.merge.util.TestUtils.createRyaStatement) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Entry(java.util.Map.Entry) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Example 79 with RyaDAOException

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");
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) URIImpl(org.openrdf.model.impl.URIImpl) Namespace(org.openrdf.model.Namespace) Test(org.junit.Test)

Example 80 with RyaDAOException

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);
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Aggregations

RyaDAOException (org.apache.rya.api.persist.RyaDAOException)100 RyaStatement (org.apache.rya.api.domain.RyaStatement)61 RyaURI (org.apache.rya.api.domain.RyaURI)45 Test (org.junit.Test)39 RyaType (org.apache.rya.api.domain.RyaType)28 IOException (java.io.IOException)26 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)23 AccumuloException (org.apache.accumulo.core.client.AccumuloException)22 SailException (org.openrdf.sail.SailException)15 HashSet (java.util.HashSet)12 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)12 RdfCloudTripleStoreUtils (org.apache.rya.api.RdfCloudTripleStoreUtils)12 Map (java.util.Map)11 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 RyaClientException (org.apache.rya.api.client.RyaClientException)11 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)8 Text (org.apache.hadoop.io.Text)8