aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-app-server/src/main')
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java29
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java10
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java3
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java41
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java52
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapEmptyResponseException.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DmaapNotFoundException.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/EnvironmentLoaderException.java2
-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.java119
-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.java8
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImpl.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTask.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java36
17 files changed, 167 insertions, 274 deletions
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 245e0959..0df6b1d1 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
@@ -91,6 +91,18 @@ public class AppConfig extends DatafileAppConfig {
@Value("${dmaap.dmaapProducerConfiguration.dmaapContentType:}")
public String producerDmaapContentType;
+ @Value("${ftp.ftpesConfiguration.keyCert:}")
+ public String keyCert;
+
+ @Value("${ftp.ftpesConfiguration.keyPassword:}")
+ public String keyPassword;
+
+ @Value("${ftp.ftpesConfiguration.trustedCA:}")
+ public String trustedCA;
+
+ @Value("${ftp.ftpesConfiguration.trustedCAPassword:}")
+ public String trustedCAPassword;
+
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return new ImmutableDmaapConsumerConfiguration.Builder()
@@ -154,4 +166,21 @@ public class AppConfig extends DatafileAppConfig {
.build();
}
+ @Override
+ public FtpesConfig getFtpesConfiguration() {
+ return new ImmutableFtpesConfig.Builder()
+ .keyCert(
+ Optional.ofNullable(keyCert).filter(p -> !p.isEmpty())
+ .orElse(ftpesConfig.keyCert()))
+ .keyPassword(
+ Optional.ofNullable(keyPassword).filter(p -> !p.isEmpty())
+ .orElse(ftpesConfig.keyPassword()))
+ .trustedCA(
+ Optional.ofNullable(trustedCA).filter(p -> !p.isEmpty())
+ .orElse(ftpesConfig.trustedCA()))
+ .trustedCAPassword(
+ Optional.ofNullable(trustedCAPassword).filter(p -> !p.isEmpty())
+ .orElse(ftpesConfig.trustedCAPassword()))
+ .build();
+ }
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java
index 7570d704..03ef70ab 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java
@@ -19,6 +19,7 @@
package org.onap.dcaegen2.collectors.datafile.configuration;
import com.google.gson.JsonObject;
+
import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration;
@@ -62,4 +63,13 @@ public class CloudConfigParser {
.consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString())
.build();
}
+
+ public FtpesConfig getFtpesConfig() {
+ return new ImmutableFtpesConfig.Builder()
+ .keyCert(jsonObject.get("dmaap.ftpesConfig.keyCert").getAsString())
+ .keyPassword(jsonObject.get("dmaap.ftpesConfig.keyPassword").getAsString())
+ .trustedCA(jsonObject.get("dmaap.ftpesConfig.trustedCA").getAsString())
+ .trustedCAPassword(jsonObject.get("dmaap.ftpesConfig.trustedCAPassword").getAsString())
+ .build();
+ }
} \ No newline at end of file
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 5ab4358a..7cd65ea2 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
@@ -31,5 +31,8 @@ public interface Config {
DmaapPublisherConfiguration getDmaapPublisherConfiguration();
+ FtpesConfig getFtpesConfiguration();
+
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 b6525f0f..66480792 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
@@ -2,17 +2,15 @@
* ============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
+ * 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========================================================================
*/
@@ -56,6 +54,9 @@ public abstract class DatafileAppConfig implements Config {
private static final String DMAAP = "dmaap";
private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
+ private static final String FTP = "ftp";
+ private static final String FTPES_CONFIGURATION = "ftpesConfiguration";
+
private static final Logger logger = LoggerFactory.getLogger(DatafileAppConfig.class);
@@ -63,6 +64,8 @@ public abstract class DatafileAppConfig implements Config {
DmaapPublisherConfiguration dmaapPublisherConfiguration;
+ FtpesConfig ftpesConfig;
+
@NotEmpty
private String filepath;
@@ -78,6 +81,11 @@ public abstract class DatafileAppConfig implements Config {
}
@Override
+ public FtpesConfig getFtpesConfiguration() {
+ return ftpesConfig;
+ }
+
+ @Override
public void initFileStreamReader() {
GsonBuilder gsonBuilder = new GsonBuilder();
@@ -88,13 +96,16 @@ public abstract class DatafileAppConfig implements Config {
JsonElement rootElement = getJsonElement(parser, inputStream);
if (rootElement.isJsonObject()) {
jsonObject = rootElement.getAsJsonObject();
+ ftpesConfig = deserializeType(gsonBuilder,
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(FTP).getAsJsonObject(FTPES_CONFIGURATION),
+ FtpesConfig.class);
dmaapConsumerConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
- DmaapConsumerConfiguration.class);
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+ DmaapConsumerConfiguration.class);
dmaapPublisherConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
- DmaapPublisherConfiguration.class);
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+ DmaapPublisherConfiguration.class);
}
} catch (IOException e) {
logger.error("Problem with file loading, file: {}", filepath, e);
@@ -108,7 +119,7 @@ public abstract class DatafileAppConfig implements Config {
}
private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
- @NotNull Class<T> type) {
+ @NotNull Class<T> type) {
return gsonBuilder.create().fromJson(jsonObject, type);
}
@@ -124,4 +135,4 @@ public abstract class DatafileAppConfig implements Config {
this.filepath = filepath;
}
-} \ No newline at end of file
+}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java
new file mode 100644
index 00000000..5861bf4e
--- /dev/null
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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
+ *
+ * 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.configuration;
+
+/**
+ * @author
+ *
+ */
+import java.io.Serializable;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@Value.Immutable
+@Value.Style(builder = "new")
+@Gson.TypeAdapters
+public abstract class FtpesConfig implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Value.Parameter
+ public abstract String keyCert();
+
+ @Value.Parameter
+ public abstract String keyPassword();
+
+ @Value.Parameter
+ public abstract String trustedCA();
+
+ @Value.Parameter
+ public abstract String trustedCAPassword();
+} \ No newline at end of file
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 98dfdedc..d6c535f0 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
@@ -37,7 +37,7 @@ import reactor.core.publisher.Mono;
* @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")
public class HeartbeatController {
private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
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 2d62871c..7a047107 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
@@ -23,6 +23,8 @@ package org.onap.dcaegen2.collectors.datafile.exceptions;
*/
public class DatafileTaskException extends Exception {
+ private static final long serialVersionUID = 1L;
+
public DatafileTaskException() {
super();
}
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 cf387296..a1758ea5 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
@@ -23,6 +23,8 @@ package org.onap.dcaegen2.collectors.datafile.exceptions;
*/
public class DmaapEmptyResponseException extends DatafileTaskException {
+ private static final long serialVersionUID = 1L;
+
public DmaapEmptyResponseException() {
super();
}
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 e27a2036..401889f8 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
@@ -23,6 +23,8 @@ package org.onap.dcaegen2.collectors.datafile.exceptions;
*/
public class DmaapNotFoundException extends DatafileTaskException {
+ private static final long serialVersionUID = 1L;
+
public DmaapNotFoundException(String message) {
super(message);
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/EnvironmentLoaderException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/EnvironmentLoaderException.java
index 75c2e8a8..ebfe1902 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/EnvironmentLoaderException.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/EnvironmentLoaderException.java
@@ -23,6 +23,8 @@ package org.onap.dcaegen2.collectors.datafile.exceptions;
*/
public class EnvironmentLoaderException extends Exception {
+ private static final long serialVersionUID = 1L;
+
public EnvironmentLoaderException(String message) {
super(message);
}
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
deleted file mode 100644
index d4eca4d7..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileServerData.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * ============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
deleted file mode 100644
index 89f5bbf2..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * ============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.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) {
- logger.trace("collectFile called with fileServerData: {}, remoteFile: {}, localFile: {}", fileServerData,
- remoteFile, 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. Data: {}", fileServerData, ex);
- result = false;
- }
- logger.trace("collectFile left with result: {}", result);
- 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. Data: {}", fileServerData, ex);
- success = false;
- }
-
- return success;
- }
-
- private void getFile(String remoteFile, String localFile, FTPSClient ftps)
- throws IOException {
- OutputStream output;
- File outfile = new File(localFile);
- outfile.createNewFile();
-
- output = new FileOutputStream(outfile);
-
- ftps.retrieveFile(remoteFile, output);
-
- output.close();
- logger.debug("File {} Download Successfull from xNF", outfile.getName());
- }
-
- 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
deleted file mode 100644
index e7c7c09b..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ============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 619ccc11..cfd06db3 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
@@ -44,7 +44,6 @@ import reactor.core.publisher.Mono;
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public class DmaapConsumerJsonParser {
-
private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerJsonParser.class);
private static final String EVENT = "event";
@@ -72,6 +71,7 @@ public class DmaapConsumerJsonParser {
}
private Mono<JsonElement> getJsonParserMessage(String message) {
+ logger.trace("original message from message router: {}", message);
return StringUtils.isEmpty(message) ? Mono.error(new DmaapEmptyResponseException())
: Mono.fromSupplier(() -> new JsonParser().parse(message));
}
@@ -87,6 +87,8 @@ public class DmaapConsumerJsonParser {
}
public Optional<JsonObject> getJsonObjectFromAnArray(JsonElement element) {
+ logger.trace("starting to getJsonObjectFromAnArray!");
+
return Optional.of(new JsonParser().parse(element.getAsString()).getAsJsonObject());
}
@@ -103,7 +105,6 @@ public class DmaapConsumerJsonParser {
String changeType = getValueFromJson(notificationFields, CHANGE_TYPE);
String notificationFieldsVersion = getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION);
JsonArray arrayOfNamedHashMap = notificationFields.getAsJsonArray(ARRAY_OF_NAMED_HASH_MAP);
-
if (isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)
&& arrayOfNamedHashMap != null) {
return getAllFileDataFromJson(changeIdentifier, changeType, arrayOfNamedHashMap);
@@ -121,7 +122,6 @@ public class DmaapConsumerJsonParser {
}
return Flux.error(
new DmaapNotFoundException("FileReady event has incorrect JsonObject - missing header. " + jsonObject));
-
}
private Flux<FileData> getAllFileDataFromJson(String changeIdentifier, String changeType,
@@ -143,6 +143,8 @@ public class DmaapConsumerJsonParser {
}
private FileData getFileDataFromJson(JsonObject fileInfo, String changeIdentifier, String changeType) {
+ logger.trace("starting to getFileDataFromJson!");
+
FileData fileData = null;
String name = getValueFromJson(fileInfo, NAME);
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 7ec474ca..f80db897 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
@@ -59,7 +59,7 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask {
@Override
Flux<FileData> consume(Mono<String> message) {
- logger.trace("consume called with arg {}", message.toString());
+ logger.trace("consume called with arg {}", message);
return dmaapConsumerJsonParser.getJsonObject(message);
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTask.java
index 66d59ae8..b98d40d3 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTask.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTask.java
@@ -18,6 +18,7 @@
package org.onap.dcaegen2.collectors.datafile.tasks;
+import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
@@ -27,5 +28,6 @@ import reactor.core.publisher.Flux;
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public interface XnfCollectorTask {
+ abstract FtpesConfig resolveConfiguration();
Flux<ConsumerDmaapModel> execute(FileData fileData);
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
index a29fb092..be6ac9cc 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java
@@ -19,6 +19,9 @@ package org.onap.dcaegen2.collectors.datafile.tasks;
import java.io.File;
import java.net.URI;
+import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
+import org.onap.dcaegen2.collectors.datafile.configuration.Config;
+import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig;
import org.onap.dcaegen2.collectors.datafile.ftp.FileServerData;
import org.onap.dcaegen2.collectors.datafile.ftp.FtpsClient;
import org.onap.dcaegen2.collectors.datafile.ftp.ImmutableFileServerData;
@@ -44,12 +47,14 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask {
private static final String SFTP = "sftp";
private static final Logger logger = LoggerFactory.getLogger(XnfCollectorTaskImpl.class);
+ private Config datafileAppConfig;
private final FtpsClient ftpsClient;
private final SftpClient sftpClient;
@Autowired
- protected XnfCollectorTaskImpl(FtpsClient ftpsCleint, SftpClient sftpClient) {
+ protected XnfCollectorTaskImpl(AppConfig datafileAppConfig, FtpsClient ftpsCleint, SftpClient sftpClient) {
+ this.datafileAppConfig = datafileAppConfig;
this.ftpsClient = ftpsCleint;
this.sftpClient = sftpClient;
}
@@ -57,6 +62,8 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask {
@Override
public Flux<ConsumerDmaapModel> execute(FileData fileData) {
logger.trace("Entering execute with {}", fileData);
+ resolveKeyStore();
+
String localFile = collectFile(fileData);
if (localFile != null) {
@@ -68,17 +75,27 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask {
return Flux.empty();
}
+ @Override
+ public FtpesConfig resolveConfiguration() {
+ return datafileAppConfig.getFtpesConfiguration();
+ }
+
+ private void resolveKeyStore() {
+ FtpesConfig ftpesConfig = resolveConfiguration();
+ ftpsClient.setKeyCertPath(ftpesConfig.keyCert());
+ ftpsClient.setKeyCertPassword(ftpesConfig.keyPassword());
+ ftpsClient.setTrustedCAPath(ftpesConfig.trustedCA());
+ ftpsClient.setTrustedCAPassword(ftpesConfig.trustedCAPassword());
+ }
+
private String collectFile(FileData fileData) {
+ logger.trace("starting to collectFile");
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();
+ FileServerData fileServerData = getFileServerData(uri);
String remoteFile = uri.getPath();
String localFile = "target" + File.separator + fileData.name();
String scheme = uri.getScheme();
-
boolean fileDownloaded = false;
if (FTPES.equals(scheme) || FTPS.equals(scheme)) {
fileDownloaded = ftpsClient.collectFile(fileServerData, remoteFile, localFile);
@@ -96,6 +113,13 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask {
return localFile;
}
+ private FileServerData getFileServerData(URI uri) {
+ String[] userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo());
+ return ImmutableFileServerData.builder().serverAddress(uri.getHost())
+ .userId(userInfo != null ? userInfo[0] : "").password(userInfo != null ? userInfo[1] : "")
+ .port(uri.getPort()).build();
+ }
+
private String[] getUserNameAndPasswordIfGiven(String userInfoString) {
String[] userInfo = null;
if (userInfoString != null && !userInfoString.isEmpty()) {