use of org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException in project incubator-rya by apache.
the class AccumuloPcjStorage method dropPcj.
@Override
public void dropPcj(final String pcjId) throws PCJStorageException {
requireNonNull(pcjId);
// Update the Rya Details for this instance to no longer include the PCJ.
try {
new RyaDetailsUpdater(ryaDetailsRepo).update(originalDetails -> {
// Drop the PCJ's metadata from the instance's metadata.
final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails);
mutated.getPCJIndexDetails().removePCJDetails(pcjId);
return mutated.build();
});
} catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new PCJStorageException(String.format("Could not drop an existing PCJ for Rya instance '%s' " + "because of a problem while updating the instance's details.", ryaInstanceName), e);
}
// Delete the table that hold's the PCJ's results.
final String pcjTableName = pcjTableNameFactory.makeTableName(ryaInstanceName, pcjId);
pcjTables.dropPcjTable(accumuloConn, pcjTableName);
}
use of org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException 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.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException in project incubator-rya by apache.
the class MongoPcjStorage method createPcj.
@Override
public String createPcj(final String sparql) throws PCJStorageException {
requireNonNull(sparql);
// Update the Rya Details for this instance to include the new PCJ
// table.
final String pcjId = pcjIdFactory.nextId();
try {
new RyaDetailsUpdater(ryaDetailsRepo).update(originalDetails -> {
// Create the new PCJ's details.
final PCJDetails.Builder newPcjDetails = PCJDetails.builder().setId(pcjId);
// Add them to the instance's details.
final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails);
mutated.getPCJIndexDetails().addPCJDetails(newPcjDetails);
return mutated.build();
});
} catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new PCJStorageException(String.format("Could not create a new PCJ for Rya instance '%s' " + "because of a problem while updating the instance's details.", ryaInstanceName), e);
}
// Create the objectID of the document to house the PCJ results.
pcjDocs.createPcj(pcjId, sparql);
// instance of Rya.
return pcjId;
}
use of org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException in project incubator-rya by apache.
the class AccumuloPcjStorage method createPcj.
@Override
public String createPcj(final String sparql) throws PCJStorageException {
requireNonNull(sparql);
// Create the variable orders that will be used within Accumulo to store the PCJ.
final Set<VariableOrder> varOrders;
try {
varOrders = pcjVarOrderFactory.makeVarOrders(sparql);
} catch (final MalformedQueryException e) {
throw new PCJStorageException("Can not create the PCJ. The SPARQL is malformed.", e);
}
// Update the Rya Details for this instance to include the new PCJ table.
final String pcjId = pcjIdFactory.nextId();
try {
new RyaDetailsUpdater(ryaDetailsRepo).update(originalDetails -> {
// Create the new PCJ's details.
final PCJDetails.Builder newPcjDetails = PCJDetails.builder().setId(pcjId);
// Add them to the instance's details.
final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails);
mutated.getPCJIndexDetails().addPCJDetails(newPcjDetails);
return mutated.build();
});
} catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new PCJStorageException(String.format("Could not create a new PCJ for Rya instance '%s' " + "because of a problem while updating the instance's details.", ryaInstanceName), e);
}
// Create the table that will hold the PCJ's results.
final String pcjTableName = pcjTableNameFactory.makeTableName(ryaInstanceName, pcjId);
pcjTables.createPcjTable(accumuloConn, pcjTableName, varOrders, sparql);
// Add access to the PCJ table to all users who are authorized for this instance of Rya.
try {
for (final String user : ryaDetailsRepo.getRyaInstanceDetails().getUsers()) {
TABLE_PERMISSIONS.grantAllPermissions(user, pcjTableName, accumuloConn);
}
} catch (final RyaDetailsRepositoryException | AccumuloException | AccumuloSecurityException e) {
throw new PCJStorageException(String.format("Could not grant authorized users access to the " + "new PCJ index table '%s' for Rya instance '%s' because of a problem while granting " + "the permissions.", pcjTableName, ryaInstanceName), e);
}
return pcjId;
}
use of org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException in project incubator-rya by apache.
the class SetRyaStreamsConfigurationBase method setRyaStreamsConfiguration.
@Override
public void setRyaStreamsConfiguration(final String ryaInstance, final RyaStreamsDetails streamsDetails) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstance);
requireNonNull(streamsDetails);
// Verify the Rya Instance exists.
if (!instanceExists.exists(ryaInstance)) {
throw new InstanceDoesNotExistException("There is no Rya instance named '" + ryaInstance + "' in this storage.");
}
// Update the old details object using the provided Rya Streams details.
final RyaDetailsRepository repo = getRyaDetailsRepo(ryaInstance);
try {
new RyaDetailsUpdater(repo).update(oldDetails -> {
final RyaDetails.Builder builder = RyaDetails.builder(oldDetails);
builder.setRyaStreamsDetails(streamsDetails);
return builder.build();
});
} catch (CouldNotApplyMutationException | RyaDetailsRepositoryException e) {
throw new RyaClientException("Unable to update which Rya Streams subsystem is used by the '" + ryaInstance + "' Rya instance.", e);
}
}
Aggregations