public TopologyBranchRule(TopologyBranchRule other) { if (other != null) { setId(other.getId()); setTopologyId(other.getTopologyId()); setVersionId(other.getVersionId()); setName(other.getName()); setDescription(other.getDescription()); setStream(other.getStream()); setCondition(other.getCondition()); setParsedRuleStr(other.getParsedRuleStr()); if (other.getActions() != null) { setActions(other.getActions().stream().map(Action::copy).collect(Collectors.toList())); } if (other.getOutputStreams() != null) { setOutputStreams(new ArrayList<>(other.getOutputStreams())); } setVersionTimestamp(other.getVersionTimestamp()); } }
public TopologyBranchRule getBranchRule(Long topologyId, Long ruleId, Long versionId) { TopologyBranchRule topologyBranchRule = new TopologyBranchRule(); topologyBranchRule.setId(ruleId); topologyBranchRule.setVersionId(versionId); topologyBranchRule = dao.get(new StorableKey(TOPOLOGY_BRANCHRULEINFO_NAMESPACE, topologyBranchRule.getPrimaryKey())); if (topologyBranchRule == null || !topologyBranchRule.getTopologyId().equals(topologyId)) { return null; } topologyBranchRule.setVersionTimestamp(getVersionTimestamp(versionId)); return topologyBranchRule; }
@Override public Rule getRule(Long topologyId, Long ruleId, Long versionId) throws Exception { TopologyBranchRule topologyBranchRule = catalogService.getBranchRule(topologyId, ruleId, versionId); if (topologyBranchRule == null) { throw new IllegalArgumentException("Cannot find branch rule with id " + ruleId); } else if (topologyBranchRule.getReconfigure()) { throw new IllegalStateException("Rule " + topologyBranchRule.getName() + " must be reconfigured"); } return topologyBranchRule.getRule(); } }));
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); }
public TopologyBranchRule addBranchRule(Long topologyId, Long versionId, TopologyBranchRule topologyBranchRule) throws Exception { if (topologyBranchRule.getId() == null) { topologyBranchRule.setId(dao.nextId(TOPOLOGY_BRANCHRULEINFO_NAMESPACE)); } topologyBranchRule.setTopologyId(topologyId); topologyBranchRule.setVersionId(versionId); String parsedRuleStr = parseAndSerialize(topologyBranchRule); LOG.debug("ParsedRuleStr {}", parsedRuleStr); topologyBranchRule.setParsedRuleStr(parsedRuleStr); dao.add(topologyBranchRule); topologyBranchRule.setVersionTimestamp(updateVersionTimestamp(versionId).getTimestamp()); return topologyBranchRule; }
public TopologyBranchRule removeBranchRule(Long topologyId, Long id, Long versionId) throws Exception { TopologyBranchRule topologyBranchRule = getBranchRule(topologyId, id, versionId); if (topologyBranchRule != null) { topologyBranchRule = dao.remove(new StorableKey(TOPOLOGY_BRANCHRULEINFO_NAMESPACE, topologyBranchRule.getPrimaryKey())); topologyBranchRule.setVersionTimestamp(updateVersionTimestamp(versionId).getTimestamp()); } return topologyBranchRule; }
Topology.NAMESPACE, topologyId, READ); TopologyBranchRule brRuleInfo = catalogService.getBranchRule(topologyId, ruleId); if (brRuleInfo != null && brRuleInfo.getTopologyId().equals(topologyId)) { return WSUtils.respondEntity(brRuleInfo, OK);
removeBranchRule(topologyId, topologyBranchRule.getId(), versionId);
addBranchRule(topologyId, newVersionId, new TopologyBranchRule(topologyBranchRule));