Search in sources :

Example 1 with RulesProcessor

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

the class TopologyTestHelper method createRulesProcessor.

public static RulesProcessor createRulesProcessor(String id) {
    RulesProcessor processor = new RulesProcessor();
    processor.setId(id);
    processor.setName("testRuleProcessor_" + id);
    processor.setConfig(new Config());
    processor.setTransformationClass("dummyTransformation");
    processor.setProcessAll(true);
    processor.setRules(Collections.emptyList());
    return processor;
}
Also used : RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Config(com.hortonworks.streamline.common.Config)

Example 2 with RulesProcessor

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

the class TopologyComponentFactory method createRulesProcessorProvider.

private Provider<StreamlineProcessor> createRulesProcessorProvider(final RuleExtractor ruleExtractor) {
    return new Provider<StreamlineProcessor>() {

        @Override
        public StreamlineProcessor create(TopologyComponent component) {
            RulesProcessor processor = new RulesProcessor();
            ObjectMapper objectMapper = new ObjectMapper();
            if (component instanceof TopologyOutputComponent) {
                Set<Stream> outputStreams = createOutputStreams((TopologyOutputComponent) component);
                processor.addOutputStreams(outputStreams);
            } else {
                throw new IllegalArgumentException("Component " + component + " must be an instance of TopologyOutputComponent");
            }
            boolean processAll = component.getConfig().getBoolean(RulesProcessor.CONFIG_PROCESS_ALL, true);
            processor.setProcessAll(processAll);
            Object ruleList = component.getConfig().getAny(RulesProcessor.CONFIG_KEY_RULES);
            List<Long> ruleIds = objectMapper.convertValue(ruleList, new TypeReference<List<Long>>() {
            });
            try {
                List<Rule> rules = new ArrayList<>();
                for (Long ruleId : ruleIds) {
                    rules.add(ruleExtractor.getRule(component.getTopologyId(), ruleId, component.getVersionId()));
                }
                processor.setRules(rules);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
            return processor;
        }
    };
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) ArrayList(java.util.ArrayList) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TopologyOutputComponent(com.hortonworks.streamline.streams.catalog.TopologyOutputComponent) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) List(java.util.List) ArrayList(java.util.ArrayList) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with RulesProcessor

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

the class WindowRulesBoltTest method doTest.

private boolean doTest(String rulesJson, int expectedExecuteCount, Function<Integer, Tuple> tupleGen) throws Exception {
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    final CountDownLatch latch = new CountDownLatch(expectedExecuteCount);
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL) {

        @Override
        public void execute(TupleWindow inputWindow) {
            super.execute(inputWindow);
            latch.countDown();
        }
    };
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    conf.put("topology.message.timeout.secs", 30);
    wbe.prepare(conf, mockContext, mockCollector);
    Thread.sleep(100);
    for (int i = 1; i <= 20; i++) {
        wbe.execute(tupleGen.apply(i));
    }
    // wait for up to 5 secs for the bolt's execute to finish
    return latch.await(5, TimeUnit.SECONDS);
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TupleWindow(org.apache.storm.windowing.TupleWindow) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with RulesProcessor

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

the class RulesProcessorMock method get.

public RulesProcessor get() {
    RulesProcessor rulesProcessor = new RulesProcessor();
    rulesProcessor.setId(String.valueOf(ruleProcessorId));
    rulesProcessor.setName(RULE_PROCESSOR + "_" + ruleProcessorId);
    rulesProcessor.setRules(getRules());
    return rulesProcessor;
}
Also used : RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)

Example 5 with RulesProcessor

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

the class StormTopologyFluxGenerator method visit.

@Override
public void visit(final RulesProcessor rulesProcessor) {
    rulesProcessor.getConfig().setAny("outputStreams", rulesProcessor.getOutputStreams());
    List<Rule> rulesWithWindow = new ArrayList<>();
    List<Rule> rulesWithoutWindow = new ArrayList<>();
    Set<String> inStreams = topologyDag.getEdgesTo(rulesProcessor).stream().flatMap(e -> e.getStreamGroupings().stream().map(sg -> sg.getStream().getId())).collect(Collectors.toSet());
    for (Rule rule : rulesProcessor.getRules()) {
        if (!inStreams.containsAll(rule.getStreams())) {
            throw new IllegalStateException("Input streams of rules processor " + inStreams + " does not contain rule's input streams " + rule.getStreams() + ". Please delete and recreate the rule.");
        }
        if (rule.getWindow() != null) {
            rulesWithWindow.add(rule);
        } else {
            rulesWithoutWindow.add(rule);
        }
    }
    // assert that RulesProcessor doesn't have mixed kinds of rules.
    if (!rulesWithWindow.isEmpty() && !rulesWithoutWindow.isEmpty()) {
        throw new IllegalStateException("RulesProcessor should have either windowed or non-windowed rules, not both.");
    }
    // associating multiple bolts to a rules processor is not allowed for simplicity.
    if (!rulesWithWindow.isEmpty()) {
        handleWindowedRules(rulesProcessor, rulesWithWindow);
    } else {
        // !rulesWithoutWindow.isEmpty()
        handleNonWindowedRules(rulesProcessor, rulesWithoutWindow);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) StormTopologyUtil(com.hortonworks.streamline.streams.storm.common.StormTopologyUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Collections2(com.google.common.collect.Collections2) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) Multimap(com.google.common.collect.Multimap) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) YAML_KEY_ID(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants.YAML_KEY_ID) TopologyDagVisitor(com.hortonworks.streamline.streams.layout.component.TopologyDagVisitor) Map(java.util.Map) YAML_KEY_STREAMS(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants.YAML_KEY_STREAMS) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Component(com.hortonworks.streamline.streams.layout.component.Component) Path(java.nio.file.Path) Config(com.hortonworks.streamline.common.Config) StreamGrouping(com.hortonworks.streamline.streams.layout.component.StreamGrouping) YAML_KEY_FROM(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants.YAML_KEY_FROM) Function(com.google.common.base.Function) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Logger(org.slf4j.Logger) Stream(com.hortonworks.streamline.streams.layout.component.Stream) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractMap(java.util.AbstractMap) List(java.util.List) YAML_KEY_TO(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants.YAML_KEY_TO) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule)

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