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;
}
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);
}
}
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());
}
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));
}
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));
}
Aggregations