Search in sources :

Example 1 with ActionRuntimeContext

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

the class SplitJoinTest method runSplitJoin.

protected void runSplitJoin(SplitAction splitAction, JoinAction joinAction, Map<String, Object> config) {
    SplitActionRuntime splitActionRuntime = new SplitActionRuntime(splitAction);
    splitActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, splitAction));
    splitActionRuntime.initialize(config);
    StreamlineEvent event = createRootEvent();
    final List<Result> results = splitActionRuntime.execute(event);
    JoinActionRuntime joinActionRuntime = new JoinActionRuntime(joinAction);
    joinActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, joinAction));
    joinActionRuntime.initialize(config);
    List<Result> effectiveResult = null;
    for (Result result : results) {
        for (StreamlineEvent e : result.events) {
            List<Result> processedResult = joinActionRuntime.execute(e);
            if (processedResult != null) {
                effectiveResult = processedResult;
            }
        }
    }
    Assert.assertNotNull(effectiveResult);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) Result(com.hortonworks.streamline.streams.Result)

Example 2 with ActionRuntimeContext

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

the class SplitJoinTest method testStageProcessor.

@Test
public void testStageProcessor() {
    final String enrichFieldName = "foo";
    final String enrichedValue = "foo-enriched-value";
    Map<Object, Object> data = new HashMap<Object, Object>() {

        {
            put("foo-value", enrichedValue);
        }
    };
    InmemoryTransformDataProvider transformDataProvider = new InmemoryTransformDataProvider(data);
    EnrichmentTransform enrichmentTransform = new EnrichmentTransform("enricher", Collections.singletonList(enrichFieldName), transformDataProvider);
    StageAction stageAction = new StageAction(Collections.<Transform>singletonList(enrichmentTransform));
    stageAction.setOutputStreams(Collections.singleton("output-stream"));
    StageActionRuntime stageActionRuntime = new StageActionRuntime(stageAction);
    stageActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, stageAction));
    stageActionRuntime.initialize(Collections.<String, Object>emptyMap());
    final List<Result> results = stageActionRuntime.execute(createRootEvent());
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            final Map enrichments = (Map) event.getAuxiliaryFieldsAndValues().get(EnrichmentTransform.ENRICHMENTS_FIELD_NAME);
            Assert.assertEquals(enrichments.get(enrichFieldName), enrichedValue);
        }
    }
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) InmemoryTransformDataProvider(com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider) EnrichmentTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform) Result(com.hortonworks.streamline.streams.Result) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with ActionRuntimeContext

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

the class SplitJoinTest method testStageProcessorWithRules.

@Test
public void testStageProcessorWithRules() {
    final String enrichFieldName = "foo";
    final String enrichedValue = "foo-enriched-value";
    Map<Object, Object> data = new HashMap<Object, Object>() {

        {
            put("foo-value", enrichedValue);
        }
    };
    InmemoryTransformDataProvider transformDataProvider = new InmemoryTransformDataProvider(data);
    EnrichmentTransform enrichmentTransform = new EnrichmentTransform("enricher", Collections.singletonList(enrichFieldName), transformDataProvider);
    StageAction stageAction = new StageAction(Collections.<Transform>singletonList(enrichmentTransform));
    SplitJoinRule stageRule = new SplitJoinRule("stage-1", stageAction, Collections.singleton("output-stream"));
    StageActionRuntime stageActionRuntime = new StageActionRuntime(stageAction);
    stageActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(stageRule, stageAction));
    stageActionRuntime.initialize(Collections.<String, Object>emptyMap());
    final List<Result> results = stageActionRuntime.execute(createRootEvent());
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            final Map enrichments = (Map) event.getAuxiliaryFieldsAndValues().get(EnrichmentTransform.ENRICHMENTS_FIELD_NAME);
            Assert.assertEquals(enrichments.get(enrichFieldName), enrichedValue);
        }
    }
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) InmemoryTransformDataProvider(com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider) EnrichmentTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform) Result(com.hortonworks.streamline.streams.Result) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ActionRuntimeContext

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

the class SplitJoinTest method runSplitJoin.

private void runSplitJoin(SplitJoinRule splitRule, SplitJoinRule joinRule, Map<String, Object> config) {
    final SplitAction splitAction = (SplitAction) splitRule.getAction();
    SplitActionRuntime splitActionRuntime = new SplitActionRuntime(splitAction);
    splitActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(splitRule, splitAction));
    splitActionRuntime.initialize(config);
    StreamlineEvent streamlineEvent = createRootEvent();
    final List<Result> results = splitActionRuntime.execute(streamlineEvent);
    JoinAction joinAction = (JoinAction) joinRule.getAction();
    JoinActionRuntime joinActionRuntime = new JoinActionRuntime(joinAction);
    joinActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(joinRule, joinAction));
    joinActionRuntime.initialize(config);
    List<Result> effectiveResult = null;
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            List<Result> processedResult = joinActionRuntime.execute(event);
            if (processedResult != null) {
                effectiveResult = processedResult;
            }
        }
    }
    Assert.assertNotNull(effectiveResult);
}
Also used : JoinAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) SplitAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) Result(com.hortonworks.streamline.streams.Result)

Example 5 with ActionRuntimeContext

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

ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)5 Result (com.hortonworks.streamline.streams.Result)4 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)4 StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)2 EnrichmentTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform)2 InmemoryTransformDataProvider (com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 JoinAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction)1 SplitAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction)1 Action (com.hortonworks.streamline.streams.layout.component.rule.action.Action)1 ActionRuntime (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)1 ArrayList (java.util.ArrayList)1