use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class WindowRuleBoltFluxComponent method addWindowConfig.
private String addWindowConfig() {
String windowId = "window" + UUID_FOR_COMPONENTS;
String windowClassName = "com.hortonworks.streamline.streams.layout.component.rule.expression.Window";
ObjectMapper mapper = new ObjectMapper();
String windowJson = null;
try {
Set<Window> windows = new HashSet<>(Collections2.transform(rulesProcessor.getRules(), new Function<Rule, Window>() {
@Override
public Window apply(Rule input) {
return input.getWindow();
}
}));
if (windows.size() != 1) {
throw new IllegalArgumentException("All the rules in a windowed rule bolt should have the same window config.");
}
windowJson = mapper.writeValueAsString(windows.iterator().next());
} catch (JsonProcessingException e) {
log.error("Error creating json config string for RulesProcessor", e);
}
List<String> constructorArgs = new ArrayList<>();
constructorArgs.add(windowJson);
this.addToComponents(this.createComponent(windowId, windowClassName, null, constructorArgs, null));
return windowId;
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class RulesProcessorMock method getRule.
private Rule getRule(long ruleId, Condition condition, TransformAction action) {
Rule rule = new Rule();
rule.setId(ruleId);
rule.setName(RULE + "_" + ruleId);
rule.setDescription(RULE + "_" + ruleId + "_desc");
rule.setRuleProcessorName(RULE_PROCESSOR + "_" + ruleProcessorId);
rule.setCondition(condition);
if (ruleId % 2 == 0) {
Projection projection = new Projection();
Expression humidity = new FieldExpression(Field.of("humidity", Schema.Type.INTEGER));
Expression deviceName = new FieldExpression(Field.of("devicename", Schema.Type.STRING));
Expression incr = new FunctionExpression("INCR", "com.hortonworks.streamline.streams.runtime.storm.layout.runtime.rule.topology.RulesProcessorMock$Incr", ImmutableList.<Expression>of(humidity, new Literal("10")));
Expression upper = new FunctionExpression("UPPER", ImmutableList.<Expression>of(deviceName));
projection.setExpressions(ImmutableList.<Expression>of(humidity, incr, upper));
rule.setProjection(projection);
}
rule.setActions(Collections.singletonList((Action) action));
return rule;
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule 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);
}
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class RuleProcessorRuntime method initializeRuleRuntimes.
private void initializeRuleRuntimes(Map<String, Object> config) {
List<Rule> rules = rulesProcessor.getRules();
if (rules != null) {
for (Rule rule : rules) {
RuleRuntime ruleRuntime;
Script script = null;
if (ScriptType.GROOVY.equals(scriptType)) {
script = createGroovyScript(rule);
} else if (ScriptType.SQL.equals(scriptType)) {
script = createSqlScript(rule);
} else {
throw new RuntimeException("Ruleruntime scriptType unsupported: " + scriptType);
}
ruleRuntime = new RuleRuntime(rule, script, createActionRuntimes(rule));
rulesRuntime.add(ruleRuntime);
ruleRuntime.initialize(config);
}
LOG.info("ruleRuntimes [{}]", rulesRuntime);
}
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class Utils method createTrueRule.
/**
* Returns a rule with no condition(which is equivalent to true) with the given action.
*
* @param action Action to be set on the rule
*/
public static Rule createTrueRule(final Action action) {
Rule rule = new Rule() {
{
setName(action.getName() + "-rule");
setId(System.currentTimeMillis());
}
};
rule.setActions(Collections.singletonList(action));
return rule;
}
Aggregations