diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-05 16:13:28 -0400 |
---|---|---|
committer | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-05 16:13:28 -0400 |
commit | f930d9ee670a6dce8977dcdb18643e48c7af33fd (patch) | |
tree | 220daa24cb41370691fe3b9143d7f9a8491364c3 /ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org | |
parent | a2d60124bd44c767c42f4aa4ac8a7edafbfa3e39 (diff) |
Move GRPC management api to designer api.
Change-Id: I58ee303d361cf4f1996c966c094ec66886587b52
Issue-ID: CCSDK-1682
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org')
4 files changed, 4 insertions, 237 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 deleted file mode 100644 index 0116680cf..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * Modifications Copyright © 2019 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api - -import io.grpc.StatusException -import io.grpc.stub.StreamObserver -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.interfaces.BluePrintCatalogService -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) - : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { - - private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) - - @PreAuthorize("hasRole('USER')") - override fun uploadBlueprint(request: BluePrintUploadInput, responseObserver: - StreamObserver<BluePrintManagementOutput>) { - runBlocking { - - 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(blueprintArchive, "cba.zip") - - saveToDisk(request, cbaFile) - - 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 { - // Clean blueprint script cache - val cacheKey = BluePrintFileUtils - .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, uploadId)) - BluePrintCompileCache.cleanClassLoader(cacheKey) - deleteNBDir(blueprintArchive) - deleteNBDir(blueprintWorking) - } - } - } - - @PreAuthorize("hasRole('USER')") - override fun removeBlueprint(request: BluePrintRemoveInput, responseObserver: - StreamObserver<BluePrintManagementOutput>) { - - runBlocking { - val blueprintName = request.blueprintName - val blueprintVersion = request.blueprintVersion - val blueprint = "blueprint $blueprintName:$blueprintVersion" - - log.info("request(${request.commonHeader.requestId}): Received delete $blueprint") - - - try { - blueprintsProcessorCatalogService.deleteFromDatabase(blueprintName, blueprintVersion) - responseObserver.onNext(successStatus("Successfully deleted $blueprint", request.commonHeader)) - responseObserver.onCompleted() - } catch (e: Exception) { - responseObserver.onError(failStatus("request(${request.commonHeader.requestId}): Failed to delete $blueprint", e)) - } - } - } - - private fun saveToDisk(request: BluePrintUploadInput, cbaFile: File) { - log.info("request(${request.commonHeader.requestId}): Writing CBA File under :${cbaFile.absolutePath}") - - // Recreate Folder - cbaFile.parentFile.reCreateDirs() - - // Write the File - cbaFile.writeBytes(request.fileChunk.chunk.toByteArray()).apply { - log.info("request(${request.commonHeader.requestId}): CBA file(${cbaFile.absolutePath} written successfully") - } - - } - - private fun successStatus(message: String, header: CommonHeader): BluePrintManagementOutput = - BluePrintManagementOutput.newBuilder() - .setCommonHeader(header) - .setStatus(Status.newBuilder() - .setTimestamp(currentTimestamp()) - .setMessage(message) - .setCode(200) - .build()) - .build() - - private fun failStatus(message: String, e: Exception): StatusException { - log.error(message, e) - return io.grpc.Status.INTERNAL - .withDescription(message) - .withCause(e) - .asException() - } -} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index d48f0c7e4..4441d2b4b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -27,11 +27,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity -import org.springframework.http.codec.multipart.FilePart import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* @@ -53,30 +51,6 @@ open class ExecutionServiceController { "Success".asJsonPrimitive() } - @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) - @ResponseBody - @PreAuthorize("hasRole('USER')") - @ApiOperation(value = "Upload a CBA", - notes = "Upload the CBA package. This will also run validation on the CBA.", - produces = MediaType.APPLICATION_JSON_VALUE) - fun upload(@ApiParam(value = "The ZIP file containing the overall CBA package.", required = true) - @RequestPart("file") filePart: FilePart): JsonNode = runBlocking { - val uploadId = executionServiceHandler.upload(filePart) - """{"upload-id" : "$uploadId"}""".asJsonType() - } - - @DeleteMapping("/name/{name}/version/{version}") - @ApiOperation(value = "Delete a CBA", - notes = "Delete the CBA package identified by its name and version.", - produces = MediaType.APPLICATION_JSON_VALUE) - @PreAuthorize("hasRole('USER')") - fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true) - @PathVariable(value = "name") name: String, - @ApiParam(value = "Version of the CBA.", required = true) - @PathVariable(value = "version") version: String) = runBlocking { - executionServiceHandler.remove(name, version) - } - @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation(value = "Execute a CBA workflow (action)", notes = "Execute the appropriate CBA's action based on the ExecutionServiceInput object passed as input.", 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 2f8878034..20af589a1 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 @@ -21,24 +21,16 @@ import io.grpc.stub.StreamObserver import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import kotlinx.coroutines.reactive.awaitSingle import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.* import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.toProto import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.slf4j.LoggerFactory -import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service -import java.io.File -import java.io.IOException -import java.util.* import java.util.stream.Collectors @Service @@ -49,37 +41,6 @@ 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) - val blueprintWorking = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId) - try { - - val compressedFile = normalizedFile(blueprintArchive, "cba.zip") - compressedFile.parentFile.reCreateNBDirs() - // Copy the File Part to Local File - copyFromFilePart(filePart, compressedFile) - // Save the Copied file to Database - return blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, true) - } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Upload CBA: ${e.message}", e) - } finally { - // Clean blueprint script cache - val cacheKey = BluePrintFileUtils - .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath,saveId)) - BluePrintCompileCache.cleanClassLoader(cacheKey) - deleteNBDir(blueprintArchive) - deleteNBDir(blueprintWorking) - } - } - - //TODO("Remove from self service api and move to designer api module") - suspend fun remove(name: String, version: String) { - blueprintsProcessorCatalogService.deleteFromDatabase(name, version) - } - suspend fun process(executionServiceInput: ExecutionServiceInput, responseObserver: StreamObserver<org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput>) { when { @@ -97,8 +58,8 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL responseObserver.onCompleted() } else -> responseObserver.onNext(response(executionServiceInput, - "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", - true).toProto()); + "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", + true).toProto()); } } @@ -115,7 +76,7 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, - executionServiceInput, hashMapOf()) + executionServiceInput, hashMapOf()) val errors = blueprintRuntimeService.getBluePrintError().errors if (errors.isNotEmpty()) { @@ -129,12 +90,6 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL } } - private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { - return filePart.transferTo(targetFile) - .thenReturn(targetFile) - .awaitSingle() - } - private fun setErrorStatus(errorMessage: String, status: Status) { status.errorMessage = errorMessage status.eventType = EventType.EVENT_COMPONENT_FAILURE.name diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt index 2cf1c1dd0..16fe36cfe 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt @@ -22,20 +22,10 @@ import org.springframework.util.StringUtils import java.io.File import java.io.IOException import java.nio.file.Path -import java.time.LocalDateTime -import java.time.ZoneId -import java.time.format.DateTimeFormatter import java.util.* const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500 -fun currentTimestamp(): String { - val now = LocalDateTime.now(ZoneId.systemDefault()) - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - return formatter.format(now) -} - - @Throws(BluePrintException::class, IOException::class) fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path { |