Search in sources :

Example 1 with LocalQueryExecutor

use of org.apache.rya.streams.querymanager.kafka.LocalQueryExecutor in project incubator-rya by apache.

the class QueryManagerDaemon method init.

@Override
public void init(final DaemonContext context) throws DaemonInitException, Exception {
    requireNonNull(context);
    // Parse the command line arguments for the configuration file to use.
    final String[] args = context.getArguments();
    final DaemonParameters params = new DaemonParameters();
    try {
        new JCommander(params).parse(args);
    } catch (final ParameterException e) {
        throw new DaemonInitException("Unable to parse the command line arguments.", e);
    }
    final Path configFile = params.config != null ? Paths.get(params.config) : DEFAULT_CONFIGURATION_PATH;
    log.info("Loading the following configuration file: " + configFile);
    // Unmarshall the configuration file into an object.
    final QueryManagerConfig config;
    try (final InputStream stream = Files.newInputStream(configFile)) {
        config = QueryManagerConfigUnmarshaller.unmarshall(stream);
    } catch (final JAXBException | SAXException e) {
        throw new DaemonInitException("Unable to marshall the configuration XML file: " + configFile, e);
    }
    // Read the source polling period from the configuration.
    final QueryChanngeLogDiscoveryPeriod periodConfig = config.getPerformanceTunning().getQueryChanngeLogDiscoveryPeriod();
    final long period = periodConfig.getValue().longValue();
    final TimeUnit units = TimeUnit.valueOf(periodConfig.getUnits().toString());
    log.info("Query Change Log Polling Period: " + period + " " + units);
    final Scheduler scheduler = Scheduler.newFixedRateSchedule(0, period, units);
    // Initialize a QueryChangeLogSource.
    final Kafka kafka = config.getQueryChangeLogSource().getKafka();
    log.info("Kafka Source: " + kafka.getHostname() + ":" + kafka.getPort());
    final QueryChangeLogSource source = new KafkaQueryChangeLogSource(kafka.getHostname(), kafka.getPort(), scheduler);
    // Initialize a QueryExecutor.
    final String zookeeperServers = config.getQueryExecutor().getLocalKafkaStreams().getZookeepers();
    final KafkaStreamsFactory streamsFactory = new SingleThreadKafkaStreamsFactory(kafka.getHostname() + ":" + kafka.getPort());
    final QueryExecutor queryExecutor = new LocalQueryExecutor(new CreateKafkaTopic(zookeeperServers), streamsFactory);
    // Initialize the QueryManager using the configured resources.
    manager = new QueryManager(queryExecutor, source, period, units);
}
Also used : Scheduler(com.google.common.util.concurrent.AbstractScheduledService.Scheduler) Kafka(org.apache.rya.streams.querymanager.xml.Kafka) SAXException(org.xml.sax.SAXException) LocalQueryExecutor(org.apache.rya.streams.querymanager.kafka.LocalQueryExecutor) JCommander(com.beust.jcommander.JCommander) LocalQueryExecutor(org.apache.rya.streams.querymanager.kafka.LocalQueryExecutor) TimeUnit(java.util.concurrent.TimeUnit) ParameterException(com.beust.jcommander.ParameterException) Path(java.nio.file.Path) QueryChanngeLogDiscoveryPeriod(org.apache.rya.streams.querymanager.xml.QueryManagerConfig.PerformanceTunning.QueryChanngeLogDiscoveryPeriod) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) InputStream(java.io.InputStream) KafkaQueryChangeLogSource(org.apache.rya.streams.querymanager.kafka.KafkaQueryChangeLogSource) JAXBException(javax.xml.bind.JAXBException) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) SingleThreadKafkaStreamsFactory(org.apache.rya.streams.kafka.SingleThreadKafkaStreamsFactory) SingleThreadKafkaStreamsFactory(org.apache.rya.streams.kafka.SingleThreadKafkaStreamsFactory) KafkaQueryChangeLogSource(org.apache.rya.streams.querymanager.kafka.KafkaQueryChangeLogSource) DaemonInitException(org.apache.commons.daemon.DaemonInitException) QueryManagerConfig(org.apache.rya.streams.querymanager.xml.QueryManagerConfig)

Aggregations

JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 TimeUnit (java.util.concurrent.TimeUnit)1 JAXBException (javax.xml.bind.JAXBException)1 DaemonInitException (org.apache.commons.daemon.DaemonInitException)1 KafkaStreamsFactory (org.apache.rya.streams.kafka.KafkaStreamsFactory)1 SingleThreadKafkaStreamsFactory (org.apache.rya.streams.kafka.SingleThreadKafkaStreamsFactory)1 CreateKafkaTopic (org.apache.rya.streams.kafka.interactor.CreateKafkaTopic)1 KafkaQueryChangeLogSource (org.apache.rya.streams.querymanager.kafka.KafkaQueryChangeLogSource)1 LocalQueryExecutor (org.apache.rya.streams.querymanager.kafka.LocalQueryExecutor)1 Kafka (org.apache.rya.streams.querymanager.xml.Kafka)1 QueryManagerConfig (org.apache.rya.streams.querymanager.xml.QueryManagerConfig)1 QueryChanngeLogDiscoveryPeriod (org.apache.rya.streams.querymanager.xml.QueryManagerConfig.PerformanceTunning.QueryChanngeLogDiscoveryPeriod)1 SAXException (org.xml.sax.SAXException)1