Search in sources :

Example 51 with FluoClient

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()));
    }
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) StatementPatternIdCache(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdCache) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with FluoClient

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));
    }
}
Also used : QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata) FluoClient(org.apache.fluo.api.client.FluoClient) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) FluoQueryMetadataDAO(org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryMetadataDAO) Transaction(org.apache.fluo.api.client.Transaction) FluoQueryStringBuilder(org.apache.rya.indexing.pcj.fluo.api.ListFluoQueries.FluoQueryStringBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with FluoClient

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);
    }
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)

Example 54 with FluoClient

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.");
        }
    }
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) DeleteFluoPcj(org.apache.rya.indexing.pcj.fluo.api.DeleteFluoPcj) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException)

Example 55 with FluoClient

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);
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) FluoConfiguration(org.apache.fluo.api.config.FluoConfiguration) Configuration(org.apache.hadoop.conf.Configuration) PrecomputedJoinUpdaterType(org.apache.rya.indexing.external.PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType) PrecomputedJoinIndexerConfig(org.apache.rya.indexing.external.PrecomputedJoinIndexerConfig) FluoConfiguration(org.apache.fluo.api.config.FluoConfiguration)

Aggregations

FluoClient (org.apache.fluo.api.client.FluoClient)57 Test (org.junit.Test)44 CreateFluoPcj (org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)22 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)21 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)21 Connector (org.apache.accumulo.core.client.Connector)19 HashSet (java.util.HashSet)16 BindingSet (org.openrdf.query.BindingSet)16 Transaction (org.apache.fluo.api.client.Transaction)15 RyaStatement (org.apache.rya.api.domain.RyaStatement)15 ValueFactory (org.openrdf.model.ValueFactory)15 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)15 Snapshot (org.apache.fluo.api.client.Snapshot)13 RyaURI (org.apache.rya.api.domain.RyaURI)13 InsertTriples (org.apache.rya.indexing.pcj.fluo.api.InsertTriples)13 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)12 Statement (org.openrdf.model.Statement)12 MapBindingSet (org.openrdf.query.impl.MapBindingSet)12 FluoClientImpl (org.apache.fluo.core.client.FluoClientImpl)11 PeriodicQueryResultStorage (org.apache.rya.indexing.pcj.storage.PeriodicQueryResultStorage)9