Search in sources :

Example 1 with MiniFluo

use of org.apache.fluo.api.mini.MiniFluo in project incubator-rya by apache.

the class DemoDriver method startMiniFluo.

/**
 * Setup a Mini Fluo cluster that uses a temporary directory to store its data.ll
 *
 * @return A Mini Fluo cluster.
 */
private static MiniFluo startMiniFluo() {
    final File miniDataDir = Files.createTempDir();
    // Setup the observers that will be used by the Fluo PCJ Application.
    final List<ObserverSpecification> observers = new ArrayList<>();
    observers.add(new ObserverSpecification(TripleObserver.class.getName()));
    observers.add(new ObserverSpecification(StatementPatternObserver.class.getName()));
    observers.add(new ObserverSpecification(JoinObserver.class.getName()));
    observers.add(new ObserverSpecification(FilterObserver.class.getName()));
    // Provide export parameters child test classes may provide to the export observer.
    final HashMap<String, String> exportParams = new HashMap<>();
    final RyaExportParameters ryaParams = new RyaExportParameters(exportParams);
    ryaParams.setUseRyaBindingSetExporter(true);
    ryaParams.setAccumuloInstanceName(accumulo.getInstanceName());
    ryaParams.setZookeeperServers(accumulo.getZooKeepers());
    ryaParams.setExporterUsername("root");
    ryaParams.setExporterPassword("password");
    ryaParams.setRyaInstanceName("demo_");
    final ObserverSpecification exportObserverConfig = new ObserverSpecification(QueryResultObserver.class.getName(), exportParams);
    observers.add(exportObserverConfig);
    // Configure how the mini fluo will run.
    final FluoConfiguration config = new FluoConfiguration();
    config.setApplicationName("IntegrationTests");
    config.setMiniDataDir(miniDataDir.getAbsolutePath());
    config.addObservers(observers);
    final MiniFluo miniFluo = FluoFactory.newMiniFluo(config);
    return miniFluo;
}
Also used : MiniFluo(org.apache.fluo.api.mini.MiniFluo) ObserverSpecification(org.apache.fluo.api.config.ObserverSpecification) HashMap(java.util.HashMap) RyaExportParameters(org.apache.rya.indexing.pcj.fluo.app.export.rya.RyaExportParameters) FluoConfiguration(org.apache.fluo.api.config.FluoConfiguration) ArrayList(java.util.ArrayList) QueryResultObserver(org.apache.rya.indexing.pcj.fluo.app.observers.QueryResultObserver) File(java.io.File)

Example 2 with MiniFluo

use of org.apache.fluo.api.mini.MiniFluo in project incubator-rya by apache.

the class RyaClientExample method main.

public static void main(final String[] args) throws Exception {
    final String accumuloUsername = "root";
    final String accumuloPassword = "password";
    MiniAccumuloCluster cluster = null;
    MiniFluo fluo = null;
    Sail ryaSail = null;
    try {
        // Setup a Mini Accumulo Cluster to host the Rya instance.
        log.info("Setting up the Mini Accumulo Cluster used by this example.");
        final File miniDataDir = Files.createTempDir();
        final MiniAccumuloConfig cfg = new MiniAccumuloConfig(miniDataDir, accumuloPassword);
        cluster = new MiniAccumuloCluster(cfg);
        cluster.start();
        // Setup a Mini Fluo application that will be used to incrementally update the PCJ indicies.
        log.info("Setting up the Mini Fluo application used by this example.");
        final String fluoAppName = "demoInstance_pcjUpdater";
        fluo = makeMiniFluo(accumuloUsername, accumuloPassword, cluster.getInstanceName(), cluster.getZooKeepers(), fluoAppName);
        // Give the root user the 'U' authorizations.
        final Connector connector = cluster.getConnector(accumuloUsername, accumuloPassword);
        connector.securityOperations().changeUserAuthorizations(accumuloUsername, new Authorizations("U"));
        // Setup a Rya Client that is able to interact with the mini cluster.
        final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(accumuloUsername, accumuloPassword.toCharArray(), cluster.getInstanceName(), cluster.getZooKeepers());
        final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, connector);
        // Install an instance of Rya that has all of the secondary indexers turned on.
        final String ryaInstanceName = "demoInstance_";
        final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableGeoIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setFluoPcjAppName(fluoAppName).build();
        ryaClient.getInstall().install(ryaInstanceName, installConfig);
        // Add a PCJ index.
        final String sparql = "SELECT ?patron ?employee " + "WHERE { " + "?patron <http://talksTo> ?employee. " + "?employee <http://worksAt> <http://CoffeeShop>. " + "}";
        // Load some statements into the Rya instance.
        final AccumuloIndexingConfiguration conf = AccumuloIndexingConfiguration.builder().setAuths("U").setAccumuloUser(accumuloUsername).setAccumuloPassword(accumuloPassword).setAccumuloInstance(cluster.getInstanceName()).setAccumuloZooKeepers(cluster.getZooKeepers()).setRyaPrefix(ryaInstanceName).setPcjUpdaterFluoAppName(fluoAppName).build();
        ryaSail = RyaSailFactory.getInstance(conf);
        final ValueFactory vf = ryaSail.getValueFactory();
        final List<Statement> statements = Lists.newArrayList(vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://talksTo"), vf.createURI("http://Charlie")), vf.createStatement(vf.createURI("http://David"), vf.createURI("http://talksTo"), vf.createURI("http://Alice")), vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://George"), vf.createURI("http://talksTo"), vf.createURI("http://Frank")), vf.createStatement(vf.createURI("http://Frank"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://talksTo"), vf.createURI("http://Bob")), vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")));
        SailConnection ryaConn = ryaSail.getConnection();
        log.info("");
        log.info("Loading the following statements:");
        ryaConn.begin();
        for (final Statement statement : statements) {
            log.info("    " + statement.toString());
            ryaConn.addStatement(statement.getSubject(), statement.getPredicate(), statement.getObject());
        }
        log.info("");
        ryaConn.close();
        fluo.waitForObservers();
        // Execute the SPARQL query and print the results.
        log.info("Executing the following query: ");
        prettyLogSparql(sparql);
        log.info("");
        final ParsedQuery parsedQuery = new SPARQLParser().parseQuery(sparql, null);
        ryaConn = ryaSail.getConnection();
        final CloseableIteration<? extends BindingSet, QueryEvaluationException> result = ryaConn.evaluate(parsedQuery.getTupleExpr(), null, null, false);
        log.info("Results:");
        while (result.hasNext()) {
            log.info("    " + result.next());
        }
        log.info("");
    } finally {
        if (ryaSail != null) {
            log.info("Shutting down the Rya Sail instance.");
            ryaSail.shutDown();
        }
        if (fluo != null) {
            try {
                log.info("Shutting down the Mini Fluo instance.");
                fluo.close();
            } catch (final Exception e) {
                log.error("Could not shut down the Mini Fluo instance.", e);
            }
        }
        if (cluster != null) {
            log.info("Sutting down the Mini Accumulo Cluster.");
            cluster.stop();
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Authorizations(org.apache.accumulo.core.security.Authorizations) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Statement(org.openrdf.model.Statement) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) AccumuloIndexingConfiguration(org.apache.rya.indexing.accumulo.AccumuloIndexingConfiguration) AlreadyInitializedException(org.apache.fluo.api.client.FluoAdmin.AlreadyInitializedException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) TableExistsException(org.apache.fluo.api.client.FluoAdmin.TableExistsException) MiniFluo(org.apache.fluo.api.mini.MiniFluo) SailConnection(org.openrdf.sail.SailConnection) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) Sail(org.openrdf.sail.Sail) File(java.io.File)

Aggregations

File (java.io.File)2 MiniFluo (org.apache.fluo.api.mini.MiniFluo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Connector (org.apache.accumulo.core.client.Connector)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 MiniAccumuloCluster (org.apache.accumulo.minicluster.MiniAccumuloCluster)1 MiniAccumuloConfig (org.apache.accumulo.minicluster.MiniAccumuloConfig)1 AlreadyInitializedException (org.apache.fluo.api.client.FluoAdmin.AlreadyInitializedException)1 TableExistsException (org.apache.fluo.api.client.FluoAdmin.TableExistsException)1 FluoConfiguration (org.apache.fluo.api.config.FluoConfiguration)1 ObserverSpecification (org.apache.fluo.api.config.ObserverSpecification)1 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)1 RyaClient (org.apache.rya.api.client.RyaClient)1 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)1 AccumuloIndexingConfiguration (org.apache.rya.indexing.accumulo.AccumuloIndexingConfiguration)1 RyaExportParameters (org.apache.rya.indexing.pcj.fluo.app.export.rya.RyaExportParameters)1 QueryResultObserver (org.apache.rya.indexing.pcj.fluo.app.observers.QueryResultObserver)1 Statement (org.openrdf.model.Statement)1 ValueFactory (org.openrdf.model.ValueFactory)1