From f337fd99d7712a9e15ad58cc599e29bd97a1833f Mon Sep 17 00:00:00 2001 From: James Gilmore <109554461+GilmoreA6@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:20:24 -0800 Subject: [PATCH] Flexion/jgilmore/update blob storage transport filenames (#16920) * modify blob transport to utilize external filename * rename variables to be clearer * update blobaccess tests * add logging * remove unused component * remove copyBlob and update blob transport to directly call downloadBlobAsByteArray --- .../src/main/kotlin/azure/BlobAccess.kt | 13 -------- .../kotlin/transport/BlobStoreTransport.kt | 6 +++- .../src/test/kotlin/azure/BlobAccessTests.kt | 32 ------------------- 3 files changed, 5 insertions(+), 46 deletions(-) diff --git a/prime-router/src/main/kotlin/azure/BlobAccess.kt b/prime-router/src/main/kotlin/azure/BlobAccess.kt index 8b88fbcf017..8cbe6f1b68e 100644 --- a/prime-router/src/main/kotlin/azure/BlobAccess.kt +++ b/prime-router/src/main/kotlin/azure/BlobAccess.kt @@ -401,19 +401,6 @@ class BlobAccess() : Logging { return binaryData } - /** - * Copy a blob at [fromBlobUrl] to a blob in [blobConnInfo] - */ - fun copyBlob(fromBlobUrl: String, blobConnInfo: BlobContainerMetadata): String { - val fromBytes = downloadBlobAsByteArray(fromBlobUrl) - logger.info("Ready to copy ${fromBytes.size} bytes from $fromBlobUrl") - val toFilename = BlobInfo.getBlobFilename(fromBlobUrl) - logger.info("New blob filename will be $toFilename") - val toBlobUrl = uploadBlob(toFilename, fromBytes, blobConnInfo) - logger.info("New blob URL is $toBlobUrl") - return toBlobUrl - } - /** * Accepts a [BlobItemAndPreviousVersions] and grabs the most recent previous version and updates * the blob to it. diff --git a/prime-router/src/main/kotlin/transport/BlobStoreTransport.kt b/prime-router/src/main/kotlin/transport/BlobStoreTransport.kt index ea372653d59..2f3dfe9e6dd 100644 --- a/prime-router/src/main/kotlin/transport/BlobStoreTransport.kt +++ b/prime-router/src/main/kotlin/transport/BlobStoreTransport.kt @@ -31,7 +31,11 @@ class BlobStoreTransport : ITransport { val receiver = header.receiver ?: error("No receiver defined for report ${header.reportFile.reportId}") val bodyUrl = header.reportFile.bodyUrl ?: error("Report ${header.reportFile.reportId} has no blob to copy") context.logger.info("About to copy $bodyUrl to $envVar:$storageName") - val newUrl = BlobAccess.copyBlob(bodyUrl, BlobAccess.BlobContainerMetadata.build(transportType)) + val blobConnection = BlobAccess.BlobContainerMetadata.build(transportType) + val blobFile = BlobAccess.downloadBlobAsByteArray(bodyUrl) + context.logger.info("New blob filename will be $externalFileName") + val newUrl = BlobAccess.uploadBlob(externalFileName, blobFile, blobConnection) + context.logger.info("New blob URL is $newUrl") val msg = "Successfully copied $bodyUrl to $newUrl" context.logger.info(msg) actionHistory.trackActionResult(msg) diff --git a/prime-router/src/test/kotlin/azure/BlobAccessTests.kt b/prime-router/src/test/kotlin/azure/BlobAccessTests.kt index bdda5a8abdd..11a3a4d52b2 100644 --- a/prime-router/src/test/kotlin/azure/BlobAccessTests.kt +++ b/prime-router/src/test/kotlin/azure/BlobAccessTests.kt @@ -704,38 +704,6 @@ class BlobAccessTests { assertThat(resultBinaryData.toString()).isEqualTo(expectedResult) } - @Test - fun `copy blob`() { - mockkClass(BlobAccess::class) - mockkObject(BlobAccess.Companion) - every { BlobAccess.Companion.getBlobConnection(any()) } returns "testconnection" - - val testUrl = "http://testurl/testfile" - val testFile = BlobAccess.BlobInfo.getBlobFilename(testUrl) - val testBlobMetadata = BlobAccess.BlobContainerMetadata.build("testcontainer", "testenvvar") - - every { BlobAccess.Companion.downloadBlobAsByteArray(testUrl) }.returns("testblob".toByteArray()) - every { - BlobAccess.Companion.uploadBlob( - testFile, - "testblob".toByteArray(), - testBlobMetadata - ) - }.returns("http://testurl2") - - val result = BlobAccess.copyBlob(testUrl, testBlobMetadata) - - verify(exactly = 1) { BlobAccess.Companion.downloadBlobAsByteArray(testUrl, any(), any()) } - verify(exactly = 1) { - BlobAccess.Companion.uploadBlob( - testFile, - "testblob".toByteArray(), - testBlobMetadata - ) - } - assertThat(result).isEqualTo("http://testurl2") - } - @Test fun `delete blob`() { val testUrl = "http://deleteblob"