diff options
author | 2019-03-29 09:05:28 +0000 | |
---|---|---|
committer | 2019-03-29 09:05:28 +0000 | |
commit | d90535ce664cfde22e0670c950498a114388df99 (patch) | |
tree | 34519336dfee99f57f6880b642ef0e9675ef4ce3 /datafile-app-server | |
parent | fc34b09dc45ede571653be2dfd37507572c27002 (diff) |
Change file name sent to DataRouter
In the previous commit for this issue, the file name sent to DataRouter
was changed. This turned out to be wrong, so in this commit it is
changed back again.
Change-Id: I9b0d726f406758846fd256626e73edf59d710c8b
Issue-ID: DCAEGEN2-1256
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Diffstat (limited to 'datafile-app-server')
6 files changed, 16 insertions, 30 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java index d0d1f91a..037bd0d3 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java @@ -20,7 +20,6 @@ import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; - import org.immutables.gson.Gson; import org.immutables.value.Value; import org.onap.dcaegen2.collectors.datafile.ftp.FileServerData; @@ -35,7 +34,7 @@ import org.onap.dcaegen2.collectors.datafile.ftp.Scheme; @Value.Immutable @Gson.TypeAdapters public abstract class FileData { - private static final String DATAFILE_TMPDIR = "/tmp/onap_datafile/"; + public static final String DATAFILE_TMPDIR = "/tmp/onap_datafile/"; /** * @return the file name with no path @@ -71,12 +70,8 @@ public abstract class FileData { return URI.create(location()).getPath(); } - public Path getLocalFileName() { - return createLocalFileName(messageMetaData().sourceName(), name()); - } - - public static Path createLocalFileName(String sourceName, String fileName) { - return Paths.get(DATAFILE_TMPDIR, sourceName + "_" + fileName); + public Path getLocalFilePath() { + return Paths.get(DATAFILE_TMPDIR, name()); } public FileServerData fileServerData() { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java index 4207d1fc..8c1a2cf4 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java @@ -26,7 +26,6 @@ import static org.onap.dcaegen2.collectors.datafile.model.logging.MdcVariables.X import com.google.gson.JsonElement; import com.google.gson.JsonParser; - import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -34,7 +33,6 @@ import java.nio.file.Path; import java.time.Duration; import java.util.Map; import java.util.UUID; - import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; @@ -52,7 +50,6 @@ import org.slf4j.MDC; import org.springframework.core.io.FileSystemResource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; - import reactor.core.publisher.Mono; /** @@ -129,7 +126,7 @@ public class DataRouterPublisher { metaData.getAsJsonObject().remove(NAME_JSON_TAG).getAsString(); metaData.getAsJsonObject().remove(INTERNAL_LOCATION_JSON_TAG); put.addHeader(X_DMAAP_DR_META, metaData.toString()); - put.setURI(getPublishUri(model.getInternalLocation().getFileName().toString())); + put.setURI(getPublishUri(model.getName())); } private void prepareBody(ConsumerDmaapModel model, HttpPut put) throws IOException { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java index 8849b45e..158bcb29 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java @@ -65,7 +65,7 @@ public class FileCollector { logger.trace("starting to collectFile {}", fileData.name()); final String remoteFile = fileData.remoteFilePath(); - final Path localFile = fileData.getLocalFileName(); + final Path localFile = fileData.getLocalFilePath(); try (FileCollectClient currentClient = createClient(fileData)) { currentClient.open(); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java index b4096c73..2a6e4c0d 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java @@ -22,7 +22,6 @@ import java.time.Duration; import java.time.Instant; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; - import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.FileData; @@ -34,7 +33,6 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; @@ -144,9 +142,9 @@ public class ScheduledTasks { private boolean shouldBePublished(FileData fileData, Map<String, String> contextMap) { boolean result = false; - Path localFileName = fileData.getLocalFileName(); - if (alreadyPublishedFiles.put(localFileName) == null) { - result = !createPublishedChecker().execute(localFileName.getFileName().toString(), contextMap); + Path localFilePath = fileData.getLocalFilePath(); + if (alreadyPublishedFiles.put(localFilePath) == null) { + result = !createPublishedChecker().execute(fileData.name(), contextMap); } return result; } @@ -160,10 +158,10 @@ public class ScheduledTasks { private Mono<ConsumerDmaapModel> handleFetchFileFailure(FileData fileData, Map<String, String> contextMap) { MdcVariables.setMdcContextMap(contextMap); - Path localFileName = fileData.getLocalFileName(); + Path localFilePath = fileData.getLocalFilePath(); logger.error("File fetching failed, fileData {}", fileData); - deleteFile(localFileName, contextMap); - alreadyPublishedFiles.remove(localFileName); + deleteFile(localFilePath, contextMap); + alreadyPublishedFiles.remove(localFilePath); currentNumberOfTasks.decrementAndGet(); return Mono.empty(); } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java index fe867738..7a9a17ab 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java @@ -37,7 +37,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -55,7 +54,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPub import org.springframework.http.HttpStatus; import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.UriBuilder; - import reactor.test.StepVerifier; /** @@ -71,7 +69,6 @@ class DataRouterPublisherTest { private static final String TIME_ZONE_OFFSET = "UTC+05:00"; private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz"; private static final String FTPES_ADDRESS = "ftpes://192.168.0.101:22/ftp/rop/" + PM_FILE_NAME; - private static final String LOCAL_FILE_NAME = SOURCE_NAME + "_" + PM_FILE_NAME; private static final String COMPRESSION = "gzip"; private static final String FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec"; @@ -111,7 +108,7 @@ class DataRouterPublisherTest { .timeZoneOffset(TIME_ZONE_OFFSET) // .name(PM_FILE_NAME) // .location(FTPES_ADDRESS) // - .internalLocation(Paths.get("target/" + LOCAL_FILE_NAME)) // + .internalLocation(Paths.get("target/" + PM_FILE_NAME)) // .compression("gzip") // .fileFormatType(FILE_FORMAT_TYPE) // .fileFormatVersion(FILE_FORMAT_VERSION) // @@ -142,7 +139,7 @@ class DataRouterPublisherTest { Path actualPath = Paths.get(actualUri.getPath()); assertTrue(PUBLISH_TOPIC.equals(actualPath.getName(0).toString())); assertTrue(FEED_ID.equals(actualPath.getName(1).toString())); - assertTrue(LOCAL_FILE_NAME.equals(actualPath.getName(2).toString())); + assertTrue(PM_FILE_NAME.equals(actualPath.getName(2).toString())); Header[] contentHeaders = actualPut.getHeaders("content-type"); assertEquals(APPLICATION_OCTET_STREAM_CONTENT_TYPE, contentHeaders[0].getValue()); @@ -228,7 +225,7 @@ class DataRouterPublisherTest { when(statusLineMock.getStatusCode()).thenReturn(firstResponse, nextHttpResponses); InputStream fileStream = new ByteArrayInputStream(FILE_CONTENT.getBytes()); - doReturn(fileStream).when(publisherTaskUnderTestSpy).createInputStream(Paths.get("target", LOCAL_FILE_NAME)); + doReturn(fileStream).when(publisherTaskUnderTestSpy).createInputStream(Paths.get("target", PM_FILE_NAME)); } private Map<String, String> getMetaDataAsMap(Header[] metaHeaders) { diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java index 6e17f27b..83827177 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java @@ -27,10 +27,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.HashMap; import java.util.Map; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig; @@ -45,7 +45,6 @@ import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData; import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData; import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData; - import reactor.test.StepVerifier; /** @@ -67,7 +66,7 @@ public class FileCollectorTest { private static final int PORT_22 = 22; private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz"; private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME; - private static final Path LOCAL_FILE_LOCATION = FileData.createLocalFileName(SOURCE_NAME, PM_FILE_NAME); + private static final Path LOCAL_FILE_LOCATION = Paths.get(FileData.DATAFILE_TMPDIR, PM_FILE_NAME); private static final String USER = "usr"; private static final String PWD = "pwd"; private static final String FTPES_LOCATION = |