use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.
the class RyaSailFactory 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);
// Instantiate a Mongo client and Mongo DAO.
dao = getMongoDAO(mongoConfig);
// Then use the DAO's newly-created stateful conf in place of the original
rdfConfig = dao.getConf();
} 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));
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 StatementMetadataExternalSetProviderTest method createMultipleMetadataNode.
@Test
public void createMultipleMetadataNode() throws MalformedQueryException {
MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
Set<RyaURI> propertySet = new HashSet<>();
propertySet.add(new RyaURI("http://createdBy"));
propertySet.add(new RyaURI("http://createdOn"));
conf.setStatementMetadataProperties(propertySet);
StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq2 = parser.parseQuery(query2, null);
ParsedQuery pq3 = parser.parseQuery(query3, null);
ParsedQuery pq1 = parser.parseQuery(query, null);
List<QueryModelNode> patterns = new ArrayList<>();
List<StatementMetadataNode<?>> expected = new ArrayList<>();
Set<StatementPattern> sp1 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq1.getTupleExpr(), propertySet);
Set<StatementPattern> sp3 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq3.getTupleExpr(), propertySet);
// added extra blankNode into query3 to make blankNode names line up with query2. Need to remove it now so that
// StatementMetadataNode doesn't blow up because all subjects aren't the same.
removePatternWithGivenSubject("-anon-1", sp3);
patterns.addAll(StatementPatternCollector.process(pq2.getTupleExpr()));
JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
expected.add(new StatementMetadataNode<>(sp1, conf));
expected.add(new StatementMetadataNode<>(sp3, conf));
Assert.assertEquals(expected, extSets);
}
use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.
the class StatementMetadataExternalSetProviderTest method getConf.
private static Configuration getConf(boolean useMongo) {
if (useMongo) {
MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration();
conf.setBoolean("sc.useMongo", true);
conf.setMongoHostname("localhost");
conf.setMongoPort("27017");
conf.setMongoDBName("rya_");
return conf;
} else {
AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
conf.set(ConfigUtils.CLOUDBASE_USER, "root");
conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "");
conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
return conf;
}
}
use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.
the class StatementMetadataExternalSetProviderTest method createSingleMongoMetadataNode.
@Test
public void createSingleMongoMetadataNode() throws MalformedQueryException {
MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
Set<RyaURI> propertySet = new HashSet<>();
propertySet.add(new RyaURI("http://createdBy"));
conf.setStatementMetadataProperties(propertySet);
StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<QueryModelNode> patterns = new ArrayList<>();
List<StatementMetadataNode<?>> expected = new ArrayList<>();
Set<StatementPattern> sp = StatementMetadataTestUtils.getMetadataStatementPatterns(pq.getTupleExpr(), propertySet);
patterns.addAll(StatementPatternCollector.process(pq.getTupleExpr()));
JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
expected.add(new StatementMetadataNode<>(sp, conf));
Assert.assertEquals(expected, extSets);
}
Aggregations