Search in sources :

Example 1 with Rule

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;
}
Also used : Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 2 with 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);
}
Also used : Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with 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);
}
Also used : Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with 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;
        }
    };
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) ArrayList(java.util.ArrayList) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TopologyOutputComponent(com.hortonworks.streamline.streams.catalog.TopologyOutputComponent) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) List(java.util.List) ArrayList(java.util.ArrayList) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Rule

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);
}
Also used : Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Aggregations

Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)7 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)7 Function (com.google.common.base.Function)5 HashSet (java.util.HashSet)5 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)4 Stream (com.hortonworks.streamline.streams.layout.component.Stream)4 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)4 ArrayList (java.util.ArrayList)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Collections2 (com.google.common.collect.Collections2)2 QueryParam (com.hortonworks.registries.common.QueryParam)2 TopologyWindow (com.hortonworks.streamline.streams.catalog.TopologyWindow)2 UDF (com.hortonworks.streamline.streams.catalog.UDF)2 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)2 List (java.util.List)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1