use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class RulesBoltConditionTest method testSimpleRuleStringLiteral.
@Test
public void testSimpleRuleStringLiteral() throws Exception {
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(ImmutableMap.<String, Object>of("foo", "Normal", "bar", "abc", "baz", 200)).dataSourceId("dsrcid").build();
Tuple tuple = new TupleImpl(mockContext, new Values(event), 1, "inputstream");
doTest(readFile("/simple-rule-string-literal.json"), tuple);
new Verifications() {
{
String streamId;
Tuple anchor;
List<List<Object>> tuples = new ArrayList<>();
mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
times = 0;
}
};
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class StormEventCorrelationInjectorTest method tupleArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent.
@Test
public void tupleArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent() throws Exception {
int parent1TaskId = 1;
String parent1ComponentName = "1-parentComponent";
int parent2TaskId = 2;
String parent2ComponentName = "2-parentComponent2";
new Expectations() {
{
mockedTopologyContext.getComponentId(parent1TaskId);
result = parent1ComponentName;
mockedTopologyContext.getComponentId(parent2TaskId);
result = parent2ComponentName;
mockedTopologyContext.getComponentOutputFields(parent1ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
mockedTopologyContext.getComponentOutputFields(parent2ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
}
};
StreamlineEvent parentEvent1 = copyEventWithNewID();
parentEvent1 = eventCorrelationInjector.injectCorrelationInformation(parentEvent1, Collections.emptyList(), TEST_COMPONENT_NAME);
Tuple parentTuple1 = new TupleImpl(mockedTopologyContext, new Values(parentEvent1), parent1TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
StreamlineEvent parentOfParentEvent2 = copyEventWithNewID();
parentOfParentEvent2 = eventCorrelationInjector.injectCorrelationInformation(parentOfParentEvent2, Collections.emptyList(), TEST_COMPONENT_NAME);
StreamlineEvent parentEvent2 = copyEventWithNewID();
parentEvent2 = eventCorrelationInjector.injectCorrelationInformation(parentEvent2, Collections.singletonList(parentOfParentEvent2), TEST_COMPONENT_NAME);
Tuple parentTuple2 = new TupleImpl(mockedTopologyContext, new Values(parentEvent2), parent2TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Lists.newArrayList(parentTuple1, parentTuple2), TEST_COMPONENT_NAME);
StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
// added headers
assertEquals(Sets.newHashSet(parentEvent1.getId(), parentOfParentEvent2.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class StormEventCorrelationInjectorTest method tupleArgsTestNoParent.
@Test
public void tupleArgsTestNoParent() throws Exception {
StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Collections.emptyList(), TEST_COMPONENT_NAME);
StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
// added headers
assertEquals(Collections.emptySet(), EventCorrelationInjector.getRootIds(injectedEvent));
assertEquals(Collections.emptySet(), EventCorrelationInjector.getParentIds(injectedEvent));
assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class HdfsTextOutputFormat method format.
@Override
public byte[] format(Tuple tuple) {
if (fields == null || fields.size() == 0) {
throw new IllegalArgumentException("Output field names not specified. Set them using withFields().");
}
StreamlineEvent event = ((StreamlineEvent) tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fields.size(); i++) {
Object value = event.get(fields.get(i));
if (value != null) {
sb.append(value);
}
if (i != fields.size() - 1) {
sb.append(this.fieldDelimiter);
}
}
sb.append(this.recordDelimiter);
return sb.toString().getBytes();
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class OutputCollectorStreamlineEventLogger method logEvent.
private void logEvent(String streamId, List<Integer> taskIds, List<Object> tuple) {
long now = System.currentTimeMillis();
StreamlineEvent streamlineEvent = (StreamlineEvent) tuple.get(0);
// will be more efficient if we split this to two streams, but it shouldn't be a big deal anyway
Set<String> targetComponentIds = taskIds.stream().map(topologyContext::getComponentId).map(StormTopologyUtil::extractStreamlineComponentName).collect(Collectors.toSet());
eventLogger.writeEvent(now, componentName, streamId, targetComponentIds, streamlineEvent);
}
Aggregations