Search in sources :

Example 1 with SailException

use of org.openrdf.sail.SailException 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 2 with SailException

use of org.openrdf.sail.SailException 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 3 with SailException

use of org.openrdf.sail.SailException 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 4 with SailException

use of org.openrdf.sail.SailException in project incubator-rya by apache.

the class RdfCloudTripleStore method initializeInternal.

@Override
protected void initializeInternal() throws SailException {
    checkNotNull(ryaDAO);
    if (this.conf == null) {
        this.conf = ryaDAO.getConf();
    }
    checkNotNull(this.conf);
    try {
        if (!ryaDAO.isInitialized()) {
            ryaDAO.setConf(this.conf);
            ryaDAO.init();
        }
    } catch (final RyaDAOException e) {
        throw new SailException(e);
    }
    if (rdfEvalStatsDAO != null && !rdfEvalStatsDAO.isInitialized()) {
        rdfEvalStatsDAO.setConf(this.conf);
        rdfEvalStatsDAO.init();
    }
    if (namespaceManager == null) {
        this.namespaceManager = new NamespaceManager(ryaDAO, this.conf);
    }
}
Also used : NamespaceManager(org.apache.rya.rdftriplestore.namespace.NamespaceManager) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.openrdf.sail.SailException)

Example 5 with SailException

use of org.openrdf.sail.SailException in project incubator-rya by apache.

the class AccumuloCreatePCJ method createPCJ.

@Override
public String createPCJ(final String instanceName, final String sparql, Set<ExportStrategy> strategies) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(sparql);
    final Optional<RyaDetails> ryaDetailsHolder = getInstanceDetails.getDetails(instanceName);
    final boolean ryaInstanceExists = ryaDetailsHolder.isPresent();
    if (!ryaInstanceExists) {
        throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
    }
    final PCJIndexDetails pcjIndexDetails = ryaDetailsHolder.get().getPCJIndexDetails();
    final boolean pcjIndexingEnabeld = pcjIndexDetails.isEnabled();
    if (!pcjIndexingEnabeld) {
        throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
    }
    // Create the PCJ table that will receive the index results.
    final String pcjId;
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(getConnector(), instanceName)) {
        pcjId = pcjStorage.createPcj(sparql);
        // If a Fluo application is being used, task it with updating the PCJ.
        final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
        if (fluoDetailsHolder.isPresent()) {
            final String fluoAppName = fluoDetailsHolder.get().getUpdateAppName();
            try {
                updateFluoApp(instanceName, fluoAppName, pcjId, sparql, strategies);
            } catch (RepositoryException | MalformedQueryException | SailException | QueryEvaluationException | PcjException | RyaDAOException e) {
                throw new RyaClientException("Problem while initializing the Fluo application with the new PCJ.", e);
            } catch (UnsupportedQueryException e) {
                throw new RyaClientException("The new PCJ could not be initialized because it either contains an unsupported query node " + "or an invalid ExportStrategy for the given QueryType.  Projection queries can be exported to either Rya or Kafka," + "unless they contain an aggregation, in which case they can only be exported to Kafka.  Construct queries can be exported" + "to Rya and Kafka, and Periodic queries can only be exported to Rya.");
            }
            // Update the Rya Details to indicate the PCJ is being updated incrementally.
            final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName);
            try {
                new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {

                    @Override
                    public RyaDetails mutate(final RyaDetails originalDetails) throws CouldNotApplyMutationException {
                        // Update the original PCJ Details to indicate they are incrementally updated.
                        final PCJDetails originalPCJDetails = originalDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
                        final PCJDetails.Builder mutatedPCJDetails = PCJDetails.builder(originalPCJDetails).setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL);
                        // Replace the old PCJ Details with the updated ones.
                        final RyaDetails.Builder builder = RyaDetails.builder(originalDetails);
                        builder.getPCJIndexDetails().addPCJDetails(mutatedPCJDetails);
                        return builder.build();
                    }
                });
            } catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
                throw new RyaClientException("Problem while updating the Rya instance's Details to indicate the PCJ is being incrementally updated.", e);
            }
        }
        // Return the ID that was assigned to the PCJ.
        return pcjId;
    } catch (final PCJStorageException e) {
        throw new RyaClientException("Problem while initializing the PCJ table.", e);
    }
}
Also used : AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) RyaDetails(org.apache.rya.api.instance.RyaDetails) AccumuloRyaInstanceDetailsRepository(org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails) PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetailsMutator(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) RepositoryException(org.openrdf.repository.RepositoryException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaDetailsRepository(org.apache.rya.api.instance.RyaDetailsRepository) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Aggregations

SailException (org.openrdf.sail.SailException)46 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)17 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RyaClientException (org.apache.rya.api.client.RyaClientException)13 SailConnection (org.openrdf.sail.SailConnection)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 Sail (org.openrdf.sail.Sail)11 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)10 URI (org.openrdf.model.URI)10 RepositoryException (org.openrdf.repository.RepositoryException)10 MalformedQueryException (org.openrdf.query.MalformedQueryException)9 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)8 Statement (org.openrdf.model.Statement)8 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 Resource (org.openrdf.model.Resource)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)4