use of org.apache.fluo.api.client.FluoClient in project incubator-rya by apache.
the class StatementPatternIdCacheIT method statementPatternIdCacheTest.
/**
* Ensure streamed matches are included in the result.
*/
@Test
public void statementPatternIdCacheTest() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql1 = "SELECT ?x WHERE { " + "?x <urn:pred1> <urn:obj1>. " + "?x <urn:pred2> <urn:obj2>." + "}";
final String sparql2 = "SELECT ?x WHERE { " + "?x <urn:pred3> <urn:obj3>. " + "?x <urn:pred4> <urn:obj4>." + "}";
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
String pcjId = FluoQueryUtils.createNewPcjId();
// Tell the Fluo app to maintain the PCJ.
FluoQuery query1 = new CreateFluoPcj().createPcj(pcjId, sparql1, new HashSet<>(), fluoClient);
Set<String> spIds1 = new HashSet<>();
for (StatementPatternMetadata metadata : query1.getStatementPatternMetadata()) {
spIds1.add(metadata.getNodeId());
}
StatementPatternIdCache cache = new StatementPatternIdCache();
assertEquals(spIds1, cache.getStatementPatternIds(fluoClient.newTransaction()));
FluoQuery query2 = new CreateFluoPcj().createPcj(pcjId, sparql2, new HashSet<>(), fluoClient);
Set<String> spIds2 = new HashSet<>();
for (StatementPatternMetadata metadata : query2.getStatementPatternMetadata()) {
spIds2.add(metadata.getNodeId());
}
assertEquals(Sets.union(spIds1, spIds2), cache.getStatementPatternIds(fluoClient.newTransaction()));
}
}
use of org.apache.fluo.api.client.FluoClient in project incubator-rya by apache.
the class ListFluoQueriesIT method queryMetadataTest.
@Test
public void queryMetadataTest() throws Exception {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
String sparql1 = "select ?x ?y ?z where {?x <uri:p1> ?y; <uri:p2> 'literal1'. ?y <uri:p3> ?z }";
String sparql2 = "select ?x ?y ?z where {{select ?x ?y ?z {?x <uri:p1> ?y; <uri:p2> ?z. ?y <uri:p3> ?z }}}";
// Create the object that will be serialized.
String queryId1 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder = QueryMetadata.builder(queryId1);
builder.setQueryType(QueryType.PROJECTION);
builder.setVarOrder(new VariableOrder("y;s;d"));
builder.setSparql(sparql1);
builder.setChildNodeId("childNodeId");
builder.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.KAFKA)));
final QueryMetadata meta1 = builder.build();
String queryId2 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder2 = QueryMetadata.builder(queryId2);
builder2.setQueryType(QueryType.PROJECTION);
builder2.setVarOrder(new VariableOrder("y;s;d"));
builder2.setSparql(sparql2);
builder2.setChildNodeId("childNodeId");
builder2.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.RYA)));
final QueryMetadata meta2 = builder2.build();
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Write it to the Fluo table.
try (Transaction tx = fluoClient.newTransaction()) {
dao.write(tx, meta1);
dao.write(tx, meta2);
tx.commit();
}
ListFluoQueries listFluoQueries = new ListFluoQueries();
List<String> queries = listFluoQueries.listFluoQueries(fluoClient);
FluoQueryStringBuilder queryBuilder1 = new FluoQueryStringBuilder();
String expected1 = queryBuilder1.setQueryId(queryId1).setQueryType(QueryType.PROJECTION).setQuery(sparql1).setExportStrategies(Sets.newHashSet(ExportStrategy.KAFKA)).build();
FluoQueryStringBuilder queryBuilder2 = new FluoQueryStringBuilder();
String expected2 = queryBuilder2.setQueryId(queryId2).setQueryType(QueryType.PROJECTION).setQuery(sparql2).setExportStrategies(Sets.newHashSet(ExportStrategy.RYA)).build();
Set<String> expected = new HashSet<>();
expected.add(expected1);
expected.add(expected2);
Assert.assertEquals(expected, Sets.newHashSet(queries));
}
}
use of org.apache.fluo.api.client.FluoClient in project incubator-rya by apache.
the class AccumuloCreatePCJ method updateFluoApp.
private void updateFluoApp(final String ryaInstance, final String fluoAppName, final String pcjId, String sparql, Set<ExportStrategy> strategies) throws RepositoryException, MalformedQueryException, SailException, QueryEvaluationException, PcjException, RyaDAOException, UnsupportedQueryException {
requireNonNull(sparql);
requireNonNull(pcjId);
requireNonNull(strategies);
// Connect to the Fluo application that is updating this instance's PCJs.
final AccumuloConnectionDetails cd = super.getAccumuloConnectionDetails();
try (final FluoClient fluoClient = new FluoClientFactory().connect(cd.getUsername(), new String(cd.getUserPass()), cd.getInstanceName(), cd.getZookeepers(), fluoAppName)) {
// Initialize the PCJ within the Fluo application.
final CreateFluoPcj fluoCreatePcj = new CreateFluoPcj();
fluoCreatePcj.withRyaIntegration(pcjId, sparql, strategies, fluoClient, getConnector(), ryaInstance);
}
}
use of org.apache.fluo.api.client.FluoClient in project incubator-rya by apache.
the class AccumuloDeletePCJ method stopUpdatingPCJ.
private void stopUpdatingPCJ(final String fluoAppName, final String pcjId) {
requireNonNull(fluoAppName);
requireNonNull(pcjId);
// Connect to the Fluo application that is updating this instance's PCJs.
final AccumuloConnectionDetails cd = super.getAccumuloConnectionDetails();
try (final FluoClient fluoClient = new FluoClientFactory().connect(cd.getUsername(), new String(cd.getUserPass()), cd.getInstanceName(), cd.getZookeepers(), fluoAppName)) {
// Delete the PCJ from the Fluo App.
try {
new DeleteFluoPcj(1000).deletePcj(fluoClient, pcjId);
} catch (Exception e) {
log.warn("PcjId corresponds to an invalid PCJ. The query cannot be deleted.");
}
}
}
use of org.apache.fluo.api.client.FluoClient in project incubator-rya by apache.
the class FluoPcjUpdaterSupplier method get.
@Override
public FluoPcjUpdater get() {
final Configuration config = configSupplier.get();
checkNotNull(config, "Could not create a FluoPcjUpdater because the application's configuration has not been provided yet.");
// Ensure the correct updater type has been set.
final PrecomputedJoinIndexerConfig indexerConfig = new PrecomputedJoinIndexerConfig(config);
final Optional<PrecomputedJoinUpdaterType> updaterType = indexerConfig.getPcjUpdaterType();
checkArgument(updaterType.isPresent() && updaterType.get() == PrecomputedJoinUpdaterType.FLUO, "This supplier requires the '" + PrecomputedJoinIndexerConfig.PCJ_UPDATER_TYPE + "' value be set to '" + PrecomputedJoinUpdaterType.FLUO + "'.");
final FluoPcjUpdaterConfig fluoUpdaterConfig = new FluoPcjUpdaterConfig(indexerConfig.getConfig());
// Make sure the required values are present.
checkArgument(fluoUpdaterConfig.getFluoAppName().isPresent(), "Missing configuration: " + FLUO_APP_NAME);
checkArgument(fluoUpdaterConfig.getFluoZookeepers().isPresent(), "Missing configuration: " + ACCUMULO_ZOOKEEPERS);
checkArgument(fluoUpdaterConfig.getAccumuloZookeepers().isPresent(), "Missing configuration: " + ACCUMULO_ZOOKEEPERS);
checkArgument(fluoUpdaterConfig.getAccumuloInstance().isPresent(), "Missing configuration: " + ACCUMULO_INSTANCE);
checkArgument(fluoUpdaterConfig.getAccumuloUsername().isPresent(), "Missing configuration: " + ACCUMULO_USERNAME);
checkArgument(fluoUpdaterConfig.getAccumuloPassword().isPresent(), "Missing configuration: " + ACCUMULO_PASSWORD);
// Fluo configuration values.
final FluoConfiguration fluoClientConfig = new FluoConfiguration();
fluoClientConfig.setApplicationName(fluoUpdaterConfig.getFluoAppName().get());
fluoClientConfig.setInstanceZookeepers(fluoUpdaterConfig.getFluoZookeepers().get());
// Accumulo Fluo Table configuration values.
fluoClientConfig.setAccumuloZookeepers(fluoUpdaterConfig.getAccumuloZookeepers().get());
fluoClientConfig.setAccumuloInstance(fluoUpdaterConfig.getAccumuloInstance().get());
fluoClientConfig.setAccumuloUser(fluoUpdaterConfig.getAccumuloUsername().get());
fluoClientConfig.setAccumuloPassword(fluoUpdaterConfig.getAccumuloPassword().get());
final FluoClient fluoClient = FluoFactory.newClient(fluoClientConfig);
return new FluoPcjUpdater(fluoClient);
}
Aggregations