Search in sources :

Example 11 with MongoDBRyaDAO

use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.

the class StatementStoreFactory method getBaseMongoStore.

private MongoRyaStatementStore getBaseMongoStore(final String hostname, final int port, final String ryaInstanceName) throws RyaDAOException {
    final MongoClient client = new MongoClient(hostname, port);
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(MergeConfigHadoopAdapter.getMongoConfiguration(configuration), client));
    dao.init();
    return new MongoRyaStatementStore(client, ryaInstanceName, dao);
}
Also used : MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaStatementStore(org.apache.rya.export.mongo.MongoRyaStatementStore) TimestampPolicyMongoRyaStatementStore(org.apache.rya.export.mongo.policy.TimestampPolicyMongoRyaStatementStore)

Example 12 with MongoDBRyaDAO

use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.

the class GeoRyaSailFactory method getRyaSail.

private static Sail getRyaSail(final Configuration config) throws InferenceEngineException, RyaDAOException, AccumuloException, AccumuloSecurityException, SailException {
    final RdfCloudTripleStore store = new RdfCloudTripleStore();
    final RyaDAO<?> dao;
    final RdfCloudTripleStoreConfiguration rdfConfig;
    final String user;
    final String pswd;
    // XXX Should(?) be MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX inside the if below. RYA-135
    final String ryaInstance = config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is missing from configuration." + RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    if (ConfigUtils.getUseMongo(config)) {
        // Get a reference to a Mongo DB configuration object.
        final MongoDBRdfConfiguration mongoConfig = (config instanceof MongoDBRdfConfiguration) ? (MongoDBRdfConfiguration) config : new MongoDBRdfConfiguration(config);
        // Create the MongoClient that will be used by the Sail object's components.
        final MongoClient client = createMongoClient(mongoConfig);
        // Add the Indexer and Optimizer names to the configuration object that are configured to be used.
        OptionalConfigUtils.setIndexers(mongoConfig);
        // Populate the configuration using previously stored Rya Details if this instance uses them.
        try {
            final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new MongoRyaInstanceDetailsRepository(client, mongoConfig.getRyaInstanceName());
            RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(), mongoConfig);
        } catch (final RyaDetailsRepositoryException e) {
            LOG.info("Instance does not have a rya details collection, skipping.");
        }
        // Set the configuration to the stateful configuration that is used to pass the constructed objects around.
        final StatefulMongoDBRdfConfiguration statefulConfig = new StatefulMongoDBRdfConfiguration(mongoConfig, client);
        final List<MongoSecondaryIndex> indexers = statefulConfig.getInstances(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, MongoSecondaryIndex.class);
        statefulConfig.setIndexers(indexers);
        rdfConfig = statefulConfig;
        // Create the DAO that is able to interact with MongoDB.
        final MongoDBRyaDAO mongoDao = new MongoDBRyaDAO();
        mongoDao.setConf(statefulConfig);
        mongoDao.init();
        dao = mongoDao;
    } else {
        rdfConfig = new AccumuloRdfConfiguration(config);
        user = rdfConfig.get(ConfigUtils.CLOUDBASE_USER);
        pswd = rdfConfig.get(ConfigUtils.CLOUDBASE_PASSWORD);
        Objects.requireNonNull(user, "Accumulo user name is missing from configuration." + ConfigUtils.CLOUDBASE_USER);
        Objects.requireNonNull(pswd, "Accumulo user password is missing from configuration." + ConfigUtils.CLOUDBASE_PASSWORD);
        rdfConfig.setTableLayoutStrategy(new TablePrefixLayoutStrategy(ryaInstance));
        RyaSailFactory.updateAccumuloConfig((AccumuloRdfConfiguration) rdfConfig, user, pswd, ryaInstance);
        dao = getAccumuloDAO((AccumuloRdfConfiguration) rdfConfig);
    }
    store.setRyaDAO(dao);
    rdfConfig.setTablePrefix(ryaInstance);
    if (rdfConfig.isInfer()) {
        final InferenceEngine inferenceEngine = new InferenceEngine();
        inferenceEngine.setConf(rdfConfig);
        inferenceEngine.setRyaDAO(dao);
        inferenceEngine.init();
        store.setInferenceEngine(inferenceEngine);
    }
    store.initialize();
    return store;
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) MongoSecondaryIndex(org.apache.rya.mongodb.MongoSecondaryIndex) MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) TablePrefixLayoutStrategy(org.apache.rya.api.layout.TablePrefixLayoutStrategy) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)

Example 13 with MongoDBRyaDAO

use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.

the class StoreToStoreIT method getChildMongo.

private static MongoRyaStatementStore getChildMongo() throws Exception {
    final MongoClient mongo = getNewMongoResources(RYA_INSTANCE);
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(ITBase.getConf(mongo), mongo));
    dao.init();
    final MongoRyaStatementStore store = new MongoRyaStatementStore(mongo, RYA_INSTANCE, dao);
    clients.add(mongo);
    return store;
}
Also used : MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaStatementStore(org.apache.rya.export.mongo.MongoRyaStatementStore) TimestampPolicyMongoRyaStatementStore(org.apache.rya.export.mongo.policy.TimestampPolicyMongoRyaStatementStore)

Example 14 with MongoDBRyaDAO

use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.

the class StoreToStoreIT method getParentMongo.

private static TimestampPolicyMongoRyaStatementStore getParentMongo() throws Exception {
    final MongoClient mongo = getNewMongoResources(RYA_INSTANCE);
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(ITBase.getConf(mongo), mongo));
    dao.init();
    final MongoRyaStatementStore store = new MongoRyaStatementStore(mongo, RYA_INSTANCE, dao);
    final TimestampPolicyMongoRyaStatementStore timeStore = new TimestampPolicyMongoRyaStatementStore(store, currentDate, RYA_INSTANCE);
    clients.add(mongo);
    return timeStore;
}
Also used : MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaStatementStore(org.apache.rya.export.mongo.MongoRyaStatementStore) TimestampPolicyMongoRyaStatementStore(org.apache.rya.export.mongo.policy.TimestampPolicyMongoRyaStatementStore) TimestampPolicyMongoRyaStatementStore(org.apache.rya.export.mongo.policy.TimestampPolicyMongoRyaStatementStore)

Example 15 with MongoDBRyaDAO

use of org.apache.rya.mongodb.MongoDBRyaDAO in project incubator-rya by apache.

the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSetInvalidProperty.

/**
 * Tests if results are filtered correctly using the metadata properties. In
 * this case, the date for the ingested RyaStatement differs from the date
 * specified in the query.
 */
@Test
public void simpleQueryWithoutBindingSetInvalidProperty() throws Exception {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        StatementMetadata metadata = new StatementMetadata();
        metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Doug"));
        metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-15"));
        RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
        dao.add(statement);
        SPARQLParser parser = new SPARQLParser();
        ParsedQuery pq = parser.parseQuery(query, null);
        List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
        StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
        List<BindingSet> bsList = new ArrayList<>();
        while (iteration.hasNext()) {
            bsList.add(iteration.next());
        }
        Assert.assertEquals(0, bsList.size());
        dao.delete(statement, conf);
    } finally {
        dao.destroy();
    }
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) Test(org.junit.Test)

Aggregations

MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)19 Test (org.junit.Test)13 BindingSet (org.openrdf.query.BindingSet)12 RyaStatement (org.apache.rya.api.domain.RyaStatement)10 RyaType (org.apache.rya.api.domain.RyaType)10 RyaURI (org.apache.rya.api.domain.RyaURI)10 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)10 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)10 ArrayList (java.util.ArrayList)8 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)8 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 HashSet (java.util.HashSet)6 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)6 MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)6 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)6 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 ParsedQuery (org.openrdf.query.parser.ParsedQuery)6 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)6 MongoClient (com.mongodb.MongoClient)5