diff options
author | 2019-09-09 16:44:39 -0400 | |
---|---|---|
committer | 2019-09-12 01:22:27 +0000 | |
commit | 338cc251c24e9ae8a0d098098d94a9c2af2a1a07 (patch) | |
tree | b36eb8d182370bd68bbb03751ef3cb9a61305cb0 /ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin | |
parent | a80bb83c9f6fd4c648abfb273d5b2b28d82a38fa (diff) |
Implement GRPC download cab.
Change-Id: I7c872b7e6e20590668c68b92ed221752a9413bd8
Issue-ID: CCSDK-1682
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin')
2 files changed, 54 insertions, 11 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 { |