Search in sources :

Example 1 with BaseTopologyRule

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;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) HashMap(java.util.HashMap) BiFunction(java.util.function.BiFunction) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)1 TopologyProcessor (com.hortonworks.streamline.streams.catalog.TopologyProcessor)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BiFunction (java.util.function.BiFunction)1