Search in sources :

Example 11 with Result

use of com.hortonworks.streamline.streams.Result in project streamline by hortonworks.

the class DefaultSplitter method splitEvent.

@Override
public List<Result> splitEvent(StreamlineEvent inputEvent, Set<String> outputStreams) {
    List<Result> results = new ArrayList<>();
    String groupId = getGroupId(inputEvent);
    int curPartNo = 0;
    int totalParts = outputStreams.size();
    for (String stream : outputStreams) {
        StreamlineEvent partitionedEvent = createPartitionEvent(inputEvent, groupId, ++curPartNo, stream, totalParts);
        results.add(new Result(stream, Collections.singletonList(partitionedEvent)));
    }
    return results;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Result(com.hortonworks.streamline.streams.Result)

Example 12 with Result

use of com.hortonworks.streamline.streams.Result 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 13 with Result

use of com.hortonworks.streamline.streams.Result 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 14 with Result

use of com.hortonworks.streamline.streams.Result 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 15 with Result

use of com.hortonworks.streamline.streams.Result in project streamline by hortonworks.

the class MultiLangProcessorRuntime method processEvent.

private List<Result> processEvent(StreamlineEvent inputEvent) {
    List<Result> results = new LinkedList<>();
    try {
        markWaitingSubprocess();
        ProcessorMsg processorMsg = createProcessorMessage(inputEvent);
        shellProcess.writeProcessorMsg(processorMsg);
        ShellMsg errorMsg = null;
        Map<String, List<ShellMsg>> emitMsgMap = new HashMap<>();
        while (true) {
            ShellMsg shellMsg = shellProcess.readShellMsg();
            String command = shellMsg.getCommand();
            if (command == null) {
                throw new IllegalArgumentException("Command not found in shell message: " + shellMsg);
            }
            setHeartbeat();
            if (command.equals("sync")) {
                break;
            } else if (command.equals("error")) {
                errorMsg = shellMsg;
            } else if (command.equals("emit")) {
                String stream = shellMsg.getOutputStream();
                List<ShellMsg> eventList = emitMsgMap.get(stream);
                if (eventList == null) {
                    eventList = new LinkedList<>();
                    emitMsgMap.put(stream, eventList);
                }
                eventList.add(shellMsg);
            } else {
                throw new RuntimeException("Unknown command received: " + command);
            }
        }
        if (errorMsg != null) {
            LOG.error(errorMsg.getMsg());
            throw new ProcessingException(errorMsg.getMsg());
        }
        for (Map.Entry<String, List<ShellMsg>> entry : emitMsgMap.entrySet()) {
            results.add(convertShellMsg(entry.getKey(), entry.getValue(), inputEvent));
        }
    } catch (IOException | ProcessingException e) {
        String processInfo = shellProcess.getProcessInfoString() + shellProcess.getProcessTerminationInfoString();
        throw new RuntimeException(processInfo, e);
    } finally {
        completedWaitingSubprocess();
    }
    return results;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Result(com.hortonworks.streamline.streams.Result) ProcessorMsg(com.hortonworks.streamline.streams.common.utils.ProcessorMsg) ShellMsg(com.hortonworks.streamline.streams.common.utils.ShellMsg) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Aggregations

Result (com.hortonworks.streamline.streams.Result)15 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)13 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)5 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)4 Map (java.util.Map)4 Test (org.junit.Test)4 ActionRuntime (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)3 Values (org.apache.storm.tuple.Values)3 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)2 StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)2 TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)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 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)2 ProjectionTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform)2 List (java.util.List)2 ScriptException (javax.script.ScriptException)2 Utils (com.hortonworks.streamline.common.util.Utils)1