summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/main/java/org/onap')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java22
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java31
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java20
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java58
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java9
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java7
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java3
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java9
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java124
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java (renamed from rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java)53
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java94
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java31
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java62
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java8
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java122
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java23
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java99
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java23
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java12
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java66
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java25
22 files changed, 366 insertions, 537 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
index 799f455..fc3e798 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2018 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.onap.holmes.rulemgt;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.CommonUtils;
@@ -25,31 +24,32 @@ import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.onap.msb.sdk.discovery.entity.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-import static org.onap.holmes.common.config.MicroServiceConfig.POD_IP;
import static org.onap.holmes.common.utils.CommonUtils.getEnv;
import static org.onap.holmes.common.utils.CommonUtils.isIpAddress;
-@Service
-public class Initializer {
+@Component
+public class Initializer implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger(Initializer.class);
private volatile static boolean readyForMsbReg = false;
private MsbRegister msbRegister;
- @Inject
+ @Autowired
public Initializer(MsbRegister msbRegister) {
this.msbRegister = msbRegister;
}
- @PostConstruct
- private void init() {
+ @Override
+ public void run(ApplicationArguments args) {
Executors.newSingleThreadExecutor().execute(() -> {
waitUntilReady();
try {
@@ -93,7 +93,7 @@ public class Initializer {
msinfo.setEnable_ssl(CommonUtils.isHttpsEnabled());
Set<Node> nodes = new HashSet<>();
Node node = new Node();
- node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv(POD_IP));
+ node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv("HOLMES_RULE_MGMT_SERVICE_HOST"));
node.setPort("9101");
/* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now
String msbAddrTemplate = (CommonUtils.isHttpsEnabled() ? "https" : "http")
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
index cedcde0..3d60a11 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,36 +16,37 @@
package org.onap.holmes.rulemgt;
-import io.dropwizard.setup.Environment;
+import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.ConfigFileScanner;
-import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;
-import org.onap.holmes.common.utils.transactionid.TransactionIdFilter;
import org.onap.holmes.rulemgt.dcae.ConfigFileScanningTask;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.context.annotation.ComponentScan;
-import javax.servlet.DispatcherType;
-import java.util.EnumSet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
+@Slf4j
+@SpringBootApplication
+@ServletComponentScan
+@ComponentScan(basePackages = {"org.onap.holmes"})
+public class RuleActiveApp implements ApplicationRunner {
- public static void main(String[] args) throws Exception {
- new RuleActiveApp().run(args);
+ public static void main(String[] args) {
+ SpringApplication.run(RuleActiveApp.class, args);
}
@Override
- public void run(RuleAppConfig configuration, Environment environment) throws Exception {
- super.run(configuration, environment);
-
+ public void run(ApplicationArguments args) {
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(
new ConfigFileScanningTask(new ConfigFileScanner()), 60L,
ConfigFileScanningTask.POLLING_PERIOD, TimeUnit.SECONDS);
- environment.servlets().addFilter("customFilter", new TransactionIdFilter()).addMappingForUrlPatterns(EnumSet
- .allOf(DispatcherType.class), true, "/*");
-
Initializer.setReadyForMsbReg(true);
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
index bf26b71..79ffa31 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
@@ -17,27 +17,25 @@
package org.onap.holmes.rulemgt;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.*;
-import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
@Slf4j
-@Service
+@Component
public class RuleAllocator {
private static final Logger LOGGER = LoggerFactory.getLogger(RuleAllocator.class);
@@ -48,16 +46,16 @@ public class RuleAllocator {
private RuleQueryWrapper ruleQueryWrapper;
private EngineWrapper engineWrapper;
private EngineTools engineTools;
- private CorrelationRuleDao correlationRuleDao;
+ private CorrelationRuleService correlationRuleService;
- @Inject
+ @Autowired
public RuleAllocator(RuleMgtWrapper ruleMgtWrapper, RuleQueryWrapper ruleQueryWrapper,
- EngineWrapper engineWrapper, EngineTools engineTools, DbDaoUtil daoUtil) {
+ EngineWrapper engineWrapper, EngineTools engineTools, CorrelationRuleService correlationRuleService) {
this.ruleMgtWrapper = ruleMgtWrapper;
this.ruleQueryWrapper = ruleQueryWrapper;
this.engineWrapper = engineWrapper;
this.engineTools = engineTools;
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
+ this.correlationRuleService = correlationRuleService;
}
@PostConstruct
@@ -228,7 +226,7 @@ public class RuleAllocator {
for (int i = 0; i <= RETRY_TIMES; ++i) {
try {
ruleMgtWrapper.deployRule2Engine(rule, ip);
- correlationRuleDao.updateRule(rule);
+ correlationRuleService.updateRule(rule);
// If the codes reach here, it means everything's okay. There's no need to run the loop more.
break;
} catch (CorrelationException e) {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java
deleted file mode 100644
index 20f96c2..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import io.dropwizard.Configuration;
-import io.dropwizard.db.DataSourceFactory;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import org.hibernate.validator.constraints.NotEmpty;
-import org.jvnet.hk2.annotations.Service;
-
-@Service
-public class RuleAppConfig extends Configuration {
-
- @NotEmpty
- private String defaultName = "Holmes Rule Management";
-
- @NotEmpty
- private String apidescription = "Holmes rule management rest API";
-
- @Valid
- @NotNull
- private DataSourceFactory database = new DataSourceFactory();
-
- @JsonProperty("database")
- public DataSourceFactory getDataSourceFactory() {
- return database;
- }
-
- @JsonProperty("database")
- public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
- this.database = dataSourceFactory;
- }
-
-
- public String getApidescription() {
- return apidescription;
- }
-
- public void setApidescription(String apidescription) {
- this.apidescription = apidescription;
- }
-
-}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
index 714a95c..5abdab7 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
@@ -15,8 +15,6 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
index 4b6e248..0d1dd05 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2021 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,13 @@
*/
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import org.jvnet.hk2.annotations.Service;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
+import org.springframework.stereotype.Service;
import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
index 7c927c0..e63b726 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
@@ -18,19 +18,18 @@ package org.onap.holmes.rulemgt.bolt.enginebolt;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-
-import javax.inject.Inject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
@Service
@Slf4j
public class EngineWrapper {
- @Inject
+ @Autowired
private EngineService engineService;
public String deployEngine(CorrelationDeployRule4Engine correlationRule, String ip) throws CorrelationException {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
index 73a2f2b..6149616 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,5 +25,4 @@ public class RuleMgtConstant {
public static final int STATUS_RULE_ALL = 2;
public static final String PACKAGE = "packageName";
public static final String ENGINE_PATH = "/api/holmes-engine-mgmt/v1/rule";
- public static final int RESPONSE_STATUS_OK = 200;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
index 2850708..a893413 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2020 ZTE Corporation.
+ * Copyright 2020-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,12 @@
package org.onap.holmes.rulemgt.controller;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -36,7 +35,7 @@ public class EngineInstanceController extends TimerTask {
private static final long THRESHOLD = 3 * INTERVAL;
private Timer timer = new Timer("EngineInstanceController", true);
- @Inject
+ @Autowired
private EngineEntityService engineEntityService;
@PostConstruct
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java
deleted file mode 100644
index a9be49f..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt.db;
-
-import java.util.List;
-
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.CorrelationRule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.BindBean;
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@Service
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
- protected abstract String addRule(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
- protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
- protected abstract int deleteRuleByRid(@Bind("rid") String rid);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
- protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE")
- protected abstract List<CorrelationRule> queryAllRules();
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
- protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
- public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
-
- public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
- return queryRuleByEngineInstance(enginetype);
- }
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
-
-
- private void deleteRule2DbInner(CorrelationRule correlationRule) {
- String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
- String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
- if (!"".equals(name) && !"".equals(rid)) {
- deleteRuleByRidAndName(rid, name);
- } else if (!"".equals(rid)) {
- deleteRuleByRid(rid);
- }
- }
-
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- addRule(correlationRule);
- return correlationRule;
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- updateRuleByRid(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- deleteRule2DbInner(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
-
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
- try {
- return queryRuleById(rid);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
- try {
- return queryRuleByName(name);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-}
-
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java
index 104f74d..9658ded 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,31 +15,28 @@
*/
package org.onap.holmes.rulemgt.db;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.statement.Query;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
@Service
@Slf4j
-public class CorrelationRuleQueryDao {
+public class CorrelationRuleQueryService {
- @Inject
- private DbDaoUtil dbDaoUtil;
+ @Autowired
+ private Jdbi jdbi;
public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
throws CorrelationException {
@@ -48,9 +45,9 @@ public class CorrelationRuleQueryDao {
String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
try {
StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);
- handle = dbDaoUtil.getHandle();
+ handle = jdbi.open();
Query query = handle.createQuery(querySql.toString());
- for (Object value : query.list()) {
+ for (Object value : query.mapToMap().list()) {
CorrelationRule correlationRule = getCorrelationRule((Map) value);
correlationRules.add(correlationRule);
}
@@ -59,7 +56,7 @@ public class CorrelationRuleQueryDao {
log.warn("Failed to query the rule: id =" + ruleQueryCondition.getRid() + ".");
throw new CorrelationException("Failed to query the rule.", e);
} finally {
- dbDaoUtil.close(handle);
+ handle.close();
}
}
@@ -69,19 +66,19 @@ public class CorrelationRuleQueryDao {
correlationRule.setRid((String) value.get("rid"));
correlationRule.setDescription((String) value.get("description"));
correlationRule.setEnabled((Integer) value.get("enable"));
- correlationRule.setTemplateID((Long) value.get("templateID"));
- correlationRule.setEngineID((String) value.get("engineID"));
- correlationRule.setEngineType((String) value.get("engineType"));
+ correlationRule.setTemplateID((Long) value.get("templateid"));
+ correlationRule.setEngineID((String) value.get("engineid"));
+ correlationRule.setEngineType((String) value.get("enginetype"));
correlationRule.setCreator((String) value.get("creator"));
- correlationRule.setCreateTime((Date) value.get("createTime"));
+ correlationRule.setCreateTime((Date) value.get("createtime"));
correlationRule.setModifier((String) value.get("updator"));
- correlationRule.setUpdateTime((Date) value.get("updateTime"));
+ correlationRule.setUpdateTime((Date) value.get("updatetime"));
correlationRule.setParams((Properties) value.get("params"));
correlationRule.setContent((String) value.get("content"));
correlationRule.setVendor((String) value.get("vendor"));
correlationRule.setPackageName((String) value.get("package"));
correlationRule.setClosedControlLoopName((String) value.get("ctrlloop"));
- correlationRule.setEngineInstance((String) value.get("engineInstance"));
+ correlationRule.setEngineInstance((String) value.get("engineinstance"));
return correlationRule;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java
new file mode 100644
index 0000000..62eae0c
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2021-2022 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CorrelationRuleService {
+
+ @Autowired
+ private CorrelationRuleDao correlationRuleDao;
+
+ public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
+ return correlationRuleDao.queryRuleByEngineInstance(enginetype);
+ }
+
+ public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
+ return correlationRuleDao.queryRuleByEnable(enable);
+ }
+
+
+ private void deleteRule2DbInner(CorrelationRule correlationRule) {
+ String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
+ String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
+ if (!StringUtils.EMPTY.equals(name) && !StringUtils.EMPTY.equals(rid)) {
+ correlationRuleDao.deleteRuleByRidAndName(rid, name);
+ } else if (!"".equals(rid)) {
+ correlationRuleDao.deleteRuleByRid(rid);
+ }
+ }
+
+ public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ correlationRuleDao.addRule(correlationRule);
+ return correlationRule;
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ correlationRuleDao.updateRuleByRid(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ deleteRule2DbInner(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+
+ public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
+ try {
+ return correlationRuleDao.queryRuleById(rid);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
+ try {
+ return correlationRuleDao.queryRuleByName(name);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java
new file mode 100644
index 0000000..6addf0f
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db;
+
+import org.jdbi.v3.core.Jdbi;
+import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class DaoProvider {
+
+ @Bean
+ public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) {
+ return jdbi.onDemand(CorrelationRuleDao.class);
+ }
+}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java
new file mode 100644
index 0000000..2ad1d17
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2017-2021 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.rulemgt.db.jdbi;
+
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.customizer.BindBean;
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.utils.CorrelationRuleMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
+ String addRule(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
+ int updateRuleByRid(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
+ int deleteRuleByRid(@Bind("rid") String rid);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
+ int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE")
+ List<CorrelationRule> queryAllRules();
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
+ CorrelationRule queryRuleById(@Bind("rid") String rid);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
+ CorrelationRule queryRuleByName(@Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
+ List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
+ List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
+}
+
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
index 8423f3d..fc042ad 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2021 ZTE Corporation.
+ * Copyright 2021-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.onap.holmes.common.ConfigFileScanner;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.FileUtils;
@@ -31,8 +31,8 @@ import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
deleted file mode 100644
index 8049e8f..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright 2017-2021 ZTE Corporation.
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.onap.holmes.rulemgt.dcae;
-
-
-import lombok.extern.slf4j.Slf4j;
-import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
-import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
-import org.onap.holmes.common.dcae.entity.Rule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.JerseyClient;
-import org.onap.holmes.common.utils.Md5Util;
-import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
-import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
-import java.util.List;
-
-@Slf4j
-@Deprecated
-public class DcaeConfigurationPolling implements Runnable {
-
- public static final long POLLING_PERIOD = 30 * 1000L;
-
- private String hostname;
-
- private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
-
- public DcaeConfigurationPolling(String hostname) {
- this.hostname = hostname;
- }
-
- private String prevConfigMd5 = Md5Util.md5(null);
-
- private boolean prevResult = false;
-
- @Override
- public void run() {
- DcaeConfigurations dcaeConfigurations = null;
- try {
- dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
- String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevResult && prevConfigMd5.equals(md5)) {
- log.info("Operation aborted due to identical configurations.");
- return;
- }
- prevConfigMd5 = md5;
- prevResult = false;
- } catch (CorrelationException e) {
- log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
- } catch (Exception e) {
- log.info("Failed to generate the MD5 information for new configurations.", e);
- }
- RuleQueryListResponse ruleQueryListResponse = null;
- if (dcaeConfigurations != null) {
- try {
- ruleQueryListResponse = getAllCorrelationRules();
- } catch (Exception e) {
- log.error("Failed to get deployed rules from the rule management module: " + e.getMessage(), e);
- }
- }
- if (ruleQueryListResponse != null) {
- List<RuleResult4API> ruleResult4APIs = ruleQueryListResponse.getCorrelationRules();
- deleteAllCorrelationRules(ruleResult4APIs);
- try {
- prevResult = addAllCorrelationRules(dcaeConfigurations);
- } catch (CorrelationException e) {
- log.error("Failed to add rules. " + e.getMessage(), e);
- prevResult = false;
- }
- }
- }
-
- private RuleQueryListResponse getAllCorrelationRules() {
- return JerseyClient.newInstance().get(url, RuleQueryListResponse.class);
- }
-
- private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations) throws CorrelationException {
- boolean suc = false;
- for (Rule rule : dcaeConfigurations.getDefaultRules()) {
- RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule);
- suc = JerseyClient.newInstance().header("Accept", MediaType.APPLICATION_JSON)
- .put(url, Entity.json(ruleCreateRequest)) != null;
-
- if (!suc) {
- break;
- }
- }
- return suc;
- }
-
- private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) {
- ruleResult4APIs.forEach(correlationRule -> {
- if (null == JerseyClient.newInstance().delete(url + "/" + correlationRule.getRuleId())) {
- log.warn("Failed to delete rule, the rule id is: {}", correlationRule.getRuleId());
- }
- });
- }
-
- private RuleCreateRequest getRuleCreateRequest(Rule rule) {
- RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
- ruleCreateRequest.setLoopControlName(rule.getLoopControlName());
- ruleCreateRequest.setRuleName(rule.getName());
- ruleCreateRequest.setContent(rule.getContents());
- ruleCreateRequest.setDescription("");
- ruleCreateRequest.setEnabled(1);
- return ruleCreateRequest;
- }
-}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
index 73d1c5b..c8befef 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,24 +19,23 @@ package org.onap.holmes.rulemgt.resources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.SwaggerDefinition;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Service
+@RestController
@SwaggerDefinition
-@Path("/healthcheck")
+@RequestMapping("/healthcheck")
@Api(tags = {"Health Check"})
@Produces(MediaType.TEXT_PLAIN)
@Slf4j
public class HealthCheck {
- @GET
- @Produces(MediaType.TEXT_PLAIN)
+ @GetMapping(produces = MediaType.TEXT_PLAIN)
@ApiOperation(value = "Interface for the health check of the rule management module for Holmes")
- public boolean healthCheck(){
- return true;
+ public void healthCheck(){
+
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
index 445c2f9..133e859 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
@@ -1,11 +1,11 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
- *
+ * Copyright 2017-2022 ZTE Corporation.
+ * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
@@ -13,17 +13,15 @@
*/
package org.onap.holmes.rulemgt.resources;
-import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
import org.onap.holmes.common.utils.GsonUtil;
-import org.onap.holmes.common.utils.LanguageUtil;
import org.onap.holmes.common.utils.UserUtil;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
@@ -33,37 +31,33 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
-import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import java.util.Locale;
-@Service
+@Slf4j
+@RestController
@SwaggerDefinition
-@Path("/rule")
+@RequestMapping("/rule")
@Api(tags = {"Holmes Rule Management"})
-@Produces(MediaType.APPLICATION_JSON)
-@Slf4j
public class RuleMgtResources {
- @Inject
+ @Autowired
private RuleMgtWrapper ruleMgtWrapper;
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PutMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",
response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
- + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
- + "and \"description\"(optional)", required = true)
- RuleCreateRequest ruleCreateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse addCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
+ + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
+ + "and \"description\"(optional)", required = true)
+ @RequestBody RuleCreateRequest ruleCreateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -76,16 +70,14 @@ public class RuleMgtResources {
}
}
- @POST
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PostMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
- RuleUpdateRequest ruleUpdateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse updateCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ @RequestBody RuleUpdateRequest ruleUpdateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -98,38 +90,31 @@ public class RuleMgtResources {
}
}
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
+ @DeleteMapping("/{ruleid}")
@ApiOperation(value = "Remove a rule from Holmes.")
- @Timed
- @Path("/{ruleid}")
- public boolean deleteCorrelationRule(@Context HttpServletRequest request,
- @PathParam("ruleid") String ruleId) {
- Locale locale = LanguageUtil.getLocale(request);
+ public ResponseEntity deleteCorrelationRule(@PathVariable("ruleid") String ruleId) {
try {
ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));
log.info("delete rule:" + ruleId + " successful");
- return true;
+ return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
} catch (CorrelationException e) {
log.error("delete rule:" + ruleId + " failed", e);
throw ExceptionUtil.buildExceptionResponse(e.getMessage());
}
}
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
- @Timed
- public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value =
- "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
- + "\"rulename\"(optional), \"creator\"(optional), "
- + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
- required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleQueryListResponse getCorrelationRules(
+ @ApiParam(value =
+ "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
+ + "\"rulename\"(optional), \"creator\"(optional), "
+ + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}")
+ @RequestParam(value = "queryrequest", required = false) String ruleQueryRequest) {
RuleQueryListResponse ruleQueryListResponse;
- RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
+ RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest);
try {
ruleQueryListResponse = ruleMgtWrapper
.getCorrelationRuleByCondition(ruleQueryCondition);
@@ -141,9 +126,7 @@ public class RuleMgtResources {
}
}
- private RuleQueryCondition getRuleQueryCondition(String queryRequest,
- HttpServletRequest request) {
- Locale locale = LanguageUtil.getLocale(request);
+ private RuleQueryCondition getRuleQueryCondition(String queryRequest) {
RuleQueryCondition ruleQueryCondition = GsonUtil
.jsonToBean(queryRequest, RuleQueryCondition.class);
if (queryRequest == null) {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
index 83555b2..74996e5 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,26 +16,23 @@
package org.onap.holmes.rulemgt.resources;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.SwaggerDefinition;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-@Service
-@Path("/swagger.json")
-@Produces(MediaType.APPLICATION_JSON)
+@RestController
+@RequestMapping("/swagger.json")
@Slf4j
public class SwaggerResource {
- @GET
+ @GetMapping
@Produces(MediaType.APPLICATION_JSON)
public String getSwaggerJson() {
URL url = SwaggerResource.class.getResource("/swagger.json");
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
index 2711d3b..f350c12 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,25 @@
package org.onap.holmes.rulemgt.tools;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
-import javax.inject.Inject;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;
-@Service
+@Component
@Slf4j
public class EngineTools {
- @Inject
+ @Autowired
private RuleQueryWrapper ruleQueryWrapper;
- @Inject
+ @Autowired
private EngineEntityService engineEntityService;
public List<String> getInstanceList() {
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 7fdae27..ec6e9b3 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
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,58 +15,44 @@
*/
package org.onap.holmes.rulemgt.wrapper;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
-import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.onap.holmes.rulemgt.bean.request.*;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
@Service
-@Singleton
@Slf4j
public class RuleMgtWrapper {
- @Inject
+ @Autowired
private EngineTools engineTools;
- @Inject
+ @Autowired
private RuleQueryWrapper ruleQueryWrapper;
- @Inject
- private CorrelationRuleQueryDao correlationRuleQueryDao;
- @Inject
- private EngineWrapper engineWarpper;
- @Inject
- private DbDaoUtil daoUtil;
+ @Autowired
+ private CorrelationRuleQueryService correlationRuleQueryDao;
- private CorrelationRuleDao correlationRuleDao;
+ @Autowired
+ private EngineWrapper engineWarpper;
- @PostConstruct
- public void initDaoUtil() {
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
- }
+ @Autowired
+ private CorrelationRuleService correlationRuleService;
public RuleAddAndUpdateResponse addCorrelationRule(String creator, RuleCreateRequest ruleCreateRequest)
throws CorrelationException {
@@ -76,7 +62,7 @@ public class RuleMgtWrapper {
CorrelationRule correlationRule = convertCreateRequest2Rule(creator,
ruleCreateRequest);
validateCorrelationRule(correlationRule);
- CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName());
+ CorrelationRule ruleTemp = correlationRuleService.queryRuleByRuleName(correlationRule.getName());
if (ruleTemp != null) {
throw new CorrelationException("A rule with the same name already exists.");
}
@@ -91,7 +77,7 @@ public class RuleMgtWrapper {
correlationRule.setEngineInstance(ip);
CorrelationRule result = null;
try {
- result = correlationRuleDao.saveRule(correlationRule);
+ result = correlationRuleService.saveRule(correlationRule);
} catch (CorrelationException e) {
engineWarpper.deleteRuleFromEngine(packageName, ip);
throw new CorrelationException(e.getMessage(), e);
@@ -106,7 +92,7 @@ public class RuleMgtWrapper {
if (ruleUpdateRequest == null) {
throw new CorrelationException("The request object can not be empty!");
}
- CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId());
+ CorrelationRule oldCorrelationRule = correlationRuleService.queryRuleByRid(ruleUpdateRequest.getRuleId());
if (oldCorrelationRule == null) {
throw new CorrelationException("You're trying to update a rule which does not exist in the system.");
}
@@ -131,7 +117,7 @@ public class RuleMgtWrapper {
engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName(), engineInstance);
}
newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule, updateIp));
- correlationRuleDao.updateRule(newCorrelationRule);
+ correlationRuleService.updateRule(newCorrelationRule);
return ruleChangeResponse;
}
@@ -172,7 +158,7 @@ public class RuleMgtWrapper {
if (ruleDeleteRequest == null) {
throw new CorrelationException("The request object can not be empty!");
}
- CorrelationRule correlationRule = correlationRuleDao.queryRuleByRid(ruleDeleteRequest.getRuleId());
+ CorrelationRule correlationRule = correlationRuleService.queryRuleByRid(ruleDeleteRequest.getRuleId());
if (correlationRule == null) {
log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId() + " does not exist the database.");
throw new CorrelationException("You're trying to delete a rule which does not exist in the system.");
@@ -181,7 +167,7 @@ public class RuleMgtWrapper {
String ip = correlationRule.getEngineInstance();
engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName(), ip);
}
- correlationRuleDao.deleteRule(correlationRule);
+ correlationRuleService.deleteRule(correlationRule);
}
private CorrelationRule convertCreateRequest2Rule(String userName,
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
index 0ad836f..1d245f8 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
@@ -16,37 +16,28 @@
package org.onap.holmes.rulemgt.wrapper;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.List;
@Service
public class RuleQueryWrapper {
- @Inject
- private DbDaoUtil daoUtil;
- private CorrelationRuleDao correlationRuleDao;
+ @Autowired
+ private CorrelationRuleService correlationRuleService;
- @PostConstruct
- public void initDaoUtil() {
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
- }
- public List<CorrelationRule> queryRuleByEnable(int enable) throws CorrelationException {
- List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleEnable(enable);
+ public List<CorrelationRule> queryRuleByEnable(int enable) {
+ List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEnable(enable);
return ruleTemp;
}
public List<CorrelationRule> queryRuleByEngineInstance(String instance) throws CorrelationException {
- List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleEngineInstance(instance);
+ List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEngineInstance(instance);
return ruleTemp;
}
}