aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-app-server')
-rw-r--r--datafile-app-server/config/application.yaml6
-rw-r--r--datafile-app-server/config/datafile_endpoints.json28
-rw-r--r--datafile-app-server/config/prh_endpoints.json47
-rw-r--r--datafile-app-server/pom.xml212
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java19
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java103
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java16
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java50
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java41
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java81
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/TomcatHttpConfig.java55
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java45
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java20
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java12
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java10
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java10
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollector.java117
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileServerData.java31
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java117
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java98
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java179
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/FileData.java (renamed from datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/AaiNotFoundException.java)32
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTask.java36
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImpl.java78
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTask.java49
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImpl.java89
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTask.java28
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java72
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTask.java43
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImpl.java62
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java50
-rw-r--r--datafile-app-server/src/main/resources/application.properties5
-rw-r--r--datafile-app-server/src/main/resources/keystore.jksbin2643 -> 2627 bytes
-rw-r--r--datafile-app-server/src/main/resources/keystore.jks.oldbin2272 -> 0 bytes
-rw-r--r--datafile-app-server/src/main/resources/logback-spring.xml16
-rw-r--r--datafile-app-server/src/main/resources/scheduled-context.xml24
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java144
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectorTest.java116
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpClientTest.java57
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java103
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ScheduledXmlContextITest.java14
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java2
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/junit5/mockito/MockitoExtension.java17
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java349
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImplTest.java149
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskSpy.java50
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImplTest.java133
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiPublisherTaskSpy.java58
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java220
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskSpy.java59
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapProducerTaskSpy.java59
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java94
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduleControllerSpy.java54
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java204
-rw-r--r--datafile-app-server/src/test/resources/datafile_endpoints.json69
55 files changed, 1800 insertions, 2032 deletions
diff --git a/datafile-app-server/config/application.yaml b/datafile-app-server/config/application.yaml
index 6a792346..ca3160c7 100644
--- a/datafile-app-server/config/application.yaml
+++ b/datafile-app-server/config/application.yaml
@@ -1,15 +1,13 @@
spring:
profiles:
active: prod
- main:
- web-application-type: none
server:
port: 8433
ssl:
key-store-type: PKCS12
- key-store-password: nokiapnf
+ key-store-password: ericssondfc
key-store: classpath:keystore.jks
- key-password: nokiapnf
+ key-password: ericssondfc
keyAlias: tomcat-localhost
logging:
level:
diff --git a/datafile-app-server/config/datafile_endpoints.json b/datafile-app-server/config/datafile_endpoints.json
new file mode 100644
index 00000000..41f9b6d8
--- /dev/null
+++ b/datafile-app-server/config/datafile_endpoints.json
@@ -0,0 +1,28 @@
+{
+ "configs": {
+ "dmaap": {
+ "dmaapConsumerConfiguration": {
+ "dmaapHostName": "localhost",
+ "dmaapPortNumber": 3904,
+ "dmaapTopicName": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT",
+ "dmaapProtocol": "http",
+ "dmaapUserName": "admin",
+ "dmaapUserPassword": "admin",
+ "dmaapContentType": "application/json",
+ "consumerId": "c12",
+ "consumerGroup": "OpenDcae-c12",
+ "timeoutMS": -1,
+ "messageLimit": 1
+ },
+ "dmaapProducerConfiguration": {
+ "dmaapHostName": "localhost",
+ "dmaapPortNumber": 3905,
+ "dmaapTopicName": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT",
+ "dmaapProtocol": "http",
+ "dmaapUserName": "admin",
+ "dmaapUserPassword": "admin",
+ "dmaapContentType": "application/octet-stream"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/datafile-app-server/config/prh_endpoints.json b/datafile-app-server/config/prh_endpoints.json
deleted file mode 100644
index 772d9708..00000000
--- a/datafile-app-server/config/prh_endpoints.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "configs": {
- "dmaap": {
- "dmaapConsumerConfiguration": {
- "dmaapHostName": "localhost",
- "dmaapPortNumber": 2222,
- "dmaapTopicName": "/events/unauthenticated.SEC_OTHER_OUTPUT",
- "dmaapProtocol": "http",
- "dmaapUserName": "admin",
- "dmaapUserPassword": "admin",
- "dmaapContentType": "application/json",
- "consumerId": "c12",
- "consumerGroup": "OpenDcae-c12",
- "timeoutMS": -1,
- "messageLimit": 1
- },
- "dmaapProducerConfiguration": {
- "dmaapHostName": "localhost",
- "dmaapPortNumber": 2223,
- "dmaapTopicName": "/events/unauthenticated.PNF_READY",
- "dmaapProtocol": "http",
- "dmaapUserName": "admin",
- "dmaapUserPassword": "admin",
- "dmaapContentType": "application/json"
- }
- },
- "aai": {
- "aaiClientConfiguration": {
- "aaiHost": "localhost",
- "aaiPort": 8080,
- "aaiProtocol": "https",
- "aaiUserName": "AAI",
- "aaiUserPassword": "AAI",
- "aaiIgnoreSSLCertificateErrors": true,
- "aaiBasePath": "/aai/v12",
- "aaiPnfPath": "/network/pnfs/pnf",
- "aaiHeaders": {
- "X-FromAppId": "datafile",
- "X-TransactionId": "9999",
- "Accept": "application/json",
- "Real-Time": "true",
- "Content-Type":"application/merge-patch+json"
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/datafile-app-server/pom.xml b/datafile-app-server/pom.xml
index 84c9539b..339daeb4 100644
--- a/datafile-app-server/pom.xml
+++ b/datafile-app-server/pom.xml
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ ============LICENSE_START=======================================================
- ~ Datafile Collector Service
- ~ ================================================================================
- ~ Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- ~ ================================================================================
+ ~ Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ ~ 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,
@@ -22,54 +20,28 @@
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">
<parent>
- <artifactId>datafile</artifactId>
<groupId>org.onap.dcaegen2.collectors</groupId>
+ <artifactId>datafile</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>datafile-app-server</artifactId>
<groupId>org.onap.dcaegen2.collectors.datafile</groupId>
+ <artifactId>datafile-app-server</artifactId>
<packaging>jar</packaging>
+
<properties>
+ <docker.image.name>onap/${project.groupId}.${project.artifactId}</docker.image.name>
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
- <project.fatJar.finalName>datafile-app-server</project.fatJar.finalName>
+ <project.fatJar.finalName>datafile-happ-server</project.fatJar.finalName>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<snapshots.path>content/repositories/snapshots/</snapshots.path>
<releases.path>content/repositories/releases/</releases.path>
- <docker.repo.url>${onap.nexus.dockerregistry.daily}</docker.repo.url>
- <nexus.staging>false</nexus.staging>
</properties>
+
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>custom-resources</id>
- <phase>process-resources</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/config</outputDirectory>
- <resources>
- <resource>
- <directory>${project.basedir}/config</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- <encoding>UTF-8</encoding>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
@@ -84,15 +56,15 @@
<mainClass>org.onap.dcaegen2.collectors.datafile.MainApp</mainClass>
</configuration>
</plugin>
- <!-- This plugin may go away in favor of a custom Dockerfile provided by Carsten and co. -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
- <skipDockerBuild>false</skipDockerBuild>
- <imageName>
- ${docker.repo.url}/onap/${project.groupId}.${project.artifactId}
- </imageName>
+ <serverId>${onap.nexus.dockerregistry.daily}</serverId>
+ <imageName>${docker.image.name}</imageName>
+ <imageTags>
+ <tag>latest</tag>
+ </imageTags>
<baseImage>openjdk:8-jre-alpine</baseImage>
<entryPoint>["java", "-jar", "/opt/${project.fatJar.finalName}.jar"]</entryPoint>
<resources>
@@ -103,7 +75,7 @@
</resource>
<resource>
<targetPath>/config</targetPath>
- <directory>${project.build.directory}/config</directory>
+ <directory>${project.basedir}/config</directory>
<include>*</include>
</resource>
</resources>
@@ -111,36 +83,73 @@
<expose>8100</expose>
<expose>8433</expose>
</exposes>
- <imageTags>
- <imageTag>${project.version}-SNAPSHOT-${maven.build.timestamp}Z</imageTag>
- <imageTag>${project.version}</imageTag>
- <imageTag>latest</imageTag>
- </imageTags>
- <serverId>${docker.repo.url}</serverId>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.sonatype.plugins</groupId>
- <artifactId>nexus-staging-maven-plugin</artifactId>
- <version>1.6.7</version>
- <extensions>true</extensions>
- <configuration>
- <serverId>ecomp-staging</serverId>
- <nexusUrl>${nexusproxy}</nexusUrl>
- <stagingProfileId>176c31dfe190a</stagingProfileId>
- <skipNexusStagingDeployMojo>${nexus.staging}</skipNexusStagingDeployMojo>
</configuration>
+ <executions>
+ <execution>
+ <id>build-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-latest</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:latest</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:${project.version}</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version-and-date</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:${project.version}-${maven.build.timestamp}Z</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
<dependencies>
-
- <!--DEVELOPMENT DEPENDENCIES-->
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-core</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
+ <groupId>org.immutables</groupId>
+ <artifactId>value</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.immutables</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
@@ -155,60 +164,17 @@
</exclusions>
</dependency>
<dependency>
- <groupId>io.projectreactor</groupId>
- <artifactId>reactor-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcprov-jdk15on</artifactId>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
</dependency>
<dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-jdk15on</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-el</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-websocket</artifactId>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>value</artifactId>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>gson</artifactId>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-commons</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
-
-
- <!-- LOGGING DEPENDENCIES-->
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jul-to-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
+ <artifactId>datafile-dmaap-client</artifactId>
+ <version>${project.parent.version}</version>
</dependency>
<!--TESTS DEPENDENCIES -->
@@ -223,11 +189,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
@@ -235,6 +196,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -254,16 +216,17 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-aai-client</artifactId>
- <version>${project.parent.version}</version>
+ <groupId>org.mockftpserver</groupId>
+ <artifactId>MockFtpServer</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-dmaap-client</artifactId>
- <version>${project.parent.version}</version>
+ <groupId>com.github.stefanbirkner</groupId>
+ <artifactId>fake-sftp-server-rule</artifactId>
+ <scope>test</scope>
</dependency>
<!--REQUIRED TO GENERATE DOCUMENTATION -->
@@ -275,6 +238,7 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
+
</dependencies>
<dependencyManagement>
<dependencies>
@@ -282,7 +246,7 @@
<!-- IMPORT DEPENDENCY MANAGEMENT FROM SPRING BOOT -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
- <version>2.0.1.RELEASE</version>
+ <version>2.0.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java
index 63fbccb0..d0443ecf 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,29 +13,24 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile;
import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-@SpringBootApplication
-@Configuration
-@ComponentScan
-@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class})
+@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
@EnableScheduling
public class MainApp {
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java
index 1fd50c94..245e0959 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,35 +13,30 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.configuration;
import java.util.Optional;
-import java.util.function.Predicate;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.collectors.datafile.config.ImmutableAaiClientConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
-
/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Component
@Configuration
public class AppConfig extends DatafileAppConfig {
- private static Predicate<String> isEmpty = String::isEmpty;
@Value("${dmaap.dmaapConsumerConfiguration.dmaapHostName:}")
public String consumerDmaapHostName;
@@ -71,8 +64,8 @@ public class AppConfig extends DatafileAppConfig {
@Value("${dmaap.dmaapConsumerConfiguration.consumerGroup:}")
public String consumerGroup;
- @Value("${dmaap.dmaapConsumerConfiguration.timeoutMs:}")
- public Integer consumerTimeoutMs;
+ @Value("${dmaap.dmaapConsumerConfiguration.timeoutMS:}")
+ public Integer consumerTimeoutMS;
@Value("${dmaap.dmaapConsumerConfiguration.message-limit:}")
public Integer consumerMessageLimit;
@@ -98,113 +91,65 @@ public class AppConfig extends DatafileAppConfig {
@Value("${dmaap.dmaapProducerConfiguration.dmaapContentType:}")
public String producerDmaapContentType;
- @Value("${aai.aaiClientConfiguration.aaiHost:}")
- public String aaiHost;
-
- @Value("${aai.aaiClientConfiguration.aaiHostPortNumber:}")
- public Integer aaiPort;
-
- @Value("${aai.aaiClientConfiguration.aaiProtocol:}")
- public String aaiProtocol;
-
- @Value("${aai.aaiClientConfiguration.aaiUserName:}")
- public String aaiUserName;
-
- @Value("${aai.aaiClientConfiguration.aaiUserPassword:}")
- public String aaiUserPassword;
-
- @Value("${aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors:}")
- public Boolean aaiIgnoreSslCertificateErrors;
-
- @Value("${aai.aaiClientConfiguration.aaiBasePath:}")
- public String aaiBasePath;
-
- @Value("${aai.aaiClientConfiguration.aaiPnfPath:}")
- public String aaiPnfPath;
-
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return new ImmutableDmaapConsumerConfiguration.Builder()
.dmaapUserPassword(
- Optional.ofNullable(consumerDmaapUserPassword).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapUserPassword).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapUserPassword()))
.dmaapUserName(
- Optional.ofNullable(consumerDmaapUserName).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapUserName).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapUserName()))
.dmaapHostName(
- Optional.ofNullable(consumerDmaapHostName).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapHostName).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapHostName()))
.dmaapPortNumber(
Optional.ofNullable(consumerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapPortNumber()))
.dmaapProtocol(
- Optional.ofNullable(consumerDmaapProtocol).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapProtocol).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapProtocol()))
.dmaapContentType(
- Optional.ofNullable(consumerDmaapContentType).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapContentType).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapContentType()))
.dmaapTopicName(
- Optional.ofNullable(consumerDmaapTopicName).filter(isEmpty.negate())
+ Optional.ofNullable(consumerDmaapTopicName).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.dmaapTopicName()))
.messageLimit(
Optional.ofNullable(consumerMessageLimit).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.messageLimit()))
- .timeoutMs(Optional.ofNullable(consumerTimeoutMs).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.timeoutMs()))
- .consumerGroup(Optional.ofNullable(consumerGroup).filter(isEmpty.negate())
+ .timeoutMS(Optional.ofNullable(consumerTimeoutMS).filter(p -> !p.toString().isEmpty())
+ .orElse(dmaapConsumerConfiguration.timeoutMS()))
+ .consumerGroup(Optional.ofNullable(consumerGroup).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.consumerGroup()))
- .consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate())
+ .consumerId(Optional.ofNullable(consumerId).filter(p -> !p.isEmpty())
.orElse(dmaapConsumerConfiguration.consumerId()))
.build();
}
@Override
- public AaiClientConfiguration getAaiClientConfiguration() {
- return new ImmutableAaiClientConfiguration.Builder()
- .aaiHost(Optional.ofNullable(aaiHost).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiHost()))
- .aaiPort(
- Optional.ofNullable(aaiPort).filter(p -> !p.toString().isEmpty())
- .orElse(aaiClientConfiguration.aaiPort()))
- .aaiIgnoreSslCertificateErrors(
- Optional.ofNullable(aaiIgnoreSslCertificateErrors).filter(p -> !p.toString().isEmpty())
- .orElse(aaiClientConfiguration.aaiIgnoreSslCertificateErrors()))
- .aaiProtocol(
- Optional.ofNullable(aaiProtocol).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiProtocol()))
- .aaiUserName(
- Optional.ofNullable(aaiUserName).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiUserName()))
- .aaiUserPassword(Optional.ofNullable(aaiUserPassword).filter(isEmpty.negate())
- .orElse(aaiClientConfiguration.aaiUserPassword()))
- .aaiBasePath(Optional.ofNullable(aaiBasePath).filter(isEmpty.negate())
- .orElse(aaiClientConfiguration.aaiBasePath()))
- .aaiPnfPath(
- Optional.ofNullable(aaiPnfPath).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiPnfPath()))
- .aaiHeaders(aaiClientConfiguration.aaiHeaders())
- .build();
- }
-
- @Override
public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
return new ImmutableDmaapPublisherConfiguration.Builder()
.dmaapContentType(
- Optional.ofNullable(producerDmaapContentType).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapContentType).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapContentType()))
.dmaapHostName(
- Optional.ofNullable(producerDmaapHostName).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapHostName).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapHostName()))
.dmaapPortNumber(
Optional.ofNullable(producerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapPortNumber()))
.dmaapProtocol(
- Optional.ofNullable(producerDmaapProtocol).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapProtocol).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapProtocol()))
.dmaapTopicName(
- Optional.ofNullable(producerDmaapTopicName).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapTopicName).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapTopicName()))
.dmaapUserName(
- Optional.ofNullable(producerDmaapUserName).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapUserName).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapUserName()))
.dmaapUserPassword(
- Optional.ofNullable(producerDmaapUserPassword).filter(isEmpty.negate())
+ Optional.ofNullable(producerDmaapUserPassword).filter(p -> !p.isEmpty())
.orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
.build();
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java
index 5c6f1512..5ab4358a 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,24 +13,22 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.configuration;
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/25/18
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public interface Config {
DmaapConsumerConfiguration getDmaapConsumerConfiguration();
- AaiClientConfiguration getAaiClientConfiguration();
-
DmaapPublisherConfiguration getDmaapPublisherConfiguration();
void initFileStreamReader();
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java
index 169bf8ed..b6525f0f 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,30 +13,21 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.configuration;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.TypeAdapterFactory;
-
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-
-import java.nio.charset.StandardCharsets;
import java.util.ServiceLoader;
+
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
import org.slf4j.Logger;
@@ -47,8 +36,16 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapterFactory;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Configuration
@EnableConfigurationProperties
@@ -56,15 +53,11 @@ import org.springframework.context.annotation.Configuration;
public abstract class DatafileAppConfig implements Config {
private static final String CONFIG = "configs";
- private static final String AAI = "aai";
private static final String DMAAP = "dmaap";
- private static final String AAI_CONFIG = "aaiClientConfiguration";
private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- AaiClientConfiguration aaiClientConfiguration;
+ private static final Logger logger = LoggerFactory.getLogger(DatafileAppConfig.class);
DmaapConsumerConfiguration dmaapConsumerConfiguration;
@@ -80,11 +73,6 @@ public abstract class DatafileAppConfig implements Config {
}
@Override
- public AaiClientConfiguration getAaiClientConfiguration() {
- return aaiClientConfiguration;
- }
-
- @Override
public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
return dmaapPublisherConfiguration;
}
@@ -100,10 +88,6 @@ public abstract class DatafileAppConfig implements Config {
JsonElement rootElement = getJsonElement(parser, inputStream);
if (rootElement.isJsonObject()) {
jsonObject = rootElement.getAsJsonObject();
- aaiClientConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
- AaiClientConfiguration.class);
-
dmaapConsumerConfiguration = deserializeType(gsonBuilder,
jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
DmaapConsumerConfiguration.class);
@@ -113,14 +97,14 @@ public abstract class DatafileAppConfig implements Config {
DmaapPublisherConfiguration.class);
}
} catch (IOException e) {
- logger.warn("Problem with file loading, file: {}", filepath, e);
+ logger.error("Problem with file loading, file: {}", filepath, e);
} catch (JsonSyntaxException e) {
- logger.warn("Problem with Json deserialization", e);
+ logger.error("Problem with Json deserialization", e);
}
}
JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
- return parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
+ return parser.parse(new InputStreamReader(inputStream));
}
private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java
index 823fe732..1d0a192f 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java
@@ -1,29 +1,25 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.configuration;
-import io.swagger.annotations.ApiOperation;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
+
import javax.annotation.PostConstruct;
import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
@@ -33,6 +29,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
+
+import io.swagger.annotations.ApiOperation;
import reactor.core.publisher.Mono;
/**
@@ -43,7 +41,7 @@ import reactor.core.publisher.Mono;
public class SchedulerConfig extends DatafileAppConfig {
private static final int SCHEDULING_DELAY = 2000;
- private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<>();
+ private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<ScheduledFuture>();
private final TaskScheduler taskScheduler;
private final ScheduledTasks scheduledTask;
@@ -63,9 +61,8 @@ public class SchedulerConfig extends DatafileAppConfig {
public synchronized Mono<ResponseEntity<String>> getResponseFromCancellationOfTasks() {
scheduledFutureList.forEach(x -> x.cancel(false));
scheduledFutureList.clear();
- return Mono.defer(() ->
- Mono.just(new ResponseEntity<>("Datafile Service has already been stopped!", HttpStatus.CREATED))
- );
+ return Mono.defer(() -> Mono
+ .just(new ResponseEntity<>("Datafile Service has already been stopped!", HttpStatus.CREATED)));
}
/**
@@ -77,8 +74,8 @@ public class SchedulerConfig extends DatafileAppConfig {
@ApiOperation(value = "Start task if possible")
public synchronized boolean tryToStartTask() {
if (scheduledFutureList.isEmpty()) {
- scheduledFutureList.add(taskScheduler
- .scheduleWithFixedDelay(scheduledTask::scheduleMainDatafileEventTask, SCHEDULING_DELAY));
+ scheduledFutureList.add(taskScheduler.scheduleWithFixedDelay(scheduledTask::scheduleMainDatafileEventTask,
+ SCHEDULING_DELAY));
return true;
} else {
return false;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java
index c45b136a..967be5f6 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,7 +13,7 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.configuration;
@@ -25,6 +23,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -37,46 +36,42 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@Configuration
@Profile("prod")
-public class SwaggerConfig extends WebMvcConfigurationSupport {
+public class SwaggerConfig extends WebMvcConfigurationSupport{
- private static final String PACKAGE_PATH = "org.onap.dcaegen2.collectors.datafile";
- private static final String API_TITLE = "Datafile app server";
- private static final String DESCRIPTION = "This page lists all the rest apis for Datafile app server.";
- private static final String VERSION = "1.0";
- private static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
- private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
- private static final String SWAGGER_UI = "swagger-ui.html";
- private static final String WEBJARS = "/webjars/**";
+ public static final String PACKAGE_PATH = "org.onap.dcaegen2.collectors.datafile";
+ public static final String API_TITLE = "DATAFILE app server";
+ public static final String DESCRIPTION = "This page lists all the rest apis for DATAFILE app server.";
+ public static final String VERSION = "1.0";
+ public static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
+ public static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
+ public static final String SWAGGER_UI = "swagger-ui.html";
+ public static final String WEBJARS = "/webjars/**";
- /**
- * Swagger configuration function for hosting it next to spring http website.
- * @return Docket
- */
- @Bean
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
- .paths(PathSelectors.any())
- .build();
- }
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
+ .paths(PathSelectors.any())
+ .build();
+ }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title(API_TITLE)
- .description(DESCRIPTION)
- .version(VERSION)
- .build();
- }
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title(API_TITLE)
+ .description(DESCRIPTION)
+ .version(VERSION)
+ .build();
+ }
- @Override
- protected void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler(SWAGGER_UI)
- .addResourceLocations(RESOURCES_PATH);
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler(SWAGGER_UI)
+ .addResourceLocations(RESOURCES_PATH);
- registry.addResourceHandler(WEBJARS)
- .addResourceLocations(WEBJARS_PATH);
- }
-} \ No newline at end of file
+ registry.addResourceHandler(WEBJARS)
+ .addResourceLocations(WEBJARS_PATH);
+ }
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/TomcatHttpConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/TomcatHttpConfig.java
deleted file mode 100644
index b6231418..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/TomcatHttpConfig.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.configuration;
-
-import org.apache.catalina.connector.Connector;
-import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
-import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/18/18
- */
-@Configuration
-public class TomcatHttpConfig {
-
- /**
- * Class for setting up hosting Datafile on http/https.
- *
- * @return ServletWebServerFactory
- */
- @Bean
- public ServletWebServerFactory servletContainer() {
- TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
- tomcat.addAdditionalTomcatConnectors(getHttpConnector());
- return tomcat;
- }
-
- private Connector getHttpConnector() {
- Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
- connector.setScheme("http");
- connector.setPort(8100);
- connector.setSecure(false);
- return connector;
- }
-
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java
index 070fe591..98dfdedc 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,15 +13,11 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.controllers;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@@ -31,35 +25,36 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@RestController
-@Api(value = "HeartbeatController", description = "Check liveness of Datafile service")
+@Api(value = "HeartbeatController", description = "Check liveness of DATAFILE service")
public class HeartbeatController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
- /**
- * Endpoint for checking that Datafile is alive.
- *
- * @return HTTP Status Code
- */
@RequestMapping(value = "heartbeat", method = RequestMethod.GET)
- @ApiOperation(value = "Returns liveness of Datafile service")
+ @ApiOperation(value = "Returns liveness of DATAFILE service")
@ApiResponses(value = {
- @ApiResponse(code = 200, message = "Datafile sevice is living"),
- @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
- @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
- @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
- }
+ @ApiResponse(code = 200, message = "DATAFILE service is living"),
+ @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
+ @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
+ @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
+ }
)
public Mono<ResponseEntity<String>> heartbeat() {
logger.trace("Receiving heartbeat request");
return Mono.defer(() ->
- Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
+ Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK))
);
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java
index f3cf354f..5765b31c 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,14 +13,11 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.controllers;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
import org.onap.dcaegen2.collectors.datafile.configuration.SchedulerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,16 +27,21 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/5/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
+
@RestController
@Api(value = "ScheduleController", description = "Schedule Controller")
public class ScheduleController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
private final SchedulerConfig schedulerConfig;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java
index 41f77332..2d62871c 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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,13 +13,13 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.exceptions;
/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public class DatafileTaskException extends Exception {
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java
index d9f6f873..cf387296 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,7 +13,7 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.exceptions;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java
index ebff8ae3..e27a2036 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,7 +13,7 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.exceptions;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollector.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollector.java
new file mode 100644
index 00000000..0f03b1a4
--- /dev/null
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollector.java
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Ericsson. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FilenameUtils;
+import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.service.FileData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import reactor.core.publisher.Mono;
+
+/**
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
+ *
+ */
+@Component
+public class FileCollector { // TODO: Should be final, but that means adding PowerMock or Mockito
+ // 2.x for testing so it is left for later improvement.
+ private static final String FTPES = "ftpes";
+ private static final String FTPS = "ftps";
+ private static final String SFTP = "sftp";
+
+ private static final Logger logger = LoggerFactory.getLogger(FileCollector.class);
+
+ private final FtpsClient ftpsClient;
+ private final SftpClient sftpClient;
+
+ @Autowired
+ protected FileCollector(FtpsClient ftpsCleint, SftpClient sftpClient) {
+ this.ftpsClient = ftpsCleint;
+ this.sftpClient = sftpClient;
+ }
+
+ public Mono<List<ConsumerDmaapModel>> getFilesFromSender(List<FileData> listOfFileData) {
+ List<ConsumerDmaapModel> consumerModels = new ArrayList<ConsumerDmaapModel>();
+ for (FileData fileData : listOfFileData) {
+ String localFile = collectFile(fileData);
+
+ if (localFile != null) {
+ ConsumerDmaapModel consumerDmaapModel = getConsumerDmaapModel(fileData, localFile);
+ consumerModels.add(consumerDmaapModel);
+ }
+ }
+ return Mono.just(consumerModels);
+ }
+
+ private String collectFile(FileData fileData) {
+ String location = fileData.location();
+ URI uri = URI.create(location);
+ String[] userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo());
+ FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(uri.getHost())
+ .userId(userInfo != null ? userInfo[0] : "").password(userInfo != null ? userInfo[1] : "")
+ .port(uri.getPort()).build();
+ String remoteFile = uri.getPath();
+ String localFile = "target/" + FilenameUtils.getName(remoteFile);
+ String scheme = uri.getScheme();
+
+ boolean fileDownloaded = false;
+ if (FTPES.equals(scheme) || FTPS.equals(scheme)) {
+ fileDownloaded = ftpsClient.collectFile(fileServerData, remoteFile, localFile);
+ } else if (SFTP.equals(scheme)) {
+ fileDownloaded = sftpClient.collectFile(fileServerData, remoteFile, localFile);
+ } else {
+
+ logger.error("DFC does not support protocol {}. Supported protocols are " + FTPES + ", " + FTPS + ", and "
+ + SFTP + ". " + fileData);
+ localFile = null;
+ }
+ if (!fileDownloaded) {
+ localFile = null;
+ }
+ return localFile;
+ }
+
+ private String[] getUserNameAndPasswordIfGiven(String userInfoString) {
+ String[] userInfo = null;
+ if (userInfoString != null && !userInfoString.isEmpty()) {
+ userInfo = userInfoString.split(":");
+ }
+ return userInfo;
+ }
+
+ private ConsumerDmaapModel getConsumerDmaapModel(FileData fileData, String localFile) {
+ String compression = fileData.compression();
+ String fileFormatType = fileData.fileFormatType();
+ String fileFormatVersion = fileData.fileFormatVersion();
+
+ return ImmutableConsumerDmaapModel.builder().location(localFile).compression(compression)
+ .fileFormatType(fileFormatType).fileFormatVersion(fileFormatVersion).build();
+ }
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileServerData.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileServerData.java
new file mode 100644
index 00000000..d4eca4d7
--- /dev/null
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileServerData.java
@@ -0,0 +1,31 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import org.immutables.value.Value;
+
+/**
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
+ *
+ */
+@Value.Immutable
+public interface FileServerData {
+ public String serverAddress();
+ public String userId();
+ public String password();
+ public int port();
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
new file mode 100644
index 00000000..a3f75826
--- /dev/null
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
@@ -0,0 +1,117 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.commons.net.util.TrustManagerUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Gets file from xNF with FTPS protocol.
+ *
+ * TODO: Refactor for better test.
+ *
+ * @author <a href="mailto:martin.c.yan@est.tech">Martin Yan</a>
+ *
+ */
+@Component
+public class FtpsClient { // TODO: Should be final but needs PowerMock or Mockito 2.x to be able to
+ // mock then, so this will be done as an improvement after first version
+ // committed.
+ private static final Logger logger = LoggerFactory.getLogger(FtpsClient.class);
+
+ public boolean collectFile(FileServerData fileServerData, String remoteFile, String localFile) {
+ boolean result = true;
+ try {
+ FTPSClient ftps = new FTPSClient("TLS");
+
+ result = setUpConnection(fileServerData, ftps);
+
+ if (result) {
+ getFile(remoteFile, localFile, ftps);
+
+ closeDownConnection(ftps);
+ }
+ } catch (IOException ex) {
+ logger.error("Unable to collect file from xNF. " + fileServerData, ex);
+ result = false;
+ }
+ return result;
+ }
+
+ private boolean setUpConnection(FileServerData fileServerData, FTPSClient ftps) {
+ boolean success = true;
+ ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
+
+ try {
+ ftps.connect(fileServerData.serverAddress(), fileServerData.port());
+
+ if (!ftps.login(fileServerData.userId(), fileServerData.password())) {
+ ftps.logout();
+ logger.error("Unable to log in to xNF. " + fileServerData);
+ success = false;
+ }
+
+ if (success) {
+ int reply = ftps.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply)) {
+ ftps.disconnect();
+ logger.error("Unable to connect in to xNF. " + fileServerData);
+ success = false;
+ }
+ ftps.enterLocalPassiveMode();
+ }
+ } catch (Exception ex) {
+ logger.error("Unable to connect to xNF." + fileServerData, ex);
+ success = false;
+ }
+
+ return success;
+ }
+
+ private void getFile(String remoteFile, String localFile, FTPSClient ftps)
+ throws IOException, FileNotFoundException {
+ OutputStream output;
+ File outfile = new File(localFile);
+ outfile.createNewFile();
+
+ output = new FileOutputStream(outfile);
+
+ ftps.retrieveFile(remoteFile, output);
+
+ output.close();
+ logger.debug("File " + outfile.getName() + " Download Successfull from xNF");
+ }
+
+ private void closeDownConnection(FTPSClient ftps) {
+ try {
+ ftps.logout();
+ ftps.disconnect();
+ } catch (Exception e) {
+ // Do nothing, file has been collected.
+ }
+ }
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java
new file mode 100644
index 00000000..e7c7c09b
--- /dev/null
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java
@@ -0,0 +1,98 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.SftpException;
+
+import org.apache.commons.io.FilenameUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Gets file from xNF with SFTP protocol.
+ *
+ * TODO: Refactor for better test.
+ *
+ * @author <a href="mailto:martin.c.yan@est.tech">Martin Yan</a>
+ *
+ */
+@Component
+public class SftpClient { // TODO: Should be final but needs PowerMock to be able to mock then, so
+ // this will be done as an improvement after first version committed.
+ private static final Logger logger = LoggerFactory.getLogger(SftpClient.class);
+
+ public boolean collectFile(FileServerData fileServerData, String remoteFile, String localFile) {
+ boolean result = true;
+ Session session = setUpSession(fileServerData);
+
+ if (session != null) {
+ ChannelSftp sftpChannel = getChannel(session, fileServerData);
+ if (sftpChannel != null) {
+ try {
+ sftpChannel.get(remoteFile, localFile);
+ logger.debug("File " + FilenameUtils.getName(localFile) + " Download Successfull from xNF");
+ } catch (SftpException e) {
+ logger.error("Unable to get file from xNF. " + fileServerData, e);
+ result = false;
+ }
+
+ sftpChannel.exit();
+ } else {
+ result = false;
+ }
+ session.disconnect();
+ } else {
+ result = false;
+ }
+ return result;
+ }
+
+ private Session setUpSession(FileServerData fileServerData) {
+ JSch jsch = new JSch(); // TODO: Might be changed to use Spring as an improvement after
+ // first version committed.
+
+ Session session = null;
+ try {
+ session = jsch.getSession(fileServerData.userId(), fileServerData.serverAddress(), fileServerData.port());
+ session.setConfig("StrictHostKeyChecking", "no");
+ session.setPassword(fileServerData.password());
+ session.connect();
+ } catch (JSchException e) {
+ logger.error("Unable to set up SFTP connection to xNF. " + fileServerData, e);
+ }
+ return session;
+ }
+
+ private ChannelSftp getChannel(Session session, FileServerData fileServerData) {
+ ChannelSftp sftpChannel = null;
+ try {
+ Channel channel;
+ channel = session.openChannel("sftp");
+ channel.connect();
+ sftpChannel = (ChannelSftp) channel;
+ } catch (JSchException e) {
+ logger.error("Unable to get sftp channel to xNF. " + fileServerData, e);
+ }
+ return sftpChannel;
+ }
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
index aeaf0da1..98f3a72a 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
@@ -1,130 +1,171 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.service;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Optional;
import java.util.stream.StreamSupport;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
import org.springframework.util.StringUtils;
+
import reactor.core.publisher.Mono;
/**
+ * Parses the fileReady event and creates an array of FileData containing the information.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public class DmaapConsumerJsonParser {
private static final String EVENT = "event";
- private static final String OTHER_FIELDS = "otherFields";
- private static final String PNF_OAM_IPV_4_ADDRESS = "pnfOamIpv4Address";
- private static final String PNF_OAM_IPV_6_ADDRESS = "pnfOamIpv6Address";
- private static final String PNF_VENDOR_NAME = "pnfVendorName";
- private static final String PNF_SERIAL_NUMBER = "pnfSerialNumber";
+ private static final String NOTIFICATION_FIELDS = "notificationFields";
+ private static final String CHANGE_IDENTIFIER = "changeIdentifier";
+ private static final String CHANGE_TYPE = "changeType";
+ private static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion";
+
+ private static final String LOCATION = "location";
+ private static final String COMPRESSION = "compression";
+ private static final String FILE_FORMAT_TYPE = "fileFormatType";
+ private static final String FILE_FORMAT_VERSION = "fileFormatVersion";
/**
- * Extract info from string and create @see {@link org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel}.
+ * Extract info from string and create @see
+ * {@link org.onap.dcaegen2.collectors.datafile.service.FileData}.
*
* @param monoMessage - results from DMaaP
- * @return reactive DMaaPModel
+ * @return reactive Mono with an array of FileData
*/
- public Mono<ConsumerDmaapModel> getJsonObject(Mono<String> monoMessage) {
- return monoMessage
- .flatMap(this::getJsonParserMessage)
- .flatMap(this::createJsonConsumerModel);
+ public Mono<List<FileData>> getJsonObject(Mono<String> monoMessage) {
+ return monoMessage.flatMap(this::getJsonParserMessage).flatMap(this::createJsonConsumerModel);
}
private Mono<JsonElement> getJsonParserMessage(String message) {
return StringUtils.isEmpty(message) ? Mono.error(new DmaapEmptyResponseException())
- : Mono.fromSupplier(() -> new JsonParser().parse(message));
+ : Mono.fromSupplier(() -> new JsonParser().parse(message));
}
- private Mono<ConsumerDmaapModel> createJsonConsumerModel(JsonElement jsonElement) {
- return jsonElement.isJsonObject()
- ? create(Mono.fromSupplier(jsonElement::getAsJsonObject))
- : getConsumerDmaapModelFromJsonArray(jsonElement);
+ private Mono<List<FileData>> createJsonConsumerModel(JsonElement jsonElement) {
+ return jsonElement.isJsonObject() ? create(Mono.fromSupplier(jsonElement::getAsJsonObject))
+ : getFileDataFromJsonArray(jsonElement);
}
- private Mono<ConsumerDmaapModel> getConsumerDmaapModelFromJsonArray(JsonElement jsonElement) {
- return create(
- Mono.fromCallable(() -> StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
- .flatMap(this::getJsonObjectFromAnArray)
- .orElseThrow(DmaapEmptyResponseException::new)));
+ private Mono<List<FileData>> getFileDataFromJsonArray(JsonElement jsonElement) {
+ return create(Mono.fromCallable(() -> StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false)
+ .findFirst().flatMap(this::getJsonObjectFromAnArray).orElseThrow(DmaapEmptyResponseException::new)));
}
public Optional<JsonObject> getJsonObjectFromAnArray(JsonElement element) {
return Optional.of(new JsonParser().parse(element.getAsString()).getAsJsonObject());
}
- private Mono<ConsumerDmaapModel> create(Mono<JsonObject> jsonObject) {
- return jsonObject.flatMap(monoJsonP ->
- !containsHeader(monoJsonP) ? Mono.error(new DmaapNotFoundException("Incorrect JsonObject - missing header"))
+ private Mono<List<FileData>> create(Mono<JsonObject> jsonObject) {
+ return jsonObject.flatMap(monoJsonP -> !containsHeader(monoJsonP)
+ ? Mono.error(new DmaapNotFoundException("Incorrect JsonObject - missing header"))
: transform(monoJsonP));
}
- private Mono<ConsumerDmaapModel> transform(JsonObject monoJsonP) {
- monoJsonP = monoJsonP.getAsJsonObject(EVENT).getAsJsonObject(OTHER_FIELDS);
- String pnfVendorName = getValueFromJson(monoJsonP, PNF_VENDOR_NAME);
- String pnfSerialNumber = getValueFromJson(monoJsonP, PNF_SERIAL_NUMBER);
- String pnfOamIpv4Address = getValueFromJson(monoJsonP, PNF_OAM_IPV_4_ADDRESS);
- String pnfOamIpv6Address = getValueFromJson(monoJsonP, PNF_OAM_IPV_6_ADDRESS);
- return
- (!vendorAndSerialNotEmpty(pnfSerialNumber, pnfVendorName) || !ipPropertiesNotEmpty(pnfOamIpv4Address,
- pnfOamIpv6Address))
- ? Mono.error(new DmaapNotFoundException("Incorrect json, consumerDmaapModel can not be created: "
- + printMessage(pnfVendorName, pnfSerialNumber, pnfOamIpv4Address, pnfOamIpv6Address))) :
- Mono.just(ImmutableConsumerDmaapModel.builder()
- .pnfName(pnfVendorName.substring(0, Math.min(pnfVendorName.length(), 3)).toUpperCase()
- .concat(pnfSerialNumber)).ipv4(pnfOamIpv4Address)
- .ipv6(pnfOamIpv6Address).build());
+ private Mono<List<FileData>> transform(JsonObject jsonObject) {
+ if (containsHeader(jsonObject, EVENT, NOTIFICATION_FIELDS)) {
+ JsonObject notificationFields = jsonObject.getAsJsonObject(EVENT).getAsJsonObject(NOTIFICATION_FIELDS);
+ String changeIdentifier = getValueFromJson(notificationFields, CHANGE_IDENTIFIER);
+ String changeType = getValueFromJson(notificationFields, CHANGE_TYPE);
+ String notificationFieldsVersion = getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION);
+ JsonArray arrayOfAdditionalFields = notificationFields.getAsJsonArray("arrayOfAdditionalFields");
+
+ if (isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)
+ && arrayOfAdditionalFields != null) {
+ Mono<List<FileData>> res =
+ getFileDataFromJson(changeIdentifier, changeType, arrayOfAdditionalFields);
+ return res;
+ }
+
+ if (!isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)) {
+ return Mono.error(
+ new DmaapNotFoundException("FileReady event header is missing information. " + jsonObject));
+ } else if (arrayOfAdditionalFields != null) {
+ return Mono.error(new DmaapNotFoundException(
+ "FileReady event arrayOfAdditionalFields is missing. " + jsonObject));
+ }
+ return Mono.error(
+ new DmaapNotFoundException("FileReady event does not contain correct information. " + jsonObject));
+ }
+ return Mono.error(
+ new DmaapNotFoundException("FileReady event has incorrect JsonObject - missing header. " + jsonObject));
+
+ }
+
+ private Mono<List<FileData>> getFileDataFromJson(String changeIdentifier, String changeType,
+ JsonArray arrayOfAdditionalFields) {
+ List<FileData> res = new ArrayList<>();
+ for (int i = 0; i < arrayOfAdditionalFields.size(); i++) {
+ if (arrayOfAdditionalFields.get(i) != null) {
+ JsonObject fileInfo = (JsonObject) arrayOfAdditionalFields.get(i);
+ String fileFormatType = getValueFromJson(fileInfo, FILE_FORMAT_TYPE);
+ String fileFormatVersion = getValueFromJson(fileInfo, FILE_FORMAT_VERSION);
+ String location = getValueFromJson(fileInfo, LOCATION);
+ String compression = getValueFromJson(fileInfo, COMPRESSION);
+ if (isFileFormatFieldsNotEmpty(fileFormatVersion, fileFormatType)
+ && isLocationAndCompressionNotEmpty(location, compression)) {
+ res.add(ImmutableFileData.builder().changeIdentifier(changeIdentifier).changeType(changeType)
+ .location(location).compression(compression).fileFormatType(fileFormatType)
+ .fileFormatVersion(fileFormatVersion).build());
+ } else {
+ return Mono.error(new DmaapNotFoundException(
+ "FileReady event does not contain correct file format information. " + fileInfo));
+ }
+ }
+ }
+ return Mono.just(res);
}
private String getValueFromJson(JsonObject jsonObject, String jsonKey) {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
- private boolean vendorAndSerialNotEmpty(String pnfSerialNumber, String pnfVendorName) {
- return (!StringUtils.isEmpty(pnfSerialNumber) && !StringUtils.isEmpty(pnfVendorName));
+ private boolean isNotificationFieldsHeaderNotEmpty(String changeIdentifier, String changeType,
+ String notificationFieldsVersion) {
+ return ((changeIdentifier != null && !changeIdentifier.isEmpty())
+ && (changeType != null && !changeType.isEmpty())
+ && (notificationFieldsVersion != null && !notificationFieldsVersion.isEmpty()));
+ }
+
+ private boolean isFileFormatFieldsNotEmpty(String fileFormatVersion, String fileFormatType) {
+ return ((fileFormatVersion != null && !fileFormatVersion.isEmpty())
+ && (fileFormatType != null && !fileFormatType.isEmpty()));
}
- private boolean ipPropertiesNotEmpty(String ipv4, String ipv6) {
- return (!StringUtils.isEmpty(ipv4)) || !(StringUtils.isEmpty(ipv6));
+ private boolean isLocationAndCompressionNotEmpty(String location, String compression) {
+ return (location != null && !location.isEmpty()) && (compression != null && !compression.isEmpty());
}
private boolean containsHeader(JsonObject jsonObject) {
- return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(OTHER_FIELDS);
+ return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(NOTIFICATION_FIELDS);
}
- private String printMessage(String pnfVendorName, String pnfSerialNumber, String pnfOamIpv4Address,
- String pnfOamIpv6Address) {
- return String.format("%n{"
- + "\"pnfVendorName\" : \"%s\","
- + "\"pnfSerialNumber\": \"%s\","
- + "\"pnfOamIpv4Address\": \"%s\","
- + "\"pnfOamIpv6Address\": \"%s\""
- + "%n}", pnfVendorName, pnfSerialNumber, pnfOamIpv4Address, pnfOamIpv6Address);
+ private boolean containsHeader(JsonObject jsonObject, String topHeader, String header) {
+ return jsonObject.has(topHeader) && jsonObject.getAsJsonObject(topHeader).has(header);
}
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/AaiNotFoundException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/FileData.java
index a83b5bd6..948976b6 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/AaiNotFoundException.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/FileData.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,17 +13,25 @@
* 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_END========================================================================
*/
-package org.onap.dcaegen2.collectors.datafile.exceptions;
+package org.onap.dcaegen2.collectors.datafile.service;
+
+import org.immutables.value.Value;
/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * Contains data, from the fileReady event, about the file to collect from the xNF.
+ *
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
+ *
*/
-public class AaiNotFoundException extends DatafileTaskException {
-
- public AaiNotFoundException(String message) {
- super(message);
- }
+@Value.Immutable
+public interface FileData {
+ public String changeIdentifier();
+ public String changeType();
+ public String location();
+ public String compression();
+ public String fileFormatType();
+ public String fileFormatVersion();
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTask.java
deleted file mode 100644
index 8083a255..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTask.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import java.util.Optional;
-
-import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.AaiConsumerClient;
-
-public abstract class AaiConsumerTask {
-
- abstract Optional<String> consume(ConsumerDmaapModel message) throws AaiNotFoundException;
-
- abstract AaiConsumerClient resolveClient();
-
- protected abstract String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException;
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImpl.java
deleted file mode 100644
index d487b6b2..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import java.io.IOException;
-import java.util.Optional;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.Config;
-import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.AaiConsumerClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class AaiConsumerTaskImpl extends AaiConsumerTask {
-
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- private final Config datafileAppConfig;
- private AaiConsumerClient aaiConsumerClient;
-
- @Autowired
- public AaiConsumerTaskImpl(AppConfig datafileAppConfig) {
- this.datafileAppConfig = datafileAppConfig;
- }
-
- @Override
- Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
- logger.trace("Method called with arg {}", consumerDmaapModel);
- try {
- return aaiConsumerClient.getHttpResponse(consumerDmaapModel);
- } catch (IOException e) {
- logger.warn("Get request not successful", e);
- throw new AaiNotFoundException("Get request not successful");
- }
- }
-
- @Override
- public String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
- consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
- .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task"));
- logger.trace("Method called with arg {}", consumerDmaapModel);
- aaiConsumerClient = resolveClient();
- return consume(consumerDmaapModel).orElseThrow(() -> new AaiNotFoundException("Null response code"));
- }
-
- protected AaiClientConfiguration resolveConfiguration() {
- return datafileAppConfig.getAaiClientConfiguration();
- }
-
- @Override
- AaiConsumerClient resolveClient() {
- return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AaiConsumerClient(resolveConfiguration()));
- }
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTask.java
deleted file mode 100644
index ca2d03da..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTask.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.AaiReactiveWebClient;
-import org.onap.dcaegen2.collectors.datafile.service.producer.AaiProducerReactiveHttpClient;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
- */
-public abstract class AaiProducerTask {
-
- abstract Mono<ConsumerDmaapModel> publish(Mono<ConsumerDmaapModel> message) throws AaiNotFoundException;
-
- abstract AaiProducerReactiveHttpClient resolveClient();
-
- protected abstract AaiClientConfiguration resolveConfiguration();
-
- protected abstract Mono<ConsumerDmaapModel> execute(Mono<ConsumerDmaapModel> consumerDmaapModel)
- throws DatafileTaskException;
-
- WebClient buildWebClient() {
- return new AaiReactiveWebClient().fromConfiguration(resolveConfiguration()).build();
- }
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImpl.java
deleted file mode 100644
index 9d888aa7..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImpl.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.Config;
-import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.model.utils.HttpUtils;
-import org.onap.dcaegen2.collectors.datafile.service.producer.AaiProducerReactiveHttpClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import reactor.core.publisher.Mono;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
- */
-@Component
-public class AaiProducerTaskImpl extends
- AaiProducerTask {
-
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- private final Config datafileAppConfig;
- private AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient;
-
- @Autowired
- public AaiProducerTaskImpl(AppConfig datafileAppConfig) {
- this.datafileAppConfig = datafileAppConfig;
- }
-
- @Override
- Mono<ConsumerDmaapModel> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) {
- logger.info("Sending PNF model to AAI {}", consumerDmaapModel);
- return aaiProducerReactiveHttpClient.getAaiProducerResponse(consumerDmaapModel)
- .flatMap(response -> {
- if (HttpUtils.isSuccessfulResponseCode(response)) {
- return consumerDmaapModel;
- }
- return Mono
- .error(new AaiNotFoundException("Incorrect response code for continuation of tasks workflow"));
- });
- }
-
- @Override
- AaiProducerReactiveHttpClient resolveClient() {
- return aaiProducerReactiveHttpClient == null ? new AaiProducerReactiveHttpClient(resolveConfiguration())
- .createAaiWebClient(buildWebClient()) : aaiProducerReactiveHttpClient;
- }
-
- @Override
- protected AaiClientConfiguration resolveConfiguration() {
- return datafileAppConfig.getAaiClientConfiguration();
- }
-
- @Override
- protected Mono<ConsumerDmaapModel> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DatafileTaskException {
- if (consumerDmaapModel == null) {
- throw new DmaapNotFoundException("Invoked null object to DMaaP task");
- }
- aaiProducerReactiveHttpClient = resolveClient();
- logger.trace("Method called with arg {}", consumerDmaapModel);
- return publish(consumerDmaapModel);
-
- }
-} \ No newline at end of file
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTask.java
index a5764704..30bf536e 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTask.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTask.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,35 +13,41 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.tasks;
+import java.util.List;
+
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
+import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.DMaaPReactiveWebClient;
-import org.onap.dcaegen2.collectors.datafile.service.consumer.DMaaPConsumerReactiveHttpClient;
+import org.onap.dcaegen2.collectors.datafile.service.DmaapReactiveWebClient;
+import org.onap.dcaegen2.collectors.datafile.service.FileData;
+import org.onap.dcaegen2.collectors.datafile.service.consumer.DmaapConsumerReactiveHttpClient;
import org.springframework.web.reactive.function.client.WebClient;
+
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
abstract class DmaapConsumerTask {
- abstract Mono<ConsumerDmaapModel> consume(Mono<String> message) throws DatafileTaskException;
+ abstract Mono<List<FileData>> consume(Mono<String> message) throws DmaapNotFoundException;
- abstract DMaaPConsumerReactiveHttpClient resolveClient();
+ abstract DmaapConsumerReactiveHttpClient resolveClient();
abstract void initConfigs();
protected abstract DmaapConsumerConfiguration resolveConfiguration();
- protected abstract Mono<ConsumerDmaapModel> execute(String object) throws DatafileTaskException;
+ protected abstract Mono<List<ConsumerDmaapModel>> execute(String object) throws DatafileTaskException;
WebClient buildWebClient() {
- return new DMaaPReactiveWebClient().fromConfiguration(resolveConfiguration()).build();
+ return new DmaapReactiveWebClient().fromConfiguration(resolveConfiguration()).build();
}
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java
index 8d45a7fd..fdd1bb49 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java
@@ -1,70 +1,86 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.tasks;
+import java.util.List;
+
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.configuration.Config;
+import org.onap.dcaegen2.collectors.datafile.ftp.FileCollector;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.service.DmaapConsumerJsonParser;
-import org.onap.dcaegen2.collectors.datafile.service.consumer.DMaaPConsumerReactiveHttpClient;
+import org.onap.dcaegen2.collectors.datafile.service.FileData;
+import org.onap.dcaegen2.collectors.datafile.service.consumer.DmaapConsumerReactiveHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Component
public class DmaapConsumerTaskImpl extends DmaapConsumerTask {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private final Config datafileAppConfig;
+ private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class);
+
+ private Config datafileAppConfig;
private DmaapConsumerJsonParser dmaapConsumerJsonParser;
- private DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient;
+ private DmaapConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient;
+ FileCollector fileCollector;
@Autowired
- public DmaapConsumerTaskImpl(AppConfig datafileAppConfig) {
+ public DmaapConsumerTaskImpl(AppConfig datafileAppConfig, FileCollector fileCollector) {
this.datafileAppConfig = datafileAppConfig;
this.dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
+ this.fileCollector = fileCollector;
}
- DmaapConsumerTaskImpl(AppConfig datafileAppConfig, DmaapConsumerJsonParser dmaapConsumerJsonParser) {
+ protected DmaapConsumerTaskImpl(AppConfig datafileAppConfig,
+ DmaapConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient,
+ DmaapConsumerJsonParser dmaapConsumerJsonParser, FileCollector fileCollector) {
this.datafileAppConfig = datafileAppConfig;
+ this.dmaaPConsumerReactiveHttpClient = dmaaPConsumerReactiveHttpClient;
this.dmaapConsumerJsonParser = dmaapConsumerJsonParser;
+ this.fileCollector = fileCollector;
}
@Override
- Mono<ConsumerDmaapModel> consume(Mono<String> message) {
- logger.info("Consumed model from DMaaP: {}", message);
+ Mono<List<FileData>> consume(Mono<String> message) {
+ logger.trace("Method called with arg {}", message);
return dmaapConsumerJsonParser.getJsonObject(message);
}
+ private Mono<List<ConsumerDmaapModel>> getFilesFromSender(List<FileData> listOfFileData) {
+ Mono<List<ConsumerDmaapModel>> filesFromSender = fileCollector.getFilesFromSender(listOfFileData);
+ return filesFromSender;
+ }
+
@Override
- public Mono<ConsumerDmaapModel> execute(String object) {
+ protected Mono<List<ConsumerDmaapModel>> execute(String object) {
dmaaPConsumerReactiveHttpClient = resolveClient();
logger.trace("Method called with arg {}", object);
- return consume((dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()));
+ Mono<List<FileData>> consumerResult =
+ consume((dmaaPConsumerReactiveHttpClient.getDmaapConsumerResponse()));
+ return consumerResult.flatMap(this::getFilesFromSender);
}
@Override
@@ -78,9 +94,9 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask {
}
@Override
- DMaaPConsumerReactiveHttpClient resolveClient() {
+ protected DmaapConsumerReactiveHttpClient resolveClient() {
return dmaaPConsumerReactiveHttpClient == null
- ? new DMaaPConsumerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient())
- : dmaaPConsumerReactiveHttpClient;
+ ? new DmaapConsumerReactiveHttpClient(resolveConfiguration()).createDmaapWebClient(buildWebClient())
+ : dmaaPConsumerReactiveHttpClient;
}
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTask.java
index 467eee0b..716b52c1 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTask.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTask.java
@@ -1,47 +1,48 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.tasks;
+import java.util.List;
+
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.DMaaPReactiveWebClient;
-import org.onap.dcaegen2.collectors.datafile.service.producer.DMaaPProducerReactiveHttpClient;
+import org.onap.dcaegen2.collectors.datafile.service.DmaapReactiveWebClient;
+import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
import org.springframework.web.reactive.function.client.WebClient;
+
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
abstract class DmaapPublisherTask {
- abstract Mono<String> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DatafileTaskException;
+ abstract Mono<String> publish(Mono<List<ConsumerDmaapModel>> consumerDmaapModel) throws DatafileTaskException;
- abstract DMaaPProducerReactiveHttpClient resolveClient();
+ abstract DmaapProducerReactiveHttpClient resolveClient();
protected abstract DmaapPublisherConfiguration resolveConfiguration();
- protected abstract Mono<String> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DatafileTaskException;
+ protected abstract Mono<String> execute(Mono<List<ConsumerDmaapModel>> consumerDmaapModel)
+ throws DatafileTaskException;
WebClient buildWebClient() {
- return new DMaaPReactiveWebClient().fromConfiguration(resolveConfiguration()).build();
+ return new DmaapReactiveWebClient().fromConfiguration(resolveConfiguration()).build();
}
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImpl.java
index 4d435a4f..8c4d7072 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImpl.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImpl.java
@@ -1,46 +1,47 @@
/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.tasks;
+import java.util.List;
+
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.configuration.Config;
+import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.producer.DMaaPProducerReactiveHttpClient;
+import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Component
public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class);
private final Config datafileAppConfig;
- private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient;
+ private DmaapProducerReactiveHttpClient dmaapProducerReactiveHttpClient;
@Autowired
public DmaapPublisherTaskImpl(AppConfig datafileAppConfig) {
@@ -48,20 +49,21 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
}
@Override
- Mono<String> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) {
- logger.info("Publishing on DMaaP topic {} object {}", resolveConfiguration().dmaapTopicName(),
- consumerDmaapModel);
- return dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel);
+ public Mono<String> publish(Mono<List<ConsumerDmaapModel>> consumerDmaapModels)
+ throws DatafileTaskException {
+ logger.info("Publishing on DMaaP DataRouter {}", consumerDmaapModels);
+ return dmaapProducerReactiveHttpClient.getDmaapProducerResponse(consumerDmaapModels);
}
@Override
- public Mono<String> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DmaapNotFoundException {
- if (consumerDmaapModel == null) {
+ public Mono<String> execute(Mono<List<ConsumerDmaapModel>> consumerDmaapModels)
+ throws DatafileTaskException {
+ if (consumerDmaapModels == null) {
throw new DmaapNotFoundException("Invoked null object to DMaaP task");
}
dmaapProducerReactiveHttpClient = resolveClient();
- logger.trace("Method called with arg {}", consumerDmaapModel);
- return publish(consumerDmaapModel);
+ logger.trace("Method called with arg {}", consumerDmaapModels);
+ return publish(consumerDmaapModels);
}
@Override
@@ -70,9 +72,9 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
}
@Override
- DMaaPProducerReactiveHttpClient resolveClient() {
+ DmaapProducerReactiveHttpClient resolveClient() {
return dmaapProducerReactiveHttpClient == null
- ? new DMaaPProducerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient())
- : dmaapProducerReactiveHttpClient;
+ ? new DmaapProducerReactiveHttpClient(resolveConfiguration()).createDmaapWebClient(buildWebClient())
+ : dmaapProducerReactiveHttpClient;
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java
index 2600b563..14085bb8 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,59 +13,57 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.tasks;
+import java.util.List;
import java.util.concurrent.Callable;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
+import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Component
public class ScheduledTasks {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
private final DmaapConsumerTask dmaapConsumerTask;
private final DmaapPublisherTask dmaapProducerTask;
- private final AaiProducerTask aaiProducerTask;
/**
- * Constructor for tasks registration in DatafileWorkflow.
+ * Constructor for task registration in Datafile Workflow.
*
* @param dmaapConsumerTask - fist task
- * @param dmaapPublisherTask - third task
- * @param aaiPublisherTask - second task
+ * @param dmaapPublisherTask - second task
*/
@Autowired
- public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask,
- AaiProducerTask aaiPublisherTask) {
+ public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask) {
this.dmaapConsumerTask = dmaapConsumerTask;
this.dmaapProducerTask = dmaapPublisherTask;
- this.aaiProducerTask = aaiPublisherTask;
}
/**
- * Main function for scheduling datafileWorkflow.
+ * Main function for scheduling Datafile Workflow.
*/
public void scheduleMainDatafileEventTask() {
logger.trace("Execution of tasks was registered");
- Mono<String> dmaapProducerResponse = Mono.fromCallable(consumeFromDMaaPMessage())
- .doOnError(DmaapEmptyResponseException.class, error -> logger.warn("Nothing to consume from DMaaP"))
- .map(this::publishToAaiConfiguration)
+ Mono<String> dmaapProducerResponse = Mono.fromCallable(consumeFromDmaapMessage())
+ .doOnError(DmaapEmptyResponseException.class, error -> logger.error("Nothing to consume from DMaaP"))
.flatMap(this::publishToDmaapConfiguration)
.subscribeOn(Schedulers.elastic());
@@ -84,28 +80,20 @@ public class ScheduledTasks {
private void onError(Throwable throwable) {
if (!(throwable instanceof DmaapEmptyResponseException)) {
- logger.warn("Chain of tasks have been aborted due to errors in Datafile workflow", throwable);
+ logger.error("Chain of tasks have been aborted due to errors in Datafile workflow", throwable);
}
}
- private Callable<Mono<ConsumerDmaapModel>> consumeFromDMaaPMessage() {
+ private Callable<Mono<List<ConsumerDmaapModel>>> consumeFromDmaapMessage() {
return () -> {
dmaapConsumerTask.initConfigs();
return dmaapConsumerTask.execute("");
};
}
- private Mono<ConsumerDmaapModel> publishToAaiConfiguration(Mono<ConsumerDmaapModel> monoDMaaPModel) {
- try {
- return aaiProducerTask.execute(monoDMaaPModel);
- } catch (DatafileTaskException e) {
- return Mono.error(e);
- }
- }
-
- private Mono<String> publishToDmaapConfiguration(Mono<ConsumerDmaapModel> monoAaiModel) {
+ private Mono<String> publishToDmaapConfiguration(Mono<List<ConsumerDmaapModel>> monoModel) {
try {
- return dmaapProducerTask.execute(monoAaiModel);
+ return dmaapProducerTask.execute(monoModel);
} catch (DatafileTaskException e) {
return Mono.error(e);
}
diff --git a/datafile-app-server/src/main/resources/application.properties b/datafile-app-server/src/main/resources/application.properties
index 205b6caa..2b9d7b1d 100644
--- a/datafile-app-server/src/main/resources/application.properties
+++ b/datafile-app-server/src/main/resources/application.properties
@@ -1,10 +1,9 @@
spring.profiles.active=prod
-spring.main.web-application-type=none
server.port=8433
server.ssl.key-store-type=PKCS12
-server.ssl.key-store-password=nokiapnf
+server.ssl.key-store-password=ericssondfc
server.ssl.key-store=classpath:keystore.jks
-server.ssl.key-password=nokiapnf
+server.ssl.key-password=ericssondfc
server.ssl.key-alias=tomcat-localhost
logging.level.root=ERROR
logging.level.org.springframework=ERROR
diff --git a/datafile-app-server/src/main/resources/keystore.jks b/datafile-app-server/src/main/resources/keystore.jks
index cd27cc01..574a585b 100644
--- a/datafile-app-server/src/main/resources/keystore.jks
+++ b/datafile-app-server/src/main/resources/keystore.jks
Binary files differ
diff --git a/datafile-app-server/src/main/resources/keystore.jks.old b/datafile-app-server/src/main/resources/keystore.jks.old
deleted file mode 100644
index 8a2b4f99..00000000
--- a/datafile-app-server/src/main/resources/keystore.jks.old
+++ /dev/null
Binary files differ
diff --git a/datafile-app-server/src/main/resources/logback-spring.xml b/datafile-app-server/src/main/resources/logback-spring.xml
index 925b38cc..af4ab189 100644
--- a/datafile-app-server/src/main/resources/logback-spring.xml
+++ b/datafile-app-server/src/main/resources/logback-spring.xml
@@ -12,11 +12,8 @@
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_FILE}</file>
- <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
- <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
- <maxFileSize>50MB</maxFileSize>
- <maxHistory>30</maxHistory>
- <totalSizeCap>10GB</totalSizeCap>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<root level="ERROR">
@@ -32,11 +29,12 @@
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_FILE}</file>
- <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
- <maxFileSize>50MB</maxFileSize>
- <maxHistory>30</maxHistory>
- <totalSizeCap>10GB</totalSizeCap>
+ <timeBasedFileNamingAndTriggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <maxFileSize>10MB</maxFileSize>
+ </timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
diff --git a/datafile-app-server/src/main/resources/scheduled-context.xml b/datafile-app-server/src/main/resources/scheduled-context.xml
index 369d2c7b..21996319 100644
--- a/datafile-app-server/src/main/resources/scheduled-context.xml
+++ b/datafile-app-server/src/main/resources/scheduled-context.xml
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:task="http://www.springframework.org/schema/task"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:task="http://www.springframework.org/schema/task"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
- <context:component-scan
- base-package="org.onap.dcaegen2.collectors.datafile"/>
- <task:scheduled-tasks>
- <task:scheduled ref="scheduleController" method="startTasks"
- fixed-rate="1000"/>
- </task:scheduled-tasks>
+ <context:component-scan
+ base-package="org.onap.dcaegen2.collectors.datafile" />
+ <task:scheduled-tasks>
+ <task:scheduled ref="scheduleController"
+ method="startTasks" fixed-rate="1000" />
+ </task:scheduled-tasks>
</beans>
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
index 7d54b4d5..12c8c7e7 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
@@ -1,21 +1,17 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.configuration;
@@ -31,154 +27,122 @@ import static org.mockito.Mockito.when;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.DatafileAppConfig;
import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@ExtendWith({MockitoExtension.class})
class DatafileAppConfigTest {
private static final String DATAFILE_ENDPOINTS = "datafile_endpoints.json";
- private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
- + "\"localhost\",\"aaiPort\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":"
- + "\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\","
- + "\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"datafile\",\"X-TransactionId\":\"9999\","
- + "\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Content-Type\":\"application/merge-patch+json\","
- + "\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},"
- + "\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\","
- + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,"
- + "\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\""
- + ":\"admin\",\"messageLimit\":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":"
- + "\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\","
- + "\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
-
- private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
- + "\"localhost\",\"aaiPort\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":\"https\","
- + "\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":"
- + "\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"datafile\",\"X-TransactionId\":\"9999\",\"Accept\":"
- + "\"application/json\",\"Real-Time\":\"true\",\"Content-Type\":\"application/merge-patch+json\","
- + "\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\""
- + ":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\""
- + ":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\""
- + ",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\""
- + ":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\","
- + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\""
- + ":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
+ private static final String JSON_STRING =
+ "{\"configs\":{\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\","
+ + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\","
+ + "\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\","
+ + "\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,"
+ + "\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\","
+ + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\","
+ + "\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
+ private static final String INCORRECT_JSON_STRING =
+ "{\"configs\":{\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\","
+ + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\","
+ + "\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\","
+ + "\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,"
+ + "\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\","
+ + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\","
+ + "\"FAULTY_PARAMETER_NAME\":\"temp\","
+ + "\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
private static DatafileAppConfig datafileAppConfig;
private static AppConfig appConfig;
private static String filePath = Objects
- .requireNonNull(DatafileAppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile();
+ .requireNonNull(DatafileAppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile();
@BeforeEach
- void setUp() {
+ public void setUp() {
datafileAppConfig = spy(DatafileAppConfig.class);
appConfig = spy(new AppConfig());
}
@Test
- void whenApplicationWasStarted_FilePathIsSet() {
- //
+ public void whenApplicationWasStarted_FilePathIsSet() {
// When
- //
datafileAppConfig.setFilepath(filePath);
- //
+
// Then
- //
verify(datafileAppConfig, times(1)).setFilepath(anyString());
verify(datafileAppConfig, times(0)).initFileStreamReader();
Assertions.assertEquals(filePath, datafileAppConfig.getFilepath());
}
@Test
- void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration()
- throws IOException {
- //
+ public void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration() throws IOException {
// Given
- //
- InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
- StandardCharsets.UTF_8)));
- //
+ InputStream inputStream = new ByteArrayInputStream((JSON_STRING.getBytes(StandardCharsets.UTF_8)));
+
// When
- //
datafileAppConfig.setFilepath(filePath);
doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
datafileAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration();
appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration();
- appConfig.aaiClientConfiguration = datafileAppConfig.getAaiClientConfiguration();
- //
+
// Then
- //
verify(datafileAppConfig, times(1)).setFilepath(anyString());
verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(datafileAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNotNull(datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions
- .assertEquals(appConfig.getDmaapPublisherConfiguration(), datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions
- .assertEquals(appConfig.getDmaapConsumerConfiguration(), datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions
- .assertEquals(appConfig.getAaiClientConfiguration(), datafileAppConfig.getAaiClientConfiguration());
+ Assertions.assertEquals(appConfig.getDmaapPublisherConfiguration(),
+ datafileAppConfig.getDmaapPublisherConfiguration());
+ Assertions.assertEquals(appConfig.getDmaapConsumerConfiguration(),
+ datafileAppConfig.getDmaapConsumerConfiguration());
}
@Test
- void whenFileIsNotExist_ThrowIoException() {
- //
+ public void whenFileIsNotExist_ThrowIoException() {
// Given
- //
filePath = "/temp.json";
datafileAppConfig.setFilepath(filePath);
- //
+
// When
- //
datafileAppConfig.initFileStreamReader();
- //
+
// Then
- //
verify(datafileAppConfig, times(1)).setFilepath(anyString());
verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(datafileAppConfig.getAaiClientConfiguration());
Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
}
@Test
- void whenFileIsExistsButJsonIsIncorrect() throws IOException {
- //
+ public void whenFileIsExistsButJsonIsIncorrect() throws IOException {
// Given
- //
- InputStream inputStream = new ByteArrayInputStream((incorrectJsonString.getBytes(
- StandardCharsets.UTF_8)));
- //
+ InputStream inputStream = new ByteArrayInputStream((INCORRECT_JSON_STRING.getBytes(StandardCharsets.UTF_8)));
+
// When
- //
datafileAppConfig.setFilepath(filePath);
doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
datafileAppConfig.initFileStreamReader();
- //
// Then
- //
verify(datafileAppConfig, times(1)).setFilepath(anyString());
verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(datafileAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
@@ -186,11 +150,9 @@ class DatafileAppConfigTest {
@Test
- void whenTheConfigurationFits_ButRootElementIsNotAJsonObject()
- throws IOException {
+ public void whenTheConfigurationFits_ButRootElementIsNotAJsonObject() throws IOException {
// Given
- InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
- StandardCharsets.UTF_8)));
+ InputStream inputStream = new ByteArrayInputStream((JSON_STRING.getBytes(StandardCharsets.UTF_8)));
// When
datafileAppConfig.setFilepath(filePath);
doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
@@ -200,13 +162,11 @@ class DatafileAppConfigTest {
datafileAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration();
appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration();
- appConfig.aaiClientConfiguration = datafileAppConfig.getAaiClientConfiguration();
// Then
verify(datafileAppConfig, times(1)).setFilepath(anyString());
verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(datafileAppConfig.getAaiClientConfiguration());
Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectorTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectorTest.java
new file mode 100644
index 00000000..5b9d0aaf
--- /dev/null
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectorTest.java
@@ -0,0 +1,116 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.service.FileData;
+import org.onap.dcaegen2.collectors.datafile.service.ImmutableFileData;
+
+import reactor.core.publisher.Mono;
+
+/**
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
+ *
+ */
+public class FileCollectorTest {
+
+ private static final String PM_MEAS_CHANGE_IDINTIFIER = "PM_MEAS_FILES";
+ private static final String FILE_READY_CHANGE_TYPE = "FileReady";
+ private static final String FTPES_SCHEME = "ftpes://";
+ private static final String SFTP_SCHEME = "sftp://";
+ private static final String SERVER_ADDRESS = "192.168.0.101";
+ private static final int PORT_22 = 22;
+ private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
+ private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME;
+ private static final String LOCAL_FILE_LOCATION = "target/" + PM_FILE_NAME;
+ private static final String FTPES_LOCATION = FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ private static final String SFTP_LOCATION = SFTP_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ private static final String GZIP_COMPRESSION = "gzip";
+ private static final String MEAS_COLLECT_FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec";
+ private static final String FILE_FORMAT_VERSION = "V10";
+
+ private FtpsClient ftpsClientMock = mock(FtpsClient.class);
+
+ private SftpClient sftpClientMock = mock(SftpClient.class);
+
+ private FileCollector fileCollectorUndetTest = new FileCollector(ftpsClientMock, sftpClientMock);
+
+ @Test
+ public void whenSingleFtpesFile_returnCorrectResponse() {
+ List<FileData> listOfFileData = new ArrayList<FileData>();
+ listOfFileData.add(ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).location(FTPES_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build());
+
+ FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).port(PORT_22)
+ .userId("").password("").build();
+ when(ftpsClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)).thenReturn(true);
+
+ Mono<List<ConsumerDmaapModel>> consumerModelsMono =
+ fileCollectorUndetTest.getFilesFromSender(listOfFileData);
+
+ List<ConsumerDmaapModel> consumerModels = consumerModelsMono.block();
+ assertEquals(1, consumerModels.size());
+ ConsumerDmaapModel consumerDmaapModel = consumerModels.get(0);
+ assertEquals(GZIP_COMPRESSION, consumerDmaapModel.getCompression());
+ assertEquals(MEAS_COLLECT_FILE_FORMAT_TYPE, consumerDmaapModel.getFileFormatType());
+ assertEquals(FILE_FORMAT_VERSION, consumerDmaapModel.getFileFormatVersion());
+ assertEquals(LOCAL_FILE_LOCATION, consumerDmaapModel.getLocation());
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS)
+ .userId("").password("").port(PORT_22).build();
+ verify(ftpsClientMock, times(1)).collectFile(expectedFileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ verifyNoMoreInteractions(ftpsClientMock);
+ }
+
+ @Test
+ public void whenSingleSftpFile_returnCorrectResponse() {
+ List<FileData> listOfFileData = new ArrayList<FileData>();
+ listOfFileData.add(ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).location(SFTP_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build());
+
+ FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).port(PORT_22)
+ .userId("").password("").build();
+ when(sftpClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)).thenReturn(true);
+
+ Mono<List<ConsumerDmaapModel>> consumerModelsMono =
+ fileCollectorUndetTest.getFilesFromSender(listOfFileData);
+
+ List<ConsumerDmaapModel> consumerModels = consumerModelsMono.block();
+ assertEquals(1, consumerModels.size());
+ ConsumerDmaapModel consumerDmaapModel = consumerModels.get(0);
+ assertEquals(GZIP_COMPRESSION, consumerDmaapModel.getCompression());
+ assertEquals(MEAS_COLLECT_FILE_FORMAT_TYPE, consumerDmaapModel.getFileFormatType());
+ assertEquals(FILE_FORMAT_VERSION, consumerDmaapModel.getFileFormatVersion());
+ assertEquals(LOCAL_FILE_LOCATION, consumerDmaapModel.getLocation());
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS)
+ .userId("").password("").port(PORT_22).build();
+ verify(sftpClientMock, times(1)).collectFile(expectedFileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ verifyNoMoreInteractions(ftpsClientMock);
+ }
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpClientTest.java
new file mode 100644
index 00000000..a95b80ed
--- /dev/null
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpClientTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.mockftpserver.fake.FakeFtpServer;
+import org.mockftpserver.fake.UserAccount;
+import org.mockftpserver.fake.filesystem.FileEntry;
+import org.mockftpserver.fake.filesystem.FileSystem;
+import org.mockftpserver.fake.filesystem.UnixFakeFileSystem;
+
+public class FtpClientTest {
+
+ private static final String HOME_DIR = "/";
+ private static final String FILE = "/dir/sample.txt";
+ private static final String CONTENTS = "abcdef 1234567890";
+ private static final int PORT = 8021;
+
+ private static final String USERNAME = "bob";
+ private static final String PASSWORD = "123";
+
+ private FakeFtpServer fakeFtpServer;
+
+ @BeforeAll
+ protected void setUp() throws Exception {
+ fakeFtpServer = new FakeFtpServer();
+ fakeFtpServer.setServerControlPort(PORT);
+
+ FileSystem fileSystem = new UnixFakeFileSystem();
+ fileSystem.add(new FileEntry(FILE, CONTENTS));
+ fakeFtpServer.setFileSystem(fileSystem);
+ UserAccount userAccount = new UserAccount(USERNAME, PASSWORD, HOME_DIR);
+ fakeFtpServer.addUserAccount(userAccount);
+
+ fakeFtpServer.start();
+ }
+
+ @AfterAll
+ protected void tearDown() throws Exception {
+ fakeFtpServer.stop();
+ }
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java
new file mode 100644
index 00000000..13f1fbb9
--- /dev/null
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java
@@ -0,0 +1,103 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.ftp;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.commons.io.IOUtils.toByteArray;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.github.stefanbirkner.fakesftpserver.rule.FakeSftpServerRule;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.SftpException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+public class SftpClientTest {
+ private static final String USERNAME = "bob";
+ private static final String PASSWORD = "123";
+ private static final String DUMMY_CONTENT = "dummy content";
+ private static final String LOCAL_DUMMY_FILE = "target/dummy.txt";
+ private static final String REMOTE_DUMMY_FILE = "/dummy_directory/dummy_file.txt";
+ private static final JSch JSCH = new JSch();
+ private static final int TIMEOUT = 2000;
+
+ @Rule
+ public final FakeSftpServerRule sftpServer = new FakeSftpServerRule().addUser(USERNAME, PASSWORD);
+
+ @Test
+ public void collectFile_withOKresponse() throws IOException, JSchException, SftpException {
+ SftpClient sftpClient = new SftpClient();
+ sftpServer.putFile(REMOTE_DUMMY_FILE, DUMMY_CONTENT, UTF_8);
+ byte[] file = downloadFile(sftpServer, REMOTE_DUMMY_FILE);
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress("127.0.0.1")
+ .userId(USERNAME).password(PASSWORD).port(sftpServer.getPort()).build();
+ sftpClient.collectFile(expectedFileServerData, REMOTE_DUMMY_FILE,
+ LOCAL_DUMMY_FILE);
+ byte[] localFile = Files.readAllBytes(new File(LOCAL_DUMMY_FILE).toPath());
+ assertThat(new String(file, UTF_8)).isEqualTo(DUMMY_CONTENT);
+ assertThat(new String(localFile, UTF_8)).isEqualTo(DUMMY_CONTENT);
+ }
+
+ private static Session connectToServer(FakeSftpServerRule sftpServer) throws JSchException {
+ return connectToServerAtPort(sftpServer.getPort());
+ }
+
+ private static Session connectToServerAtPort(int port) throws JSchException {
+ Session session = createSessionWithCredentials(USERNAME, PASSWORD, port);
+ session.connect(TIMEOUT);
+ return session;
+ }
+
+ private static ChannelSftp connectSftpChannel(Session session) throws JSchException {
+ ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
+ channel.connect();
+ return channel;
+ }
+
+ private static Session createSessionWithCredentials(String username, String password, int port)
+ throws JSchException {
+ Session session = JSCH.getSession(username, "127.0.0.1", port);
+ session.setConfig("StrictHostKeyChecking", "no");
+ session.setPassword(password);
+ return session;
+ }
+
+ private static byte[] downloadFile(FakeSftpServerRule server, String path)
+ throws JSchException, SftpException, IOException {
+ Session session = connectToServer(server);
+ ChannelSftp channel = connectSftpChannel(session);
+ try {
+ InputStream is = channel.get(path);
+ return toByteArray(is);
+ } finally {
+ channel.disconnect();
+ session.disconnect();
+ }
+ }
+
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ScheduledXmlContextITest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ScheduledXmlContextITest.java
index b9aa2f78..b5f05a71 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ScheduledXmlContextITest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ScheduledXmlContextITest.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,7 +13,7 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.integration;
@@ -26,6 +24,7 @@ import static org.mockito.Mockito.verify;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
@@ -39,6 +38,7 @@ import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Configuration
@@ -62,5 +62,3 @@ class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
verify(scheduledTask, atLeast(1)).scheduleMainDatafileEventTask();
}
}
-
-
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
index 47107588..05a4f515 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/junit5/mockito/MockitoExtension.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/junit5/mockito/MockitoExtension.java
index df167425..bc4e6401 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/junit5/mockito/MockitoExtension.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/junit5/mockito/MockitoExtension.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,7 +13,7 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito;
@@ -36,9 +34,10 @@ import org.mockito.MockitoAnnotations;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
*
- * {@code MockitoExtension } showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension
- * APIs of JUnit 5 by providing dependency injection support at the field level and at the method parameter level
- * viaMockito 2.x's {@link Mock @Mock} annotation.
+ * {@code MockitoExtension} showcases the {@link TestInstancePostProcessor} and
+ * {@link ParameterResolver} extension APIs of JUnit 5 by providing dependency injection
+ * support at the field level and at the method parameter level via Mockito 2.x's
+ * {@link Mock @Mock} annotation.
*/
public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver {
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
index d7ceee82..dc51343d 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
@@ -1,21 +1,17 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.service;
@@ -24,250 +20,161 @@ import static org.mockito.Mockito.spy;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+
+import java.util.List;
import java.util.Optional;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.DmaapConsumerJsonParser;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
+import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
class DmaapConsumerJsonParserTest {
@Test
- void whenPassingCorrectJson_validationNotThrowingAnException() {
- //given
- String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
- + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":"
- + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400"
- + ",\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
- + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
- + "\"Nokia\"}}}]";
-
- String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":"
- + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
- + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
- + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
- + "\"Nokia\"}}}";
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
- //when
+ void whenPassingCorrectJson_validationNotThrowingAnException() throws DmaapNotFoundException {
+ // given
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+
+ String parsedString = message.getParsed();
+
+ FileData expectedFileData = ImmutableFileData.builder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
+ .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ // when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
- .getJsonObject(Mono.just((message))).block();
- //then
- Assertions.assertNotNull(consumerDmaapModel);
- Assertions.assertEquals(expectedObject, consumerDmaapModel);
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ List<FileData> listOfFileData = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+ // then
+ Assertions.assertNotNull(listOfFileData);
+ Assertions.assertEquals(expectedFileData, listOfFileData.get(0));
}
@Test
- void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
- //given
- String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
- + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}"
- + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv6Address\":"
- + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\""
- + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
-
- String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}"
- + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv6Address\":"
- + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\""
- + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
-
- //when
+ void whenPassingCorrectJsonWihoutLocation_validationThrowingAnException() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+
+ String parsedString = message.getParsed();
+
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- dmaapConsumerJsonParser.getJsonObject(Mono.just((message)));
- ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
- .block();
- //then
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
- Assertions.assertNotNull(consumerDmaapModel);
- Assertions.assertEquals(expectedObject, consumerDmaapModel);
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
+ .expectError(DmaapNotFoundException.class).verify();
}
@Test
- void whenPassingCorrectJsonWihoutIpv6_validationNotThrowingAnException() {
- //given
- String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
- + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
- + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate"
- + "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address"
- + "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
- + "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
- String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
- + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate"
- + "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address"
- + "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
- + "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
-
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234").ipv6("")
- .pnfName("NOKQTFCOC540002E").build();
- //when
+ void whenPassingCorrectJsonWihoutCompression_validationThrowingAnException() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+
+ String parsedString = message.getParsed();
+
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
- .block();
- //then
- Assertions.assertNotNull(consumerDmaapModel);
- Assertions.assertEquals(expectedObject, consumerDmaapModel);
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
+ .expectError(DmaapNotFoundException.class).verify();
}
@Test
- void whenPassingCorrectJsonWihoutIpv4andIpv6_validationThrowingAnException() {
- String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
- + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
- + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
- + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":"
- + "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
- String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
- + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
- + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":"
- + "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
- .expectSubscription().expectError(DmaapNotFoundException.class).verify();
+ void whenPassingCorrectJsonWihoutFileFormatType_validationThrowingAnException() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+ String parsedString = message.getParsed();
+
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
+ .expectError(DmaapNotFoundException.class).verify();
}
@Test
- void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() {
- String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\""
- + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\""
- + ":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\","
- + "\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}}}";
+ void whenPassingCorrectJsonWihoutFileFormatVersion_validationThrowingAnException() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+
+ String parsedString = message.getParsed();
+
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String incorrectMessage =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\""
- + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
- + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3"
- + "}}}]";
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage)))
- .expectSubscription().expectError(DmaapNotFoundException.class).verify();
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
+ .expectError(DmaapNotFoundException.class).verify();
}
+ // Fixed temprarily
@Test
- void whenPassingJsonWithoutPnfSerialNumberOrPnfVendorName_validationThrowingAnException() {
- String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":"
- + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\""
- + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\","
- + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,"
- + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\""
- + "version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
- + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":"
- + "\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}";
+ void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() {
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES_INVALID")
+ .changeType("FileReady_INVALID").notificationFieldsVersion("1.0_INVALID").build();
+ String incorrectMessageString = message.toString();
+
+ String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String jsonWithoutPnfVendorAndSerialNumber =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":"
- + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\""
- + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\","
- + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,"
- + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,"
- + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\","
- + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\","
- + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\","
- + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}]";
- StepVerifier
- .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutPnfVendorAndSerialNumber)))
- .expectSubscription().expectError(DmaapNotFoundException.class).verify();
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
+ .expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
@Test
- void whenPassingJsonWithoutIpInformation_validationThrowingAnException() {
- String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
- + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
- + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
- + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":"
- + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":"
- + "\"AirScale\"," + "\"pnfVendorName\":\"Nokia\"}}}";
+ void whenPassingJsonWithNullJsonElement_validationThrowingAnException() {
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().build();
+ String incorrectMessageString = message.toString();
+
+ String parsedString = message.getParsed();
+
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String jsonWithoutIpInformation =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
- + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
- + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
- + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSerialNumber\""
- + ":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
- + "\"pnfVendorName\":\"Nokia\"}}}]";
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
- .expectSubscription().expectError(DmaapNotFoundException.class).verify();
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
+ .expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImplTest.java
deleted file mode 100644
index 05a99b43..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskImplTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.function.Executable;
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.AaiConsumerClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiConsumerTaskImpl;
-import org.onap.dcaegen2.collectors.datafile.config.ImmutableAaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
- */
-class AaiConsumerTaskImplTest {
-
- private static ConsumerDmaapModel consumerDmaapModel;
- private static AaiConsumerTaskImpl aaiConsumerTask;
-
- private static final String AAI_HOST = "/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E";
- private static final Integer PORT = 1234;
- private static final String PROTOCOL = "https";
- private static final String USER_NAME_PASSWORD = "Datafile";
- private static final String BASE_PATH = "/aai/v12";
- private static final String PNF_PATH = "/network/pnfs/pnf";
-
- private static AaiClientConfiguration aaiClientConfiguration;
- private static AaiConsumerClient aaiConsumerClient;
- private static AppConfig appConfig;
-
- @BeforeAll
- static void setUp() {
- aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
- .aaiHost(AAI_HOST)
- .aaiPort(PORT)
- .aaiProtocol(PROTOCOL)
- .aaiUserName(USER_NAME_PASSWORD)
- .aaiUserPassword(USER_NAME_PASSWORD)
- .aaiIgnoreSslCertificateErrors(true)
- .aaiBasePath(BASE_PATH)
- .aaiPnfPath(PNF_PATH)
- .build();
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
- appConfig = mock(AppConfig.class);
-
- }
-
- @Test
- void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
- //given/when
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiConsumerTask = new AaiConsumerTaskImpl(appConfig);
- Executable executableCode = () -> aaiConsumerTask.execute(null);
- //then
- Assertions
- .assertThrows(DatafileTaskException.class, executableCode, "Passing wrong object type to execute function");
-
- }
-
- @Test
- void whenPassedObjectFits_ReturnsCorrectStatus() throws DatafileTaskException, IOException {
- //given/when
- getAaiConsumerTask_WhenMockingHttpResponseCode("200", false);
- String response = aaiConsumerTask.execute(consumerDmaapModel);
-
- //then
- verify(aaiConsumerClient, times(1)).getHttpResponse(any(ConsumerDmaapModel.class));
- verifyNoMoreInteractions(aaiConsumerClient);
- Assertions.assertEquals("200", response);
- }
-
- @Test
- void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, AaiNotFoundException {
- //given/when
- getAaiConsumerTask_WhenMockingHttpResponseCode("400", false);
- String response = aaiConsumerTask.execute(consumerDmaapModel);
-
- //then
- verify(aaiConsumerClient, times(1)).getHttpResponse(any(ConsumerDmaapModel.class));
- verifyNoMoreInteractions(aaiConsumerClient);
- Assertions.assertEquals("400", response);
- }
-
- @Test
- void whenPassedObjectFits_ThrowsIoExceptionAndHandleIt() throws IOException {
- //given/when
- getAaiConsumerTask_WhenMockingHttpResponseCode(null, true);
- Executable executableCode = () -> aaiConsumerTask.execute(any(ConsumerDmaapModel.class));
- Assertions
- .assertThrows(DatafileTaskException.class, executableCode, "HttpClient throws IOException");
-
- //then
- verifyNoMoreInteractions(aaiConsumerClient);
- }
-
-
- private static void getAaiConsumerTask_WhenMockingHttpResponseCode(String httpResponseCode, boolean throwsException)
- throws IOException {
- aaiConsumerClient = mock(AaiConsumerClient.class);
- if (throwsException) {
- when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenThrow(IOException.class);
- } else {
- when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of(httpResponseCode));
- }
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiConsumerTask = spy(new AaiConsumerTaskImpl(appConfig));
- when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
- doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient();
- }
-
-} \ No newline at end of file
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskSpy.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskSpy.java
deleted file mode 100644
index 9e1842b0..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiConsumerTaskSpy.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiConsumerTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiConsumerTaskImpl;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-@Configuration
-public class AaiConsumerTaskSpy {
-
- /**
- * Mocking bean for tests.
- *
- * @return A&AI ConsumerTask spy
- */
- @Bean
- @Primary
- public AaiConsumerTask registerSimpleAaiPublisherTask() {
- AppConfig appConfig = mock(AppConfig.class);
- when(appConfig.getAaiClientConfiguration()).thenReturn(mock(AaiClientConfiguration.class));
- return spy(new AaiConsumerTaskImpl(appConfig));
- }
-} \ No newline at end of file
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImplTest.java
deleted file mode 100644
index f33fc931..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiProducerTaskImplTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.function.Executable;
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.producer.AaiProducerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiProducerTaskImpl;
-import org.onap.dcaegen2.collectors.datafile.config.ImmutableAaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
-
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/14/18
- */
-class AaiProducerTaskImplTest {
-
-
- private static final String AAI_HOST = "/aai/v11/network/pnfs/pnf/NOKQTFCOC540002E";
- private static final Integer PORT = 1234;
- private static final String PROTOCOL = "https";
- private static final String USER_NAME_PASSWORD = "Datafile";
- private static final String BASE_PATH = "/aai/v11";
- private static final String PNF_PATH = "/network/pnfs/pnf";
-
- private static ConsumerDmaapModel consumerDmaapModel;
- private static AaiProducerTaskImpl aaiProducerTask;
- private static AaiClientConfiguration aaiClientConfiguration;
- private static AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient;
- private static AppConfig appConfig;
-
- @BeforeAll
- static void setUp() {
- aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
- .aaiHost(AAI_HOST)
- .aaiPort(PORT)
- .aaiProtocol(PROTOCOL)
- .aaiUserName(USER_NAME_PASSWORD)
- .aaiUserPassword(USER_NAME_PASSWORD)
- .aaiIgnoreSslCertificateErrors(true)
- .aaiBasePath(BASE_PATH)
- .aaiPnfPath(PNF_PATH)
- .build();
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
- appConfig = mock(AppConfig.class);
-
- }
-
- @Test
- void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
- //given/when/
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = new AaiProducerTaskImpl(appConfig);
- Executable executableCode = () -> aaiProducerTask.execute(null);
-
- //then
- Assertions
- .assertThrows(DatafileTaskException.class, executableCode, "Passing wrong object type to execute function");
- }
-
- @Test
- void whenPassedObjectFits_ReturnsCorrectStatus() throws DatafileTaskException {
- //given/when
- getAaiProducerTask_whenMockingResponseObject(200);
- Mono<ConsumerDmaapModel> response = aaiProducerTask.execute(Mono.just(consumerDmaapModel));
-
- //then
- verify(aaiProducerReactiveHttpClient, times(1)).getAaiProducerResponse(any());
- verifyNoMoreInteractions(aaiProducerReactiveHttpClient);
- Assertions.assertEquals(consumerDmaapModel, response.block());
-
- }
-
-
- @Test
- void whenPassedObjectFits_butIncorrectResponseReturns() throws DatafileTaskException {
- //given/when
- getAaiProducerTask_whenMockingResponseObject(400);
- StepVerifier.create(aaiProducerTask.execute(Mono.just(consumerDmaapModel))).expectSubscription()
- .expectError(DatafileTaskException.class).verify();
- //then
- verify(aaiProducerReactiveHttpClient, times(1)).getAaiProducerResponse(any());
- verifyNoMoreInteractions(aaiProducerReactiveHttpClient);
- }
-
- private static void getAaiProducerTask_whenMockingResponseObject(Integer statusCode) {
- //given
- aaiProducerReactiveHttpClient = mock(AaiProducerReactiveHttpClient.class);
- when(aaiProducerReactiveHttpClient.getAaiProducerResponse(any()))
- .thenReturn(Mono.just(statusCode));
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
- when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
- doReturn(aaiProducerReactiveHttpClient).when(aaiProducerTask).resolveClient();
- }
-} \ No newline at end of file
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiPublisherTaskSpy.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiPublisherTaskSpy.java
deleted file mode 100644
index 3beda94b..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/AaiPublisherTaskSpy.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
-import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.service.producer.AaiProducerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiProducerTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiProducerTaskImpl;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
- */
-@Configuration
-public class AaiPublisherTaskSpy {
-
- /**
- * Mocking bean for tests.
- *
- * @return A&AI ProducerTask spy
- */
- @Bean
- @Primary
- public AaiProducerTask registerSimpleAaiPublisherTask() {
- AppConfig appConfig = spy(AppConfig.class);
- doReturn(mock(AaiClientConfiguration.class)).when(appConfig).getAaiClientConfiguration();
- AaiProducerTaskImpl aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
- AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient = mock(AaiProducerReactiveHttpClient.class);
- doReturn(mock(AaiClientConfiguration.class)).when(aaiProducerTask).resolveConfiguration();
- doReturn(aaiProducerReactiveHttpClient).when(aaiProducerTask).resolveClient();
- return aaiProducerTask;
- }
-}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java
index 19ab1ab9..c21c5988 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java
@@ -1,136 +1,190 @@
/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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
+ * 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=========================================================
+ * 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.dcaegen2.collectors.datafile.tasks;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
+import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
+import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
+import org.onap.dcaegen2.collectors.datafile.ftp.FileCollector;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.DmaapConsumerJsonParser;
-import org.onap.dcaegen2.collectors.datafile.service.consumer.DMaaPConsumerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapConsumerTaskImpl;
-import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.service.DmaapConsumerJsonParser;
+import org.onap.dcaegen2.collectors.datafile.service.FileData;
+import org.onap.dcaegen2.collectors.datafile.service.ImmutableFileData;
+import org.onap.dcaegen2.collectors.datafile.service.consumer.DmaapConsumerReactiveHttpClient;
+import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
+import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
class DmaapConsumerTaskImplTest {
+ private static final String PM_MEAS_CHANGE_IDINTIFIER = "PM_MEAS_FILES";
+ private static final String FILE_READY_CHANGE_TYPE = "FileReady";
+ private static final String FTPES_SCHEME = "ftpes://";
+ private static final String SFTP_SCHEME = "sftp://";
+ private static final String SERVER_ADDRESS = "192.168.0.101";
+ private static final String PORT_22 = "22";
+ private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
+ private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME;
+ private static final String LOCAL_FILE_LOCATION = "target/" + PM_FILE_NAME;
+ private static final String FTPES_LOCATION = FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ private static final String SFTP_LOCATION = SFTP_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ private static final String GZIP_COMPRESSION = "gzip";
+ private static final String MEAS_COLLECT_FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec";
+ private static final String FILE_FORMAT_VERSION = "V10";
+
+ private static List<ConsumerDmaapModel> listOfConsumerDmaapModel = new ArrayList<ConsumerDmaapModel>();
- private static ConsumerDmaapModel consumerDmaapModel;
- private static DmaapConsumerTaskImpl dmaapConsumerTask;
- private static DMaaPConsumerReactiveHttpClient dMaaPConsumerReactiveHttpClient;
private static AppConfig appConfig;
private static DmaapConsumerConfiguration dmaapConsumerConfiguration;
- private static String message;
- private static String parsed;
+ private DmaapConsumerTaskImpl dmaapConsumerTask;
+ private DmaapConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient;
+
+ private static FileCollector fileCollectorMock;
+
+ private static String ftpesMessage;
+ private static List<FileData> ftpesFileDataAfterConsume = new ArrayList<FileData>();
+
+ private static String sftpMessage;
+ private static List<FileData> sftpFileDataAfterConsume = new ArrayList<FileData>();
@BeforeAll
- static void setUp() {
+ public static void setUp() {
dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder().consumerGroup("OpenDCAE-c12")
- .consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
- .dmaapProtocol("https").dmaapUserName("Datafile").dmaapUserPassword("Datafile")
- .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMs(-1).messageLimit(-1).build();
+ .consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2")
+ .dmaapPortNumber(1234).dmaapProtocol("https").dmaapUserName("Datafile").dmaapUserPassword("Datafile")
+ .dmaapTopicName("unauthenticated.NOTIFICATION").timeoutMS(-1).messageLimit(-1).build();
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
appConfig = mock(AppConfig.class);
- message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
- + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
- + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
- + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
- + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
- + "\"Nokia\"}}}]";
- parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
- + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\","
- + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\","
- + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\","
- + "\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
- + "\"pnfVendorName\":\"Nokia\"}}}";
+
+ AdditionalField ftpesAdditionalField =
+ new JsonMessage.AdditionalFieldBuilder().location(FTPES_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).notificationFieldsVersion("1.0")
+ .addAdditionalField(ftpesAdditionalField).build();
+ ftpesMessage = ftpesJsonMessage.toString();
+ FileData ftpesFileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).location(FTPES_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ ftpesFileDataAfterConsume.add(ftpesFileData);
+
+ AdditionalField sftpAdditionalField =
+ new JsonMessage.AdditionalFieldBuilder().location(SFTP_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).notificationFieldsVersion("1.0")
+ .addAdditionalField(sftpAdditionalField).build();
+ sftpMessage = sftpJsonMessage.toString();
+ FileData sftpFileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER)
+ .changeType(FILE_READY_CHANGE_TYPE).location(SFTP_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ sftpFileDataAfterConsume.add(sftpFileData);
+
+
+ ImmutableConsumerDmaapModel consumerDmaapModel =
+ ImmutableConsumerDmaapModel.builder().location(LOCAL_FILE_LOCATION).compression(GZIP_COMPRESSION)
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ listOfConsumerDmaapModel.add(consumerDmaapModel);
+
+ fileCollectorMock = mock(FileCollector.class);
}
@Test
- void whenPassedObjectDoesntFit_DoesNotThrowDatafileTaskException() {
- //given
- prepareMocksForDmaapConsumer(Optional.empty());
+ public void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
+ // given
+ prepareMocksForDmaapConsumer("", new ArrayList<FileData>());
- //then
+ // then
StepVerifier.create(dmaapConsumerTask.execute("Sample input")).expectSubscription()
- .expectError(DmaapEmptyResponseException.class).verify();
+ .expectError(DmaapEmptyResponseException.class).verify();
- verify(dMaaPConsumerReactiveHttpClient, times(1)).getDMaaPConsumerResponse();
+ verify(dmaapConsumerReactiveHttpClient, times(1)).getDmaapConsumerResponse();
}
@Test
- void whenPassedObjectFits_ReturnsCorrectResponse() {
- //given
- prepareMocksForDmaapConsumer(Optional.of(message));
- //when
- Mono<ConsumerDmaapModel> response = dmaapConsumerTask.execute("Sample input");
+ public void whenFtpes_ReturnsCorrectResponse() throws DatafileTaskException {
+ // given
+ prepareMocksForDmaapConsumer(ftpesMessage, ftpesFileDataAfterConsume);
+ // when
+ final List<ConsumerDmaapModel> arrayOfResponse = dmaapConsumerTask.execute("Sample input").block();
+ // then
+ verify(dmaapConsumerReactiveHttpClient, times(1)).getDmaapConsumerResponse();
+ verifyNoMoreInteractions(dmaapConsumerReactiveHttpClient);
+ verify(fileCollectorMock, times(1)).getFilesFromSender(ftpesFileDataAfterConsume);
+ verifyNoMoreInteractions(fileCollectorMock);
+ Assertions.assertEquals(listOfConsumerDmaapModel, arrayOfResponse);
- //then
- verify(dMaaPConsumerReactiveHttpClient, times(1)).getDMaaPConsumerResponse();
- assertEquals(consumerDmaapModel, response.block());
+ }
+ @Test
+ public void whenSftp_ReturnsCorrectResponse() throws DatafileTaskException {
+ // given
+ prepareMocksForDmaapConsumer(sftpMessage, sftpFileDataAfterConsume);
+ // when
+ final List<ConsumerDmaapModel> arrayOfResponse = dmaapConsumerTask.execute("Sample input").block();
+ // then
+ verify(dmaapConsumerReactiveHttpClient, times(1)).getDmaapConsumerResponse();
+ verifyNoMoreInteractions(dmaapConsumerReactiveHttpClient);
+ verify(fileCollectorMock, times(1)).getFilesFromSender(sftpFileDataAfterConsume);
+ verifyNoMoreInteractions(fileCollectorMock);
+ Assertions.assertEquals(listOfConsumerDmaapModel, arrayOfResponse);
}
- private void prepareMocksForDmaapConsumer(Optional<String> message) {
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- dMaaPConsumerReactiveHttpClient = mock(DMaaPConsumerReactiveHttpClient.class);
- when(dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).thenReturn(Mono.just(message.orElse("")));
- when(appConfig.getDmaapConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration);
- dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig, dmaapConsumerJsonParser));
+ private void prepareMocksForDmaapConsumer(String message, List<FileData> fileDataAfterConsume) {
+ Mono<String> messageAsMono = Mono.just(message);
+ DmaapConsumerJsonParser dmaapConsumerJsonParserMock = mock(DmaapConsumerJsonParser.class);
+ dmaapConsumerReactiveHttpClient = mock(DmaapConsumerReactiveHttpClient.class);
+ when(dmaapConsumerReactiveHttpClient.getDmaapConsumerResponse()).thenReturn(messageAsMono);
+
+ if (!message.isEmpty()) {
+ when(dmaapConsumerJsonParserMock.getJsonObject(messageAsMono)).thenReturn(Mono.just(fileDataAfterConsume));
+ } else {
+ when(dmaapConsumerJsonParserMock.getJsonObject(messageAsMono))
+ .thenReturn(Mono.error(new DmaapEmptyResponseException()));
+ }
+ when(fileCollectorMock.getFilesFromSender(fileDataAfterConsume))
+ .thenReturn(Mono.just(listOfConsumerDmaapModel));
+
+ dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig, dmaapConsumerReactiveHttpClient,
+ dmaapConsumerJsonParserMock, fileCollectorMock));
when(dmaapConsumerTask.resolveConfiguration()).thenReturn(dmaapConsumerConfiguration);
- doReturn(dMaaPConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
+ doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskSpy.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskSpy.java
deleted file mode 100644
index de5c8535..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskSpy.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
-import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.service.consumer.DMaaPConsumerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapConsumerTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapConsumerTaskImpl;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
- */
-@Configuration
-public class DmaapConsumerTaskSpy {
-
- /**
- * Mocking bean for tests.
- *
- * @return DMaaP ConsumerTask spy
- */
- @Bean
- @Primary
- public DmaapConsumerTask registerSimpleDmaapConsumerTask() {
- AppConfig appConfig = spy(AppConfig.class);
- doReturn(mock(DmaapConsumerConfiguration.class)).when(appConfig).getDmaapConsumerConfiguration();
- DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig));
- DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient = mock(
- DMaaPConsumerReactiveHttpClient.class);
- doReturn(mock(DmaapConsumerConfiguration.class)).when(dmaapConsumerTask).resolveConfiguration();
- doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
- return dmaapConsumerTask;
- }
-}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapProducerTaskSpy.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapProducerTaskSpy.java
deleted file mode 100644
index 870c712e..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapProducerTaskSpy.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
-import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.service.producer.DMaaPProducerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapPublisherTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapPublisherTaskImpl;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
- */
-@Configuration
-public class DmaapProducerTaskSpy {
-
- /**
- * Mocking bean for tests.
- *
- * @return DMaaP PublisherTask spy
- */
- @Bean
- @Primary
- public DmaapPublisherTask registerSimpleDmaapPublisherTask() {
- AppConfig appConfig = spy(AppConfig.class);
- doReturn(mock(DmaapPublisherConfiguration.class)).when(appConfig).getDmaapPublisherConfiguration();
- DmaapPublisherTaskImpl dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
- DMaaPProducerReactiveHttpClient extendedDmaapProducerHttpClient = mock(
- DMaaPProducerReactiveHttpClient.class);
- doReturn(mock(DmaapPublisherConfiguration.class)).when(dmaapPublisherTask).resolveConfiguration();
- doReturn(extendedDmaapProducerHttpClient).when(dmaapPublisherTask).resolveClient();
- return dmaapPublisherTask;
- }
-}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java
index 2b79bc40..4f7787e9 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java
@@ -1,9 +1,7 @@
/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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,12 +13,11 @@
* 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_END========================================================================
*/
package org.onap.dcaegen2.collectors.datafile.tasks;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -30,95 +27,96 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.service.producer.DMaaPProducerReactiveHttpClient;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapPublisherTaskImpl;
-import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
import org.springframework.http.HttpStatus;
+
import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
class DmaapPublisherTaskImplTest {
private static ConsumerDmaapModel consumerDmaapModel;
+ private static List<ConsumerDmaapModel> listOfConsumerDmaapModel;
private static DmaapPublisherTaskImpl dmaapPublisherTask;
- private static DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
+ private static DmaapProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
private static AppConfig appConfig;
private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
@BeforeAll
- static void setUp() {
- dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
- .dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
- .dmaapProtocol("https").dmaapUserName("Datafile").dmaapUserPassword("Datafile")
- .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").build();
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
+ public static void setUp() {
+ dmaapPublisherConfiguration =
+ new ImmutableDmaapPublisherConfiguration.Builder().dmaapContentType("application/json")
+ .dmaapHostName("54.45.33.2").dmaapPortNumber(1234).dmaapProtocol("https").dmaapUserName("DFC")
+ .dmaapUserPassword("DFC").dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT").build();
+ consumerDmaapModel = ImmutableConsumerDmaapModel.builder().location("target/A20161224.1030-1045.bin.gz")
+ .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ listOfConsumerDmaapModel = new ArrayList<ConsumerDmaapModel>();
+ listOfConsumerDmaapModel.add(consumerDmaapModel);
appConfig = mock(AppConfig.class);
}
@Test
- void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
- //given
+ public void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
+ // given
when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
dmaapPublisherTask = new DmaapPublisherTaskImpl(appConfig);
- //when
+ // when
Executable executableFunction = () -> dmaapPublisherTask.execute(null);
- //then
- assertThrows(DatafileTaskException.class, executableFunction, "The specified parameter is incorrect");
+ // then
+ Assertions.assertThrows(DatafileTaskException.class, executableFunction,
+ "The specified parameter is incorrect");
}
@Test
- void whenPassedObjectFits_ReturnsCorrectStatus() throws DatafileTaskException {
- //given
+ public void whenPassedObjectFits_ReturnsCorrectStatus() throws DatafileTaskException {
+ // given
prepareMocksForTests(HttpStatus.OK.value());
- //when
- StepVerifier.create(dmaapPublisherTask.execute(Mono.just(consumerDmaapModel))).expectSubscription()
- .expectNext(HttpStatus.OK.toString()).verifyComplete();
+ // when
+ dmaapPublisherTask.execute(Mono.just(listOfConsumerDmaapModel));
- //then
- verify(dMaaPProducerReactiveHttpClient, times(1))
- .getDMaaPProducerResponse(any(Mono.class));
+ // then
+ verify(dMaaPProducerReactiveHttpClient, times(1)).getDmaapProducerResponse(any());
verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
}
-
@Test
- void whenPassedObjectFits_butIncorrectResponseReturns() throws DmaapNotFoundException {
- //given
- prepareMocksForTests(HttpStatus.UNAUTHORIZED.value());
+ public void whenPassedObjectFits_ReturnsNoContent() throws DatafileTaskException {
+ // given
+ prepareMocksForTests(HttpStatus.NO_CONTENT.value());
- //when
- StepVerifier.create(dmaapPublisherTask.execute(Mono.just(consumerDmaapModel))).expectSubscription()
- .expectNext(String.valueOf(HttpStatus.UNAUTHORIZED.value())).verifyComplete();
+ dmaapPublisherTask.execute(Mono.just(listOfConsumerDmaapModel));
- //then
- verify(dMaaPProducerReactiveHttpClient, times(1)).getDMaaPProducerResponse(any(Mono.class));
+ // then
+ verify(dMaaPProducerReactiveHttpClient, times(1)).getDmaapProducerResponse(any());
verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
}
-
private void prepareMocksForTests(Integer httpResponseCode) {
- dMaaPProducerReactiveHttpClient = mock(DMaaPProducerReactiveHttpClient.class);
- when(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(any(Mono.class)))
- .thenReturn(Mono.just(httpResponseCode.toString()));
+ dMaaPProducerReactiveHttpClient = mock(DmaapProducerReactiveHttpClient.class);
+ when(dMaaPProducerReactiveHttpClient.getDmaapProducerResponse(any()))
+ .thenReturn(Mono.just(httpResponseCode.toString()));
+ when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
when(dmaapPublisherTask.resolveConfiguration()).thenReturn(dmaapPublisherConfiguration);
doReturn(dMaaPProducerReactiveHttpClient).when(dmaapPublisherTask).resolveClient();
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduleControllerSpy.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduleControllerSpy.java
deleted file mode 100644
index d47d31d1..00000000
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduleControllerSpy.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Datafile Collector Service
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.tasks;
-
-import static org.mockito.Mockito.spy;
-
-import org.onap.dcaegen2.collectors.datafile.tasks.AaiProducerTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapConsumerTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.DmaapPublisherTask;
-import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/5/18
- */
-@Configuration
-public class ScheduleControllerSpy {
-
- @Autowired
- private DmaapConsumerTask dmaapConsumerTaskImplSpy;
-
- @Autowired
- private DmaapPublisherTask dmaapPublisherTaskImplSpy;
-
- @Autowired
- private AaiProducerTask aaiPublisherTaskImplSpy;
-
- @Bean
- @Primary
- public ScheduledTasks registerSimpleScheduledTask() {
- return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy));
- }
-}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
new file mode 100644
index 00000000..264a9945
--- /dev/null
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
@@ -0,0 +1,204 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. 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========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.utils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Utility class to produce correctly formatted fileReady event Json messages.
+ *
+ * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> on 7/25/18
+ *
+ */
+public class JsonMessage {
+ private String changeIdentifier;
+ private String changeType;
+ private String notificationFieldsVersion;
+ private List<AdditionalField> arrayOfAdditionalFields;
+
+
+ @Override
+ public String toString() {
+ return "[" + getParsed() + "]";
+ }
+
+ /**
+ * Gets the message in parsed format.
+ * @return the massage in parsed format.
+ */
+ public String getParsed() {
+ StringBuffer additionalFieldsString = new StringBuffer();
+ if (arrayOfAdditionalFields.size() > 0) {
+ additionalFieldsString.append("\"arrayOfAdditionalFields\": [");
+ for (Iterator<AdditionalField> iterator = arrayOfAdditionalFields.iterator(); iterator.hasNext();) {
+ AdditionalField additionalField = iterator.next();
+ additionalFieldsString.append(additionalField.toString());
+ if (iterator.hasNext()) {
+ additionalFieldsString.append(",");
+ }
+ }
+ additionalFieldsString.append("]");
+ }
+
+ return "{" + "\"event\":{" + "\"commonEventHeader\":{" + "\"domain\":\"notification\","
+ + "\"eventId\":\"<<SerialNumber>>-reg\"," + "\"eventName\":\"EriNoti_RnNode_FileReady\","
+ + "\"eventType\":\"fileReady\"," + "\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682," + "\"nfNamingCode\":\"5GRAN\"," + "\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\"," + "\"reportingEntityName\":\"5GRAN_DU\"," + "\"sequence\":0,"
+ + "\"sourceId\":\"<<SerialNumber>>\"," + "\"sourceName\":\"5GRAN_DU\","
+ + "\"startEpochMicrosec\":\"1519837825682\"," + "\"version\":3" + "}," + "\"notificationFields\":{"
+ + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier,
+ changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ + getAsStringIfParameterIsSet("changeType", changeType,
+ notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ + getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion,
+ arrayOfAdditionalFields.size() > 0)
+ + additionalFieldsString.toString() + "}" + "}" + "}";
+ }
+
+ private JsonMessage(final JsonMessageBuilder builder) {
+ this.changeIdentifier = builder.changeIdentifier;
+ this.changeType = builder.changeType;
+ this.notificationFieldsVersion = builder.notificationFieldsVersion;
+ this.arrayOfAdditionalFields = builder.arrayOfAdditionalFields;
+ }
+
+ public static class AdditionalField {
+ private String location;
+ private String compression;
+ private String fileFormatType;
+ private String fileFormatVersion;
+
+ @Override
+ public String toString() {
+ return "{"
+ + getAsStringIfParameterIsSet("location", location,
+ compression != null || fileFormatType != null || fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("compression", compression,
+ fileFormatType != null || fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) + "}";
+ }
+
+
+ private AdditionalField(AdditionalFieldBuilder builder) {
+ this.location = builder.location;
+ this.compression = builder.compression;
+ this.fileFormatType = builder.fileFormatType;
+ this.fileFormatVersion = builder.fileFormatVersion;
+ }
+
+ }
+
+ public static class AdditionalFieldBuilder {
+ private String location;
+ private String compression;
+ private String fileFormatType;
+ private String fileFormatVersion;
+
+ public AdditionalFieldBuilder location(String location) {
+ this.location = location;
+ return this;
+ }
+
+ public AdditionalFieldBuilder compression(String compression) {
+ this.compression = compression;
+ return this;
+ }
+
+ public AdditionalFieldBuilder fileFormatType(String fileFormatType) {
+ this.fileFormatType = fileFormatType;
+ return this;
+ }
+
+ public AdditionalFieldBuilder fileFormatVersion(String fileFormatVersion) {
+ this.fileFormatVersion = fileFormatVersion;
+ return this;
+ }
+
+ public AdditionalField build() {
+ return new AdditionalField(this);
+ }
+ }
+
+ public static class JsonMessageBuilder {
+ private String changeIdentifier;
+ private String changeType;
+ private String notificationFieldsVersion;
+ private List<AdditionalField> arrayOfAdditionalFields = new ArrayList<AdditionalField>();
+
+ public JsonMessageBuilder changeIdentifier(String changeIdentifier) {
+ this.changeIdentifier = changeIdentifier;
+ return this;
+ }
+
+ public JsonMessageBuilder changeType(String changeType) {
+ this.changeType = changeType;
+ return this;
+ }
+
+ public JsonMessageBuilder notificationFieldsVersion(String notificationFieldsVersion) {
+ this.notificationFieldsVersion = notificationFieldsVersion;
+ return this;
+ }
+
+ public JsonMessageBuilder addAdditionalField(AdditionalField additionalField) {
+ this.arrayOfAdditionalFields.add(additionalField);
+ return this;
+ }
+
+ public JsonMessage build() {
+ return new JsonMessage(this);
+ }
+ }
+
+ private static String getAsStringIfParameterIsSet(String parameterName, String parameterValue,
+ boolean withSeparator) {
+ String result = "";
+ if (parameterValue != null) {
+ result = "\"" + parameterName + "\":\"" + parameterValue + "\"";
+
+ if (withSeparator) {
+ result = result + ",";
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Can be used to produce a correct test Json message. Tip! Check the formatting with
+ * <a href="https://jsonformatter.org/">Json fomatter</a>
+ *
+ * @param args Not used
+ */
+ public static void main(String[] args) {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField)
+ .addAdditionalField(secondAdditionalField).build();
+ System.out.println(message.toString());
+ }
+}
diff --git a/datafile-app-server/src/test/resources/datafile_endpoints.json b/datafile-app-server/src/test/resources/datafile_endpoints.json
index 599315b6..f6b65fba 100644
--- a/datafile-app-server/src/test/resources/datafile_endpoints.json
+++ b/datafile-app-server/src/test/resources/datafile_endpoints.json
@@ -1,47 +1,28 @@
{
- "configs": {
- "aai": {
- "aaiClientConfiguration": {
- "aaiHost": "localhost",
- "aaiPort": 8080,
- "aaiIgnoreSSLCertificateErrors": true,
- "aaiProtocol": "https",
- "aaiUserName": "AAI",
- "aaiUserPassword": "AAI",
- "aaiBasePath": "/aai/v11",
- "aaiPnfPath": "/network/pnfs/pnf",
- "aaiHeaders": {
- "X-FromAppId": "datafile",
- "X-TransactionId": "9999",
- "Accept": "application/json",
- "Real-Time": "true",
- "Content-Type":"application/merge-patch+json"
+ "configs": {
+ "dmaap": {
+ "dmaapConsumerConfiguration": {
+ "consumerGroup": "notification",
+ "consumerId": "1",
+ "dmaapContentType": "application/json",
+ "dmaapHostName": "localhost",
+ "dmaapPortNumber": 3904,
+ "dmaapProtocol": "http",
+ "dmaapTopicName": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT",
+ "dmaapUserName": "admin",
+ "dmaapUserPassword": "admin",
+ "messageLimit": 1000,
+ "timeoutMS": 1000
+ },
+ "dmaapProducerConfiguration": {
+ "dmaapContentType": "application/octet-stream",
+ "dmaapHostName": "localhost",
+ "dmaapPortNumber": 3905,
+ "dmaapProtocol": "http",
+ "dmaapTopicName": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT",
+ "dmaapUserName": "admin",
+ "dmaapUserPassword": "admin"
+ }
}
- }
- },
- "dmaap": {
- "dmaapConsumerConfiguration": {
- "consumerGroup": "other",
- "consumerId": "1",
- "dmaapContentType": "application/json",
- "dmaapHostName": "localhost",
- "dmaapPortNumber": 2222,
- "dmaapProtocol": "http",
- "dmaapTopicName": "/events/pnfReady",
- "dmaapUserName": "admin",
- "dmaapUserPassword": "admin",
- "messageLimit": 1000,
- "timeoutMS": 1000
- },
- "dmaapProducerConfiguration": {
- "dmaapContentType": "application/json",
- "dmaapHostName": "localhost",
- "dmaapPortNumber": 2223,
- "dmaapProtocol": "http",
- "dmaapTopicName": "/events/pnfReady",
- "dmaapUserName": "admin",
- "dmaapUserPassword": "admin"
- }
}
- }
-} \ No newline at end of file
+}