diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/a1pesimulator/service/fileready/FtpServerService.java | 39 | ||||
-rw-r--r-- | src/main/resources/application.properties | 2 | ||||
-rw-r--r-- | src/test/resources/application.properties | 2 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/main/java/org/onap/a1pesimulator/service/fileready/FtpServerService.java b/src/main/java/org/onap/a1pesimulator/service/fileready/FtpServerService.java index 3d751f5..d71cdf0 100644 --- a/src/main/java/org/onap/a1pesimulator/service/fileready/FtpServerService.java +++ b/src/main/java/org/onap/a1pesimulator/service/fileready/FtpServerService.java @@ -10,12 +10,14 @@ import java.io.IOException; import java.nio.file.Files; import java.util.zip.GZIPOutputStream; + import org.onap.a1pesimulator.data.fileready.FileData; import org.onap.a1pesimulator.exception.NotUploadedToFtpException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.util.FileCopyUtils; import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.sftp.SFTPClient; @@ -27,6 +29,14 @@ public class FtpServerService { private static final Logger log = LoggerFactory.getLogger(FtpServerService.class); + //true - file will be uploaded to FTP; false - file will be copied into xmlPmLocation + @Value("${ftp.server.upload}") + private boolean ftpServerUpload; + + // location where archived file will be copied + @Value("${xml.pm.location}") + private String xmlPmLocation; + @Value("${ftp.server.url}") private String ftpServerUrl; @@ -48,7 +58,7 @@ public class FtpServerService { public Mono<FileData> uploadFileToFtp(FileData fileData) { return Mono.just(fileData) .flatMap(this::tryToCompressFile) - .flatMap(this::tryToUploadFileToFtp) + .flatMap(this::tryToUploadOrSaveFileToFtp) .onErrorResume(throwable -> resumeError(throwable, fileData)) .doOnNext(file -> deletePMBulkFile(file.getPmBulkFile())); } @@ -73,12 +83,33 @@ public class FtpServerService { log.trace("Compressing file {}", fileData.getPmBulkFile().getName()); return Mono.just(fileData); } catch (IOException e) { - log.error("Could not compress file ", e); + log.error("Could not compress file", e); return Mono.empty(); } } /** + * Upload file to FTP or copy it to mounted location + * + * @param fileData data about file + * @return fileData for fileReadyEvent + */ + private Mono<FileData> tryToUploadOrSaveFileToFtp(FileData fileData) { + if (ftpServerUpload) { + return tryToUploadFileToFtp(fileData); + } else { + File fileOnFtp = new File(xmlPmLocation, fileData.getArchivedPmBulkFile().getName()); + try { + FileCopyUtils.copy(fileData.getArchivedPmBulkFile(), fileOnFtp); + log.info("Uploading file to the location: {}", fileOnFtp); + return Mono.just(fileData); + } catch (IOException e) { + return Mono.error(new NotUploadedToFtpException("File was not copied to FTP location", e)); + } + } + } + + /** * Upload file to FTP * * @param fileData archived file in Mono @@ -155,6 +186,10 @@ public class FtpServerService { /** * Try to clean up things after an exception + * + * @param throwable error thrown + * @param fileData data about files which needs to be deleted + * @return empty Mono object */ private Mono<FileData> resumeError(Throwable throwable, FileData fileData) { log.error("Error occurs while uploading file to FTP server", throwable); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1cb06ec..fd95743 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,6 +22,7 @@ ves.failing.throughput=1 ves.failing.latency=500 # in sec ves.failing.checkout.delay=15 +ftp.server.upload=false ftp.server.protocol=sftp ftp.server.url=localhost ftp.server.port=22222 @@ -39,6 +40,7 @@ logging.config=classpath:logback-spring.xml refresher.fixed.rate.ms=60000 restapi.version=v1 # PM Bulk File constants +xml.pm.location=/a1pesim/generated_pm_bulks xml.pm.bulk.fileFormatVersion=32.435 V7.0 xml.pm.bulk.vendorName=Samsung xml.pm.bulk.userLabel=ORAN PE Sim diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 27d2fda..77c2933 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -33,11 +33,13 @@ topology.ue.config.file=src/test/resources/ue.json refresher.fixed.rate.ms=60000 restapi.version=v1 # PM Bulk File constants +xml.pm.location=/a1pesim/generated_pm_bulks xml.pm.bulk.fileFormatVersion=32.435 V7.0 xml.pm.bulk.vendorName=Samsung xml.pm.bulk.userLabel=ORAN PE Sim xml.pm.bulk.fileSender=ORAN #File Ready Event constants +ftp.server.upload=false file.ready.version=4.0.1 file.ready.vesEventListenerVersion=7.0.1 file.ready.domain=notification |