Search in sources :

Example 6 with Sail

use of org.eclipse.rdf4j.sail.Sail in project incubator-rya by apache.

the class RulesetCopyIT method runQuery.

private Set<BindingSet> runQuery(final String query, final Configuration conf) throws Exception {
    SailRepository repository = null;
    SailRepositoryConnection conn = null;
    try {
        final Sail extSail = RyaSailFactory.getInstance(conf);
        repository = new SailRepository(extSail);
        conn = repository.getConnection();
        final ResultHandler handler = new ResultHandler();
        final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
        tq.evaluate(handler);
        return handler.getSolutions();
    } finally {
        if (conn != null) {
            conn.close();
        }
        if (repository != null) {
            repository.shutDown();
        }
    }
}
Also used : SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) TupleQueryResultHandler(org.eclipse.rdf4j.query.TupleQueryResultHandler) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)

Example 7 with Sail

use of org.eclipse.rdf4j.sail.Sail in project incubator-rya by apache.

the class PcjVisibilityIT method visibilitySimplified.

@Test
public void visibilitySimplified() throws Exception {
    // Create a PCJ index within Rya.
    final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "?customer <" + TALKS_TO + "> ?worker. " + "?worker <" + LIVES_IN + "> ?city. " + "?worker <" + WORKS_AT + "> <" + BURGER_JOINT + ">. " + "}";
    final Connector accumuloConn = super.getAccumuloConnector();
    final String instanceName = super.getMiniAccumuloCluster().getInstanceName();
    final String zookeepers = super.getMiniAccumuloCluster().getZooKeepers();
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(createConnectionDetails(), accumuloConn);
    final String pcjId = ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
    // Grant the root user the "u" authorization.
    super.getAccumuloConnector().securityOperations().changeUserAuthorizations(getUsername(), new Authorizations("u"));
    // Setup a connection to the Rya instance that uses the "u" authorizations. This ensures
    // any statements that are inserted will have the "u" authorization on them and that the
    // PCJ updating application will have to maintain visibilities.
    final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
    ryaConf.setTablePrefix(getRyaInstanceName());
    // Accumulo connection information.
    ryaConf.setAccumuloUser(getUsername());
    ryaConf.setAccumuloPassword(getPassword());
    ryaConf.setAccumuloInstance(super.getAccumuloConnector().getInstance().getInstanceName());
    ryaConf.setAccumuloZookeepers(super.getAccumuloConnector().getInstance().getZooKeepers());
    ryaConf.set(ConfigUtils.CLOUDBASE_AUTHS, "u");
    ryaConf.set(RdfCloudTripleStoreConfiguration.CONF_CV, "u");
    // PCJ configuration information.
    ryaConf.set(ConfigUtils.USE_PCJ, "true");
    ryaConf.set(ConfigUtils.USE_PCJ_UPDATER_INDEX, "true");
    ryaConf.set(ConfigUtils.FLUO_APP_NAME, super.getFluoConfiguration().getApplicationName());
    ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType.ACCUMULO.toString());
    ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType.FLUO.toString());
    Sail sail = null;
    RyaSailRepository ryaRepo = null;
    RepositoryConnection ryaConn = null;
    try {
        sail = RyaSailFactory.getInstance(ryaConf);
        ryaRepo = new RyaSailRepository(sail);
        ryaConn = ryaRepo.getConnection();
        // Load a few Statements into Rya.
        ryaConn.add(VF.createStatement(ALICE, TALKS_TO, BOB));
        ryaConn.add(VF.createStatement(BOB, LIVES_IN, HAPPYVILLE));
        ryaConn.add(VF.createStatement(BOB, WORKS_AT, BURGER_JOINT));
        // Wait for Fluo to finish processing.
        super.getMiniFluo().waitForObservers();
        // Fetch the exported result and show that its column visibility has been simplified.
        final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), pcjId);
        final Scanner scan = accumuloConn.createScanner(pcjTableName, new Authorizations("u"));
        scan.fetchColumnFamily(new Text("customer;worker;city"));
        final Entry<Key, Value> result = scan.iterator().next();
        final Key key = result.getKey();
        assertEquals(new Text("u"), key.getColumnVisibility());
    } finally {
        if (ryaConn != null) {
            try {
                ryaConn.close();
            } finally {
            }
        }
        if (ryaRepo != null) {
            try {
                ryaRepo.shutDown();
            } finally {
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } finally {
            }
        }
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) Text(org.apache.hadoop.io.Text) RyaClient(org.apache.rya.api.client.RyaClient) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Sail(org.eclipse.rdf4j.sail.Sail) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 8 with Sail

use of org.eclipse.rdf4j.sail.Sail in project incubator-rya by apache.

the class KafkaExportITBase method installRyaInstance.

private void installRyaInstance() throws Exception {
    final MiniAccumuloCluster cluster = super.getMiniAccumuloCluster();
    final String instanceName = cluster.getInstanceName();
    final String zookeepers = cluster.getZooKeepers();
    // Install the Rya instance to the mini accumulo cluster.
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), instanceName, zookeepers), super.getAccumuloConnector());
    ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableFreeTextIndex(false).setEnableEntityCentricIndex(false).setEnableGeoIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(true).setFluoPcjAppName(super.getFluoConfiguration().getApplicationName()).build());
    // Connect to the Rya instance that was just installed.
    final AccumuloRdfConfiguration conf = makeConfig(instanceName, zookeepers);
    final Sail sail = RyaSailFactory.getInstance(conf);
    dao = RyaSailFactory.getAccumuloDAOWithUpdatedConfig(conf);
    ryaSailRepo = new RyaSailRepository(sail);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) Sail(org.eclipse.rdf4j.sail.Sail) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) RyaClient(org.apache.rya.api.client.RyaClient) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 9 with Sail

use of org.eclipse.rdf4j.sail.Sail in project incubator-rya by apache.

the class AccumuloInstall method install.

@Override
public void install(final String instanceName, final InstallConfiguration installConfig) throws DuplicateInstanceNameException, RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(installConfig);
    // Check to see if a Rya instance has already been installed with this name.
    if (instanceExists.exists(instanceName)) {
        throw new DuplicateInstanceNameException("An instance of Rya has already been installed to this Rya storage " + "with the name '" + instanceName + "'. Try again with a different name.");
    }
    // Initialize the Rya Details table.
    RyaDetails details;
    try {
        details = initializeRyaDetails(instanceName, installConfig, getConnector().whoami());
    } catch (final AlreadyInitializedException e) {
        // This can only happen if somebody else installs an instance of Rya with the name between the check and now.
        throw new DuplicateInstanceNameException("An instance of Rya has already been installed to this Rya storage " + "with the name '" + instanceName + "'. Try again with a different name.");
    } catch (final RyaDetailsRepositoryException e) {
        throw new RyaClientException("The RyaDetails couldn't be initialized. Details: " + e.getMessage(), e);
    }
    // Initialize the rest of the tables used by the Rya instance.
    final AccumuloRdfConfiguration ryaConfig = makeRyaConfig(getAccumuloConnectionDetails(), details);
    try {
        final Sail ryaSail = RyaSailFactory.getInstance(ryaConfig);
        ryaSail.shutDown();
    } catch (final AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
        throw new RyaClientException("Could not initialize all of the tables for the new Rya instance. " + "This instance may be left in a bad state.", e);
    } catch (final SailException e) {
        throw new RyaClientException("Problem shutting down the Sail object used to install Rya.", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetails(org.apache.rya.api.instance.RyaDetails) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) SailException(org.eclipse.rdf4j.sail.SailException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) AlreadyInitializedException(org.apache.rya.api.instance.RyaDetailsRepository.AlreadyInitializedException) Sail(org.eclipse.rdf4j.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 10 with Sail

use of org.eclipse.rdf4j.sail.Sail in project incubator-rya by apache.

the class AccumuloLoadStatements method loadStatements.

@Override
public void loadStatements(final String ryaInstanceName, final Iterable<? extends Statement> statements) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(statements);
    // Ensure the Rya Instance exists.
    if (!instanceExists.exists(ryaInstanceName)) {
        throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
    }
    Sail sail = null;
    SailRepository sailRepo = null;
    SailRepositoryConnection sailRepoConn = null;
    try {
        // Get a Sail object that is connected to the Rya instance.
        final AccumuloRdfConfiguration ryaConf = getAccumuloConnectionDetails().buildAccumuloRdfConfiguration(ryaInstanceName);
        // RYA-327 should address this hardcoded value.
        ryaConf.setFlush(false);
        sail = RyaSailFactory.getInstance(ryaConf);
        // Load the file.
        sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        sailRepoConn.add(statements);
    } catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the load to fail.", e);
    } catch (final Exception e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem processing the RDF statements has caused the load into Rya instance named " + ryaInstanceName + "to fail.", e);
    } finally {
        // Shut it all down.
        if (sailRepoConn != null) {
            try {
                sailRepoConn.close();
            } catch (final RepositoryException e) {
                log.warn("Couldn't close the SailRepoConnection that is attached to the Rya instance.", e);
            }
        }
        if (sailRepo != null) {
            try {
                sailRepo.shutDown();
            } catch (final RepositoryException e) {
                log.warn("Couldn't shut down the SailRepository that is attached to the Rya instance.", e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.warn("Couldn't shut down the Sail that is attached to the Rya instance.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.eclipse.rdf4j.sail.SailException) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) SailException(org.eclipse.rdf4j.sail.SailException) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RyaClientException(org.apache.rya.api.client.RyaClientException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Sail(org.eclipse.rdf4j.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Aggregations

Sail (org.eclipse.rdf4j.sail.Sail)68 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)49 SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)37 Test (org.junit.Test)33 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)15 BindingSet (org.eclipse.rdf4j.query.BindingSet)13 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)13 SailException (org.eclipse.rdf4j.sail.SailException)13 HashSet (java.util.HashSet)11 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)11 SailConnection (org.eclipse.rdf4j.sail.SailConnection)11 RyaClient (org.apache.rya.api.client.RyaClient)9 ArrayList (java.util.ArrayList)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Configuration (org.apache.hadoop.conf.Configuration)8 RyaClientException (org.apache.rya.api.client.RyaClientException)8 MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)7 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)7 MapBindingSet (org.eclipse.rdf4j.query.impl.MapBindingSet)7 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7