X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=rulemgt%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Frulemgt%2Fwrapper%2FRuleMgtWrapper.java;h=196b21a2f8ba0b34e520591ec45216904d0d8552;hb=580d4ce637b1c09b3bd2258b0b9c8332b8789bad;hp=5c2a428db871a3897a22cf896124cd6f13bba8b9;hpb=973f3377b5e3590fd0cb71b6fd8d00ffc5aa55b8;p=holmes%2Frule-management.git diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java index 5c2a428..196b21a 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; -import org.onap.holmes.common.dmaap.DmaapService; import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine; import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.onap.holmes.rulemgt.constant.RuleMgtConstant; @@ -40,6 +39,7 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao; +import org.onap.holmes.rulemgt.send.Ip4AddingRule; @Service @@ -47,6 +47,12 @@ import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao; @Slf4j public class RuleMgtWrapper { + @Inject + private Ip4AddingRule ip4AddingRule; + + @Inject + private RuleQueryWrapper ruleQueryWrapper; + @Inject private CorrelationRuleQueryDao correlationRuleQueryDao; @Inject @@ -73,16 +79,21 @@ public class RuleMgtWrapper { if (ruleTemp != null) { throw new CorrelationException("A rule with the same name already exists."); } - - String packageName = deployRule2Engine(correlationRule); - DmaapService.loopControlNames.put(packageName, ruleCreateRequest.getLoopControlName()); + String ip =""; + try{ + ip = ip4AddingRule.getEngineIp4AddRule(); + }catch(Exception e){ + log.error("When adding rules, can not get engine instance ip"); + } + String packageName = deployRule2Engine(correlationRule, ip); correlationRule.setPackageName(packageName); + correlationRule.setEngineInstance(ip); CorrelationRule result = null; try { result = correlationRuleDao.saveRule(correlationRule); } catch (CorrelationException e) { - engineWarpper.deleteRuleFromEngine(packageName); - throw new CorrelationException(e.getMessage()); + engineWarpper.deleteRuleFromEngine(packageName, ip); + throw new CorrelationException(e.getMessage(), e); } RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse(); ruleAddAndUpdateResponse.setRuleId(result.getRid()); @@ -98,18 +109,23 @@ public class RuleMgtWrapper { if (oldCorrelationRule == null) { throw new CorrelationException("You're trying to update a rule which does not exist in the system."); } + String updateIp = ""; + updateIp = oldCorrelationRule.getEngineInstance(); CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier, ruleUpdateRequest, oldCorrelationRule.getName()); + newCorrelationRule.setEngineInstance(updateIp); checkCorrelation(newCorrelationRule); RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse(); ruleChangeResponse.setRuleId(newCorrelationRule.getRid()); + if (!haveChange(newCorrelationRule, oldCorrelationRule)) { return ruleChangeResponse; } if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) { - engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName()); + String oldRuleEngineInstance = oldCorrelationRule.getEngineInstance(); + engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName(), oldRuleEngineInstance); } - newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule)); + newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule, updateIp)); correlationRuleDao.updateRule(newCorrelationRule); return ruleChangeResponse; } @@ -137,7 +153,10 @@ public class RuleMgtWrapper { int oldEnabled = oldCorrelationRule.getEnabled(); String newDes = newCorrelationRule.getDescription(); String oldDes = oldCorrelationRule.getDescription(); - if (newContent.equals(oldContent) && newEnabled == oldEnabled && newDes.equals(oldDes)) { + String oldControlLoop = oldCorrelationRule.getClosedControlLoopName(); + String newControlLoop = newCorrelationRule.getClosedControlLoopName(); + if (newContent.equals(oldContent) && newEnabled == oldEnabled + && newDes.equals(oldDes) && newControlLoop.equals(oldControlLoop)) { return false; } return true; @@ -154,7 +173,8 @@ public class RuleMgtWrapper { throw new CorrelationException("You're trying to delete a rule which does not exist in the system."); } if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) { - engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName()); + String ip = correlationRule.getEngineInstance(); + engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName(), ip); } correlationRuleDao.deleteRule(correlationRule); } @@ -180,6 +200,7 @@ public class RuleMgtWrapper { correlationRule.setCreator(userName); correlationRule.setModifier(userName); correlationRule.setEnabled(ruleCreateRequest.getEnabled()); + correlationRule.setClosedControlLoopName(ruleCreateRequest.getLoopControlName()); return correlationRule; } @@ -194,14 +215,15 @@ public class RuleMgtWrapper { correlationRule.setUpdateTime(new Date()); correlationRule.setModifier(modifier); correlationRule.setName(ruleName); + correlationRule.setClosedControlLoopName(ruleUpdateRequest.getLoopControlName()); return correlationRule; } - private String deployRule2Engine(CorrelationRule correlationRule) + public String deployRule2Engine(CorrelationRule correlationRule, String ip) throws CorrelationException { - if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule)) && ( + if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule), ip) && ( correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN)) { - return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule)); + return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule), ip); } return ""; } @@ -232,6 +254,7 @@ public class RuleMgtWrapper { ruleResult4API.setUpdateTime(correlationRule.getUpdateTime()); ruleResult4API.setModifier(correlationRule.getModifier()); ruleResult4API.setEnabled(correlationRule.getEnabled()); + ruleResult4API.setLoopControlName(correlationRule.getClosedControlLoopName()); ruleResult4APIs.add(ruleResult4API); } return ruleResult4APIs; @@ -242,6 +265,7 @@ public class RuleMgtWrapper { CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine(); correlationDeployRule4Engine.setContent(correlationRule.getContent()); correlationDeployRule4Engine.setEngineId(correlationRule.getEngineID()); + correlationDeployRule4Engine.setLoopControlName(correlationRule.getClosedControlLoopName()); return correlationDeployRule4Engine; }