Search in sources :

Example 1 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException 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 2 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class MongoGetInstanceDetails method getDetails.

@Override
public Optional<RyaDetails> getDetails(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));
    }
    // If the instance has details, then return them.
    final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(adminClient, ryaInstanceName);
    try {
        return Optional.of(detailsRepo.getRyaInstanceDetails());
    } catch (final NotInitializedException e) {
        return Optional.absent();
    } catch (final RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not fetch the Rya instance's details.", e);
    }
}
Also used : NotInitializedException(org.apache.rya.api.instance.RyaDetailsRepository.NotInitializedException) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetailsRepository(org.apache.rya.api.instance.RyaDetailsRepository) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException)

Example 3 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException 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)

Example 4 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class MongoPcjIndexSetProvider method hasRyaDetails.

private boolean hasRyaDetails() {
    final StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
    final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(mongoConf.getMongoClient(), mongoConf.getRyaInstanceName());
    try {
        detailsRepo.getRyaInstanceDetails();
        return true;
    } catch (final RyaDetailsRepositoryException e) {
        return false;
    }
}
Also used : StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) RyaDetailsRepository(org.apache.rya.api.instance.RyaDetailsRepository) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)

Example 5 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class AccumuloAddUser method addUser.

@Override
public void addUser(final String instanceName, final String username) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(username);
    // If the user has already been added, then return immediately.
    try {
        final RyaDetails details = new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName).getRyaInstanceDetails();
        final List<String> users = details.getUsers();
        if (users.contains(username)) {
            return;
        }
    } catch (final RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not fetch the RyaDetails for Rya instance named '" + instanceName + ".", e);
    }
    // Update the instance details
    final RyaDetailsUpdater updater = new RyaDetailsUpdater(new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName));
    try {
        updater.update(originalDetails -> RyaDetails.builder(originalDetails).addUser(username).build());
    } catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
        throw new RyaClientException("Could not add the user '" + username + "' to the Rya instance's details.", e);
    }
    // Grant all access to all the instance's tables.
    try {
        // Build the list of tables that are present within the Rya instance.
        final List<String> tables = new RyaTableNames().getTableNames(instanceName, getConnector());
        // Update the user permissions for those tables.
        for (final String table : tables) {
            try {
                TABLE_PERMISSIONS.grantAllPermissions(username, table, getConnector());
            } catch (AccumuloException | AccumuloSecurityException e) {
                throw new RyaClientException("Could not grant access to table '" + table + "' for user '" + username + "'.", e);
            }
        }
    } catch (PCJStorageException | RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not determine which tables exist for the '" + instanceName + "' instance of Rya.", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) RyaDetails(org.apache.rya.api.instance.RyaDetails) AccumuloRyaInstanceDetailsRepository(org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository) RyaTableNames(org.apache.rya.accumulo.utils.RyaTableNames) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Aggregations

RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)23 RyaDetails (org.apache.rya.api.instance.RyaDetails)15 RyaClientException (org.apache.rya.api.client.RyaClientException)12 RyaDetailsUpdater (org.apache.rya.api.instance.RyaDetailsUpdater)10 CouldNotApplyMutationException (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException)10 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)9 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)6 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)6 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)6 MongoRyaInstanceDetailsRepository (org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository)6 NotInitializedException (org.apache.rya.api.instance.RyaDetailsRepository.NotInitializedException)4 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)4 RyaTableNames (org.apache.rya.accumulo.utils.RyaTableNames)3 PCJIndexDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)3 RyaDetailsMutator (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)3 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)3 SailException (org.openrdf.sail.SailException)3