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