client-id: datafile-1
# input topic
file-ready-event-topic: file-ready
- # Configues if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
+ # Configures if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
use-oath-token: false
ssl:
key-store-type: PEM
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
- * Copyright (C) 2020-2021 Nokia. 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.oran.datafile.commons;
-
-import org.oran.datafile.exceptions.DatafileTaskException;
-
-/**
- * Enum specifying the schemes that DFC support for downloading files.
- *
- */
-public enum Scheme {
- FTPES, SFTP, HTTP, HTTPS;
-
- public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol ";
- public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE =
- ". Supported protocols are FTPeS, sFTP, HTTP and HTTPS";
-
- /**
- * Get a <code>Scheme</code> from a string.
- *
- * @param schemeString the string to convert to <code>Scheme</code>.
- * @return The corresponding <code>Scheme</code>
- * @throws DatafileTaskException if the value of the string doesn't match any
- * defined scheme.
- */
- public static Scheme getSchemeFromString(String schemeString) throws DatafileTaskException {
- Scheme result;
- if ("FTPES".equalsIgnoreCase(schemeString)) {
- result = Scheme.FTPES;
- } else if ("SFTP".equalsIgnoreCase(schemeString)) {
- result = Scheme.SFTP;
- } else if ("HTTP".equalsIgnoreCase(schemeString)) {
- result = Scheme.HTTP;
- } else if ("HTTPS".equalsIgnoreCase(schemeString)) {
- result = Scheme.HTTPS;
- } else {
- throw new DatafileTaskException(
- DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
- }
- return result;
- }
-
- /**
- * Check if <code>Scheme</code> is FTP type or HTTP type.
- *
- * @param scheme the <code>Scheme</code> which has to be checked.
- * @return true if <code>Scheme</code> is FTP type or false if it is HTTP type
- */
- public static boolean isFtpScheme(Scheme scheme) {
- return scheme == SFTP || scheme == FTPES;
- }
-}
+++ /dev/null
-/*-
- * ============LICENSE_START======================================================================
- * Copyright (C) 2021 Nokia. 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.oran.datafile.commons;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Utility class containing functions used for certificates configuration
- */
-public final class SecurityUtil {
- private SecurityUtil() {
- }
-
- private static final Logger logger = LoggerFactory.getLogger(SecurityUtil.class);
-
- public static String getKeystorePasswordFromFile(String passwordPath) {
- return getPasswordFromFile(passwordPath, "Keystore");
- }
-
- public static String getTruststorePasswordFromFile(String passwordPath) {
- return getPasswordFromFile(passwordPath, "Truststore");
- }
-
- public static String getPasswordFromFile(String passwordPath, String element) {
- try {
- return new String(Files.readAllBytes(Paths.get(passwordPath)));
- } catch (IOException e) {
- logger.error("{} password file at path: {} cannot be opened ", element, passwordPath);
- }
- return "";
- }
-}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
import org.oran.datafile.commons.FileCollectClient;
-import org.oran.datafile.commons.FileServerData;
-import org.oran.datafile.commons.SecurityUtil;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
+import org.oran.datafile.model.FileServerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.FileSystemResource;
throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
synchronized (FtpesClient.class) {
if (theTrustManager == null && trustedCaPath != null) {
- String trustedCaPassword = SecurityUtil.getTruststorePasswordFromFile(trustedCaPasswordPath);
+ String trustedCaPassword = Files.readString(Paths.get((trustedCaPasswordPath)));
theTrustManager = createTrustManager(trustedCaPath, trustedCaPassword);
}
return theTrustManager;
synchronized (FtpesClient.class) {
if (theKeyManager == null) {
- String keyCertPassword = SecurityUtil.getKeystorePasswordFromFile(keyCertPasswordPath);
+ String keyCertPassword = Files.readString(Paths.get((keyCertPasswordPath)));
theKeyManager = createKeyManager(keyCertPath, keyCertPassword);
}
return theKeyManager;
import java.nio.file.Path;
import org.oran.datafile.commons.FileCollectClient;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
+import org.oran.datafile.model.FileServerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer;
import org.oran.datafile.commons.FileCollectClient;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
-import org.oran.datafile.service.HttpUtils;
+import org.oran.datafile.model.FileServerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.oran.datafile.commons.FileCollectClient;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
-import org.oran.datafile.service.HttpUtils;
+import org.oran.datafile.model.FileServerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ============LICENSE_END========================================================================
*/
-package org.oran.datafile.service;
+package org.oran.datafile.http;
import java.util.Base64;
import java.util.List;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.http.HttpStatus;
-import org.oran.datafile.commons.FileServerData;
+import org.oran.datafile.model.FileServerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.KeyStoreException;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
-import org.oran.datafile.commons.SecurityUtil;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static SSLContextBuilder supplyKeyInfo(String keyCertPath, String keyCertPasswordPath,
SSLContextBuilder sslBuilder) throws IOException, KeyStoreException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException {
- String keyPass = SecurityUtil.getKeystorePasswordFromFile(keyCertPasswordPath);
+ String keyPass = Files.readString(Paths.get((keyCertPasswordPath)));
KeyStore keyFile = createKeyStore(keyCertPath, keyPass);
return sslBuilder.loadKeyMaterial(keyFile, keyPass.toCharArray());
}
private static SSLContextBuilder supplyTrustInfo(String trustedCaPath, String trustedCaPasswordPath,
SSLContextBuilder sslBuilder)
throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
- String trustPass = SecurityUtil.getTruststorePasswordFromFile(trustedCaPasswordPath);
+ String trustPass = Files.readString(Paths.get((trustedCaPasswordPath)));
File trustStoreFile = new File(trustedCaPath);
return sslBuilder.loadTrustMaterial(trustStoreFile, trustPass.toCharArray());
}
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.net.URIBuilder;
-import org.oran.datafile.commons.FileServerData;
-import org.oran.datafile.commons.FileServerData.FileServerDataBuilder;
-import org.oran.datafile.commons.Scheme;
import org.oran.datafile.configuration.AppConfig;
+import org.oran.datafile.exceptions.DatafileTaskException;
+import org.oran.datafile.model.FileServerData.FileServerDataBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Builder
public class FileData {
+ public enum Scheme {
+ FTPES, SFTP, HTTP, HTTPS;
+
+ public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol ";
+ public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE =
+ ". Supported protocols are FTPeS, sFTP, HTTP and HTTPS";
+
+ /**
+ * Get a <code>Scheme</code> from a string.
+ *
+ * @param schemeString the string to convert to <code>Scheme</code>.
+ * @return The corresponding <code>Scheme</code>
+ * @throws DatafileTaskException if the value of the string doesn't match any
+ * defined scheme.
+ */
+ public static Scheme getSchemeFromString(String schemeString) throws DatafileTaskException {
+ Scheme result;
+ if ("FTPES".equalsIgnoreCase(schemeString)) {
+ result = Scheme.FTPES;
+ } else if ("SFTP".equalsIgnoreCase(schemeString)) {
+ result = Scheme.SFTP;
+ } else if ("HTTP".equalsIgnoreCase(schemeString)) {
+ result = Scheme.HTTP;
+ } else if ("HTTPS".equalsIgnoreCase(schemeString)) {
+ result = Scheme.HTTPS;
+ } else {
+ throw new DatafileTaskException(
+ DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
+ }
+ return result;
+ }
+
+ public static boolean isFtpScheme(Scheme scheme) {
+ return scheme == SFTP || scheme == FTPES;
+ }
+ }
+
private static final Logger logger = LoggerFactory.getLogger(FileData.class);
public FileReadyMessage.ArrayOfNamedHashMap fileInfo;
* ============LICENSE_END========================================================================
*/
-package org.oran.datafile.commons;
+package org.oran.datafile.model;
import java.util.ArrayList;
import java.util.List;
package org.oran.datafile.oauth2;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
String scope = "";
}
- public static OAuthBearerTokenJwt create(String tokenRaw)
- throws DatafileTaskException, JsonMappingException, JsonProcessingException {
+ public static OAuthBearerTokenJwt create(String tokenRaw) throws DatafileTaskException {
String[] chunks = tokenRaw.split("\\.");
Base64.Decoder decoder = Base64.getUrlDecoder();
if (chunks.length < 2) {
}
String payloadStr = new String(decoder.decode(chunks[1]));
JwtTokenBody token = gson.fromJson(payloadStr, JwtTokenBody.class);
- logger.error("Token: {}", token);
+ logger.debug("Token: {}", token);
return new OAuthBearerTokenJwt(token, tokenRaw);
}
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.internals.RecordHeader;
import org.apache.kafka.common.serialization.StringSerializer;
-import org.oran.datafile.commons.Scheme;
import org.oran.datafile.configuration.AppConfig;
import org.oran.datafile.configuration.CertificateConfig;
import org.oran.datafile.datastore.DataStore;
Path localFilePath = fileData.getLocalFilePath(this.appConfig);
logger.error("File fetching failed, path {}, reason: {}", fileData.remoteFilePath(), t.getMessage());
deleteFile(localFilePath);
- if (Scheme.isFtpScheme(fileData.scheme())) {
+ if (FileData.Scheme.isFtpScheme(fileData.scheme())) {
counters.incNoOfFailedFtp();
} else {
counters.incNoOfFailedHttp();
import java.util.Optional;
import org.oran.datafile.commons.FileCollectClient;
-import org.oran.datafile.commons.Scheme;
import org.oran.datafile.configuration.AppConfig;
import org.oran.datafile.configuration.CertificateConfig;
import org.oran.datafile.exceptions.DatafileTaskException;
}
private void incFailedAttemptsCounter(FileData fileData) {
- if (Scheme.isFtpScheme(fileData.scheme())) {
+ if (FileData.Scheme.isFtpScheme(fileData.scheme())) {
counters.incNoOfFailedFtpAttempts();
} else {
counters.incNoOfFailedHttpAttempts();
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
-import org.oran.datafile.commons.FileServerData;
+import org.oran.datafile.model.FileServerData;
import org.springframework.http.HttpStatus;
public class FtpesClientTest {
private static final String XNF_ADDRESS = "127.0.0.1";
private static final int PORT = 8021;
private static final String FTP_KEY_PATH = "ftpKeyPath";
- private static final String FTP_KEY_PASSWORD = "ftpKeyPassword";
+ private static final String FTP_KEY_PASSWORD_PATH = "ftpKeyPasswordPath";
private static final Path TRUSTED_CA_PATH = Paths.get("trustedCaPath");
private static final String TRUSTED_CA_PASSWORD = "trustedCaPassword";
@BeforeEach
protected void setUp() throws Exception {
- clientUnderTestSpy = spy(new FtpesClient(createFileServerData(), Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD,
+ clientUnderTestSpy = spy(new FtpesClient(createFileServerData(), Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH,
TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD));
clientUnderTestSpy.realFtpsClient = ftpsClientMock;
}
@Test
public void collectFile_allOk() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(trustManagerMock).when(clientUnderTestSpy).getTrustManager(TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD);
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
doReturn(true).when(ftpsClientMock).login(USERNAME, PASSWORD);
public void collectFileFaultyOwnKey_shouldFail() throws Exception {
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
- assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessageContaining("Could not open connection: java.io.FileNotFoundException:");
+ assertThatThrownBy(() -> clientUnderTestSpy.open()).hasMessageContaining("Could not open connection:");
verify(ftpsClientMock).setNeedClientAuth(true);
@Test
public void collectFileFaultTrustedCA_shouldFail_no_trustedCA_file() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doThrow(new IOException("problem")).when(clientUnderTestSpy).createInputStream(TRUSTED_CA_PATH);
- assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessage("Could not open connection: java.io.IOException: problem");
+ assertThatThrownBy(() -> clientUnderTestSpy.open()).hasMessageContaining("Could not open connection:");
+
}
@Test
public void collectFileFaultTrustedCA_shouldFail_empty_trustedCA_file() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(inputStreamMock).when(clientUnderTestSpy).createInputStream(TRUSTED_CA_PATH);
- assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessage("Could not open connection: java.io.EOFException");
+ assertThatThrownBy(() -> clientUnderTestSpy.open()).hasMessageContaining("Could not open connection: ");
}
@Test
public void collectFileFaultyLogin_shouldFail() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(trustManagerMock).when(clientUnderTestSpy).getTrustManager(TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD);
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
doReturn(false).when(ftpsClientMock).login(USERNAME, PASSWORD);
@Test
public void collectFileBadRequestResponse_shouldFail() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(trustManagerMock).when(clientUnderTestSpy).getTrustManager(TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD);
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
doReturn(true).when(ftpsClientMock).login(USERNAME, PASSWORD);
@Test
public void collectFile_shouldFail() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(trustManagerMock).when(clientUnderTestSpy).getTrustManager(TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD);
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
doReturn(true).when(ftpsClientMock).login(USERNAME, PASSWORD);
@Test
public void collectFile_shouldFail_ioexception() throws Exception {
- doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD);
+ doReturn(keyManagerMock).when(clientUnderTestSpy).getKeyManager(Paths.get(FTP_KEY_PATH), FTP_KEY_PASSWORD_PATH);
doReturn(trustManagerMock).when(clientUnderTestSpy).getTrustManager(TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD);
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
doReturn(true).when(ftpsClientMock).login(USERNAME, PASSWORD);
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.configuration.SftpConfig;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
+import org.oran.datafile.model.FileServerData;
@ExtendWith(MockitoExtension.class)
public class SftpClientTest {
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.exceptions.DatafileTaskException;
-import org.oran.datafile.service.HttpUtils;
+import org.oran.datafile.model.FileServerData;
import reactor.core.publisher.Flux;
import reactor.netty.http.client.HttpClientConfig;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.oran.datafile.commons.FileServerData;
import org.oran.datafile.exceptions.DatafileTaskException;
import org.oran.datafile.exceptions.NonRetryableDatafileTaskException;
+import org.oran.datafile.model.FileServerData;
@ExtendWith(MockitoExtension.class)
class DfcHttpsClientTest {
* ============LICENSE_END========================================================================
*/
-package org.oran.datafile.service;
+package org.oran.datafile.http;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.net.URIBuilder;
import org.junit.jupiter.api.Test;
-import org.oran.datafile.commons.FileServerData;
+import org.oran.datafile.model.FileServerData;
class HttpUtilsTest {
* ============LICENSE_END=========================================================
*/
-package org.oran.datafile.scheme;
+package org.oran.datafile.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
-import org.oran.datafile.commons.Scheme;
import org.oran.datafile.exceptions.DatafileTaskException;
+import org.oran.datafile.model.FileData.Scheme;
public class SchemeTest {
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018-2023 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.oran.datafile.utils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Utility class to produce correctly formatted fileReady event Json messages.
- */
-public class JsonMessage {
- private String eventName;
- private String changeIdentifier;
- private String changeType;
- private String notificationFieldsVersion;
- private List<AdditionalField> arrayOfAdditionalFields;
-
- public List<AdditionalField> getAdditionalFields() {
- return 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("\"arrayOfNamedHashMap\":[");
- 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\":\"" + eventName + "\"," //
- + "\"eventType\":\"fileReady\"," //
- + "\"internalHeaderFields\":{}," //
- + "\"lastEpochMicrosec\":1519837825682," //
- + "\"nfNamingCode\":\"5GRAN\"," //
- + "\"nfcNamingCode\":\"5DU\"," //
- + "\"priority\":\"Normal\"," //
- + "\"reportingEntityName\":\"5GRAN_DU\"," //
- + "\"sequence\":0," //
- + "\"sourceId\":\"<<SerialNumber>>\"," //
- + "\"sourceName\":\"5GRAN_DU\"," //
- + "\"timeZoneOffset\":\"UTC+05:00\"," //
- + "\"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.eventName = builder.eventName;
- this.changeIdentifier = builder.changeIdentifier;
- this.changeType = builder.changeType;
- this.notificationFieldsVersion = builder.notificationFieldsVersion;
- this.arrayOfAdditionalFields = builder.arrayOfAdditionalFields;
- }
-
- public static class AdditionalField {
- private String name;
- private String location;
- private String compression;
- private String fileFormatType;
- private String fileFormatVersion;
-
- @Override
- public String toString() {
- 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) //
- + "}" //
- + "}";
- }
-
- private AdditionalField(AdditionalFieldBuilder builder) {
- this.name = builder.name;
- this.location = builder.location;
- this.compression = builder.compression;
- this.fileFormatType = builder.fileFormatType;
- this.fileFormatVersion = builder.fileFormatVersion;
- }
-
- }
-
- 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;
- }
-
- 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 eventName;
- private String changeIdentifier;
- private String changeType;
- private String notificationFieldsVersion;
- private List<AdditionalField> arrayOfAdditionalFields = new ArrayList<AdditionalField>();
-
- public JsonMessageBuilder eventName(String eventName) {
- this.eventName = eventName;
- return this;
- }
-
- 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 formatter</a>
- *
- * @param args Not used
- */
- public static void main(String[] args) {
- 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() //
- .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() //
- .eventName("Noti_NrRadio-Ericsson_FileReady") //
- .changeIdentifier("PM_MEAS_FILES") //
- .changeType("FileReady") //
- .notificationFieldsVersion("2.0") //
- .addAdditionalField(additionalField) //
- .addAdditionalField(secondAdditionalField) //
- .build();
- System.out.println(message.toString());
- }
-}
max-poll-records: 500
group-id: kafkaGroupId
client-id: kafkaClientId
- # Configues if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
+ # Configures if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
use-oath-token: false
ssl:
key-store-type: PEM
bootstrap-servers: localhost:9092
# The maximum number of records returned in a single call to poll() (default 100)
max-poll-records: 500
- # Configues if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
+ # Configures if oath2 tokens shall be used. If set to true, auth-token-file must also be configured
use-oath-token: false
ssl:
key-store-type: PEM