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);
}
}
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);
}
}
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);
}
}
Aggregations