Search in sources :

Example 1 with StageAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction 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 2 with StageAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction 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 3 with StageAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction in project streamline by hortonworks.

the class TopologyComponentFactory method stageProcessorProvider.

private Map.Entry<String, Provider<StreamlineProcessor>> stageProcessorProvider() {
    Provider<StreamlineProcessor> provider = new Provider<StreamlineProcessor>() {

        @Override
        public StreamlineProcessor create(TopologyComponent component) {
            Object stageConfig = component.getConfig().getAny(StageProcessor.CONFIG_KEY_STAGE);
            ObjectMapper objectMapper = new ObjectMapper();
            StageAction stageAction = objectMapper.convertValue(stageConfig, StageAction.class);
            StageProcessor stageProcessor = new StageProcessor();
            stageProcessor.setStageAction(stageAction);
            return stageProcessor;
        }
    };
    return new SimpleImmutableEntry<>(STAGE, provider);
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StageProcessor(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageProcessor) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)3 Result (com.hortonworks.streamline.streams.Result)2 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)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 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TopologyComponent (com.hortonworks.streamline.streams.catalog.TopologyComponent)1 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)1 StageProcessor (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageProcessor)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1