Search in sources :

Example 11 with SailException

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

the class AccumuloBatchUpdatePCJ method updatePCJResults.

private void updatePCJResults(final String ryaInstanceName, final String pcjId) throws InstanceDoesNotExistException, PCJDoesNotExistException, RyaClientException {
    // Things that have to be closed before we exit.
    Sail sail = null;
    SailConnection sailConn = null;
    CloseableIteration<? extends BindingSet, QueryEvaluationException> results = null;
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(super.getConnector(), ryaInstanceName)) {
        // Create an instance of Sail backed by the Rya instance.
        sail = connectToRya(ryaInstanceName);
        // Purge the old results from the PCJ.
        try {
            pcjStorage.purge(pcjId);
        } catch (final PCJStorageException e) {
            throw new RyaClientException("Could not batch update PCJ with ID '" + pcjId + "' because the old " + "results could not be purged from it.", e);
        }
        // Parse the PCJ's SPARQL query.
        final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
        final String sparql = metadata.getSparql();
        final SPARQLParser parser = new SPARQLParser();
        final ParsedQuery parsedQuery = parser.parseQuery(sparql, null);
        // Execute the query.
        sailConn = sail.getConnection();
        results = sailConn.evaluate(parsedQuery.getTupleExpr(), null, null, false);
        // Load the results into the PCJ table.
        final List<VisibilityBindingSet> batch = new ArrayList<>(1000);
        while (results.hasNext()) {
            final VisibilityBindingSet result = new VisibilityBindingSet(results.next(), "");
            batch.add(result);
            if (batch.size() == 1000) {
                pcjStorage.addResults(pcjId, batch);
                batch.clear();
            }
        }
        if (!batch.isEmpty()) {
            pcjStorage.addResults(pcjId, batch);
            batch.clear();
        }
    } catch (final MalformedQueryException | PCJStorageException | SailException | QueryEvaluationException e) {
        throw new RyaClientException("Fail to batch load new results into the PCJ with ID '" + pcjId + "'.", e);
    } finally {
        if (results != null) {
            try {
                results.close();
            } catch (final QueryEvaluationException e) {
                log.warn(e.getMessage(), e);
            }
        }
        if (sailConn != null) {
            try {
                sailConn.close();
            } catch (final SailException e) {
                log.warn(e.getMessage(), e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.warn(e.getMessage(), e);
            }
        }
    }
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) RyaClientException(org.apache.rya.api.client.RyaClientException) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) SailException(org.eclipse.rdf4j.sail.SailException) SailConnection(org.eclipse.rdf4j.sail.SailConnection) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Sail(org.eclipse.rdf4j.sail.Sail) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 12 with SailException

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

the class MongoExecuteSparqlQuery method executeSparqlQuery.

@Override
public TupleQueryResult 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));
    }
    try {
        // Get a Sail object that is connected to the Rya instance.
        final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
        sail = RyaSailFactory.getInstance(ryaConf);
        final SailRepository sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        // Execute the query.
        final TupleQuery tupleQuery = sailRepoConn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQuery);
        return tupleQuery.evaluate();
    } catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
        throw new RyaClientException("Could not create the Sail object used to query the RYA instance.", e);
    } catch (final MalformedQueryException | QueryEvaluationException | RepositoryException e) {
        throw new RyaClientException("Could not execute the SPARQL query.", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) 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) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Example 13 with SailException

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

the class MongoInstall 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.
    final RyaDetails ryaDetails;
    try {
        ryaDetails = initializeRyaDetails(instanceName, installConfig);
    } 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 collections used by the Rya instance.
    final MongoDBRdfConfiguration ryaConfig = makeRyaConfig(connectionDetails, ryaDetails);
    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) 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) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Example 14 with SailException

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

the class MongoLoadStatementsFile method loadStatements.

@Override
public void loadStatements(final String ryaInstanceName, final Path statementsFile, final RDFFormat format) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(statementsFile);
    requireNonNull(format);
    // 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;
    SailRepositoryConnection sailRepoConn = null;
    try {
        // Get a Sail object that is connected to the Rya instance.
        final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
        sail = RyaSailFactory.getInstance(ryaConf);
        final SailRepository sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        // Load the file.
        sailRepoConn.add(statementsFile.toFile(), null, format);
    } catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
        throw new RyaClientException("Could not load statements into Rya because of a problem while creating the Sail object.", e);
    } catch (RDFParseException | RepositoryException | IOException e) {
        throw new RyaClientException("Could not load the statements into Rya.", e);
    } finally {
        // Close the resources that were opened.
        if (sailRepoConn != null) {
            try {
                sailRepoConn.close();
            } catch (final RepositoryException e) {
                log.error("Couldn't close the SailRepositoryConnection object.", e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.error("Couldn't close the Sail object.", 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) IOException(java.io.IOException) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Sail(org.eclipse.rdf4j.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 15 with SailException

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

the class MongoLoadStatements 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;
    SailRepositoryConnection sailRepoConn = null;
    try {
        // Get a Sail object that is connected to the Rya instance.
        final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
        sail = RyaSailFactory.getInstance(ryaConf);
        final SailRepository sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        // Load the statements.
        sailRepoConn = sailRepo.getConnection();
        sailRepoConn.add(statements);
    } catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
        throw new RyaClientException("Could not load statements into Rya because of a problem while creating the Sail object.", e);
    } catch (final RepositoryException e) {
        throw new RyaClientException("Could not load the statements into Rya.", e);
    } finally {
        // Close the resources that were opened.
        if (sailRepoConn != null) {
            try {
                sailRepoConn.close();
            } catch (final RepositoryException e) {
                log.error("Couldn't close the SailRepositoryConnection object.", e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.error("Couldn't close the Sail object.", 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) Sail(org.eclipse.rdf4j.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Aggregations

SailException (org.eclipse.rdf4j.sail.SailException)36 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)19 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)17 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)17 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 RyaClientException (org.apache.rya.api.client.RyaClientException)13 Sail (org.eclipse.rdf4j.sail.Sail)13 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)12 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)8 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)7 IOException (java.io.IOException)6 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)6 PathPatternException (com.inova8.pathql.processor.PathPatternException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 RecognitionException (org.antlr.v4.runtime.RecognitionException)5 Resource (org.eclipse.rdf4j.model.Resource)5 SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)5 SailConnection (org.eclipse.rdf4j.sail.SailConnection)5