Search in sources :

Example 11 with MongoDBRdfConfiguration

use of org.apache.rya.mongodb.MongoDBRdfConfiguration 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 12 with MongoDBRdfConfiguration

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

the class ITBase method setupRya.

/**
 * Sets up a Rya instance
 *
 * @param user
 * @param password
 * @param instanceName
 * @param zookeepers
 * @param appName
 * @return
 * @throws AccumuloException
 * @throws AccumuloSecurityException
 * @throws RepositoryException
 * @throws RyaDAOException
 * @throws NumberFormatException
 * @throws UnknownHostException
 * @throws InferenceEngineException
 * @throws SailException
 */
protected static RyaSailRepository setupRya(final String ryaInstanceName, final String hostname, final int port, final MongoClient client) throws AccumuloException, AccumuloSecurityException, RepositoryException, RyaDAOException, NumberFormatException, UnknownHostException, InferenceEngineException, SailException {
    checkNotNull(ryaInstanceName);
    // Setup Rya configuration values.
    final MongoDBRdfConfiguration conf = getConf(ryaInstanceName, hostname, port);
    configs.put(client, conf);
    final Sail sail = RyaSailFactory.getInstance(conf);
    final RyaSailRepository ryaRepo = new RyaSailRepository(sail);
    return ryaRepo;
}
Also used : Sail(org.openrdf.sail.Sail) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Example 13 with MongoDBRdfConfiguration

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

the class MergeConfigHadoopAdapter method getMongoConfiguration.

public static MongoDBRdfConfiguration getMongoConfiguration(final MergeConfiguration config) {
    final MongoDBRdfConfiguration configuration = new MongoDBRdfConfiguration();
    configuration.setMongoHostname(config.getChildHostname());
    configuration.set(MongoDBRdfConfiguration.MONGO_PORT, config.getChildPort() + "");
    configuration.set(MongoDBRdfConfiguration.MONGO_DB_NAME, config.getChildRyaInstanceName());
    return configuration;
}
Also used : MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Example 14 with MongoDBRdfConfiguration

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

the class ITBase method getConf.

protected static MongoDBRdfConfiguration getConf(final String ryaInstanceName, final String hostname, final int port) {
    final MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration();
    conf.setBoolean(ConfigUtils.USE_MONGO, true);
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, false);
    conf.setTablePrefix(RYA_TABLE_PREFIX);
    conf.setDisplayQueryPlan(true);
    conf.set(ConfigUtils.CLOUDBASE_USER, USER);
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, PASSWORD);
    conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
    conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
    conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
    conf.setMongoPort("" + port);
    conf.setMongoHostname(hostname);
    conf.setMongoDBName(ryaInstanceName);
    return conf;
}
Also used : MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Example 15 with MongoDBRdfConfiguration

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

the class MongoPcjIntegrationTest method testEvaluateOneIndex.

@Test
public void testEvaluateOneIndex() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final URI superclass = new URIImpl("uri:superclass");
        final URI superclass2 = new URIImpl("uri:superclass2");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final CountingResultHandler crh1 = new CountingResultHandler();
        final CountingResultHandler crh2 = new CountingResultHandler();
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh1);
        PcjIntegrationTestingUtil.deleteCoreRyaTables(getMongoClient(), conf.getRyaInstanceName(), conf.getTriplesCollectionName());
        pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh2);
        assertEquals(crh1.count, crh2.count);
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) URIImpl(org.openrdf.model.impl.URIImpl) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Aggregations

MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)24 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 ParsedQuery (org.openrdf.query.parser.ParsedQuery)9 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)9 Sail (org.openrdf.sail.Sail)9 RyaURI (org.apache.rya.api.domain.RyaURI)8 LiteralImpl (org.openrdf.model.impl.LiteralImpl)7 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)6 MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)6 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)6 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)6 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 RyaStatement (org.apache.rya.api.domain.RyaStatement)5 RyaType (org.apache.rya.api.domain.RyaType)5 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)5 HashSet (java.util.HashSet)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)4