diff options
Diffstat (limited to 'datafile-dmaap-client/src/main/java/org')
9 files changed, 27 insertions, 347 deletions
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java deleted file mode 100644 index 29160c94..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.IOException; -import java.io.OutputStream; -import javax.net.ssl.KeyManager; -import javax.net.ssl.TrustManager; -import org.apache.commons.net.ftp.FTPSClient; -import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; - -public class FTPSClientWrapper implements IFTPSClient { - private FTPSClient ftpsClient = new FTPSClient(); - - @Override - public void setNeedClientAuth(boolean isNeedClientAuth) { - ftpsClient.setNeedClientAuth(isNeedClientAuth); - } - - @Override - public void setKeyManager(KeyManager keyManager) { - ftpsClient.setKeyManager(keyManager); - } - - @Override - public void setTrustManager(TrustManager trustManager) { - ftpsClient.setTrustManager(trustManager); - } - - @Override - public void connect(String hostName, int port) throws IOException { - ftpsClient.connect(hostName, port); - } - - @Override - public boolean login(String username, String password) throws IOException { - return ftpsClient.login(username, password); - } - - @Override - public boolean logout() throws IOException { - return ftpsClient.logout(); - } - - @Override - public int getReplyCode() { - return ftpsClient.getReplyCode(); - } - - @Override - public void disconnect() throws IOException { - ftpsClient.disconnect(); - } - - @Override - public void enterLocalPassiveMode() { - ftpsClient.enterLocalPassiveMode(); - } - - @Override - public void setFileType(int fileType) throws IOException { - ftpsClient.setFileType(fileType); - } - - @Override - public void execPBSZ(int psbz) throws IOException { - ftpsClient.execPBSZ(psbz); - } - - @Override - public void execPROT(String prot) throws IOException { - ftpsClient.execPROT(prot); - } - - @Override - public void retrieveFile(String remote, OutputStream local) throws DatafileTaskException { - try { - if (!ftpsClient.retrieveFile(remote, local)) { - throw new DatafileTaskException("could not retrieve file"); - } - } catch (IOException e) { - throw new DatafileTaskException(e); - } - } - - @Override - public void setTimeout(Integer t) { - this.ftpsClient.setDefaultTimeout(t); - } - - @Override - public boolean isConnected() { - return ftpsClient.isConnected(); - } - - @Override - public void setBufferSize(int bufSize) { - ftpsClient.setBufferSize(bufSize); - } -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java index f330b673..bedae43a 100644 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java +++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java @@ -17,11 +17,13 @@ package org.onap.dcaegen2.collectors.datafile.ftp; import java.nio.file.Path; + import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; /** * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ +@FunctionalInterface public interface FileCollectClient { public void collectFile(String remoteFile, Path localFile) throws DatafileTaskException; } diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java index 461b2200..c3b7990f 100644 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java +++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java @@ -16,6 +16,8 @@ package org.onap.dcaegen2.collectors.datafile.ftp; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -27,12 +29,10 @@ import java.util.Optional; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPReply; +import org.apache.commons.net.ftp.FTPSClient; import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.io.FileSystemResourceWrapper; -import org.onap.dcaegen2.collectors.datafile.io.FileWrapper; -import org.onap.dcaegen2.collectors.datafile.io.IFile; import org.onap.dcaegen2.collectors.datafile.io.IFileSystemResource; -import org.onap.dcaegen2.collectors.datafile.io.IOutputStream; import org.onap.dcaegen2.collectors.datafile.ssl.IKeyManagerUtils; import org.onap.dcaegen2.collectors.datafile.ssl.IKeyManagerUtils.KeyManagerException; import org.onap.dcaegen2.collectors.datafile.ssl.IKeyStore; @@ -55,13 +55,11 @@ public class FtpsClient implements FileCollectClient { private Path trustedCAPath; private String trustedCAPassword; - private IFTPSClient realFtpsClient = new FTPSClientWrapper(); + private FTPSClient realFtpsClient = new FTPSClient(); private IKeyManagerUtils keyManagerUtils = new KeyManagerUtilsWrapper(); private IKeyStore keyStore; private ITrustManagerFactory trustManagerFactory; - private IFile localFile = new FileWrapper(); private IFileSystemResource fileSystemResource = new FileSystemResourceWrapper(); - private IOutputStream outputStream; private boolean keyManagerSet = false; private boolean trustManagerSet = false; private final FileServerData fileServerData; @@ -83,7 +81,7 @@ public class FtpsClient implements FileCollectClient { getFileFromxNF(realFtpsClient, remoteFile, localFile); } catch (IOException e) { logger.trace("", e); - throw new DatafileTaskException("Could not open connection: " + e); + throw new DatafileTaskException("Could not open connection: ", e); } catch (KeyManagerException e) { logger.trace("", e); throw new DatafileTaskException(e); @@ -93,7 +91,7 @@ public class FtpsClient implements FileCollectClient { logger.trace("collectFile fetched: {}", localFile); } - private void setUpKeyManager(IFTPSClient ftps) throws KeyManagerException { + private void setUpKeyManager(FTPSClient ftps) throws KeyManagerException { if (keyManagerSet) { logger.trace("keyManager already set!"); } else { @@ -104,7 +102,7 @@ public class FtpsClient implements FileCollectClient { logger.trace("complete setUpKeyManager"); } - private void setUpTrustedCA(IFTPSClient ftps) throws DatafileTaskException { + private void setUpTrustedCA(FTPSClient ftps) throws DatafileTaskException { if (trustManagerSet) { logger.trace("trustManager already set!"); } else { @@ -130,7 +128,7 @@ public class FtpsClient implements FileCollectClient { return port.isPresent() ? port.get() : FTPS_DEFAULT_PORT; } - private void setUpConnection(IFTPSClient ftps) throws DatafileTaskException, IOException { + private void setUpConnection(FTPSClient ftps) throws DatafileTaskException, IOException { if (!ftps.isConnected()) { ftps.connect(fileServerData.serverAddress(), getPort(fileServerData.port())); logger.trace("after ftp connect"); @@ -155,23 +153,26 @@ public class FtpsClient implements FileCollectClient { logger.trace("setUpConnection successfully!"); } - private void getFileFromxNF(IFTPSClient ftps, String remoteFileName, Path localFileName) - throws IOException, DatafileTaskException { + private void getFileFromxNF(FTPSClient ftps, String remoteFileName, Path localFileName) + throws IOException { logger.trace("starting to getFile"); - this.localFile.setPath(localFileName); - this.localFile.createNewFile(); - - OutputStream output = this.outputStream.getOutputStream(this.localFile.getFile()); + File localFile = localFileName.toFile(); + if (localFile.createNewFile()) { + logger.warn("Local file {} already created", localFileName); + } + OutputStream output = new FileOutputStream(localFile); logger.trace("begin to retrieve from xNF."); - ftps.retrieveFile(remoteFileName, output); + if (!ftps.retrieveFile(remoteFileName, output)) { + throw new IOException("Could not retrieve file"); + } logger.trace("end retrieve from xNF."); output.close(); logger.debug("File {} Download Successfull from xNF", localFileName); } - private void closeDownConnection(IFTPSClient ftps) { + private void closeDownConnection(FTPSClient ftps) { logger.trace("starting to closeDownConnection"); if (ftps != null && ftps.isConnected()) { try { @@ -220,7 +221,7 @@ public class FtpsClient implements FileCollectClient { return keyStore; } - void setFtpsClient(IFTPSClient ftpsClient) { + void setFtpsClient(FTPSClient ftpsClient) { this.realFtpsClient = ftpsClient; } @@ -236,14 +237,6 @@ public class FtpsClient implements FileCollectClient { trustManagerFactory = tmf; } - void setFile(IFile file) { - localFile = file; - } - - void setOutputStream(IOutputStream outputStream) { - this.outputStream = outputStream; - } - void setFileSystemResource(IFileSystemResource fileSystemResource) { this.fileSystemResource = fileSystemResource; } diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java deleted file mode 100644 index 3dcaa656..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.IOException; -import java.io.OutputStream; -import javax.net.ssl.KeyManager; -import javax.net.ssl.TrustManager; -import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; - -public interface IFTPSClient { - public void setNeedClientAuth(boolean isNeedClientAuth); - - public void setKeyManager(KeyManager keyManager); - - public void setTrustManager(TrustManager trustManager); - - public void connect(String hostname, int port) throws IOException; - - public boolean login(String username, String password) throws IOException; - - public boolean logout() throws IOException; - - public int getReplyCode(); - - public void setBufferSize(int bufSize); - - public boolean isConnected(); - - public void disconnect() throws IOException; - - public void enterLocalPassiveMode(); - - public void setFileType(int fileType) throws IOException; - - public void execPBSZ(int newParam) throws IOException; - - public void execPROT(String prot) throws IOException; - - public void retrieveFile(String remote, OutputStream local) throws DatafileTaskException; - - void setTimeout(Integer t); -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/FileWrapper.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/FileWrapper.java deleted file mode 100644 index 203a5985..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/FileWrapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.io; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -public class FileWrapper implements IFile { - private File file; - - @Override - public void setPath(Path path) { - file = path.toFile(); - } - - @Override - public boolean createNewFile() throws IOException { - if (file == null) { - throw new IOException("Path to file not set."); - } - return file.createNewFile(); - } - - @Override - public File getFile() { - return file; - } - - @Override - public boolean delete() { - return file.delete(); - } -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IFile.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IFile.java deleted file mode 100644 index 2b95842f..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IFile.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.io; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -public interface IFile { - public void setPath(Path path); - - public boolean createNewFile() throws IOException; - - public File getFile(); - - public boolean delete(); -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IOutputStream.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IOutputStream.java deleted file mode 100644 index 8015ea76..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IOutputStream.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.io; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.OutputStream; - -@FunctionalInterface -public interface IOutputStream { - public OutputStream getOutputStream(File file) throws FileNotFoundException; -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/OutputStreamWrapper.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/OutputStreamWrapper.java deleted file mode 100644 index 88787826..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/OutputStreamWrapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018-2019 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.io; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; - -public class OutputStreamWrapper implements IOutputStream { - - @Override - public OutputStream getOutputStream(File file) throws FileNotFoundException { - return new FileOutputStream(file); - } - -} 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 bced3d85..4869e4c2 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 @@ -53,7 +53,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.web.util.DefaultUriBuilderFactory; -import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 @@ -101,7 +101,7 @@ public class DmaapProducerReactiveHttpClient { * @param consumerDmaapModel - object which will be sent to DMaaP DataRouter * @return status code of operation */ - public Flux<HttpStatus> getDmaapProducerResponse(ConsumerDmaapModel consumerDmaapModel) { + public Mono<HttpStatus> getDmaapProducerResponse(ConsumerDmaapModel consumerDmaapModel) { logger.trace("Entering getDmaapProducerResponse with {}", consumerDmaapModel); try { logger.trace("Starting to publish to DR {}", consumerDmaapModel.getInternalLocation()); @@ -116,12 +116,12 @@ public class DmaapProducerReactiveHttpClient { Future<HttpResponse> future = webClient.execute(put, null); HttpResponse response = future.get(); - logger.trace(response.toString()); + logger.trace("{}", response); webClient.close(); - return Flux.just(HttpStatus.valueOf(response.getStatusLine().getStatusCode())); + return Mono.just(HttpStatus.valueOf(response.getStatusLine().getStatusCode())); } catch (Exception e) { logger.error("Unable to send file to DataRouter. Data: {}", consumerDmaapModel.getInternalLocation(), e); - return Flux.error(e); + return Mono.error(e); } } |