use of org.apache.rya.streams.api.exception.RyaStreamsException in project incubator-rya by apache.
the class RyaStreamsCommands method stopQuery.
@CliCommand(value = STREAM_QUERIES_STOP_CMD, help = "Stop processing a SPARQL query using the Rya Streams subsystem.")
public String stopQuery(@CliOption(key = { "queryId" }, mandatory = true, help = "The ID of the query to stop processing.") final String queryId) {
final RyaStreamsClient streamsClient = state.getShellState().getRyaStreamsCommands().get();
try {
// Ensure the query exists.
final UUID id = UUID.fromString(queryId);
final java.util.Optional<StreamsQuery> streamsQuery = streamsClient.getGetQuery().getQuery(id);
if (!streamsQuery.isPresent()) {
throw new RuntimeException("No Rya Streams query exists for ID " + queryId);
}
// Ensure it isn't already stopped.
if (!streamsQuery.get().isActive()) {
return "That query is already stopped.";
}
// Stop it.
streamsClient.getStopQuery().stop(id);
return "The query will no longer be processed by the Rya Streams subsystem.";
} catch (final RyaStreamsException e) {
throw new RuntimeException("Unable to start the Query.", e);
}
}
use of org.apache.rya.streams.api.exception.RyaStreamsException in project incubator-rya by apache.
the class RyaStreamsCommands method printQueryDetails.
@CliCommand(value = STREAM_QUERIES_DETAILS_CMD, help = "Print detailed information about a specific query managed by the Rya Streams subsystem.")
public String printQueryDetails(@CliOption(key = { "queryId" }, mandatory = true, help = "The ID of the query whose details will be printed.") final String queryId) {
final RyaStreamsClient streamsClient = state.getShellState().getRyaStreamsCommands().get();
final UUID id = UUID.fromString(queryId);
try {
final java.util.Optional<StreamsQuery> query = streamsClient.getGetQuery().getQuery(id);
if (!query.isPresent()) {
return "There is no query with the specified ID.";
}
return StreamsQueryFormatter.format(query.get());
} catch (final RyaStreamsException e) {
throw new RuntimeException("Unable to fetch the query from the Rya Streams subsystem.", e);
} catch (final Exception e) {
throw new RuntimeException("Unable to print the query to the console.", e);
}
}
use of org.apache.rya.streams.api.exception.RyaStreamsException in project incubator-rya by apache.
the class RyaStreamsCommands method startQuery.
@CliCommand(value = STREAM_QUERIES_START_CMD, help = "Start processing a SPARQL query using the Rya Streams subsystem.")
public String startQuery(@CliOption(key = { "queryId" }, mandatory = true, help = "The ID of the query to start processing.") final String queryId) {
final RyaStreamsClient streamsClient = state.getShellState().getRyaStreamsCommands().get();
try {
// Ensure the query exists.
final UUID id = UUID.fromString(queryId);
final java.util.Optional<StreamsQuery> streamsQuery = streamsClient.getGetQuery().getQuery(id);
if (!streamsQuery.isPresent()) {
throw new RuntimeException("No Rya Streams query exists for ID " + queryId);
}
// Ensure it isn't already started.
if (streamsQuery.get().isActive()) {
return "That query is already running.";
}
// Start it.
streamsClient.getStartQuery().start(id);
return "The query will be processed by the Rya Streams subsystem.";
} catch (final RyaStreamsException e) {
throw new RuntimeException("Unable to start the Query.", e);
}
}
use of org.apache.rya.streams.api.exception.RyaStreamsException in project incubator-rya by apache.
the class RyaStreamsCommands method addQuery.
@CliCommand(value = STREAM_QUERIES_ADD_CMD, help = "Add a SPARQL query to the Rya Streams subsystem.")
public String addQuery(@CliOption(key = { "inactive" }, mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Setting this flag will add the query, but not run it. (default: false)") final boolean inactive, @CliOption(key = { "insert" }, mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Setting this flag will insert the query's results back into Rya. (default: false)") final boolean isInsert) {
final RyaStreamsClient streamsClient = state.getShellState().getRyaStreamsCommands().get();
// Prompt the user for the SPARQL that defines the query.
try {
final Optional<String> sparql = sparqlPrompt.getSparql();
// If the user aborted the prompt, return.
if (!sparql.isPresent()) {
return "";
}
final boolean isConstructQuery = QueryInvestigator.isConstruct(sparql.get());
final boolean isInsertQuery = QueryInvestigator.isInsertWhere(sparql.get());
// If the user wants to insert a CONSTRUCT into Rya, print a warning.
if (isInsert && isConstructQuery) {
consolePrinter.println("WARNING: CONSTRUCT is part of the SPARQL Query API, so they do not normally");
consolePrinter.println("get written back to the triple store. Consider using an INSERT, which is");
consolePrinter.println("part of the SPARQL Update API, in the future.");
}
// If the user wants to use an INSERT query, but not insert it back into Rya, suggest using a construct.
if (!isInsert && isInsertQuery) {
consolePrinter.println("WARNING: INSERT is part of the SPARQL Update API, so they normally get written");
consolePrinter.println("back to the triple store. Consider using a CONSTRUCT, which is part of the");
consolePrinter.println("SPARQL Query API, in the future.");
}
// If the user wants to insert the query back into Rya, make sure it is a legal query to do that.
if (isInsert && !(isConstructQuery || isInsertQuery)) {
throw new RuntimeException("Only CONSTRUCT queries and INSERT updates may be inserted back to the triple store.");
}
final StreamsQuery streamsQuery = streamsClient.getAddQuery().addQuery(sparql.get(), !inactive, isInsert);
return "The added query's ID is " + streamsQuery.getQueryId();
} catch (final MalformedQueryException | IOException | RyaStreamsException e) {
throw new RuntimeException("Unable to add the SPARQL query to the Rya Streams subsystem.", e);
}
}
use of org.apache.rya.streams.api.exception.RyaStreamsException in project incubator-rya by apache.
the class RyaStreamsCommands method deleteQuery.
@CliCommand(value = STREAM_QUERIES_DELETE_CMD, help = "Delete a SPARQL query from the Rya Streams subsystem.")
public String deleteQuery(@CliOption(key = { "queryId" }, mandatory = true, help = "The ID of the query to remove.") final String queryId) {
final RyaStreamsClient streamsClient = state.getShellState().getRyaStreamsCommands().get();
final UUID id = UUID.fromString(queryId);
try {
streamsClient.getDeleteQuery().delete(id);
} catch (final RyaStreamsException e) {
throw new RuntimeException("Could not delete the query from the Rya Streams subsystem.", e);
}
return "The query has been deleted.";
}
Aggregations