diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-04 11:14:39 -0400 |
---|---|---|
committer | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-04 11:14:39 -0400 |
commit | b8afed63dea50e0833a820bd15bbeafc1a08412e (patch) | |
tree | c734aa01a8e9a28cb58870bdfb6a85afeac511e6 /ms/blueprintsprocessor/modules/inbounds/selfservice-api | |
parent | f58ffbbdac2800a6828d072223883e52714460b6 (diff) |
Add draft and publish grpc upload options.
Change-Id: Id1476f1cb449c4070a7ef53a918b62d26da26391
Issue-ID: CCSDK-1682
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api')
3 files changed, 53 insertions, 19 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt index 451f827b6..0116680cf 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt @@ -24,21 +24,19 @@ import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.currentTimestamp import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.common.api.Status +import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.cds.controllerblueprints.core.reCreateDirs -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.cds.controllerblueprints.management.api.* import org.slf4j.LoggerFactory import org.springframework.security.access.prepost.PreAuthorize import org.springframework.stereotype.Service import java.io.File import java.util.* +// TODO("move to management-api or designer-api module") @Service open class BluePrintManagementGRPCHandler(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, private val blueprintsProcessorCatalogService: BluePrintCatalogService) @@ -53,19 +51,48 @@ open class BluePrintManagementGRPCHandler(private val bluePrintLoadConfiguration log.info("request(${request.commonHeader.requestId})") val uploadId = UUID.randomUUID().toString() + val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, uploadId) + val blueprintWorking = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, uploadId) try { - val cbaFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, uploadId, "cba-zip") + val cbaFile = normalizedFile(blueprintArchive, "cba.zip") saveToDisk(request, cbaFile) - val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(uploadId, cbaFile) - responseObserver.onNext(successStatus("Successfully uploaded CBA($blueprintId)...", request.commonHeader)) + val uploadAction = request.actionIdentifiers?.actionName.emptyTONull() + ?: UploadAction.DRAFT.toString() + + when (uploadAction) { + UploadAction.DRAFT.toString() -> { + val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(uploadId, cbaFile, false) + responseObserver.onNext(successStatus("Successfully uploaded CBA($blueprintId)...", + request.commonHeader)) + } + UploadAction.PUBLISH.toString() -> { + val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(uploadId, cbaFile, true) + responseObserver.onNext(successStatus("Successfully uploaded CBA($blueprintId)...", + request.commonHeader)) + } + UploadAction.VALIDATE.toString() -> { + //TODO("Not Implemented") + responseObserver.onError(failStatus("Not Implemented", + BluePrintProcessorException("Not Implemented"))) + } + UploadAction.ENRICH.toString() -> { + //TODO("Not Implemented") + responseObserver.onError(failStatus("Not Implemented", + BluePrintProcessorException("Not Implemented"))) + } + } responseObserver.onCompleted() } catch (e: Exception) { responseObserver.onError(failStatus("request(${request.commonHeader.requestId}): Failed to upload CBA", e)) } finally { - deleteDir(bluePrintLoadConfiguration.blueprintArchivePath, uploadId) - deleteDir(bluePrintLoadConfiguration.blueprintWorkingPath, uploadId) + // Clean blueprint script cache + val cacheKey = BluePrintFileUtils + .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, uploadId)) + BluePrintCompileCache.cleanClassLoader(cacheKey) + deleteNBDir(blueprintArchive) + deleteNBDir(blueprintWorking) } } } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 9dd04bf95..2f8878034 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -49,6 +49,7 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString()) + //TODO("Remove from self service api and move to designer api module") suspend fun upload(filePart: FilePart): String { val saveId = UUID.randomUUID().toString() val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, saveId) @@ -74,6 +75,7 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL } } + //TODO("Remove from self service api and move to designer api module") suspend fun remove(name: String, version: String) { blueprintsProcessorCatalogService.deleteFromDatabase(name, version) } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt index e084c60cf..ea05e88c0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt @@ -25,13 +25,11 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.messaginglib.MessagingControllerTest import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.messaginglib.ProducerConfiguration +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput -import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk +import org.onap.ccsdk.cds.controllerblueprints.management.api.* import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan @@ -75,7 +73,7 @@ class BluePrintManagementGRPCHandlerTest { fun `test upload blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) val id = "123_upload" - val req = createUploadInputRequest(id) + val req = createUploadInputRequest(id, UploadAction.PUBLISH.toString()) val output = blockingStub.uploadBlueprint(req) assertEquals(200, output.status.code) @@ -87,7 +85,7 @@ class BluePrintManagementGRPCHandlerTest { fun `test delete blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) val id = "123_delete" - val req = createUploadInputRequest(id) + val req = createUploadInputRequest(id, UploadAction.DRAFT.toString()) var output = blockingStub.uploadBlueprint(req) assertEquals(200, output.status.code) @@ -99,7 +97,7 @@ class BluePrintManagementGRPCHandlerTest { assertEquals(200, output.status.code) } - private fun createUploadInputRequest(id: String): BluePrintUploadInput { + private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput { val file = normalizedFile("./src/test/resources/test-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") @@ -110,11 +108,18 @@ class BluePrintManagementGRPCHandlerTest { .setRequestId(id) .setSubRequestId("1234-56").build() + val actionIdentifier = ActionIdentifiers.newBuilder() + .setActionName(action) + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .build() + val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) .build() return BluePrintUploadInput.newBuilder() .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) .setFileChunk(fileChunk) .build() } |