summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml288
-rw-r--r--rulemgt-frontend/pom.xml2
-rw-r--r--rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts10
-rw-r--r--rulemgt-standalone/src/main/assembly/Dockerfile1
-rw-r--r--rulemgt-standalone/src/main/assembly/bin/run.sh35
-rw-r--r--rulemgt-standalone/src/main/assembly/conf/application.yaml23
-rw-r--r--rulemgt/pom.xml56
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java22
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java31
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java20
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java58
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java9
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java7
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java3
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java9
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java124
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java (renamed from rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java)53
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java94
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java31
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java62
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java8
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java122
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java23
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java99
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java23
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java12
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java66
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java25
-rw-r--r--rulemgt/src/main/resources/logback-spring.xml59
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java7
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java32
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java59
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java4
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java6
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java9
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java9
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java1
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java (renamed from rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java)59
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java5
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java116
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java43
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java64
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java2
50 files changed, 788 insertions, 1041 deletions
diff --git a/pom.xml b/pom.xml
index 3e2388c..f0935b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright 2017-2020 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.
@@ -35,37 +35,34 @@
</modules>
<properties>
- <packagename>onap-holmes-rulemgt</packagename>
- <finalName>${project.artifactId}-${project.version}</finalName>
-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.test.failure.ignore>false</maven.test.failure.ignore>
+ <packagename>onap-holmes-rulemgt</packagename>
+ <finalName>${project.artifactId}-${project.version}</finalName>
<release.dir>${basedir}/target</release.dir>
<bundle.name>${project.artifactId}-${project.version}</bundle.name>
- <powermock.version>2.0.7</powermock.version>
- <dropwizard.version>2.0.10</dropwizard.version>
- <jersey.version>2.31</jersey.version>
- <jacoco.version>0.8.5</jacoco.version>
+ <jersey.version>3.0.5</jersey.version>
+ <springboot.version>2.7.2</springboot.version>
+ <jetty.version>9.4.18.v20190429</jetty.version>
+ <powermock.version>2.0.9</powermock.version>
+ <jdbi.version>3.19.0</jdbi.version>
<slf4j.version>1.7.25</slf4j.version>
+ <jakarta.ws.rs.version>3.1.0</jakarta.ws.rs.version>
<linux64id>linux64</linux64id>
<linux64outputdir>target/assembly/${linux64id}</linux64outputdir>
<version.output>target/version</version.output>
-
- <sonar.coverage.jacoco.xmlReportPaths>
- ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
- </sonar.coverage.jacoco.xmlReportPaths>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.glassfish.jersey</groupId>
- <artifactId>jersey-bom</artifactId>
- <version>${jersey.version}</version>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -74,9 +71,28 @@
<dependencies>
<dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.2.3</version>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-json</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-autoconfigure</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jdbi</groupId>
+ <artifactId>jdbi3-postgres</artifactId>
+ <version>${jdbi.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jdbi</groupId>
+ <artifactId>jdbi3-sqlobject</artifactId>
+ <version>${jdbi.version}</version>
</dependency>
<dependency>
<groupId>org.onap.msb.java-sdk</groupId>
@@ -118,25 +134,11 @@
</exclusions>
</dependency>
<dependency>
- <groupId>com.squareup.retrofit2</groupId>
- <artifactId>retrofit</artifactId>
- <version>2.5.0</version>
- </dependency>
- <dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
- <version>0.9.9</version>
- </dependency>
- <dependency>
<groupId>org.onap.holmes.common</groupId>
<artifactId>holmes-actions</artifactId>
- <version>1.4.2</version>
+ <version>1.4.3</version>
<exclusions>
<exclusion>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet-core</artifactId>
- </exclusion>
- <exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
</exclusion>
@@ -147,25 +149,14 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>4.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>io.dropwizard</groupId>
- <artifactId>dropwizard-core</artifactId>
- <version>${dropwizard.version}</version>
- </dependency>
- <dependency>
- <groupId>io.dropwizard</groupId>
- <artifactId>dropwizard-db</artifactId>
- <version>${dropwizard.version}</version>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <version>${jakarta.ws.rs.version}</version>
</dependency>
<dependency>
- <groupId>io.dropwizard</groupId>
- <artifactId>dropwizard-jdbi</artifactId>
- <version>2.0.0-rc9</version>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>okhttp</artifactId>
+ <version>3.14.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@@ -180,7 +171,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.8.2</version>
+ <version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -190,12 +181,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
@@ -233,16 +218,59 @@
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</exclusion>
+ <exclusion>
+ <artifactId>javassist</artifactId>
+ <groupId>org.javassist</groupId>
+ </exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>jakarta.activation</groupId>
+ <artifactId>jakarta.activation-api</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <version>4.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.24.1-GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-classloading-xstream</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>xstream</artifactId>
+ <groupId>com.thoughtworks.xstream</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>4.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
@@ -250,6 +278,18 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
@@ -261,13 +301,14 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.24.1-GA</version>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.28.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-classloading-xstream</artifactId>
+ <artifactId>powermock-api-support</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
@@ -278,6 +319,13 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-classloading-xstream</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.5</version>
@@ -290,103 +338,55 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>net.sf.json-lib</groupId>
- <artifactId>json-lib</artifactId>
- <version>2.4</version>
- <classifier>jdk15</classifier>
- <exclusions>
- <exclusion>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.2</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
- <version>2.8.9</version>
+ <version>2.8.6</version>
</dependency>
-
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-server</artifactId>
- <exclusions>
- <exclusion>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- </exclusion>
- </exclusions>
+ <artifactId>jersey-common</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.inject</groupId>
+ <artifactId>jersey-hk2</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ <version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
+ <version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-common</artifactId>
+ <artifactId>jersey-server</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <version>2.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.0</version>
- <configuration>
- <release>11</release>
- </configuration>
- </plugin>
-<!-- <plugin>-->
-<!-- <groupId>org.apache.maven.plugins</groupId>-->
-<!-- <artifactId>maven-enforcer-plugin</artifactId>-->
-<!-- <version>1.4.1</version>-->
-<!-- <executions>-->
-<!-- <execution>-->
-<!-- <id>enforce</id>-->
-<!-- <configuration>-->
-<!-- <rules>-->
-<!-- <dependencyConvergence/>-->
-<!-- </rules>-->
-<!-- </configuration>-->
-<!-- <goals>-->
-<!-- <goal>enforce</goal>-->
-<!-- </goals>-->
-<!-- </execution>-->
-<!-- </executions>-->
-<!-- </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>
</project>
diff --git a/rulemgt-frontend/pom.xml b/rulemgt-frontend/pom.xml
index 2415bb2..dfba79e 100644
--- a/rulemgt-frontend/pom.xml
+++ b/rulemgt-frontend/pom.xml
@@ -79,6 +79,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
+ <version>3.3.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceExcludes>
@@ -103,6 +104,7 @@
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
+ <tarLongFileMode>posix</tarLongFileMode>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>target/</outputDirectory>
</configuration>
diff --git a/rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts b/rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts
index 93a0662..e60dbef 100644
--- a/rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts
+++ b/rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts
@@ -110,7 +110,7 @@ export class RuleInfo implements OnInit {
let msg = { title: 'modalTitleUpdate', message: 'message_update_rule_success' };
this.modalService.announceOpenModal(msg);
this.router.navigate(['alarmRule']);
- } else if (res.status == 499) {
+ } else if (res.status == 500) {
let msg = { title: 'modalTitleUpdate', message: 'message_exception_rule_fail' };
this.modalService.announceOpenModal(msg);
} else {
@@ -123,7 +123,7 @@ export class RuleInfo implements OnInit {
this.modalService.announceOpenModal(msg);
}
);
- } else if (res.status == 499) {
+ } else if (res.status == 500) {
let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
this.modalService.announceOpenModal(msg);
return false;
@@ -152,7 +152,7 @@ export class RuleInfo implements OnInit {
let msg = { title: 'modalTitleDefault', message: 'message_add_rule_success' };
this.modalService.announceOpenModal(msg);
this.router.navigate(['alarmRule']);
- } else if (res.status == 499) {
+ } else if (res.status == 500) {
let msg = { title: 'modalTitleDefault', message: 'message_rule_name_repeat_error' };
this.modalService.announceOpenModal(msg);
} else {
@@ -165,7 +165,7 @@ export class RuleInfo implements OnInit {
this.modalService.announceOpenModal(msg);
});
return true;
- } else if (res.status == 499) {
+ } else if (res.status == 500) {
let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
this.modalService.announceOpenModal(msg);
return false;
@@ -196,7 +196,7 @@ export class RuleInfo implements OnInit {
if (res.status == 200) {
let msg = { 'title': 'modalTitleCheck', message: 'message_checkContent_rule_success' };
this.modalService.announceOpenModal(msg);
- } else if (res.status == 499) {
+ } else if (res.status == 500) {
let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
this.modalService.announceOpenModal(msg);
return false;
diff --git a/rulemgt-standalone/src/main/assembly/Dockerfile b/rulemgt-standalone/src/main/assembly/Dockerfile
index 03630eb..198d0ef 100644
--- a/rulemgt-standalone/src/main/assembly/Dockerfile
+++ b/rulemgt-standalone/src/main/assembly/Dockerfile
@@ -29,6 +29,7 @@ RUN mkdir -p /usr/share/nginx/logs \
&& chmod -R 777 /usr/share/nginx/ \
&& chmod -R 777 /var/lib/nginx/ \
&& chmod -R 755 /etc/ssl/private/ \
+ && chmod -R 755 /etc/ssl/certs/ \
&& chmod -R 777 /etc/nginx/conf.d/ \
&& chmod -R a+rw /opt/onap/ \
&& chmod -R a+rw /var/log/ \
diff --git a/rulemgt-standalone/src/main/assembly/bin/run.sh b/rulemgt-standalone/src/main/assembly/bin/run.sh
index 1db65ca..f54ca50 100644
--- a/rulemgt-standalone/src/main/assembly/bin/run.sh
+++ b/rulemgt-standalone/src/main/assembly/bin/run.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
-# 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.
@@ -48,13 +48,19 @@ if [ -z ${DB_NAME} ]; then
echo "No database is name is specified. Use the default value \"$DB_NAME\"."
fi
+export DB_PORT=5432
+if [ ! -z ${URL_JDBC} ] && [ `expr index $URL_JDBC :` != 0 ]; then
+ export DB_PORT="${URL_JDBC##*:}"
+fi
+echo DB_PORT=$DB_PORT
+
# if deployed using helm, use the helm-generated configuration file.
if [ -d /opt/hrmconfig ]; then
- cp /opt/hrmconfig/rulemgt.yml "$main_path/conf/rulemgt.yml"
+ cp /opt/hrmconfig/application.yaml "$main_path/conf/application.yaml"
else
- sed -i "s|user:.*|user: $JDBC_USERNAME|" "$main_path/conf/rulemgt.yml"
- sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/rulemgt.yml"
- sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC/$DB_NAME|" "$main_path/conf/rulemgt.yml"
+ sed -i "s|username:.*|username: $JDBC_USERNAME|" "$main_path/conf/application.yaml"
+ sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/application.yaml"
+ sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC:$DB_PORT/$DB_NAME|" "$main_path/conf/application.yaml"
fi
export SERVICE_IP=`hostname -i | awk '{print $1}'`
@@ -66,12 +72,6 @@ else
export HOSTNAME=${SERVICE_IP}:9101
fi
-export DB_PORT=5432
-if [ ! -z ${URL_JDBC} ] && [ `expr index $URL_JDBC :` != 0 ]; then
- export DB_PORT="${URL_JDBC##*:}"
-fi
-echo DB_PORT=$DB_PORT
-
if [ -z ${ENABLE_ENCRYPT} ]; then
export ENABLE_ENCRYPT=true
fi
@@ -89,8 +89,8 @@ echo "KEY_PATH=$KEY_PATH"
echo "KEY_PASS=$KEY_PASSWORD"
#HTTPS Configurations
-sed -i "s|keyStorePath:.*|keyStorePath: $KEY_PATH|" "$main_path/conf/rulemgt.yml"
-sed -i "s|keyStorePassword:.*|keyStorePassword: $KEY_PASSWORD|" "$main_path/conf/rulemgt.yml"
+sed -i "s|key-store:.*|key-store: $KEY_PATH|" "$main_path/conf/application.yaml"
+sed -i "s|key-store-password:.*|key-store-password: $KEY_PASSWORD|" "$main_path/conf/application.yaml"
if [ ${ENABLE_ENCRYPT} = true ]; then
sed -i "s|type:\s*https\?$|type: https|" "$main_path/conf/rulemgt.yml"
@@ -122,10 +122,13 @@ else
fi
if [ "${ENABLE_ENCRYPT}"x = "true"x ]; then
- nginx -c /etc/nginx/conf.d/nginx-https.conf
+ sudo nginx -c /etc/nginx/conf.d/nginx-https.conf
else
- nginx -c /etc/nginx/conf.d/nginx-http.conf
+ sudo nginx -c /etc/nginx/conf.d/nginx-http.conf
fi
echo nginx started.
-"$JAVA" $JAVA_OPTS -classpath "$class_path" org.onap.holmes.rulemgt.RuleActiveApp server "$main_path/conf/rulemgt.yml"
+cat "$main_path/conf/application.yaml"
+
+JAR=`ls -lt $main_path/lib | grep -e "holmes-rulemgt-.*jar$" | awk '{print $9}'`
+"$JAVA" $JAVA_OPTS -jar "$main_path/lib/$JAR" -classpath "$class_path" --spring.config.location="$main_path/conf/application.yaml"
diff --git a/rulemgt-standalone/src/main/assembly/conf/application.yaml b/rulemgt-standalone/src/main/assembly/conf/application.yaml
new file mode 100644
index 0000000..f5c789d
--- /dev/null
+++ b/rulemgt-standalone/src/main/assembly/conf/application.yaml
@@ -0,0 +1,23 @@
+server:
+ port: 9101
+ servlet:
+ context-path: /api/holmes-rule-mgmt/v1
+ ssl:
+ key-store: /opt/onap/conf/holmes.keystore
+ key-store-password: holmes
+ #PKCS12
+ key-store-type: JKS
+
+logging:
+ config: classpath:logback-spring.xml
+
+spring:
+ application:
+ name: Holmes Rule Management
+ datasource:
+ dirver-class-name: org.postgresql.Driver
+ url: jdbc:postgresql://localhost:5432/holmes
+ username: holmes
+ password: holmespwd
+ mvc:
+ throw-exception-if-no-handler-found: true \ No newline at end of file
diff --git a/rulemgt/pom.xml b/rulemgt/pom.xml
index 12ecd57..29bf27c 100644
--- a/rulemgt/pom.xml
+++ b/rulemgt/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright 2017-2020 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.
@@ -14,7 +14,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -28,7 +29,11 @@
<packaging>jar</packaging>
<properties>
- <jetty.version>9.4.18.v20190429</jetty.version>
+ <main-class>org.onap.holmes.rulemgt.RuleActiveApp</main-class>
+ <sonar.coverage.jacoco.xmlReportPaths>
+ ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
+ </sonar.coverage.jacoco.xmlReportPaths>
+ <jacoco.version>0.8.5</jacoco.version>
</properties>
<build>
@@ -36,10 +41,49 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.3</version>
+ <version>3.8.0</version>
<configuration>
- <source>1.8</source>
- <target>1.8</target>
+ <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>
+ <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>
</plugins>
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
index 799f455..fc3e798 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2018 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.onap.holmes.rulemgt;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.CommonUtils;
@@ -25,31 +24,32 @@ import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.onap.msb.sdk.discovery.entity.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-import static org.onap.holmes.common.config.MicroServiceConfig.POD_IP;
import static org.onap.holmes.common.utils.CommonUtils.getEnv;
import static org.onap.holmes.common.utils.CommonUtils.isIpAddress;
-@Service
-public class Initializer {
+@Component
+public class Initializer implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger(Initializer.class);
private volatile static boolean readyForMsbReg = false;
private MsbRegister msbRegister;
- @Inject
+ @Autowired
public Initializer(MsbRegister msbRegister) {
this.msbRegister = msbRegister;
}
- @PostConstruct
- private void init() {
+ @Override
+ public void run(ApplicationArguments args) {
Executors.newSingleThreadExecutor().execute(() -> {
waitUntilReady();
try {
@@ -93,7 +93,7 @@ public class Initializer {
msinfo.setEnable_ssl(CommonUtils.isHttpsEnabled());
Set<Node> nodes = new HashSet<>();
Node node = new Node();
- node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv(POD_IP));
+ node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv("HOLMES_RULE_MGMT_SERVICE_HOST"));
node.setPort("9101");
/* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now
String msbAddrTemplate = (CommonUtils.isHttpsEnabled() ? "https" : "http")
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
index cedcde0..3d60a11 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,36 +16,37 @@
package org.onap.holmes.rulemgt;
-import io.dropwizard.setup.Environment;
+import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.ConfigFileScanner;
-import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;
-import org.onap.holmes.common.utils.transactionid.TransactionIdFilter;
import org.onap.holmes.rulemgt.dcae.ConfigFileScanningTask;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.context.annotation.ComponentScan;
-import javax.servlet.DispatcherType;
-import java.util.EnumSet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
+@Slf4j
+@SpringBootApplication
+@ServletComponentScan
+@ComponentScan(basePackages = {"org.onap.holmes"})
+public class RuleActiveApp implements ApplicationRunner {
- public static void main(String[] args) throws Exception {
- new RuleActiveApp().run(args);
+ public static void main(String[] args) {
+ SpringApplication.run(RuleActiveApp.class, args);
}
@Override
- public void run(RuleAppConfig configuration, Environment environment) throws Exception {
- super.run(configuration, environment);
-
+ public void run(ApplicationArguments args) {
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(
new ConfigFileScanningTask(new ConfigFileScanner()), 60L,
ConfigFileScanningTask.POLLING_PERIOD, TimeUnit.SECONDS);
- environment.servlets().addFilter("customFilter", new TransactionIdFilter()).addMappingForUrlPatterns(EnumSet
- .allOf(DispatcherType.class), true, "/*");
-
Initializer.setReadyForMsbReg(true);
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
index bf26b71..79ffa31 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
@@ -17,27 +17,25 @@
package org.onap.holmes.rulemgt;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.*;
-import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
@Slf4j
-@Service
+@Component
public class RuleAllocator {
private static final Logger LOGGER = LoggerFactory.getLogger(RuleAllocator.class);
@@ -48,16 +46,16 @@ public class RuleAllocator {
private RuleQueryWrapper ruleQueryWrapper;
private EngineWrapper engineWrapper;
private EngineTools engineTools;
- private CorrelationRuleDao correlationRuleDao;
+ private CorrelationRuleService correlationRuleService;
- @Inject
+ @Autowired
public RuleAllocator(RuleMgtWrapper ruleMgtWrapper, RuleQueryWrapper ruleQueryWrapper,
- EngineWrapper engineWrapper, EngineTools engineTools, DbDaoUtil daoUtil) {
+ EngineWrapper engineWrapper, EngineTools engineTools, CorrelationRuleService correlationRuleService) {
this.ruleMgtWrapper = ruleMgtWrapper;
this.ruleQueryWrapper = ruleQueryWrapper;
this.engineWrapper = engineWrapper;
this.engineTools = engineTools;
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
+ this.correlationRuleService = correlationRuleService;
}
@PostConstruct
@@ -228,7 +226,7 @@ public class RuleAllocator {
for (int i = 0; i <= RETRY_TIMES; ++i) {
try {
ruleMgtWrapper.deployRule2Engine(rule, ip);
- correlationRuleDao.updateRule(rule);
+ correlationRuleService.updateRule(rule);
// If the codes reach here, it means everything's okay. There's no need to run the loop more.
break;
} catch (CorrelationException e) {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java
deleted file mode 100644
index 20f96c2..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import io.dropwizard.Configuration;
-import io.dropwizard.db.DataSourceFactory;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import org.hibernate.validator.constraints.NotEmpty;
-import org.jvnet.hk2.annotations.Service;
-
-@Service
-public class RuleAppConfig extends Configuration {
-
- @NotEmpty
- private String defaultName = "Holmes Rule Management";
-
- @NotEmpty
- private String apidescription = "Holmes rule management rest API";
-
- @Valid
- @NotNull
- private DataSourceFactory database = new DataSourceFactory();
-
- @JsonProperty("database")
- public DataSourceFactory getDataSourceFactory() {
- return database;
- }
-
- @JsonProperty("database")
- public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
- this.database = dataSourceFactory;
- }
-
-
- public String getApidescription() {
- return apidescription;
- }
-
- public void setApidescription(String apidescription) {
- this.apidescription = apidescription;
- }
-
-}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
index 714a95c..5abdab7 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
@@ -15,8 +15,6 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
index 4b6e248..0d1dd05 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2021 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,13 @@
*/
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import org.jvnet.hk2.annotations.Service;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
+import org.springframework.stereotype.Service;
import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
index 7c927c0..e63b726 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
@@ -18,19 +18,18 @@ package org.onap.holmes.rulemgt.bolt.enginebolt;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-
-import javax.inject.Inject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
@Service
@Slf4j
public class EngineWrapper {
- @Inject
+ @Autowired
private EngineService engineService;
public String deployEngine(CorrelationDeployRule4Engine correlationRule, String ip) throws CorrelationException {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
index 73a2f2b..6149616 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,5 +25,4 @@ public class RuleMgtConstant {
public static final int STATUS_RULE_ALL = 2;
public static final String PACKAGE = "packageName";
public static final String ENGINE_PATH = "/api/holmes-engine-mgmt/v1/rule";
- public static final int RESPONSE_STATUS_OK = 200;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
index 2850708..a893413 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2020 ZTE Corporation.
+ * Copyright 2020-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,12 @@
package org.onap.holmes.rulemgt.controller;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -36,7 +35,7 @@ public class EngineInstanceController extends TimerTask {
private static final long THRESHOLD = 3 * INTERVAL;
private Timer timer = new Timer("EngineInstanceController", true);
- @Inject
+ @Autowired
private EngineEntityService engineEntityService;
@PostConstruct
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java
deleted file mode 100644
index a9be49f..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt.db;
-
-import java.util.List;
-
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.CorrelationRule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.BindBean;
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@Service
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
- protected abstract String addRule(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
- protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
- protected abstract int deleteRuleByRid(@Bind("rid") String rid);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
- protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE")
- protected abstract List<CorrelationRule> queryAllRules();
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
- protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
- public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
-
- public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
- return queryRuleByEngineInstance(enginetype);
- }
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
-
-
- private void deleteRule2DbInner(CorrelationRule correlationRule) {
- String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
- String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
- if (!"".equals(name) && !"".equals(rid)) {
- deleteRuleByRidAndName(rid, name);
- } else if (!"".equals(rid)) {
- deleteRuleByRid(rid);
- }
- }
-
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- addRule(correlationRule);
- return correlationRule;
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- updateRuleByRid(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- deleteRule2DbInner(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
-
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
- try {
- return queryRuleById(rid);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
- try {
- return queryRuleByName(name);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-}
-
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java
index 104f74d..9658ded 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,31 +15,28 @@
*/
package org.onap.holmes.rulemgt.db;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.statement.Query;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
@Service
@Slf4j
-public class CorrelationRuleQueryDao {
+public class CorrelationRuleQueryService {
- @Inject
- private DbDaoUtil dbDaoUtil;
+ @Autowired
+ private Jdbi jdbi;
public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
throws CorrelationException {
@@ -48,9 +45,9 @@ public class CorrelationRuleQueryDao {
String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
try {
StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);
- handle = dbDaoUtil.getHandle();
+ handle = jdbi.open();
Query query = handle.createQuery(querySql.toString());
- for (Object value : query.list()) {
+ for (Object value : query.mapToMap().list()) {
CorrelationRule correlationRule = getCorrelationRule((Map) value);
correlationRules.add(correlationRule);
}
@@ -59,7 +56,7 @@ public class CorrelationRuleQueryDao {
log.warn("Failed to query the rule: id =" + ruleQueryCondition.getRid() + ".");
throw new CorrelationException("Failed to query the rule.", e);
} finally {
- dbDaoUtil.close(handle);
+ handle.close();
}
}
@@ -69,19 +66,19 @@ public class CorrelationRuleQueryDao {
correlationRule.setRid((String) value.get("rid"));
correlationRule.setDescription((String) value.get("description"));
correlationRule.setEnabled((Integer) value.get("enable"));
- correlationRule.setTemplateID((Long) value.get("templateID"));
- correlationRule.setEngineID((String) value.get("engineID"));
- correlationRule.setEngineType((String) value.get("engineType"));
+ correlationRule.setTemplateID((Long) value.get("templateid"));
+ correlationRule.setEngineID((String) value.get("engineid"));
+ correlationRule.setEngineType((String) value.get("enginetype"));
correlationRule.setCreator((String) value.get("creator"));
- correlationRule.setCreateTime((Date) value.get("createTime"));
+ correlationRule.setCreateTime((Date) value.get("createtime"));
correlationRule.setModifier((String) value.get("updator"));
- correlationRule.setUpdateTime((Date) value.get("updateTime"));
+ correlationRule.setUpdateTime((Date) value.get("updatetime"));
correlationRule.setParams((Properties) value.get("params"));
correlationRule.setContent((String) value.get("content"));
correlationRule.setVendor((String) value.get("vendor"));
correlationRule.setPackageName((String) value.get("package"));
correlationRule.setClosedControlLoopName((String) value.get("ctrlloop"));
- correlationRule.setEngineInstance((String) value.get("engineInstance"));
+ correlationRule.setEngineInstance((String) value.get("engineinstance"));
return correlationRule;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java
new file mode 100644
index 0000000..62eae0c
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2021-2022 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CorrelationRuleService {
+
+ @Autowired
+ private CorrelationRuleDao correlationRuleDao;
+
+ public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
+ return correlationRuleDao.queryRuleByEngineInstance(enginetype);
+ }
+
+ public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
+ return correlationRuleDao.queryRuleByEnable(enable);
+ }
+
+
+ private void deleteRule2DbInner(CorrelationRule correlationRule) {
+ String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
+ String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
+ if (!StringUtils.EMPTY.equals(name) && !StringUtils.EMPTY.equals(rid)) {
+ correlationRuleDao.deleteRuleByRidAndName(rid, name);
+ } else if (!"".equals(rid)) {
+ correlationRuleDao.deleteRuleByRid(rid);
+ }
+ }
+
+ public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ correlationRuleDao.addRule(correlationRule);
+ return correlationRule;
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ correlationRuleDao.updateRuleByRid(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
+ try {
+ deleteRule2DbInner(correlationRule);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+
+ public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
+ try {
+ return correlationRuleDao.queryRuleById(rid);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
+ try {
+ return correlationRuleDao.queryRuleByName(name);
+ } catch (Exception e) {
+ throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java
new file mode 100644
index 0000000..6addf0f
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db;
+
+import org.jdbi.v3.core.Jdbi;
+import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class DaoProvider {
+
+ @Bean
+ public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) {
+ return jdbi.onDemand(CorrelationRuleDao.class);
+ }
+}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java
new file mode 100644
index 0000000..2ad1d17
--- /dev/null
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2017-2021 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.rulemgt.db.jdbi;
+
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.customizer.BindBean;
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.utils.CorrelationRuleMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
+ String addRule(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
+ int updateRuleByRid(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
+ int deleteRuleByRid(@Bind("rid") String rid);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
+ int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE")
+ List<CorrelationRule> queryAllRules();
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
+ CorrelationRule queryRuleById(@Bind("rid") String rid);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
+ CorrelationRule queryRuleByName(@Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
+ List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
+ List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
+}
+
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
index 8423f3d..fc042ad 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2021 ZTE Corporation.
+ * Copyright 2021-2022 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.onap.holmes.common.ConfigFileScanner;
import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.FileUtils;
@@ -31,8 +31,8 @@ import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
deleted file mode 100644
index 8049e8f..0000000
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright 2017-2021 ZTE Corporation.
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.onap.holmes.rulemgt.dcae;
-
-
-import lombok.extern.slf4j.Slf4j;
-import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
-import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
-import org.onap.holmes.common.dcae.entity.Rule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.JerseyClient;
-import org.onap.holmes.common.utils.Md5Util;
-import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
-import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
-import java.util.List;
-
-@Slf4j
-@Deprecated
-public class DcaeConfigurationPolling implements Runnable {
-
- public static final long POLLING_PERIOD = 30 * 1000L;
-
- private String hostname;
-
- private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
-
- public DcaeConfigurationPolling(String hostname) {
- this.hostname = hostname;
- }
-
- private String prevConfigMd5 = Md5Util.md5(null);
-
- private boolean prevResult = false;
-
- @Override
- public void run() {
- DcaeConfigurations dcaeConfigurations = null;
- try {
- dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
- String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevResult && prevConfigMd5.equals(md5)) {
- log.info("Operation aborted due to identical configurations.");
- return;
- }
- prevConfigMd5 = md5;
- prevResult = false;
- } catch (CorrelationException e) {
- log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
- } catch (Exception e) {
- log.info("Failed to generate the MD5 information for new configurations.", e);
- }
- RuleQueryListResponse ruleQueryListResponse = null;
- if (dcaeConfigurations != null) {
- try {
- ruleQueryListResponse = getAllCorrelationRules();
- } catch (Exception e) {
- log.error("Failed to get deployed rules from the rule management module: " + e.getMessage(), e);
- }
- }
- if (ruleQueryListResponse != null) {
- List<RuleResult4API> ruleResult4APIs = ruleQueryListResponse.getCorrelationRules();
- deleteAllCorrelationRules(ruleResult4APIs);
- try {
- prevResult = addAllCorrelationRules(dcaeConfigurations);
- } catch (CorrelationException e) {
- log.error("Failed to add rules. " + e.getMessage(), e);
- prevResult = false;
- }
- }
- }
-
- private RuleQueryListResponse getAllCorrelationRules() {
- return JerseyClient.newInstance().get(url, RuleQueryListResponse.class);
- }
-
- private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations) throws CorrelationException {
- boolean suc = false;
- for (Rule rule : dcaeConfigurations.getDefaultRules()) {
- RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule);
- suc = JerseyClient.newInstance().header("Accept", MediaType.APPLICATION_JSON)
- .put(url, Entity.json(ruleCreateRequest)) != null;
-
- if (!suc) {
- break;
- }
- }
- return suc;
- }
-
- private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) {
- ruleResult4APIs.forEach(correlationRule -> {
- if (null == JerseyClient.newInstance().delete(url + "/" + correlationRule.getRuleId())) {
- log.warn("Failed to delete rule, the rule id is: {}", correlationRule.getRuleId());
- }
- });
- }
-
- private RuleCreateRequest getRuleCreateRequest(Rule rule) {
- RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
- ruleCreateRequest.setLoopControlName(rule.getLoopControlName());
- ruleCreateRequest.setRuleName(rule.getName());
- ruleCreateRequest.setContent(rule.getContents());
- ruleCreateRequest.setDescription("");
- ruleCreateRequest.setEnabled(1);
- return ruleCreateRequest;
- }
-}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
index 73d1c5b..c8befef 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,24 +19,23 @@ package org.onap.holmes.rulemgt.resources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.SwaggerDefinition;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Service
+@RestController
@SwaggerDefinition
-@Path("/healthcheck")
+@RequestMapping("/healthcheck")
@Api(tags = {"Health Check"})
@Produces(MediaType.TEXT_PLAIN)
@Slf4j
public class HealthCheck {
- @GET
- @Produces(MediaType.TEXT_PLAIN)
+ @GetMapping(produces = MediaType.TEXT_PLAIN)
@ApiOperation(value = "Interface for the health check of the rule management module for Holmes")
- public boolean healthCheck(){
- return true;
+ public void healthCheck(){
+
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
index 445c2f9..133e859 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
@@ -1,11 +1,11 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
- *
+ * Copyright 2017-2022 ZTE Corporation.
+ * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
@@ -13,17 +13,15 @@
*/
package org.onap.holmes.rulemgt.resources;
-import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
+import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
import org.onap.holmes.common.utils.GsonUtil;
-import org.onap.holmes.common.utils.LanguageUtil;
import org.onap.holmes.common.utils.UserUtil;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
@@ -33,37 +31,33 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
-import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import java.util.Locale;
-@Service
+@Slf4j
+@RestController
@SwaggerDefinition
-@Path("/rule")
+@RequestMapping("/rule")
@Api(tags = {"Holmes Rule Management"})
-@Produces(MediaType.APPLICATION_JSON)
-@Slf4j
public class RuleMgtResources {
- @Inject
+ @Autowired
private RuleMgtWrapper ruleMgtWrapper;
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PutMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",
response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
- + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
- + "and \"description\"(optional)", required = true)
- RuleCreateRequest ruleCreateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse addCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
+ + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
+ + "and \"description\"(optional)", required = true)
+ @RequestBody RuleCreateRequest ruleCreateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -76,16 +70,14 @@ public class RuleMgtResources {
}
}
- @POST
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @PostMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)
- @Timed
- public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
- RuleUpdateRequest ruleUpdateRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleAddAndUpdateResponse updateCorrelationRule(HttpServletRequest request,
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleId\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ @RequestBody RuleUpdateRequest ruleUpdateRequest) {
RuleAddAndUpdateResponse ruleChangeResponse;
try {
ruleChangeResponse = ruleMgtWrapper
@@ -98,38 +90,31 @@ public class RuleMgtResources {
}
}
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
+ @DeleteMapping("/{ruleid}")
@ApiOperation(value = "Remove a rule from Holmes.")
- @Timed
- @Path("/{ruleid}")
- public boolean deleteCorrelationRule(@Context HttpServletRequest request,
- @PathParam("ruleid") String ruleId) {
- Locale locale = LanguageUtil.getLocale(request);
+ public ResponseEntity deleteCorrelationRule(@PathVariable("ruleid") String ruleId) {
try {
ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));
log.info("delete rule:" + ruleId + " successful");
- return true;
+ return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
} catch (CorrelationException e) {
log.error("delete rule:" + ruleId + " failed", e);
throw ExceptionUtil.buildExceptionResponse(e.getMessage());
}
}
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @ResponseBody
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
- @Timed
- public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value =
- "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
- + "\"rulename\"(optional), \"creator\"(optional), "
- + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
- required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
- Locale locale = LanguageUtil.getLocale(request);
+ public RuleQueryListResponse getCorrelationRules(
+ @ApiParam(value =
+ "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
+ + "\"rulename\"(optional), \"creator\"(optional), "
+ + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}")
+ @RequestParam(value = "queryrequest", required = false) String ruleQueryRequest) {
RuleQueryListResponse ruleQueryListResponse;
- RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
+ RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest);
try {
ruleQueryListResponse = ruleMgtWrapper
.getCorrelationRuleByCondition(ruleQueryCondition);
@@ -141,9 +126,7 @@ public class RuleMgtResources {
}
}
- private RuleQueryCondition getRuleQueryCondition(String queryRequest,
- HttpServletRequest request) {
- Locale locale = LanguageUtil.getLocale(request);
+ private RuleQueryCondition getRuleQueryCondition(String queryRequest) {
RuleQueryCondition ruleQueryCondition = GsonUtil
.jsonToBean(queryRequest, RuleQueryCondition.class);
if (queryRequest == null) {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
index 83555b2..74996e5 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,26 +16,23 @@
package org.onap.holmes.rulemgt.resources;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.SwaggerDefinition;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-@Service
-@Path("/swagger.json")
-@Produces(MediaType.APPLICATION_JSON)
+@RestController
+@RequestMapping("/swagger.json")
@Slf4j
public class SwaggerResource {
- @GET
+ @GetMapping
@Produces(MediaType.APPLICATION_JSON)
public String getSwaggerJson() {
URL url = SwaggerResource.class.getResource("/swagger.json");
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
index 2711d3b..f350c12 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,25 @@
package org.onap.holmes.rulemgt.tools;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
-import javax.inject.Inject;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;
-@Service
+@Component
@Slf4j
public class EngineTools {
- @Inject
+ @Autowired
private RuleQueryWrapper ruleQueryWrapper;
- @Inject
+ @Autowired
private EngineEntityService engineEntityService;
public List<String> getInstanceList() {
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java
index 7fdae27..ec6e9b3 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,58 +15,44 @@
*/
package org.onap.holmes.rulemgt.wrapper;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
-import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.onap.holmes.rulemgt.bean.request.*;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
@Service
-@Singleton
@Slf4j
public class RuleMgtWrapper {
- @Inject
+ @Autowired
private EngineTools engineTools;
- @Inject
+ @Autowired
private RuleQueryWrapper ruleQueryWrapper;
- @Inject
- private CorrelationRuleQueryDao correlationRuleQueryDao;
- @Inject
- private EngineWrapper engineWarpper;
- @Inject
- private DbDaoUtil daoUtil;
+ @Autowired
+ private CorrelationRuleQueryService correlationRuleQueryDao;
- private CorrelationRuleDao correlationRuleDao;
+ @Autowired
+ private EngineWrapper engineWarpper;
- @PostConstruct
- public void initDaoUtil() {
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
- }
+ @Autowired
+ private CorrelationRuleService correlationRuleService;
public RuleAddAndUpdateResponse addCorrelationRule(String creator, RuleCreateRequest ruleCreateRequest)
throws CorrelationException {
@@ -76,7 +62,7 @@ public class RuleMgtWrapper {
CorrelationRule correlationRule = convertCreateRequest2Rule(creator,
ruleCreateRequest);
validateCorrelationRule(correlationRule);
- CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName());
+ CorrelationRule ruleTemp = correlationRuleService.queryRuleByRuleName(correlationRule.getName());
if (ruleTemp != null) {
throw new CorrelationException("A rule with the same name already exists.");
}
@@ -91,7 +77,7 @@ public class RuleMgtWrapper {
correlationRule.setEngineInstance(ip);
CorrelationRule result = null;
try {
- result = correlationRuleDao.saveRule(correlationRule);
+ result = correlationRuleService.saveRule(correlationRule);
} catch (CorrelationException e) {
engineWarpper.deleteRuleFromEngine(packageName, ip);
throw new CorrelationException(e.getMessage(), e);
@@ -106,7 +92,7 @@ public class RuleMgtWrapper {
if (ruleUpdateRequest == null) {
throw new CorrelationException("The request object can not be empty!");
}
- CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId());
+ CorrelationRule oldCorrelationRule = correlationRuleService.queryRuleByRid(ruleUpdateRequest.getRuleId());
if (oldCorrelationRule == null) {
throw new CorrelationException("You're trying to update a rule which does not exist in the system.");
}
@@ -131,7 +117,7 @@ public class RuleMgtWrapper {
engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName(), engineInstance);
}
newCorrelationRule.setPackageName(deployRule2Engine(newCorrelationRule, updateIp));
- correlationRuleDao.updateRule(newCorrelationRule);
+ correlationRuleService.updateRule(newCorrelationRule);
return ruleChangeResponse;
}
@@ -172,7 +158,7 @@ public class RuleMgtWrapper {
if (ruleDeleteRequest == null) {
throw new CorrelationException("The request object can not be empty!");
}
- CorrelationRule correlationRule = correlationRuleDao.queryRuleByRid(ruleDeleteRequest.getRuleId());
+ CorrelationRule correlationRule = correlationRuleService.queryRuleByRid(ruleDeleteRequest.getRuleId());
if (correlationRule == null) {
log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId() + " does not exist the database.");
throw new CorrelationException("You're trying to delete a rule which does not exist in the system.");
@@ -181,7 +167,7 @@ public class RuleMgtWrapper {
String ip = correlationRule.getEngineInstance();
engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName(), ip);
}
- correlationRuleDao.deleteRule(correlationRule);
+ correlationRuleService.deleteRule(correlationRule);
}
private CorrelationRule convertCreateRequest2Rule(String userName,
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
index 0ad836f..1d245f8 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
@@ -16,37 +16,28 @@
package org.onap.holmes.rulemgt.wrapper;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
import java.util.List;
@Service
public class RuleQueryWrapper {
- @Inject
- private DbDaoUtil daoUtil;
- private CorrelationRuleDao correlationRuleDao;
+ @Autowired
+ private CorrelationRuleService correlationRuleService;
- @PostConstruct
- public void initDaoUtil() {
- correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);
- }
- public List<CorrelationRule> queryRuleByEnable(int enable) throws CorrelationException {
- List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleEnable(enable);
+ public List<CorrelationRule> queryRuleByEnable(int enable) {
+ List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEnable(enable);
return ruleTemp;
}
public List<CorrelationRule> queryRuleByEngineInstance(String instance) throws CorrelationException {
- List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
- .queryRuleByRuleEngineInstance(instance);
+ List<CorrelationRule> ruleTemp = correlationRuleService.queryRuleByRuleEngineInstance(instance);
return ruleTemp;
}
}
diff --git a/rulemgt/src/main/resources/logback-spring.xml b/rulemgt/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..197057e
--- /dev/null
+++ b/rulemgt/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/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
index 8e4a6fe..0687731 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/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
@@ -22,15 +22,12 @@ import org.onap.holmes.common.utils.MsbRegister;
import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.internal.WhiteboxImpl;
import java.util.concurrent.TimeUnit;
@RunWith(PowerMockRunner.class)
@PrepareForTest(MicroServiceConfig.class)
-@SuppressStaticInitializationFor("org.onap.holmes.common.utils.CommonUtils")
public class InitializerTest {
@Test
@@ -49,7 +46,7 @@ public class InitializerTest {
setReadyFlagAfter(3);
- WhiteboxImpl.invokeMethod(initializer, "init");
+ initializer.run(null);
TimeUnit.SECONDS.sleep(6);
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java
index 04be2e0..561f5d5 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,24 +17,17 @@
package org.onap.holmes.rulemgt;
-import org.glassfish.hk2.api.ServiceLocator;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.onap.holmes.common.api.entity.CorrelationRule;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
import java.util.Calendar;
@@ -44,17 +37,15 @@ import java.util.stream.Collectors;
import static org.easymock.EasyMock.*;
import static org.onap.holmes.rulemgt.RuleAllocator.ENABLE;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ServiceLocator.class, RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class,
- EngineTools.class, DbDaoUtil.class, ServiceLocatorHolder.class})
+@PrepareForTest({RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class,
+ EngineTools.class})
public class RuleAllocatorTest {
private RuleMgtWrapper ruleMgtWrapperMock;
private RuleQueryWrapper ruleQueryWrapperMock;
private EngineWrapper engineWrapperMock;
private EngineTools engineToolsMock;
- private DbDaoUtil dbDaoUtilMock;
- private CorrelationRuleDao correlationRuleDaoMock;
+ private CorrelationRuleService correlationRuleServiceMock;
private List<CorrelationRule> rules;
private List<String> existingIps;
@@ -65,8 +56,7 @@ public class RuleAllocatorTest {
ruleQueryWrapperMock = PowerMock.createMock(RuleQueryWrapper.class);
engineWrapperMock = PowerMock.createMock(EngineWrapper.class);
engineToolsMock = PowerMock.createMock(EngineTools.class);
- dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class);
- correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class);
+ correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class);
rules = new ArrayList<>();
for (int i = 0; i < 20; ++i) {
@@ -107,7 +97,6 @@ public class RuleAllocatorTest {
ipListFromMsb.addAll(newEngineInstances);
ipListFromMsb.addAll(existingIps);
- expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock);
expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb);
expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps);
expect(ruleQueryWrapperMock.queryRuleByEnable(ENABLE)).andReturn(rules.stream()
@@ -124,13 +113,13 @@ public class RuleAllocatorTest {
expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class),
anyObject(String.class))).andReturn("").anyTimes();
- correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class));
+ correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class));
expectLastCall().anyTimes();
PowerMock.replayAll();
RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock,
- engineWrapperMock, engineToolsMock, dbDaoUtilMock);
+ engineWrapperMock, engineToolsMock, correlationRuleServiceMock);
ruleAllocator.allocateRules();
PowerMock.verifyAll();
@@ -144,7 +133,6 @@ public class RuleAllocatorTest {
ipListFromMsb.addAll(existingIps);
ipListFromMsb.remove(0);
- expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock);
expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb);
expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps);
for (String ip : existingIps) {
@@ -153,13 +141,13 @@ public class RuleAllocatorTest {
}
expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class), anyString())).andReturn("anyId").times(2);
- correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class));
+ correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class));
expectLastCall().times(2);
PowerMock.replayAll();
RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock,
- engineWrapperMock, engineToolsMock, dbDaoUtilMock);
+ engineWrapperMock, engineToolsMock, correlationRuleServiceMock);
ruleAllocator.allocateRules();
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java
deleted file mode 100644
index d411603..0000000
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.holmes.rulemgt;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-
-import io.dropwizard.db.DataSourceFactory;
-import org.junit.Before;
-import org.junit.Test;
-
-public class RuleAppConfigTest {
-
- private RuleAppConfig ruleAppConfig;
-
- @Before
- public void setUp() {
- ruleAppConfig = new RuleAppConfig();
- }
-
- @Test
- public void getDataSourceFactory() throws Exception {
- assertThat(ruleAppConfig.getDataSourceFactory(), notNullValue());
- }
-
- @Test
- public void setDataSourceFactory() throws Exception {
- final DataSourceFactory factory = new DataSourceFactory();
- ruleAppConfig.setDataSourceFactory(factory);
- assertThat(ruleAppConfig.getDataSourceFactory(), equalTo(factory));
- }
-
- @Test
- public void getApidescription() throws Exception {
- assertThat(ruleAppConfig.getApidescription(), equalTo("Holmes rule management rest API"));
- }
-
- @Test
- public void setApidescription() throws Exception {
- final String value = "desc";
- ruleAppConfig.setApidescription(value);
- assertThat(ruleAppConfig.getApidescription(), equalTo(value));
- }
-} \ No newline at end of file
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java
index e292e16..e5b42fe 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationCheckRule4EngineTest {
@Test
public void getterAndSetter4Content(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java
index 418ff41..82ad66d 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationDeployRule4EngineTest {
@Test
public void getterAndSetter4Content(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java
index e616a71..52f7b50 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java
@@ -17,11 +17,11 @@
package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.Test;
-
public class CorrelationRestRequestTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java
index 54fa132..7fb874e 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleCreateRequestTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java
index 3d49b2f..97bcd5c 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleDeleteRequestTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java
index 36d5024..9488faa 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleQueryConditionTest {
@Test
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java
index 9f24c0c..f693c76 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleUpdateRequestTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java
index a7db0fe..f36fdb4 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java
@@ -16,11 +16,11 @@
package org.onap.holmes.rulemgt.bean.response;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleAddAndUpdateResponseTest {
@Test
public void getterAndSetter4RuleId(){
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java
index fa423db..aaa62f5 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java
@@ -16,13 +16,14 @@
package org.onap.holmes.rulemgt.bean.response;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleQueryListResponseTest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java
index 2c006ab..0953d10 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java
@@ -16,12 +16,13 @@
package org.onap.holmes.rulemgt.bean.response;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
+import org.junit.Test;
import java.util.Date;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleResult4APITest {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
index 6bfb387..5e7eb19 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
@@ -33,6 +33,7 @@ import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.powermock.api.easymock.PowerMock.createMock;
import static org.powermock.api.easymock.PowerMock.*;
@RunWith(PowerMockRunner.class)
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java
index 0e97e3a..a2bd863 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java
@@ -17,6 +17,10 @@
package org.onap.holmes.rulemgt.db;
import org.easymock.EasyMock;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.result.ResultIterable;
+import org.jdbi.v3.core.statement.Query;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -24,14 +28,11 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
import java.util.*;
@@ -39,30 +40,28 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DbDaoUtil.class, Handle.class, Query.class})
-public class CorrelationRuleQueryDaoTest {
+@PrepareForTest({Handle.class, Query.class})
+public class CorrelationRuleQueryServiceTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
-
- private DbDaoUtil dbDaoUtil;
-
private Handle handle;
-
private Query query;
-
- private CorrelationRuleQueryDao correlationRuleQueryDao;
+ private ResultIterable resultIterable;
+ private CorrelationRuleQueryService correlationRuleQueryDao;
private RuleQueryCondition ruleQueryCondition;
+ private Jdbi jdbi;
@Before
public void setUp() throws Exception {
- correlationRuleQueryDao = new CorrelationRuleQueryDao();
+ correlationRuleQueryDao = new CorrelationRuleQueryService();
- dbDaoUtil = PowerMock.createMock(DbDaoUtil.class);
+ jdbi = PowerMock.createMock(Jdbi.class);
handle = PowerMock.createMock(Handle.class);
query = PowerMock.createMock(Query.class);
+ resultIterable = PowerMock.createMock(ResultIterable.class);
- Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil);
+ Whitebox.setInternalState(correlationRuleQueryDao, "jdbi", jdbi);
ruleQueryCondition = createRuleQueryCondition();
}
@@ -74,10 +73,10 @@ public class CorrelationRuleQueryDaoTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to query the rule.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andThrow(new RuntimeException()).anyTimes();
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -89,10 +88,11 @@ public class CorrelationRuleQueryDaoTest {
@Test
public void getCorrelationRulesByCondition_normal() throws Exception {
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -108,10 +108,11 @@ public class CorrelationRuleQueryDaoTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("An error occurred while building the query SQL.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -128,16 +129,16 @@ public class CorrelationRuleQueryDaoTest {
value.put("rid", "rule_" + System.currentTimeMillis());
value.put("description", "desc");
value.put("enable", 0);
- value.put("templateID", 1L);
- value.put("engineId", "engine-001");
- value.put("engineType", "engineType-001");
+ value.put("templateid", 1L);
+ value.put("engineid", "engine-001");
+ value.put("enginetype", "engineType-001");
value.put("creator", "admin");
- value.put("createTime", new Date());
+ value.put("createtime", new Date());
value.put("updator", "admin");
- value.put("updateTime", new Date());
+ value.put("updatetime", new Date());
value.put("params", new Properties());
value.put("domain", "Domain");
- value.put("isManual", 0);
+ value.put("ismanual", 0);
value.put("vendor", "Vendor");
value.put("content", "Contents");
value.put("package", "package");
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java
index 0f0f81a..396c2c1 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java
@@ -28,20 +28,15 @@ import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
@PrepareForTest({JerseyClient.class})
-@SuppressStaticInitializationFor({"org.onap.holmes.common.utils.JerseyClient"})
public class ConfigFileScanningTaskTest {
@Rule
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
deleted file mode 100644
index b6e7149..0000000
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Copyright 2017-2021 ZTE Corporation.
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.holmes.rulemgt.dcae;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
-import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
-import org.onap.holmes.common.dcae.entity.Rule;
-import org.onap.holmes.common.utils.JerseyClient;
-import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.easymock.EasyMock.*;
-import static org.powermock.api.easymock.PowerMock.*;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.onap.holmes.common.utils.JerseyClient")
-@PrepareForTest({DcaeConfigurationPolling.class, DcaeConfigurationQuery.class})
-public class DcaeConfigurationPollingTest {
-
- @Test
- public void run() throws Exception {
- DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
- dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
- mockStatic(DcaeConfigurationQuery.class);
- expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations);
- DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost");
-
- Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
-
- RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
- List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() {
- {
- add(new RuleResult4API());
- }
- };
- ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
- ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
-
- JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class);
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse);
-
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.delete(anyString())).andReturn("true");
-
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true");
-
- replayAll();
-
- dcaeConfigurationPolling.run();
-
- verifyAll();
- }
-
- @Test
- public void run_identical_contents() throws Exception {
- DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
- dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
- mockStatic(DcaeConfigurationQuery.class);
- expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations).times(2);
- DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost");
-
- Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
-
- RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
- List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() {
- {
- add(new RuleResult4API());
- }
- };
- ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
- ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
- JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class);
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse);
-
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.delete(anyString())).andReturn("true");
-
- PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient);
- expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true");
-
- replayAll();
-
- dcaeConfigurationPolling.run();
- dcaeConfigurationPolling.run();
-
- verifyAll();
- }
-} \ No newline at end of file
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
index a35f6b8..a515196 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.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,25 +17,28 @@
package org.onap.holmes.rulemgt.resources;
import com.google.gson.JsonSyntaxException;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
+import jakarta.ws.rs.WebApplicationException;
import org.easymock.EasyMock;
-import org.eclipse.jetty.server.Request;
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.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
-import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
-import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import javax.servlet.http.HttpServletRequest;
+
+@RunWith(PowerMockRunner.class)
public class RuleMgtResourcesTest {
@Rule
@@ -47,8 +50,6 @@ public class RuleMgtResourcesTest {
private RuleMgtResources ruleMgtResources = new RuleMgtResources();
- private Request requestMock = PowerMock.createMock(Request.class);
-
@Before
public void setUp() throws Exception {
Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);
@@ -63,7 +64,6 @@ public class RuleMgtResourcesTest {
final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))
.andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
@@ -76,7 +76,6 @@ public class RuleMgtResourcesTest {
final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin",
ruleCreateRequest)).andReturn(new RuleAddAndUpdateResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
@@ -90,7 +89,6 @@ public class RuleMgtResourcesTest {
final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))
.andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
@@ -102,7 +100,6 @@ public class RuleMgtResourcesTest {
final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin",
ruleUpdateRequest)).andReturn(new RuleAddAndUpdateResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
EasyMock.expect(request.getHeader("username")).andReturn("admin");
PowerMock.replayAll();
ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
@@ -115,10 +112,9 @@ public class RuleMgtResourcesTest {
final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
- EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expectLastCall().andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -127,9 +123,8 @@ public class RuleMgtResourcesTest {
final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
EasyMock.expectLastCall();
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -140,10 +135,9 @@ public class RuleMgtResourcesTest {
final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","
+ "\"enabled\":0,\"creator\":\"admin\"}";
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
- .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+ .andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, requestStr);
+ ruleMgtResources.getCorrelationRules(requestStr);
PowerMock.verifyAll();
}
@@ -152,10 +146,9 @@ public class RuleMgtResourcesTest {
thrown.expect(JsonSyntaxException.class);
String queryRequest = "this is error param";
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, queryRequest);
+ ruleMgtResources.getCorrelationRules(queryRequest);
PowerMock.verifyAll();
}
@@ -164,9 +157,8 @@ public class RuleMgtResourcesTest {
public void getCorrelationRules_normal_request_string_null() throws Exception {
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
.andReturn(new RuleQueryListResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, null);
+ ruleMgtResources.getCorrelationRules(null);
PowerMock.verifyAll();
}
@@ -176,9 +168,8 @@ public class RuleMgtResourcesTest {
+ "\"creator\":\"admin\"}";
EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
.andReturn(new RuleQueryListResponse());
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, requestStr);
+ ruleMgtResources.getCorrelationRules(requestStr);
PowerMock.verifyAll();
}
} \ No newline at end of file
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
index 626b91d..1ba93d4 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
@@ -22,19 +22,16 @@ 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.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
import org.onap.holmes.rulemgt.bean.request.*;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
-import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
-import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao;
+import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService;
+import org.onap.holmes.rulemgt.db.CorrelationRuleService;
import org.onap.holmes.rulemgt.tools.EngineTools;
import org.powermock.api.easymock.PowerMock;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
@@ -46,7 +43,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
-@RunWith(PowerMockRunner.class)
public class RuleMgtWrapperTest {
@Rule
@@ -56,42 +52,33 @@ public class RuleMgtWrapperTest {
private EngineWrapper engineWrapperMock;
- private DbDaoUtil dbDaoUtilMock;
+ private CorrelationRuleQueryService correlationRuleQueryDaoMock;
- private CorrelationRuleQueryDao correlationRuleQueryDaoMock;
-
- private CorrelationRuleDao correlationRuleDaoMock;
+ private CorrelationRuleService correlationRuleServiceMock;
private EngineTools engineToolsMock;
private static final String USER_NAME = "admin";
@Before
- public void setUp() throws Exception {
+ public void setUp() {
ruleMgtWrapper = new RuleMgtWrapper();
engineWrapperMock = PowerMock.createMock(EngineWrapper.class);
- correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryDao.class);
- dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class);
- correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class);
+ correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryService.class);
+ correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class);
engineToolsMock = PowerMock.createMock(EngineTools.class);
- Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock);
+ Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleService", correlationRuleServiceMock);
Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock);
Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock);
- Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock);
Whitebox.setInternalState(ruleMgtWrapper,"engineTools", engineToolsMock);
PowerMock.resetAll();
}
@Test
- public void initDaoUtil_normal() {
- ruleMgtWrapper.initDaoUtil();
- }
-
- @Test
public void addCorrelationRule_name_is_null() throws Exception {
thrown.expect(CorrelationException.class);
thrown.expectMessage("The name of the rule can not be empty.");
@@ -147,7 +134,7 @@ public class RuleMgtWrapperTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("A rule with the same name already exists.");
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule);
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule);
PowerMock.replayAll();
ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);
@@ -166,7 +153,7 @@ public class RuleMgtWrapperTest {
CorrelationRule correlationRuleRet = new CorrelationRule();
correlationRuleRet.setRid("rule_" + System.currentTimeMillis());
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(null);
EasyMock.expect(engineToolsMock.getEngineWithLeastRules()).andReturn("127.0.0.1");
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)
, EasyMock.anyObject(String.class)))
@@ -174,12 +161,13 @@ public class RuleMgtWrapperTest {
EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)
, EasyMock.anyObject(String.class)))
.andReturn("package-001");
- EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class)))
+ EasyMock.expect(correlationRuleServiceMock.saveRule(EasyMock.anyObject(CorrelationRule.class)))
.andReturn(correlationRuleRet);
PowerMock.replayAll();
RuleAddAndUpdateResponse response = ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);
+
PowerMock.verifyAll();
assertThat(response.getRuleId(), equalTo(correlationRuleRet.getRid()));
@@ -206,10 +194,10 @@ public class RuleMgtWrapperTest {
oldCorrelationRule.setEngineInstance("127.0.0.1");
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des2", "contetnt2", 1);
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2")).times(2);
EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName", "127.0.0.1")).andReturn(true);
- correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));
+ correlationRuleServiceMock.updateRule(EasyMock.anyObject(CorrelationRule.class));
EasyMock.expectLastCall();
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)
, EasyMock.anyObject(String.class)))
@@ -239,7 +227,7 @@ public class RuleMgtWrapperTest {
oldCorrelationRule.setEngineInstance("127.0.0.1");
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des1", "content", 1);
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2"));
PowerMock.replayAll();
@@ -256,7 +244,7 @@ public class RuleMgtWrapperTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("You're trying to update a rule which does not exist in the system.");
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null);
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null);
PowerMock.replayAll();
@@ -280,9 +268,7 @@ public class RuleMgtWrapperTest {
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());
- EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(
- correlationRuleDaoMock).anyTimes();
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
.andReturn(null);
PowerMock.replayAll();
@@ -297,11 +283,11 @@ public class RuleMgtWrapperTest {
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());
CorrelationRule correlationRule = new CorrelationRule();
correlationRule.setEnabled(1);
- EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
+ EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
.andReturn(correlationRule);
EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class)
, EasyMock.anyObject(String.class))).andReturn(true);
- correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class));
+ correlationRuleServiceMock.deleteRule(EasyMock.anyObject(CorrelationRule.class));
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -319,11 +305,11 @@ public class RuleMgtWrapperTest {
RuleQueryCondition.class)))
.andThrow(new CorrelationException("An error occurred while building the query SQL."));
- PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
- PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
}
@Test
@@ -335,11 +321,11 @@ public class RuleMgtWrapperTest {
RuleQueryCondition.class)))
.andThrow(new CorrelationException("Failed to query the rule."));
- PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
- PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
}
@Test
@@ -362,11 +348,11 @@ public class RuleMgtWrapperTest {
EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(
RuleQueryCondition.class))).andReturn(correlationRuleList);
- PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
RuleQueryListResponse response = ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
- PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class);
assertThat(response.getTotalCount(), is(10));
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java
index 4c7b1a0..8bb7e7a 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java
@@ -22,7 +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.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
import org.powermock.api.easymock.PowerMock;
import java.util.ArrayList;