use of com.hortonworks.streamline.streams.catalog.BaseTopologyRule in project streamline by hortonworks.
the class StreamCatalogService method setReconfigureRules.
private void setReconfigureRules(List<TopologyProcessor> processors, List<TopologyStream> affectedStreams) {
Map<Long, BiFunction<TopologyProcessor, Long, BaseTopologyRule>> bundles = new HashMap<>();
TopologyComponentBundle bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.RULE);
bundles.put(bundle.getId(), (p, r) -> getRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.BRANCH);
bundles.put(bundle.getId(), (p, r) -> getBranchRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.PROJECTION);
bundles.put(bundle.getId(), (p, r) -> getRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.WINDOW);
bundles.put(bundle.getId(), (p, r) -> getWindow(p.getTopologyId(), r, p.getVersionId()));
Set<String> affectedStreamIds = affectedStreams.stream().map(TopologyStream::getStreamId).collect(Collectors.toSet());
for (TopologyProcessor processor : processors) {
BiFunction<TopologyProcessor, Long, BaseTopologyRule> function;
if ((function = bundles.get(processor.getTopologyComponentBundleId())) != null) {
Optional<Object> ruleList = processor.getConfig().getAnyOptional(RulesProcessor.CONFIG_KEY_RULES);
if (ruleList.isPresent()) {
ObjectMapper objectMapper = new ObjectMapper();
List<Long> ruleIds = objectMapper.convertValue(ruleList.get(), new TypeReference<List<Long>>() {
});
for (Long ruleId : ruleIds) {
BaseTopologyRule rule = function.apply(processor, ruleId);
if (rule != null) {
for (String stream : rule.getInputStreams()) {
if (affectedStreamIds.contains(stream)) {
rule.setReconfigure(true);
dao.addOrUpdate(rule);
break;
}
}
}
}
}
}
}
}
Aggregations