From b8afed63dea50e0833a820bd15bbeafc1a08412e Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 4 Sep 2019 11:14:39 -0400 Subject: Add draft and publish grpc upload options. Change-Id: Id1476f1cb449c4070a7ef53a918b62d26da26391 Issue-ID: CCSDK-1682 Signed-off-by: Brinda Santh --- .../api/BluePrintManagementGRPCHandler.kt | 51 +++++++++++++++++----- .../selfservice/api/ExecutionServiceHandler.kt | 2 + 2 files changed, 41 insertions(+), 12 deletions(-) (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org') 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) } -- cgit 1.2.3-korg