aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--datafile-app-server/pom.xml28
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java62
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java117
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java43
-rw-r--r--datafile-commons/pom.xml21
-rw-r--r--datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtils.java6
-rw-r--r--datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctionsTest.java20
-rw-r--r--datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModelTest.java7
-rw-r--r--datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtilsTest.java5
-rw-r--r--datafile-dmaap-client/pom.xml15
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java1
-rw-r--r--pom.xml88
12 files changed, 201 insertions, 212 deletions
diff --git a/datafile-app-server/pom.xml b/datafile-app-server/pom.xml
index 860c1cc0..88a7a6d1 100644
--- a/datafile-app-server/pom.xml
+++ b/datafile-app-server/pom.xml
@@ -150,16 +150,6 @@
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
- <groupId>com.spotify</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <exclusions>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
@@ -224,6 +214,11 @@
<artifactId>fake-sftp-server-rule</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.53</version>
+ </dependency>
<!--REQUIRED TO GENERATE DOCUMENTATION -->
<dependency>
@@ -234,18 +229,5 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
-
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <!-- IMPORT DEPENDENCY MANAGEMENT FROM SPRING BOOT -->
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>2.0.4.RELEASE</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
</project>
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 98f3a72a..c71d1435 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
@@ -28,6 +28,8 @@ import java.util.stream.StreamSupport;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;
@@ -40,12 +42,17 @@ import reactor.core.publisher.Mono;
*/
public class DmaapConsumerJsonParser {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DmaapConsumerJsonParser.class);
+
private static final String EVENT = "event";
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 ARRAY_OF_NAMED_HASH_MAP = "arrayOfNamedHashMap";
+ private static final String NAME = "name";
+ private static final String HASH_MAP = "hashMap";
private static final String LOCATION = "location";
private static final String COMPRESSION = "compression";
private static final String FILE_FORMAT_TYPE = "fileFormatType";
@@ -93,21 +100,20 @@ public class DmaapConsumerJsonParser {
String changeIdentifier = getValueFromJson(notificationFields, CHANGE_IDENTIFIER);
String changeType = getValueFromJson(notificationFields, CHANGE_TYPE);
String notificationFieldsVersion = getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION);
- JsonArray arrayOfAdditionalFields = notificationFields.getAsJsonArray("arrayOfAdditionalFields");
+ JsonArray arrayOfNamedHashMap = notificationFields.getAsJsonArray(ARRAY_OF_NAMED_HASH_MAP);
if (isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)
- && arrayOfAdditionalFields != null) {
- Mono<List<FileData>> res =
- getFileDataFromJson(changeIdentifier, changeType, arrayOfAdditionalFields);
+ && arrayOfNamedHashMap != null) {
+ Mono<List<FileData>> res = getAllFileDataFromJson(changeIdentifier, changeType, arrayOfNamedHashMap);
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));
+ } else if (arrayOfNamedHashMap != null) {
+ return Mono.error(
+ new DmaapNotFoundException("FileReady event arrayOfNamedHashMap is missing. " + jsonObject));
}
return Mono.error(
new DmaapNotFoundException("FileReady event does not contain correct information. " + jsonObject));
@@ -117,30 +123,43 @@ public class DmaapConsumerJsonParser {
}
- private Mono<List<FileData>> getFileDataFromJson(String changeIdentifier, String changeType,
+ private Mono<List<FileData>> getAllFileDataFromJson(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());
+ FileData fileData = getFileDataFromJson(fileInfo, changeIdentifier, changeType);
+
+ if (fileData != null) {
+ res.add(fileData);
} else {
- return Mono.error(new DmaapNotFoundException(
- "FileReady event does not contain correct file format information. " + fileInfo));
+ LOGGER.error("Unable to collect file from xNF. File information wrong. " + fileInfo);
}
}
}
return Mono.just(res);
}
+ private FileData getFileDataFromJson(JsonObject fileInfo, String changeIdentifier, String changeType) {
+ FileData fileData = null;
+
+ String name = getValueFromJson(fileInfo, NAME);
+ JsonObject data = fileInfo.getAsJsonObject(HASH_MAP);
+ String fileFormatType = getValueFromJson(data, FILE_FORMAT_TYPE);
+ String fileFormatVersion = getValueFromJson(data, FILE_FORMAT_VERSION);
+ String location = getValueFromJson(data, LOCATION);
+ String compression = getValueFromJson(data, COMPRESSION);
+
+ if (isFileFormatFieldsNotEmpty(fileFormatVersion, fileFormatType)
+ && isNameAndLocationAndCompressionNotEmpty(name, location, compression)) {
+ fileData = ImmutableFileData.builder().changeIdentifier(changeIdentifier).changeType(changeType)
+ .location(location).compression(compression).fileFormatType(fileFormatType)
+ .fileFormatVersion(fileFormatVersion).build();
+ }
+ return fileData;
+ }
+
private String getValueFromJson(JsonObject jsonObject, String jsonKey) {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
@@ -157,8 +176,9 @@ public class DmaapConsumerJsonParser {
&& (fileFormatType != null && !fileFormatType.isEmpty()));
}
- private boolean isLocationAndCompressionNotEmpty(String location, String compression) {
- return (location != null && !location.isEmpty()) && (compression != null && !compression.isEmpty());
+ private boolean isNameAndLocationAndCompressionNotEmpty(String name, String location, String compression) {
+ return (name != null && !name.isEmpty()) && (location != null && !location.isEmpty())
+ && (compression != null && !compression.isEmpty());
}
private boolean containsHeader(JsonObject jsonObject) {
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 dc51343d..4aad5f45 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
@@ -16,21 +16,22 @@
package org.onap.dcaegen2.collectors.datafile.service;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
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.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -42,122 +43,150 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJson_validationNotThrowingAnException() throws DmaapNotFoundException {
- // given
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.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
+
+ 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);
- List<FileData> listOfFileData = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
- // then
- Assertions.assertNotNull(listOfFileData);
- Assertions.assertEquals(expectedFileData, listOfFileData.get(0));
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(expectedFileData, fileDataResult.get(0));
}
@Test
- void whenPassingCorrectJsonWihoutLocation_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().compression("gzip")
+ void whenPassingCorrectJsonWihoutName_noFileData() {
+ 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();
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
+ }
+
+ @Test
+ void whenPassingCorrectJsonWihoutLocation_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("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();
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();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutCompression_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutCompression_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.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(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatType_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutFileFormatType_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.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();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatVersion_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingOneCorrectJsonWihoutFileFormatVersionAndOneCorrect_oneFileData() {
+ AdditionalField additionalFaultyField =
+ new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").build();
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
- .fileFormatType("org.3GPP.32.435#measCollec").build();
+ .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();
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalFaultyField)
+ .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();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(1, fileDataResult.size());
}
- // Fixed temprarily
@Test
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 incorrectMessageString = 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(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
@@ -165,15 +194,15 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingJsonWithNullJsonElement_validationThrowingAnException() {
JsonMessage message = new JsonMessage.JsonMessageBuilder().build();
- String incorrectMessageString = message.toString();
+ String incorrectMessageString = 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(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
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
index 264a9945..14251406 100644
--- 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
@@ -2,17 +2,15 @@
* ============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
+ * 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.
+ * 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========================================================================
*/
@@ -42,12 +40,13 @@ public class JsonMessage {
/**
* 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\": [");
+ additionalFieldsString.append("\"arrayOfNamedHashMap\": [");
for (Iterator<AdditionalField> iterator = arrayOfAdditionalFields.iterator(); iterator.hasNext();) {
AdditionalField additionalField = iterator.next();
additionalFieldsString.append(additionalField.toString());
@@ -82,6 +81,7 @@ public class JsonMessage {
}
public static class AdditionalField {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
@@ -89,17 +89,19 @@ public class JsonMessage {
@Override
public String toString() {
- return "{"
+ return "{" + getAsStringIfParameterIsSet("name", name, true)
+ + "\"hashMap\":{"
+ 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) + "}";
+ + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) + "}}";
}
private AdditionalField(AdditionalFieldBuilder builder) {
+ this.name = builder.name;
this.location = builder.location;
this.compression = builder.compression;
this.fileFormatType = builder.fileFormatType;
@@ -109,11 +111,17 @@ public class JsonMessage {
}
public static class AdditionalFieldBuilder {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
private String fileFormatVersion;
+ public AdditionalFieldBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
public AdditionalFieldBuilder location(String location) {
this.location = location;
return this;
@@ -190,14 +198,15 @@ public class JsonMessage {
* @param args Not used
*/
public static void main(String[] args) {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.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();
+ AdditionalField secondAdditionalField =
+ new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .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)
+ .changeType("FileReady").notificationFieldsVersion("2.0").addAdditionalField(additionalField)
.addAdditionalField(secondAdditionalField).build();
System.out.println(message.toString());
}
diff --git a/datafile-commons/pom.xml b/datafile-commons/pom.xml
index 3f551542..d018ff79 100644
--- a/datafile-commons/pom.xml
+++ b/datafile-commons/pom.xml
@@ -31,10 +31,6 @@
<artifactId>datafile-commons</artifactId>
<packaging>jar</packaging>
- <properties>
- <main.basedir>${project.parent.basedir}</main.basedir>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.immutables</groupId>
@@ -45,16 +41,6 @@
<artifactId>gson</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
-
- <!-- TEST DEPENDENCIES -->
- <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
@@ -69,8 +55,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
-
- <!-- LOGGING DEPENDENCIES -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
@@ -83,5 +67,10 @@
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>5.0.5.RELEASE</version>
+ </dependency>
</dependencies>
</project>
diff --git a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtils.java b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtils.java
index af41b356..91cc3c69 100644
--- a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtils.java
+++ b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtils.java
@@ -18,13 +18,13 @@
package org.onap.dcaegen2.collectors.datafile.model.utils;
-import org.apache.http.HttpStatus;
+import org.springframework.http.HttpStatus;
-public final class HttpUtils implements HttpStatus {
+public final class HttpUtils {
private HttpUtils() {}
public static boolean isSuccessfulResponseCode(Integer statusCode) {
- return statusCode >= 200 && statusCode < 300;
+ return statusCode >= HttpStatus.OK.value() && statusCode < HttpStatus.MULTIPLE_CHOICES.value();
}
}
diff --git a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctionsTest.java b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctionsTest.java
index 675589fb..062724e7 100644
--- a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctionsTest.java
+++ b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctionsTest.java
@@ -17,31 +17,15 @@
package org.onap.dcaegen2.collectors.datafile.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
class CommonFunctionsTest {
// Given
private ConsumerDmaapModel model = new ConsumerDmaapModelForUnitTest();
private static final String EXPECTED_RESULT =
- "{\"location\":\"target/A20161224.1030-1045.bin.gz\",\"compression\":\"gzip\","
- + "\"fileFormatType\":\"org.3GPP.32.435#measCollec\",\"fileFormatVersion\":\"V10\"}";
-
- private static final HttpResponse httpResponseMock = mock(HttpResponse.class);
- private static final HttpEntity httpEntityMock = mock(HttpEntity.class);
- private static final StatusLine statusLineMock = mock(StatusLine.class);
-
- @BeforeAll
- static void setup() {
- when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
- when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
- }
+ "{\"location\":\"target/A20161224.1030-1045.bin.gz\",\"compression\":\"gzip\","
+ + "\"fileFormatType\":\"org.3GPP.32.435#measCollec\",\"fileFormatVersion\":\"V10\"}";
@Test
void createJsonBody_shouldReturnJsonInString() {
diff --git a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModelTest.java b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModelTest.java
index dcccd5f5..5b028973 100644
--- a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModelTest.java
+++ b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModelTest.java
@@ -21,8 +21,6 @@ import org.junit.jupiter.api.Test;
public class ConsumerDmaapModelTest {
- // Given
- private ConsumerDmaapModel consumerDmaapModel;
private static final String LOCATION = "target/A20161224.1030-1045.bin.gz";
private static final String COMPRESSION = "gzip";
private static final String FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec";
@@ -32,8 +30,9 @@ public class ConsumerDmaapModelTest {
public void consumerDmaapModelBuilder_shouldBuildAnObject() {
// When
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().location(LOCATION).compression(COMPRESSION)
- .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
+ // Given
+ ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder().location(LOCATION).compression(COMPRESSION)
+ .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build();
// Then
Assertions.assertNotNull(consumerDmaapModel);
diff --git a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtilsTest.java b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtilsTest.java
index 83fe14a7..8effcbb8 100644
--- a/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtilsTest.java
+++ b/datafile-commons/src/test/java/org/onap/dcaegen2/collectors/datafile/model/utils/HttpUtilsTest.java
@@ -21,7 +21,6 @@ package org.onap.dcaegen2.collectors.datafile.model.utils;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
@@ -29,11 +28,11 @@ public class HttpUtilsTest {
@Test
public void isSuccessfulResponseCode_shouldReturnTrue() {
- assertTrue(HttpUtils.isSuccessfulResponseCode(HttpUtils.SC_ACCEPTED));
+ assertTrue(HttpUtils.isSuccessfulResponseCode(202));
}
@Test
public void isSuccessfulResponseCode_shouldReturnFalse() {
- assertFalse(HttpUtils.isSuccessfulResponseCode(HttpStatus.SC_BAD_GATEWAY));
+ assertFalse(HttpUtils.isSuccessfulResponseCode(502));
}
}
diff --git a/datafile-dmaap-client/pom.xml b/datafile-dmaap-client/pom.xml
index d458eca3..96e0988c 100644
--- a/datafile-dmaap-client/pom.xml
+++ b/datafile-dmaap-client/pom.xml
@@ -49,11 +49,10 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
- <scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-reactor-netty</artifactId>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@@ -64,8 +63,10 @@
<artifactId>datafile-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
-
- <!-- TEST DEPENDENCIES -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-reactor-netty</artifactId>
+ </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@@ -87,10 +88,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java
index 8010bdc1..fd3c0c84 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java
@@ -109,6 +109,7 @@ public class DmaapProducerReactiveHttpClient {
responseSpec.onStatus(HttpStatus::is5xxServerError,
clientResponse -> handlePostErrors(model, clientResponse));
String bodyToMono = responseSpec.bodyToMono(String.class).block();
+ logger.debug("File info sent to DR with response: " + bodyToMono);
}
}
diff --git a/pom.xml b/pom.xml
index 190c62a9..189e392b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,9 @@
~ limitations under the License.
~ ============LICENSE_END=======================================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -29,6 +31,7 @@
<groupId>org.onap.dcaegen2.collectors</groupId>
<artifactId>datafile</artifactId>
<version>1.0.0-SNAPSHOT</version>
+
<name>dcaegen2-collectors.datafile</name>
<description>datafile collector</description>
<packaging>pom</packaging>
@@ -40,20 +43,14 @@
</license>
</licenses>
-
<properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-
- <!-- JAVA VERSION -->
<java.version>8</java.version>
- <compiler.plugin.version>3.7.0</compiler.plugin.version>
- <tomcat.version>8.5.28</tomcat.version>
+ <immutable.version>2.7.1</immutable.version>
+ <spring.version>5.0.5.RELEASE</spring.version>
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
+ <tomcat.version>8.5.32</tomcat.version>
<docker.maven.version>1.0.0</docker.maven.version>
<resource.maven.plugin.version>3.1.0</resource.maven.plugin.version>
- <!-- DEVELOPMENT SETTINGS -->
- <immutable.version>2.7.1</immutable.version>
<!-- LOGGING SETTINGS -->
<slf4j.version>1.7.25</slf4j.version>
@@ -138,8 +135,20 @@
<dependencyManagement>
<dependencies>
-
- <!-- DEVELOPMENT TOOLS DEPENDENCIES -->
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-bom</artifactId>
+ <version>Bismuth-SR10</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
@@ -152,16 +161,19 @@
<version>${immutable.version}</version>
</dependency>
<dependency>
- <groupId>io.projectreactor</groupId>
- <artifactId>reactor-bom</artifactId>
- <version>Bismuth-RELEASE</version>
- <type>pom</type>
- <scope>import</scope>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
</dependency>
<dependency>
- <groupId>com.spotify</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <version>${docker.maven.version}</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webflux</artifactId>
+ <version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
@@ -169,16 +181,6 @@
<version>${resource.maven.plugin.version}</version>
</dependency>
<dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcprov-jdk15on</artifactId>
- <version>1.59</version>
- </dependency>
- <dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-jdk15on</artifactId>
- <version>1.59</version>
- </dependency>
- <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.1.0</version>
@@ -204,27 +206,6 @@
<version>1.3.2</version>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>5.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>5.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webflux</artifactId>
- <version>5.0.5.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-reactor-netty</artifactId>
- <version>2.0.4.RELEASE</version>
- </dependency>
- <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
@@ -240,7 +221,6 @@
<version>${tomcat.version}</version>
</dependency>
- <!-- LOGGING dependencies> -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
@@ -258,7 +238,6 @@
<version>1.7.25</version>
</dependency>
- <!-- TESTING TOOLS DEPENDENCIES -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@@ -286,7 +265,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
- <version>5.0.4.RELEASE</version>
+ <version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -355,3 +334,4 @@
</dependencies>
</dependencyManagement>
</project>
+