use of org.apache.rya.api.client.InstanceDoesNotExistException in project incubator-rya by apache.
the class AccumuloBatchUpdatePCJ method verifyPCJState.
private void verifyPCJState(final String ryaInstanceName, final String pcjId) throws RyaClientException {
try {
// Fetch the Rya instance's details.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(super.getConnector(), 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 + "'.");
}
// Ensure the PCJ is not already being incrementally updated.
final PCJDetails pcjDetails = ryaDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final Optional<PCJUpdateStrategy> updateStrategy = pcjDetails.getUpdateStrategy();
if (updateStrategy.isPresent() && updateStrategy.get() == PCJUpdateStrategy.INCREMENTAL) {
throw new RyaClientException("The PCJ with id '" + pcjId + "' is already being updated incrementally.");
}
} 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);
}
}
use of org.apache.rya.api.client.InstanceDoesNotExistException in project incubator-rya by apache.
the class MongoLoadStatementsFile method loadStatements.
@Override
public void loadStatements(final String ryaInstanceName, final Path statementsFile, final RDFFormat format) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(statementsFile);
requireNonNull(format);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
Sail sail = null;
SailRepositoryConnection sailRepoConn = null;
try {
// Get a Sail object that is connected to the Rya instance.
final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
sail = RyaSailFactory.getInstance(ryaConf);
final SailRepository sailRepo = new SailRepository(sail);
sailRepoConn = sailRepo.getConnection();
// Load the file.
sailRepoConn.add(statementsFile.toFile(), null, format);
} catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
throw new RyaClientException("Could not load statements into Rya because of a problem while creating the Sail object.", e);
} catch (RDFParseException | RepositoryException | IOException e) {
throw new RyaClientException("Could not load the statements into Rya.", e);
} finally {
// Close the resources that were opened.
if (sailRepoConn != null) {
try {
sailRepoConn.close();
} catch (final RepositoryException e) {
log.error("Couldn't close the SailRepositoryConnection object.", e);
}
}
if (sail != null) {
try {
sail.shutDown();
} catch (final SailException e) {
log.error("Couldn't close the Sail object.", e);
}
}
}
}
use of org.apache.rya.api.client.InstanceDoesNotExistException in project incubator-rya by apache.
the class MongoLoadStatements method loadStatements.
@Override
public void loadStatements(final String ryaInstanceName, final Iterable<? extends Statement> statements) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(statements);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
Sail sail = null;
SailRepositoryConnection sailRepoConn = null;
try {
// Get a Sail object that is connected to the Rya instance.
final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
sail = RyaSailFactory.getInstance(ryaConf);
final SailRepository sailRepo = new SailRepository(sail);
sailRepoConn = sailRepo.getConnection();
// Load the statements.
sailRepoConn = sailRepo.getConnection();
sailRepoConn.add(statements);
} catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
throw new RyaClientException("Could not load statements into Rya because of a problem while creating the Sail object.", e);
} catch (final RepositoryException e) {
throw new RyaClientException("Could not load the statements into Rya.", e);
} finally {
// Close the resources that were opened.
if (sailRepoConn != null) {
try {
sailRepoConn.close();
} catch (final RepositoryException e) {
log.error("Couldn't close the SailRepositoryConnection object.", e);
}
}
if (sail != null) {
try {
sail.shutDown();
} catch (final SailException e) {
log.error("Couldn't close the Sail object.", e);
}
}
}
}
use of org.apache.rya.api.client.InstanceDoesNotExistException in project incubator-rya by apache.
the class RyaAdminCommands method removeUser.
@CliCommand(value = REMOVE_USER_CMD, help = "Removes an authorized user from the Rya instance.")
public void removeUser(@CliOption(key = { "username" }, mandatory = true, help = "The username of the user whose access will be revoked.") final String username) {
// Fetch the Rya client that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient ryaClient = shellState.getConnectedCommands().get();
final String ryaInstance = shellState.getRyaInstanceName().get();
try {
ryaClient.getRemoveUser().get().removeUser(ryaInstance, username);
} catch (final InstanceDoesNotExistException e) {
throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e);
} catch (final RyaClientException e) {
throw new RuntimeException("The user's access could not be revoked. Provided reason: " + e.getMessage(), e);
}
}
use of org.apache.rya.api.client.InstanceDoesNotExistException in project incubator-rya by apache.
the class RyaAdminCommands method createPeriodicPcj.
@CliCommand(value = CREATE_PERIODIC_PCJ_CMD, help = "Creates and starts the maintenance of a new Periodic PCJ and registers the associated Periodic Notification with Kafka.")
public String createPeriodicPcj(@CliOption(key = { "topic" }, mandatory = true, help = "Kafka topic for registering new PeriodicNotifications. This topic is monitored by the Periodic Notification Service.") final String topic, @CliOption(key = { "brokers" }, mandatory = true, help = "Comma delimited list of host/port pairs to establish the initial connection to the Kafka cluster.") final String brokers) {
// Fetch the command that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient commands = shellState.getConnectedCommands().get();
final String ryaInstance = shellState.getRyaInstanceName().get();
try {
// Prompt the user for the SPARQL.
final Optional<String> sparql = sparqlPrompt.getSparql();
if (sparql.isPresent()) {
// Execute the command.
final String pcjId = commands.getCreatePeriodicPCJ().get().createPeriodicPCJ(ryaInstance, sparql.get(), topic, brokers);
// Return a message that indicates the ID of the newly created ID.
return String.format("The Periodic PCJ has been created. Its ID is '%s'.", pcjId);
} else {
// user aborted the SPARQL prompt.
return "";
}
} catch (final InstanceDoesNotExistException e) {
throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e);
} catch (final IOException | RyaClientException e) {
throw new RuntimeException("Could not create the Periodic PCJ. Provided reasons: " + e.getMessage(), e);
}
}
Aggregations