Search in sources :

Example 1 with TransformAction

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"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) SubstituteTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 2 with TransformAction

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"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 3 with TransformAction

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)));
}
Also used : TransformActionRuntime(com.hortonworks.streamline.streams.runtime.TransformActionRuntime) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)

Example 4 with TransformAction

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;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)

Example 5 with TransformAction

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()));
}
Also used : TransformActionRuntime(com.hortonworks.streamline.streams.runtime.TransformActionRuntime) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) Transform(com.hortonworks.streamline.streams.layout.Transform)

Aggregations

TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)5 Result (com.hortonworks.streamline.streams.Result)2 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)2 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)2 ProjectionTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform)2 TransformActionRuntime (com.hortonworks.streamline.streams.runtime.TransformActionRuntime)2 ActionRuntime (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Transform (com.hortonworks.streamline.streams.layout.Transform)1 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)1 Action (com.hortonworks.streamline.streams.layout.component.rule.action.Action)1 SubstituteTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform)1 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)1 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)1 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)1 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)1 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)1 Projection (com.hortonworks.streamline.streams.layout.component.rule.expression.Projection)1