Search in sources :

Example 6 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class Tools method runProcessing.

public static void runProcessing(Event sent, Pipeline pipe, Properties props) throws ProcessorException {
    EventsProcessor ep = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
    sent.inject(pipe, props.mainQueue);
    Processor processor;
    while ((processor = sent.next()) != null) {
        ep.process(sent, processor);
    }
}
Also used : EventsProcessor(loghub.EventsProcessor) EventsProcessor(loghub.EventsProcessor)

Example 7 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class TestConfigurations method testTwoPipe.

@Test
public void testTwoPipe() throws InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("twopipe.conf");
    Thread t = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    t.setDaemon(true);
    t.start();
    Event sent = Tools.getEvent();
    sent.put("message", "1");
    sent.inject(conf.namedPipeLine.get("pipeone"), conf.mainQueue);
    try {
        Event re = conf.outputQueues.get("main").poll(1, TimeUnit.SECONDS);
        Assert.assertEquals("wrong event received", "1", re.get("message"));
    } finally {
        logger.debug("{} is at main pipeline {}", sent, sent.getCurrentPipeline());
        t.interrupt();
    }
}
Also used : Event(loghub.Event) EventsProcessor(loghub.EventsProcessor) Test(org.junit.Test)

Example 8 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class TestEventProcessing method check.

public static void check(String pipeLineTest, String configFile) {
    try {
        Properties props = Configuration.parse(configFile);
        TestEventProcessing.setAppender();
        props.pipelines.stream().forEach(i -> i.configure(props));
        Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
        t.setName("ProcessingThread");
        t.setDaemon(true);
        t.start();
        ObjectMapper mapper = new ObjectMapper(factory);
        ObjectReader reader = mapper.reader().forType(Map.class);
        MappingIterator<Map<String, Object>> i = reader.readValues(new InputStreamReader(System.in, "UTF-8"));
        while (i.hasNext()) {
            Map<String, Object> eventMap = i.next();
            Date eventDate = null;
            if (eventMap.containsKey(Event.TIMESTAMPKEY) && eventMap.get(Event.TIMESTAMPKEY) instanceof String) {
                TemporalAccessor ta = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:m:ss.SSSxx").parse((CharSequence) eventMap.remove(Event.TIMESTAMPKEY));
                OffsetDateTime now;
                // Try to resolve the time zone first
                ZoneId zi = ta.query(TemporalQueries.zone());
                ZoneOffset zo = ta.query(TemporalQueries.offset());
                if (zo != null) {
                    now = OffsetDateTime.now(zo);
                } else if (zi != null) {
                    now = OffsetDateTime.now(zi);
                } else {
                    now = OffsetDateTime.now(ZoneId.systemDefault());
                }
                eventDate = Date.from(now.toInstant());
            }
            Event ev = Event.emptyTestEvent(ConnectionContext.EMPTY);
            ev.putAll(eventMap);
            if (eventDate != null) {
                ev.setTimestamp(eventDate);
            }
            ev.inject(props.namedPipeLine.get(pipeLineTest), props.mainQueue);
        }
        Thread.currentThread().join();
    // Thread.sleep(Long.MAX_VALUE);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ConfigException e) {
        System.out.format("Error in %s: %s\n", e.getLocation(), e.getMessage());
        System.exit(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) InputStreamReader(java.io.InputStreamReader) ZoneId(java.time.ZoneId) IOException(java.io.IOException) EventsProcessor(loghub.EventsProcessor) Date(java.util.Date) ZoneOffset(java.time.ZoneOffset) OffsetDateTime(java.time.OffsetDateTime) Event(loghub.Event) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EventsProcessor (loghub.EventsProcessor)8 Event (loghub.Event)6 Test (org.junit.Test)5 Properties (loghub.configuration.Properties)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pipeline (loghub.Pipeline)1