Search in sources :

Example 6 with RyaStreamsException

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);
    }
}
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 7 with RyaStreamsException

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);
    }
}
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 8 with RyaStreamsException

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);
    }
}
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 9 with RyaStreamsException

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);
    }
}
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) MalformedQueryException(org.openrdf.query.MalformedQueryException) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 10 with RyaStreamsException

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

Aggregations

RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)11 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)8 UUID (java.util.UUID)5 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)5 CliCommand (org.springframework.shell.core.annotation.CliCommand)5 InMemoryQueryRepository (org.apache.rya.streams.api.queries.InMemoryQueryRepository)4 QueryRepository (org.apache.rya.streams.api.queries.QueryRepository)4 JCommander (com.beust.jcommander.JCommander)3 ParameterException (com.beust.jcommander.ParameterException)3 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)3 IOException (java.io.IOException)3 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)3 MalformedQueryException (org.openrdf.query.MalformedQueryException)3 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1