Search in sources :

Example 21 with InstallConfiguration

use of org.apache.rya.api.client.Install.InstallConfiguration 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)

Example 22 with InstallConfiguration

use of org.apache.rya.api.client.Install.InstallConfiguration in project incubator-rya by apache.

the class MongoLoadStatementsFileIT method loadTurtleFile.

@Test
public void loadTurtleFile() throws Exception {
    // Install an instance of Rya.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).build();
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install(conf.getRyaInstanceName(), installConfig);
    // Load the test statement file.
    ryaClient.getLoadStatementsFile().loadStatements(conf.getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
    // Verify that the statements were loaded.
    final ValueFactory vf = new ValueFactoryImpl();
    final Set<Statement> expected = new HashSet<>();
    expected.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
    expected.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
    expected.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
    final Set<Statement> statements = new HashSet<>();
    final MongoCursor<Document> triplesIterator = getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).find().iterator();
    while (triplesIterator.hasNext()) {
        final Document triple = triplesIterator.next();
        statements.add(vf.createStatement(vf.createURI(triple.getString("subject")), vf.createURI(triple.getString("predicate")), vf.createURI(triple.getString("object"))));
    }
    assertEquals(expected, statements);
}
Also used : Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) Document(org.bson.Document) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with InstallConfiguration

use of org.apache.rya.api.client.Install.InstallConfiguration in project incubator-rya by apache.

the class MongoSetRyaStreamsConfigurationIT method updatesRyaDetails.

@Test
public void updatesRyaDetails() throws Exception {
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    // Install an instance of Rya.
    final String ryaInstance = conf.getRyaInstanceName();
    final Install installRya = ryaClient.getInstall();
    final InstallConfiguration installConf = InstallConfiguration.builder().build();
    installRya.install(ryaInstance, installConf);
    // Fetch its details and show they do not have any RyaStreamsDetails.
    com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
    assertFalse(streamsDetails.isPresent());
    // Set the details.
    final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
    ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
    // Fetch its details again and show that they are now filled in.
    streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
    assertEquals(details, streamsDetails.get());
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClient(org.apache.rya.api.client.RyaClient) Install(org.apache.rya.api.client.Install) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Test(org.junit.Test)

Example 24 with InstallConfiguration

use of org.apache.rya.api.client.Install.InstallConfiguration in project incubator-rya by apache.

the class AccumuloCreatePCJIT method createPCJ_invalidSparql.

@Test(expected = RyaClientException.class)
public void createPCJ_invalidSparql() throws DuplicateInstanceNameException, RyaClientException {
    // Install an instance of Rya.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(true).setEnableGeoIndex(false).setFluoPcjAppName(getRyaInstanceName()).build();
    final Install install = new AccumuloInstall(createConnectionDetails(), accumuloConn);
    install.install(getRyaInstanceName(), installConfig);
    // Create a PCJ using invalid SPARQL.
    final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
    createPCJ.createPCJ(getRyaInstanceName(), "not valid sparql");
}
Also used : CreatePCJ(org.apache.rya.api.client.CreatePCJ) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Example 25 with InstallConfiguration

use of org.apache.rya.api.client.Install.InstallConfiguration in project incubator-rya by apache.

the class AccumuloGetInstanceDetailsIT method getDetails.

@Test
public void getDetails() throws AccumuloException, AccumuloSecurityException, DuplicateInstanceNameException, RyaClientException {
    // Install an instance of Rya.
    final String instanceName = getRyaInstanceName();
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setEnableGeoIndex(true).build();
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
    final Install install = new AccumuloInstall(connectionDetails, getConnector());
    install.install(instanceName, installConfig);
    // Verify the correct details were persisted.
    final GetInstanceDetails getInstanceDetails = new AccumuloGetInstanceDetails(connectionDetails, getConnector());
    final Optional<RyaDetails> details = getInstanceDetails.getDetails(instanceName);
    final RyaDetails expectedDetails = RyaDetails.builder().setRyaInstanceName(instanceName).setRyaVersion(details.get().getRyaVersion()).setTemporalIndexDetails(new TemporalIndexDetails(true)).setFreeTextDetails(new FreeTextIndexDetails(true)).setEntityCentricIndexDetails(new EntityCentricIndexDetails(true)).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).setProspectorDetails(new ProspectorDetails(Optional.<Date>absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.<Date>absent())).build();
    assertEquals(expectedDetails, details.get());
}
Also used : ProspectorDetails(org.apache.rya.api.instance.RyaDetails.ProspectorDetails) RyaDetails(org.apache.rya.api.instance.RyaDetails) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Date(java.util.Date) JoinSelectivityDetails(org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails) EntityCentricIndexDetails(org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails) TemporalIndexDetails(org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails) GetInstanceDetails(org.apache.rya.api.client.GetInstanceDetails) FreeTextIndexDetails(org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Aggregations

InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)32 RyaClient (org.apache.rya.api.client.RyaClient)26 Test (org.junit.Test)26 Install (org.apache.rya.api.client.Install)20 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)6 Statement (org.openrdf.model.Statement)5 CreatePCJ (org.apache.rya.api.client.CreatePCJ)4 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)4 RyaDetails (org.apache.rya.api.instance.RyaDetails)4 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)4 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DuplicateInstanceNameException (org.apache.rya.api.client.Install.DuplicateInstanceNameException)3 InstanceExists (org.apache.rya.api.client.InstanceExists)3 RyaClientException (org.apache.rya.api.client.RyaClientException)3 AccumuloCreatePCJ (org.apache.rya.api.client.accumulo.AccumuloCreatePCJ)3 ValueFactory (org.openrdf.model.ValueFactory)3 Sail (org.openrdf.sail.Sail)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3