use of com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction in project streamline by hortonworks.
the class TransformRuntimePipelineActionTest method testMergeSubstituteProject.
@Test
public void testMergeSubstituteProject() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "${1} plus ${1}");
Map<String, Object> defaults = new HashMap<>();
defaults.put("2", "TWO");
defaults.put("3", "THREE");
defaults.put("4", "${2} plus ${2}");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
MergeTransform merge = new MergeTransform(defaults);
SubstituteTransform substitute = new SubstituteTransform();
ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
TransformAction transformAction = new TransformAction(ImmutableList.of(merge, substitute, projection));
transformAction.setOutputStreams(ImmutableSet.of("streamid"));
ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
List<StreamlineEvent> resultEvents = new ArrayList<>();
for (Result result : actionRuntime.execute(event)) {
resultEvents.addAll(result.events);
}
assertEquals(1, resultEvents.size());
assertEquals(3, resultEvents.get(0).size());
assertEquals("THREE", resultEvents.get(0).get("3"));
assertEquals("one plus one", resultEvents.get(0).get("2"));
assertEquals("one plus one plus one plus one", resultEvents.get(0).get("4"));
}
use of com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction in project streamline by hortonworks.
the class TransformRuntimePipelineActionTest method testMergeProject.
@Test
public void testMergeProject() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "two");
Map<String, String> defaults = new HashMap<>();
defaults.put("2", "TWO");
defaults.put("3", "THREE");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
MergeTransform merge = new MergeTransform(defaults);
ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
TransformAction transformAction = new TransformAction(ImmutableList.of(merge, projection));
transformAction.setOutputStreams(ImmutableSet.of("streamid"));
ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
List<StreamlineEvent> resultEvents = new ArrayList<>();
for (Result result : actionRuntime.execute(event)) {
resultEvents.addAll(result.events);
}
assertEquals(1, resultEvents.size());
assertEquals(2, resultEvents.get(0).size());
assertEquals("THREE", resultEvents.get(0).get("3"));
assertEquals("two", resultEvents.get(0).get("2"));
}
use of com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction in project streamline by hortonworks.
the class NotifierActionRuntime method setActionRuntimeContext.
@Override
public void setActionRuntimeContext(ActionRuntimeContext actionRuntimeContext) {
outputStream = notifierAction.getOutputStreams().iterator().next();
LOG.debug("Notifier action {}, outputStream set to {}", notifierAction, outputStream);
transformActionRuntime = new TransformActionRuntime(new TransformAction(getNotificationTransforms(notifierAction, actionRuntimeContext.getRule().getId()), Collections.singleton(outputStream)));
}
use of com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction in project streamline by hortonworks.
the class RulesProcessorMock method getRule.
private Rule getRule(long ruleId, Condition condition, TransformAction action) {
Rule rule = new Rule();
rule.setId(ruleId);
rule.setName(RULE + "_" + ruleId);
rule.setDescription(RULE + "_" + ruleId + "_desc");
rule.setRuleProcessorName(RULE_PROCESSOR + "_" + ruleProcessorId);
rule.setCondition(condition);
if (ruleId % 2 == 0) {
Projection projection = new Projection();
Expression humidity = new FieldExpression(Field.of("humidity", Schema.Type.INTEGER));
Expression deviceName = new FieldExpression(Field.of("devicename", Schema.Type.STRING));
Expression incr = new FunctionExpression("INCR", "com.hortonworks.streamline.streams.runtime.storm.layout.runtime.rule.topology.RulesProcessorMock$Incr", ImmutableList.<Expression>of(humidity, new Literal("10")));
Expression upper = new FunctionExpression("UPPER", ImmutableList.<Expression>of(deviceName));
projection.setExpressions(ImmutableList.<Expression>of(humidity, incr, upper));
rule.setProjection(projection);
}
rule.setActions(Collections.singletonList((Action) action));
return rule;
}
use of com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction in project streamline by hortonworks.
the class StageActionRuntime method buildTransformActionRuntime.
protected void buildTransformActionRuntime() {
final List<Transform> transforms = stageAction.getTransforms();
if (stageAction.getOutputStreams().size() != 1) {
throw new RuntimeException("Stage can only have one output stream.");
}
transformActionRuntime = new TransformActionRuntime(new TransformAction(transforms, stageAction.getOutputStreams()));
}
Aggregations