Search in sources :

Example 1 with DefaultListQueries

use of org.apache.rya.streams.api.interactor.defaults.DefaultListQueries in project incubator-rya by apache.

the class ListQueriesCommand method execute.

@Override
public void execute(final String[] args) throws ArgumentsException, ExecutionException {
    requireNonNull(args);
    // Parse the command line arguments.
    final KafkaParameters params = new KafkaParameters();
    try {
        new JCommander(params, args);
    } catch (final ParameterException e) {
        throw new ArgumentsException("Could not list the queries because of invalid command line parameters.", e);
    }
    // Create the Kafka backed QueryChangeLog.
    final String bootstrapServers = params.kafkaIP + ":" + params.kafkaPort;
    final String topic = KafkaTopics.queryChangeLogTopic(params.ryaInstance);
    final QueryChangeLog queryChangeLog = KafkaQueryChangeLogFactory.make(bootstrapServers, topic);
    // The ListQueries command doesn't use the scheduled service feature.
    final Scheduler scheduler = Scheduler.newFixedRateSchedule(0L, 5, TimeUnit.SECONDS);
    final QueryRepository queryRepo = new InMemoryQueryRepository(queryChangeLog, scheduler);
    // Execute the list queries command.
    try {
        final ListQueries listQueries = new DefaultListQueries(queryRepo);
        try {
            final Set<StreamsQuery> queries = listQueries.all();
            System.out.println(formatQueries(queries));
        } catch (final RyaStreamsException e) {
            System.err.println("Unable to retrieve the queries.");
            e.printStackTrace();
            System.exit(1);
        }
    } catch (final Exception e) {
        System.err.println("Problem encountered while closing the QueryRepository.");
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) Scheduler(com.google.common.util.concurrent.AbstractScheduledService.Scheduler) ListQueries(org.apache.rya.streams.api.interactor.ListQueries) DefaultListQueries(org.apache.rya.streams.api.interactor.defaults.DefaultListQueries) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) ParameterException(com.beust.jcommander.ParameterException) JCommander(com.beust.jcommander.JCommander) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) ParameterException(com.beust.jcommander.ParameterException) 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)

Example 2 with DefaultListQueries

use of org.apache.rya.streams.api.interactor.defaults.DefaultListQueries 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

DefaultListQueries (org.apache.rya.streams.api.interactor.defaults.DefaultListQueries)2 InMemoryQueryRepository (org.apache.rya.streams.api.queries.InMemoryQueryRepository)2 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)2 QueryRepository (org.apache.rya.streams.api.queries.QueryRepository)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)1 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)1 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)1 RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)1 ListQueries (org.apache.rya.streams.api.interactor.ListQueries)1 DefaultAddQuery (org.apache.rya.streams.api.interactor.defaults.DefaultAddQuery)1 DefaultDeleteQuery (org.apache.rya.streams.api.interactor.defaults.DefaultDeleteQuery)1 DefaultGetQuery (org.apache.rya.streams.api.interactor.defaults.DefaultGetQuery)1 DefaultStartQuery (org.apache.rya.streams.api.interactor.defaults.DefaultStartQuery)1 DefaultStopQuery (org.apache.rya.streams.api.interactor.defaults.DefaultStopQuery)1 QueryChange (org.apache.rya.streams.api.queries.QueryChange)1 KafkaQueryChangeLog (org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog)1 VisibilityBindingSetDeserializer (org.apache.rya.streams.kafka.serialization.VisibilityBindingSetDeserializer)1 VisibilityStatementDeserializer (org.apache.rya.streams.kafka.serialization.VisibilityStatementDeserializer)1