Search in sources :

Example 6 with Action

use of com.hortonworks.streamline.streams.layout.component.rule.action.Action in project streamline by hortonworks.

the class TopologyBranchRule method fromMap.

@Override
public Storable fromMap(Map<String, Object> map) {
    super.fromMap(map);
    setId((Long) map.get(ID));
    setVersionId((Long) map.get(VERSION_ID));
    setTopologyId((Long) map.get(TOPOLOGY_ID));
    setName((String) map.get(NAME));
    setDescription((String) map.get(DESCRIPTION));
    setCondition((String) map.get(CONDITION));
    setParsedRuleStr((String) map.get(PARSED_RULE_STR));
    setStream((String) map.get(STREAM));
    try {
        ObjectMapper mapper = new ObjectMapper();
        String outputStreamsStr = (String) map.get(OUTPUT_STREAMS);
        if (!StringUtils.isEmpty(outputStreamsStr)) {
            List<String> outputStreams = mapper.readValue(outputStreamsStr, new TypeReference<List<String>>() {
            });
            setOutputStreams(outputStreams);
        }
        String actionsStr = (String) map.get(ACTIONS);
        if (!StringUtils.isEmpty(actionsStr)) {
            List<Action> actions = mapper.readValue(actionsStr, new TypeReference<List<Action>>() {
            });
            setActions(actions);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with Action

use of com.hortonworks.streamline.streams.layout.component.rule.action.Action in project streamline by hortonworks.

the class TopologyBranchRule method toMap.

@Override
public Map<String, Object> toMap() {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> map = super.toMap();
    try {
        map.put(OUTPUT_STREAMS, outputStreams != null ? mapper.writeValueAsString(outputStreams) : "");
        map.put(ACTIONS, actions != null ? mapper.writerFor(new TypeReference<List<Action>>() {
        }).writeValueAsString(actions) : "");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 8 with Action

use of com.hortonworks.streamline.streams.layout.component.rule.action.Action in project streamline by hortonworks.

the class TopologyRule method toMap.

@Override
public Map<String, Object> toMap() {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> map = super.toMap();
    try {
        map.put(STREAMS, streams != null ? mapper.writeValueAsString(streams) : "");
        map.put(OUTPUT_STREAMS, outputStreams != null ? mapper.writeValueAsString(outputStreams) : "");
        map.put(WINDOW, window != null ? mapper.writeValueAsString(window) : "");
        map.put(PROJECTIONS, projections != null ? mapper.writerFor(new TypeReference<List<Projection>>() {
        }).writeValueAsString(projections) : "");
        map.put(ACTIONS, actions != null ? mapper.writerFor(new TypeReference<List<Action>>() {
        }).writeValueAsString(actions) : "");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 9 with Action

use of com.hortonworks.streamline.streams.layout.component.rule.action.Action in project streamline by hortonworks.

the class RulesProcessor method setRules.

public void setRules(List<Rule> rules) {
    this.rules = rules;
    Set<String> streamIds = new HashSet<>(Collections2.transform(getOutputStreams(), new Function<Stream, String>() {

        @Override
        public String apply(Stream input) {
            return input.getId();
        }
    }));
    for (Rule rule : rules) {
        for (Action action : rule.getActions()) {
            for (String stream : action.getOutputStreams()) {
                if (!streamIds.contains(stream)) {
                    String errorMsg = String.format("Action [%s] stream [%s] does not exist in processor [%s]'s output streams [%s]", action, stream, getName(), streamIds);
                    log.error(errorMsg);
                    throw new IllegalArgumentException(errorMsg);
                }
            }
        }
    }
}
Also used : Function(com.google.common.base.Function) Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) Stream(com.hortonworks.streamline.streams.layout.component.Stream) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) HashSet(java.util.HashSet)

Example 10 with Action

use of com.hortonworks.streamline.streams.layout.component.rule.action.Action in project streamline by hortonworks.

the class RuleProcessorRuntime method createActionRuntimes.

private List<ActionRuntime> createActionRuntimes(Rule rule) {
    List<ActionRuntime> runtimeActions = new ArrayList<>();
    for (Action action : rule.getActions()) {
        final ActionRuntime actionRuntime = ActionRuntimeService.get().get(action);
        actionRuntime.setActionRuntimeContext(new ActionRuntimeContext(rule, action));
        runtimeActions.add(actionRuntime);
    }
    return runtimeActions;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) ArrayList(java.util.ArrayList) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)

Aggregations

Action (com.hortonworks.streamline.streams.layout.component.rule.action.Action)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)2 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)2 Function (com.google.common.base.Function)1 Stream (com.hortonworks.streamline.streams.layout.component.Stream)1 JoinAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction)1 SplitAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction)1 StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)1 TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)1 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)1 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)1 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)1 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)1 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)1 Projection (com.hortonworks.streamline.streams.layout.component.rule.expression.Projection)1