Search in sources :

Example 6 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloExecuteSparqlQuery method executeSparqlQuery.

@Override
public String executeSparqlQuery(final String ryaInstanceName, final String sparqlQuery) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(sparqlQuery);
    // 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);
        sail = RyaSailFactory.getInstance(ryaConf);
        sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        // Execute the query.
        final long start = System.currentTimeMillis();
        final TupleQuery tupleQuery = sailRepoConn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQuery);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final CountingSPARQLResultsCSVWriter handler = new CountingSPARQLResultsCSVWriter(baos);
        tupleQuery.evaluate(handler);
        final StringBuilder sb = new StringBuilder();
        final String newline = "\n";
        sb.append("Query Result:").append(newline);
        sb.append(new String(baos.toByteArray(), StandardCharsets.UTF_8));
        final String seconds = new DecimalFormat("0.0##").format((System.currentTimeMillis() - start) / 1000.0);
        sb.append("Retrieved ").append(handler.getCount()).append(" results in ").append(seconds).append(" seconds.");
        return sb.toString();
    } catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
        throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the query to fail.", e);
    } catch (final MalformedQueryException e) {
        throw new RyaClientException("There was a problem parsing the supplied query.", e);
    } catch (final QueryEvaluationException | TupleQueryResultHandlerException e) {
        throw new RyaClientException("There was a problem evaluating the supplied query.", e);
    } catch (final RepositoryException e) {
        throw new RyaClientException("There was a problem executing the query against the Rya instance named " + ryaInstanceName + ".", 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) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) SailRepository(org.openrdf.repository.sail.SailRepository) DecimalFormat(java.text.DecimalFormat) TupleQuery(org.openrdf.query.TupleQuery) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SailException(org.openrdf.sail.SailException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MalformedQueryException(org.openrdf.query.MalformedQueryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 7 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration 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.openrdf.sail.SailException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) AlreadyInitializedException(org.apache.rya.api.instance.RyaDetailsRepository.AlreadyInitializedException) Sail(org.openrdf.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 8 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloInstall method makeRyaConfig.

/**
 * Builds a {@link AccumuloRdfConfiguration} object that will be used by the
 * Rya DAO to initialize all of the tables it will need.
 *
 * @param connectionDetails - Indicates how to connect to Accumulo. (not null)
 * @param details - Indicates what needs to be installed. (not null)
 * @return A Rya Configuration object that can be used to perform the install.
 */
private static AccumuloRdfConfiguration makeRyaConfig(final AccumuloConnectionDetails connectionDetails, final RyaDetails details) {
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    // The Rya Instance Name is used as a prefix for the index tables in Accumulo.
    conf.setTablePrefix(details.getRyaInstanceName());
    // Enable the indexers that the instance is configured to use.
    /**
     * RYA-215
     * conf.set(ConfigUtils.USE_GEO, "" + details.getGeoIndexDetails().isEnabled() );
     */
    /**
     * RYA-322
     * conf.setPrefixRowsWithHash(details.getPrefixRowsWithHashDetails().isEnabled());
     */
    conf.set(ConfigUtils.USE_FREETEXT, "" + details.getFreeTextIndexDetails().isEnabled());
    conf.set(ConfigUtils.USE_TEMPORAL, "" + details.getTemporalIndexDetails().isEnabled());
    conf.set(ConfigUtils.USE_ENTITY, "" + details.getEntityCentricIndexDetails().isEnabled());
    conf.set(ConfigUtils.USE_PCJ, "" + details.getPCJIndexDetails().isEnabled());
    conf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
    final Optional<FluoDetails> fluoHolder = details.getPCJIndexDetails().getFluoDetails();
    final PrecomputedJoinUpdaterType updaterType = fluoHolder.isPresent() ? PrecomputedJoinUpdaterType.FLUO : PrecomputedJoinUpdaterType.NO_UPDATE;
    conf.set(ConfigUtils.PCJ_UPDATER_TYPE, updaterType.toString());
    // XXX The Accumulo implementation of the secondary indices make need all
    // of the accumulo connector's parameters to initialize themselves, so
    // we need to include them here. It would be nice if the secondary
    // indexers used the connector that is provided to them instead of
    // building a new one.
    conf.set(ConfigUtils.CLOUDBASE_USER, connectionDetails.getUsername());
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, new String(connectionDetails.getUserPass()));
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, connectionDetails.getInstanceName());
    conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, connectionDetails.getZookeepers());
    // This initializes the living indexers that will be used by the application and
    // caches them within the configuration object so that they may be used later.
    ConfigUtils.setIndexers(conf);
    return conf;
}
Also used : PrecomputedJoinUpdaterType(org.apache.rya.indexing.external.PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails)

Example 9 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration 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.openrdf.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailException(org.openrdf.sail.SailException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RepositoryException(org.openrdf.repository.RepositoryException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 10 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class GraphXInputFormatTest method init.

@Before
public void init() throws Exception {
    instance = new MockInstance(GraphXInputFormatTest.class.getName() + ".mock_instance");
    Connector connector = instance.getConnector(username, password);
    connector.tableOperations().create(table);
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("rya_");
    conf.setDisplayQueryPlan(false);
    conf.setBoolean("sc.use_entity", true);
    apiImpl = new AccumuloRyaDAO();
    apiImpl.setConf(conf);
    apiImpl.setConnector(connector);
    apiImpl.init();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Before(org.junit.Before)

Aggregations

AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)108 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)26 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)25 Test (org.junit.Test)24 RyaURI (org.apache.rya.api.domain.RyaURI)22 Connector (org.apache.accumulo.core.client.Connector)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 Sail (org.openrdf.sail.Sail)15 RyaType (org.apache.rya.api.domain.RyaType)14 StatementPattern (org.openrdf.query.algebra.StatementPattern)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)12 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 BindingSet (org.openrdf.query.BindingSet)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10