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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations