summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-09-09 16:44:39 -0400
committerBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>2019-09-12 01:22:27 +0000
commit338cc251c24e9ae8a0d098098d94a9c2af2a1a07 (patch)
treeb36eb8d182370bd68bbb03751ef3cb9a61305cb0
parenta80bb83c9f6fd4c648abfb273d5b2b28d82a38fa (diff)
Implement GRPC download cab.
Change-Id: I7c872b7e6e20590668c68b92ed221752a9413bd8 Issue-ID: CCSDK-1682 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt38
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt27
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt29
3 files changed, 82 insertions, 12 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
index 08250ed9d..a3bf3709d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt
@@ -73,7 +73,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
}
UploadAction.ENRICH.toString() -> {
val enrichedByteArray = bluePrintModelHandler.enrichBlueprintFileSource(byteArray)
- responseObserver.onNext(enrichmentStatus(request.commonHeader, enrichedByteArray))
+ responseObserver.onNext(outputWithFileBytes(request.commonHeader, enrichedByteArray))
}
else -> {
responseObserver.onNext(failStatus(request.commonHeader,
@@ -91,6 +91,40 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
}
@PreAuthorize("hasRole('USER')")
+ override fun downloadBlueprint(request: BluePrintDownloadInput,
+ responseObserver: StreamObserver<BluePrintManagementOutput>) {
+ runBlocking {
+ val blueprintName = request.actionIdentifiers.blueprintName
+ val blueprintVersion = request.actionIdentifiers.blueprintVersion
+ val blueprint = "blueprint $blueprintName:$blueprintVersion"
+
+ /** Get the Search Action */
+ val searchAction = request.actionIdentifiers?.actionName.emptyTONull()
+ ?: DownloadAction.SEARCH.toString()
+
+ log.info("request(${request.commonHeader.requestId}): Received download $blueprint")
+ try {
+ when (searchAction) {
+ DownloadAction.SEARCH.toString() -> {
+ val downloadByteArray = bluePrintModelHandler.download(blueprintName, blueprintVersion)
+ responseObserver.onNext(outputWithFileBytes(request.commonHeader, downloadByteArray))
+ }
+ else -> {
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "Search action($searchAction) not implemented",
+ BluePrintProcessorException("Not implemented")))
+ }
+ }
+ } catch (e: Exception) {
+ responseObserver.onNext(failStatus(request.commonHeader,
+ "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e))
+ } finally {
+ responseObserver.onCompleted()
+ }
+ }
+ }
+
+ @PreAuthorize("hasRole('USER')")
override fun removeBlueprint(request: BluePrintRemoveInput, responseObserver:
StreamObserver<BluePrintManagementOutput>) {
@@ -112,7 +146,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu
}
}
- private fun enrichmentStatus(header: CommonHeader, byteArray: ByteArray): BluePrintManagementOutput =
+ private fun outputWithFileBytes(header: CommonHeader, byteArray: ByteArray): BluePrintManagementOutput =
BluePrintManagementOutput.newBuilder()
.setCommonHeader(header)
.setFileChunk(FileChunk.newBuilder().setChunk(ByteString.copyFrom(byteArray)))
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
index 212ffd907..526e92cea 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
@@ -123,19 +123,14 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService:
@Throws(BluePrintException::class)
open fun downloadBlueprintModelFileByNameAndVersion(name: String,
version: String): ResponseEntity<Resource> {
- val blueprintModel: BlueprintModel
try {
- blueprintModel = getBlueprintModelByNameAndVersion(name, version)
+ val archiveByteArray = download(name, version)
+ val fileName = "${name}_$version.zip"
+ return prepareResourceEntity(fileName, archiveByteArray)
} catch (e: BluePrintException) {
throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
String.format("Error while " + "downloading the CBA file: %s", e.message), e)
}
-
- val fileName = blueprintModel.id + ".zip"
- val file = blueprintModel.blueprintModelContent?.content
- ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
- String.format("Error while downloading the CBA file: couldn't get model content"))
- return prepareResourceEntity(fileName, file)
}
/**
@@ -153,7 +148,7 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService:
throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e)
}
- val fileName = blueprintModel.id + ".zip"
+ val fileName = "${blueprintModel.artifactName}_${blueprintModel.artifactVersion}.zip"
val file = blueprintModel.blueprintModelContent?.content
?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
String.format("Error while downloading the CBA file: couldn't get model content"))
@@ -319,6 +314,20 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService:
}
}
+ /** Common CBA download function for RestController and GRPC Handler, the [fileSource] may be
+ * byteArray or File Part type.*/
+ open fun download(name: String, version: String): ByteArray {
+ try {
+ val blueprintModel = getBlueprintModelByNameAndVersion(name, version)
+ return blueprintModel.blueprintModelContent?.content
+ ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+ String.format("Error while downloading the CBA file: couldn't get model content"))
+ } catch (e: BluePrintException) {
+ throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+ String.format("Error while " + "downloading the CBA file: %s", e.message), e)
+ }
+ }
+
/** Common CBA Enrich function for RestController and GRPC Handler, the [fileSource] may be
* byteArray or File Part type.*/
open suspend fun enrichBlueprintFileSource(fileSource: Any): ByteArray {
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
index 9f1bd9c7c..691cfd760 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt
@@ -68,7 +68,7 @@ class BluePrintManagementGRPCHandlerTest {
}
@Test
- fun `test upload blueprint`() {
+ fun `test upload and download blueprint`() {
val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel)
val id = "123_upload"
val req = createUploadInputRequest(id, UploadAction.PUBLISH.toString())
@@ -78,6 +78,16 @@ class BluePrintManagementGRPCHandlerTest {
assertTrue(output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
"failed to get success status")
assertEquals(id, output.commonHeader.requestId)
+
+ val downloadId = "123_download"
+ val downloadReq = createDownloadInputRequest(downloadId, DownloadAction.SEARCH.toString())
+
+ val downloadOutput = blockingStub.downloadBlueprint(downloadReq)
+ assertEquals(200, downloadOutput.status.code)
+ assertTrue(downloadOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
+ "failed to get success status")
+ assertNotNull(downloadOutput.fileChunk?.chunk, "failed to get cba file chunks")
+ assertEquals(downloadId, downloadOutput.commonHeader.requestId)
}
@Test
@@ -146,6 +156,23 @@ class BluePrintManagementGRPCHandlerTest {
.build()
}
+ private fun createDownloadInputRequest(id: String, action: String): BluePrintDownloadInput {
+ val commonHeader = CommonHeader
+ .newBuilder()
+ .setTimestamp("2012-04-23T18:25:43.511Z")
+ .setOriginatorId("System")
+ .setRequestId(id)
+ .setSubRequestId("1234-56").build()
+
+ return BluePrintDownloadInput.newBuilder()
+ .setCommonHeader(commonHeader)
+ .setActionIdentifiers(ActionIdentifiers.newBuilder()
+ .setBlueprintName("baseconfiguration")
+ .setBlueprintVersion("1.0.0")
+ .setActionName(action).build())
+ .build()
+ }
+
private fun createRemoveInputRequest(id: String): BluePrintRemoveInput {
val commonHeader = CommonHeader
.newBuilder()