use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class BaseTopologyRule method getRule.
@JsonIgnore
public final Rule getRule() throws IOException {
ObjectMapper mapper = new ObjectMapper();
Rule rule = mapper.readValue(getParsedRuleStr(), Rule.class);
if (rule.getId() == null) {
rule.setId(getId());
}
return rule;
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class StreamCatalogService method parseAndSerialize.
private String parseAndSerialize(TopologyBranchRule ruleInfo) throws JsonProcessingException {
Rule rule = new Rule();
rule.setId(ruleInfo.getId());
rule.setName(ruleInfo.getName());
rule.setDescription(ruleInfo.getDescription());
rule.setActions(ruleInfo.getActions());
String sql = getSqlString(Collections.singletonList(ruleInfo.getStream()), null, ruleInfo.getCondition(), null);
updateRuleWithSql(rule, sql, ruleInfo.getTopologyId(), ruleInfo.getVersionId());
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(rule);
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule in project streamline by hortonworks.
the class StreamCatalogService method parseAndSerialize.
private String parseAndSerialize(TopologyWindow topologyWindow) throws JsonProcessingException {
if (topologyWindow.getStreams() == null || topologyWindow.getStreams().isEmpty()) {
LOG.error("Streams should be specified.");
return StringUtils.EMPTY;
}
Rule rule = new Rule();
rule.setId(topologyWindow.getId());
rule.setName(topologyWindow.getName());
rule.setDescription(topologyWindow.getDescription());
rule.setWindow(topologyWindow.getWindow());
rule.setActions(topologyWindow.getActions());
String sql = getSqlString(topologyWindow.getStreams(), topologyWindow.getProjections(), topologyWindow.getCondition(), topologyWindow.getGroupbykeys());
updateRuleWithSql(rule, sql, topologyWindow.getTopologyId(), topologyWindow.getVersionId());
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(rule);
}
use of com.hortonworks.streamline.streams.layout.component.rule.Rule 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.rule.Rule in project streamline by hortonworks.
the class TopologyExportVisitor method visit.
public void visit(RulesProcessor rulesProcessor) {
try {
TopologyComponentBundle componentBundle = streamCatalogService.getTopologyComponentBundle(Long.parseLong(rulesProcessor.getTopologyComponentBundleId()));
String subType = componentBundle.getSubType();
RulesHandler rulesHandler = rulesHandlerMap.get(subType);
for (Rule rule : rulesProcessor.getRules()) {
rulesHandler.handle(rule);
}
} catch (Exception e) {
throw new RuntimeException(String.format("Unexpected exception thrown while trying to add the rule %s", rulesProcessor.getId()), e);
}
TopologyProcessor topologyProcessor = streamCatalogService.getTopologyProcessor(topologyId, Long.parseLong(rulesProcessor.getId()));
topologyData.addProcessor(topologyProcessor);
storeBundleIdToType(rulesProcessor);
}
Aggregations