Skip to content

Commit

Permalink
Flexion/jgilmore/update blob storage transport filenames (#16920)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GilmoreA6 authored Jan 7, 2025
1 parent ba46ef8 commit f337fd9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 46 deletions.
13 changes: 0 additions & 13 deletions prime-router/src/main/kotlin/azure/BlobAccess.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion prime-router/src/main/kotlin/transport/BlobStoreTransport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 0 additions & 32 deletions prime-router/src/test/kotlin/azure/BlobAccessTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f337fd9

Please sign in to comment.