use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class RyaCommands method sparqlQuery.
@CliCommand(value = SPARQL_QUERY_CMD, help = "Executes the provided SPARQL Query on the connected Rya instance.")
public String sparqlQuery(@CliOption(key = { "file" }, mandatory = false, help = "A local file containing the SPARQL Query that is to be read and executed.") final String file) {
// Fetch the command that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient commands = shellState.getConnectedCommands().get();
final Optional<String> ryaInstanceName = shellState.getRyaInstanceName();
try {
// file option specified
String sparqlQuery;
if (file != null) {
sparqlQuery = new String(Files.readAllBytes(new File(file).toPath()), StandardCharsets.UTF_8);
consolePrinter.println("Loaded Query:");
consolePrinter.println(sparqlQuery);
} else {
// No Options specified. Show the user the SPARQL Prompt
final Optional<String> sparqlQueryOpt = sparqlPrompt.getSparql();
if (sparqlQueryOpt.isPresent()) {
sparqlQuery = sparqlQueryOpt.get();
} else {
// user aborted the SPARQL prompt.
return "";
}
}
consolePrinter.println("Executing Query...");
consolePrinter.flush();
return commands.getExecuteSparqlQuery().executeSparqlQuery(ryaInstanceName.get(), sparqlQuery);
} catch (final RyaClientException | IOException e) {
log.error("Error", e);
throw new RuntimeException("Can not execute the SPARQL Query. Reason: " + e.getMessage(), e);
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class AccumuloListIncrementalQueries method listIncrementalQueries.
@Override
public String listIncrementalQueries(String instanceName) throws RyaClientException {
requireNonNull(instanceName);
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));
}
// 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 {
return getFluoQueryString(instanceName, fluoAppName);
} catch (Exception e) {
throw new RyaClientException("Problem while creating Fluo Query Strings.", e);
}
} else {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have Fluo incremental updating enabled.", instanceName));
}
}
use of org.apache.rya.api.client.RyaClientException 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.client.RyaClientException in project incubator-rya by apache.
the class MongoDeletePCJ method deletePCJ.
@Override
public void deletePCJ(final String ryaInstanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(pcjId);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
try (final MongoPcjStorage pcjStore = new MongoPcjStorage(mongoClient, ryaInstanceName)) {
pcjStore.dropPcj(pcjId);
} catch (final PCJStorageException e) {
throw new RyaClientException("Unable to drop PCJ : " + pcjId, e);
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class AccumuloLoadStatementsFile 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;
SailRepository sailRepo = null;
SailRepositoryConnection sailRepoConn = null;
try {
// Get a Sail object that is connected to the Rya instance.
final AccumuloRdfConfiguration ryaConf = getAccumuloConnectionDetails().buildAccumuloRdfConfiguration(ryaInstanceName);
// RYA-327 should address this hardcoded value.
ryaConf.setFlush(false);
sail = RyaSailFactory.getInstance(ryaConf);
// Load the file.
sailRepo = new SailRepository(sail);
sailRepoConn = sailRepo.getConnection();
sailRepoConn.add(statementsFile.toFile(), null, format);
} catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
log.warn("Exception while loading:", e);
throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the load to fail.", e);
} catch (final RepositoryException | RDFParseException | UnsupportedRDFormatException | IOException e) {
log.warn("Exception while loading:", e);
throw new RyaClientException("A problem processing the RDF file has caused the load into Rya instance named " + ryaInstanceName + "to fail.", e);
} finally {
// Shut it all down.
if (sailRepoConn != null) {
try {
sailRepoConn.close();
} catch (final RepositoryException e) {
log.warn("Couldn't close the SailRepoConnection that is attached to the Rya instance.", e);
}
}
if (sailRepo != null) {
try {
sailRepo.shutDown();
} catch (final RepositoryException e) {
log.warn("Couldn't shut down the SailRepository that is attached to the Rya instance.", e);
}
}
if (sail != null) {
try {
sail.shutDown();
} catch (final SailException e) {
log.warn("Couldn't shut down the Sail that is attached to the Rya instance.", e);
}
}
}
}
Aggregations