Search in sources :

Example 6 with RulesProcessor

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

the class RulesTopologyTest method createTopology.

protected StormTopology createTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    RulesProcessor rulesProcessor = createRulesProcessor();
    builder.setSpout(RULES_TEST_SPOUT, new RulesTestSpout());
    builder.setBolt(RULES_BOLT, createRulesBolt(rulesProcessor, getScriptType())).shuffleGrouping(RULES_TEST_SPOUT);
    builder.setBolt(RULES_TEST_SINK_BOLT_1, new RulesTestSinkBolt()).shuffleGrouping(RULES_BOLT, rulesProcessor.getRules().get(0).getOutputStreamNameForAction(rulesProcessor.getRules().get(0).getActions().iterator().next()));
    builder.setBolt(RULES_TEST_SINK_BOLT_2, new RulesTestSinkBolt()).shuffleGrouping(RULES_BOLT, rulesProcessor.getRules().get(1).getOutputStreamNameForAction(rulesProcessor.getRules().get(1).getActions().iterator().next()));
    return builder.createTopology();
}
Also used : RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TopologyBuilder(org.apache.storm.topology.TopologyBuilder)

Example 7 with RulesProcessor

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

the class TestTopologyDagCreatingVisitorTest method visitRulesProcessor_connectedFromSource.

@Test
public void visitRulesProcessor_connectedFromSource() throws Exception {
    StreamlineSource originSource = TopologyTestHelper.createStreamlineSource("1");
    RulesProcessor rulesProcessor = TopologyTestHelper.createRulesProcessor("2");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originSource);
    originTopologyDag.add(rulesProcessor);
    originTopologyDag.addEdge(new Edge("e1", originSource, rulesProcessor, "default", Stream.Grouping.SHUFFLE));
    TestRunSource testSource = createTestRunSource(originSource);
    TestRunRulesProcessor testRulesProcessor = createTestRunRulesProcessor(rulesProcessor);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.singletonMap(originSource.getName(), testSource), Collections.emptyMap(), Collections.singletonMap(rulesProcessor.getName(), testRulesProcessor), Collections.emptyMap());
    visitor.visit(originSource);
    visitor.visit(rulesProcessor);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testRulesProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunRulesProcessor && o.getName().equals(rulesProcessor.getName()))).collect(toList());
    List<OutputComponent> testSources = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunSource && o.getName().equals(originSource.getName()))).collect(toList());
    TestRunRulesProcessor testRunRulesProcessor = (TestRunRulesProcessor) testRulesProcessors.get(0);
    TestRunSource testRunSource = (TestRunSource) testSources.get(0);
    assertEquals(1, testTopologyDag.getEdgesFrom(testRunSource).size());
    assertEquals(1, testTopologyDag.getEdgesTo(testRunRulesProcessor).size());
    assertTrue(testTopologyDag.getEdgesFrom(testRunSource).get(0) == testTopologyDag.getEdgesTo(testRunRulesProcessor).get(0));
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Example 8 with RulesProcessor

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

the class TestTopologyDagCreatingVisitorTest method visitRulesProcessor_connectedFromProcessor.

@Test
public void visitRulesProcessor_connectedFromProcessor() throws Exception {
    StreamlineProcessor originProcessor = TopologyTestHelper.createStreamlineProcessor("1");
    RulesProcessor rulesProcessor = TopologyTestHelper.createRulesProcessor("2");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originProcessor);
    originTopologyDag.add(rulesProcessor);
    originTopologyDag.addEdge(new Edge("e1", originProcessor, rulesProcessor, "default", Stream.Grouping.SHUFFLE));
    TestRunProcessor testProcessor = createTestRunProcessor(originProcessor);
    TestRunRulesProcessor testRulesProcessor = createTestRunRulesProcessor(rulesProcessor);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.emptyMap(), Collections.singletonMap(originProcessor.getName(), testProcessor), Collections.singletonMap(rulesProcessor.getName(), testRulesProcessor), Collections.emptyMap());
    visitor.visit(originProcessor);
    visitor.visit(rulesProcessor);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunProcessor)).collect(toList());
    List<OutputComponent> testRulesProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunRulesProcessor)).collect(toList());
    Optional<OutputComponent> testRunProcessorOptional = testProcessors.stream().filter(o -> o.getName().equals(originProcessor.getName())).findAny();
    Optional<OutputComponent> testRunRuleProcessorOptional = testRulesProcessors.stream().filter(o -> o.getName().equals(rulesProcessor.getName())).findAny();
    assertTrue(testRunProcessorOptional.isPresent());
    assertTrue(testRunRuleProcessorOptional.isPresent());
    TestRunProcessor testRunProcessor = (TestRunProcessor) testRunProcessorOptional.get();
    TestRunRulesProcessor testRunRuleProcessor = (TestRunRulesProcessor) testRunRuleProcessorOptional.get();
    assertEquals(1, testTopologyDag.getEdgesFrom(testRunProcessor).size());
    assertEquals(1, testTopologyDag.getEdgesTo(testRunRuleProcessor).size());
    assertTrue(testTopologyDag.getEdgesFrom(testRunProcessor).get(0) == testTopologyDag.getEdgesTo(testRunRuleProcessor).get(0));
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Example 9 with RulesProcessor

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

the class WindowRulesBoltTest method testCountBasedWindowWithGroupbyUnordered.

@Test
public void testCountBasedWindowWithGroupbyUnordered() throws Exception {
    String rulesJson = readFile("/window-rule-groupby-unordered.json");
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL);
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    wbe.prepare(conf, mockContext, mockCollector);
    wbe.execute(getNextTuple(10));
    wbe.execute(getNextTuple(15));
    wbe.execute(getNextTuple(11));
    wbe.execute(getNextTuple(16));
    new Verifications() {

        {
            String streamId;
            Collection<Tuple> anchors;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchors = withCapture(), withCapture(tuples));
            Assert.assertEquals(2, tuples.size());
            Map<String, Object> fieldsAndValues = ((StreamlineEvent) tuples.get(0).get(0));
            Assert.assertEquals(2, fieldsAndValues.get("deptid"));
            Assert.assertEquals(110, fieldsAndValues.get("salary_MAX"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(1).get(0));
            Assert.assertEquals(3, fieldsAndValues.get("deptid"));
            Assert.assertEquals(160, fieldsAndValues.get("salary_MAX"));
        }
    };
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Verifications(mockit.Verifications) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 10 with RulesProcessor

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

the class StormTopologyFluxGenerator method handleWindowedRules.

private void handleWindowedRules(RulesProcessor rulesProcessor, List<Rule> rulesWithWindow) {
    // assert that RulesProcessor only has a windowed rule, not multiple rules.
    if (rulesWithWindow.size() > 1) {
        throw new IllegalStateException("Windowed RulesProcessor should have only one rule.");
    }
    Rule rule = rulesWithWindow.get(0);
    Collection<Rule> rules = Collections.singletonList(rule);
    Window window = rulesWithWindow.get(0).getWindow();
    // create windowed bolt per unique window configuration
    RulesProcessor windowedRulesProcessor = copyRulesProcessor(rulesProcessor);
    windowedRulesProcessor.setRules(new ArrayList<>(rules));
    windowedRulesProcessor.setId(rulesProcessor.getId());
    windowedRulesProcessor.setName(rulesProcessor.getName());
    windowedRulesProcessor.getConfig().setAny(RulesProcessor.CONFIG_KEY_RULES, Collections2.transform(rules, new Function<Rule, Long>() {

        @Override
        public Long apply(Rule input) {
            return input.getId();
        }
    }));
    LOG.debug("Rules processor with window {}", windowedRulesProcessor);
    keysAndComponents.add(makeEntry(StormTopologyLayoutConstants.YAML_KEY_BOLTS, getYamlComponents(fluxComponentFactory.getFluxComponent(windowedRulesProcessor), windowedRulesProcessor)));
    List<Edge> originEdgesTo = topologyDag.getEdgesTo(rulesProcessor);
    List<Edge> originEdgesFrom = topologyDag.getEdgesFrom(rulesProcessor);
    // remove streams before wiring
    removeFluxStreamsTo(getFluxId(rulesProcessor));
    removeFluxStreamsFrom(getFluxId(rulesProcessor));
    // Wire the windowed bolt with the appropriate edges
    wireWindowedRulesProcessor(windowedRulesProcessor, originEdgesTo, originEdgesFrom);
    mayBeUpdateTopologyConfig(window);
    edgeAlreadyAddedComponents.add(getFluxId(rulesProcessor));
}
Also used : Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) Function(com.google.common.base.Function) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) Edge(com.hortonworks.streamline.streams.layout.component.Edge)

Aggregations

RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)11 List (java.util.List)6 Edge (com.hortonworks.streamline.streams.layout.component.Edge)4 Stream (com.hortonworks.streamline.streams.layout.component.Stream)4 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)4 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)4 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)4 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 InputComponent (com.hortonworks.streamline.streams.layout.component.InputComponent)3 OutputComponent (com.hortonworks.streamline.streams.layout.component.OutputComponent)3 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)3 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)3 TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)3 TestRunSink (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink)3 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)3 Collections (java.util.Collections)3 Map (java.util.Map)3 Optional (java.util.Optional)3