Fixed MSB Invocation Issues
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / wrapper / RuleMgtWrapper.java
index 196b21a..22982da 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
  * Copyright 2017 ZTE Corporation.\r
- *\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.annotation.PostConstruct;\r
 import javax.inject.Inject;\r
 import javax.inject.Singleton;\r
+\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
@@ -39,7 +40,7 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
 import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
 import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;\r
 import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao;\r
-import org.onap.holmes.rulemgt.send.Ip4AddingRule;\r
+import org.onap.holmes.rulemgt.tools.EngineTools;\r
 \r
 \r
 @Service\r
@@ -48,7 +49,7 @@ import org.onap.holmes.rulemgt.send.Ip4AddingRule;
 public class RuleMgtWrapper {\r
 \r
     @Inject\r
-    private Ip4AddingRule ip4AddingRule;\r
+    private EngineTools engineTools;\r
 \r
     @Inject\r
     private RuleQueryWrapper ruleQueryWrapper;\r
@@ -79,10 +80,10 @@ public class RuleMgtWrapper {
         if (ruleTemp != null) {\r
             throw new CorrelationException("A rule with the same name already exists.");\r
         }\r
-        String ip ="";\r
-        try{\r
-            ip = ip4AddingRule.getEngineIp4AddRule();\r
-        }catch(Exception e){\r
+        String ip = "";\r
+        try {\r
+            ip = engineTools.getEngineWithLeastRules();\r
+        } catch (Exception e) {\r
             log.error("When adding rules, can not get engine instance ip");\r
         }\r
         String packageName = deployRule2Engine(correlationRule, ip);\r
@@ -180,7 +181,7 @@ public class RuleMgtWrapper {
     }\r
 \r
     private CorrelationRule convertCreateRequest2Rule(String userName,\r
-            RuleCreateRequest ruleCreateRequest) throws CorrelationException {\r
+                                                      RuleCreateRequest ruleCreateRequest) throws CorrelationException {\r
         String tempContent = ruleCreateRequest.getContent();\r
         CorrelationRule correlationRule = new CorrelationRule();\r
         String ruleId = "rule_" + System.currentTimeMillis();\r
@@ -205,7 +206,7 @@ public class RuleMgtWrapper {
     }\r
 \r
     private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,\r
-            RuleUpdateRequest ruleUpdateRequest, String ruleName) throws CorrelationException {\r
+                                                                     RuleUpdateRequest ruleUpdateRequest, String ruleName) throws CorrelationException {\r
         CorrelationRule correlationRule = new CorrelationRule();\r
         String description = ruleUpdateRequest.getDescription() == null ? "" : ruleUpdateRequest.getDescription();\r
         correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
@@ -221,7 +222,7 @@ public class RuleMgtWrapper {
 \r
     public String deployRule2Engine(CorrelationRule correlationRule, String ip)\r
             throws CorrelationException {\r
-        if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule), ip) && (\r
+        if (engineWarpper.checkRuleFromEngine(toCorrelationCheckRule(correlationRule), ip) && (\r
                 correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN)) {\r
             return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule), ip);\r
         }\r
@@ -269,7 +270,7 @@ public class RuleMgtWrapper {
         return correlationDeployRule4Engine;\r
     }\r
 \r
-    private CorrelationCheckRule4Engine correlationRules2CheckRule(\r
+    private CorrelationCheckRule4Engine toCorrelationCheckRule(\r
             CorrelationRule correlationRule) {\r
         CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
         correlationCheckRule4Engine.setContent(correlationRule.getContent());\r