Search in sources :

Example 86 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class TransformActionRuntime method doTransform.

/*
     * applies the i th transform and recursively invokes the method to apply
     * the rest of the transformations in the chain.
     */
private List<StreamlineEvent> doTransform(StreamlineEvent inputEvent, int i) {
    if (i >= transformRuntimes.size()) {
        return Collections.singletonList(inputEvent);
    }
    List<StreamlineEvent> transformed = new ArrayList<>();
    final List<StreamlineEvent> events = transformRuntimes.get(i).execute(inputEvent);
    for (StreamlineEvent event : events) {
        transformed.addAll(doTransform(event, i + 1));
    }
    return transformed;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList)

Example 87 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class TestRunSinkBolt method execute.

@Override
public void execute(Tuple input) {
    Object value = input.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
    StreamlineEvent event = (StreamlineEvent) value;
    String outputFilePath = testRunSink.getOutputFilePath();
    try (FileWriter fw = new FileWriter(outputFilePath, true)) {
        LOG.debug("writing event to file " + outputFilePath);
        fw.write(objectMapper.writeValueAsString(event) + "\n");
        fw.flush();
        collector.ack(input);
    } catch (FileNotFoundException e) {
        LOG.error("Can't open file for write: " + outputFilePath);
        throw new RuntimeException(e);
    } catch (IOException e) {
        LOG.error("Fail to write event to output file " + outputFilePath + " : exception occurred.", e);
        throw new RuntimeException(e);
    }
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 88 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class EventInformationBuilderTest method testBuild.

@Test
public void testBuild() throws Exception {
    long timestamp = System.currentTimeMillis();
    EventCorrelationInjector injector = new EventCorrelationInjector();
    StreamlineEvent parentEvent = copyEventWithNewID();
    // use same component name for parent and ancestor for easy testing
    // this line is covered via `testNoParent()`
    parentEvent = injector.injectCorrelationInformation(parentEvent, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent injectedEvent = injector.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Collections.singletonList(parentEvent), TEST_COMPONENT_NAME);
    EventInformation information = sut.build(timestamp, TEST_COMPONENT_NAME, TEST_STREAM_ID, Sets.newHashSet(TEST_TARGET_COMPONENT_NAME, TEST_TARGET_COMPONENT_NAME_2), injectedEvent);
    assertEquals(timestamp, information.getTimestamp());
    assertEquals(injectedEvent.getId(), information.getEventId());
    assertEquals(EventCorrelationInjector.getRootIds(injectedEvent), information.getRootIds());
    assertEquals(EventCorrelationInjector.getParentIds(injectedEvent), information.getParentIds());
    assertEquals(EventCorrelationInjector.getSourceComponentName(injectedEvent), information.getComponentName());
    assertEquals(TEST_COMPONENT_NAME, information.getComponentName());
    assertEquals(TEST_STREAM_ID, information.getStreamId());
    assertEquals(Sets.newHashSet(TEST_TARGET_COMPONENT_NAME, TEST_TARGET_COMPONENT_NAME_2), information.getTargetComponents());
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) EventCorrelationInjector(com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector) Test(org.junit.Test)

Example 89 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class EventCorrelationInjectorTest method eventArgsTestWithAParentWhichIsRootEvent.

@Test
public void eventArgsTestWithAParentWhichIsRootEvent() throws Exception {
    StreamlineEvent parentEvent = copyEventWithNewID();
    // use same component name for parent and ancestor for easy testing
    // this line is covered via `testNoParent()`
    parentEvent = sut.injectCorrelationInformation(parentEvent, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Collections.singletonList(parentEvent), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Collections.singleton(parentEvent.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Collections.singleton(parentEvent.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(TEST_COMPONENT_NAME, EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Test(org.junit.Test)

Example 90 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class EventCorrelationInjectorTest method eventArgsTestWithTwoParentsWhichAreRootEvents.

@Test
public void eventArgsTestWithTwoParentsWhichAreRootEvents() throws Exception {
    StreamlineEvent parentEvent1 = copyEventWithNewID();
    // this line is covered via `testNoParent()`
    parentEvent1 = sut.injectCorrelationInformation(parentEvent1, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent parentEvent2 = copyEventWithNewID();
    // this line is covered via `testNoParent()`
    parentEvent2 = sut.injectCorrelationInformation(parentEvent2, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Lists.newArrayList(parentEvent1, parentEvent2), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(TEST_COMPONENT_NAME, EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3