use of org.apache.rya.streams.api.entity.StreamsQuery in project incubator-rya by apache.
the class StreamsQueryFormatterTest method formatQueries.
@Test
public void formatQueries() throws Exception {
// Format the queries.
final Set<StreamsQuery> queries = Sets.newHashSet(new StreamsQuery(UUID.fromString("33333333-3333-3333-3333-333333333333"), "SELECT * WHERE { ?person <urn:worksAt> ?business . }", true, true), new StreamsQuery(UUID.fromString("11111111-1111-1111-1111-111111111111"), "SELECT * WHERE { ?a ?b ?c . }", true, false), new StreamsQuery(UUID.fromString("22222222-2222-2222-2222-222222222222"), "SELECT * WHERE { ?d ?e ?f . }", false, true));
final String formatted = StreamsQueryFormatter.format(queries);
// Ensure it has the expected format.
final String expected = "-----------------------------------------------\n" + " Query ID: 11111111-1111-1111-1111-111111111111\n" + "Is Active: true\n" + "Is Insert: false\n" + " SPARQL: select ?a ?b ?c\n" + " where {\n" + " ?a ?b ?c.\n" + " }\n" + "-----------------------------------------------\n" + " Query ID: 22222222-2222-2222-2222-222222222222\n" + "Is Active: false\n" + "Is Insert: true\n" + " SPARQL: select ?d ?e ?f\n" + " where {\n" + " ?d ?e ?f.\n" + " }\n" + "-----------------------------------------------\n" + " Query ID: 33333333-3333-3333-3333-333333333333\n" + "Is Active: true\n" + "Is Insert: true\n" + " SPARQL: select ?person ?business\n" + " where {\n" + " ?person <urn:worksAt> ?business.\n" + " }\n" + "-----------------------------------------------\n";
assertEquals(expected, formatted);
}
use of org.apache.rya.streams.api.entity.StreamsQuery in project incubator-rya by apache.
the class StreamsQueryFormatterTest method formatQuery.
@Test
public void formatQuery() throws Exception {
// Format the query.
final StreamsQuery query = new StreamsQuery(UUID.fromString("da55cea5-c21c-46a5-ab79-5433eef4efaa"), "SELECT * WHERE { ?a ?b ?c . }", true, false);
final String formatted = StreamsQueryFormatter.format(query);
// Ensure it has the expected format.
final String expected = " Query ID: da55cea5-c21c-46a5-ab79-5433eef4efaa\n" + "Is Active: true\n" + "Is Insert: false\n" + " SPARQL: select ?a ?b ?c\n" + " where {\n" + " ?a ?b ?c.\n" + " }\n";
assertEquals(expected, formatted);
}
use of org.apache.rya.streams.api.entity.StreamsQuery 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.entity.StreamsQuery 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.entity.StreamsQuery 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);
}
}
Aggregations