/**\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
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
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
public class RuleMgtWrapper {\r
\r
@Inject\r
- private Ip4AddingRule ip4AddingRule;\r
+ private EngineTools engineTools;\r
\r
@Inject\r
private RuleQueryWrapper ruleQueryWrapper;\r
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
}\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
}\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
\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
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