Search in sources :

Example 1 with Action

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

the class TopologyWindow 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(ACTIONS, actions != null ? mapper.writerFor(new TypeReference<List<Action>>() {
        }).writeValueAsString(actions) : "");
        map.put(PROJECTIONS, projections != null ? mapper.writeValueAsString(projections) : "");
        map.put(GROUPBYKEYS, groupbykeys != null ? mapper.writeValueAsString(groupbykeys) : "");
    } 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 2 with Action

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

the class TopologyWindow method fromMap.

@Override
public Storable fromMap(Map<String, Object> map) {
    super.fromMap(map);
    setId((Long) map.get(ID));
    setVersionId((Long) map.get(VERSIONID));
    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));
    try {
        ObjectMapper mapper = new ObjectMapper();
        String streamsStr = (String) map.get(STREAMS);
        if (!StringUtils.isEmpty(streamsStr)) {
            List<String> streams = mapper.readValue(streamsStr, new TypeReference<List<String>>() {
            });
            setStreams(streams);
        }
        String outputStreamsStr = (String) map.get(OUTPUT_STREAMS);
        if (!StringUtils.isEmpty(outputStreamsStr)) {
            List<String> outputStreams = mapper.readValue(outputStreamsStr, new TypeReference<List<String>>() {
            });
            setOutputStreams(outputStreams);
        }
        String windowStr = (String) map.get(WINDOW);
        if (!StringUtils.isEmpty(windowStr)) {
            Window window = mapper.readValue(windowStr, Window.class);
            setWindow(window);
        }
        String actionsStr = (String) map.get(ACTIONS);
        if (!StringUtils.isEmpty(actionsStr)) {
            List<Action> actions = mapper.readValue(actionsStr, new TypeReference<List<Action>>() {
            });
            setActions(actions);
        }
        String projectionsStr = (String) map.get(PROJECTIONS);
        if (!StringUtils.isEmpty(projectionsStr)) {
            List<Projection> projections = mapper.readValue(projectionsStr, new TypeReference<List<Projection>>() {
            });
            setProjections(projections);
        }
        String groupbykeysStr = (String) map.get(GROUPBYKEYS);
        if (!StringUtils.isEmpty(groupbykeysStr)) {
            List<String> groupbykeys = mapper.readValue(groupbykeysStr, new TypeReference<List<String>>() {
            });
            setGroupbykeys(groupbykeys);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Action

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

the class TopologyRule method fromMap.

@Override
public Storable fromMap(Map<String, Object> map) {
    super.fromMap(map);
    setId((Long) map.get(ID));
    setVersionId((Long) map.get(VERSIONID));
    setTopologyId((Long) map.get(TOPOLOGY_ID));
    setName((String) map.get(NAME));
    setDescription((String) map.get(DESCRIPTION));
    setCondition((String) map.get(CONDITION));
    setSql((String) map.get(SQL));
    setParsedRuleStr((String) map.get(PARSED_RULE_STR));
    try {
        ObjectMapper mapper = new ObjectMapper();
        String streamsStr = (String) map.get(STREAMS);
        if (!StringUtils.isEmpty(streamsStr)) {
            List<String> streams = mapper.readValue(streamsStr, new TypeReference<List<String>>() {
            });
            setStreams(streams);
        }
        String outputStreamsStr = (String) map.get(OUTPUT_STREAMS);
        if (!StringUtils.isEmpty(outputStreamsStr)) {
            List<String> outputStreams = mapper.readValue(outputStreamsStr, new TypeReference<List<String>>() {
            });
            setOutputStreams(outputStreams);
        }
        String windowStr = (String) map.get(WINDOW);
        if (!StringUtils.isEmpty(windowStr)) {
            Window window = mapper.readValue(windowStr, Window.class);
            setWindow(window);
        }
        String projectionsStr = (String) map.get(PROJECTIONS);
        if (!StringUtils.isEmpty(projectionsStr)) {
            setProjections(mapper.readValue(projectionsStr, new TypeReference<List<Projection>>() {
            }));
        }
        String actionsStr = (String) map.get(ACTIONS);
        if (!StringUtils.isEmpty(actionsStr)) {
            setActions(mapper.readValue(actionsStr, new TypeReference<List<Action>>() {
            }));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with Action

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

the class SplitJoinTest method checkActionWriteReadJsons.

protected static void checkActionWriteReadJsons(Action action) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    final String value = objectMapper.writeValueAsString(action);
    log.info("####### value = " + value);
    Class<? extends Action> actionClass = Action.class;
    Action actionRead = objectMapper.readValue(value, actionClass);
    log.info("####### actionRead = " + actionRead);
}
Also used : SplitAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction) JoinAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Action

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

the class RulesProcessorMock method getRule.

private Rule getRule(long ruleId, Condition condition, TransformAction action) {
    Rule rule = new Rule();
    rule.setId(ruleId);
    rule.setName(RULE + "_" + ruleId);
    rule.setDescription(RULE + "_" + ruleId + "_desc");
    rule.setRuleProcessorName(RULE_PROCESSOR + "_" + ruleProcessorId);
    rule.setCondition(condition);
    if (ruleId % 2 == 0) {
        Projection projection = new Projection();
        Expression humidity = new FieldExpression(Field.of("humidity", Schema.Type.INTEGER));
        Expression deviceName = new FieldExpression(Field.of("devicename", Schema.Type.STRING));
        Expression incr = new FunctionExpression("INCR", "com.hortonworks.streamline.streams.runtime.storm.layout.runtime.rule.topology.RulesProcessorMock$Incr", ImmutableList.<Expression>of(humidity, new Literal("10")));
        Expression upper = new FunctionExpression("UPPER", ImmutableList.<Expression>of(deviceName));
        projection.setExpressions(ImmutableList.<Expression>of(humidity, incr, upper));
        rule.setProjection(projection);
    }
    rule.setActions(Collections.singletonList((Action) action));
    return rule;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)

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