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;
}
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;
}
};
}
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);
}
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;
}
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);
}
}
Aggregations