Search in sources :

Example 41 with RyaClientException

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

the class AccumuloUninstall method uninstall.

@Override
public void uninstall(final String ryaInstanceName) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    // Ensure the Rya Instance exists.
    if (!instanceExists.exists(ryaInstanceName)) {
        throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
    }
    try {
        // Build the list of tables that are present within the Rya instance.
        final List<String> tables = new RyaTableNames().getTableNames(ryaInstanceName, getConnector());
        // Delete them.
        final TableOperations tableOps = getConnector().tableOperations();
        for (final String table : tables) {
            try {
                tableOps.delete(table);
            } catch (final TableNotFoundException e) {
                log.warn("Uninstall could not delete table named '" + LogUtils.clean(table) + "' because it does not exist. " + "Something else is also deleting tables.");
            }
        }
    } catch (PCJStorageException | RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not uninstall the Rya instance named '" + ryaInstanceName + "' because we could not determine which tables are associated with it.", e);
    } catch (AccumuloException | AccumuloSecurityException e) {
        throw new RyaClientException("Could not uninstall the Rya instance named '" + ryaInstanceName + "' because of a problem interacting with Accumulo..", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) RyaTableNames(org.apache.rya.accumulo.utils.RyaTableNames) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 42 with RyaClientException

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

the class MongoBatchUpdatePCJ method verifyPCJState.

private void verifyPCJState(final String ryaInstanceName, final String pcjId, final MongoClient client) throws RyaClientException {
    try {
        // Fetch the Rya instance's details.
        final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(client, ryaInstanceName);
        final RyaDetails ryaDetails = detailsRepo.getRyaInstanceDetails();
        // Ensure PCJs are enabled.
        if (!ryaDetails.getPCJIndexDetails().isEnabled()) {
            throw new RyaClientException("PCJs are not enabled for the Rya instance named '" + ryaInstanceName + "'.");
        }
        // Ensure the PCJ exists.
        if (!ryaDetails.getPCJIndexDetails().getPCJDetails().containsKey(pcjId)) {
            throw new PCJDoesNotExistException("The PCJ with id '" + pcjId + "' does not exist within Rya instance '" + ryaInstanceName + "'.");
        }
    } catch (final NotInitializedException e) {
        throw new InstanceDoesNotExistException("No RyaDetails are initialized for the Rya instance named '" + ryaInstanceName + "'.", e);
    } catch (final RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not fetch the RyaDetails for the Rya instance named '" + ryaInstanceName + "'.", e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) NotInitializedException(org.apache.rya.api.instance.RyaDetailsRepository.NotInitializedException) PCJDoesNotExistException(org.apache.rya.api.client.PCJDoesNotExistException) RyaDetailsRepository(org.apache.rya.api.instance.RyaDetailsRepository) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException)

Example 43 with RyaClientException

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

the class MongoBatchUpdatePCJ method updatePCJResults.

private void updatePCJResults(final String ryaInstanceName, final String pcjId, final MongoClient client) throws InstanceDoesNotExistException, PCJDoesNotExistException, RyaClientException {
    // Things that have to be closed before we exit.
    Sail sail = null;
    SailConnection sailConn = null;
    try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(client, ryaInstanceName)) {
        // Create an instance of Sail backed by the Rya instance.
        sail = connectToRya(ryaInstanceName);
        final SailRepository sailRepo = new SailRepository(sail);
        final SailRepositoryConnection sailRepoConn = sailRepo.getConnection();
        // 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();
        sailConn = sail.getConnection();
        final TupleQuery tupleQuery = sailRepoConn.prepareTupleQuery(QueryLanguage.SPARQL, sparql);
        // Execute the query.
        final List<VisibilityBindingSet> batch = new ArrayList<>(1000);
        tupleQuery.evaluate(new TupleQueryResultHandlerBase() {

            @Override
            public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException {
                final VisibilityBindingSet result = new VisibilityBindingSet(bindingSet, "");
                log.warn("Visibility information on the binding set is lost during a batch update." + "  This can create data leaks.");
                batch.add(result);
                if (batch.size() == 1000) {
                    try {
                        pcjStorage.addResults(pcjId, batch);
                    } catch (final PCJStorageException e) {
                        throw new TupleQueryResultHandlerException("Fail to batch load new results into the PCJ with ID '" + pcjId + "'.", e);
                    }
                    batch.clear();
                }
            }
        });
        if (!batch.isEmpty()) {
            pcjStorage.addResults(pcjId, batch);
            batch.clear();
        }
    } catch (final MalformedQueryException | PCJStorageException | SailException | QueryEvaluationException | RepositoryException | TupleQueryResultHandlerException e) {
        throw new RyaClientException("Fail to batch load new results into the PCJ with ID '" + pcjId + "'.", e);
    } finally {
        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 : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) RyaClientException(org.apache.rya.api.client.RyaClientException) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TupleQueryResultHandlerBase(org.openrdf.query.TupleQueryResultHandlerBase) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) SailRepository(org.openrdf.repository.sail.SailRepository) ArrayList(java.util.ArrayList) TupleQuery(org.openrdf.query.TupleQuery) RepositoryException(org.openrdf.repository.RepositoryException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) SailException(org.openrdf.sail.SailException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) MongoPcjStorage(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage) SailConnection(org.openrdf.sail.SailConnection) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Sail(org.openrdf.sail.Sail) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 44 with RyaClientException

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

the class MongoCreatePCJ method createPCJ.

@Override
public String createPCJ(final String ryaInstanceName, final String sparql, final Set<ExportStrategy> strategies) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(sparql);
    // Ensure the Rya Instance exists.
    if (!instanceExists.exists(ryaInstanceName)) {
        throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
    }
    try (final MongoPcjStorage pcjStore = new MongoPcjStorage(mongoClient, ryaInstanceName)) {
        return pcjStore.createPcj(sparql);
    } catch (final PCJStorageException e) {
        throw new RyaClientException("Unable to create PCJ for: " + sparql, e);
    }
}
Also used : MongoPcjStorage(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage) RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 45 with RyaClientException

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

the class AccumuloTemporalIndexer method initReadWrite.

/**
 * Initialize for writable use.
 * This is called from the DAO, perhaps others.
 */
private void initReadWrite() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, RyaClientException {
    if (mtbw == null)
        throw new RyaClientException("Failed to initialize temporal index, setMultiTableBatchWriter() was not set.");
    if (conf == null)
        throw new RyaClientException("Failed to initialize temporal index, setConf() was not set.");
    if (temporalIndexTableName == null)
        throw new RyaClientException("Failed to set temporalIndexTableName==null.");
    // Now do all the writable setup, read should already be complete.
    // Create one index table on first run.
    Boolean isCreated = ConfigUtils.createTableIfNotExists(conf, temporalIndexTableName);
    if (isCreated) {
        logger.info("First run, created temporal index table: " + temporalIndexTableName);
    }
    temporalIndexBatchWriter = mtbw.getBatchWriter(temporalIndexTableName);
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException)

Aggregations

RyaClientException (org.apache.rya.api.client.RyaClientException)48 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)27 RyaClient (org.apache.rya.api.client.RyaClient)18 CliCommand (org.springframework.shell.core.annotation.CliCommand)18 RyaDetails (org.apache.rya.api.instance.RyaDetails)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)14 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)13 SailException (org.openrdf.sail.SailException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)12 IOException (java.io.IOException)11 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 Sail (org.openrdf.sail.Sail)10 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)9 RepositoryException (org.openrdf.repository.RepositoryException)9 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)8 MalformedQueryException (org.openrdf.query.MalformedQueryException)8 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)7 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7