summaryrefslogtreecommitdiffstats
path: root/engine-d
diff options
context:
space:
mode:
Diffstat (limited to 'engine-d')
-rw-r--r--engine-d/pom.xml60
-rw-r--r--engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java14
-rw-r--r--engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java8
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java32
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/EngineDAppConfig.java51
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/Initializer.java22
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java (renamed from engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java)132
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java35
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java37
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java43
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java (renamed from engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java)29
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/dcae/ConfigFileScanningTask.java8
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/dcae/DcaeConfigurationPolling.java15
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPolling.java13
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/dmaap/SubscriberAction.java33
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java40
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java8
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/request/CompileRuleRequest.java11
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/request/DeployRuleRequest.java14
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/request/DmaapConfigRequest.java3
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java52
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java92
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/resources/HealthCheck.java23
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/resources/SwaggerResource.java24
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/response/CorrelationRuleResponse.java8
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java27
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/wrapper/RuleMgtWrapper.java30
-rw-r--r--engine-d/src/main/resources/logback-spring.xml59
-rw-r--r--engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java1
-rw-r--r--engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java26
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java60
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java5
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java14
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java1
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java19
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java33
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java156
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java33
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java29
39 files changed, 656 insertions, 644 deletions
diff --git a/engine-d/pom.xml b/engine-d/pom.xml
index 6fc236f..1ff46dc 100644
--- a/engine-d/pom.xml
+++ b/engine-d/pom.xml
@@ -22,13 +22,17 @@
<parent>
<groupId>org.onap.holmes.engine-management</groupId>
<artifactId>holmes-engine-parent</artifactId>
- <version>1.3.7-SNAPSHOT</version>
+ <version>1.3.8-SNAPSHOT</version>
</parent>
<artifactId>holmes-engine-d</artifactId>
<name>holmes-engine-d-service</name>
<packaging>jar</packaging>
+ <properties>
+ <main-class>org.onap.holmes.engine.EngineDActiveApp</main-class>
+ </properties>
+
<build>
<resources>
<resource>
@@ -39,8 +43,61 @@
</resource>
<resource>
<directory>src/main/resources</directory>
+ <excludes>
+ <exclude>swagger.json</exclude>
+ </excludes>
</resource>
</resources>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${springboot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>${main-class}</mainClass>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <source>8</source>
+ <target>8</target>
+ <release>11</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco.version}</version>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
</build>
<profiles>
@@ -53,7 +110,6 @@
<version>1.5.0</version>
</dependency>
</dependencies>
-
<build>
<plugins>
<plugin>
diff --git a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
index 394dc08..4abf296 100644
--- a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
+++ b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
@@ -15,22 +15,18 @@
*/
package org.onap.holmes.dsa.dmaappolling;
+import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.api.stat.AlarmAdditionalField;
-import com.google.gson.Gson;
+import org.onap.holmes.common.api.stat.VesAlarm;
+import org.springframework.stereotype.Component;
-import java.util.Map;
-import java.util.TimeZone;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
import static org.onap.holmes.common.utils.GsonUtil.*;
-@Service
+@Component
public class DMaaPResponseUtil {
public VesAlarm convertJsonToVesAlarm(String responseJson) {
diff --git a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java
index af772fb..4fd52ef 100644
--- a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java
+++ b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.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.
@@ -20,11 +20,10 @@ import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.JerseyClient;
+import org.onap.holmes.common.utils.SpringContextUtil;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -34,8 +33,7 @@ import java.util.UUID;
@Slf4j
public class Subscriber {
- private DMaaPResponseUtil dMaaPResponseUtil = ServiceLocatorHolder.getLocator()
- .getService(DMaaPResponseUtil.class);
+ private DMaaPResponseUtil dMaaPResponseUtil = SpringContextUtil.getBean(DMaaPResponseUtil.class);
/**
* The number of milliseconds to wait for messages if none are immediately available. This
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
index b1cc335..f5d6d8a 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.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,40 +15,36 @@
*/
package org.onap.holmes.engine;
-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.engine.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;
@Slf4j
-public class EngineDActiveApp extends IOCApplication<EngineDAppConfig> {
-
- public static void main(String[] args) throws Exception {
- new EngineDActiveApp().run(args);
+@SpringBootApplication
+@ServletComponentScan
+@ComponentScan(basePackages = {"org.onap.holmes"})
+public class EngineDActiveApp implements ApplicationRunner {
+ public static void main(String[] args) {
+ SpringApplication.run(EngineDActiveApp.class, args);
}
@Override
- public void run(EngineDAppConfig 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("logFilter", new TransactionIdFilter()).addMappingForUrlPatterns(EnumSet
- .allOf(DispatcherType.class), true, "/*");
-
Initializer.setReadyForMsbReg(true);
}
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/EngineDAppConfig.java b/engine-d/src/main/java/org/onap/holmes/engine/EngineDAppConfig.java
deleted file mode 100644
index 836912f..0000000
--- a/engine-d/src/main/java/org/onap/holmes/engine/EngineDAppConfig.java
+++ /dev/null
@@ -1,51 +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.engine;
-
-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.jvnet.hk2.annotations.Service;
-
-@Service
-public class EngineDAppConfig extends Configuration {
-
- 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/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java b/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java
index 4474fec..60869a1 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/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.engine;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.MsbRegister;
@@ -24,32 +23,33 @@ 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.config.MicroServiceConfig.getMicroServiceIpAndPort;
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_ENGINE_MGMT_SERVICE_HOST"));
node.setPort("9102");
/* 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/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java
index 83fa3f6..5c3444e 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDao.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/AlarmInfoDaoService.java
@@ -1,70 +1,62 @@
-/**
- * Copyright 2017 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.engine.db;
-
-import org.onap.holmes.common.api.entity.AlarmInfo;
-import org.onap.holmes.common.exception.AlarmInfoException;
-import org.onap.holmes.common.utils.AlarmInfoMapper;
-import org.skife.jdbi.v2.sqlobject.*;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-import java.util.List;
-
-@RegisterMapper(AlarmInfoMapper.class)
-public abstract class AlarmInfoDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,SEQUENCE,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:sequence,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")
- protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);
-
- @SqlQuery("SELECT * FROM ALARM_INFO")
- protected abstract List<AlarmInfo> queryAlarm();
-
- @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")
- protected abstract int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,
- @Bind("sourceId") String sourceId,
- @Bind("sourceName") String sourceName);
-
- public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
- try {
- addAlarm(alarmInfo);
- return alarmInfo;
- } catch (Exception e) {
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
- try {
- return queryAlarm();
- } catch (Exception e) {
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteAlarm(AlarmInfo alarmInfo) {
- if (alarmInfo.getAlarmIsCleared() != 1) {
- return;
- }
-
- String sourceId = alarmInfo.getSourceId();
- String sourceName = alarmInfo.getSourceName();
- String eventName = alarmInfo.getEventName();
- eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
-
- deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);
- }
-}
+/**
+ * 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.
+ * 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.engine.db;
+
+import org.onap.holmes.common.api.entity.AlarmInfo;
+import org.onap.holmes.common.exception.AlarmInfoException;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+
+public class AlarmInfoDaoService {
+
+ @Autowired
+ private AlarmInfoDao alarmInfoDao;
+
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
+ try {
+ alarmInfoDao.addAlarm(alarmInfo);
+ return alarmInfo;
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
+ try {
+ return alarmInfoDao.queryAlarm();
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void deleteAlarm(AlarmInfo alarmInfo) {
+ if (alarmInfo.getAlarmIsCleared() != 1) {
+ return;
+ }
+
+ String sourceId = alarmInfo.getSourceId();
+ String sourceName = alarmInfo.getSourceName();
+ String eventName = alarmInfo.getEventName();
+ eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
+
+ alarmInfoDao.deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java b/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java
new file mode 100644
index 0000000..a80a255
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDaoService.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 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.engine.db;
+
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.engine.db.jdbi.CorrelationRuleDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CorrelationRuleDaoService {
+
+ @Autowired
+ private CorrelationRuleDao correlationRuleDao;
+
+ public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
+ return correlationRuleDao.queryRuleByEnable(enable);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java b/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java
new file mode 100644
index 0000000..3a52fd0
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/DaoProvider.java
@@ -0,0 +1,37 @@
+/**
+ * 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.engine.db;
+
+import org.jdbi.v3.core.Jdbi;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
+import org.onap.holmes.engine.db.jdbi.CorrelationRuleDao;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class DaoProvider {
+
+ @Bean
+ public AlarmInfoDao alarmInfoDao(Jdbi jdbi) {
+ return jdbi.onDemand(AlarmInfoDao.class);
+ }
+
+ @Bean
+ public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) {
+ return jdbi.onDemand(CorrelationRuleDao.class);
+ }
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java
new file mode 100644
index 0000000..e4b2f1a
--- /dev/null
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/AlarmInfoDao.java
@@ -0,0 +1,43 @@
+/**
+ * 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 the License.
+ */
+package org.onap.holmes.engine.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.AlarmInfo;
+import org.onap.holmes.common.utils.AlarmInfoMapper;
+
+import java.util.List;
+
+@RegisterRowMapper(AlarmInfoMapper.class)
+public interface AlarmInfoDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO ALARM_INFO (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,SEQUENCE,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:sequence,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")
+ String addAlarm(@BindBean AlarmInfo alarmInfo);
+
+ @SqlQuery("SELECT * FROM ALARM_INFO")
+ List<AlarmInfo> queryAlarm();
+
+ @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")
+ int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,
+ @Bind("sourceId") String sourceId,
+ @Bind("sourceName") String sourceName);
+}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java
index 8cd61ef..bb0f128 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/db/CorrelationRuleDao.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/db/jdbi/CorrelationRuleDao.java
@@ -1,37 +1,32 @@
/**
* Copyright 2017 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.engine.db;
+package org.onap.holmes.engine.db.jdbi;
-import java.util.List;
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
+import java.util.List;
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
@SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
+ public List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/dcae/ConfigFileScanningTask.java b/engine-d/src/main/java/org/onap/holmes/engine/dcae/ConfigFileScanningTask.java
index 15cb327..85e4a74 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/dcae/ConfigFileScanningTask.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/dcae/ConfigFileScanningTask.java
@@ -20,14 +20,15 @@ import org.onap.holmes.common.ConfigFileScanner;
import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.Md5Util;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
import org.onap.holmes.engine.dmaap.SubscriberAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.HashMap;
import java.util.Map;
public class ConfigFileScanningTask implements Runnable {
@@ -35,7 +36,7 @@ public class ConfigFileScanningTask implements Runnable {
final private static Logger LOGGER = LoggerFactory.getLogger(ConfigFileScanningTask.class);
private String configFile = "/opt/hemtopics/cfy.json";
private ConfigFileScanner configFileScanner;
- private String prevConfigMd5 = Md5Util.md5(null);
+ private String prevConfigMd5 = Md5Util.md5(new HashMap<String, String>());
public ConfigFileScanningTask(ConfigFileScanner configFileScanner) {
this.configFileScanner = configFileScanner;
@@ -76,8 +77,7 @@ public class ConfigFileScanningTask implements Runnable {
}
private void addSubscribers(DcaeConfigurations dcaeConfigurations) {
- SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
- .getService(SubscriberAction.class);
+ SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class);
for (String key : dcaeConfigurations.getSubKeys()) {
Subscriber subscriber = new Subscriber();
subscriber.setTopic(key);
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/dcae/DcaeConfigurationPolling.java b/engine-d/src/main/java/org/onap/holmes/engine/dcae/DcaeConfigurationPolling.java
index 15d77d6..6009b20 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/dcae/DcaeConfigurationPolling.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/dcae/DcaeConfigurationPolling.java
@@ -1,12 +1,12 @@
/**
* 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -19,9 +19,9 @@ import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.Md5Util;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
import org.onap.holmes.engine.dmaap.SubscriberAction;
@@ -45,7 +45,7 @@ public class DcaeConfigurationPolling implements Runnable {
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevConfigMd5.equals(md5)){
+ if (prevConfigMd5.equals(md5)) {
log.info("Operation aborted due to identical Configurations.");
return;
}
@@ -62,8 +62,7 @@ public class DcaeConfigurationPolling implements Runnable {
}
private void addSubscribers(DcaeConfigurations dcaeConfigurations) {
- SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
- .getService(SubscriberAction.class);
+ SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class);
for (String key : dcaeConfigurations.getSubKeys()) {
Subscriber subscriber = new Subscriber();
subscriber.setTopic(key);
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPolling.java b/engine-d/src/main/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPolling.java
index e2ad89c..5e8da83 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPolling.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPolling.java
@@ -21,10 +21,9 @@ import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.exception.AlarmInfoException;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
import org.onap.holmes.engine.manager.DroolsEngine;
-import java.util.ArrayList;
import java.util.List;
@Slf4j
@@ -33,13 +32,13 @@ public class DMaaPAlarmPolling implements Runnable {
private Subscriber subscriber;
private DroolsEngine droolsEngine;
private volatile boolean isAlive = true;
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
- public DMaaPAlarmPolling(Subscriber subscriber, DroolsEngine droolsEngine, AlarmInfoDao alarmInfoDao) {
+ public DMaaPAlarmPolling(Subscriber subscriber, DroolsEngine droolsEngine, AlarmInfoDaoService alarmInfoDaoService) {
this.subscriber = subscriber;
this.droolsEngine = droolsEngine;
- this.alarmInfoDao = alarmInfoDao;
+ this.alarmInfoDaoService = alarmInfoDaoService;
}
public void run() {
@@ -51,9 +50,9 @@ public class DMaaPAlarmPolling implements Runnable {
try {
AlarmInfo alarmInfo = getAlarmInfo(vesAlarm);
if (alarmInfo.getAlarmIsCleared() != 1) {
- alarmInfoDao.saveAlarm(alarmInfo);
+ alarmInfoDaoService.saveAlarm(alarmInfo);
} else {
- alarmInfoDao.deleteAlarm(alarmInfo);
+ alarmInfoDaoService.deleteAlarm(alarmInfo);
}
droolsEngine.putRaisedIntoStream(vesAlarm);
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/dmaap/SubscriberAction.java b/engine-d/src/main/java/org/onap/holmes/engine/dmaap/SubscriberAction.java
index 1297f11..21f5961 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/dmaap/SubscriberAction.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/dmaap/SubscriberAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2021 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.
@@ -15,26 +15,31 @@
*/
package org.onap.holmes.engine.dmaap;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
+import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.utils.DbDaoUtil;
+import org.onap.holmes.common.database.DbDaoUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
import org.onap.holmes.engine.manager.DroolsEngine;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
-@Service
+@Component
@Slf4j
public class SubscriberAction {
- @Inject
+ @Autowired
private DroolsEngine droolsEngine;
- @Inject
+ @Autowired
private DbDaoUtil daoUtil;
+ @Autowired
+ private AlarmInfoDaoService alarmInfoDaoService;
+
private HashMap<String, DMaaPAlarmPolling> pollingTasks = new HashMap<>();
public synchronized void addSubscriber(Subscriber subscriber) {
@@ -44,7 +49,7 @@ public class SubscriberAction {
removeSubscriber(subscriber);
}
AlarmInfoDao alarmInfoDao = daoUtil.getJdbiDaoByOnDemand(AlarmInfoDao.class);
- DMaaPAlarmPolling pollingTask = new DMaaPAlarmPolling(subscriber, droolsEngine, alarmInfoDao);
+ DMaaPAlarmPolling pollingTask = new DMaaPAlarmPolling(subscriber, droolsEngine, alarmInfoDaoService);
Thread thread = new Thread(pollingTask);
thread.start();
pollingTasks.put(topic, pollingTask);
@@ -67,7 +72,7 @@ public class SubscriberAction {
public void stopPollingTasks() {
Iterator iterator = pollingTasks.entrySet().iterator();
while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry)iterator.next();
+ Map.Entry entry = (Map.Entry) iterator.next();
String key = (String) entry.getKey();
pollingTasks.get(key).stopTask();
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
index cbda858..5970b59 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
@@ -18,7 +18,6 @@ package org.onap.holmes.engine.manager;
import lombok.extern.slf4j.Slf4j;
import org.drools.compiler.kie.builder.impl.InternalKieModule;
import org.drools.core.util.StringUtils;
-import org.jvnet.hk2.annotations.Service;
import org.kie.api.KieServices;
import org.kie.api.builder.*;
import org.kie.api.builder.Message.Level;
@@ -37,14 +36,15 @@ import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.AlarmInfoException;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.common.utils.ExceptionUtil;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.onap.holmes.engine.wrapper.RuleMgtWrapper;
+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.ArrayList;
import java.util.List;
import java.util.Map;
@@ -52,15 +52,13 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Slf4j
-@Service
-public class DroolsEngine {
-
+@Component
+public class DroolsEngine implements ApplicationRunner {
private final static int ENABLE = 1;
private final Map<String, String> deployed = new ConcurrentHashMap<>();
private RuleMgtWrapper ruleMgtWrapper;
- private DbDaoUtil daoUtil;
private ClosedLoopControlNameCache closedLoopControlNameCache;
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
private KieServices ks = KieServices.Factory.get();
private ReleaseId releaseId = ks.newReleaseId("org.onap.holmes", "rules", "1.0.0-SNAPSHOT");
private ReleaseId compilationRelease = ks.newReleaseId("org.onap.holmes", "compilation", "1.0.0-SNAPSHOT");
@@ -68,24 +66,23 @@ public class DroolsEngine {
private KieSession session;
private String instanceIp;
- @Inject
- public void setRuleMgtWrapper(RuleMgtWrapper ruleMgtWrapper) {
- this.ruleMgtWrapper = ruleMgtWrapper;
+ @Autowired
+ public void setAlarmInfoDaoService(AlarmInfoDaoService alarmInfoDaoService) {
+ this.alarmInfoDaoService = alarmInfoDaoService;
}
- @Inject
- public void setDaoUtil(DbDaoUtil daoUtil) {
- this.daoUtil = daoUtil;
+ @Autowired
+ public void setRuleMgtWrapper(RuleMgtWrapper ruleMgtWrapper) {
+ this.ruleMgtWrapper = ruleMgtWrapper;
}
- @Inject
+ @Autowired
public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) {
this.closedLoopControlNameCache = closedLoopControlNameCache;
}
- @PostConstruct
- private void init() {
- alarmInfoDao = daoUtil.getJdbiDaoByOnDemand(AlarmInfoDao.class);
+ @Override
+ public void run(ApplicationArguments args) {
instanceIp = MicroServiceConfig.getMicroServiceIpAndPort()[0];
try {
log.info("Drools engine initializing...");
@@ -146,7 +143,7 @@ public class DroolsEngine {
}
public void syncAlarms() throws AlarmInfoException {
- alarmInfoDao.queryAllAlarm().forEach(alarmInfo -> putRaisedIntoStream(convertAlarmInfo2VesAlarm(alarmInfo)));
+ alarmInfoDaoService.queryAllAlarm().forEach(alarmInfo -> putRaisedIntoStream(convertAlarmInfo2VesAlarm(alarmInfo)));
}
public String deployRule(DeployRuleRequest rule) throws CorrelationException {
@@ -330,5 +327,4 @@ public class DroolsEngine {
Resource jarRes = ks.getResources().newByteArrayResource(jar);
return ks.getRepository().addKieModule(jarRes);
}
-
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java
index 0b15999..0e65a28 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java
@@ -16,22 +16,22 @@
package org.onap.holmes.engine.manager.status;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
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.Optional;
import java.util.Timer;
import java.util.TimerTask;
import static java.util.concurrent.TimeUnit.SECONDS;
-@Service
+@Component
public class EntityStatusRefreshTask extends TimerTask {
private static final Logger logger = LoggerFactory.getLogger(EntityStatusRefreshTask.class);
private final long INTERVAL = SECONDS.toMillis(15);
@@ -39,7 +39,7 @@ public class EntityStatusRefreshTask extends TimerTask {
private Timer timer = new Timer("EntityStatusRefreshTimer", true);
private EngineEntityService engineEntityService;
- @Inject
+ @Autowired
public EntityStatusRefreshTask(EngineEntityService engineEntityService) {
this.engineEntityService = engineEntityService;
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/request/CompileRuleRequest.java b/engine-d/src/main/java/org/onap/holmes/engine/request/CompileRuleRequest.java
index b38ee5f..1baa8ad 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/request/CompileRuleRequest.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/request/CompileRuleRequest.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,10 +15,11 @@
*/
package org.onap.holmes.engine.request;
-import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
+import javax.validation.constraints.NotNull;
+
@Getter
@Setter
public class CompileRuleRequest {
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/request/DeployRuleRequest.java b/engine-d/src/main/java/org/onap/holmes/engine/request/DeployRuleRequest.java
index f2ef369..3e1b6ca 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/request/DeployRuleRequest.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/request/DeployRuleRequest.java
@@ -1,12 +1,12 @@
/**
- * 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.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,10 +15,11 @@
*/
package org.onap.holmes.engine.request;
-import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
+import javax.validation.constraints.NotNull;
+
@Getter
@Setter
public class DeployRuleRequest {
@@ -26,6 +27,7 @@ public class DeployRuleRequest {
@NotNull
private String content;
+ @NotNull
private String engineId;
@NotNull
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/request/DmaapConfigRequest.java b/engine-d/src/main/java/org/onap/holmes/engine/request/DmaapConfigRequest.java
index 6fa1928..ede1d71 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/request/DmaapConfigRequest.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/request/DmaapConfigRequest.java
@@ -16,10 +16,11 @@
package org.onap.holmes.engine.request;
-import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
+import javax.validation.constraints.NotNull;
+
@Getter
@Setter
public class DmaapConfigRequest {
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java
index 548b9b2..576170f 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.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.
@@ -18,45 +18,35 @@ package org.onap.holmes.engine.resources;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
import org.onap.holmes.common.dcae.entity.SecurityInfo;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
import org.onap.holmes.engine.dmaap.SubscriberAction;
import org.onap.holmes.engine.request.DmaapConfigRequest;
+import org.springframework.web.bind.annotation.*;
-@Service
@Slf4j
-//@Api(tags = {"DMaaP Configurations"})
-@Path("/dmaap")
+@RestController
+@RequestMapping("/dmaap")
public class DmaapConfigurationService {
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Subscribe to a new topic. "
+ "If the topic already exists, it is replaced with the new configuration.")
- @Path("/sub")
+ @RequestMapping(value = "/sub", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON)
public String addSubInfo(
- @ApiParam (value = "A JSON object with the fields named <b>name</b>"
- + " and <b>url</b>. Both fields are required.") DmaapConfigRequest config,
- @Context HttpServletRequest request){
+ @ApiParam(value = "A JSON object with the fields named <b>name</b>"
+ + " and <b>url</b>. Both fields are required.")
+ @RequestBody DmaapConfigRequest config) {
String url = config.getUrl();
if (url.startsWith("http://") || url.startsWith("https://")) {
Subscriber subscriber = new Subscriber();
subscriber.setTopic(config.getName());
subscriber.setUrl(url);
- SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
- .getService(SubscriberAction.class);
+ SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class);
subscriberAction.removeSubscriber(subscriber);
subscriberAction.addSubscriber(subscriber);
@@ -67,30 +57,26 @@ public class DmaapConfigurationService {
return "{\"message\": \"Only the HTTP or HTTPS protocol is supported!\"}";
}
- @DELETE
@Path("/sub/{topic}")
@ApiOperation(value = "Unsubscribe a topic from DMaaP.")
- @Produces(MediaType.APPLICATION_JSON)
- public String removeSubInfo(@PathParam("topic") String topic){
+ @RequestMapping(value = "/sub/{topic}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON)
+ public String removeSubInfo(@PathVariable("topic") String topic) {
Subscriber subscriber = new Subscriber();
subscriber.setTopic(topic);
- SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
- .getService(SubscriberAction.class);
+ SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class);
subscriberAction.removeSubscriber(subscriber);
return "{\"message\": \"Topic unsubscribed.\"}";
}
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/pub")
@ApiOperation(value = "Add/Update a publishing topic. "
+ "If the topic already exists, it is replaced with the new configuration.")
+ @RequestMapping(value = "/pub", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON)
public String updatePubInfo(
- @ApiParam (value = "A JSON object with the fields named <b>name</b>"
- + " and <b>url</b>. Both fields are required.") DmaapConfigRequest config,
- @Context HttpServletRequest request){
+ @ApiParam(value = "A JSON object with the fields named <b>name</b>"
+ + " and <b>url</b>. Both fields are required.")
+ @RequestBody DmaapConfigRequest config) {
String url = config.getUrl();
if (url.startsWith("http://") || url.startsWith("https://")) {
SecurityInfo securityInfo = new SecurityInfo();
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
index 0aa3a59..cb41533 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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.
@@ -16,64 +16,59 @@
package org.onap.holmes.engine.resources;
-import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
-import org.onap.holmes.common.utils.LanguageUtil;
import org.onap.holmes.engine.manager.DroolsEngine;
import org.onap.holmes.engine.request.CompileRuleRequest;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.onap.holmes.engine.response.CorrelationRuleResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+import jakarta.ws.rs.core.MediaType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-@Service
-@Path("/rule")
-@Api(tags = {"Holmes Engine Management"})
-@Produces(MediaType.APPLICATION_JSON)
@Slf4j
+@RestController
+@RequestMapping("/rule")
+@Api(tags = {"Holmes Engine Management"})
public class EngineResources {
- @Inject
- DroolsEngine droolsEngine;
- private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*");
+ private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*");
private ClosedLoopControlNameCache closedLoopControlNameCache;
+ private DroolsEngine droolsEngine;
+
+ @Autowired
+ public void setDroolsEngine(DroolsEngine droolsEngine) {
+ this.droolsEngine = droolsEngine;
+ }
- @Inject
+ @Autowired
public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) {
this.closedLoopControlNameCache = closedLoopControlNameCache;
}
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
- @Timed
+ @ResponseBody
+ @PutMapping(produces = MediaType.APPLICATION_JSON)
public CorrelationRuleResponse deployRule(
@ApiParam(value = "The request entity of the HTTP call, which comprises three "
+ "fields: \"content\" , \"loopControlName\" and \"engineId\". "
+ "The \"content\" should be a valid Drools rule string and the \"engineId\" "
- + "has to be \"engine-d\" in the Amsterdam release.", required = true) DeployRuleRequest deployRuleRequest,
- @Context HttpServletRequest httpRequest) {
+ + "has to be \"engine-d\" in the Amsterdam release.", required = true)
+ @RequestBody DeployRuleRequest deployRuleRequest) {
CorrelationRuleResponse crResponse = new CorrelationRuleResponse();
- Locale locale = LanguageUtil.getLocale(httpRequest);
try {
String packageName = getPackageName(deployRuleRequest.getContent());
- if(packageName == null) {
- throw new CorrelationException("Could not find package name in rule: "+deployRuleRequest.getContent());
+ if (packageName == null) {
+ throw new CorrelationException("Could not find package name in rule: " + deployRuleRequest.getContent());
}
-
+
closedLoopControlNameCache
.put(packageName, deployRuleRequest.getLoopControlName());
String packageNameRet = droolsEngine.deployRule(deployRuleRequest);
@@ -97,15 +92,8 @@ public class EngineResources {
return crResponse;
}
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- @Timed
- @Path("/{packageName}")
- public boolean undeployRule(@PathParam("packageName") String packageName,
- @Context HttpServletRequest httpRequest) {
-
- Locale locale = LanguageUtil.getLocale(httpRequest);
-
+ @DeleteMapping(value = "/{packageName}")
+ public void undeployRule(@PathVariable("packageName") String packageName) {
try {
droolsEngine.undeployRule(packageName);
closedLoopControlNameCache.remove(packageName);
@@ -113,36 +101,26 @@ public class EngineResources {
log.error(correlationException.getMessage(), correlationException);
throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());
}
-
- return true;
}
-
- @POST
+ @PostMapping
@ApiOperation(value = "Check the validity of a rule.")
- @Produces(MediaType.APPLICATION_JSON)
- @Timed
- public boolean compileRule(CompileRuleRequest compileRuleRequest,
- @Context HttpServletRequest httpRequest) {
-
- Locale locale = LanguageUtil.getLocale(httpRequest);
-
+ public void compileRule(@RequestBody CompileRuleRequest compileRuleRequest) {
try {
droolsEngine.compileRule(compileRuleRequest.getContent());
} catch (CorrelationException correlationException) {
log.error(correlationException.getMessage(), correlationException);
throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());
}
- return true;
}
-
- private String getPackageName(String contents){
+
+ private String getPackageName(String contents) {
Matcher m = packagePattern.matcher(contents);
-
- if (m.find( )) {
- return m.group(1);
- }else {
- return null;
+
+ if (m.find()) {
+ return m.group(1);
+ } else {
+ return null;
}
}
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/HealthCheck.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/HealthCheck.java
index c86bf06..44d238a 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/resources/HealthCheck.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/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,17 @@ package org.onap.holmes.engine.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 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
@ApiOperation(value = "Interface for the health check of the engine management module for Holmes")
- public boolean healthCheck(){
- return true;
+ public void healthCheck() {
}
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/SwaggerResource.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/SwaggerResource.java
index 6743b8e..494df77 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/resources/SwaggerResource.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/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,27 +16,25 @@
package org.onap.holmes.engine.resources;
+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 jakarta.ws.rs.core.MediaType;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
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)
@Slf4j
+@RestController
+@RequestMapping("/swagger.json")
public class SwaggerResource {
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
public String getSwaggerJson() {
URL url = SwaggerResource.class.getResource("/swagger.json");
String ret = "{}";
@@ -54,7 +52,7 @@ public class SwaggerResource {
return ret;
}
- try(BufferedReader br = new BufferedReader(new FileReader(file))) {
+ try (BufferedReader br = new BufferedReader(new FileReader(file))) {
StringBuffer buffer = new StringBuffer();
String line = " ";
while ((line = br.readLine()) != null) {
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/response/CorrelationRuleResponse.java b/engine-d/src/main/java/org/onap/holmes/engine/response/CorrelationRuleResponse.java
index 306bd7f..96913a2 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/response/CorrelationRuleResponse.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/response/CorrelationRuleResponse.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java b/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
index c7eb02b..19d6f38 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,12 +15,11 @@
*/
package org.onap.holmes.engine.utils;
+import org.onap.holmes.common.api.stat.Alarm;
+
import java.util.HashMap;
import java.util.Map;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.stat.Alarm;
-@Service
public class AlarmUtil {
private final static AlarmUtil alarmUtil = new AlarmUtil();
@@ -28,7 +27,7 @@ public class AlarmUtil {
* Map<ruleId, <ProbableCause-EquipType, priority>>
*/
private final Map<String, Map<String, Integer>> rootPriorityMap =
- new HashMap<String, Map<String, Integer>>();
+ new HashMap<String, Map<String, Integer>>();
/**
* Map<rule, ProbableCause+EquipType+priority>
*/
@@ -49,7 +48,7 @@ public class AlarmUtil {
String[] probableCauseStrs = probableCauseStr.replace(" ", "").split(",");
for (int i = 0; i < probableCauseStrs.length; i++) {
if (alarm.getProbableCause() == Long.parseLong(probableCauseStrs[i])
- && alarm.getEquipType().equals(equipTypes[i])) {
+ && alarm.getEquipType().equals(equipTypes[i])) {
return true;
}
}
@@ -57,10 +56,10 @@ public class AlarmUtil {
}
public Integer getPriority(String ruleId, String probableCauseStr, String rootAlarmFeatureStr,
- String equipTypeStr, Alarm alarm) {
+ String equipTypeStr, Alarm alarm) {
if (rootPriorityMap.containsKey(ruleId)) {
if (!saveRuleMsg.get(ruleId)
- .equals(probableCauseStr + equipTypeStr + rootAlarmFeatureStr)) {
+ .equals(probableCauseStr + equipTypeStr + rootAlarmFeatureStr)) {
setPriority(ruleId, probableCauseStr, rootAlarmFeatureStr, equipTypeStr);
}
} else {
@@ -68,7 +67,7 @@ public class AlarmUtil {
}
Integer priority =
- rootPriorityMap.get(ruleId).get(alarm.getProbableCause() + "-" + alarm.getEquipType());
+ rootPriorityMap.get(ruleId).get(alarm.getProbableCause() + "-" + alarm.getEquipType());
if (priority == null) {
priority = 0;
}
@@ -76,7 +75,7 @@ public class AlarmUtil {
}
private void setPriority(String ruleId, String probableCauseStr, String rootAlarmFeatureStr,
- String equipTypeStr) {
+ String equipTypeStr) {
saveRuleMsg.put(ruleId, probableCauseStr + equipTypeStr + rootAlarmFeatureStr);
Map<String, Integer> map = new HashMap<String, Integer>();
@@ -85,7 +84,7 @@ public class AlarmUtil {
String[] equipTypes = equipTypeStr.replace(" ", "").split(",");
for (int i = 0; i < rootAlarmFeatureStrs.length; i++) {
map.put(probableCauseStrs[i] + "-" + equipTypes[i],
- Integer.parseInt(rootAlarmFeatureStrs[i]));
+ Integer.parseInt(rootAlarmFeatureStrs[i]));
}
rootPriorityMap.put(ruleId, map);
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/wrapper/RuleMgtWrapper.java b/engine-d/src/main/java/org/onap/holmes/engine/wrapper/RuleMgtWrapper.java
index 1fbbfe7..08ec63e 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/wrapper/RuleMgtWrapper.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/wrapper/RuleMgtWrapper.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,29 +15,29 @@
*/
package org.onap.holmes.engine.wrapper;
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.engine.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.engine.db.CorrelationRuleDaoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
@Service
-@Singleton
@Slf4j
public class RuleMgtWrapper {
+ private CorrelationRuleDaoService correlationRuleDaoService;
- @Inject
- private DbDaoUtil daoUtil;
+ @Autowired
+ public RuleMgtWrapper(CorrelationRuleDaoService correlationRuleDaoService) {
+ this.correlationRuleDaoService = correlationRuleDaoService;
+ }
public List<CorrelationRule> queryRuleByEnable(int enable) throws CorrelationException {
- List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleEnable(enable);
+ List<CorrelationRule> ruleTemp = correlationRuleDaoService.queryRuleByRuleEnable(enable);
return ruleTemp;
}
}
diff --git a/engine-d/src/main/resources/logback-spring.xml b/engine-d/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..197057e
--- /dev/null
+++ b/engine-d/src/main/resources/logback-spring.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false">
+ <property name="LOG_HOME" value="/var/log/ONAP/holmes"/>
+ <property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss SSS} %-5p [%c][%t] - %msg%n" />
+
+ <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>${LOG_PATTERN}</pattern>
+ <charset>UTF-8</charset>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>debug</level>
+ </filter>
+ </appender>
+
+ <appender name="FileOutputForDebug" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${LOG_HOME}/holmes-engine-mgmt-debug.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${LOG_HOME}/archived/holmes-engine-mgmt-debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+ <maxHistory>15</maxHistory>
+ <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <maxFileSize>100MB</maxFileSize>
+ </timeBasedFileNamingAndTriggeringPolicy>
+ </rollingPolicy>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>${LOG_PATTERN}</pattern>
+ <charset>UTF-8</charset>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>info</level>
+ </filter>
+ </appender>
+
+ <appender name="FileOutputForError" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${LOG_HOME}/holmes-engine-mgmt-error.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${LOG_HOME}/archived/holmes-engine-mgmt-error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
+ <maxHistory>15</maxHistory>
+ <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <maxFileSize>10MB</maxFileSize>
+ </timeBasedFileNamingAndTriggeringPolicy>
+ </rollingPolicy>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>${LOG_PATTERN}</pattern>
+ <charset>UTF-8</charset>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>error</level>
+ <onMatch>deny</onMatch>
+ <onMismatch>accept</onMismatch>
+ </filter>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="Console" />
+ <appender-ref ref="FileOutputForDebug" />
+ <appender-ref ref="FileOutputForError" />
+ </root>
+</configuration> \ No newline at end of file
diff --git a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
index ded50b0..9f5fd0f 100644
--- a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
@@ -19,7 +19,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.powermock.core.classloader.annotations.PrepareForTest;
diff --git a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
index 339a23e..96794ce 100644
--- a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
@@ -15,25 +15,23 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import org.glassfish.hk2.api.ServiceLocator;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.JerseyClient;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
-import java.util.List;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import static org.easymock.EasyMock.*;
@@ -41,7 +39,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ServiceLocatorHolder.class, JerseyClient.class})
+@PrepareForTest({SpringContextUtil.class, JerseyClient.class})
@PowerMockIgnore("javax.net.ssl.*")
public class SubscriberTest {
@@ -52,10 +50,8 @@ public class SubscriberTest {
@Before
public void init() {
- PowerMock.mockStatic(ServiceLocatorHolder.class);
- ServiceLocator serviceLocator = PowerMock.createMock(ServiceLocator.class);
- expect(ServiceLocatorHolder.getLocator()).andReturn(serviceLocator).anyTimes();
- expect(serviceLocator.getService(DMaaPResponseUtil.class)).andReturn(util).anyTimes();
+ PowerMock.mockStatic(SpringContextUtil.class);
+ expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(util).anyTimes();
}
@Test
@@ -77,9 +73,9 @@ public class SubscriberTest {
vesAlarm.setStartEpochMicrosec(500L);
vesAlarm.setVersion("4.0");
Map alarmAdditionalFields = new HashMap<String, String>();
- alarmAdditionalFields.put("addInfo", "addInfo");
- vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
- vesAlarm.setAlarmCondition("alarmCondition");
+ alarmAdditionalFields.put("addInfo", "addInfo");
+ vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
+ vesAlarm.setAlarmCondition("alarmCondition");
vesAlarm.setAlarmInterfaceA("alarmInterfaceA");
vesAlarm.setEventCategory("eventCategory");
vesAlarm.setEventSeverity("eventSeverity");
@@ -161,9 +157,9 @@ public class SubscriberTest {
vesAlarm.setStartEpochMicrosec(500L);
vesAlarm.setVersion("4.0");
Map alarmAdditionalFields = new HashMap<String, String>();
- alarmAdditionalFields.put("addInfo", "addInfo");
- vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
- vesAlarm.setAlarmCondition("alarmCondition");
+ alarmAdditionalFields.put("addInfo", "addInfo");
+ vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
+ vesAlarm.setAlarmCondition("alarmCondition");
vesAlarm.setAlarmInterfaceA("alarmInterfaceA");
vesAlarm.setEventCategory("eventCategory");
vesAlarm.setEventSeverity("eventSeverity");
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java b/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java
deleted file mode 100644
index c550b37..0000000
--- a/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java
+++ /dev/null
@@ -1,60 +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.engine;
-
-import io.dropwizard.db.DataSourceFactory;
-import org.hamcrest.core.IsEqual;
-import org.hamcrest.core.IsNull;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.powermock.api.easymock.PowerMock;
-
-public class EnginedAppConfigTest {
-
- private EngineDAppConfig engineAppConfig;
-
- @Before
- public void setUp() {
- engineAppConfig = new EngineDAppConfig();
- }
-
- @Test
- public void getDataSourceFactory() {
- Assert.assertThat(engineAppConfig.getDataSourceFactory(), IsNull.<DataSourceFactory>notNullValue());
- }
-
- @Test
- public void setDataSourceFactory() {
- DataSourceFactory database = new DataSourceFactory();
- engineAppConfig.setDataSourceFactory(database);
- Assert.assertThat(engineAppConfig.getDataSourceFactory(), IsEqual.equalTo(database));
- }
-
- @Test
- public void getApidescription() {
- final String apidescription = "Holmes rule management rest API";
- Assert.assertThat(engineAppConfig.getApidescription(), IsEqual.equalTo(apidescription));
- }
-
- @Test
- public void setApidescription() {
- final String apidescription = "set api description";
- engineAppConfig.setApidescription(apidescription);
- Assert.assertThat(engineAppConfig.getApidescription(), IsEqual.equalTo(apidescription));
- }
-}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java b/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java
index 788c3ae..4dec23d 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2020 ZTE Corporation.
+ * Copyright 2020-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
@@ -23,7 +23,6 @@ import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.internal.WhiteboxImpl;
import java.util.concurrent.TimeUnit;
@@ -47,7 +46,7 @@ public class InitializerTest {
setReadyFlagAfter(3);
- WhiteboxImpl.invokeMethod(initializer, "init");
+ initializer.run(null);
TimeUnit.SECONDS.sleep(6);
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java b/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java
index 9945322..0eb9049 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.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.
@@ -17,15 +17,11 @@
package org.onap.holmes.engine.db;
import org.easymock.EasyMock;
-import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.holmes.common.api.entity.AlarmInfo;
-import org.onap.holmes.common.exception.AlarmInfoException;
import org.powermock.api.easymock.PowerMock;
import java.util.ArrayList;
@@ -34,20 +30,20 @@ import java.util.List;
public class AlarmInfoDaoTest {
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
@Before
public void setUp() {
- alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
+ alarmInfoDaoService = PowerMock.createMock(AlarmInfoDaoService.class);
}
@Test
public void queryAllAlarm() throws Exception {
- EasyMock.expect(alarmInfoDao.queryAllAlarm()).andReturn(new ArrayList<AlarmInfo>());
+ EasyMock.expect(alarmInfoDaoService.queryAllAlarm()).andReturn(new ArrayList<AlarmInfo>());
PowerMock.replayAll();
- List<AlarmInfo> alarmInfoList = alarmInfoDao.queryAllAlarm();
+ List<AlarmInfo> alarmInfoList = alarmInfoDaoService.queryAllAlarm();
PowerMock.verifyAll();
Assert.assertThat(alarmInfoList, IsNull.<List<AlarmInfo>>notNullValue());
}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java b/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
index 128f58a..01fb585 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
@@ -22,6 +22,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.engine.db.jdbi.CorrelationRuleDao;
import org.powermock.api.easymock.PowerMock;
import java.util.ArrayList;
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java b/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
index b663133..7f01aa4 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
@@ -17,15 +17,15 @@
package org.onap.holmes.engine.dcae;
import org.easymock.EasyMock;
-import org.glassfish.hk2.api.ServiceLocator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.onap.holmes.dsa.dmaappolling.DMaaPResponseUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
import org.onap.holmes.engine.dmaap.SubscriberAction;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@@ -33,16 +33,16 @@ import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
+@PrepareForTest({SpringContextUtil.class})
public class ConfigFileScanningTaskTest {
@Test
public void run() {
- ServiceLocator mockedSl = PowerMock.createMock(ServiceLocator.class);
+ PowerMock.mockStatic(SpringContextUtil.class);
SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
- ServiceLocatorHolder.setLocator(mockedSl);
- EasyMock.expect(mockedSl.getService(SubscriberAction.class)).andReturn(mockedSa);
+ EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
// This is invoked while executing new Subscriber().
- EasyMock.expect(mockedSl.getService(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
+ EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
EasyMock.expectLastCall();
@@ -60,13 +60,12 @@ public class ConfigFileScanningTaskTest {
@Test
public void run_config_not_changed() {
- ServiceLocator mockedSl = PowerMock.createMock(ServiceLocator.class);
+ PowerMock.mockStatic(SpringContextUtil.class);
SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
- ServiceLocatorHolder.setLocator(mockedSl);
// mocked objects will be only used once
- EasyMock.expect(mockedSl.getService(SubscriberAction.class)).andReturn(mockedSa);
+ EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
// This is invoked while executing new Subscriber().
- EasyMock.expect(mockedSl.getService(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
+ EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
EasyMock.expectLastCall();
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
index 74765f5..e809cd8 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
@@ -1,12 +1,12 @@
/**
- * 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.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,39 +15,40 @@
*/
package org.onap.holmes.engine.dmaap;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import java.lang.reflect.Field;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.holmes.common.api.entity.AlarmInfo;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
import org.onap.holmes.engine.manager.DroolsEngine;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-@PrepareForTest({Subscriber.class, DroolsEngine.class,DMaaPAlarmPolling.class})
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+@PrepareForTest({Subscriber.class, DroolsEngine.class, DMaaPAlarmPolling.class})
@RunWith(PowerMockRunner.class)
public class DMaaPAlarmPollingTest {
private DMaaPAlarmPolling dMaaPAlarmPolling;
private Subscriber subscriber;
private DroolsEngine droolsEngine;
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
@Before
public void setUp() {
subscriber = PowerMock.createMock(Subscriber.class);
droolsEngine = PowerMock.createMock(DroolsEngine.class);
- alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
- dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine,alarmInfoDao);
+ alarmInfoDaoService = PowerMock.createMock(AlarmInfoDaoService.class);
+ dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine, alarmInfoDaoService);
PowerMock.replayAll();
}
@@ -72,7 +73,7 @@ public class DMaaPAlarmPollingTest {
vesAlarm.setRootFlag(0);
PowerMock.replayAll();
- AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling,"getAlarmInfo",vesAlarm);
+ AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling, "getAlarmInfo", vesAlarm);
PowerMock.verifyAll();
assertThat(alarmInfo.getAlarmIsCleared(), is(1));
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java
index cb28faa..31f1817 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.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.
@@ -16,7 +16,6 @@
package org.onap.holmes.engine.manager;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -26,11 +25,10 @@ import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
+import org.onap.holmes.engine.db.CorrelationRuleDaoService;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.onap.holmes.engine.wrapper.RuleMgtWrapper;
-import org.powermock.api.easymock.PowerMock;
import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
@@ -47,33 +45,31 @@ public class DroolsEngineTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private RuleMgtWrapper ruleMgtWrapper;
+ private RuleMgtWrapper ruleMgtWrapperMock;
private DroolsEngine droolsEngine;
- private DbDaoUtil dbDaoUtilStub;
+ private AlarmInfoDaoService alarmInfoDaoServiceStub;
+
+ private CorrelationRuleDaoService correlationRuleDaoServiceStub;
private ClosedLoopControlNameCache closedLoopControlNameCache;
public DroolsEngineTest() throws Exception {
System.setProperty(MicroServiceConfig.HOSTNAME, "127.0.0.1:80");
droolsEngine = new DroolsEngine();
- ruleMgtWrapper = new RuleMgtWrapperStub();
- dbDaoUtilStub = new DbDaoUtilStub();
+ alarmInfoDaoServiceStub = new AlarmInfoDaoServiceStub();
+ droolsEngine.setAlarmInfoDaoService(alarmInfoDaoServiceStub);
+ correlationRuleDaoServiceStub = new CorrelationRuleDaoServiceStub();
+ ruleMgtWrapperMock = new RuleMgtWrapperStub(correlationRuleDaoServiceStub);
closedLoopControlNameCache = new ClosedLoopControlNameCache();
droolsEngine.setClosedLoopControlNameCache(closedLoopControlNameCache);
- droolsEngine.setDaoUtil(dbDaoUtilStub);
- droolsEngine.setRuleMgtWrapper(ruleMgtWrapper);
+ droolsEngine.setRuleMgtWrapper(ruleMgtWrapperMock);
- Whitebox.invokeMethod(droolsEngine, "init");
+ Whitebox.invokeMethod(droolsEngine, "run", null);
System.clearProperty(MicroServiceConfig.HOSTNAME);
}
- @Before
- public void setUp() throws Exception {
- PowerMock.resetAll();
- }
-
@Test
public void deployRule_rule_is_null() throws CorrelationException {
thrown.expect(NullPointerException.class);
@@ -241,78 +237,74 @@ public class DroolsEngineTest {
assertThat(packages.contains("packageCheck"), is(true));
}
-}
-
-class RuleMgtWrapperStub extends RuleMgtWrapper {
- private List<CorrelationRule> rules;
-
- public RuleMgtWrapperStub() {
- rules = new ArrayList<>();
- CorrelationRule rule = new CorrelationRule();
- rule.setEnabled(1);
- rule.setContent("package org.onap.holmes;");
- rule.setPackageName("UT");
- rule.setClosedControlLoopName(UUID.randomUUID().toString());
- rule.setEngineInstance("127.0.0.1");
- rules.add(rule);
- }
-
- public List<CorrelationRule> getRules() {
- return rules;
- }
-
- public void setRules(List<CorrelationRule> rules) {
- this.rules = rules;
- }
- @Override
- public List<CorrelationRule> queryRuleByEnable(int enabled) throws CorrelationException {
- return rules.stream().filter(rule -> rule.getEnabled() == enabled).collect(Collectors.toList());
+ class RuleMgtWrapperStub extends RuleMgtWrapper {
+ private List<CorrelationRule> rules;
+
+ public RuleMgtWrapperStub(CorrelationRuleDaoService correlationRuleDaoService) {
+ super(correlationRuleDaoService);
+ rules = new ArrayList<>();
+ CorrelationRule rule = new CorrelationRule();
+ rule.setEnabled(1);
+ rule.setContent("package org.onap.holmes;");
+ rule.setPackageName("UT");
+ rule.setClosedControlLoopName(UUID.randomUUID().toString());
+ rule.setEngineInstance("127.0.0.1");
+ rules.add(rule);
+ }
+
+ public List<CorrelationRule> getRules() {
+ return rules;
+ }
+
+ public void setRules(List<CorrelationRule> rules) {
+ this.rules = rules;
+ }
+
+ @Override
+ public List<CorrelationRule> queryRuleByEnable(int enabled) throws CorrelationException {
+ return rules.stream().filter(rule -> rule.getEnabled() == enabled).collect(Collectors.toList());
+ }
}
-}
-class AlarmInfoDaoStub extends AlarmInfoDao {
-
- private List<AlarmInfo> alarms;
-
- public AlarmInfoDaoStub() {
- alarms = new ArrayList<>();
- AlarmInfo info = new AlarmInfo();
- info.setEventId("eventId");
- info.setEventName("eventName");
- info.setStartEpochMicroSec(1L);
- info.setLastEpochMicroSec(1L);
- info.setSourceId("sourceId");
- info.setSourceName("sourceName");
- info.setRootFlag(0);
- info.setAlarmIsCleared(1);
- alarms.add(info);
+ class AlarmInfoDaoServiceStub extends AlarmInfoDaoService {
+
+ private List<AlarmInfo> alarms;
+
+ public AlarmInfoDaoServiceStub() {
+ alarms = new ArrayList<>();
+ AlarmInfo info = new AlarmInfo();
+ info.setEventId("eventId");
+ info.setEventName("eventName");
+ info.setStartEpochMicroSec(1L);
+ info.setLastEpochMicroSec(1L);
+ info.setSourceId("sourceId");
+ info.setSourceName("sourceName");
+ info.setRootFlag(0);
+ info.setAlarmIsCleared(1);
+ alarms.add(info);
+ }
+
+ @Override
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) {
+ alarms.add(alarmInfo);
+ return alarmInfo;
+ }
+
+ @Override
+ public List<AlarmInfo> queryAllAlarm() {
+ return alarms;
+ }
+
+ @Override
+ public void deleteAlarm(AlarmInfo alarmInfo) {
+
+ }
}
- @Override
- protected String addAlarm(AlarmInfo alarmInfo) {
- alarms.add(alarmInfo);
- return null;
- }
-
- @Override
- protected List<AlarmInfo> queryAlarm() {
- return alarms;
- }
+ class CorrelationRuleDaoServiceStub extends CorrelationRuleDaoService {
- @Override
- protected int deleteAlarmByAlarmIsCleared(String alarmName, String sourceName, String sourceId) {
- return 1;
}
}
-class DbDaoUtilStub extends DbDaoUtil {
- private AlarmInfoDao dao = new AlarmInfoDaoStub();
- @Override
- public <T> T getJdbiDaoByOnDemand(Class<T> daoClazz) {
-
- return (T) dao;
-
- }
-}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
index aa2052d..f4ad483 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
@@ -26,11 +26,8 @@ import org.onap.holmes.engine.manager.DroolsEngine;
import org.onap.holmes.engine.request.CompileRuleRequest;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.powermock.api.easymock.PowerMock;
-import org.powermock.reflect.Whitebox;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
-import java.util.Locale;
+import jakarta.ws.rs.WebApplicationException;
import static org.easymock.EasyMock.*;
@@ -47,23 +44,20 @@ public class EngineResourcesTest {
closedLoopControlNameCache = new ClosedLoopControlNameCache();
engineResources = new EngineResources();
engineResources.setClosedLoopControlNameCache(closedLoopControlNameCache);
-
- Whitebox.setInternalState(engineResources,"droolsEngine", droolsEngine);
+ engineResources.setDroolsEngine(droolsEngine);
PowerMock.resetAll();
}
@Test
public void deployRule_exception() throws CorrelationException {
DeployRuleRequest deployRuleRequest = new DeployRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
expect(droolsEngine.deployRule(anyObject(DeployRuleRequest.class))).
andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.deployRule(deployRuleRequest, httpRequest);
+ engineResources.deployRule(deployRuleRequest);
PowerMock.verifyAll();
}
@@ -72,66 +66,55 @@ public class EngineResourcesTest {
DeployRuleRequest deployRuleRequest = new DeployRuleRequest();
deployRuleRequest.setContent("package packageName;\n\nimport xxx.xxx.xxx;");
deployRuleRequest.setLoopControlName("loopControlName");
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
expect(droolsEngine.deployRule(anyObject(DeployRuleRequest.class))).andReturn("packageName");
PowerMock.replayAll();
- engineResources.deployRule(deployRuleRequest, httpRequest);
+ engineResources.deployRule(deployRuleRequest);
PowerMock.verifyAll();
}
@Test
public void undeployRule_exception() throws CorrelationException {
String packageName = "packageName";
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.undeployRule(anyObject(String.class));
expectLastCall().andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.undeployRule(packageName, httpRequest);
+ engineResources.undeployRule(packageName);
PowerMock.verifyAll();
}
@Test
public void undeployRule_normal() throws CorrelationException {
String packageName = "packageName";
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.undeployRule(anyObject(String.class));
PowerMock.replayAll();
- engineResources.undeployRule(packageName, httpRequest);
+ engineResources.undeployRule(packageName);
PowerMock.verifyAll();
}
@Test
public void compileRule_exception() throws CorrelationException {
CompileRuleRequest compileRuleRequest = new CompileRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.compileRule(anyObject(String.class));
expectLastCall().andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.compileRule(compileRuleRequest, httpRequest);
+ engineResources.compileRule(compileRuleRequest);
PowerMock.verifyAll();
}
@Test
public void compileRule_normal() throws CorrelationException {
CompileRuleRequest compileRuleRequest = new CompileRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
-
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.compileRule(anyObject(String.class));
PowerMock.replayAll();
- engineResources.compileRule(compileRuleRequest, httpRequest);
+ engineResources.compileRule(compileRuleRequest);
PowerMock.verifyAll();
}
}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java b/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java
index cd7aff4..05fb7b5 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.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.
@@ -16,45 +16,38 @@
package org.onap.holmes.engine.wrapper;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-
-import java.util.ArrayList;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-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.engine.db.CorrelationRuleDao;
+import org.onap.holmes.engine.db.CorrelationRuleDaoService;
import org.powermock.api.easymock.PowerMock;
-import org.powermock.reflect.Whitebox;
+
+import java.util.ArrayList;
+
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.expect;
public class RuleMgtWrapperTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private DbDaoUtil daoUtil;
+ private CorrelationRuleDaoService correlationRuleDaoService;
private RuleMgtWrapper ruleMgtWrapper;
@Before
public void setUp() {
- daoUtil = PowerMock.createMock(DbDaoUtil.class);
- ruleMgtWrapper = new RuleMgtWrapper();
+ correlationRuleDaoService = PowerMock.createMock(CorrelationRuleDaoService.class);
+ ruleMgtWrapper = new RuleMgtWrapper(correlationRuleDaoService);
- Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", daoUtil);
PowerMock.resetAll();
}
@Test
public void queryRuleByEnable_normal() throws CorrelationException {
int enable = 3;
-
- CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);
- expect(daoUtil.getJdbiDaoByOnDemand(anyObject(Class.class))).andReturn(correlationRuleDao);
- expect(correlationRuleDao.queryRuleByRuleEnable(anyInt())).andReturn(new ArrayList<CorrelationRule>());
+ expect(correlationRuleDaoService.queryRuleByRuleEnable(anyInt())).andReturn(new ArrayList());
PowerMock.replayAll();
ruleMgtWrapper.queryRuleByEnable(enable);
PowerMock.verifyAll();