Search in sources :

Example 1 with ActionRuntime

use of com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime 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 ActionRuntime

use of com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime 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 ActionRuntime

use of com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime in project streamline by hortonworks.

the class RuleRuntime method process.

/**
 * Executes a {@link Rule}'s Action
 *
 * @param event runtime input to this rule
 */
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
    LOG.debug("process invoked with StreamlineEvent {}", event);
    List<Result> allResults = new ArrayList<>();
    try {
        for (ActionRuntime action : actions) {
            List<Result> actionResults = action.execute(event);
            LOG.debug("Applied action {}, Result {}", action, actionResults);
            if (actionResults != null) {
                allResults.addAll(actionResults);
            }
        }
    } catch (Exception e) {
        String message = "Error evaluating rule with id:" + rule.getId();
        LOG.error(message);
        throw new ProcessingException(message, e);
    }
    LOG.debug("Returning allResults {}", allResults);
    return allResults;
}
Also used : ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException) ConditionEvaluationException(com.hortonworks.streamline.streams.layout.component.rule.exception.ConditionEvaluationException) ScriptException(javax.script.ScriptException) Result(com.hortonworks.streamline.streams.Result) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Example 4 with ActionRuntime

use of com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime in project streamline by hortonworks.

the class RuleProcessorRuntime method createActionRuntimes.

private List<ActionRuntime> createActionRuntimes(Rule rule) {
    List<ActionRuntime> runtimeActions = new ArrayList<>();
    for (Action action : rule.getActions()) {
        final ActionRuntime actionRuntime = ActionRuntimeService.get().get(action);
        actionRuntime.setActionRuntimeContext(new ActionRuntimeContext(rule, action));
        runtimeActions.add(actionRuntime);
    }
    return runtimeActions;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) ArrayList(java.util.ArrayList) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)

Aggregations

ActionRuntime (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)4 ArrayList (java.util.ArrayList)4 Result (com.hortonworks.streamline.streams.Result)3 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)2 TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)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 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)1 Action (com.hortonworks.streamline.streams.layout.component.rule.action.Action)1 SubstituteTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform)1 ConditionEvaluationException (com.hortonworks.streamline.streams.layout.component.rule.exception.ConditionEvaluationException)1 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)1 ScriptException (javax.script.ScriptException)1