summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/datalake-handler/Changelog.md22
-rw-r--r--components/datalake-handler/admin/Dockerfile21
-rw-r--r--components/datalake-handler/admin/pom.xml158
-rw-r--r--components/datalake-handler/admin/src/CHANGELOG.md11
-rw-r--r--components/datalake-handler/admin/src/package.json2
-rw-r--r--components/datalake-handler/collector/pom.xml20
-rw-r--r--components/datalake-handler/des/pom.xml579
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java162
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java4
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java11
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java3
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java89
-rw-r--r--components/datalake-handler/feeder/pom.xml612
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java16
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java148
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java117
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java50
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java75
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java267
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java67
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java22
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java8
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java6
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java7
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java37
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java7
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java127
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java22
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java8
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java105
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java118
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java55
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java389
-rw-r--r--[-rwxr-xr-x]components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java241
-rw-r--r--components/datalake-handler/pom.xml539
-rw-r--r--components/datalake-handler/version.properties2
-rw-r--r--components/kpi-computation-ms/Changelog.md4
-rw-r--r--components/kpi-computation-ms/pom.xml12
-rw-r--r--components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/DmaapClient.java10
-rw-r--r--components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClient.java14
-rw-r--r--components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumer.java30
-rw-r--r--components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducer.java39
-rw-r--r--components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/utils/DmaapUtils.java103
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java33
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java51
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java32
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java44
-rw-r--r--components/kpi-computation-ms/version.properties2
-rw-r--r--components/slice-analysis-ms/ChangeLog.md14
-rw-r--r--components/slice-analysis-ms/pom.xml3
-rw-r--r--components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json3
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java46
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java38
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java2
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java18
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java40
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java75
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java45
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java107
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java64
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java209
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java164
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java2
-rw-r--r--components/slice-analysis-ms/src/main/resources/logback.xml3
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java4
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java20
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java9
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java27
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategyTest.java69
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java51
-rw-r--r--components/slice-analysis-ms/src/test/resources/config_all.json3
-rw-r--r--releases/slice-analysis-ms-1.1.5-container.yaml10
72 files changed, 3640 insertions, 1887 deletions
diff --git a/components/datalake-handler/Changelog.md b/components/datalake-handler/Changelog.md
new file mode 100644
index 00000000..247d41e1
--- /dev/null
+++ b/components/datalake-handler/Changelog.md
@@ -0,0 +1,22 @@
+# Change Log
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/)
+and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## [1.1.2]
+### Changed
+* CodeCoverage improvement for dcaegen2-services-data-handler (DCAEGEN2-3161)
+
+## [1.1.1] 2022-09-14
+* DCAEGEN2-3004 - Fix DL-Admin Docker docker build issue
+
+## [1.0.0] 2019-08-01
+### Initial DL-Admin UI code
+### Features
+* add button component ([9e04f08](https://gerrit.onap.org/r/dcaegen2/services/commits/9e04f08))
+* add database to design module ([eba414f](https://gerrit.onap.org/r/dcaegen2/services/commits/eba414f))
+* change the structure of the project ([f761909](https://gerrit.onap.org/r/dcaegen2/services/commits/f761909))
+* new changes for design module ([c4c391b](https://gerrit.onap.org/r/dcaegen2/services/commits/c4c391b))
+
diff --git a/components/datalake-handler/admin/Dockerfile b/components/datalake-handler/admin/Dockerfile
index 6237741a..4c659598 100644
--- a/components/datalake-handler/admin/Dockerfile
+++ b/components/datalake-handler/admin/Dockerfile
@@ -1,9 +1,30 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019 QCT. All rights reserved.
+# Copyright (c) 2022 AT&T. All rights reserved.
+# ================================================================================
+# 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.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
FROM node:alpine AS builder
MAINTAINER Ekko Chang <ekko.chang@qct.io>
LABEL org.label-schema.docker.build="docker build -t dl-admin . --no-cache" \
org.label-schema.docker.run="docker run -p 80:80 --add-host=dl_feeder:your_feeder_ipaddress dl-admin"
+ENV NODE_OPTIONS "--openssl-legacy-provider"
+
WORKDIR /app
COPY ./src .
COPY ./nginx .
diff --git a/components/datalake-handler/admin/pom.xml b/components/datalake-handler/admin/pom.xml
index 7cc30d78..305579d5 100644
--- a/components/datalake-handler/admin/pom.xml
+++ b/components/datalake-handler/admin/pom.xml
@@ -1,26 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (c) 2019 QCT. All rights reserved.
+ Copyright (c) 2022 AT&T. All rights reserved.
+ Copyright (C) 2022 Wipro Limited. All rights reserved.
+ ================================================================================
+ 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.
+ ============LICENSE_END=========================================================
+-->
<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>
+ 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>
- <groupId>org.onap.dcaegen2.services.components</groupId>
- <artifactId>datalake-handler</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.onap.dcaegen2.services.components</groupId>
+ <artifactId>datalake-handler</artifactId>
+ <version>1.1.2-SNAPSHOT</version>
+ </parent>
- <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId>
- <artifactId>admin</artifactId>
- <packaging>pom</packaging>
- <properties>
- <swagger.version>2.9.2</swagger.version>
- <dockerfile-maven.version>1.4.5</dockerfile-maven.version>
- <docker.image.path>onap/org.onap.dcaegen2.services.datalakeadminui</docker.image.path>
- <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
- </properties>
- <name>DataLake Admin</name>
- <build>
+ <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId>
+ <artifactId>admin</artifactId>
+ <packaging>pom</packaging>
+ <properties>
+ <swagger.version>2.9.2</swagger.version>
+ <dockerfile-maven.version>1.4.5</dockerfile-maven.version>
+ <docker.image.path>onap/org.onap.dcaegen2.services.datalakeadminui</docker.image.path>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+ <onap-gerrit-review>-changelog-missing</onap-gerrit-review>
+ </properties>
+ <name>DataLake Admin</name>
+ <build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
@@ -30,58 +46,58 @@
<repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
<tag>${project.version}</tag>
<dockerfile>Dockerfile</dockerfile>
- </configuration>
- <executions>
- <execution>
- <id>build-datalake-admin-ui-image</id>
- <phase>package</phase>
- <goals>
- <goal>build</goal>
- </goals>
- <configuration>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-latest</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>latest</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version-and-date</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}-${maven.build.timestamp}Z</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- </executions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-datalake-admin-ui-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ <configuration>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-latest</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>latest</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version-and-date</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}-${maven.build.timestamp}Z</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ </executions>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
diff --git a/components/datalake-handler/admin/src/CHANGELOG.md b/components/datalake-handler/admin/src/CHANGELOG.md
deleted file mode 100644
index 0cf0870a..00000000
--- a/components/datalake-handler/admin/src/CHANGELOG.md
+++ /dev/null
@@ -1,11 +0,0 @@
-# [0.0.0](https://gerrit.onap.org/r/dcaegen2/services/compare/4.0.0-ONAP...0.0.0) (2019-08-01)
-
-
-### Features
-
-* add button component ([9e04f08](https://gerrit.onap.org/r/dcaegen2/services/commits/9e04f08))
-* add database to design module ([eba414f](https://gerrit.onap.org/r/dcaegen2/services/commits/eba414f))
-* change the structure of the project ([f761909](https://gerrit.onap.org/r/dcaegen2/services/commits/f761909))
-* new changes for design module ([c4c391b](https://gerrit.onap.org/r/dcaegen2/services/commits/c4c391b))
-
-
diff --git a/components/datalake-handler/admin/src/package.json b/components/datalake-handler/admin/src/package.json
index d4e0444c..30b9d88c 100644
--- a/components/datalake-handler/admin/src/package.json
+++ b/components/datalake-handler/admin/src/package.json
@@ -1,6 +1,6 @@
{
"name": "DataLake-AdminUI",
- "version": "0.0.0",
+ "version": "1.1.2",
"scripts": {
"ng": "ng",
"start": "ng serve --host='0.0.0.0' --proxy-config proxy.conf.json",
diff --git a/components/datalake-handler/collector/pom.xml b/components/datalake-handler/collector/pom.xml
deleted file mode 100644
index a3eeff15..00000000
--- a/components/datalake-handler/collector/pom.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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>
- <groupId>org.onap.dcaegen2.services.components</groupId>
- <artifactId>datalake-handler</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId>
- <artifactId>collector</artifactId>
- <packaging>pom</packaging>
- <name>DataLake Collector</name>
-
-
-
-</project>
diff --git a/components/datalake-handler/des/pom.xml b/components/datalake-handler/des/pom.xml
index 87ae9443..64d382f1 100644
--- a/components/datalake-handler/des/pom.xml
+++ b/components/datalake-handler/des/pom.xml
@@ -2,7 +2,8 @@
<!--
~ ============LICENSE_START=======================================================
~ Copyright (c) 2020 China Mobile. All rights reserved.
- ~ ================================================================================
+ ~ Copyright (C) 2022 Wipro Limited. All rights reserved.
+ ~ ================================================================================
~ 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
@@ -15,313 +16,275 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ ============LICENSE_END=========================================================
- -->
-
+-->
<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>
- <groupId>org.onap.dcaegen2.services.components</groupId>
- <artifactId>datalake-handler</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>des</artifactId>
- <packaging>jar</packaging>
- <name>DataLake Extraction Service</name>
-
- <properties>
- <swagger.version>2.9.2</swagger.version>
- <dockerfile-maven.version>1.4.10</dockerfile-maven.version>
- <docker.image.path>onap/org.onap.dcaegen2.services.datalake.exposure.service</docker.image.path>
- <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.jdom</groupId>
- <artifactId>jdom2</artifactId>
- <version>2.0.6</version>
- </dependency>
-
- <dependency>
- <groupId>com.facebook.presto</groupId>
- <artifactId>presto-jdbc</artifactId>
- <version>0.240</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-client</artifactId>
- <version>${hadoop.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>42.2.18</version>
- </dependency>
-
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20190722</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.5.10</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kafka</groupId>
- <artifactId>kafka-clients</artifactId>
- <version>2.3.1</version>
- </dependency>
-
- <dependency>
+ 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>
+ <groupId>org.onap.dcaegen2.services.components</groupId>
+ <artifactId>datalake-handler</artifactId>
+ <version>1.1.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>des</artifactId>
+ <packaging>jar</packaging>
+ <name>DataLake Extraction Service</name>
+ <properties>
+ <swagger.version>2.9.2</swagger.version>
+ <dockerfile-maven.version>1.4.10</dockerfile-maven.version>
+ <docker.image.path>onap/org.onap.dcaegen2.services.datalake.exposure.service</docker.image.path>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+ <onap-gerrit-review>-changelog-missing</onap-gerrit-review>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom2</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.facebook.presto</groupId>
+ <artifactId>presto-jdbc</artifactId>
+ <version>0.240</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-client</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>42.2.18</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20190722</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.10</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-couchbase</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>${springboot.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.elasticsearch.client</groupId>
+ <artifactId>elasticsearch-rest-high-level-client</artifactId>
+ <version>${elasticsearchjava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.10</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.druid</groupId>
+ <artifactId>tranquility-core_2.11</artifactId>
+ <version>0.8.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity-engine-core</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>5.3.7.Final</version>
+ </dependency>
+ <!-- jsr303 validation -->
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>2.0.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>6.1.0.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>${mongojava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.couchbase.mock</groupId>
+ <artifactId>CouchbaseMock</artifactId>
+ <version>1.5.22</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-couchbase</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <version>${springboot.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-high-level-client</artifactId>
- <version>${elasticsearchjava.version}</version>
- </dependency>
-
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.6</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-yaml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-xml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.10</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>io.druid</groupId>
- <artifactId>tranquility-core_2.11</artifactId>
- <version>0.8.3</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-engine-core</artifactId>
- <version>2.1</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>5.3.7.Final</version>
- </dependency>
-
- <!-- jsr303 validation -->
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>2.0.1.Final</version>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>6.1.0.Final</version>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>${swagger.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${swagger.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>${mongojava.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.couchbase.mock</groupId>
- <artifactId>CouchbaseMock</artifactId>
- <version>1.5.22</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <version>2.8</version>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <classifier>execute</classifier>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>com.spotify</groupId>
- <artifactId>dockerfile-maven-plugin</artifactId>
- <version>${dockerfile-maven.version}</version>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}</tag>
- <dockerfile>Dockerfile</dockerfile>
- <buildArgs>
- <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
- </buildArgs>
- </configuration>
- <executions>
- <execution>
- <id>build-sl-des-image</id>
- <phase>package</phase>
- <goals>
- <goal>build</goal>
- </goals>
- <configuration>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-latest</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>latest</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version-and-date</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}-${maven.build.timestamp}Z</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <!-- To make this work on JDK 9+ -->
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>javax.activation-api</artifactId>
- <version>1.2.0</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <configuration>
+ <classifier>execute</classifier>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>dockerfile-maven-plugin</artifactId>
+ <version>${dockerfile-maven.version}</version>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}</tag>
+ <dockerfile>Dockerfile</dockerfile>
+ <buildArgs>
+ <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
+ </buildArgs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-sl-des-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ <configuration>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-latest</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>latest</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version-and-date</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}-${maven.build.timestamp}Z</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <!-- To make this work on JDK 9+ -->
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>javax.activation-api</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
index 4cadc31d..c4abac98 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE DES
* ================================================================================
* Copyright (C) 2020 China Mobile. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,20 +22,28 @@
package org.onap.datalake.des.controller;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.des.domain.DataExposure;
+import org.onap.datalake.des.domain.Db;
+import org.onap.datalake.des.domain.DbType;
+import org.onap.datalake.des.dto.DataExposureConfig;
import org.onap.datalake.des.repository.DataExposureRepository;
+import org.onap.datalake.des.service.DataExposureService;
import org.springframework.validation.BindingResult;
/**
@@ -54,16 +63,157 @@ public class DataExposureControllerTest {
@Mock
private BindingResult mockBindingResult;
+ @Mock
+ private DataExposureService dataExposureService;
+
+ @InjectMocks
+ private DataExposureController dataExposureController;
+
+ /**
+ * Generate data exposure config.
+ *
+ * @return DataExposureConfig object
+ *
+ */
+ public DataExposureConfig getDataExposureConfig() {
+ DataExposureConfig dataExposureConfig = new DataExposureConfig();
+ dataExposureConfig.setDbId(1);
+ dataExposureConfig.setId("1");
+ dataExposureConfig.setNote("note");
+ dataExposureConfig.setSqlTemplate("sqlTemplate");
+ return dataExposureConfig;
+ }
+
+ /**
+ * Generate data exposure.
+ *
+ * @return DataExposure object
+ *
+ */
+ public DataExposure getDataExposure() {
+ DbType dbType = new DbType("ES", "Elasticsearch");
+ Db db = new Db();
+ db.setId(1);
+ db.setDbType(dbType);
+ db.setDatabase("Elasticsearch");
+
+ DataExposure dataExposure = new DataExposure();
+ dataExposure.setId("1");
+ dataExposure.setNote("note");
+ dataExposure.setSqlTemplate("sqlTemplate");
+ dataExposure.setDb(db);
+ return dataExposure;
+ }
+
@Test(expected = NullPointerException.class)
- public void testServe()
- throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
+ public void testServeNull()
+ throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
DataExposureController dataExposureController = new DataExposureController();
String serviceId = "test";
- Map<String, String> requestMap = new HashMap<String, String>();
+ Map < String, String > requestMap = new HashMap < String, String > ();
requestMap.put("name", "oteNB5309");
- HashMap<String, Object> result = dataExposureController.serve(serviceId, requestMap, mockBindingResult,
- httpServletResponse);
+ HashMap < String, Object > result = dataExposureController.serve(serviceId, requestMap, mockBindingResult,
+ httpServletResponse);
assertEquals(null, result);
when(mockBindingResult.hasErrors()).thenReturn(true);
}
+
+ @Test(expected = SQLException.class)
+ public void testServeException()
+ throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
+ String serviceId = "test";
+ Map < String, String > requestMap = new HashMap < String, String > ();
+ requestMap.put("name", "oteNB5309");
+
+ DataExposure dataExposure = getDataExposure();
+ when(dataExposureService.getDataExposure(serviceId)).thenReturn(dataExposure);
+ dataExposureController.serve(serviceId, requestMap, mockBindingResult,
+ httpServletResponse);
+ }
+
+ @Test
+ public void testQueryAllDataExposure() {
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ List < DataExposureConfig > dataExposureList = new ArrayList < > ();
+ dataExposureList.add(dataExposureConfig);
+ when(dataExposureService.queryAllDataExposure()).thenReturn(dataExposureList);
+ assertEquals(dataExposureList, dataExposureController.queryAllDataExposure());
+ }
+
+ @Test
+ public void TestQueryAllDataExposureByIdNull() throws IOException {
+ when(dataExposureService.getDataExposureById("1")).thenReturn(null);
+ assertEquals(null, dataExposureController.queryAllDataExposure("1", httpServletResponse));
+ }
+
+ @Test
+ public void TestQueryAllDataExposureById() throws IOException {
+ DataExposure dataExposure = getDataExposure();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure);
+ dataExposureController.queryAllDataExposure("1", httpServletResponse);
+ }
+
+ @Test
+ public void testCreateDataExposureNull() throws IOException {
+ DataExposure dataExposure = getDataExposure();
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure);
+ assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testCreateDataExposure() throws IOException {
+ DataExposure dataExposure = getDataExposure();
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(null);
+ when(dataExposureService.fillDataExposureConfiguration(dataExposureConfig)).thenReturn(dataExposure);
+ dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void testCreateDataExposureException() throws IOException {
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(null);
+ when(dataExposureService.fillDataExposureConfiguration(dataExposureConfig)).thenThrow(NullPointerException.class);
+ assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testCreateDataExposureError() throws IOException {
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateDataExposureNull() throws IOException {
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(null);
+ assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateDataExposure() throws IOException {
+ DataExposure dataExposure = getDataExposure();
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure);
+ dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse);
+ }
+
+ @Test
+ public void testUpdateDataExposureException() throws IOException {
+ DataExposure dataExposure = getDataExposure();
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure);
+ doThrow(NullPointerException.class).when(dataExposureService).fillDataExposureConfiguration(dataExposureConfig, dataExposure);
+ assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateDataExposureError() throws IOException {
+ DataExposureConfig dataExposureConfig = getDataExposureConfig();
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse));
+ }
+
}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
index cd5c6b4d..e6dba7f0 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake DES
* ================================================================================
* Copyright 2020 China Mobile. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +24,7 @@ package org.onap.datalake.des.domain;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -74,5 +76,7 @@ public class DbTest {
assertTrue("property2".equals(mongoDb2.getProperty2()));
assertTrue("property3".equals(mongoDb2.getProperty3()));
assertEquals(mongoDb2.getDbConfig().getHost(), mongoDb2.getHost());
+ assertNotNull(mongoDb1.toString());
}
+
}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
index 4b83a03b..9f727c5c 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake DES
* ================================================================================
* Copyright 2020 China Mobile. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,16 +38,18 @@ public class DbTypeTest {
@Test
public void test() {
- DbType dbType = new DbType("ES","Elasticsearch");
+ DbType dbType = new DbType("ES", "Elasticsearch");
- dbType.setTool(false);
+ dbType.setTool(false);
assertNotNull(dbType.toString());
assertEquals(dbType, dbType);
assertNotEquals(dbType, null);
assertNotEquals(dbType, "ES");
- DbType dbType2 = new DbType("MONGO", "MongoDB");
+ DbType dbType2 = new DbType();
+ dbType2.setId("MONGO");
+ dbType2.setName("MongoDB");
assertNotEquals(dbType, dbType2);
assertNotNull(dbType.hashCode());
@@ -59,4 +62,4 @@ public class DbTypeTest {
assertNull(dbType2.getDbs());
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java
index ee21f475..09f868f8 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE DES
* ================================================================================
* Copyright (C) 2020 China Mobile. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,5 +54,7 @@ public class DbConfigTest {
assertFalse("123".equals(dbConfig.getPort()));
dbConfig.setPoperties("driver");
assertTrue("driver".equals(dbConfig.getPoperties()));
+ dbConfig.setDbTypeId("123");
+ assertTrue("123".equals(dbConfig.getDbTypeId()));
}
}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java
index 254afcb5..9671a94b 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake DES
* ================================================================================
* Copyright 2020 China Mobile. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +23,9 @@ package org.onap.datalake.des.service;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -40,7 +39,6 @@ import org.onap.datalake.des.dto.DbConfig;
import org.onap.datalake.des.repository.DataExposureRepository;
import org.onap.datalake.des.repository.DbRepository;
import org.springframework.context.ApplicationContext;
-
/**
* Test DB exposure Service.
*
@@ -100,6 +98,34 @@ public class DataExposureServiceTest {
}
@Test
+ public void testGetDataExposure() {
+ Db newdb = new Db();
+ DbConfig dbConfig = getDbConfig();
+ newdb.setName(dbConfig.getName());
+ newdb.setHost(dbConfig.getHost());
+ newdb.setPort(dbConfig.getPort());
+ newdb.setEnabled(dbConfig.isEnabled());
+ newdb.setLogin(dbConfig.getLogin());
+ newdb.setPass(dbConfig.getPass());
+ newdb.setEncrypt(dbConfig.isEncrypt());
+
+ DataExposure de = new DataExposure();
+ de.setId("1");
+ de.setNote("note");
+ de.setSqlTemplate("sqlTemplate");
+ de.setDb(newdb);
+ when(dataExposureRepository.findById("1")).thenReturn(Optional.of(de));
+ assertEquals(de, dataExposureService.getDataExposure("1"));
+ }
+
+ @Test
+ public void testGetDataExposureNull() {
+ Optional < DataExposure > de = Optional.ofNullable(null);
+ when(dataExposureRepository.findById(null)).thenReturn(de);
+ assertEquals(dataExposureService.getDataExposure(null), null);
+ }
+
+ @Test
public void testQueryAllDataExposure() {
Db newdb = new Db();
DbConfig dbConfig = getDbConfig();
@@ -110,20 +136,56 @@ public class DataExposureServiceTest {
newdb.setLogin(dbConfig.getLogin());
newdb.setPass(dbConfig.getPass());
newdb.setEncrypt(dbConfig.isEncrypt());
+
DataExposureConfig deConfig = getDataExposureConfig();
DataExposure de = new DataExposure();
de.setDb(newdb);
de.setId(deConfig.getId());
de.setNote(deConfig.getNote());
de.setSqlTemplate(deConfig.getSqlTemplate());
- List<DataExposure> deList = new ArrayList<>();
+ List < DataExposure > deList = new ArrayList < > ();
deList.add(de);
when(dataExposureRepository.findAll()).thenReturn(deList);
- List<DataExposureConfig> deConfigList = dataExposureService.queryAllDataExposure();
+ List < DataExposureConfig > deConfigList = dataExposureService.queryAllDataExposure();
assertEquals(de.getId(), deConfigList.get(0).getId());
}
@Test
+ public void testQueryAllDataExposureNull() {
+ List < DataExposure > deList = new ArrayList < > ();
+ when(dataExposureRepository.findAll()).thenReturn(deList);
+ assertEquals(dataExposureService.queryAllDataExposure(), deList);
+ }
+
+ @Test
+ public void testGetDataExposureById() {
+ Db newdb = new Db();
+ DbConfig dbConfig = getDbConfig();
+ newdb.setName(dbConfig.getName());
+ newdb.setHost(dbConfig.getHost());
+ newdb.setPort(dbConfig.getPort());
+ newdb.setEnabled(dbConfig.isEnabled());
+ newdb.setLogin(dbConfig.getLogin());
+ newdb.setPass(dbConfig.getPass());
+ newdb.setEncrypt(dbConfig.isEncrypt());
+
+ DataExposure de = new DataExposure();
+ de.setId("1");
+ de.setNote("note");
+ de.setSqlTemplate("sqlTemplate");
+ de.setDb(newdb);
+ when(dataExposureRepository.findById("1")).thenReturn(Optional.of(de));
+ assertEquals(de, dataExposureService.getDataExposureById("1"));
+ }
+
+ @Test
+ public void testGetDataExposureByIdNull() {
+ Optional < DataExposure > de = Optional.ofNullable(null);
+ when(dataExposureRepository.findById(null)).thenReturn(de);
+ assertEquals(dataExposureService.getDataExposureById(null), null);
+ }
+
+ @Test
public void testFillDataExposureConfiguration() {
Db newdb = new Db();
DbConfig dbConfig = getDbConfig();
@@ -153,6 +215,7 @@ public class DataExposureServiceTest {
newdb.setEncrypt(dbConfig.isEncrypt());
DataExposureConfig deConfig = getDataExposureConfig();
when(dbRepository.findById(deConfig.getDbId())).thenReturn(Optional.of(newdb));
+
DataExposure de = new DataExposure();
de.setDb(newdb);
de.setId(deConfig.getId());
@@ -161,4 +224,20 @@ public class DataExposureServiceTest {
dataExposureService.fillDataExposureConfiguration(deConfig, de);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testFillDataExposureException() {
+ DataExposureConfig deConfig = getDataExposureConfig();
+ deConfig.setDbId(null);
+ dataExposureService.fillDataExposureConfiguration(deConfig);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testFillDataExposureIllegalArgumentException() {
+ DataExposureConfig deConfig = getDataExposureConfig();
+ deConfig.setDbId(1);
+ Optional < Db > dbOptional = Optional.ofNullable(null);
+ when(dbRepository.findById(deConfig.getDbId())).thenReturn(dbOptional);
+ dataExposureService.fillDataExposureConfiguration(deConfig);
+ }
+
}
diff --git a/components/datalake-handler/feeder/pom.xml b/components/datalake-handler/feeder/pom.xml
index 49ad6094..312e8dcc 100644
--- a/components/datalake-handler/feeder/pom.xml
+++ b/components/datalake-handler/feeder/pom.xml
@@ -1,299 +1,319 @@
<?xml version="1.0" encoding="UTF-8"?>
-<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>
- <groupId>org.onap.dcaegen2.services.components</groupId>
- <artifactId>datalake-handler</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId>
- <artifactId>feeder</artifactId>
- <packaging>jar</packaging>
- <name>DataLake Feeder</name>
-
- <properties>
- <swagger.version>2.9.2</swagger.version>
- <dockerfile-maven.version>1.4.5</dockerfile-maven.version>
- <docker.image.path>onap/org.onap.dcaegen2.services.datalakefeeder</docker.image.path>
- <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
-
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.jdom</groupId>
- <artifactId>jdom2</artifactId>
- <version>2.0.6</version>
- </dependency>
-
- <dependency>
- <groupId>com.facebook.presto</groupId>
- <artifactId>presto-jdbc</artifactId>
- <version>0.229</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-client</artifactId>
- <version>${hadoop.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>42.2.18</version>
+<!--
+ ~ ============LICENSE_START=======================================================
+ ~ Copyright (C) 2018-2019 Huawei. All rights reserved.
+ ~ Copyright 2018 TechMahindra. All rights reserved.
+ ~ Copyright (C) 2019 QCT. All rights reserved.
+ ~ Copyright (c) 2019-2020 China Mobile. All rights reserved.
+ ~ Copyright (C) 2021-2022 Wipro Limited. All rights reserved.
+ ~ ================================================================================
+ ~ 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.
+ ~ ============LICENSE_END=========================================================
+-->
+<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>
+ <groupId>org.onap.dcaegen2.services.components</groupId>
+ <artifactId>datalake-handler</artifactId>
+ <version>1.1.2-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId>
+ <artifactId>feeder</artifactId>
+ <packaging>jar</packaging>
+ <name>DataLake Feeder</name>
+
+ <properties>
+ <swagger.version>2.9.2</swagger.version>
+ <dockerfile-maven.version>1.4.5</dockerfile-maven.version>
+ <docker.image.path>onap/org.onap.dcaegen2.services.datalakefeeder</docker.image.path>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+ <onap-gerrit-review>-changelog-missing</onap-gerrit-review>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom2</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.presto</groupId>
+ <artifactId>presto-jdbc</artifactId>
+ <version>0.229</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-client</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>42.2.18</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20190722</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.10</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-couchbase</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>${springboot.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.elasticsearch.client</groupId>
+ <artifactId>elasticsearch-rest-high-level-client</artifactId>
+ <version>${elasticsearchjava.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.10</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>io.druid</groupId>
+ <artifactId>tranquility-core_2.11</artifactId>
+ <version>0.8.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity-engine-core</artifactId>
+ <version>2.1</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>5.3.7.Final</version>
+ </dependency>
+
+ <!-- jsr303 validation -->
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>2.0.1.Final</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>6.1.0.Final</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>${mongojava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.couchbase.mock</groupId>
+ <artifactId>CouchbaseMock</artifactId>
+ <version>1.5.22</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <configuration>
+ <classifier>exec</classifier>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>dockerfile-maven-plugin</artifactId>
+ <version>${dockerfile-maven.version}</version>
+ <configuration>
+ <!-- <username>docker</username> <password>docker</password> -->
+ <!-- repository>repo.treescale.com/moguobiao/datalake-feeder-maven</repository -->
+ <!-- repository>moguobiao/datalake-feeder-maven-spotify</repository -->
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <!-- <repository>mizunoami123/dl-feeder</repository> -->
+ <tag>${project.version}</tag>
+ <dockerfile>Dockerfile</dockerfile>
+ <!-- useMavenSettingsForAuth>true</useMavenSettingsForAuth -->
+ <buildArgs>
+ <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
+ </buildArgs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-sl-feeder-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ <configuration>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-latest</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>latest</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version-and-date</id>
+ <phase>package</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
+ <tag>${project.version}-${maven.build.timestamp}Z</tag>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <!-- To make this work on JDK 9+ -->
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>javax.activation-api</artifactId>
+ <version>1.2.0</version>
</dependency>
-
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20190722</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.5.10</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kafka</groupId>
- <artifactId>kafka-clients</artifactId>
- <version>2.3.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-couchbase</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <version>${springboot.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-high-level-client</artifactId>
- <version>${elasticsearchjava.version}</version>
- </dependency>
-
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.6</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-yaml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-xml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.10</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>io.druid</groupId>
- <artifactId>tranquility-core_2.11</artifactId>
- <version>0.8.3</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-engine-core</artifactId>
- <version>2.1</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>5.3.7.Final</version>
- </dependency>
-
- <!-- jsr303 validation -->
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>2.0.1.Final</version>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>6.1.0.Final</version>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>${swagger.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${swagger.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>${mongojava.version}</version>
- </dependency>
- <dependency>
- <groupId>com.couchbase.mock</groupId>
- <artifactId>CouchbaseMock</artifactId>
- <version>1.5.22</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <classifier>exec</classifier>
- </configuration>
- </plugin>
- <plugin>
- <groupId>com.spotify</groupId>
- <artifactId>dockerfile-maven-plugin</artifactId>
- <version>${dockerfile-maven.version}</version>
- <configuration>
- <!--
- <username>docker</username>
- <password>docker</password> -->
- <!-- repository>repo.treescale.com/moguobiao/datalake-feeder-maven</repository -->
- <!-- repository>moguobiao/datalake-feeder-maven-spotify</repository -->
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <!-- <repository>mizunoami123/dl-feeder</repository> -->
- <tag>${project.version}</tag>
- <dockerfile>Dockerfile</dockerfile>
- <!-- useMavenSettingsForAuth>true</useMavenSettingsForAuth -->
- <buildArgs>
- <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
- </buildArgs>
- </configuration>
- <executions>
- <execution>
- <id>build-sl-feeder-image</id>
- <phase>package</phase>
- <goals>
- <goal>build</goal>
- </goals>
- <configuration>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-latest</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>latest</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- <execution>
- <id>tag-and-push-image-with-version-and-date</id>
- <phase>package</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository>
- <tag>${project.version}-${maven.build.timestamp}Z</tag>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <!-- To make this work on JDK 9+ -->
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>javax.activation-api</artifactId>
- <version>1.2.0</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java
index 2e959fa2..0e617f5e 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java
@@ -3,6 +3,7 @@
* ONAP : DataLake
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,14 +21,15 @@
package org.onap.datalake.feeder.service;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import org.onap.datalake.feeder.domain.Kafka;
import org.onap.datalake.feeder.dto.KafkaConfig;
import org.onap.datalake.feeder.repository.KafkaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.*;
-
/**
* Service for kafkas
*
@@ -41,15 +43,15 @@ public class KafkaService {
public Kafka getKafkaById(int id) {
- Optional<Kafka> ret = kafkaRepository.findById(id);
+ Optional < Kafka > ret = kafkaRepository.findById(id);
return ret.isPresent() ? ret.get() : null;
}
- public List<KafkaConfig> getAllKafka() {
+ public List < KafkaConfig > getAllKafka() {
- List<KafkaConfig> kafkaConfigList = new ArrayList<>();
- Iterable<Kafka> kafkaIterable = kafkaRepository.findAll();
- for(Kafka portal : kafkaIterable) {
+ List < KafkaConfig > kafkaConfigList = new ArrayList < > ();
+ Iterable < Kafka > kafkaIterable = kafkaRepository.findAll();
+ for (Kafka portal: kafkaIterable) {
kafkaConfigList.add(portal.getKafkaConfig());
}
return kafkaConfigList;
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
index 9318ee00..889821a6 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright (C) 2018-2019 Huawei. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +30,13 @@ import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.controller.domain.PostReturnBody;
import org.onap.datalake.feeder.domain.Db;
+import org.onap.datalake.feeder.domain.DbType;
+import org.onap.datalake.feeder.domain.DesignType;
import org.onap.datalake.feeder.domain.Topic;
import org.onap.datalake.feeder.dto.DbConfig;
import org.onap.datalake.feeder.repository.DbRepository;
+import org.onap.datalake.feeder.repository.DbTypeRepository;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
import org.onap.datalake.feeder.service.DbService;
import org.onap.datalake.feeder.util.TestUtil;
import org.springframework.validation.BindingResult;
@@ -62,11 +67,20 @@ public class DbControllerTest {
private DbRepository dbRepository;
@Mock
+ private DbTypeRepository dbTypeRepository;
+
+ @Mock
+ private DesignTypeRepository designTypeRepository;
+
+ @Mock
private BindingResult mockBindingResult;
@InjectMocks
private DbService dbService1;
-
+
+ @InjectMocks
+ private DbController dbController;
+
public DbConfig getDbConfig() {
DbConfig dbConfig = new DbConfig();
dbConfig.setId(1);
@@ -77,16 +91,16 @@ public class DbControllerTest {
dbConfig.setDatabase("Elecsticsearch");
dbConfig.setPort(123);
dbConfig.setPoperties("driver");
- dbConfig.setDbTypeId("ES");
+ dbConfig.setDbTypeId("ES");
return dbConfig;
}
public void setAccessPrivateFields(DbController dbController) throws NoSuchFieldException,
- IllegalAccessException {
- Field dbRepository1 = dbController.getClass().getDeclaredField("dbRepository");
- dbRepository1.setAccessible(true);
- dbRepository1.set(dbController, dbRepository);
- }
+ IllegalAccessException {
+ Field dbRepository1 = dbController.getClass().getDeclaredField("dbRepository");
+ dbRepository1.setAccessible(true);
+ dbRepository1.set(dbController, dbRepository);
+ }
@Before
public void setupTest() {
@@ -101,7 +115,7 @@ public class DbControllerTest {
DbController dbController = new DbController();
DbConfig dbConfig = getDbConfig();
setAccessPrivateFields(dbController);
- PostReturnBody<DbConfig> db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
+ PostReturnBody < DbConfig > db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
assertEquals(200, db.getStatusCode());
when(mockBindingResult.hasErrors()).thenReturn(true);
db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
@@ -113,8 +127,8 @@ public class DbControllerTest {
DbController dbController = new DbController();
DbConfig dbConfig = getDbConfig();
when(mockBindingResult.hasErrors()).thenReturn(true);
- PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult,
- httpServletResponse);
+ PostReturnBody < DbConfig > db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult,
+ httpServletResponse);
assertEquals(null, db);
//when(mockBindingResult.hasErrors()).thenReturn(false);
setAccessPrivateFields(dbController);
@@ -135,12 +149,12 @@ public class DbControllerTest {
DbController dbController = new DbController();
String name = "Elecsticsearch";
int testId = 1234;
- List<Db> dbs = new ArrayList<>();
+ List < Db > dbs = new ArrayList < > ();
dbs.add(TestUtil.newDb(name));
setAccessPrivateFields(dbController);
when(dbRepository.findAll()).thenReturn(dbs);
- List<Integer> list = dbController.list();
- for (int id : list) {
+ List < Integer > list = dbController.list();
+ for (int id: list) {
assertNotEquals(1234, id);
}
//dbController.deleteDb("Elecsticsearch", httpServletResponse);
@@ -155,18 +169,18 @@ public class DbControllerTest {
Topic topic = TestUtil.newTopic(topicName);
topic.setEnabled(true);
topic.setId(1);
- Set<Topic> topics = new HashSet<>();
+ Set < Topic > topics = new HashSet < > ();
topics.add(topic);
Db db1 = TestUtil.newDb(dbName);
db1.setTopics(topics);
setAccessPrivateFields(dbController);
- Set<Topic> elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse);
+ Set < Topic > elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse);
assertEquals(Collections.emptySet(), elecsticsearch);
when(dbRepository.findByName(dbName)).thenReturn(db1);
elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse);
- for (Topic anElecsticsearch : elecsticsearch) {
- Topic tmp = TestUtil.newTopic(topicName);
- tmp.setId(2);
+ for (Topic anElecsticsearch: elecsticsearch) {
+ Topic tmp = TestUtil.newTopic(topicName);
+ tmp.setId(2);
assertNotEquals(tmp, anElecsticsearch);
}
//dbController.deleteDb(dbName, httpServletResponse);
@@ -177,7 +191,7 @@ public class DbControllerTest {
DbController dbController = new DbController();
DbConfig dbConfig = getDbConfig();
setAccessPrivateFields(dbController);
- PostReturnBody<DbConfig> db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
+ PostReturnBody < DbConfig > db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
assertNotNull(db);
}
@@ -185,8 +199,102 @@ public class DbControllerTest {
public void testVerifyConnection() throws IOException {
DbController dbController = new DbController();
DbConfig dbConfig = getDbConfig();
- PostReturnBody<DbConfig> dbConfigPostReturnBody = dbController.verifyDbConnection(dbConfig, httpServletResponse);
+ PostReturnBody < DbConfig > dbConfigPostReturnBody = dbController.verifyDbConnection(dbConfig, httpServletResponse);
assertEquals(null, dbConfigPostReturnBody);
}
+ @Test
+ public void testDeleteDbNull() throws IOException {
+ Optional < Db > dbOptional = Optional.ofNullable(null);
+ when(dbRepository.findById(1)).thenReturn(dbOptional);
+ dbController.deleteDb(1, httpServletResponse);
+ }
+
+ @Test
+ public void deleteDbTest() throws IOException {
+ Db db = TestUtil.newDb("Elecsticsearch");
+ Topic topic = TestUtil.newTopic("Elecsticsearch");
+ topic.setEnabled(true);
+ topic.setId(1);
+ Set < Topic > topics = new HashSet < > ();
+ topics.add(topic);
+ db.setTopics(topics);
+ Optional < Db > dbOptional = Optional.ofNullable(db);
+ when(dbRepository.findById(1)).thenReturn(dbOptional);
+ dbController.deleteDb(1, httpServletResponse);
+ }
+
+ @Test
+ public void testUpdateDbNull() throws IOException {
+ DbConfig dbConfig = getDbConfig();
+ Db db = TestUtil.newDb("Elecsticsearch");
+ Optional < Db > dbOptional = Optional.ofNullable(db);
+ when(dbRepository.findById(dbConfig.getId())).thenReturn(dbOptional);
+ dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void testDblistByTool() {
+ List < DbType > dbTypeList = new ArrayList < > ();
+ DbType dbType = new DbType("ES", "Elasticsearch");
+ Set < Db > dbs = new HashSet < > ();
+ dbs.add(TestUtil.newDb("MongoDB"));
+ dbType.setDbs(dbs);
+ dbTypeList.add(dbType);
+ when(dbTypeRepository.findByTool(false)).thenReturn(dbTypeList);
+ dbController.dblistByTool(true);
+ }
+
+ @Test
+ public void testListIdAndName() {
+ DesignType designType = new DesignType();
+ DbType dbType = new DbType("ES", "Elasticsearch");
+ Set < Db > dbs = new HashSet < > ();
+ dbs.add(TestUtil.newDb("MongoDB"));
+ dbType.setDbs(dbs);
+ designType.setName("Kibana");
+ designType.setDbType(dbType);
+ when(designTypeRepository.findById("1")).thenReturn(Optional.of(designType));
+ dbController.listIdAndName("1");
+ }
+
+ @Test
+ public void testCreateDbError() throws IOException {
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ assertEquals(null, dbController.createDb(getDbConfig(), mockBindingResult, httpServletResponse));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testCreateDbException() throws IOException {
+ DbConfig dbConfig = getDbConfig();
+ dbConfig.setDbTypeId("");
+ dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void createDbTest() throws IOException {
+ DbConfig dbConfig = getDbConfig();
+ DbType dbType = new DbType("ES", "Elasticsearch");
+ when(dbTypeRepository.findById(dbConfig.getDbTypeId())).thenReturn(Optional.of(dbType));
+ dbController.createDb(dbConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void testGetDb() throws IOException {
+ DbConfig elecsticsearch = dbController.getDb(1, httpServletResponse);
+ assertEquals(null, elecsticsearch);
+ }
+
+ @Test
+ public void testGetDbTypes() throws IOException {
+ List < DbType > dbTypeList = new ArrayList < > ();
+ DbType dbType = new DbType("ES", "Elasticsearch");
+ Set < Db > dbs = new HashSet < > ();
+ dbs.add(TestUtil.newDb("MongoDB"));
+ dbType.setDbs(dbs);
+ dbTypeList.add(dbType);
+ when(dbTypeRepository.findAll()).thenReturn(dbTypeList);
+ dbController.getDbTypes(httpServletResponse);
+ }
+
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java
index 4b933bee..ca670998 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,10 +30,12 @@ import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.controller.domain.PostReturnBody;
-import org.onap.datalake.feeder.domain.*;
import org.onap.datalake.feeder.domain.Design;
+import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.domain.TopicName;
import org.onap.datalake.feeder.dto.DesignConfig;
import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
import org.onap.datalake.feeder.repository.DesignRepository;
import org.onap.datalake.feeder.service.DesignService;
import org.onap.datalake.feeder.service.TopicService;
@@ -46,12 +49,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DesignControllerTest {
-
+
//static String Kibana_Dashboard_Import_Api = "/api/kibana/dashboards/import?exclude=index-pattern";
@Mock
@@ -72,9 +77,14 @@ public class DesignControllerTest {
@Mock
private DesignTypeRepository designTypeRepository;
- @InjectMocks
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @Mock
private DesignService designService;
+ @InjectMocks
+ private DesignController testDesignController;
@Before
public void setupTest() {
@@ -85,40 +95,82 @@ public class DesignControllerTest {
@Test
public void testCreateDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
- DesignController testDesignController = new DesignController();
- setAccessPrivateFields(testDesignController);
Design testDesign = fillDomain();
+ DesignConfig designConfig = new DesignConfig();
+ when(designService.fillDesignConfiguration(designConfig)).thenReturn(testDesign);
+ testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void testCreateDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+ DesignConfig designConfig = new DesignConfig();
+ when(designService.fillDesignConfiguration(designConfig)).thenThrow(NullPointerException.class);
+ testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse);
+ }
+
+ @Test
+ public void testCreateDesignError() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+ DesignConfig designConfig = new DesignConfig();
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ assertEquals(null, testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+ Design testDesign = fillDomain();
+ Integer id = 1;
//when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
-// when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType()));
- PostReturnBody<DesignConfig> postPortal = testDesignController.createDesign(testDesign.getDesignConfig(), mockBindingResult, httpServletResponse);
+ // when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType()));
+ PostReturnBody < DesignConfig > postPortal = testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse);
//assertEquals(postPortal.getStatusCode(), 200);
assertNull(postPortal);
}
@Test
+ public void testUpdateDesignError() throws NoSuchFieldException, IllegalAccessException, IOException {
+ Design testDesign = fillDomain();
+ Integer id = 1;
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ assertEquals(null, testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse));
+ }
+
+ @Test
public void testUpdateDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
+ Design testDesign = fillDomain();
+ Integer id = 1;
+ when(designService.getDesign(id)).thenReturn(testDesign);
+ testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse);
+ }
- DesignController testDesignController = new DesignController();
- setAccessPrivateFields(testDesignController);
+ @Test
+ public void testUpdateDesignException() throws NoSuchFieldException, IllegalAccessException, IOException {
Design testDesign = fillDomain();
+ DesignConfig designConfig = new DesignConfig();
Integer id = 1;
- when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
- //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT"));
- // when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType()));
- PostReturnBody<DesignConfig> postPortal = testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse);
- //assertEquals(postPortal.getStatusCode(), 200);
- assertNull(postPortal);
+ when(designService.getDesign(id)).thenReturn(testDesign);
+ doThrow(NullPointerException.class).when(designService).fillDesignConfiguration(designConfig, testDesign);
+ testDesignController.updateDesign(designConfig, mockBindingResult, id, httpServletResponse);
+ }
+
+ @Test
+ public void testDeleteDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+ Design testDesign = fillDomain();
+ Integer id = 1;
+ testDesign.setId(1);
+ testDesignController.deleteDesign(id, httpServletResponse);
}
@Test
public void testDeleteDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
- DesignController testDesignController = new DesignController();
- setAccessPrivateFields(testDesignController);
Design testDesign = fillDomain();
Integer id = 1;
testDesign.setId(1);
- when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
+ when(designService.getDesign(id)).thenReturn(testDesign);
testDesignController.deleteDesign(id, httpServletResponse);
}
@@ -128,22 +180,27 @@ public class DesignControllerTest {
DesignController testDesignController = new DesignController();
setAccessPrivateFields(testDesignController);
Design testDesign = fillDomain();
- List<Design> designList = new ArrayList<>();
+ List < Design > designList = new ArrayList < > ();
designList.add(testDesign);
- when(designRepository.findAll()).thenReturn(designList);
- assertEquals(1, testDesignController.queryAllDesign().size());
+ assertEquals(0, testDesignController.queryAllDesign().size());
+ }
+
+ @Test
+ public void testDeployDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException {
+
+ Design testDesign = fillDomain();
+ Integer id = 1;
+ testDesign.setId(1);
+ testDesignController.deployDesign(id, httpServletResponse);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testDeployDesign() throws NoSuchFieldException, IllegalAccessException, IOException {
- DesignController testDesignController = new DesignController();
- setAccessPrivateFields(testDesignController);
Design testDesign = fillDomain();
Integer id = 1;
testDesign.setId(1);
- //when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn(Kibana_Dashboard_Import_Api);
- when(designRepository.findById(id)).thenReturn((Optional.of(testDesign)));
+ when(designRepository.findById(id)).thenReturn(Optional.of(new Design()));
testDesignController.deployDesign(id, httpServletResponse);
}
@@ -158,16 +215,18 @@ public class DesignControllerTest {
}
- public Design fillDomain(){
+ public Design fillDomain() {
Design design = new Design();
+ design.setId(1);
design.setName("Kibana");
design.setBody("jsonString");
design.setSubmitted(false);
design.setNote("test");
DesignType designType = new DesignType();
+ designType.setId("1");
designType.setName("Kibana Dashboard");
design.setDesignType(designType);
design.setTopicName(new TopicName("unauthenticated.SEC_FAULT_OUTPUT"));
return design;
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java
index 91af11ca..531b0b28 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,50 +25,51 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.dto.DesignTypeConfig;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
import org.onap.datalake.feeder.service.DesignTypeService;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DesignTypeControllerTest {
- @InjectMocks
+ @Mock
+ private DesignTypeRepository designTypeRepository;
+
+ @Mock
private DesignTypeService designTypeService;
+ @InjectMocks
+ private DesignTypeController designTypeController;
+
@Before
public void setupTest() {
MockitoAnnotations.initMocks(this);
}
- @Test(expected = NullPointerException.class)
- public void getTemplateTypeName() throws NoSuchFieldException, IllegalAccessException {
-
- DesignTypeController testDesignTypeController = new DesignTypeController();
- setAccessPrivateFields(testDesignTypeController);
- DesignType testDesignType = fillDomain();
- List<String> designTypeNamesList = new ArrayList<>();
- designTypeNamesList.add(testDesignType.getName());
- assertEquals(1, testDesignTypeController.getDesignType().size());
- }
-
- public void setAccessPrivateFields(DesignTypeController designTypeController) throws NoSuchFieldException, IllegalAccessException {
-
- Field testDesignTypeService = designTypeController.getClass().getDeclaredField("designTypeService");
- testDesignTypeService.setAccessible(true);
- testDesignTypeService.set(designTypeController, designTypeService);
- }
-
-
- public DesignType fillDomain(){
+ public DesignType fillDomain() {
DesignType designType = new DesignType();
designType.setName("Kibana Dashboard");
return designType;
}
-} \ No newline at end of file
+
+ @Test
+ public void testGetDesignType() {
+ List < DesignTypeConfig > designTypeNamesList = new ArrayList < > ();
+ List < DesignType > designTypeList = new ArrayList < > ();
+ DesignType designType = fillDomain();
+ designTypeList.add(designType);
+ when(designTypeService.getDesignTypes()).thenReturn(designTypeNamesList);
+ assertNotNull(designTypeController.getDesignType());
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
index 06aa61db..fd685fef 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +36,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -68,17 +70,74 @@ public class KafkaControllerTest {
when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null).thenReturn(kafka);
when(kafkaRepository.save(kafka)).thenReturn(null);
when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenReturn(kafka);
- when(mockBindingResult.hasErrors()).thenReturn(false,true,false,true);
+ when(mockBindingResult.hasErrors()).thenReturn(false, true, false, true);
- kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
- kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse);
+ kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse);
+ kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse);
- kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
- kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse);
+ kafkaController.updateKafka(kafkaConfig, mockBindingResult, id, httpServletResponse);
+ kafkaController.updateKafka(kafkaConfig, mockBindingResult, id, httpServletResponse);
- kafkaController.deleteKafka(id,httpServletResponse);
+ kafkaController.deleteKafka(id, httpServletResponse);
when(kafkaService.getAllKafka()).thenReturn(null);
kafkaController.queryAllKafka();
}
-} \ No newline at end of file
+
+ @Test
+ public void testCreateKafkaNull() throws IOException {
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ kafkaConfig.setId(1);
+ kafkaConfig.setName("123");
+ when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(kafka);
+ assertEquals(null, kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testCreateKafkaException() throws IOException {
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ kafkaConfig.setId(1);
+ kafkaConfig.setName("123");
+ when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null);
+ when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenThrow(NullPointerException.class);
+ assertEquals(null, kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateKafkaNull() throws IOException {
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ kafkaConfig.setId(1);
+ kafkaConfig.setName("123");
+ when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null);
+ assertEquals(null, kafkaController.updateKafka(kafkaConfig, mockBindingResult, 1, httpServletResponse));
+ }
+
+ @Test
+ public void testUpdateKafkaException() throws IOException {
+ KafkaConfig kafkaConfig = new KafkaConfig();
+ kafkaConfig.setId(1);
+ kafkaConfig.setName("123");
+ when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(kafka);
+ doThrow(NullPointerException.class).when(kafkaService).fillKafkaConfiguration(kafkaConfig, kafka);
+ assertEquals(null, kafkaController.updateKafka(kafkaConfig, mockBindingResult, 1, httpServletResponse));
+ }
+
+ @Test
+ public void testDeleteKafkaNull() throws IOException {
+ when(kafkaService.getKafkaById(1)).thenReturn(null);
+ kafkaController.deleteKafka(1, httpServletResponse);
+ }
+
+ @Test
+ public void testGetKafkaDetailNull() throws IOException {
+ when(kafkaService.getKafkaById(1)).thenReturn(null);
+ kafkaController.getKafkaDetail(1, httpServletResponse);
+ }
+
+ @Test
+ public void testGetKafkaDetail() throws IOException {
+ when(kafkaService.getKafkaById(1)).thenReturn(kafka);
+ assertEquals(null, kafkaController.getKafkaDetail(1, httpServletResponse));
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
index 988010ec..17107120 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright (C) 2018-2019 Huawei. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,145 +28,185 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.controller.domain.PostReturnBody;
+import org.onap.datalake.feeder.domain.Kafka;
import org.onap.datalake.feeder.domain.Topic;
import org.onap.datalake.feeder.dto.TopicConfig;
+import org.onap.datalake.feeder.repository.KafkaRepository;
import org.onap.datalake.feeder.repository.TopicNameRepository;
import org.onap.datalake.feeder.repository.TopicRepository;
import org.onap.datalake.feeder.service.DbService;
import org.onap.datalake.feeder.service.DmaapService;
import org.onap.datalake.feeder.service.TopicService;
import org.onap.datalake.feeder.util.TestUtil;
+import org.springframework.context.ApplicationContext;
import org.springframework.validation.BindingResult;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class TopicControllerTest {
- static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
+ static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
- @Mock
- private HttpServletResponse httpServletResponse;
+ @Mock
+ private HttpServletResponse httpServletResponse;
- @Mock
- private BindingResult mockBindingResult;
+ @Mock
+ private BindingResult mockBindingResult;
- @Mock
- private TopicRepository topicRepository;
+ @Mock
+ private TopicRepository topicRepository;
- @Mock
- private TopicService topicService;
+ @Mock
+ private TopicService topicService;
- @Mock
- private TopicNameRepository topicNameRepository;
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @Mock
+ private KafkaRepository kafkaRepository;
+
+ @InjectMocks
+ TopicController topicController;
+
+ @Mock
+ private ApplicationConfiguration config;
+
+ @Mock
+ private ApplicationContext context;
+
+ @Mock
+ private DbService dbService;
+
+ @Mock
+ private DmaapService dmaapService;
+
+ @Before
+ public void setupTest() throws NoSuchFieldException, IllegalAccessException {
+ // While the default boolean return value for a mock is 'false',
+ // it's good to be explicit anyway:
+ when(mockBindingResult.hasErrors()).thenReturn(false);
+ }
+
+ @Test
+ public void testListTopic() throws IOException, NoSuchFieldException, IllegalAccessException {}
+
+ @Test
+ public void testCreateTopic() throws IOException {
+ Topic a = TestUtil.newTopic("a");
+ a.setId(1);
+ a.setEnabled(true);
+
+ TopicConfig ac = a.getTopicConfig();
+
+ when(topicService.fillTopicConfiguration(ac)).thenReturn(a);
+ PostReturnBody < TopicConfig > postTopic = topicController.createTopic(ac, mockBindingResult, httpServletResponse);
+ assertEquals(postTopic.getStatusCode(), 200);
+
+ when(topicService.fillTopicConfiguration(ac)).thenReturn(a);
+ a.setTtl(0);
+ PostReturnBody < TopicConfig > postTopicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse);
+ assertEquals(postTopicConfig.getStatusCode(), 200);
+
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ PostReturnBody < TopicConfig > topicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse);
+ assertEquals(null, topicConfig);
+ }
+
+ @Test
+ public void testUpdateTopic() throws IOException {
+ Topic a = TestUtil.newTopic("a");
+ a.setId(1);
+ a.setEnabled(true);
+
+ TopicConfig ac = a.getTopicConfig();
+
+ when(topicService.getTopic(1)).thenReturn(a);
+ PostReturnBody < TopicConfig > postConfig1 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
+ assertEquals(200, postConfig1.getStatusCode());
+ TopicConfig ret = postConfig1.getReturnBody();
+ assertEquals("a", ret.getName());
+ assertEquals(true, ret.isEnabled());
+
+ topicController.updateTopic(0, ac, mockBindingResult, httpServletResponse);
+
+ when(topicService.getTopic(1)).thenReturn(null);
+ topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
+
+ when(mockBindingResult.hasErrors()).thenReturn(true);
+ PostReturnBody < TopicConfig > postConfig2 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
+ assertNull(postConfig2);
+
+ }
+
+ @Test
+ public void testGetTopic() throws IOException {
+ Topic a = TestUtil.newTopic("a");
+ a.setId(1);
+ a.setEnabled(true);
+
+ when(topicService.getTopic(1)).thenReturn(a);
+ TopicConfig ac = topicController.getTopic(1, httpServletResponse);
+ when(topicService.getTopic(1)).thenReturn(null);
+ ac = topicController.getTopic(1, httpServletResponse);
+ }
+
+ @Test
+ public void testDeleteTopic() throws IOException {
+ Topic a = TestUtil.newTopic("a");
+ a.setId(1);
+ a.setEnabled(true);
+
+ when(topicService.getTopic(1)).thenReturn(a);
+ topicController.deleteTopic(1, httpServletResponse);
+ when(topicService.getTopic(1)).thenReturn(null);
+ topicController.deleteTopic(1, httpServletResponse);
+ }
+
+ @Test
+ public void testList() {
+ ArrayList < Topic > topics = new ArrayList < > ();
+ topics.add(TestUtil.newTopic("a"));
+ topics.add(TestUtil.newTopic(DEFAULT_TOPIC_NAME));
+ when(topicRepository.findAll()).thenReturn(topics);
+
+ List < Integer > ids = topicController.list();
+ for (Integer topic: ids) {
+ System.out.println(topic);
+ }
+ }
+
+ @Test
+ public void testGetDefaultConfigNull() throws IOException {
+ Topic topic = null;
+ when(topicService.getDefaultTopicFromFeeder()).thenReturn(topic);
+ assertEquals(null, topicController.getDefaultConfig(httpServletResponse));
+ }
+
+ @Test
+ public void testGetDefaultConfig() throws IOException {
+ Topic topic = TestUtil.newTopic(DEFAULT_TOPIC_NAME);
+ when(topicService.getDefaultTopicFromFeeder()).thenReturn(topic);
+ assertEquals(topic.getName(), topicController.getDefaultConfig(httpServletResponse).getName());
+ }
+
+ @Test
+ public void testListDmaapTopics() {
+ Kafka kafka = TestUtil.newKafka("test");
+ when(kafkaRepository.findById(1)).thenReturn(Optional.of(kafka));
+ DmaapService dmaapService = mock(DmaapService.class);
+ when(context.getBean(DmaapService.class, kafka)).thenReturn(dmaapService);
+ when(dmaapService.getTopics()).thenReturn(null);
+ assertEquals(null, topicController.listDmaapTopics(1));
+ }
- @InjectMocks
- TopicController topicController;
-
- @Mock
- private ApplicationConfiguration config;
-
- @Mock
- private DbService dbService;
-
- @Mock
- private DmaapService dmaapService;
-
- @Before
- public void setupTest() throws NoSuchFieldException, IllegalAccessException {
- // While the default boolean return value for a mock is 'false',
- // it's good to be explicit anyway:
- when(mockBindingResult.hasErrors()).thenReturn(false);
- }
-
- @Test
- public void testListTopic() throws IOException, NoSuchFieldException, IllegalAccessException {
- }
-
- @Test
- public void testCreateTopic() throws IOException {
- Topic a = TestUtil.newTopic("a");
- a.setId(1);
- a.setEnabled(true);
-
- TopicConfig ac = a.getTopicConfig();
-
- when(topicService.fillTopicConfiguration(ac)).thenReturn(a);
- PostReturnBody<TopicConfig> postTopic = topicController.createTopic(ac, mockBindingResult, httpServletResponse);
- assertEquals(postTopic.getStatusCode(), 200);
-
- when(mockBindingResult.hasErrors()).thenReturn(true);
- PostReturnBody<TopicConfig> topicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse);
- assertEquals(null, topicConfig);
- }
-
- @Test
- public void testUpdateTopic() throws IOException {
- Topic a = TestUtil.newTopic("a");
- a.setId(1);
- a.setEnabled(true);
-
- TopicConfig ac = a.getTopicConfig();
-
- when(topicService.getTopic(1)).thenReturn(a);
- PostReturnBody<TopicConfig> postConfig1 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
- assertEquals(200, postConfig1.getStatusCode());
- TopicConfig ret = postConfig1.getReturnBody();
- assertEquals("a", ret.getName());
- assertEquals(true, ret.isEnabled());
-
- topicController.updateTopic(0, ac, mockBindingResult, httpServletResponse);
-
- when(topicService.getTopic(1)).thenReturn(null);
- topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
-
- when(mockBindingResult.hasErrors()).thenReturn(true);
- PostReturnBody<TopicConfig> postConfig2 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse);
- assertNull(postConfig2);
-
- }
-
- @Test
- public void testGetTopic() throws IOException {
- Topic a = TestUtil.newTopic("a");
- a.setId(1);
- a.setEnabled(true);
-
- when(topicService.getTopic(1)).thenReturn(a);
- TopicConfig ac = topicController.getTopic(1, httpServletResponse);
- when(topicService.getTopic(1)).thenReturn(null);
- ac = topicController.getTopic(1, httpServletResponse);
- }
-
- @Test
- public void testDeleteTopic() throws IOException {
- Topic a = TestUtil.newTopic("a");
- a.setId(1);
- a.setEnabled(true);
-
- when(topicService.getTopic(1)).thenReturn(a);
- topicController.deleteTopic(1, httpServletResponse);
- when(topicService.getTopic(1)).thenReturn(null);
- topicController.deleteTopic(1, httpServletResponse);
- }
-
- @Test
- public void testList() {
- ArrayList<Topic> topics = new ArrayList<>();
- topics.add(TestUtil.newTopic("a"));
- topics.add(TestUtil.newTopic(DEFAULT_TOPIC_NAME));
- when(topicRepository.findAll()).thenReturn(topics);
-
- List<Integer> ids = topicController.list();
- for (Integer topic : ids) {
- System.out.println(topic);
- }
- }
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java
new file mode 100644
index 00000000..9ac5f1b3
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java
@@ -0,0 +1,67 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright (C) 2022 Wipro Limited.
+ * =================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.datalake.feeder.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.domain.Topic;
+import org.onap.datalake.feeder.domain.TopicName;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TopicNameControllerTest {
+
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @InjectMocks
+ TopicNameController topicNameController;
+
+ @Test
+ public void testList() throws IOException {
+ List < TopicName > topicNameList = new ArrayList < > ();
+
+ TopicName topicName = new TopicName();
+ topicName.setId("1");
+ topicName.setDesigns(null);
+ Topic topic = new Topic();
+ topic.setId(1);
+ Set < Topic > topics = new HashSet < > ();
+ topics.add(topic);
+ topicName.setTopics(topics);
+ topicNameList.add(topicName);
+
+ when(topicNameRepository.findAll()).thenReturn(topicNameList);
+ List < String > retString = topicNameController.list();
+ assertEquals("1", retString.get(0));
+
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java
index 4a75df17..11432e16 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,20 +20,23 @@
*/
package org.onap.datalake.feeder.domain;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class DbTypeTest {
@Test
- public void test(){
- DbType dbType = new DbType("ES","Elasticsearch");
-
+ public void test() {
+ DbType dbType = new DbType("ES", "Elasticsearch");
+
DbType dbType2 = new DbType("MONGO", "MongoDB");
- dbType.setTool(false);
-
+ dbType.setTool(false);
+
assertNotNull(dbType.toString());
assertEquals(dbType, dbType);
@@ -44,10 +48,10 @@ public class DbTypeTest {
assertEquals("MongoDB", dbType2.getName());
dbType2.setName(null);
dbType2.setDefaultPort(1);
- assertTrue(1==dbType2.getDefaultPort());
+ assertTrue(1 == dbType2.getDefaultPort());
dbType2.setDbs(null);
assertNull(dbType2.getDbs());
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java
index de6fec27..efc49bf9 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +21,12 @@
package org.onap.datalake.feeder.domain;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.datalake.feeder.util.TestUtil;
-import static org.junit.Assert.*;
-
public class DesignTest {
@Test
@@ -53,4 +55,4 @@ public class DesignTest {
assertNull(design.getDbs());
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java
index e02c2d1c..da1c5ec1 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +21,9 @@
package org.onap.datalake.feeder.domain;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class DesignTypeTest {
@Test
@@ -40,4 +40,4 @@ public class DesignTypeTest {
designType.getDesigns();
designType.getDesignTypeConfig();
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java
index 22ebe4f1..6b0b006f 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +21,13 @@
package org.onap.datalake.feeder.dto;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
import org.onap.datalake.feeder.domain.Design;
import org.onap.datalake.feeder.domain.DesignType;
import org.onap.datalake.feeder.domain.TopicName;
-import static org.junit.Assert.*;
-
public class DesignConfigTest {
@Test
@@ -58,4 +59,4 @@ public class DesignConfigTest {
assertEquals(testDesignConfig.getDesignType(), null);
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java
new file mode 100644
index 00000000..a7253ae8
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright (C) 2022 Wipro Limited.
+ * =================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.datalake.feeder.dto;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class DesignTypeConfigTest {
+
+ @Test
+ public void testDesignTypeConfig() {
+ DesignTypeConfig designTypeConfig = new DesignTypeConfig();
+ designTypeConfig.setId("123");
+ designTypeConfig.setName("test");
+ assertEquals("123", designTypeConfig.getId());
+ assertEquals("test", designTypeConfig.getName());
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
index b2104177..2d38f532 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,12 +20,12 @@
*/
package org.onap.datalake.feeder.dto;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
import org.onap.datalake.feeder.domain.Kafka;
import org.onap.datalake.feeder.util.TestUtil;
-import static org.junit.Assert.*;
-
/**
* Test Kafka
*
@@ -76,4 +77,4 @@ public class KafkaConfigTest {
assertNotEquals(null, testKafkaConfig.getTimeout());
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java
index 65b373f5..cdc8c42a 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DCAE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +26,27 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.Db;
import org.onap.datalake.feeder.domain.Design;
import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.domain.TopicName;
+import org.onap.datalake.feeder.dto.DesignConfig;
+import org.onap.datalake.feeder.repository.DbRepository;
+import org.onap.datalake.feeder.repository.DesignRepository;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+import org.onap.datalake.feeder.util.TestUtil;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
@RunWith(MockitoJUnitRunner.class)
public class DesignServiceTest {
@@ -37,14 +54,26 @@ public class DesignServiceTest {
private DesignType designType;
@Mock
+ private DesignRepository designRepository;
+
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @Mock
+ private DbRepository dbRepository;
+
+ @Mock
private ApplicationConfiguration applicationConfiguration;
+ @Mock
+ private DesignTypeRepository designTypeRepository;
+
@InjectMocks
private DesignService designService;
@Test(expected = RuntimeException.class)
- public void testDeploy() {
- when(designType.getId()).thenReturn("KIBANA_DB","ES_MAPPING");
+ public void testDeployException() {
+ when(designType.getId()).thenReturn("KIBANA_DB", "ES_MAPPING");
Design design = new Design();
design.setDesignType(designType);
design.setBody("jsonString");
@@ -53,4 +82,96 @@ public class DesignServiceTest {
designService.deploy(design);
System.out.println();
}
-} \ No newline at end of file
+
+ @Test
+ public void testFillDesignConfigurationNull() {
+ DesignConfig designConfig = new DesignConfig();
+ designConfig.setTopicName("topic");
+ designConfig.setDesignType("designType");
+ TopicName topicName = new TopicName("test");
+ Optional < TopicName > topicNameOptional = Optional.of(topicName);
+ when(topicNameRepository.findById(designConfig.getTopicName())).thenReturn(topicNameOptional);
+ when(designTypeRepository.findById(designConfig.getDesignType())).thenReturn(Optional.of(new DesignType()));
+ assertNull(designService.fillDesignConfiguration(designConfig).getName());
+ }
+
+ @Test
+ public void testFillDesignConfiguration() {
+ DesignConfig designConfig = new DesignConfig();
+ designConfig.setTopicName("topic");
+ designConfig.setDesignType("designType");
+
+ List < Integer > dbs = new ArrayList < > ();
+ dbs.add(1);
+ designConfig.setDbs(dbs);
+ when(topicNameRepository.findById(designConfig.getTopicName())).thenReturn(Optional.of(new TopicName()));
+ when(designTypeRepository.findById(designConfig.getDesignType())).thenReturn(Optional.of(new DesignType()));
+ when(dbRepository.findById(designConfig.getDbs().get(0))).thenReturn(Optional.of(new Db()));
+ designService.fillDesignConfiguration(designConfig).getName();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testFillDesign() {
+ Design design = new Design();
+ design.setDesignType(designType);
+ DesignConfig designConfig = new DesignConfig();
+ designService.fillDesignConfiguration(designConfig, design);
+ }
+
+ @Test
+ public void testGetDesignNull() {
+ Optional < Design > testDesign = Optional.ofNullable(null);
+ when(designRepository.findById(1)).thenReturn(testDesign);
+ assertNull(designService.getDesign(1));
+ }
+
+ @Test
+ public void testDeploy() {
+ when(designType.getId()).thenReturn("KIBANA_DB");
+ Design design = getDesign();
+ assertNotNull(designService.deploy(design));
+ }
+
+ @Test
+ public void testDeployESMappingCase() {
+ when(designType.getId()).thenReturn("ES_MAPPING");
+ Design design = getDesign();
+ assertNotNull(designService.deploy(design));
+ }
+
+ @Test
+ public void testDeployDefault() {
+ when(designType.getId()).thenReturn("KIBANA_SEARCH");
+ Design design = getDesign();
+ assertNull(designService.deploy(design));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testQueryAllDesignNull() {
+ when(designRepository.findAll()).thenReturn(null);
+ designService.queryAllDesign();
+ }
+
+ @Test
+ public void testQueryAllDesign() {
+ List < Design > designList = new ArrayList < > ();
+ Design design = getDesign();
+ designList.add(design);
+ when(designRepository.findAll()).thenReturn(designList);
+ designService.queryAllDesign();
+ }
+
+ public Design getDesign() {
+ Design design = new Design();
+ design.setDesignType(designType);
+ design.setBody("jsonString");
+ design.setTopicName(new TopicName("1"));
+ Set < Db > dbs = new HashSet < > ();
+ Db db = TestUtil.newDb("MongoDB");
+ db.setEnabled(true);
+ dbs.add(db);
+ design.setDbs(dbs);
+ return design;
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java
index 5879deb6..28c84750 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DataLake
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,13 +26,11 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.domain.DesignType;
-import org.onap.datalake.feeder.dto.DesignTypeConfig;
import org.onap.datalake.feeder.repository.DesignTypeRepository;
-
import java.util.ArrayList;
import java.util.List;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -44,16 +43,19 @@ public class DesignTypeServiceTest {
private DesignTypeService designTypeService;
@Test
- public void testDesignTypeService(){
- List<DesignType> designTypeList = new ArrayList<>();
+ public void testDesignTypeService() {
+ List < DesignType > designTypeList = new ArrayList < > ();
DesignType designType = new DesignType();
designType.setName("test");
- //DesignTypeConfig designTypeConfig = new DesignTypeConfig();
- //designTypeConfig.setDesignType("test");
- //designTypeConfig.setDisplay("test");
designTypeList.add(designType);
when(designTypeRepository.findAll()).thenReturn(designTypeList);
assertNotNull(designTypeService.getDesignTypes());
}
-} \ No newline at end of file
+ @Test
+ public void testDesignTypeServiceNull() {
+ when(designTypeRepository.findAll()).thenReturn(null);
+ assertEquals(0, designTypeService.getDesignTypes().size());
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
index 0274d309..2cb0740c 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,12 +29,11 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.domain.Kafka;
import org.onap.datalake.feeder.dto.KafkaConfig;
import org.onap.datalake.feeder.repository.KafkaRepository;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -67,4 +67,4 @@ public class KafkaServiceTest {
kafkaService.fillKafkaConfiguration(kafkaConfig);
}
-} \ No newline at end of file
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java
index d6298b87..f587f358 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,74 +28,72 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.springframework.context.ApplicationContext;
-
import java.lang.reflect.Field;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class PullServiceTest {
- @InjectMocks
- private PullService pullService;
+ @InjectMocks
+ private PullService pullService;
- @Mock
- private ApplicationContext context;
+ @Mock
+ private ApplicationContext context;
- @Mock
- private ApplicationConfiguration config;
+ @Mock
+ private ApplicationConfiguration config;
- @Mock
- private ExecutorService executorService;
+ @Mock
+ private ExecutorService executorService;
- @Mock
- private List<Puller> consumers;
+ @Mock
+ private List < Puller > consumers;
- @Test
- public void isRunning() {
- assertFalse(pullService.isRunning());
- }
+ @Test
+ public void isRunning() {
+ assertFalse(pullService.isRunning());
+ }
- @Test(expected = NullPointerException.class)
- public void start() {
- setRunning(false);
- pullService.start();
- setRunning(true);
- pullService.start();
- }
+ @Test(expected = NullPointerException.class)
+ public void start() {
+ setRunning(false);
+ pullService.start();
+ setRunning(true);
+ pullService.start();
+ }
- @Test
- public void shutdown() {
- when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock());
- setRunning(false);
- pullService.shutdown();
- setRunning(true);
- pullService.shutdown();
- }
+ @Test
+ public void shutdown() {
+ when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock());
+ setRunning(false);
+ pullService.shutdown();
+ setRunning(true);
+ pullService.shutdown();
+ }
- private void setRunning(boolean running) {
- Field configField;
- try {
- configField = PullService.class.getDeclaredField("isRunning");
- configField.setAccessible(true);
- configField.set(pullService, running);
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ private void setRunning(boolean running) {
+ Field configField;
+ try {
+ configField = PullService.class.getDeclaredField("isRunning");
+ configField.setAccessible(true);
+ configField.set(pullService, running);
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
- } catch (NoSuchFieldException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-} \ No newline at end of file
+ } catch (NoSuchFieldException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java
index bd26519b..e30aa7b8 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.datalake.feeder.service;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -30,6 +32,7 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,6 +43,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.EffectiveTopic;
import org.onap.datalake.feeder.domain.Kafka;
import org.onap.datalake.feeder.util.TestUtil;
@@ -51,73 +55,87 @@ import org.onap.datalake.feeder.util.TestUtil;
*/
@RunWith(MockitoJUnitRunner.class)
public class TopicConfigPollingServiceTest {
- @Mock
- private ApplicationConfiguration config;
- @Mock
- private DmaapService dmaapService;
+ @Mock
+ private ApplicationConfiguration config;
- @InjectMocks
- private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService();
+ @Mock
+ private DmaapService dmaapService;
- static String KAFKA_NAME = "kafka1";
+ @Mock
+ private Map < Integer, Map < String, List < EffectiveTopic >>> effectiveTopicMap = new HashMap < > ();
- @Before
- public void init() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
- Method init = topicConfigPollingService.getClass().getDeclaredMethod("init");
- init.setAccessible(true);
- init.invoke(topicConfigPollingService);
+ @InjectMocks
+ private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService();
- Set<String> activeTopics = new HashSet<>(Arrays.asList("test"));
- Map<Integer, Set<String>> activeTopicMap = new HashMap<>();
- activeTopicMap.put(1, activeTopics);
+ static String KAFKA_NAME = "kafka1";
- Field activeTopicsField = TopicConfigPollingService.class.getDeclaredField("activeTopicMap");
- activeTopicsField.setAccessible(true);
- activeTopicsField.set(topicConfigPollingService, activeTopicMap);
+ @Before
+ public void init()
+ throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
+ Method init = topicConfigPollingService.getClass().getDeclaredMethod("init");
+ init.setAccessible(true);
+ init.invoke(topicConfigPollingService);
- Method initMethod = TopicConfigPollingService.class.getDeclaredMethod("init");
- initMethod.setAccessible(true);
- initMethod.invoke(topicConfigPollingService);
- }
+ Set < String > activeTopics = new HashSet < > (Arrays.asList("test"));
+ Map < Integer, Set < String >> activeTopicMap = new HashMap < > ();
+ activeTopicMap.put(1, activeTopics);
- @Test
- public void testRun() throws InterruptedException {
+ Field activeTopicsField = TopicConfigPollingService.class.getDeclaredField("activeTopicMap");
+ activeTopicsField.setAccessible(true);
+ activeTopicsField.set(topicConfigPollingService, activeTopicMap);
- when(config.getCheckTopicInterval()).thenReturn(1L);
+ Method initMethod = TopicConfigPollingService.class.getDeclaredMethod("init");
+ initMethod.setAccessible(true);
+ initMethod.invoke(topicConfigPollingService);
+ }
- Thread thread = new Thread(topicConfigPollingService);
- thread.start();
+ @Test
+ public void testRun() throws InterruptedException {
- Thread.sleep(50);
- topicConfigPollingService.shutdown();
- thread.join();
+ when(config.getCheckTopicInterval()).thenReturn(1L);
- assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
- }
+ Thread thread = new Thread(topicConfigPollingService);
+ thread.start();
- @Test
- public void testRunNoChange() throws InterruptedException {
+ Thread.sleep(50);
+ topicConfigPollingService.shutdown();
+ thread.join();
- when(config.getCheckTopicInterval()).thenReturn(1L);
+ assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
+ }
- Thread thread = new Thread(topicConfigPollingService);
- thread.start();
+ @Test
+ public void testRunNoChange() throws InterruptedException {
- Thread.sleep(50);
- topicConfigPollingService.shutdown();
- thread.join();
+ when(config.getCheckTopicInterval()).thenReturn(1L);
- assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
- }
+ Thread thread = new Thread(topicConfigPollingService);
+ thread.start();
- @Test
- public void testGet() {
- Kafka kafka = TestUtil.newKafka(KAFKA_NAME);
- kafka.setId(1);
- //assertNull(topicConfigPollingService.getEffectiveTopic (kafka, "test"));
- assertNotNull(topicConfigPollingService.getActiveTopics(kafka));
+ Thread.sleep(50);
+ topicConfigPollingService.shutdown();
+ thread.join();
- }
+ assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka()));
+ }
-} \ No newline at end of file
+ @Test
+ public void testGet() {
+ Kafka kafka = TestUtil.newKafka(KAFKA_NAME);
+ kafka.setId(1);
+ //assertNull(topicConfigPollingService.getEffectiveTopic (kafka, "test"));
+ assertNotNull(topicConfigPollingService.getActiveTopics(kafka));
+
+ }
+
+ @Test
+ public void testGetEffectiveTopic() {
+ Kafka kafka = TestUtil.newKafka(KAFKA_NAME);
+ kafka.setId(1);
+ Map < String, List < EffectiveTopic >> effectiveTopicMapKafka = new HashMap < > ();
+ when(effectiveTopicMap.get(kafka.getId())).thenReturn(effectiveTopicMapKafka);
+ assertNull(topicConfigPollingService.getEffectiveTopic(kafka, "test"));
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java
new file mode 100644
index 00000000..f040261c
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright (C) 2022 Wipro Limited.
+ * =================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.datalake.feeder.service;
+
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.domain.TopicName;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TopicNameServiceTest {
+
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @InjectMocks
+ private TopicNameService topicNameService;
+
+ @Test
+ public void testUpdate() {
+ List < TopicName > topicNameList = new ArrayList < > ();
+ topicNameList.add(new TopicName("test"));
+ Collection < String > allTopicNames = new ArrayList < > ();
+ allTopicNames.add("MONGODB");
+ when(topicNameRepository.findAll()).thenReturn(topicNameList);
+ topicNameService.update(allTopicNames);
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
index eea47501..3c03f14e 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
@@ -1,53 +1,51 @@
/*
-* ============LICENSE_START=======================================================
-* ONAP : DATALAKE
-* ================================================================================
-* Copyright 2019 China Mobile
-*=================================================================================
-* 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.
-* ============LICENSE_END=========================================================
-*/
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ * Copyright (C) 2022 Wipro Limited.
+ *=================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.datalake.feeder.service;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
-import org.elasticsearch.client.IndicesClient;
-import org.elasticsearch.client.RequestOptions;
-import org.elasticsearch.client.RestHighLevelClient;
-import org.elasticsearch.client.indices.GetIndexRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
-import org.onap.datalake.feeder.domain.*;
+import org.onap.datalake.feeder.domain.Db;
+import org.onap.datalake.feeder.domain.DbType;
+import org.onap.datalake.feeder.domain.Kafka;
+import org.onap.datalake.feeder.domain.Topic;
+import org.onap.datalake.feeder.domain.TopicName;
import org.onap.datalake.feeder.dto.TopicConfig;
-import org.onap.datalake.feeder.enumeration.DbTypeEnum;
import org.onap.datalake.feeder.repository.DbRepository;
+import org.onap.datalake.feeder.repository.KafkaRepository;
import org.onap.datalake.feeder.repository.TopicNameRepository;
import org.onap.datalake.feeder.repository.TopicRepository;
import org.onap.datalake.feeder.service.db.ElasticsearchService;
@@ -61,127 +59,210 @@ import org.onap.datalake.feeder.service.db.ElasticsearchService;
@RunWith(MockitoJUnitRunner.class)
public class TopicServiceTest {
- static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
-
- @Mock
- private ApplicationConfiguration config;
-
- @Mock
- private TopicRepository topicRepository;
-
- @Mock
- private ElasticsearchService elasticsearchService;
-
- @Mock
- private DbService dbService;
-
- @Mock
- private DbRepository dbRepository;
-
- @Mock
- private TopicNameRepository topicNameRepository;
-
- @InjectMocks
- private TopicService topicService;
-
- @Test(expected = NullPointerException.class)
- public void testGetTopic() throws IOException{
- List<Topic> topics = new ArrayList<>();
- Topic topic = new Topic();
- DbType dbType = new DbType();
- Set<Kafka> kafkas = new HashSet<>();
- Set<Db> dbs = new HashSet<>();
- Db db = new Db();
- db.setName("Elasticsearch");
- dbs.add(db);
-
- dbType.setId("ES");
- db.setDbType(dbType);
-
- Kafka kafka = new Kafka();
- kafka.setName("1234");
- kafkas.add(kafka);
-
- TopicName topicName = new TopicName();
- topicName.setId("1234");
-
- topic.setTopicName(topicName);
- topic.setKafkas(kafkas);
- topic.setEnabled(true);
- topic.setDbs(dbs);
- topics.add(topic);
- when(topicRepository.findAll()).thenReturn(topics);
- when((ElasticsearchService)dbService.findDbStoreService(db)).thenReturn(new ElasticsearchService(db));
- topicService.findTopics(kafka,topicName.getId());
- topicService.getEnabledEffectiveTopic(kafka,topicName.getId(),true);
-
- }
- @Test
- public void testGetTopicNull() {
- Topic topic = new Topic();
- TopicName topicName = new TopicName();
- topicName.setId("_DL_DEFAULT_");
- topic.setId(1234);
- topic.setTopicName(topicName);
- Optional<Topic> optional = Optional.of(topic);
- when(topicRepository.findById(0)).thenReturn(optional);
- when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_");
- assertEquals(topic,topicService.getTopic(0));
- assertTrue(topicService.isDefaultTopic(topic));
- }
-
- @Test
- public void testFillTopic(){
- TopicConfig tConfig = new TopicConfig();
- tConfig.setId(1234);
- tConfig.setName("1234");
- tConfig.setLogin("1234");
- tConfig.setPassword("1234");
- tConfig.setEnabled(true);
- tConfig.setSaveRaw(true);
- tConfig.setDataFormat("1234");
- tConfig.setTtl(1234);
- tConfig.setCorrelateClearedMessage(true);
- tConfig.setMessageIdPath("1234");
- tConfig.setAggregateArrayPath("1234");
- tConfig.setFlattenArrayPath("1234");
- List<Integer> sinkdbs = new ArrayList<>();
- sinkdbs.add(1234);
- tConfig.setSinkdbs(sinkdbs);
-
- Db db = new Db();
- db.setId(1234);
-
- TopicName topicName = new TopicName();
- topicName.setId("1234");
-
- Optional<TopicName> optional = Optional.of(topicName);
- when(dbRepository.findById(1234)).thenReturn(Optional.of(db));
- when(topicNameRepository.findById(tConfig.getName())).thenReturn(optional);
-
- topicService.fillTopicConfiguration(tConfig);
- }
+ static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
-/*
- @Test
- public void testGetEffectiveTopic() throws IOException {
- String name = "a";
- Topic topic = new Topic(name);
- topic.setEnabled(true);
- Set<Db> dbSet = new HashSet<>();
- dbSet.add(new Db("Elasticsearch"));
- topic.setDbs(dbSet);
-
- when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
- when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic));
- when(topicRepository.findById(name)).thenReturn(Optional.of(topic));
- when(topicRepository.findById(null)).thenReturn(Optional.empty());
-
- assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false));
-
- assertNotNull(topicService.getEffectiveTopic(null));
-
- topicService.getEffectiveTopic(name, true);
- }
-*/
+ @Mock
+ private ApplicationConfiguration config;
+
+ @Mock
+ private TopicRepository topicRepository;
+
+ @Mock
+ private ElasticsearchService elasticsearchService;
+
+ @Mock
+ private DbService dbService;
+
+ @Mock
+ private DbRepository dbRepository;
+
+ @Mock
+ private TopicNameRepository topicNameRepository;
+
+ @Mock
+ private KafkaRepository kafkaRepository;
+
+ @InjectMocks
+ private TopicService topicService;
+
+ @Test(expected = NullPointerException.class)
+ public void testGetTopicException() throws IOException {
+ List < Topic > topics = new ArrayList < > ();
+ Topic topic = new Topic();
+ DbType dbType = new DbType();
+ Set < Kafka > kafkas = new HashSet < > ();
+ Set < Db > dbs = new HashSet < > ();
+ Db db = new Db();
+ db.setName("Elasticsearch");
+ dbs.add(db);
+
+ dbType.setId("ES");
+ db.setDbType(dbType);
+
+ Kafka kafka = new Kafka();
+ kafka.setName("1234");
+ kafkas.add(kafka);
+
+ TopicName topicName = new TopicName();
+ topicName.setId("1234");
+
+ topic.setTopicName(topicName);
+ topic.setKafkas(kafkas);
+ topic.setEnabled(true);
+ topic.setDbs(dbs);
+ topics.add(topic);
+ when(topicRepository.findAll()).thenReturn(topics);
+ when((ElasticsearchService) dbService.findDbStoreService(db)).thenReturn(new ElasticsearchService(db));
+ topicService.findTopics(kafka, topicName.getId());
+ topicService.getEnabledEffectiveTopic(kafka, topicName.getId(), true);
+
+ }
+
+ @Test
+ public void testGetTopic() throws IOException {
+ ArrayList < Topic > topics = new ArrayList < > ();
+ Topic topic = new Topic();
+ Set < Kafka > kafkas = new HashSet < > ();
+ Kafka kafka = new Kafka();
+ kafka.setName("1234");
+ kafkas.add(kafka);
+ TopicName topicName = new TopicName();
+ topicName.setId(DEFAULT_TOPIC_NAME);
+ topic.setTopicName(topicName);
+ topic.setKafkas(kafkas);
+ topics.add(topic);
+ when(topicRepository.findAll()).thenReturn(topics);
+ when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_");
+ topicService.getEnabledEffectiveTopic(new Kafka(), "test", true);
+ }
+
+ @Test
+ public void testFindTopics() {
+ ArrayList < Topic > topics = new ArrayList < > ();
+ Topic topic = new Topic();
+ Set < Kafka > kafkas = new HashSet < > ();
+ Kafka kafka = new Kafka();
+ kafka.setName("1234");
+ kafkas.add(kafka);
+ TopicName topicName = new TopicName();
+ topicName.setId(DEFAULT_TOPIC_NAME);
+ topic.setTopicName(topicName);
+ topic.setKafkas(kafkas);
+ topics.add(topic);
+ when(topicRepository.findAll()).thenReturn(topics);
+ topicService.findTopics(kafka, topicName.getId());
+ }
+
+ @Test
+ public void testGetTopicNull() {
+ Topic topic = new Topic();
+ TopicName topicName = new TopicName();
+ topicName.setId("_DL_DEFAULT_");
+ topic.setId(1234);
+ topic.setTopicName(topicName);
+ Optional < Topic > optional = Optional.of(topic);
+ when(topicRepository.findById(0)).thenReturn(optional);
+ when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_");
+ assertEquals(topic, topicService.getTopic(0));
+ assertTrue(topicService.isDefaultTopic(topic));
+ }
+
+ @Test
+ public void testFillTopic() {
+ TopicConfig tConfig = new TopicConfig();
+ tConfig.setId(1234);
+ tConfig.setName("1234");
+ tConfig.setLogin("1234");
+ tConfig.setPassword("1234");
+ tConfig.setEnabled(true);
+ tConfig.setSaveRaw(true);
+ tConfig.setDataFormat("1234");
+ tConfig.setTtl(1234);
+ tConfig.setCorrelateClearedMessage(true);
+ tConfig.setMessageIdPath("1234");
+ tConfig.setAggregateArrayPath("1234");
+ tConfig.setFlattenArrayPath("1234");
+ List < Integer > sinkdbs = new ArrayList < > ();
+ sinkdbs.add(1234);
+ tConfig.setSinkdbs(sinkdbs);
+ List < Integer > kafkas = new ArrayList < > ();
+ kafkas.add(1);
+ tConfig.setKafkas(kafkas);
+
+ Db db = new Db();
+ db.setId(1234);
+
+ TopicName topicName = new TopicName();
+ topicName.setId("1234");
+
+ Optional < TopicName > optional = Optional.of(topicName);
+ when(dbRepository.findById(1234)).thenReturn(Optional.of(db));
+ when(kafkaRepository.findById(1)).thenReturn(Optional.of(new Kafka()));
+ when(topicNameRepository.findById(tConfig.getName())).thenReturn(optional);
+ topicService.fillTopicConfiguration(tConfig);
+ }
+
+ @Test
+ public void testGetDefaultTopicFromFeeder() {
+ when(topicRepository.findByTopicName_Id(config.getDefaultTopicName())).thenReturn(new Topic());
+ topicService.getDefaultTopicFromFeeder();
+ }
+
+ @Test
+ public void testGetDefaultTopic() {
+ List < Topic > topics = new ArrayList < > ();
+ Topic topic = new Topic();
+ DbType dbType = new DbType();
+ Set < Kafka > kafkas = new HashSet < > ();
+ Set < Db > dbs = new HashSet < > ();
+ Db db = new Db();
+ db.setName("Elasticsearch");
+ dbs.add(db);
+
+ dbType.setId("ES");
+ db.setDbType(dbType);
+
+ Kafka kafka = new Kafka();
+ kafka.setName("1234");
+ kafkas.add(kafka);
+
+ TopicName topicName = new TopicName();
+ topicName.setId(DEFAULT_TOPIC_NAME);
+ topic.setTopicName(topicName);
+ topic.setKafkas(kafkas);
+ topic.setEnabled(true);
+ topic.setDbs(dbs);
+ topics.add(topic);
+ when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
+ when(topicRepository.findAll()).thenReturn(topics);
+ topicService.getDefaultTopic(kafka);
+ }
+
+ @Test
+ public void testIsDefaultTopic() {
+ assertEquals(false, topicService.isDefaultTopic(null));
+ }
+
+ /*
+ @Test
+ public void testGetEffectiveTopic() throws IOException {
+ String name = "a";
+ Topic topic = new Topic(name);
+ topic.setEnabled(true);
+ Set<Db> dbSet = new HashSet<>();
+ dbSet.add(new Db("Elasticsearch"));
+ topic.setDbs(dbSet);
+
+ when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
+ when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic));
+ when(topicRepository.findById(name)).thenReturn(Optional.of(topic));
+ when(topicRepository.findById(null)).thenReturn(Optional.empty());
+
+ assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false));
+
+ assertNotNull(topicService.getEffectiveTopic(null));
+
+ topicService.getEffectiveTopic(name, true);
+ }
+ */
}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java
index 2a7745b4..0abee7fc 100755..100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java
@@ -3,6 +3,7 @@
* ONAP : DATALAKE
* ================================================================================
* Copyright (C) 2018-2019 Huawei. All rights reserved.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +21,12 @@
package org.onap.datalake.feeder.service.db;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
@@ -29,6 +34,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.domain.Db;
@@ -46,111 +53,129 @@ import com.couchbase.mock.client.MockClient;
@RunWith(MockitoJUnitRunner.class)
public class CouchbaseServiceTest {
- protected final BucketConfiguration bucketConfiguration = new BucketConfiguration();
- protected MockClient mockClient;
- protected CouchbaseMock couchbaseMock;
- protected Cluster cluster;
- protected com.couchbase.client.java.Bucket bucket;
- protected int carrierPort;
- protected int httpPort;
-
- protected void getPortInfo(String bucket) throws Exception {
- httpPort = couchbaseMock.getHttpPort();
- carrierPort = couchbaseMock.getCarrierPort(bucket);
- }
-
- protected void createMock(@NotNull String name, @NotNull String password) throws Exception {
- bucketConfiguration.numNodes = 1;
- bucketConfiguration.numReplicas = 1;
- bucketConfiguration.numVBuckets = 1024;
- bucketConfiguration.name = name;
- bucketConfiguration.type = Bucket.BucketType.COUCHBASE;
- bucketConfiguration.password = password;
- ArrayList<BucketConfiguration> configList = new ArrayList<BucketConfiguration>();
- configList.add(bucketConfiguration);
- couchbaseMock = new CouchbaseMock(0, configList);
- couchbaseMock.start();
- couchbaseMock.waitForStartup();
- }
-
- protected void createClient() {
- cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().bootstrapCarrierDirectPort(carrierPort).bootstrapHttpDirectPort(httpPort).build(), "couchbase://127.0.0.1");
- bucket = cluster.openBucket("default");
- }
-
- @Before
- public void setUp() throws Exception {
- createMock("default", "");
- getPortInfo("default");
- createClient();
- }
-
- @After
- public void tearDown() {
- if (cluster != null) {
- cluster.disconnect();
- }
- if (couchbaseMock != null) {
- couchbaseMock.stop();
- }
- if (mockClient != null) {
- mockClient.shutdown();
- }
- }
-
- @Test
- public void testSaveJsonsWithTopicId() {
- ApplicationConfiguration appConfig = new ApplicationConfiguration();
- appConfig.setTimestampLabel("datalake_ts_");
-
- String text = "{ data: { data2 : { value : 'hello'}}}";
-
- JSONObject json = new JSONObject(text);
-
- Topic topic = TestUtil.newTopic("test getMessageId");
- topic.setMessageIdPath("/data/data2/value");
- List<JSONObject> jsons = new ArrayList<>();
- json.put(appConfig.getTimestampLabel(), 1234);
- jsons.add(json);
- CouchbaseService couchbaseService = new CouchbaseService(new Db());
- couchbaseService.bucket = bucket;
- couchbaseService.config = appConfig;
-
- couchbaseService.init();
- EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test");
- couchbaseService.saveJsons(effectiveTopic, jsons);
-
- }
-
- @Test
- public void testSaveJsonsWithOutTopicId() {
- ApplicationConfiguration appConfig = new ApplicationConfiguration();
- appConfig.setTimestampLabel("datalake_ts_");
-
- String text = "{ data: { data2 : { value : 'hello'}}}";
-
- JSONObject json = new JSONObject(text);
-
- Topic topic = TestUtil.newTopic("test getMessageId");
- List<JSONObject> jsons = new ArrayList<>();
- json.put(appConfig.getTimestampLabel(), 1234);
- jsons.add(json);
- CouchbaseService couchbaseService = new CouchbaseService(new Db());
- couchbaseService.bucket = bucket;
- couchbaseService.config = appConfig;
-
- couchbaseService.init();
- EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test");
- couchbaseService.saveJsons(effectiveTopic, jsons);
- }
-
- @Test
- public void testCleanupBucket() {
- // CouchbaseService couchbaseService = new CouchbaseService(new Db());
- // couchbaseService.bucket = bucket;
- // ApplicationConfiguration appConfig = new ApplicationConfiguration();
- // couchbaseService.config = appConfig;
- // couchbaseService.cleanUp();
- }
-
-} \ No newline at end of file
+ protected final BucketConfiguration bucketConfiguration = new BucketConfiguration();
+ protected MockClient mockClient;
+ protected CouchbaseMock couchbaseMock;
+ protected Cluster cluster;
+ protected com.couchbase.client.java.Bucket bucket;
+ protected int carrierPort;
+ protected int httpPort;
+
+ @InjectMocks
+ private CouchbaseService couchbaseService;
+
+ @Mock
+ private ApplicationConfiguration config;
+
+ @Before
+ public void init() throws NoSuchFieldException, IllegalAccessException {
+ Db db = TestUtil.newDb("Couchbasedb");
+ db.setDatabase("database");
+ db.setLogin("login");
+ couchbaseService = new CouchbaseService(db);
+
+ Field configField = CouchbaseService.class.getDeclaredField("config");
+ configField.setAccessible(true);
+ configField.set(couchbaseService, config);
+ couchbaseService.bucket = bucket;
+ couchbaseService.init();
+ }
+
+ protected void getPortInfo(String bucket) throws Exception {
+ httpPort = couchbaseMock.getHttpPort();
+ carrierPort = couchbaseMock.getCarrierPort(bucket);
+ }
+
+ protected void createMock(@NotNull String name, @NotNull String password) throws Exception {
+ bucketConfiguration.numNodes = 1;
+ bucketConfiguration.numReplicas = 1;
+ bucketConfiguration.numVBuckets = 1024;
+ bucketConfiguration.name = name;
+ bucketConfiguration.type = Bucket.BucketType.COUCHBASE;
+ bucketConfiguration.password = password;
+ ArrayList < BucketConfiguration > configList = new ArrayList < BucketConfiguration > ();
+ configList.add(bucketConfiguration);
+ couchbaseMock = new CouchbaseMock(0, configList);
+ couchbaseMock.start();
+ couchbaseMock.waitForStartup();
+ }
+
+ protected void createClient() {
+ cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().bootstrapCarrierDirectPort(carrierPort)
+ .bootstrapHttpDirectPort(httpPort).build(), "couchbase://127.0.0.1");
+ bucket = cluster.openBucket("default");
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ createMock("default", "");
+ getPortInfo("default");
+ createClient();
+ }
+
+ @After
+ public void tearDown() {
+ if (cluster != null) {
+ cluster.disconnect();
+ }
+ if (couchbaseMock != null) {
+ couchbaseMock.stop();
+ }
+ if (mockClient != null) {
+ mockClient.shutdown();
+ }
+ }
+
+ @Test
+ public void testSaveJsonsWithTopicId() {
+ ApplicationConfiguration appConfig = new ApplicationConfiguration();
+ appConfig.setTimestampLabel("datalake_ts_");
+
+ String text = "{ data: { data2 : { value : 'hello'}}}";
+
+ JSONObject json = new JSONObject(text);
+
+ Topic topic = TestUtil.newTopic("test getMessageId");
+ topic.setMessageIdPath("/data/data2/value");
+ List < JSONObject > jsons = new ArrayList < > ();
+ json.put(appConfig.getTimestampLabel(), 1234);
+ jsons.add(json);
+ CouchbaseService couchbaseService = new CouchbaseService(new Db());
+ couchbaseService.bucket = bucket;
+ couchbaseService.config = appConfig;
+
+ couchbaseService.init();
+ EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test");
+ couchbaseService.saveJsons(effectiveTopic, jsons);
+
+ }
+
+ @Test
+ public void testSaveJsonsWithOutTopicId() {
+ ApplicationConfiguration appConfig = new ApplicationConfiguration();
+ appConfig.setTimestampLabel("datalake_ts_");
+
+ String text = "{ data: { data2 : { value : 'hello'}}}";
+
+ JSONObject json = new JSONObject(text);
+
+ Topic topic = TestUtil.newTopic("test getMessageId");
+ List < JSONObject > jsons = new ArrayList < > ();
+ json.put(appConfig.getTimestampLabel(), 1234);
+ jsons.add(json);
+ CouchbaseService couchbaseService = new CouchbaseService(new Db());
+ couchbaseService.bucket = bucket;
+ couchbaseService.config = appConfig;
+
+ couchbaseService.init();
+ EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test");
+ couchbaseService.saveJsons(effectiveTopic, jsons);
+ }
+
+ @Test
+ public void testCleanupBucket() {
+ when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock());
+ couchbaseService.cleanUp();
+ }
+
+}
diff --git a/components/datalake-handler/pom.xml b/components/datalake-handler/pom.xml
index 2a45c023..0db38d14 100644
--- a/components/datalake-handler/pom.xml
+++ b/components/datalake-handler/pom.xml
@@ -1,267 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+============LICENSE_START=======================================================
+ Copyright (c) 2020 China Mobile. All rights reserved.
+ Copyright (C) 2022 Wipro Limited. All rights reserved.
+ ================================================================================
+ 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.
+============LICENSE_END=========================================================
+-->
<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>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>2.0.0</version>
- </parent>
-
- <groupId>org.onap.dcaegen2.services.components</groupId>
- <artifactId>datalake-handler</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- <packaging>pom</packaging>
-
- <name>dcaegen2-service-datalake-handler</name>
-
- <modules>
- <module>feeder</module>
- <module>admin</module>
- <module>collector</module>
- <module>des</module>
- </modules>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>11</java.version>
-
- <mongojava.version>3.10.1</mongojava.version>
- <springboot.version>2.1.0.RELEASE</springboot.version>
- <springcouchbase.version>3.1.2.RELEASE</springcouchbase.version>
- <jackson.version>2.9.8</jackson.version>
- <kafka.version>2.0.0</kafka.version>
- <elasticsearchjava.version>7.1.1</elasticsearchjava.version>
- <hadoop.version>3.2.0</hadoop.version>
-
- <sonar.coverage.jacoco.xmlReportPaths>
- ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
- </sonar.coverage.jacoco.xmlReportPaths>
- </properties>
-
- <dependencyManagement>
- <dependencies>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-client</artifactId>
- <version>${hadoop.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.mariadb.jdbc</groupId>
- <artifactId>mariadb-java-client</artifactId>
- <version>2.4.1</version>
- </dependency>
-
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.6</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-yaml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-xml</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.2</version>
- </dependency>
-
- <dependency>
- <groupId>io.druid</groupId>
- <artifactId>tranquility-core_2.11</artifactId>
- <version>0.8.3</version>
- </dependency>
-
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>4.0.1</version>
- <!--scope>provided</scope -->
- </dependency>
-
- <dependency>
- <groupId>org.apache.kafka</groupId>
- <artifactId>kafka-clients</artifactId>
- <version>${kafka.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-engine-core</artifactId>
- <version>2.0</version>
- </dependency>
-
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20180813</version>
- </dependency>
-
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>${mongojava.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-couchbase</artifactId>
- <version>${springcouchbase.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <!-- tag::actuator[] -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- <version>${springboot.version}</version>
- </dependency>
- <!-- end::actuator[] -->
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-couchbase</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-mongodb</artifactId>
- <version>${springboot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-rest</artifactId>
- <version>${springboot.version}</version>
- </dependency>
- <!-- tag::tests[] -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <version>${springboot.version}</version>
- <scope>test</scope>
- </dependency>
- <!-- end::tests[] -->
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <version>${springboot.version}</version>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-high-level-client</artifactId>
- <version>${elasticsearchjava.version}</version>
- </dependency>
-
- </dependencies>
- </dependencyManagement>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>${springboot.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <artifactId>maven-failsafe-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <downloadSources>true</downloadSources>
- <downloadJavadocs>true</downloadJavadocs>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <version>2.8</version>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.0</version>
- </plugin>
-
- </plugins>
- </build>
+ 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>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>2.0.0</version>
+ </parent>
+
+ <groupId>org.onap.dcaegen2.services.components</groupId>
+ <artifactId>datalake-handler</artifactId>
+ <version>1.1.2-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>dcaegen2-service-datalake-handler</name>
+
+ <modules>
+ <module>feeder</module>
+ <module>admin</module>
+ <module>des</module>
+ </modules>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <java.version>11</java.version>
+
+ <mongojava.version>3.10.1</mongojava.version>
+ <springboot.version>2.1.0.RELEASE</springboot.version>
+ <springcouchbase.version>3.1.2.RELEASE</springcouchbase.version>
+ <jackson.version>2.9.8</jackson.version>
+ <kafka.version>2.0.0</kafka.version>
+ <elasticsearchjava.version>7.1.1</elasticsearchjava.version>
+ <hadoop.version>3.2.0</hadoop.version>
+
+ <sonar.coverage.jacoco.xmlReportPaths>
+ ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
+ </sonar.coverage.jacoco.xmlReportPaths>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-client</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>2.4.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.druid</groupId>
+ <artifactId>tranquility-core_2.11</artifactId>
+ <version>0.8.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>4.0.1</version>
+ <!--scope>provided</scope -->
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ <version>${kafka.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity-engine-core</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20180813</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>${mongojava.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-couchbase</artifactId>
+ <version>${springcouchbase.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <!-- tag::actuator[] -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <!-- end::actuator[] -->
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-couchbase</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-mongodb</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-rest</artifactId>
+ <version>${springboot.version}</version>
+ </dependency>
+ <!-- tag::tests[] -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>${springboot.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- end::tests[] -->
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <version>${springboot.version}</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.elasticsearch.client</groupId>
+ <artifactId>elasticsearch-rest-high-level-client</artifactId>
+ <version>${elasticsearchjava.version}</version>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${springboot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ </plugin>
+
+ </plugins>
+ </build>
</project>
diff --git a/components/datalake-handler/version.properties b/components/datalake-handler/version.properties
index 9461aa95..e6eb586c 100644
--- a/components/datalake-handler/version.properties
+++ b/components/datalake-handler/version.properties
@@ -1,6 +1,6 @@
major=1
minor=1
-patch=1
+patch=2
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT
diff --git a/components/kpi-computation-ms/Changelog.md b/components/kpi-computation-ms/Changelog.md
index 65ecd176..e96d7884 100644
--- a/components/kpi-computation-ms/Changelog.md
+++ b/components/kpi-computation-ms/Changelog.md
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [1.0.10]
+### Changed
+* Revert commit - KPI MS - Switch from Cambria library to dmaap-client library (dcaegen2/sdk) (DCAEGEN2-3180)
+
## [1.0.9]
### Changed
* KPI MS - Vulnerability updates (DCAEGEN2-3216)
diff --git a/components/kpi-computation-ms/pom.xml b/components/kpi-computation-ms/pom.xml
index 6625181c..8ee82800 100644
--- a/components/kpi-computation-ms/pom.xml
+++ b/components/kpi-computation-ms/pom.xml
@@ -29,7 +29,7 @@
<groupId>org.onap.dcaegen2.services.components</groupId>
<artifactId>kpi-ms</artifactId>
- <version>1.0.9-SNAPSHOT</version>
+ <version>1.0.10-SNAPSHOT</version>
<name>dcaegen2-services-kpi-computation-ms</name>
<description>Kpi ms</description>
<packaging>jar</packaging>
@@ -124,6 +124,11 @@
<scope>import</scope>
</dependency>
<dependency>
+ <groupId>com.att.nsa</groupId>
+ <artifactId>cambriaClient</artifactId>
+ <version>0.0.1</version>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.3</version>
@@ -292,11 +297,6 @@
<artifactId>logback-core</artifactId>
<version>1.2.11</version>
</dependency>
- <dependency>
- <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
- <artifactId>dmaap-client</artifactId>
- <version>${sdk.version}</version>
- </dependency>
</dependencies>
<build>
diff --git a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/DmaapClient.java b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/DmaapClient.java
index c5dea5e8..44b6535b 100644
--- a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/DmaapClient.java
+++ b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/DmaapClient.java
@@ -21,6 +21,8 @@
package org.onap.dcaegen2.kpi.dmaap;
+import com.att.nsa.cambria.client.CambriaConsumer;
+
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -30,10 +32,9 @@ import javax.annotation.PostConstruct;
import org.onap.dcaegen2.kpi.models.Configuration;
import org.onap.dcaegen2.kpi.utils.DmaapUtils;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.springframework.stereotype.Component;
/**
@@ -77,13 +78,12 @@ public class DmaapClient {
String pmTopic = pmTopicSplit[pmTopicSplit.length - 1];
log.debug("pm topic : {}", pmTopic);
- MessageRouterSubscriber pmNotifSubscriber = dmaapUtils.buildSubscriber();
- MessageRouterSubscribeRequest subscriberRequest = dmaapUtils.buildSubscriberRequest(configuration, pmTopic);
+ CambriaConsumer pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic);
ScheduledExecutorService executorPool;
// create notification consumers for PM
- NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifSubscriber, subscriberRequest,
+ NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifCambriaConsumer,
new KpiComputationCallBack());
// start pm notification consumer threads
executorPool = Executors.newScheduledThreadPool(10);
diff --git a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClient.java b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClient.java
index eeeb7256..fb96787b 100644
--- a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClient.java
+++ b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClient.java
@@ -26,11 +26,11 @@ import java.util.Map;
import org.onap.dcaegen2.kpi.models.Configuration;
import org.onap.dcaegen2.kpi.utils.DmaapUtils;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+
/**
* Client class to handle kpi interactions.
*/
@@ -62,12 +62,12 @@ public class KpiDmaapClient {
logger.info("Kpi publish topic url: {}", topicUrl);
String[] topicSplit = topicUrl.split("\\/");
String topic = topicSplit[topicSplit.length - 1];
- MessageRouterPublisher messageRouterPublisher;
- MessageRouterPublishRequest messageRouterPublishRequest;
+ CambriaBatchingPublisher cambriaBatchingPublisher;
try {
- messageRouterPublisher = dmaapUtils.buildPublisher();
- messageRouterPublishRequest = dmaapUtils.buildPublisherRequest(configuration, topic);
- NotificationProducer notificationProducer = new NotificationProducer(messageRouterPublisher, messageRouterPublishRequest);
+
+ cambriaBatchingPublisher = dmaapUtils.buildPublisher(configuration, topic);
+
+ NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher);
notificationProducer.sendNotification(msg);
} catch (IOException e) {
return false;
diff --git a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumer.java b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumer.java
index eba60196..fbf8bc7e 100644
--- a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumer.java
+++ b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumer.java
@@ -21,31 +21,26 @@
package org.onap.dcaegen2.kpi.dmaap;
-import java.time.Duration;
+import com.att.nsa.cambria.client.CambriaConsumer;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonElement;
-
/**
* Consume Notifications from DMAAP events.
*/
public class NotificationConsumer implements Runnable {
+
private static Logger log = LoggerFactory.getLogger(NotificationConsumer.class);
- private MessageRouterSubscriber messageSubscriber;
- private MessageRouterSubscribeRequest subscriberRequest;
+ private CambriaConsumer cambriaConsumer;
private NotificationCallback notificationCallback;
/**
* Parameterized Constructor.
*/
- public NotificationConsumer(MessageRouterSubscriber messageSubscriber, MessageRouterSubscribeRequest subscriberRequest, NotificationCallback notificationCallback) {
+ public NotificationConsumer(CambriaConsumer cambriaConsumer, NotificationCallback notificationCallback) {
super();
- this.messageSubscriber = messageSubscriber;
- this.subscriberRequest = subscriberRequest;
+ this.cambriaConsumer = cambriaConsumer;
this.notificationCallback = notificationCallback;
}
@@ -54,14 +49,15 @@ public class NotificationConsumer implements Runnable {
*/
@Override
public void run() {
- messageSubscriber.subscribeForElements(subscriberRequest, Duration.ofMinutes(1))
- .map(JsonElement::getAsString)
- .subscribe(msg -> {
+ try {
+ Iterable<String> msgs = cambriaConsumer.fetch();
+ for (String msg : msgs) {
log.info(msg);
notificationCallback.activateCallBack(msg);
- },
- ex -> {
- log.warn("An unexpected error while receiving messages from DMaaP", ex);
- });
+ }
+ } catch (Exception e) {
+ log.debug("exception when fetching msgs from dmaap", e);
+ }
+
}
}
diff --git a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducer.java b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducer.java
index c5be6cc0..34255431 100644
--- a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducer.java
+++ b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducer.java
@@ -21,47 +21,32 @@
package org.onap.dcaegen2.kpi.dmaap;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+
import java.io.IOException;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.gson.JsonPrimitive;
-import reactor.core.publisher.Flux;
/**
* Produces Notification on DMAAP events.
*/
public class NotificationProducer {
- private static Logger logger = LoggerFactory.getLogger(NotificationProducer.class);
- private MessageRouterPublisher messageRouterPublisher;
- private MessageRouterPublishRequest messageRouterPublishRequest;
-
+
+ private CambriaBatchingPublisher cambriaBatchingPublisher;
+
/**
* Parameterized constructor.
*/
- public NotificationProducer(MessageRouterPublisher messageRouterPublisher, MessageRouterPublishRequest messageRouterPublishRequest) {
+ public NotificationProducer(CambriaBatchingPublisher cambriaBatchingPublisher) {
super();
- this.messageRouterPublisher = messageRouterPublisher;
- this.messageRouterPublishRequest = messageRouterPublishRequest;
+ this.cambriaBatchingPublisher = cambriaBatchingPublisher;
}
/**
* sends notification to dmaap.
*/
- public void sendNotification(String msg) throws IOException {
- Flux.just(1, 2, 3)
- .map(JsonPrimitive::new)
- .transform(input -> messageRouterPublisher.put(messageRouterPublishRequest, input))
- .subscribe(resp -> {
- if (resp.successful()) {
- logger.debug("Sent a batch of messages to the MR");
- } else {
- logger.warn("Message sending has failed: {}", resp.failReason());
- }
- },
- ex -> {
- logger.warn("An unexpected error while sending messages to DMaaP", ex);
- });
+ public int sendNotification(String msg) throws IOException {
+
+ return cambriaBatchingPublisher.send("", msg);
+
}
+
}
diff --git a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/utils/DmaapUtils.java b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/utils/DmaapUtils.java
index 38c1ca81..2f1e19cc 100644
--- a/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/utils/DmaapUtils.java
+++ b/components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/utils/DmaapUtils.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 China Mobile.
- * Copyright (c) 2021-2022 Wipro Limited.
+ * Copyright (C) 2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,21 +21,16 @@
package org.onap.dcaegen2.kpi.utils;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaClientBuilders;
+import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
+import com.att.nsa.cambria.client.CambriaConsumer;
+
+import java.net.MalformedURLException;
+import java.security.GeneralSecurityException;
+
import org.onap.dcaegen2.kpi.models.Configuration;
-import org.onap.dcaegen2.services.sdk.model.streams.ImmutableAafCredentials;
-import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSink;
-import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSource;
-import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink;
-import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSource;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.DmaapClientFactory;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterSubscribeRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.MessageRouterPublisherConfig;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.MessageRouterSubscriberConfig;
/**
* Utility class to perform actions related to Dmaap.
@@ -45,35 +40,65 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.Me
*/
public class DmaapUtils {
- public MessageRouterPublisher buildPublisher() {
- final MessageRouterPublisher publisher = DmaapClientFactory
- .createMessageRouterPublisher(MessageRouterPublisherConfig.createDefault());
- return publisher;
+ /**
+ * Build publisher.
+ */
+ public CambriaBatchingPublisher buildPublisher(Configuration config, String topic) {
+ try {
+ return builder(config, topic).build();
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ return null;
+
+ }
+ }
+
+ /**
+ * Build consumer.
+ */
+ public CambriaConsumer buildConsumer(Configuration config, String topic) {
+
+ try {
+ return builderConsumer(config, topic).build();
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ return null;
+ }
+
}
- public MessageRouterPublishRequest buildPublisherRequest(Configuration config, String topicUrl) {
- MessageRouterSink sinkDefinition = ImmutableMessageRouterSink.builder().topicUrl(topicUrl)
- .aafCredentials(ImmutableAafCredentials.builder().username(config.getAafUsername())
- .password(config.getAafPassword()).build())
- .build();
- MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
- .sinkDefinition(sinkDefinition).build();
- return request;
+ private static PublisherBuilder builder(Configuration config, String topic) {
+ if (config.isSecured()) {
+ return authenticatedBuilder(config, topic);
+ } else {
+ return unAuthenticatedBuilder(config, topic);
+ }
}
- public MessageRouterSubscriber buildSubscriber() {
- MessageRouterSubscriber subscriber = DmaapClientFactory
- .createMessageRouterSubscriber(MessageRouterSubscriberConfig.createDefault());
- return subscriber;
+ private static PublisherBuilder authenticatedBuilder(Configuration config, String topic) {
+ return unAuthenticatedBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(),
+ config.getAafPassword());
}
- public MessageRouterSubscribeRequest buildSubscriberRequest(Configuration config, String topicUrl) {
- MessageRouterSource sourceDefinition = ImmutableMessageRouterSource.builder().topicUrl(topicUrl)
- .aafCredentials(ImmutableAafCredentials.builder().username(config.getAafUsername())
- .password(config.getAafPassword()).build())
- .build();
- MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
- .consumerGroup(config.getCg()).consumerId(config.getCid()).sourceDefinition(sourceDefinition).build();
- return request;
+ private static PublisherBuilder unAuthenticatedBuilder(Configuration config, String topic) {
+ return new CambriaClientBuilders.PublisherBuilder().usingHosts(config.getDmaapServers()).onTopic(topic)
+ .logSendFailuresAfter(5);
}
+
+ private static ConsumerBuilder builderConsumer(Configuration config, String topic) {
+ if (config.isSecured()) {
+ return authenticatedConsumerBuilder(config, topic);
+ } else {
+ return unAuthenticatedConsumerBuilder(config, topic);
+ }
+ }
+
+ private static ConsumerBuilder unAuthenticatedConsumerBuilder(Configuration config, String topic) {
+ return new CambriaClientBuilders.ConsumerBuilder().usingHosts(config.getDmaapServers()).onTopic(topic)
+ .knownAs(config.getCg(), config.getCid()).withSocketTimeout(config.getPollingTimeout() * 1000);
+ }
+
+ private static ConsumerBuilder authenticatedConsumerBuilder(Configuration config, String topic) {
+ return unAuthenticatedConsumerBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(),
+ config.getAafPassword());
+ }
+
}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java
index cc23bab8..f51bf241 100644
--- a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java
@@ -21,8 +21,15 @@
package org.onap.dcaegen2.kpi.dmaap;
+import static org.mockito.Mockito.when;
+
+import com.att.nsa.cambria.client.CambriaTopicManager;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
import java.io.BufferedReader;
import java.io.FileReader;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -32,20 +39,20 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.dcaegen2.kpi.models.Configuration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-//import com.att.nsa.cambria.client.CambriaTopicManager;
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DmaapClientTest.class)
public class DmaapClientTest {
+ @Mock
+ private CambriaTopicManager topicManager;
+
@InjectMocks
DmaapClient client;
@@ -67,9 +74,18 @@ public class DmaapClientTest {
configuration.setCid("cid");
configuration.setPollingInterval(30);
configuration.setPollingTimeout(100);
- client = Mockito.mock(DmaapClient.class);
- client.initClient();
- Mockito.verify(client).initClient();
+
+ try {
+ when(topicManager.getTopics()).thenReturn(topics);
+
+ client = Mockito.mock(DmaapClient.class);
+ client.initClient();
+ Mockito.verify(client).initClient();
+ // Mockito.verifycreateAndConfigureTopics();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@Test
@@ -85,6 +101,9 @@ public class DmaapClientTest {
configuration.updateConfigurationFromJsonObject(config);
DmaapClient client = new DmaapClient();
client.initClient();
+ // Mockito.verify(client).startClient();
+ // Mockito.verifycreateAndConfigureTopics();
+
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java
index 81699c20..bf5b6253 100644
--- a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java
@@ -22,8 +22,6 @@
package org.onap.dcaegen2.kpi.dmaap;
import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.HashMap;
@@ -38,15 +36,10 @@ import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.dcaegen2.kpi.models.Configuration;
import org.onap.dcaegen2.kpi.utils.DmaapUtils;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
import org.springframework.boot.test.context.SpringBootTest;
-import com.google.gson.JsonPrimitive;
-
-import reactor.core.publisher.Flux;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaConsumer;
@RunWith(MockitoJUnitRunner.class)
@SpringBootTest(classes = KpiDmaapClient.class)
@@ -56,38 +49,42 @@ public class KpiDmaapClientTest {
Configuration configurationMock;
@Mock
- DmaapUtils dmaapUtilsMock;
-
- @Mock
- MessageRouterPublisher messageRouterPublisher;
+ DmaapUtils dmaapUtilsMock;
+
+ @InjectMocks
+ KpiDmaapClient kpiDmaapClient;
@Mock
- MessageRouterPublishRequest messageRouterPublishRequest;
+ CambriaConsumer kpiResponseCambriaConsumerMock;
@Mock
- KpiDmaapClient kpiDmaapClient;
+ CambriaBatchingPublisher cambriaBatchingPublisherMock;
@Mock
NotificationProducer notificationProducerMock;
+ @Before
+ public void setup() {
+ kpiDmaapClient = new KpiDmaapClient(dmaapUtilsMock, configurationMock);
+ }
+
@Test
- public void sendNotificationToPolicyTest() throws IOException {
+ public void sendNotificationToPolicyTest() {
Map<String, Object> streamsPublishes = new HashMap<>();
Map<String, String> topics = new HashMap<>();
Map<String, Object> dmaapInfo = new HashMap<>();
topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_KPI_OUTPUT");
dmaapInfo.put("dmaap_info", topics);
streamsPublishes.put("kpi_topic", dmaapInfo);
- Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes);
- Mockito.doNothing().when(notificationProducerMock).sendNotification(Mockito.anyString());
- io.vavr.collection.List<String> expectedItems = io.vavr.collection.List.of("kpi-1", "kpi-2", "kpi-3");
- MessageRouterPublishResponse expectedResponse = ImmutableMessageRouterPublishResponse
- .builder().items(expectedItems.map(JsonPrimitive::new))
- .build();
- Flux<MessageRouterPublishResponse> responses = Flux.just(expectedResponse);
- when(messageRouterPublisher.put(Mockito.any(), Mockito.any())).thenReturn(responses);
- when(kpiDmaapClient.sendNotificationToDmaap(Mockito.anyString())).thenReturn(Boolean.TRUE);
- Boolean response = kpiDmaapClient.sendNotificationToDmaap(Mockito.anyString());
- assertEquals(Boolean.TRUE, response);
+ Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes);
+ Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_KPI_OUTPUT"))
+ .thenReturn(cambriaBatchingPublisherMock);
+ try {
+ Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0);
+ } catch (IOException e) {
+ e.printStackTrace();
}
+ assertTrue(kpiDmaapClient.sendNotificationToDmaap("hello"));
+
+ }
}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java
index 8d72d3cd..69d0daaa 100644
--- a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java
@@ -21,53 +21,43 @@
package org.onap.dcaegen2.kpi.dmaap;
-import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
-import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import com.google.gson.JsonElement;
-
-import reactor.core.CoreSubscriber;
-import reactor.core.publisher.Flux;
+import com.att.nsa.cambria.client.CambriaConsumer;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NotificationConsumerTest.class)
public class NotificationConsumerTest {
@Mock
+ CambriaConsumer cambriaConsumer;
+
+ @Mock
NotificationCallback notificationCallback;
@InjectMocks
NotificationConsumer notificationConsumer;
-
- @Mock
- MessageRouterSubscriber messageSubscriber;
-
- @Mock
- MessageRouterSubscribeRequest subscriberRequest;
@Test
public void testNotificationConsumer() {
try {
- Flux<JsonElement> json = new Flux<JsonElement>() {
- @Override
- public void subscribe(CoreSubscriber<? super JsonElement> actual) {
- }
- };
+ List<String> notifications = new ArrayList<>();
+ notifications.add("notification1");
+ when(cambriaConsumer.fetch()).thenReturn(notifications);
Mockito.doNothing().when(notificationCallback).activateCallBack(Mockito.anyString());
- when(messageSubscriber.subscribeForElements(subscriberRequest, Duration.ofMinutes(1))).thenReturn(json);
- assertNotNull(messageSubscriber.subscribeForElements(subscriberRequest, Duration.ofMinutes(1)));
+ notificationConsumer.run();
+
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java
index f880ec7a..7ad5786c 100644
--- a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java
@@ -21,8 +21,14 @@
package org.onap.dcaegen2.kpi.dmaap;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
import java.io.IOException;
import org.junit.Test;
@@ -32,19 +38,10 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.onap.dcaegen2.kpi.computation.FileUtils;
import org.onap.dcaegen2.kpi.models.Configuration;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
+import org.powermock.api.mockito.PowerMockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-
-import reactor.core.publisher.Flux;
-
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NotificationProducerTest.class)
public class NotificationProducerTest {
@@ -53,25 +50,24 @@ public class NotificationProducerTest {
private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
@Mock
- MessageRouterPublisher messageRouterPublisher;
-
- @Mock
- MessageRouterPublishRequest messageRouterPublishRequest;
-
+ CambriaBatchingPublisher cambriaBatchingPublisher;
+
@InjectMocks
NotificationProducer notificationProducer;
@Test
- public void notificationProducerTest() throws IOException {
- io.vavr.collection.List<String> expectedItems = io.vavr.collection.List.of("kpi-1", "kpi-2", "kpi-3");
- MessageRouterPublishResponse expectedResponse = ImmutableMessageRouterPublishResponse
- .builder().items(expectedItems.map(JsonPrimitive::new))
- .build();
- Flux<MessageRouterPublishResponse> responses = Flux.just(expectedResponse);
- when(messageRouterPublisher.put(Mockito.any(), Mockito.any())).thenReturn(responses);
- notificationProducer.sendNotification("msg");
+ public void notificationProducerTest() {
+
+ try {
+ when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0);
+ int result = notificationProducer.sendNotification("msg");
+ assertEquals(0, result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
}
-
+
@Test
public void kpiResultWithoutConfigTest() {
diff --git a/components/kpi-computation-ms/version.properties b/components/kpi-computation-ms/version.properties
index f57e7a9e..db099b7f 100644
--- a/components/kpi-computation-ms/version.properties
+++ b/components/kpi-computation-ms/version.properties
@@ -21,7 +21,7 @@
###############################################################################
major=1
minor=0
-patch=9
+patch=10
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT
diff --git a/components/slice-analysis-ms/ChangeLog.md b/components/slice-analysis-ms/ChangeLog.md
index f3152d32..aa92c9cd 100644
--- a/components/slice-analysis-ms/ChangeLog.md
+++ b/components/slice-analysis-ms/ChangeLog.md
@@ -4,13 +4,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
-## [1.1.5] - 2022/08/27
+## [1.1.5] - 2022/09/14
- [DCAEGEN2-3221](https://jira.onap.org/browse/DCAEGEN2-3221) - Slice-Analysis-Ms vulnerability updates
- [DCAEGEN2-3195](https://jira.onap.org/browse/DCAEGEN2-3195) - CCVPN Kohn Enhancements for Intent-based Cloud Leased Line and Transport Slicing
- [DCAEGEN2-3239](https://jira.onap.org/browse/DCAEGEN2-3239) - Enhance BandwidthEvaluator to listen on user's bandwidth threshold
+ - [DCAEGEN2-3238](https://jira.onap.org/browse/DCAEGEN2-3238) - Enhance BandwidthEvaluator in slice-analysis-ms to support detailed bandwidth adjustment
+
+ - [DCAEGEN2-3255](https://jira.onap.org/browse/DCAEGEN2-3255) - Fix bug of application failed to start
+
+ - [DCAEGEN2-3264](https://jira.onap.org/browse/DCAEGEN2-3264) - Fix bug that cll service instance info didn't get updated when a cll service is deleted
+
+ - [DCAEGEN2-3240](https://jira.onap.org/browse/DCAEGEN2-3240) - Implement runtime service configuration
+
+ - [DCAEGEN2-3273](https://jira.onap.org/browse/DCAEGEN2-3273) - Fix bug that config thread hang up when cbs policy is empty
+
+ - [DCAEGEN2-3270](https://jira.onap.org/browse/DCAEGEN2-3270) - Dcae slicems startup error, breaking the circular dependency.
+
## [1.1.4] - 2022/07/28
- [DCAEGEN2-3120](https://jira.onap.org/browse/DCAEGEN2-3120) - Enhance sliceanalysis MS to use DCAE SDK dmaap-client lib
diff --git a/components/slice-analysis-ms/pom.xml b/components/slice-analysis-ms/pom.xml
index 3b2cfcd7..15ae6ed7 100644
--- a/components/slice-analysis-ms/pom.xml
+++ b/components/slice-analysis-ms/pom.xml
@@ -7,6 +7,7 @@
* Copyright (C) 2020-2022 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
* Copyright (C) 2022 CTC, Inc.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -316,7 +317,7 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
- <version>10.0.21</version>
+ <version>9.0.65</version>
</dependency>
<!-- https://mvnrepository.com/artifact/nl.jqno.equalsverifier/equalsverifier -->
<dependency>
diff --git a/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json
index 12e9d08c..9e233536 100644
--- a/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json
+++ b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json
@@ -106,11 +106,12 @@
"sliceanalysisms.aaiNotif.targetSource" : "UUI",
"sliceanalysisms.aaiNotif.targetEntity" : "service-instance",
"sliceanalysisms.ccvpnEvalInterval": 5,
- "sliceanalysisms.ccvpnEvalThreshold": 0.8,
"sliceanalysisms.ccvpnEvalPrecision": 100.0,
"sliceanalysisms.ccvpnEvalPeriodicCheckOn": true,
"sliceanalysisms.ccvpnEvalOnDemandCheckOn": true,
"sliceanalysisms.ccvpnEvalStrategy" : "FlexibleThresholdStrategy",
+ "sliceanalysisms.ccvpnEvalUpperThreshold": 0.8,
+ "sliceanalysisms.ccvpnEvalLowerThreshold": 0.3,
"service_calls": {
"policy-req": []
},
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
index 57a831ea..44566637 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
@@ -1,51 +1,55 @@
/*******************************************************************************
* ============LICENSE_START=======================================================
- * son-handler
+ * slice-analysis-ms
* ================================================================================
* Copyright (C) 2019-2020 Wipro Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* 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.
* ============LICENSE_END=========================================================
- *
+ *
*******************************************************************************/
package org.onap.slice.analysis.ms;
+import org.onap.slice.analysis.ms.service.ConfigThread;
import org.onap.slice.analysis.ms.service.ConsumerThread;
import org.onap.slice.analysis.ms.service.PmThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
+/**
* This class starts the pm thread and consumer thread
*/
public class MainThread {
- private static Logger log = LoggerFactory.getLogger(MainThread.class);
-
- private MainThread() {
-
- }
-
- /**
- * main thread initialization.
- */
- public static void initiateThreads() {
- log.debug("initializing Pm thread & Consumer thread");
- Thread pmThread = new Thread(new PmThread());
- pmThread.start();
- Thread consumerThread = new Thread(new ConsumerThread());
- consumerThread.start();
- }
+ private static Logger log = LoggerFactory.getLogger(MainThread.class);
+
+ private MainThread() {
+
+ }
+
+ /**
+ * main thread initialization.
+ */
+ public static void initiateThreads() {
+ log.debug("initializing Pm thread & Consumer thread");
+ Thread pmThread = new Thread(new PmThread());
+ pmThread.start();
+ Thread consumerThread = new Thread(new ConsumerThread());
+ consumerThread.start();
+ Thread configThread = new Thread(new ConfigThread());
+ configThread.start();
+ }
}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java
index 9459b64f..b68373d1 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2021-2022 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,10 +27,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.slice.analysis.ms.models.Configuration;
@@ -111,6 +114,39 @@ public class AaiService implements AaiInterface {
}
/**
+ * fetch all valid cll instances
+ * @return
+ */
+ public Set<String> fetchAllCllInstances() {
+ globalSubscriberId = "IBNCustomer";
+ subscriptionServiceType = "IBN";
+ String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId
+ + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances";
+ log.info("serviceReqUrl {}", serviceReqUrl);
+ Set<String> cllInstances = new HashSet<>();
+ try {
+ String serviceInstance =
+ restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() {}).getBody();
+ log.debug("The service instance response msg are :{}", serviceInstance);
+ JSONObject serviceInstanceJson = new JSONObject(serviceInstance);
+ JSONArray serviceInstanceArray = serviceInstanceJson.getJSONArray("service-instance");
+ for (int i = 0; i < serviceInstanceArray.length(); i++) {
+ JSONObject serviceObj = serviceInstanceArray.getJSONObject(i);
+ String serviceId = serviceObj.getString("service-instance-id");
+ log.debug("Jsonobject {}", serviceObj);
+ if(serviceId.startsWith("cll")){
+ cllInstances.add(serviceId);
+ log.debug("Add {} to latest service id list", serviceId);
+ }
+ }
+ return cllInstances;
+ } catch (Exception e) {
+ log.error("Exception while fetching serviceDetails: " + e);
+ }
+ return new HashSet<>();
+ }
+
+ /**
* Fetches the current configuration of a Slice from AAI
*
* @param snssai SNSSAI ID
@@ -210,7 +246,7 @@ public class AaiService implements AaiInterface {
/**
* Fetches the SNSSIs of a serviceInstanceId
*
- * @param serviceInstanceId service instance ID
+ * @param sliceInstanceId service instance ID
* @return snssaiList contains list of SNSSAIs
*/
public List<String> getSnssaiList(String sliceInstanceId) {
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java
index 2bdb0506..e69d45f2 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java
@@ -97,8 +97,8 @@ public class ConfigFetchFromCbs implements Runnable {
Type mapType = new TypeToken<Map<String, Object>>() {
}.getType();
-
if (jsonObject.getAsJsonObject("policies") != null) {
+ log.info("Policy file exist");
if(jsonObject.getAsJsonObject("policies").getAsJsonArray("items").size() == 0) {
log.error("No policy in policy drool pdp engine, nothing to update.");
} else {
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java
index 584da7b7..fff156cc 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +22,10 @@
package org.onap.slice.analysis.ms.dmaap;
-import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Set;
+import org.onap.slice.analysis.ms.aai.AaiService;
import org.onap.slice.analysis.ms.models.Configuration;
import org.onap.slice.analysis.ms.models.vesnotification.NotificationFields;
@@ -51,6 +53,9 @@ public class VesNotificationCallback implements NotificationCallback {
@Autowired
CCVPNPmDatastore ccvpnPmDatastore;
+ @Autowired
+ AaiService aaiService;
+
private static Logger log = LoggerFactory.getLogger(VesNotificationCallback.class);
/**
@@ -86,10 +91,10 @@ public class VesNotificationCallback implements NotificationCallback {
String uniId = null;
String bw = null;
try {
+ updateCllInstance();
JsonNode node = obj.readTree(msg);
JsonNode notificationNode = node.get(EVENT).get(NOTIFICATIONFIELDS);
output = obj.treeToValue(notificationNode, NotificationFields.class);
-
//Filter out target notification changeIdentifier and changeType
notifChangeIdentifier = output.getChangeIdentifier();
notifChangeType = output.getChangeType();
@@ -104,11 +109,18 @@ public class VesNotificationCallback implements NotificationCallback {
log.error("Error converting VES msg to object, {}", e.getMessage());
}
if (cllId != null && uniId != null && bw != null){
- log.info("Saving new CCVPN service usage data into ccvpnPmDatastore");
log.debug("new bandwidth data -- serviceId: {}, uniId: {}, bw: {}", cllId, uniId, bw);
ccvpnPmDatastore.addUsedBwToEndpoint(cllId, uniId, bw);
}
+ }
+ /**
+ * Get latest services list, and update local related variables.
+ */
+ public void updateCllInstance(){
+ Set<String> instances = aaiService.fetchAllCllInstances();
+ log.debug("All valid instances are {}", instances);
+ ccvpnPmDatastore.updateCllInstances(instances);
}
}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java
index 4b5fe2ed..c1599517 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2020-2022 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,12 +70,12 @@ public class Configuration {
private String rannfnssiDetailsTemplateId;
private String desUrl;
private int pmDataDurationInWeeks;
-
private int vesNotifPollingInterval;
private String vesNotifChangeIdentifier;
private String vesNotifChangeType;
private int ccvpnEvalInterval;
- private double ccvpnEvalThreshold;
+ private double ccvpnEvalUpperThreshold;
+ private double ccvpnEvalLowerThreshold;
private double ccvpnEvalPrecision;
private String aaiNotifTargetAction;
private String aaiNotifTargetSource;
@@ -108,15 +109,21 @@ public class Configuration {
@Override
public String toString() {
- return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
- + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cpsUrl="
- + cpsUrl + ", aaiUrl=" + aaiUrl + ", configDbEnabled=" + configDbEnabled + ", cg=" + cg + ", cid=" + cid
- + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", aafUsername="
- + aafUsername + ", aafPassword=" + aafPassword + ", streamsSubscribes=" + streamsSubscribes
- + ", streamsPublishes=" + streamsPublishes + ", samples=" + samples + ", minPercentageChange="
- + minPercentageChange + ", initialDelaySeconds=" + initialDelaySeconds + ", rannfnssiDetailsTemplateId="
- + rannfnssiDetailsTemplateId + ", desUrl=" + desUrl + ", pmDataDurationInWeeks=" + pmDataDurationInWeeks
- + "]";
+ return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername +
+ ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cpsUrl="
+ + cpsUrl + ", aaiUrl=" + aaiUrl + ", configDbEnabled=" + configDbEnabled + ", cg=" + cg + ", cid=" + cid
+ + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", aafUsername="
+ + aafUsername + ", streamsSubscribes=" + streamsSubscribes
+ + ", streamsPublishes=" + streamsPublishes + ", samples=" + samples + ", minPercentageChange="
+ + minPercentageChange + ", initialDelaySeconds=" + initialDelaySeconds + ", rannfnssiDetailsTemplateId="
+ + rannfnssiDetailsTemplateId + ", desUrl=" + desUrl + ", pmDataDurationInWeeks=" + pmDataDurationInWeeks
+ + ", vesNotifPollingInterval=" + vesNotifPollingInterval + ", vesNotifChangeIdentifier="
+ + vesNotifChangeIdentifier + ", vesNotifChangeIdentifier=" + vesNotifChangeType + ", ccvpnEvalInterval=" +
+ ccvpnEvalInterval + ", ccvpnEvalUpperThreshold=" + ccvpnEvalUpperThreshold + ", ccvpnEvalLowerThreshold=" +
+ ccvpnEvalLowerThreshold + ", ccvpnEvalPrecision=" + ccvpnEvalPrecision + ", aaiNotifTargetAction=" +
+ aaiNotifTargetAction + ", aaiNotifTargetSource=" + aaiNotifTargetSource + ", aaiNotifTargetEntity=" +
+ aaiNotifTargetEntity + ", ccvpnEvalPeriodicCheckOn=" + ccvpnEvalPeriodicCheckOn +
+ ", ccvpnEvalOnDemandCheckOn=" + ccvpnEvalOnDemandCheckOn + ", ccvpnEvalStrategy=" + ccvpnEvalStrategy + "]";
}
/**
@@ -126,7 +133,8 @@ public class Configuration {
log.info("Updating configuration from CBS");
- Type mapType = new TypeToken<Map<String, Object>>() {}.getType();
+ Type mapType = new TypeToken<Map<String, Object>>() {
+ }.getType();
JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
streamsSubscribes = new Gson().fromJson(subscribes, mapType);
@@ -141,7 +149,8 @@ public class Configuration {
pgHost = jsonObject.get("postgres.host").getAsString();
JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server");
- Type listType = new TypeToken<List<String>>() {}.getType();
+ Type listType = new TypeToken<List<String>>() {
+ }.getType();
dmaapServers = new Gson().fromJson(servers, listType);
cg = jsonObject.get("sliceanalysisms.cg").getAsString();
@@ -165,7 +174,8 @@ public class Configuration {
aaiNotifTargetSource = jsonObject.get("sliceanalysisms.aaiNotif.targetSource").getAsString();
aaiNotifTargetEntity = jsonObject.get("sliceanalysisms.aaiNotif.targetEntity").getAsString();
ccvpnEvalInterval = jsonObject.get("sliceanalysisms.ccvpnEvalInterval").getAsInt();
- ccvpnEvalThreshold = jsonObject.get("sliceanalysisms.ccvpnEvalThreshold").getAsDouble();
+ ccvpnEvalUpperThreshold = jsonObject.get("sliceanalysisms.ccvpnEvalUpperThreshold").getAsDouble();
+ ccvpnEvalLowerThreshold = jsonObject.get("sliceanalysisms.ccvpnEvalLowerThreshold").getAsDouble();
ccvpnEvalPrecision = jsonObject.get("sliceanalysisms.ccvpnEvalPrecision").getAsDouble();
ccvpnEvalPeriodicCheckOn = jsonObject.get("sliceanalysisms.ccvpnEvalPeriodicCheckOn").getAsBoolean();
ccvpnEvalOnDemandCheckOn = jsonObject.get("sliceanalysisms.ccvpnEvalOnDemandCheckOn").getAsBoolean();
@@ -191,6 +201,6 @@ public class Configuration {
} else {
cpsUrl = jsonObject.get("sliceanalysisms.cps.url").getAsString();
}
- log.info("configuration from CBS {}", this);
+ log.info("configuration from CBS has been updated to {}", this);
}
}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java
new file mode 100644
index 00000000..88477eb0
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
+ * ==============================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ *******************************************************************************/
+
+package org.onap.slice.analysis.ms.service;
+
+import org.onap.slice.analysis.ms.models.ConfigPolicy;
+import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
+import org.onap.slice.analysis.ms.utils.BeanUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This thread is used to convert ccvpn runtime configurations from policy to our local memory CCVPNPmDatastore
+ */
+public class ConfigThread extends Thread{
+
+ CCVPNPmDatastore ccvpnPmDatastore = BeanUtil.getBean(CCVPNPmDatastore.class);
+ private static Logger log = LoggerFactory.getLogger(ConfigThread.class);
+
+ public ConfigThread () {
+ super();
+ }
+
+ public void run() {
+ log.info("Config Thread is starting...");
+ boolean done = false;
+ while(!done) {
+ try {
+ Thread.sleep(1000);
+ ConfigPolicy configPolicy = ConfigPolicy.getInstance();
+ if(configPolicy != null && configPolicy.getConfig() != null) {
+ String cllId = null;
+ Boolean clBwAssuranceStatus = null;
+ int originalBw = 0;
+ if(configPolicy.getConfig().containsKey("cllId")){
+ cllId = String.valueOf(configPolicy.getConfig().get("cllId"));
+ }
+ if(configPolicy.getConfig().containsKey("closedLoopStatus")){
+ clBwAssuranceStatus = String.valueOf(configPolicy.getConfig().get("closedLoopStatus")).equalsIgnoreCase("true");
+ }
+ if(configPolicy.getConfig().containsKey("originalBw")){
+ originalBw = Integer.parseInt(String.valueOf(configPolicy.getConfig().get("originalBw")));
+ }
+ if(cllId!=null && clBwAssuranceStatus!=null){
+ ccvpnPmDatastore.updateConfigFromPolicy(cllId, clBwAssuranceStatus, originalBw);
+ }
+ } else {
+ log.error("Config policy is empty, nothing to update.");
+ }
+
+ } catch (Exception e) {
+ log.error("Exception in Config Thread ", e);
+ done = true;
+ }
+ }
+ }
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java
index 43391809..c5e3151a 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,21 +51,13 @@ public class BandwidthEvaluator {
private Configuration configuration;
@Autowired
- AaiService aaiService;
-
- @Autowired
- CCVPNPmDatastore ccvpnPmDatastore;
-
- @Autowired
StrategyFactory strategyFactory;
private Loop evaluationEventLoop;
- private Loop aaiEventLoop;
private static final Event KILL_PILL = new SimpleEvent(null, 0);
private static final int DEFAULT_EVAL_INTERVAL = 5;
private static final String DEFAULT_STRATEGY_NAME = "FixedUpperBoundStrategy";
-
/**
* Interval of each round of evaluation, defined in config_all.json
*/
@@ -86,6 +79,7 @@ public class BandwidthEvaluator {
strategyName = (strategyName != null)? strategyName : DEFAULT_STRATEGY_NAME;
evaluationInterval = (evaluationInterval == 0)? DEFAULT_EVAL_INTERVAL : evaluationInterval;
EvaluationStrategy strategy = strategyFactory.getStrategy(strategyName);
+ log.info("{} is utilized as the bandwidth evaluatior strategy", strategyName);
/**
* Evalution main loop
@@ -97,32 +91,6 @@ public class BandwidthEvaluator {
}
};
- /**
- * AAI data consumer loop
- */
- aaiEventLoop = new Loop("AAIEventLoop"){
- @Override
- public void process(Event event) {
- if (event.type() == SimpleEvent.Type.AAI_BW_REQ){
- log.debug("=== Processing new AAI network policy query at: {} ===", event.time());
- String serviceId = (String) event.subject();
- Map<String, Integer> maxBandwidthData = aaiService.fetchMaxBandwidthOfService(serviceId);
- if (maxBandwidthData.get("maxBandwidth") != null){
- log.info("Successfully retrieved bandwidth info from AAI; service: {}, bandwidth: {}",
- serviceId, maxBandwidthData.get("maxBandwidth"));
- int bwValue = maxBandwidthData.get("maxBandwidth").intValue();
- if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0){
- ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true);
- } else if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) != bwValue) {
- log.info("Service modification complete; serviceId: {} with new bandwidth: {}", serviceId, bwValue);
- ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true);
- ccvpnPmDatastore.updateSvcState(serviceId, ServiceState.RUNNING);
- }
- }
- log.debug("=== Processing AAI network policy query complete ===");
- }
- }
- };
scheduleEvaluation();
}
@@ -132,7 +100,6 @@ public class BandwidthEvaluator {
@PreDestroy
public void stop(){
stopScheduleEvaluation();
- aaiEventLoop.stop();
evaluationEventLoop.stop();
}
@@ -160,21 +127,21 @@ public class BandwidthEvaluator {
* @param event event object
*/
public void post(@NonNull Event event){
- log.debug("A new event triggered, type: {}, subject: {}, at time: {}",
+ log.info("A new event triggered, type: {}, subject: {}, at time: {}",
event.type(), event.subject(), event.time());
- if (event.type() == SimpleEvent.Type.AAI_BW_REQ) {
- aaiEventLoop.add(event);
- } else if (event.type() == SimpleEvent.Type.PERIODIC_CHECK) {
+ if (event.type() == SimpleEvent.Type.PERIODIC_CHECK) {
evaluationEventLoop.add(event);
} else if (event.type() == SimpleEvent.Type.ONDEMAND_CHECK) {
evaluationEventLoop.add(event);
}
}
+ // update configuration
private void loadConfig() {
configuration = Configuration.getInstance();
evaluationInterval = configuration.getCcvpnEvalInterval();
strategyName = configuration.getCcvpnEvalStrategy();
+ log.info("Evaluation loop configs has been loaded. Strategy {}.", strategyName);
}
/**
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java
index 6d9b9604..3e6c4746 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,10 @@
*******************************************************************************/
package org.onap.slice.analysis.ms.service.ccvpn;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -42,13 +47,23 @@ public class CCVPNPmDatastore {
private static Logger log = LoggerFactory.getLogger(CCVPNPmDatastore.class);
private static final Pattern pattern = Pattern.compile("([0-9.]+)\\s*(kb|Kb|mb|Mb|Gb|gb)*");
private static final int WINDOW_SIZE = 5;
+ @Getter
private final ConcurrentMap<String, ServiceState> svcStatus = new ConcurrentHashMap<>();
// Provisioned bandwidth of each endpoint
+ @Getter
private final ConcurrentMap<String, Integer> endpointToProvBw = new ConcurrentHashMap<>();
// Max bandwidth (upper-bound) of each endpoint
+ @Getter
private final ConcurrentMap<String, Integer> upperBoundBw = new ConcurrentHashMap<>();
// Current bandwidth usage data list from customers
+ @Getter
private final ConcurrentMap<Endpointkey, EvictingQueue<Integer>> endpointToUsedBw = new ConcurrentHashMap<>();
+ // Original bandwidth of each endpoint
+ @Getter
+ private final ConcurrentMap<String, Integer> endpointToOriginalBw = new ConcurrentHashMap<>();
+ // Assurance Status of each endpoint
+ @Getter
+ private final ConcurrentMap<String, Boolean> closedLoopBwAssuranceStatus = new ConcurrentHashMap<>();
/**
* Given a cllId, return a map between Endpointkey and their corresponding UsedBw Queue.
@@ -88,11 +103,30 @@ public class CCVPNPmDatastore {
return svcStatus.getOrDefault(cllId, ServiceState.UNKNOWN);
}
+ /**
+ * If ccvpn flexible threshold is on, then bandwidth can be assured within scope.
+ * @param cllId
+ * @return
+ */
public Integer getUpperBoundBwOfSvc(String cllId){
return upperBoundBw.getOrDefault(cllId, Integer.MAX_VALUE);
}
/**
+ * Get closed loop check status of this cll service
+ * @param cllId
+ * @return
+ */
+ public Boolean getClosedloopStatus(String cllId){
+ return closedLoopBwAssuranceStatus.getOrDefault(cllId,true);
+ }
+
+ public int getOriginalBw(String cllId) {
+ return endpointToOriginalBw.getOrDefault(cllId, 0);
+ }
+
+
+ /**
* return the complete map of cll service status
* @return complete map of serviceStatusMap
*/
@@ -121,6 +155,35 @@ public class CCVPNPmDatastore {
}
/**
+ * Update the status, whether close loop bw modification of this cll service is on.
+ * @param cllId
+ * @param status
+ */
+ public void updateClosedloopStatus(String cllId, Boolean status){
+ closedLoopBwAssuranceStatus.put(cllId, status);
+ }
+
+ /**
+ * Update cll original bw, which will not influenced by closed loop bw assurance
+ * @param cllId
+ * @param originalBw
+ */
+ public void updateOriginalBw(String cllId, int originalBw){
+ endpointToOriginalBw.put(cllId, originalBw);
+ }
+
+ /**
+ * Update runtime configurations;
+ * @param cllId
+ * @param closedLoopBwAssuranceStatus
+ * @param originalBw
+ */
+ public void updateConfigFromPolicy(String cllId, Boolean closedLoopBwAssuranceStatus, int originalBw) {
+ updateClosedloopStatus(cllId, closedLoopBwAssuranceStatus);
+ updateOriginalBw(cllId, originalBw);
+ }
+
+ /**
* Update upper bound bandwidth value to given bandwidth
* @param cllId target cll instance id
* @param bw new bandwidth
@@ -130,6 +193,47 @@ public class CCVPNPmDatastore {
}
/**
+ * Update local service related variables in case cll is deleted.
+ * @param allValidCllInstances
+ */
+ public void updateCllInstances(Set<String> allValidCllInstances){
+ Set<String> invalidCllIds;
+ invalidCllIds= filterInvalidCllIds(allValidCllInstances, svcStatus.keySet());
+ for(String invalidCllId : invalidCllIds) {
+ log.debug("drop {} from endpointToUsedBw", invalidCllId);
+ endpointToUsedBw.entrySet().stream().dropWhile(map -> map.getKey().getCllId().equalsIgnoreCase(invalidCllId));
+ Iterator<Map.Entry<Endpointkey, EvictingQueue<Integer>>> iterator = endpointToUsedBw.entrySet().iterator();
+ while(iterator.hasNext()) {
+ Endpointkey endpointkey = iterator.next().getKey();
+ if(endpointkey.getCllId().equalsIgnoreCase(invalidCllId)) {
+ endpointToUsedBw.remove(endpointkey);
+ }
+ }
+ }
+ svcStatus.keySet().removeAll(invalidCllIds);
+ invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToProvBw.keySet());
+ endpointToProvBw.keySet().removeAll(invalidCllIds);
+ invalidCllIds = filterInvalidCllIds(allValidCllInstances, upperBoundBw.keySet());
+ upperBoundBw.keySet().removeAll(invalidCllIds);
+ invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToOriginalBw.keySet());
+ endpointToOriginalBw.keySet().removeAll(invalidCllIds);
+ invalidCllIds = filterInvalidCllIds(allValidCllInstances, closedLoopBwAssuranceStatus.keySet());
+ closedLoopBwAssuranceStatus.keySet().removeAll(invalidCllIds);
+ }
+
+ /**
+ * Filter out cllId to be deleted
+ * @param allValidCllInstances
+ * @param currentCllInstances
+ * @return
+ */
+ public Set<String> filterInvalidCllIds(Set<String> allValidCllInstances, Set<String> currentCllInstances) {
+ Set<String> invalidCllInstances = new HashSet<>(currentCllInstances);
+ invalidCllInstances.removeAll(allValidCllInstances);
+ return invalidCllInstances;
+ }
+
+ /**
* Update provisioned bandwidth to given bandwidth value;
* if @param{override} is false, only write the bandwidth if it is absent.
* Otherwise override the old value no matter if it exists or not
@@ -141,8 +245,7 @@ public class CCVPNPmDatastore {
* @return whether bandwidth value is changed or not.
*/
public boolean updateProvBw(String cllId, int bw, boolean override){
- if (!override && !endpointToProvBw.containsKey(cllId)){
- endpointToProvBw.put(cllId, bw);
+ if ( endpointToProvBw.putIfAbsent(cllId, bw) == null || !override){
return true;
} else {
if (endpointToProvBw.get(cllId) == bw){
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java
index 874e3271..66dc6dc0 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +35,10 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
+/**
+ * Threshold strategy can be configured via configuration
+ * If "sliceanalysisms.ccvpnEvalStrategy" is set to "FixedUpperBoundStrategy", then this class is triggered.
+ */
@Component
public class FixedUpperBoundStrategy implements EvaluationStrategy{
private static Logger log = LoggerFactory.getLogger(FixedUpperBoundStrategy.class);
@@ -46,7 +51,7 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
/**
* Percentage threshold of bandwidth adjustment.
*/
- private static double threshold;
+ private static double upperThreshold;
/**
* Precision of bandwidth evaluation and adjustment.
@@ -54,7 +59,7 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
private static double precision; // in Mbps;
@Autowired
- BandwidthEvaluator bandwidthEvaluator;
+ NetworkPolicyMonitor networkPolicyMonitor;
@Autowired
CCVPNPmDatastore ccvpnPmDatastore;
@@ -67,6 +72,11 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
loadConfig();
}
+ /**
+ * Periodically ensure endpoint bw adjustment is under assurance.
+ * This method will be invoked when FixedUpperBoundStrategy is set.
+ * @param event
+ */
@Override
public void execute(Event event){
if (event.type() == SimpleEvent.Type.PERIODIC_CHECK && isPeriodicCheckOn()){
@@ -77,14 +87,18 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
String serviceId = entry.getKey().getCllId();
Object[] usedBws = entry.getValue().tryReadToArray();
+ if (!ccvpnPmDatastore.getClosedloopStatus(serviceId)) {
+ log.info("CCVPN Evaluator Output: service {}, closed loop bw modification is off.", serviceId);
+ continue;
+ }
if (usedBws == null) {
// No enough data for evaluating
- log.debug("CCVPN Evaluator Output: service {}, not enough data to evaluate", serviceId);
+ log.info("CCVPN Evaluator Output: service {}, not enough data to evaluate", serviceId);
continue;
}
if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0) {
// Max bandwidth not cached yet
- log.debug("CCVPN Evaluator Output: service {}, max bandwidth not cached, wait for next round", serviceId);
+ log.info("CCVPN Evaluator Output: service {}, max bandwidth not cached, wait for next round", serviceId);
post(new SimpleEvent(SimpleEvent.Type.AAI_BW_REQ, serviceId));
continue;
}
@@ -110,33 +124,39 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
// fetch the provisioned bandwidth info if underMaintenance; otherwise send modification request
for(Map.Entry<String, Integer> entry: candidate.entrySet()) {
//still doing adjustment
- if (isServiceUnderMaintenance(entry.getKey())) {
- if (entry.getValue() == 0){
- log.debug("CCVPN Evaluator Output: service {}," +
- " is in maintenance state, fetching bandwidth info from AAI", entry.getKey());
+ String cllId = entry.getKey();
+ Integer newBw = entry.getValue();
+ if(!ccvpnPmDatastore.getClosedloopStatus(cllId)) {
+ log.info("CCVPN Evaluator Output: service {} is not under closed loop assurance", cllId);
+ continue;
+ }
+ if (isServiceUnderMaintenance(cllId)) {
+ if (newBw == 0){
+ log.info("CCVPN Evaluator Output: service {}," +
+ " is in maintenance state, fetching bandwidth info from AAI", cllId);
} else {
- log.debug("CCVPN Evaluator Output: candidate {}," +
- " need an adjustment, but skipped due to in maintenance state", entry.getKey());
+ log.info("CCVPN Evaluator Output: candidate {}," +
+ " need an adjustment, but skipped due to in maintenance state", cllId);
}
- post(new SimpleEvent(SimpleEvent.Type.AAI_BW_REQ, entry.getKey()));
+ post(new SimpleEvent(SimpleEvent.Type.AAI_BW_REQ, cllId));
continue;
}
//not in the mid of adjustment; we are free to adjust.
log.info("CCVPN Evaluator Output: candidate {}," +
- " need an adjustment, sending request to policy", entry.getKey());
+ " need an adjustment, sending request to policy", entry.getKey());
ccvpnPmDatastore.updateSvcState(entry.getKey(), ServiceState.UNDER_MAINTENANCE);
- sendModifyRequest(entry.getKey(), entry.getValue(), RequestOwner.DCAE);
+ sendModifyRequest(entry.getKey(), newBw, RequestOwner.DCAE);
}
log.debug("=== Processing periodic check complete ===");
}
if (event.type() == SimpleEvent.Type.ONDEMAND_CHECK && isOnDemandCheckOn()) {
- log.debug("=== Processing upperbound adjustment request: {} ===", event.time());
+ log.info("=== Processing upperbound adjustment request: {} ===", event.time());
JsonObject payload = (JsonObject) event.subject();
String serviceId = payload.get(SERVICE_INSTANCE_LOCATION_ID).getAsString();
int newBandwidth = payload.get(BANDWIDTH_TOTAL).getAsInt();
log.info("Update service {} bandwidth upperbound to {} ", serviceId, newBandwidth);
ccvpnPmDatastore.updateUpperBoundBw(serviceId, newBandwidth);
- log.debug("=== Processing upperbound adjustment complete ===");
+ log.info("=== Processing upperbound adjustment complete ===");
}
}
@@ -146,16 +166,16 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
}
/**
- * Post/broadcast event to the BandwidthEvaluator
+ * Post/broadcast event to the networkPolicyMonitor
* @param event event object
*/
private void post(Event event){
- bandwidthEvaluator.post(event);
+ networkPolicyMonitor.post(event);
}
private void loadConfig() {
configuration = Configuration.getInstance();
- threshold = configuration.getCcvpnEvalThreshold();
+ upperThreshold = configuration.getCcvpnEvalUpperThreshold();
precision = configuration.getCcvpnEvalPrecision(); // in Mbps;
}
@@ -179,9 +199,9 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
}
// check if an adjustment is necessary
private boolean needAdjust(String serivceId, double used, int provBandwidth, int upper){
- log.debug("CCVPN Service Usage Analysis: usage: {}, threshold: {}, currentProvisioned {}, upperbound {}",
- used, threshold, provBandwidth, upper);
- return provBandwidth > upper || used > threshold * provBandwidth;
+ log.info("CCVPN Service Usage Analysis: usage: {}, threshold: {}, currentProvisioned {}, upperbound {}",
+ used, upperThreshold, provBandwidth, upper);
+ return provBandwidth > upper || used > upperThreshold * provBandwidth;
}
// calculate new bandwidth to accomodate customer
@@ -189,7 +209,7 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{
if (cur >= upper){
return upper;
}
- int expected = (int) (Math.ceil((used / threshold) * 1.2 / precision) * precision);
+ int expected = (int) (Math.ceil((used / upperThreshold) * 1.2 / precision) * precision);
return Math.min(expected, upper);
}
// check is service under maint
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java
index d60c3eae..6b552165 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,18 +21,220 @@
*******************************************************************************/
package org.onap.slice.analysis.ms.service.ccvpn;
+import com.google.gson.JsonObject;
+import org.onap.slice.analysis.ms.models.Configuration;
+import org.onap.slice.analysis.ms.service.PolicyService;
+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 java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+/**
+ * Threshold strategy can be configured via configuration
+ * If "sliceanalysisms.ccvpnEvalStrategy" is set to "FlexibleThresholdStrategy", then this class is triggered.
+ */
@Component
-public class FlexibleThresholdStrategy implements EvaluationStrategy {
+public class FlexibleThresholdStrategy implements EvaluationStrategy{
+ private static Logger log = LoggerFactory.getLogger(FlexibleThresholdStrategy.class);
+ private Configuration configuration;
private static final String TYPE_NAME = "FlexibleThresholdStrategy";
+ private static final String SERVICE_INSTANCE_LOCATION_ID = "service-instance-location-id";
+ private static final String BANDWIDTH_TOTAL = "bandwidth-total";
+
+ /**
+ * Percentage threshold of bandwidth increase adjustment.
+ */
+ private static double upperThreshold;
+
+ /**
+ * Percentage threshold of bandwidth decrease adjustment.
+ */
+ private static double lowerThreshold;
+
+ /**
+ * Precision of bandwidth evaluation and adjustment.
+ */
+ private static double precision; // in Mbps;
+
+ @Autowired
+ NetworkPolicyMonitor networkPolicyMonitor;
+
+ @Autowired
+ CCVPNPmDatastore ccvpnPmDatastore;
+
+ @Autowired
+ PolicyService policyService;
+
+ @PostConstruct
+ public void init() {
+ loadConfig();
+ }
+
+ /**
+ * Periodically ensure endpoint bw adjustment is under assurance.
+ * This method will be invoked when FlexibleThresholdStrategy is set.
+ * @param event
+ */
@Override
- public void execute(Event event) {
- return;
+ public void execute(Event event){
+ if (event.type() == SimpleEvent.Type.PERIODIC_CHECK && isPeriodicCheckOn()){
+ log.info("=== Processing new periodic check request: {} ===", event.time());
+ Map<Endpointkey, CCVPNPmDatastore.EvictingQueue<Integer>> usedBwMap = ccvpnPmDatastore.getUsedBwMap();
+ Map<String, Integer> candidate = new TreeMap<>();
+ for(Map.Entry<Endpointkey, CCVPNPmDatastore.EvictingQueue<Integer>> entry: usedBwMap.entrySet()) {
+ String serviceId = entry.getKey().getCllId();
+ Object[] usedBws = entry.getValue().tryReadToArray();
+ // Judge whether this cll is under closed loop assurance
+ if (!ccvpnPmDatastore.getClosedloopStatus(serviceId)) {
+ log.info("CCVPN Evaluator Output: service {}, closed loop bw modification is off.", serviceId);
+ continue;
+ }
+ if (usedBws == null) {
+ // Not enough data for evaluating
+ log.info("CCVPN Evaluator Output: service {}, not enough data to evaluate", serviceId);
+ continue;
+ }
+ if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0) {
+ // Max bandwidth not cached yet
+ log.info("CCVPN Evaluator Output: service {}, max bandwidth not cached, wait for next round", serviceId);
+ post(new SimpleEvent(SimpleEvent.Type.AAI_BW_REQ, serviceId));
+ continue;
+ }
+ double avg = Arrays.stream(usedBws)
+ .mapToInt(o -> (int) o)
+ .summaryStatistics()
+ .getAverage();
+ int provBw = ccvpnPmDatastore.getProvBwOfSvc(serviceId);
+ int originalBw = ccvpnPmDatastore.getOriginalBw(serviceId);
+
+ if(needIncrease(serviceId, avg, provBw)){
+ int newBw = (int) (Math.ceil((avg / upperThreshold) * 1.2 / precision) * precision);
+ log.info("For cll {}, going to increase bw to {}", serviceId, newBw);
+ candidate.put(serviceId, Math.max(candidate.getOrDefault(serviceId, 0), newBw));
+ } else {
+ if(needDecrease(serviceId, avg, provBw, originalBw)) {
+ int newBw = Math.max((int) (Math.ceil(provBw * 0.5)), originalBw);
+ log.info("For cll {}, going to decrease bw to {}", serviceId, newBw);
+ candidate.put(serviceId, Math.max(candidate.getOrDefault(serviceId, 0), newBw));
+ }
+ }
+ }
+ // check svc under maintenance
+ Map<String , ServiceState> svcUnderMaintenance = getServicesUnderMaintenance();
+ for (Map.Entry<String, ServiceState> entry: svcUnderMaintenance.entrySet()){
+ candidate.putIfAbsent(entry.getKey(), 0);
+ }
+ // fetch the provisioned bandwidth info if underMaintenance; otherwise send modification request
+ for(Map.Entry<String, Integer> entry: candidate.entrySet()) {
+ //still doing adjustment
+ String cllId = entry.getKey();
+ Integer newBw = entry.getValue();
+ if(!ccvpnPmDatastore.getClosedloopStatus(cllId)) {
+ log.info("CCVPN Evaluator Output: service {} is not under closed loop assurance", cllId);
+ continue;
+ }
+ if (isServiceUnderMaintenance(cllId)) {
+ if (newBw == 0){
+ log.info("CCVPN Evaluator Output: service {}," +
+ " is in maintenance state, fetching bandwidth info from AAI", cllId);
+ } else {
+ log.info("CCVPN Evaluator Output: candidate {}," +
+ " need an adjustment, but skipped due to in maintenance state", cllId);
+ }
+ post(new SimpleEvent(SimpleEvent.Type.AAI_BW_REQ, cllId));
+ continue;
+ }
+ //not in the mid of adjustment; we are free to adjust.
+ log.info("CCVPN Evaluator Output: candidate {}," +
+ " need an adjustment, sending request to policy, service state changed to under maintenance", entry.getKey());
+ ccvpnPmDatastore.updateSvcState(entry.getKey(), ServiceState.UNDER_MAINTENANCE);
+ sendModifyRequest(entry.getKey(), newBw, RequestOwner.DCAE);
+ }
+ log.debug("=== Processing periodic check complete ===");
+ } else if (event.type() == SimpleEvent.Type.ONDEMAND_CHECK && isOnDemandCheckOn()) {
+ log.info("=== Processing upperbound adjustment request: {} ===", event.time());
+ JsonObject payload = (JsonObject) event.subject();
+ String serviceId = payload.get(SERVICE_INSTANCE_LOCATION_ID).getAsString();
+ int newBandwidth = payload.get(BANDWIDTH_TOTAL).getAsInt();
+ log.info("Update service {} bandwidth upperbound to {} ", serviceId, newBandwidth);
+ ccvpnPmDatastore.updateUpperBoundBw(serviceId, newBandwidth);
+ log.debug("=== Processing upperbound adjustment complete ===");
+ }
}
@Override
public String getName() {
return TYPE_NAME;
}
+
+ /**
+ * Post/broadcast event to the networkPolicyMonitor
+ * @param event event object
+ */
+ private void post(Event event){
+ networkPolicyMonitor.post(event);
+ }
+
+ private void loadConfig() {
+ configuration = Configuration.getInstance();
+ upperThreshold = configuration.getCcvpnEvalUpperThreshold();
+ lowerThreshold = configuration.getCcvpnEvalLowerThreshold();
+ precision = configuration.getCcvpnEvalPrecision(); // in Mbps;
+ }
+
+ private boolean isPeriodicCheckOn() {
+ configuration = Configuration.getInstance();
+ return configuration.isCcvpnEvalPeriodicCheckOn();
+ }
+
+ private boolean isOnDemandCheckOn() {
+ configuration = Configuration.getInstance();
+ return configuration.isCcvpnEvalOnDemandCheckOn();
+ }
+
+ // send modification requestion
+ private void sendModifyRequest(String cllId, Integer newBandwidth, RequestOwner owner) {
+ log.info("Sending modification request to policy. RequestOwner: {} - Service: {} change to bw: {}",
+ owner, cllId, newBandwidth);
+ policyService.sendOnsetMessageToPolicy(
+ policyService.formPolicyOnsetMessageForCCVPN(cllId, newBandwidth, owner)
+ );
+ }
+
+ private boolean needIncrease(String serviceId, double currAvgUsage, int provBw) {
+ log.info("For service {} judge whether to increase, currAvg bw {}, maxBw {}", serviceId, currAvgUsage, provBw);
+ if ( currAvgUsage > upperThreshold * provBw ) {
+ log.info("decide to increase");
+ return true;
+ }
+ return false;
+ }
+
+ private boolean needDecrease(String serviceId, double currAvgUsage, int provBw, int originalBw) {
+ log.info("For service {} judge whether to decrease, original bw {}, currAvg bw {}, prov {}", serviceId, originalBw, currAvgUsage, provBw);
+ if( currAvgUsage < lowerThreshold * provBw) {
+ log.info("decide to decrease");
+ return true;
+ }
+ return false;
+ }
+
+ // check is service under maintenance
+ private boolean isServiceUnderMaintenance(String serivceId) {
+ return ccvpnPmDatastore.getStatusOfSvc(serivceId) == ServiceState.UNDER_MAINTENANCE;
+ }
+
+ // get a collection of service under maintenance
+ private Map<String, ServiceState> getServicesUnderMaintenance(){
+ return ccvpnPmDatastore.getSvcStatusMap().entrySet()
+ .stream()
+ .filter(e -> e.getValue() == ServiceState.UNDER_MAINTENANCE)
+ .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
+ }
}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java
new file mode 100644
index 00000000..9948804a
--- /dev/null
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2022 Huawei Canada Limited.
+ * ==============================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ *******************************************************************************/
+
+package org.onap.slice.analysis.ms.service.ccvpn;
+
+import lombok.NonNull;
+import org.onap.slice.analysis.ms.aai.AaiService;
+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 java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Actor that processes aai network-policy query request
+ */
+@Component
+public class NetworkPolicyMonitor {
+ private static Logger log = LoggerFactory.getLogger(NetworkPolicyMonitor.class);
+ private Loop aaiEventLoop;
+ private static final Event KILL_PILL = new SimpleEvent(null, 0);
+
+ @Autowired
+ AaiService aaiService;
+
+ @Autowired
+ CCVPNPmDatastore ccvpnPmDatastore;
+
+ /**
+ * Initialize and start the NetworkPolicyMonitor.
+ */
+ @PostConstruct
+ public void init() {
+ /**
+ * AAI data consumer loop
+ */
+ aaiEventLoop = new Loop("AAIEventLoop"){
+ @Override
+ public void process(Event event) {
+ if (event.type() == SimpleEvent.Type.AAI_BW_REQ){
+ log.debug("=== Processing new AAI network policy query at: {} ===", event.time());
+ String serviceId = (String) event.subject();
+ Map<String, Integer> maxBandwidthData = aaiService.fetchMaxBandwidthOfService(serviceId);
+ if (maxBandwidthData.get("maxBandwidth") != null){
+ log.debug("Successfully retrieved bandwidth info from AAI; service: {}, bandwidth: {}",
+ serviceId, maxBandwidthData.get("maxBandwidth"));
+ int bwValue = maxBandwidthData.get("maxBandwidth").intValue();
+ if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0){
+ ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true);
+ log.debug("Provision bw of cll {} updated from 0 to {}, max bw is {}", serviceId, ccvpnPmDatastore.getProvBwOfSvc(serviceId), bwValue);
+ } else if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) != bwValue) {
+ log.debug("Service modification complete; serviceId: {} update prov bw from {} to {}", serviceId, ccvpnPmDatastore.getProvBwOfSvc(serviceId), bwValue);
+ ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true);
+ ccvpnPmDatastore.updateSvcState(serviceId, ServiceState.RUNNING);
+ log.debug("Service state of {} is changed to running, {}", serviceId, ccvpnPmDatastore.getStatusOfSvc(serviceId));
+ }
+ }
+ log.debug("=== Processing AAI network policy query complete ===");
+ }
+ }
+ };
+ }
+
+ /**
+ * Post/broadcast event between Loops
+ * @param event event object
+ */
+ public void post(@NonNull Event event) {
+ if (event.type() == SimpleEvent.Type.AAI_BW_REQ) {
+ aaiEventLoop.add(event);
+ }
+ }
+ /**
+ * Inner loop implementation. Each loop acts like an actor.
+ */
+ private abstract class Loop implements Runnable {
+ private final String name;
+ private volatile boolean running;
+ private final BlockingQueue<Event> eventsQueue;
+ private final ExecutorService executor;
+ private volatile Future<?> dispatchFuture;
+
+ /**
+ * Constructor that accepts a loop name
+ * @param name name of this loop
+ */
+ Loop(String name){
+ this.name = name;
+ executor = Executors.newSingleThreadExecutor();
+ eventsQueue = new LinkedBlockingQueue<>();
+ dispatchFuture = executor.submit(this);
+ }
+
+ /**
+ * Add new event to this loop
+ * @param evt Event
+ * @return true
+ */
+ public boolean add(Event evt) {
+ return eventsQueue.add(evt);
+ }
+
+ /**
+ * Running loop that process event accordingly
+ */
+ @Override
+ public void run(){
+ running = true;
+ log.info("NetworkPolicyMonitor -- {} initiated", this.name);
+ while (running){
+ try{
+ Event event = eventsQueue.take();
+ if (event == KILL_PILL){
+ break;
+ }
+ process(event);
+ } catch (InterruptedException e){
+ log.warn("Process loop interrupted");
+ } catch (Exception | Error e){
+ log.warn("Process loop hit an error {}", e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Operation defined by subclass for different event processing
+ * @param event incoming event
+ */
+ abstract public void process(Event event);
+
+ /**
+ * Stop this loop
+ */
+ public void stop(){
+ running = false;
+ add(KILL_PILL);
+ }
+ }
+}
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java
index 824731fc..2feba83d 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java
@@ -35,7 +35,7 @@ public class StrategyFactory {
private static Logger log = LoggerFactory.getLogger(StrategyFactory.class);
@Autowired
- List<EvaluationStrategy> strategies;
+ public List<EvaluationStrategy> strategies;
private StrategyFactory() {}
diff --git a/components/slice-analysis-ms/src/main/resources/logback.xml b/components/slice-analysis-ms/src/main/resources/logback.xml
index d727d05d..134c25dc 100644
--- a/components/slice-analysis-ms/src/main/resources/logback.xml
+++ b/components/slice-analysis-ms/src/main/resources/logback.xml
@@ -7,6 +7,7 @@
* Copyright (C) 2020 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
* Copyright (C) 2022 CTC, Inc.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +34,7 @@
</layout>
</appender>
- <root level="debug">
+ <root level="info">
<appender-ref ref="CONSOLE"/>
</root>
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java
index 16745193..9fce12f1 100644
--- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
* Copyright (C) 2022 CTC, Inc.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,7 +84,8 @@ public class AaiEventNotificationCallbackTest {
jsonObject.addProperty("sliceanalysisms.vesNotifChangeType", "1");
jsonObject.addProperty("sliceanalysisms.vesNotifPollingInterval", "1");
jsonObject.addProperty("sliceanalysisms.ccvpnEvalInterval", "1");
- jsonObject.addProperty("sliceanalysisms.ccvpnEvalThreshold", "1");
+ jsonObject.addProperty("sliceanalysisms.ccvpnEvalUpperThreshold", "1");
+ jsonObject.addProperty("sliceanalysisms.ccvpnEvalLowerThreshold", "1");
jsonObject.addProperty("sliceanalysisms.ccvpnEvalPrecision", "1");
jsonObject.addProperty("sliceanalysisms.ccvpnEvalPeriodicCheckOn", "1");
jsonObject.addProperty("sliceanalysisms.ccvpnEvalOnDemandCheckOn", "1");
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java
index 74f75a8c..97ee9fa9 100644
--- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2020 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,12 +23,20 @@
package org.onap.slice.analysis.ms.dmaap;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
+import org.onap.slice.analysis.ms.aai.AaiService;
+import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
+import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
@@ -39,6 +48,12 @@ import java.nio.file.Paths;
public class VesNotificationCallbackTest {
ObjectMapper obj = new ObjectMapper();
+ @Mock
+ AaiService aaiService;
+
+ @Mock
+ CCVPNPmDatastore ccvpnPmDatastore;
+
@Spy
@InjectMocks
VesNotificationCallback vesNotificationCallback;
@@ -57,6 +72,11 @@ public class VesNotificationCallbackTest {
} catch (IOException e) {
e.printStackTrace();
}
+ Set<String> cllInstances = new HashSet<>();
+ cllInstances.add("cll-01");
+ cllInstances.add("cll-02");
+ Mockito.when(aaiService.fetchAllCllInstances()).thenReturn(cllInstances);
+ Mockito.doNothing().when(ccvpnPmDatastore).updateCllInstances(Mockito.any());
vesNotificationCallback.activateCallBack(input);
Mockito.verify(vesNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
}
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java
index 3d9b58d4..78379094 100644
--- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2020-2021 Wipro Limited.
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +59,9 @@ public class ConfigurationTest {
configuration.setVesNotifChangeType("BandwidthChanged");
configuration.setCcvpnEvalInterval(5);
configuration.setCcvpnEvalPrecision(100);
- configuration.setCcvpnEvalThreshold(0.8);
+ configuration.setCcvpnEvalUpperThreshold(0.8);
+ configuration.setCcvpnEvalLowerThreshold(0.3);
+ configuration.setCcvpnEvalStrategy("FlexibleThresholdStrategy");
assertEquals(true,configuration.isSecured());
assertEquals("user", configuration.getAafUsername());
assertEquals("password", configuration.getAafPassword());
@@ -85,6 +88,8 @@ public class ConfigurationTest {
assertEquals("BandwidthChanged", configuration.getVesNotifChangeType());
assertEquals(5, configuration.getCcvpnEvalInterval());
assertEquals(100.0, configuration.getCcvpnEvalPrecision(), 0.001);
- assertEquals(0.8, configuration.getCcvpnEvalThreshold(), 0.001);
+ assertEquals(0.8, configuration.getCcvpnEvalUpperThreshold(), 0.001);
+ assertEquals(0.3, configuration.getCcvpnEvalLowerThreshold(), 0.001);
+ assertEquals("FlexibleThresholdStrategy", configuration.getCcvpnEvalStrategy());
}
}
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java
index 673ec6a8..8b0b99f3 100644
--- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java
@@ -3,6 +3,7 @@
* slice-analysis-ms
* ================================================================================
* Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,8 @@
package org.onap.slice.analysis.ms.service.ccvpn;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -119,4 +122,28 @@ public class CCVPNPmDatastoreTest {
.mapToInt(o -> (int)o)
.sum() == 300602 );
}
+
+ @Test
+ public void updateCllInstancesTest() {
+ datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb");
+ datastore.updateUpperBoundBw("cll-01", 300);
+ datastore.updateProvBw("cll-01", "300");
+ datastore.updateSvcState("cll-01", ServiceState.RUNNING);
+ datastore.updateOriginalBw("cll-01", 1000);
+ datastore.updateClosedloopStatus("cll-01", true);
+ datastore.addUsedBwToEndpoint("cll-02", "uni-n2", "300Mb");
+ datastore.updateUpperBoundBw("cll-02", 300);
+ datastore.updateProvBw("cll-02", "300");
+ datastore.updateSvcState("cll-02", ServiceState.RUNNING);
+ datastore.updateOriginalBw("cll-02", 1000);
+ datastore.updateClosedloopStatus("cll-02", true);
+ Set<String> cllId = new HashSet<>();
+ cllId.add("cll-01");
+ datastore.updateCllInstances(cllId);
+ assertEquals(datastore.getEndpointToUsedBw().keySet().size(), 1);
+ assertEquals(datastore.getUpperBoundBw().keySet().equals(cllId), true);
+ assertEquals(datastore.getEndpointToProvBw().keySet().equals(cllId), true);
+ assertEquals(datastore.getSvcStatus().keySet().equals(cllId), true);
+ assertEquals(datastore.getEndpointToOriginalBw().keySet().equals(cllId), true);
+ }
}
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategyTest.java
new file mode 100644
index 00000000..40028923
--- /dev/null
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategyTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2022 Huawei Technologies Co., Ltd.
+ * ==============================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ *******************************************************************************/
+package org.onap.slice.analysis.ms.service.ccvpn;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = FixedUpperBoundStrategyTest.class)
+public class FlexibleThresholdStrategyTest {
+
+ @Spy
+ @InjectMocks
+ BandwidthEvaluator bandwidthEvaluator;
+
+ @Spy
+ @InjectMocks
+ FlexibleThresholdStrategy flexibleThresholdStrategy;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void initTest() {
+ flexibleThresholdStrategy.init();
+ Mockito.verify(flexibleThresholdStrategy, Mockito.atLeastOnce()).init();
+ }
+
+ @Test
+ public void executeTest() {
+ Event evt = new SimpleEvent(null, "{}");
+ flexibleThresholdStrategy.execute(evt);
+ Mockito.verify(flexibleThresholdStrategy, Mockito.atLeastOnce())
+ .execute(Mockito.any(Event.class));
+ }
+
+ @Test
+ public void getNameTest() {
+ flexibleThresholdStrategy.getName();
+ Mockito.verify(flexibleThresholdStrategy, Mockito.atLeastOnce()).getName();
+ }
+}
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java
new file mode 100644
index 00000000..23366ab9
--- /dev/null
+++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2022 Huawei Canada Limited.
+ * ==============================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ *
+ *******************************************************************************/
+
+package org.onap.slice.analysis.ms.service.ccvpn;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = BandwidthEvaluatorTest.class)
+public class NetworkPolicyMonitorTest {
+
+ @Spy
+ @InjectMocks
+ NetworkPolicyMonitor NetworkPolicyMonitor;
+ @Test
+ public void initTest() {
+ NetworkPolicyMonitor.init();
+ Mockito.verify(NetworkPolicyMonitor, Mockito.atLeastOnce()).init();
+ }
+
+ @Test
+ public void postTest() {
+ Event evt = new SimpleEvent(null, "{}");
+ NetworkPolicyMonitor.post(evt);
+ Mockito.verify(NetworkPolicyMonitor, Mockito.atLeastOnce()).post(Mockito.any(Event.class));
+ }
+}
diff --git a/components/slice-analysis-ms/src/test/resources/config_all.json b/components/slice-analysis-ms/src/test/resources/config_all.json
index f37e438c..fc18cc14 100644
--- a/components/slice-analysis-ms/src/test/resources/config_all.json
+++ b/components/slice-analysis-ms/src/test/resources/config_all.json
@@ -106,7 +106,8 @@
"sliceanalysisms.aaiNotif.targetSource" : "UUI",
"sliceanalysisms.aaiNotif.targetEntity" : "service-instance",
"sliceanalysisms.ccvpnEvalInterval": 5,
- "sliceanalysisms.ccvpnEvalThreshold": 0.8,
+ "sliceanalysisms.ccvpnEvalUpperThreshold": 0.8,
+ "sliceanalysisms.ccvpnEvalLowerThreshold": 0.3,
"sliceanalysisms.ccvpnEvalPrecision": 100.0,
"sliceanalysisms.ccvpnEvalPeriodicCheckOn": true,
"sliceanalysisms.ccvpnEvalOnDemandCheckOn": true,
diff --git a/releases/slice-analysis-ms-1.1.5-container.yaml b/releases/slice-analysis-ms-1.1.5-container.yaml
new file mode 100644
index 00000000..2e05a021
--- /dev/null
+++ b/releases/slice-analysis-ms-1.1.5-container.yaml
@@ -0,0 +1,10 @@
+distribution_type: 'container'
+version: '1.1.5'
+project: 'dcaegen2-services-slice-analysis-ms'
+log_dir: 'dcaegen2-services-slice-analysis-ms-maven-docker-stage-master/794'
+containers:
+ - name: 'org.onap.dcaegen2.services.components.slice-analysis-ms'
+ version: '1.1.5-20220927T221042Z'
+container_release_tag: '1.1.5'
+ref: '63d6a20970b8b37506141a2529fe5f3e8deaa3a1'
+git_tag: '1.1.5-slice-analysis-ms'