Search in sources :

Example 36 with StreamsQuery

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);
}
Also used : StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) Test(org.junit.Test)

Example 37 with StreamsQuery

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);
}
Also used : StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) Test(org.junit.Test)

Example 38 with StreamsQuery

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);
    }
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) UUID(java.util.UUID) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 39 with StreamsQuery

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);
    }
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) UUID(java.util.UUID) RyaClientException(org.apache.rya.api.client.RyaClientException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 40 with StreamsQuery

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);
    }
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) UUID(java.util.UUID) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Aggregations

StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)51 Test (org.junit.Test)40 UUID (java.util.UUID)24 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)14 CountDownLatch (java.util.concurrent.CountDownLatch)10 RyaClient (org.apache.rya.api.client.RyaClient)10 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)10 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)10 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)10 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)8 KafkaStreamsFactory (org.apache.rya.streams.kafka.KafkaStreamsFactory)8 CreateKafkaTopic (org.apache.rya.streams.kafka.interactor.CreateKafkaTopic)8 QueryExecutor (org.apache.rya.streams.querymanager.QueryExecutor)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)7 KafkaStreams (org.apache.kafka.streams.KafkaStreams)7 QueryEvent (org.apache.rya.streams.querymanager.QueryManager.QueryEvent)7 InMemoryQueryChangeLog (org.apache.rya.streams.api.queries.InMemoryQueryChangeLog)6 HashSet (java.util.HashSet)5