Migrate from DW to Springboot 59/130259/11
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Tue, 28 Dec 2021 02:14:42 +0000 (10:14 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Thu, 11 Aug 2022 12:18:53 +0000 (20:18 +0800)
Issue-ID: HOLMES-511
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Change-Id: I1be0775a4fc8b754218cd584a5de7af96b2ee0e2

50 files changed:
pom.xml
rulemgt-frontend/pom.xml
rulemgt-frontend/src/app/correlation-ruleInfo/ruleInfo.component.ts
rulemgt-standalone/src/main/assembly/Dockerfile
rulemgt-standalone/src/main/assembly/bin/run.sh
rulemgt-standalone/src/main/assembly/conf/application.yaml [new file with mode: 0644]
rulemgt/pom.xml
rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAllocator.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleAppConfig.java [deleted file]
rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/controller/EngineInstanceController.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java [deleted file]
rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java [moved from rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java with 84% similarity]
rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java [new file with mode: 0644]
rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java [new file with mode: 0644]
rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java [new file with mode: 0644]
rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java [deleted file]
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/tools/EngineTools.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapper.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapper.java
rulemgt/src/main/resources/logback-spring.xml [new file with mode: 0644]
rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java [deleted file]
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java [moved from rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java with 72% similarity]
rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java [deleted file]
rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java

diff --git a/pom.xml b/pom.xml
index 3e2388c..f0935b7 100644 (file)
--- 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.
     </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>
 
     <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>
                 </exclusion>
             </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>
             </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>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.8.2</version>
+            <version>4.13.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <version>1.3</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.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
                     <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>
             <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</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-module-junit4-rule</artifactId>
             <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>
             <version>1.16.0</version>
             <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>
             <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>
index 2415bb2..dfba79e 100644 (file)
@@ -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>
           <descriptors>
             <descriptor>assembly.xml</descriptor>
           </descriptors>
+          <tarLongFileMode>posix</tarLongFileMode>
           <appendAssemblyId>false</appendAssemblyId>
           <outputDirectory>target/</outputDirectory>
         </configuration>
index 93a0662..e60dbef 100644 (file)
@@ -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;
index 03630eb..198d0ef 100644 (file)
@@ -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/ \
index 1db65ca..f54ca50 100644 (file)
@@ -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 (file)
index 0000000..f5c789d
--- /dev/null
@@ -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
index 12ecd57..29bf27c 100644 (file)
@@ -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>
     <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>
             <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>
index 799f455..fc3e798 100644 (file)
@@ -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")
index cedcde0..3d60a11 100644 (file)
@@ -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.
 
 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);
     }
 }
index bf26b71..79ffa31 100644 (file)
 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 (file)
index 20f96c2..0000000
+++ /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;
-    }
-
-}
index 714a95c..5abdab7 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
-import com.google.gson.annotations.SerializedName;\r
 import lombok.Getter;\r
 import lombok.Setter;\r
 \r
index 4b6e248..0d1dd05 100644 (file)
@@ -1,5 +1,5 @@
 /**\r
- * Copyright 2017-2021 ZTE Corporation.\r
+ * Copyright 2017-2022 ZTE Corporation.\r
  * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  */\r
 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
 \r
-import org.jvnet.hk2.annotations.Service;\r
+import jakarta.ws.rs.client.Entity;\r
+import jakarta.ws.rs.core.MediaType;\r
 import org.onap.holmes.common.utils.CommonUtils;\r
 import org.onap.holmes.common.utils.JerseyClient;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
-\r
-import javax.ws.rs.client.Entity;\r
-import javax.ws.rs.core.MediaType;\r
+import org.springframework.stereotype.Service;\r
 \r
 import static org.onap.holmes.rulemgt.constant.RuleMgtConstant.ENGINE_PATH;\r
 \r
index 7c927c0..e63b726 100644 (file)
@@ -18,19 +18,18 @@ package org.onap.holmes.rulemgt.bolt.enginebolt;
 import com.google.gson.JsonObject;\r
 import com.google.gson.JsonParser;\r
 import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
-\r
-import javax.inject.Inject;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
 \r
 @Service\r
 @Slf4j\r
 public class EngineWrapper {\r
 \r
-    @Inject\r
+    @Autowired\r
     private EngineService engineService;\r
 \r
     public String deployEngine(CorrelationDeployRule4Engine correlationRule, String ip) throws CorrelationException {\r
index 73a2f2b..6149616 100644 (file)
@@ -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;
 }
index 2850708..a893413 100644 (file)
@@ -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.
 
 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 (file)
index a9be49f..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.holmes.rulemgt.db;\r
-\r
-import java.util.List;\r
-\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.api.entity.CorrelationRule;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.holmes.common.utils.CorrelationRuleMapper;\r
-import org.skife.jdbi.v2.sqlobject.Bind;\r
-import org.skife.jdbi.v2.sqlobject.BindBean;\r
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;\r
-import org.skife.jdbi.v2.sqlobject.SqlQuery;\r
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;\r
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
-\r
-@Service\r
-@RegisterMapper(CorrelationRuleMapper.class)\r
-public abstract class CorrelationRuleDao {\r
-\r
-    @GetGeneratedKeys\r
-    @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)")\r
-    protected abstract String addRule(@BindBean CorrelationRule correlationRule);\r
-\r
-    @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")\r
-    protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);\r
-\r
-    @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")\r
-    protected abstract int deleteRuleByRid(@Bind("rid") String rid);\r
-\r
-    @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")\r
-    protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);\r
-\r
-    @SqlQuery("SELECT * FROM APLUS_RULE")\r
-    protected abstract List<CorrelationRule> queryAllRules();\r
-\r
-    @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")\r
-    protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);\r
-\r
-    @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")\r
-    protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);\r
-\r
-    @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")\r
-    public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);\r
-\r
-    @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")\r
-    public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);\r
-\r
-    public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {\r
-        return queryRuleByEngineInstance(enginetype);\r
-    }\r
-\r
-    public List<CorrelationRule> queryRuleByRuleEnable(int enable) {\r
-        return queryRuleByEnable(enable);\r
-    }\r
-\r
-\r
-    private void deleteRule2DbInner(CorrelationRule correlationRule) {\r
-        String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";\r
-        String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";\r
-        if (!"".equals(name) && !"".equals(rid)) {\r
-            deleteRuleByRidAndName(rid, name);\r
-        } else if (!"".equals(rid)) {\r
-            deleteRuleByRid(rid);\r
-        }\r
-    }\r
-\r
-    public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {\r
-        try {\r
-            addRule(correlationRule);\r
-            return correlationRule;\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
-        }\r
-    }\r
-\r
-    public void updateRule(CorrelationRule correlationRule) throws CorrelationException {\r
-        try {\r
-            updateRuleByRid(correlationRule);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
-        }\r
-    }\r
-\r
-    public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {\r
-        try {\r
-            deleteRule2DbInner(correlationRule);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
-        }\r
-    }\r
-\r
-\r
-    public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {\r
-        try {\r
-            return queryRuleById(rid);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
-        }\r
-    }\r
-\r
-    public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {\r
-        try {\r
-            return queryRuleByName(name);\r
-        } catch (Exception e) {\r
-            throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);\r
-        }\r
-    }\r
-}\r
-\r
@@ -1,5 +1,5 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
+ * Copyright 2017-2021 ZTE Corporation.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  */\r
 package org.onap.holmes.rulemgt.db;\r
 \r
-import java.beans.PropertyDescriptor;\r
-import java.lang.reflect.Field;\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Properties;\r
-import javax.inject.Inject;\r
 import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;\r
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
+import org.jdbi.v3.core.Handle;\r
+import org.jdbi.v3.core.Jdbi;\r
+import org.jdbi.v3.core.statement.Query;\r
 import org.onap.holmes.common.api.entity.CorrelationRule;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.holmes.common.utils.DbDaoUtil;\r
-import org.skife.jdbi.v2.Handle;\r
-import org.skife.jdbi.v2.Query;\r
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;\r
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
+\r
+import java.beans.PropertyDescriptor;\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Method;\r
+import java.util.*;\r
 \r
 @Service\r
 @Slf4j\r
-public class CorrelationRuleQueryDao {\r
+public class CorrelationRuleQueryService {\r
 \r
-    @Inject\r
-    private DbDaoUtil dbDaoUtil;\r
+    @Autowired\r
+    private Jdbi jdbi;\r
 \r
     public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)\r
             throws CorrelationException {\r
@@ -48,9 +45,9 @@ public class CorrelationRuleQueryDao {
         String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);\r
         try {\r
             StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);\r
-            handle = dbDaoUtil.getHandle();\r
+            handle = jdbi.open();\r
             Query query = handle.createQuery(querySql.toString());\r
-            for (Object value : query.list()) {\r
+            for (Object value : query.mapToMap().list()) {\r
                 CorrelationRule correlationRule = getCorrelationRule((Map) value);\r
                 correlationRules.add(correlationRule);\r
             }\r
@@ -59,7 +56,7 @@ public class CorrelationRuleQueryDao {
             log.warn("Failed to query the rule: id =" + ruleQueryCondition.getRid() + ".");\r
             throw new CorrelationException("Failed to query the rule.", e);\r
         } finally {\r
-            dbDaoUtil.close(handle);\r
+            handle.close();\r
         }\r
     }\r
 \r
@@ -69,19 +66,19 @@ public class CorrelationRuleQueryDao {
         correlationRule.setRid((String) value.get("rid"));\r
         correlationRule.setDescription((String) value.get("description"));\r
         correlationRule.setEnabled((Integer) value.get("enable"));\r
-        correlationRule.setTemplateID((Long) value.get("templateID"));\r
-        correlationRule.setEngineID((String) value.get("engineID"));\r
-        correlationRule.setEngineType((String) value.get("engineType"));\r
+        correlationRule.setTemplateID((Long) value.get("templateid"));\r
+        correlationRule.setEngineID((String) value.get("engineid"));\r
+        correlationRule.setEngineType((String) value.get("enginetype"));\r
         correlationRule.setCreator((String) value.get("creator"));\r
-        correlationRule.setCreateTime((Date) value.get("createTime"));\r
+        correlationRule.setCreateTime((Date) value.get("createtime"));\r
         correlationRule.setModifier((String) value.get("updator"));\r
-        correlationRule.setUpdateTime((Date) value.get("updateTime"));\r
+        correlationRule.setUpdateTime((Date) value.get("updatetime"));\r
         correlationRule.setParams((Properties) value.get("params"));\r
         correlationRule.setContent((String) value.get("content"));\r
         correlationRule.setVendor((String) value.get("vendor"));\r
         correlationRule.setPackageName((String) value.get("package"));\r
         correlationRule.setClosedControlLoopName((String) value.get("ctrlloop"));\r
-        correlationRule.setEngineInstance((String) value.get("engineInstance"));\r
+        correlationRule.setEngineInstance((String) value.get("engineinstance"));\r
         return correlationRule;\r
     }\r
 \r
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 (file)
index 0000000..62eae0c
--- /dev/null
@@ -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 (file)
index 0000000..6addf0f
--- /dev/null
@@ -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 (file)
index 0000000..2ad1d17
--- /dev/null
@@ -0,0 +1,62 @@
+/**\r
+ * Copyright 2017-2021 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.holmes.rulemgt.db.jdbi;\r
+\r
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;\r
+import org.jdbi.v3.sqlobject.customizer.Bind;\r
+import org.jdbi.v3.sqlobject.customizer.BindBean;\r
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;\r
+import org.jdbi.v3.sqlobject.statement.SqlQuery;\r
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;\r
+import org.onap.holmes.common.api.entity.CorrelationRule;\r
+import org.onap.holmes.common.utils.CorrelationRuleMapper;\r
+import org.springframework.stereotype.Service;\r
+\r
+import java.util.List;\r
+\r
+@Service\r
+@RegisterRowMapper(CorrelationRuleMapper.class)\r
+public interface CorrelationRuleDao {\r
+\r
+    @GetGeneratedKeys\r
+    @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)")\r
+    String addRule(@BindBean CorrelationRule correlationRule);\r
+\r
+    @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")\r
+    int updateRuleByRid(@BindBean CorrelationRule correlationRule);\r
+\r
+    @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")\r
+    int deleteRuleByRid(@Bind("rid") String rid);\r
+\r
+    @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")\r
+    int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);\r
+\r
+    @SqlQuery("SELECT * FROM APLUS_RULE")\r
+    List<CorrelationRule> queryAllRules();\r
+\r
+    @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")\r
+    CorrelationRule queryRuleById(@Bind("rid") String rid);\r
+\r
+    @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")\r
+    CorrelationRule queryRuleByName(@Bind("name") String name);\r
+\r
+    @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")\r
+    List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);\r
+\r
+    @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")\r
+   List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);\r
+}\r
+\r
index 8423f3d..fc042ad 100644 (file)
@@ -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 (file)
index 8049e8f..0000000
+++ /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;
-    }
-}
index 73d1c5b..c8befef 100644 (file)
@@ -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(){
+
     }
 }
index 445c2f9..133e859 100644 (file)
@@ -1,11 +1,11 @@
 /**\r
- * Copyright 2017-2020 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2022 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
  * in compliance with the License. You may obtain a copy of the License at\r
- *\r
+ * <p>\r
  * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software distributed under the License\r
  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
  * or implied. See the License for the specific language governing permissions and limitations under\r
  */\r
 package org.onap.holmes.rulemgt.resources;\r
 \r
-import com.codahale.metrics.annotation.Timed;\r
 import io.swagger.annotations.Api;\r
 import io.swagger.annotations.ApiOperation;\r
 import io.swagger.annotations.ApiParam;\r
 import io.swagger.annotations.SwaggerDefinition;\r
+import jakarta.ws.rs.core.MediaType;\r
 import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.common.utils.ExceptionUtil;\r
 import org.onap.holmes.common.utils.GsonUtil;\r
-import org.onap.holmes.common.utils.LanguageUtil;\r
 import org.onap.holmes.common.utils.UserUtil;\r
 import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;\r
 import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;\r
@@ -33,37 +31,33 @@ import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
 import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
 import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.http.HttpStatus;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.web.bind.annotation.*;\r
 \r
-import javax.inject.Inject;\r
 import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.*;\r
-import javax.ws.rs.core.Context;\r
-import javax.ws.rs.core.MediaType;\r
-import java.util.Locale;\r
 \r
-@Service\r
+@Slf4j\r
+@RestController\r
 @SwaggerDefinition\r
-@Path("/rule")\r
+@RequestMapping("/rule")\r
 @Api(tags = {"Holmes Rule Management"})\r
-@Produces(MediaType.APPLICATION_JSON)\r
-@Slf4j\r
 public class RuleMgtResources {\r
 \r
-    @Inject\r
+    @Autowired\r
     private RuleMgtWrapper ruleMgtWrapper;\r
 \r
-    @PUT\r
-    @Produces(MediaType.APPLICATION_JSON)\r
+    @ResponseBody\r
+    @PutMapping(produces = MediaType.APPLICATION_JSON)\r
     @ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",\r
             response = RuleAddAndUpdateResponse.class)\r
-    @Timed\r
-    public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value =\r
-                    "The request entity of the HTTP call, which comprises \"ruleName\"(required), "\r
-                            + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "\r
-                            + "and \"description\"(optional)", required = true)\r
-                    RuleCreateRequest ruleCreateRequest) {\r
-        Locale locale = LanguageUtil.getLocale(request);\r
+    public RuleAddAndUpdateResponse addCorrelationRule(HttpServletRequest request,\r
+               @ApiParam(value =\r
+                       "The request entity of the HTTP call, which comprises \"ruleName\"(required), "\r
+                               + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "\r
+                               + "and \"description\"(optional)", required = true)\r
+               @RequestBody RuleCreateRequest ruleCreateRequest) {\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
             ruleChangeResponse = ruleMgtWrapper\r
@@ -76,16 +70,14 @@ public class RuleMgtResources {
         }\r
     }\r
 \r
-    @POST\r
-    @Produces(MediaType.APPLICATION_JSON)\r
+    @ResponseBody\r
+    @PostMapping(produces = MediaType.APPLICATION_JSON)\r
     @ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)\r
-    @Timed\r
-    public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value =\r
-                    "The request entity of the HTTP call, which comprises \"ruleId\"(required), "\r
-                            + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
-                    RuleUpdateRequest ruleUpdateRequest) {\r
-        Locale locale = LanguageUtil.getLocale(request);\r
+    public RuleAddAndUpdateResponse updateCorrelationRule(HttpServletRequest request,\r
+              @ApiParam(value =\r
+                      "The request entity of the HTTP call, which comprises \"ruleId\"(required), "\r
+                              + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
+              @RequestBody RuleUpdateRequest ruleUpdateRequest) {\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
             ruleChangeResponse = ruleMgtWrapper\r
@@ -98,38 +90,31 @@ public class RuleMgtResources {
         }\r
     }\r
 \r
-    @DELETE\r
-    @Produces(MediaType.APPLICATION_JSON)\r
+    @DeleteMapping("/{ruleid}")\r
     @ApiOperation(value = "Remove a rule from Holmes.")\r
-    @Timed\r
-    @Path("/{ruleid}")\r
-    public boolean deleteCorrelationRule(@Context HttpServletRequest request,\r
-            @PathParam("ruleid") String ruleId) {\r
-        Locale locale = LanguageUtil.getLocale(request);\r
+    public ResponseEntity deleteCorrelationRule(@PathVariable("ruleid") String ruleId) {\r
         try {\r
             ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));\r
             log.info("delete rule:" + ruleId + " successful");\r
-            return true;\r
+            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();\r
         } catch (CorrelationException e) {\r
             log.error("delete rule:" + ruleId + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(e.getMessage());\r
         }\r
     }\r
 \r
-    @GET\r
-    @Produces(MediaType.APPLICATION_JSON)\r
+    @ResponseBody\r
+    @GetMapping(produces = MediaType.APPLICATION_JSON)\r
     @ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)\r
-    @Timed\r
-    public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
-            @ApiParam(value =\r
-                    "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "\r
-                            + "\"rulename\"(optional), \"creator\"(optional), "\r
-                            + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",\r
-                    required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
-        Locale locale = LanguageUtil.getLocale(request);\r
+    public RuleQueryListResponse getCorrelationRules(\r
+             @ApiParam(value =\r
+                     "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "\r
+                             + "\"rulename\"(optional), \"creator\"(optional), "\r
+                             + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}")\r
+             @RequestParam(value = "queryrequest", required = false) String ruleQueryRequest) {\r
         RuleQueryListResponse ruleQueryListResponse;\r
 \r
-        RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);\r
+        RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest);\r
         try {\r
             ruleQueryListResponse = ruleMgtWrapper\r
                     .getCorrelationRuleByCondition(ruleQueryCondition);\r
@@ -141,9 +126,7 @@ public class RuleMgtResources {
         }\r
     }\r
 \r
-    private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
-            HttpServletRequest request) {\r
-        Locale locale = LanguageUtil.getLocale(request);\r
+    private RuleQueryCondition getRuleQueryCondition(String queryRequest) {\r
         RuleQueryCondition ruleQueryCondition = GsonUtil\r
                 .jsonToBean(queryRequest, RuleQueryCondition.class);\r
         if (queryRequest == null) {\r
index 83555b2..74996e5 100644 (file)
@@ -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.
 
 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");
index 2711d3b..f350c12 100644 (file)
@@ -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.
 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() {
index 7fdae27..ec6e9b3 100644 (file)
@@ -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.
  */
 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,
index 0ad836f..1d245f8 100644 (file)
 
 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 (file)
index 0000000..197057e
--- /dev/null
@@ -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
index 8e4a6fe..0687731 100644 (file)
@@ -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);
 
index 04be2e0..561f5d5 100644 (file)
@@ -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.
 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 (file)
index d411603..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.holmes.rulemgt;\r
-\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.hamcrest.core.IsNull.notNullValue;\r
-import static org.junit.Assert.assertThat;\r
-\r
-import io.dropwizard.db.DataSourceFactory;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class RuleAppConfigTest {\r
-\r
-    private RuleAppConfig ruleAppConfig;\r
-\r
-    @Before\r
-    public void setUp() {\r
-        ruleAppConfig = new RuleAppConfig();\r
-    }\r
-\r
-    @Test\r
-    public void getDataSourceFactory() throws Exception {\r
-        assertThat(ruleAppConfig.getDataSourceFactory(), notNullValue());\r
-    }\r
-\r
-    @Test\r
-    public void setDataSourceFactory() throws Exception {\r
-        final DataSourceFactory factory = new DataSourceFactory();\r
-        ruleAppConfig.setDataSourceFactory(factory);\r
-        assertThat(ruleAppConfig.getDataSourceFactory(), equalTo(factory));\r
-    }\r
-\r
-    @Test\r
-    public void getApidescription() throws Exception {\r
-        assertThat(ruleAppConfig.getApidescription(), equalTo("Holmes rule management rest API"));\r
-    }\r
-\r
-    @Test\r
-    public void setApidescription() throws Exception {\r
-        final String value = "desc";\r
-        ruleAppConfig.setApidescription(value);\r
-        assertThat(ruleAppConfig.getApidescription(), equalTo(value));\r
-    }\r
-}
\ No newline at end of file
index e292e16..e5b42fe 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
-\r
 import org.junit.Test;\r
 \r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
 public class CorrelationCheckRule4EngineTest {\r
     @Test\r
     public void getterAndSetter4Content(){\r
index 418ff41..82ad66d 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
-import static org.junit.Assert.*;\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-\r
 import org.junit.Test;\r
 \r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
 public class CorrelationDeployRule4EngineTest {\r
     @Test\r
     public void getterAndSetter4Content(){\r
index e616a71..52f7b50 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
+import org.junit.Test;\r
+\r
 import static org.hamcrest.core.IsEqual.equalTo;\r
 import static org.junit.Assert.assertThat;\r
 \r
-import org.junit.Test;\r
-\r
 public class CorrelationRestRequestTest {\r
 \r
     @Test\r
index 54fa132..7fb874e 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
+import org.junit.Test;\r
+\r
 import static org.hamcrest.core.Is.is;\r
 import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.Test;\r
+import static org.junit.Assert.assertThat;\r
 \r
 public class RuleCreateRequestTest {\r
 \r
index 3d49b2f..97bcd5c 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
-\r
 import org.junit.Test;\r
 \r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
 \r
 public class RuleDeleteRequestTest {\r
     @Test\r
index 36d5024..9488faa 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
+import org.junit.Test;\r
+\r
 import static org.hamcrest.core.Is.is;\r
 import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.Test;\r
+import static org.junit.Assert.assertThat;\r
 \r
 public class RuleQueryConditionTest {\r
     @Test\r
index 9f24c0c..f693c76 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
+import org.junit.Test;\r
+\r
 import static org.hamcrest.core.Is.is;\r
 import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.Test;\r
+import static org.junit.Assert.assertThat;\r
 \r
 \r
 public class RuleUpdateRequestTest {\r
index a7db0fe..f36fdb4 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.response;\r
 \r
-import static org.junit.Assert.*;\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-\r
 import org.junit.Test;\r
 \r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
 public class RuleAddAndUpdateResponseTest {\r
     @Test\r
     public void getterAndSetter4RuleId(){\r
index fa423db..aaa62f5 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.response;\r
 \r
-import static org.hamcrest.core.Is.is;\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.assertThat;\r
+import org.junit.Test;\r
 \r
 import java.util.ArrayList;\r
 import java.util.List;\r
-import org.junit.Test;\r
+\r
+import static org.hamcrest.core.Is.is;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
 \r
 public class RuleQueryListResponseTest {\r
 \r
index 2c006ab..0953d10 100644 (file)
 \r
 package org.onap.holmes.rulemgt.bean.response;\r
 \r
-import static org.hamcrest.core.Is.is;\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
+import org.junit.Test;\r
 \r
 import java.util.Date;\r
-import org.junit.Test;\r
+\r
+import static org.hamcrest.core.Is.is;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
 \r
 public class RuleResult4APITest {\r
 \r
index 6bfb387..5e7eb19 100644 (file)
@@ -33,6 +33,7 @@ import static org.easymock.EasyMock.*;
 import static org.hamcrest.MatcherAssert.assertThat;\r
 import static org.hamcrest.Matchers.equalTo;\r
 import static org.hamcrest.Matchers.is;\r
+import static org.powermock.api.easymock.PowerMock.createMock;\r
 import static org.powermock.api.easymock.PowerMock.*;\r
 \r
 @RunWith(PowerMockRunner.class)\r
 package org.onap.holmes.rulemgt.db;\r
 \r
 import org.easymock.EasyMock;\r
+import org.jdbi.v3.core.Handle;\r
+import org.jdbi.v3.core.Jdbi;\r
+import org.jdbi.v3.core.result.ResultIterable;\r
+import org.jdbi.v3.core.statement.Query;\r
 import org.junit.Before;\r
 import org.junit.Rule;\r
 import org.junit.Test;\r
@@ -24,14 +28,11 @@ import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;\r
 import org.onap.holmes.common.api.entity.CorrelationRule;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.holmes.common.utils.DbDaoUtil;\r
 import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;\r
 import org.powermock.api.easymock.PowerMock;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
 import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.reflect.Whitebox;\r
-import org.skife.jdbi.v2.Handle;\r
-import org.skife.jdbi.v2.Query;\r
 \r
 import java.util.*;\r
 \r
@@ -39,30 +40,28 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;\r
 \r
 @RunWith(PowerMockRunner.class)\r
-@PrepareForTest({DbDaoUtil.class, Handle.class, Query.class})\r
-public class CorrelationRuleQueryDaoTest {\r
+@PrepareForTest({Handle.class, Query.class})\r
+public class CorrelationRuleQueryServiceTest {\r
 \r
     @Rule\r
     public ExpectedException thrown = ExpectedException.none();\r
-\r
-    private DbDaoUtil dbDaoUtil;\r
-\r
     private Handle handle;\r
-\r
     private Query query;\r
-\r
-    private CorrelationRuleQueryDao correlationRuleQueryDao;\r
+    private ResultIterable resultIterable;\r
+    private CorrelationRuleQueryService correlationRuleQueryDao;\r
     private RuleQueryCondition ruleQueryCondition;\r
+    private Jdbi jdbi;\r
 \r
     @Before\r
     public void setUp() throws Exception {\r
-        correlationRuleQueryDao = new CorrelationRuleQueryDao();\r
+        correlationRuleQueryDao = new CorrelationRuleQueryService();\r
 \r
-        dbDaoUtil = PowerMock.createMock(DbDaoUtil.class);\r
+        jdbi = PowerMock.createMock(Jdbi.class);\r
         handle = PowerMock.createMock(Handle.class);\r
         query = PowerMock.createMock(Query.class);\r
+        resultIterable = PowerMock.createMock(ResultIterable.class);\r
 \r
-        Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil);\r
+        Whitebox.setInternalState(correlationRuleQueryDao, "jdbi", jdbi);\r
 \r
         ruleQueryCondition = createRuleQueryCondition();\r
     }\r
@@ -74,10 +73,10 @@ public class CorrelationRuleQueryDaoTest {
         thrown.expect(CorrelationException.class);\r
         thrown.expectMessage("Failed to query the rule.");\r
 \r
-        EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
+        EasyMock.expect(jdbi.open()).andReturn(handle);\r
         EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);\r
-        EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes();\r
-        dbDaoUtil.close(handle);\r
+        EasyMock.expect(query.mapToMap()).andThrow(new RuntimeException()).anyTimes();\r
+        handle.close();\r
         EasyMock.expectLastCall();\r
 \r
         PowerMock.replayAll();\r
@@ -89,10 +88,11 @@ public class CorrelationRuleQueryDaoTest {
 \r
     @Test\r
     public void getCorrelationRulesByCondition_normal() throws Exception {\r
-        EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
+        EasyMock.expect(jdbi.open()).andReturn(handle);\r
         EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);\r
-        EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();\r
-        dbDaoUtil.close(handle);\r
+        EasyMock.expect(query.mapToMap()).andReturn(resultIterable);\r
+        EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());\r
+        handle.close();\r
         EasyMock.expectLastCall();\r
 \r
         PowerMock.replayAll();\r
@@ -108,10 +108,11 @@ public class CorrelationRuleQueryDaoTest {
         thrown.expect(CorrelationException.class);\r
         thrown.expectMessage("An error occurred while building the query SQL.");\r
 \r
-        EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
+        EasyMock.expect(jdbi.open()).andReturn(handle);\r
         EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);\r
-        EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();\r
-        dbDaoUtil.close(handle);\r
+        EasyMock.expect(query.mapToMap()).andReturn(resultIterable);\r
+        EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());\r
+        handle.close();\r
         EasyMock.expectLastCall();\r
 \r
         PowerMock.replayAll();\r
@@ -128,16 +129,16 @@ public class CorrelationRuleQueryDaoTest {
         value.put("rid", "rule_" + System.currentTimeMillis());\r
         value.put("description", "desc");\r
         value.put("enable", 0);\r
-        value.put("templateID", 1L);\r
-        value.put("engineId", "engine-001");\r
-        value.put("engineType", "engineType-001");\r
+        value.put("templateid", 1L);\r
+        value.put("engineid", "engine-001");\r
+        value.put("enginetype", "engineType-001");\r
         value.put("creator", "admin");\r
-        value.put("createTime", new Date());\r
+        value.put("createtime", new Date());\r
         value.put("updator", "admin");\r
-        value.put("updateTime", new Date());\r
+        value.put("updatetime", new Date());\r
         value.put("params", new Properties());\r
         value.put("domain", "Domain");\r
-        value.put("isManual", 0);\r
+        value.put("ismanual", 0);\r
         value.put("vendor", "Vendor");\r
         value.put("content", "Contents");\r
         value.put("package", "package");\r
index 0f0f81a..396c2c1 100644 (file)
@@ -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 (file)
index b6e7149..0000000
+++ /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
index a35f6b8..a515196 100644 (file)
@@ -1,5 +1,5 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
+ * Copyright 2017-2022 ZTE Corporation.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 package org.onap.holmes.rulemgt.resources;\r
 \r
 import com.google.gson.JsonSyntaxException;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.WebApplicationException;\r
+import jakarta.ws.rs.WebApplicationException;\r
 import org.easymock.EasyMock;\r
-import org.eclipse.jetty.server.Request;\r
 import org.junit.Before;\r
 import org.junit.Rule;\r
 import org.junit.Test;\r
 import org.junit.rules.ExpectedException;\r
+import org.junit.runner.RunWith;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;\r
 import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;\r
-import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;\r
 import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;\r
 import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;\r
 import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
+import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
 import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.reflect.Whitebox;\r
 \r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+@RunWith(PowerMockRunner.class)\r
 public class RuleMgtResourcesTest {\r
 \r
     @Rule\r
@@ -47,8 +50,6 @@ public class RuleMgtResourcesTest {
 \r
     private RuleMgtResources ruleMgtResources = new RuleMgtResources();\r
 \r
-    private Request requestMock = PowerMock.createMock(Request.class);\r
-\r
     @Before\r
     public void setUp() throws Exception {\r
         Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);\r
@@ -63,7 +64,6 @@ public class RuleMgtResourcesTest {
         final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
         EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
                 .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
         ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
@@ -76,7 +76,6 @@ public class RuleMgtResourcesTest {
         final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
         EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin",\r
                 ruleCreateRequest)).andReturn(new RuleAddAndUpdateResponse());\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
         ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
@@ -90,7 +89,6 @@ public class RuleMgtResourcesTest {
         final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
         EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
                 .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
         ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
@@ -102,7 +100,6 @@ public class RuleMgtResourcesTest {
         final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
         EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin",\r
                 ruleUpdateRequest)).andReturn(new RuleAddAndUpdateResponse());\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
         ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
@@ -115,10 +112,9 @@ public class RuleMgtResourcesTest {
 \r
         final String ruleId = "mockedRule";\r
         ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));\r
-        EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
+        EasyMock.expectLastCall().andThrow(new CorrelationException("any string"));\r
         PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleId);\r
+        ruleMgtResources.deleteCorrelationRule(ruleId);\r
         PowerMock.verifyAll();\r
     }\r
 \r
@@ -127,9 +123,8 @@ public class RuleMgtResourcesTest {
         final String ruleId = "mockedRule";\r
         ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));\r
         EasyMock.expectLastCall();\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleId);\r
+        ruleMgtResources.deleteCorrelationRule(ruleId);\r
         PowerMock.verifyAll();\r
     }\r
 \r
@@ -140,10 +135,9 @@ public class RuleMgtResourcesTest {
         final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
                 + "\"enabled\":0,\"creator\":\"admin\"}";\r
         EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
-                .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
+                .andThrow(new CorrelationException("any string"));\r
         PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, requestStr);\r
+        ruleMgtResources.getCorrelationRules(requestStr);\r
         PowerMock.verifyAll();\r
     }\r
 \r
@@ -152,10 +146,9 @@ public class RuleMgtResourcesTest {
         thrown.expect(JsonSyntaxException.class);\r
 \r
         String queryRequest = "this is error param";\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
 \r
         PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, queryRequest);\r
+        ruleMgtResources.getCorrelationRules(queryRequest);\r
         PowerMock.verifyAll();\r
 \r
     }\r
@@ -164,9 +157,8 @@ public class RuleMgtResourcesTest {
     public void getCorrelationRules_normal_request_string_null() throws Exception {\r
         EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
                 .andReturn(new RuleQueryListResponse());\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
         PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, null);\r
+        ruleMgtResources.getCorrelationRules(null);\r
         PowerMock.verifyAll();\r
     }\r
 \r
@@ -176,9 +168,8 @@ public class RuleMgtResourcesTest {
                 + "\"creator\":\"admin\"}";\r
         EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
                 .andReturn(new RuleQueryListResponse());\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
         PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, requestStr);\r
+        ruleMgtResources.getCorrelationRules(requestStr);\r
         PowerMock.verifyAll();\r
     }\r
 }
\ No newline at end of file
index 626b91d..1ba93d4 100644 (file)
@@ -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,41 +52,32 @@ 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);
@@ -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));
 
index 4c7b1a0..8bb7e7a 100644 (file)
@@ -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;