Search in sources :

Example 1 with RyaTableNames

use of org.apache.rya.accumulo.utils.RyaTableNames 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)

Example 2 with RyaTableNames

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

the class AccumuloRemoveUser method removeUser.

@Override
public void removeUser(final String instanceName, final String username) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(username);
    // Update the instance details.
    final RyaDetailsUpdater updater = new RyaDetailsUpdater(new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName));
    try {
        updater.update(originalDetails -> RyaDetails.builder(originalDetails).removeUser(username).build());
    } catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
        throw new RyaClientException("Could not remove the user '" + username + "' from the Rya instance's details.", e);
    }
    // Revoke 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.revokeAllPermissions(username, table, getConnector());
            } catch (AccumuloException | AccumuloSecurityException e) {
                throw new RyaClientException("Could not revoke access to table '" + table + "' from 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) 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)

Example 3 with RyaTableNames

use of org.apache.rya.accumulo.utils.RyaTableNames 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)

Aggregations

AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 RyaTableNames (org.apache.rya.accumulo.utils.RyaTableNames)3 RyaClientException (org.apache.rya.api.client.RyaClientException)3 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)3 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)3 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)2 RyaDetailsUpdater (org.apache.rya.api.instance.RyaDetailsUpdater)2 CouldNotApplyMutationException (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)1 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)1 RyaDetails (org.apache.rya.api.instance.RyaDetails)1