Search in sources :

Example 21 with RyaStreamsClient

use of org.apache.rya.streams.api.RyaStreamsClient 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)

Example 22 with RyaStreamsClient

use of org.apache.rya.streams.api.RyaStreamsClient in project incubator-rya by apache.

the class KafkaRyaStreamsClientFactory method make.

/**
 * Initialize a {@link RyaStreamsClient} that will interact with an instance of Rya Streams
 * that is backed by Kafka.
 *
 * @param ryaInstance - The name of the Rya Instance the client is connected to. (not null)
 * @param kafkaHostname - The hostname of the Kafka Broker.
 * @param kafkaPort - The port of the Kafka Broker.
 * @return The initialized commands.
 */
public static RyaStreamsClient make(final String ryaInstance, final String kafkaHostname, final int kafkaPort) {
    requireNonNull(ryaInstance);
    requireNonNull(kafkaHostname);
    // Setup Query Repository used by the Kafka Rya Streams subsystem.
    final Producer<?, QueryChange> queryProducer = makeProducer(kafkaHostname, kafkaPort, StringSerializer.class, QueryChangeSerializer.class);
    final Consumer<?, QueryChange> queryConsumer = fromStartConsumer(kafkaHostname, kafkaPort, StringDeserializer.class, QueryChangeDeserializer.class);
    final String changeLogTopic = KafkaTopics.queryChangeLogTopic(ryaInstance);
    final QueryChangeLog changeLog = new KafkaQueryChangeLog(queryProducer, queryConsumer, changeLogTopic);
    final QueryRepository queryRepo = new InMemoryQueryRepository(changeLog, SCHEDULER);
    // Create the Rya Streams client that is backed by a Kafka Query Change Log.
    return new RyaStreamsClient(new DefaultAddQuery(queryRepo), new DefaultGetQuery(queryRepo), new DefaultDeleteQuery(queryRepo), new KafkaGetQueryResultStream<>(kafkaHostname, "" + kafkaPort, VisibilityStatementDeserializer.class), new KafkaGetQueryResultStream<>(kafkaHostname, "" + kafkaPort, VisibilityBindingSetDeserializer.class), new DefaultListQueries(queryRepo), new DefaultStartQuery(queryRepo), new DefaultStopQuery(queryRepo)) {

        /**
         * Close the QueryRepository used by the returned client.
         */
        @Override
        public void close() {
            try {
                queryRepo.stopAndWait();
            } catch (final Exception e) {
                log.warn("Couldn't close a QueryRepository.", e);
            }
        }
    };
}
Also used : DefaultGetQuery(org.apache.rya.streams.api.interactor.defaults.DefaultGetQuery) VisibilityBindingSetDeserializer(org.apache.rya.streams.kafka.serialization.VisibilityBindingSetDeserializer) DefaultDeleteQuery(org.apache.rya.streams.api.interactor.defaults.DefaultDeleteQuery) VisibilityStatementDeserializer(org.apache.rya.streams.kafka.serialization.VisibilityStatementDeserializer) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) DefaultAddQuery(org.apache.rya.streams.api.interactor.defaults.DefaultAddQuery) DefaultStopQuery(org.apache.rya.streams.api.interactor.defaults.DefaultStopQuery) QueryChange(org.apache.rya.streams.api.queries.QueryChange) DefaultStartQuery(org.apache.rya.streams.api.interactor.defaults.DefaultStartQuery) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryRepository(org.apache.rya.streams.api.queries.QueryRepository) DefaultListQueries(org.apache.rya.streams.api.interactor.defaults.DefaultListQueries)

Aggregations

RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)22 RyaClient (org.apache.rya.api.client.RyaClient)15 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)14 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)13 Test (org.junit.Test)13 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)12 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)12 UUID (java.util.UUID)10 CliCommand (org.springframework.shell.core.annotation.CliCommand)8 RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)6 AddQuery (org.apache.rya.streams.api.interactor.AddQuery)5 GetQuery (org.apache.rya.streams.api.interactor.GetQuery)5 IOException (java.io.IOException)4 RyaClientException (org.apache.rya.api.client.RyaClientException)4 MalformedQueryException (org.openrdf.query.MalformedQueryException)3 RyaStreamsDetails (org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails)2 StartQuery (org.apache.rya.streams.api.interactor.StartQuery)2 StopQuery (org.apache.rya.streams.api.interactor.StopQuery)2 MongoClient (com.mongodb.MongoClient)1 MongoException (com.mongodb.MongoException)1