diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-03-26 09:49:13 -0400 |
---|---|---|
committer | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-03-26 09:49:13 -0400 |
commit | 72d22a4339db09824d46746dacbba1e141763dc0 (patch) | |
tree | 7fbfea4b81afca0bc0c95e5d4b810f236f4dea29 /ms/blueprintsprocessor/modules/inbounds/selfservice-api | |
parent | ef6983b670796becfa66c69075c1829e8f9aef4b (diff) |
Migrate ccdsk/apps to ccsdk/cds
Change-Id: I020a2ccec4e691717f888e8bd2afec91a7c4e987
Issue-ID: CCSDK-1178
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api')
19 files changed, 0 insertions, 1335 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml deleted file mode 100755 index 0c6b8e77..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright © 2017-2018 AT&T Intellectual Property. - ~ - ~ Modifications Copyright © 2019 Bell Canada. - ~ Modifications Copyright © 2018 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> - <artifactId>inbounds</artifactId> - <version>0.4.2-SNAPSHOT</version> - </parent> - - <artifactId>selfservice-api</artifactId> - <packaging>jar</packaging> - <name>Blueprints Processor Selfservice API</name> - <description>Blueprints Processor Selfservice API</description> - - <dependencies> - - <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-core</artifactId> - </dependency> - - <dependency> - <groupId>org.onap.ccsdk.apps.components</groupId> - <artifactId>proto-definition</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> - <artifactId>blueprint-core</artifactId> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> - <artifactId>blueprint-validation</artifactId> - </dependency> - <dependency> - <groupId>io.grpc</groupId> - <artifactId>grpc-testing</artifactId> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt deleted file mode 100644 index d689187e..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api - -import io.grpc.StatusException -import io.grpc.stub.StreamObserver -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.currentTimestamp -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.common.api.Status -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementOutput -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.slf4j.LoggerFactory -import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.stereotype.Service -import java.io.File - -@Service -open class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, - private val bluePrintCatalogService: BluePrintCatalogService) - : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { - - private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) - - @PreAuthorize("hasRole('USER')") - override fun uploadBlueprint(request: BluePrintManagementInput, responseObserver: StreamObserver<BluePrintManagementOutput>) { - val blueprintName = request.blueprintName - val blueprintVersion = request.blueprintVersion - val blueprint = "blueprint $blueprintName:$blueprintVersion" - - log.info("request(${request.commonHeader.requestId}): Received upload $blueprint") - - val blueprintArchivedFilePath = "${bluePrintCoreConfiguration.archivePath}/$blueprintName/$blueprintVersion/$blueprintName.zip" - try { - val blueprintArchivedFile = File(blueprintArchivedFilePath) - - saveToDisk(request, blueprintArchivedFile) - val blueprintId = bluePrintCatalogService.saveToDatabase(blueprintArchivedFile) - - File("${bluePrintCoreConfiguration.archivePath}/$blueprintName").deleteRecursively() - - responseObserver.onNext(successStatus("Successfully uploaded $blueprint with id($blueprintId)", request.commonHeader)) - responseObserver.onCompleted() - } catch (e: Exception) { - failStatus("request(${request.commonHeader.requestId}): Failed to upload $blueprint at path $blueprintArchivedFilePath", e) - } - } - - @PreAuthorize("hasRole('USER')") - override fun removeBlueprint(request: BluePrintManagementInput, responseObserver: StreamObserver<BluePrintManagementOutput>) { - val blueprintName = request.blueprintName - val blueprintVersion = request.blueprintVersion - val blueprint = "blueprint $blueprintName:$blueprintVersion" - - log.info("request(${request.commonHeader.requestId}): Received delete $blueprint") - - try { - bluePrintCatalogService.deleteFromDatabase(blueprintName, blueprintVersion) - responseObserver.onNext(successStatus("Successfully deleted $blueprint", request.commonHeader)) - responseObserver.onCompleted() - } catch (e: Exception) { - failStatus("request(${request.commonHeader.requestId}): Failed to delete $blueprint", e) - } - } - - private fun saveToDisk(request: BluePrintManagementInput, blueprintDir: File) { - log.info("request(${request.commonHeader.requestId}): Writing CBA File under :${blueprintDir.absolutePath}") - if (blueprintDir.exists()) { - log.info("request(${request.commonHeader.requestId}): Re-creating blueprint directory(${blueprintDir.absolutePath})") - //FileUtils.deleteDirectory(blueprintDir.parentFile) - blueprintDir.parentFile.deleteRecursively() - } - blueprintDir.parentFile.mkdirs() - //FileUtils.forceMkdir(blueprintDir.parentFile) - blueprintDir.writeBytes(request.fileChunk.chunk.toByteArray()).apply { - log.info("request(${request.commonHeader.requestId}): CBA file(${blueprintDir.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/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt deleted file mode 100644 index ebeda69b..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * 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.apps.blueprintsprocessor.selfservice.api - -import io.grpc.stub.StreamObserver -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toJava -import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput -import org.slf4j.LoggerFactory -import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.stereotype.Service - -@Service -open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, - private val executionServiceHandler: ExecutionServiceHandler) - : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java) - - @PreAuthorize("hasRole('USER')") - override fun process( - responseObserver: StreamObserver<ExecutionServiceOutput>): StreamObserver<ExecutionServiceInput> { - - return object : StreamObserver<ExecutionServiceInput> { - override fun onNext(executionServiceInput: ExecutionServiceInput) { - try { - runBlocking { - executionServiceHandler.process(executionServiceInput.toJava(), responseObserver) - } - } catch (e: Exception) { - onError(e) - } - } - - override fun onError(error: Throwable) { - log.debug("Fail to process message", error) - responseObserver.onError(io.grpc.Status.INTERNAL - .withDescription(error.message) - .asException()) - } - - override fun onCompleted() { - log.info("Completed") - } - } - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt deleted file mode 100644 index 6e729479..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * 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.apps.blueprintsprocessor.selfservice.api - -import io.swagger.annotations.ApiOperation -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType -import org.springframework.http.codec.multipart.FilePart -import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* -import reactor.core.publisher.Mono - -@RestController -@RequestMapping("/api/v1/execution-service") -open class ExecutionServiceController { - - @Autowired - lateinit var executionServiceHandler: ExecutionServiceHandler - - @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun ping(): String = runBlocking { - "Success" - } - - @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) - @ApiOperation(value = "Upload CBA", notes = "Takes a File and load it in the runtime database") - @ResponseBody - @PreAuthorize("hasRole('USER')") - fun upload(@RequestPart("file") parts: Mono<FilePart>): Mono<String> { - return parts - .filter { it is FilePart } - .ofType(FilePart::class.java) - .flatMap(executionServiceHandler::upload) - } - - @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Resolve Resource Mappings", - notes = "Takes the blueprint information and process as per the payload") - @ResponseBody - @PreAuthorize("hasRole('USER')") - fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput = runBlocking { - if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) { - throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.") - } - executionServiceHandler.doProcess(executionServiceInput) - } -} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt deleted file mode 100644 index 05a569cb..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * 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.apps.blueprintsprocessor.selfservice.api - -import com.fasterxml.jackson.databind.node.JsonNodeFactory -import io.grpc.stub.StreamObserver -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toProto -import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.slf4j.LoggerFactory -import org.springframework.http.codec.multipart.FilePart -import org.springframework.stereotype.Service -import reactor.core.publisher.Mono -import java.util.stream.Collectors - -@Service -class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, - private val bluePrintCatalogService: BluePrintCatalogService, - private val bluePrintWorkflowExecutionService - : BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>) { - - private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString()) - - fun upload(filePart: FilePart): Mono<String> { - try { - val archivedPath = BluePrintFileUtils.getCbaStorageDirectory(bluePrintCoreConfiguration.archivePath) - val cbaPath = saveCBAFile(filePart, archivedPath) - bluePrintCatalogService.saveToDatabase(cbaPath.toFile()).let { - return Mono.just("{\"status\": \"Successfully uploaded blueprint with id($it)\"}") - } - } catch (e: Exception) { - return Mono.error<String>(BluePrintException("Error uploading the CBA file.", e)) - } - } - - suspend fun process(executionServiceInput: ExecutionServiceInput, - responseObserver: StreamObserver<org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput>) { - when { - executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> { - GlobalScope.launch(Dispatchers.Default) { - val executionServiceOutput = doProcess(executionServiceInput) - responseObserver.onNext(executionServiceOutput.toProto()) - responseObserver.onCompleted() - } - responseObserver.onNext(response(executionServiceInput).toProto()) - } - executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> { - val executionServiceOutput = doProcess(executionServiceInput) - responseObserver.onNext(executionServiceOutput.toProto()) - responseObserver.onCompleted() - } - else -> responseObserver.onNext(response(executionServiceInput, - "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", - true).toProto()); - } - } - - suspend fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { - val requestId = executionServiceInput.commonHeader.requestId - log.info("processing request id $requestId") - - val actionIdentifiers = executionServiceInput.actionIdentifiers - - val blueprintName = actionIdentifiers.blueprintName - val blueprintVersion = actionIdentifiers.blueprintVersion - - val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion) - log.info("blueprint base path $basePath") - - val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) - - val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, - executionServiceInput, hashMapOf()) - - val errors = blueprintRuntimeService.getBluePrintError().errors - if (errors.isNotEmpty()) { - val errorMessage = errors.stream().map { it.toString() }.collect(Collectors.joining(", ")) - setErrorStatus(errorMessage, output.status) - } - - return output - } - - private fun setErrorStatus(errorMessage: String, status: Status) { - status.errorMessage = errorMessage - status.eventType = EventType.EVENT_COMPONENT_FAILURE.name - status.code = 500 - status.message = BluePrintConstants.STATUS_FAILURE - } - - private fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "", - failure: Boolean = false): ExecutionServiceOutput { - val executionServiceOutput = ExecutionServiceOutput() - executionServiceOutput.commonHeader = executionServiceInput.commonHeader - executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers - executionServiceOutput.payload = JsonNodeFactory.instance.objectNode() - - val status = Status() - if (failure) { - setErrorStatus(errorMessage, status) - } else { - status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name - status.code = 200 - status.message = BluePrintConstants.STATUS_PROCESSING - } - - executionServiceOutput.status = status - - return executionServiceOutput - } - -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt deleted file mode 100644 index c344ca00..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api.utils - -import com.fasterxml.jackson.databind.node.ObjectNode -import com.google.common.base.Strings -import com.google.protobuf.Struct -import com.google.protobuf.util.JsonFormat -import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType -import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag -import org.onap.ccsdk.apps.controllerblueprints.common.api.Status -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput -import java.text.SimpleDateFormat -import java.util.* - -private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - -// ACTION IDENTIFIER - -fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers.toProto(): ActionIdentifiers { - val actionIdentifier = ActionIdentifiers.newBuilder() - actionIdentifier.actionName = this.actionName - actionIdentifier.blueprintName = this.blueprintName - actionIdentifier.blueprintVersion = this.blueprintVersion - actionIdentifier.mode = this.mode - return actionIdentifier.build() -} - -fun ActionIdentifiers.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers { - val actionIdentifier = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers() - actionIdentifier.actionName = this.actionName - actionIdentifier.blueprintName = this.blueprintName - actionIdentifier.blueprintVersion = this.blueprintVersion - actionIdentifier.mode = this.mode - return actionIdentifier -} - -// COMMON HEADER - -fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader.toProto(): CommonHeader { - val commonHeader = CommonHeader.newBuilder() - commonHeader.originatorId = this.originatorId - commonHeader.requestId = this.requestId - commonHeader.subRequestId = this.subRequestId - commonHeader.timestamp = this.timestamp.toString() - commonHeader.flag = this.flags?.toProto() - return commonHeader.build() -} - -fun CommonHeader.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader() - commonHeader.originatorId = this.originatorId - commonHeader.requestId = this.requestId - commonHeader.subRequestId = this.subRequestId - commonHeader.timestamp = if (!Strings.isNullOrEmpty(this.timestamp)) { - formatter.parse(this.timestamp) - } else { - Date() - } - commonHeader.flags = this.flag?.toJava() - return commonHeader -} - -// FLAG - -fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags.toProto(): Flag { - val flag = Flag.newBuilder() - flag.isForce = this.isForce - flag.ttl = this.ttl - return flag.build() -} - -fun Flag.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags { - val flag = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags() - flag.isForce = this.isForce - flag.ttl = this.ttl - return flag -} - -// STATUS - -fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status.toProto(): Status { - val status = Status.newBuilder() - status.code = this.code - status.errorMessage = this.errorMessage ?: "" - status.message = this.message - status.timestamp = this.timestamp.toString() - status.eventType = EventType.valueOf(this.eventType) - return status.build() -} - -// EXECUTION INPUT - -fun ExecutionServiceInput.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput { - val executionServiceInput = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput() - executionServiceInput.actionIdentifiers = this.actionIdentifiers.toJava() - executionServiceInput.commonHeader = this.commonHeader.toJava() - executionServiceInput.payload = JacksonUtils.jsonNode(JsonFormat.printer().print(this.payload)) as ObjectNode - return executionServiceInput -} - -// EXECUTION OUPUT - -fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(): ExecutionServiceOutput { - val executionServiceOuput = ExecutionServiceOutput.newBuilder() - executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto() - executionServiceOuput.commonHeader = this.commonHeader.toProto() - executionServiceOuput.status = this.status.toProto() - val struct = Struct.newBuilder() - JsonFormat.parser().merge(JacksonUtils.getJson(this.payload), struct) - executionServiceOuput.payload = struct.build() - return executionServiceOuput.build() -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt deleted file mode 100644 index 6d22fdab..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api.utils - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.springframework.http.codec.multipart.FilePart -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.* - - -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 { - - val fileName = StringUtils.cleanPath(filePart.filename()) - - if (StringUtils.getFilenameExtension(fileName) != "zip") { - throw BluePrintException("Invalid file extension required ZIP") - } - - val changedFileName = UUID.randomUUID().toString() + ".zip" - - val targetLocation = targetDirectory.resolve(changedFileName) - - val file = File(targetLocation.toString()) - if (file.exists()) { - file.delete() - } - file.createNewFile() - - filePart.transferTo(file) - - return targetLocation -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt deleted file mode 100644 index 100bd320..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2018 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.apps.blueprintsprocessor.selfservice.api.validation - -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintDesignTimeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator -import org.springframework.stereotype.Service - -@Service -open class BluePrintRuntimeValidatorService(bluePrintTypeValidatorService: BluePrintTypeValidatorService, - resourceDefinitionValidator: ResourceDefinitionValidator) - : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator) diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt deleted file mode 100644 index 264e2aea..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api - -import com.google.protobuf.ByteString -import io.grpc.testing.GrpcServerRule -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import java.io.File -import kotlin.test.AfterTest -import kotlin.test.BeforeTest -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration -@DirtiesContext -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class BluePrintManagementGRPCHandlerTest { - - @get:Rule - val grpcServerRule = GrpcServerRule().directExecutor() - - @Autowired - lateinit var bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler - - @BeforeTest - fun init() { - // Create a server, add service, start, and register for automatic graceful shutdown. - grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler) - } - - @AfterTest - fun cleanDir() { - //TODO It's giving fluctuating results, need to look for another way to cleanup - // works sometimes otherwise results IO Exception - // Most probably bufferReader stream is not getting closed when cleanDir is getting invoked - File("./target/blueprints").deleteRecursively() - } - - @Test - fun `test upload blueprint`() { - val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) - val id = "123_upload" - val req = createInputRequest(id) - val output = blockingStub.uploadBlueprint(req) - - assertEquals(200, output.status.code) - assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) - assertEquals(id, output.commonHeader.requestId) - } - - @Test - fun `test delete blueprint`() { - val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) - val id = "123_delete" - val req = createInputRequest(id) - - var output = blockingStub.uploadBlueprint(req) - assertEquals(200, output.status.code) - assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) - assertEquals(id, output.commonHeader.requestId) - - output = blockingStub.removeBlueprint(req) - assertEquals(200, output.status.code) - } - - private fun createInputRequest(id: String): BluePrintManagementInput { - val file = File("./src/test/resources/test-cba.zip") - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - - val commonHeader = CommonHeader - .newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(id) - .setSubRequestId("1234-56").build() - - val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) - .build() - - return BluePrintManagementInput.newBuilder() - .setCommonHeader(commonHeader) - .setBlueprintName("sample") - .setBlueprintVersion("1.0.0") - .setFileChunk(fileChunk) - .build() - } -} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt deleted file mode 100644 index 01984b21..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api - - -import com.google.protobuf.util.JsonFormat -import io.grpc.stub.StreamObserver -import io.grpc.testing.GrpcServerRule -import org.junit.Assert -import org.junit.Ignore -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.BeforeTest - -@Ignore -@RunWith(SpringRunner::class) -@DirtiesContext -@EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class BluePrintProcessingGRPCHandlerTest { - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) - - @get:Rule - val grpcServerRule = GrpcServerRule().directExecutor() - - @Autowired - lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler - - lateinit var requestObs: StreamObserver<ExecutionServiceInput> - - @BeforeTest - fun init() { - grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler) - - val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel) - - requestObs = blockingStub.process(object : StreamObserver<ExecutionServiceOutput> { - override fun onNext(executionServiceOuput: ExecutionServiceOutput) { - log.debug("onNext {}", executionServiceOuput) - if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { - Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage) - } - } - - override fun onError(error: Throwable) { - log.debug("Fail to process message", error) - Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message) - } - - override fun onCompleted() { - log.info("Done") - } - }) - } - - @Test - fun testSelfServiceGRPCHandler() { - val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("1234") - .setSubRequestId("1234-56").build() - - val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json") - val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder - JsonFormat.parser().merge(jsonContent, payloadBuilder) - - val input = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setPayload(payloadBuilder.build()) - .build() - - requestObs.onNext(input) - - val commonHeader2 = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("2345") - .setSubRequestId("1234-56").build() - - val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build() - - val input2 = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader2) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() - - requestObs.onNext(input2) - - requestObs.onCompleted() - } - -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt deleted file mode 100644 index b730472e..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.security.SecurityProperties -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.core.io.ByteArrayResource -import org.springframework.http.client.MultipartBodyBuilder -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.reactive.server.WebTestClient -import org.springframework.web.reactive.function.BodyInserters -import java.nio.file.Files -import java.nio.file.Paths -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@WebFluxTest -@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class ExecutionServiceHandlerTest { - - @Autowired - lateinit var blueprintCatalog: BluePrintCatalogService - @Autowired - lateinit var webTestClient: WebTestClient - - - @Test - fun `test rest upload blueprint`() { - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - - val body = MultipartBodyBuilder().apply { - part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) { - override fun getFilename(): String { - return "test-cba.zip" - } - }) - }.build() - - webTestClient - .post() - .uri("/api/v1/execution-service/upload") - .body(BodyInserters.fromMultipartData(body)) - .exchange() - .expectStatus().isOk - } - - @Test - fun `test rest process`() { - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - blueprintCatalog.saveToDatabase(file) - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!! - webTestClient - .post() - .uri("/api/v1/execution-service/process") - .body(BodyInserters.fromObject(executionServiceInput)) - .exchange() - .expectStatus().isOk - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt deleted file mode 100644 index 19c624bc..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * 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.apps.blueprintsprocessor.selfservice.api.mock - -import io.mockk.mockk -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive -import org.slf4j.LoggerFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -@Configuration -open class MockComponentConfiguration { - - @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"]) - open fun createComponentFunction(): AbstractComponentFunction { - return MockComponentFunction() - } -} - -class MockComponentFunction : AbstractComponentFunction() { - - private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) - - override fun process(executionRequest: ExecutionServiceInput) { - log.info("Processing component : $operationInputs") - - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - "assignment-params", "params".asJsonPrimitive()) - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - log.info("Recovering component..") - } -} - -open class MockResourceSource { - @Bean(name = [ - "rr-processor-source-input", - "rr-processor-source-default", - "rr-processor-source-primary-db", - "rr-processor-source-rest"]) - open fun sourceInstance(): ResourceAssignmentProcessor { - return mockk<ResourceAssignmentProcessor>() - } - -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt deleted file mode 100644 index 770e4a9b..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt +++ /dev/null @@ -1,132 +0,0 @@ -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils - -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags -import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType -import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag -import org.springframework.test.context.junit4.SpringRunner -import java.text.SimpleDateFormat - -@RunWith(SpringRunner::class) -class BluePrintMappingsTest { - - val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - val dateString = "2019-01-16T18:25:43.511Z" - val dateForTest = formatter.parse(dateString) - - val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() - - fun createFlag(): Flags { - val flag = Flags() - flag.isForce = false - flag.ttl = 1 - return flag - } - - @Test - fun flagToJavaTest() { - val flag2 = flag.toJava() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - @Test - fun flagToProtoTest() { - val flag = createFlag() - val flag2 = flag.toProto() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - fun createStatus(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status { - val status = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status() - status.code = 400 - status.errorMessage = "Concurrent modification exception" - status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name - status.message = "Error uploading data" - status.timestamp = dateForTest - return status - } - - @Test - fun statusToProtoTest() { - val status = createStatus() - val status2 = status.toProto() - - Assert.assertEquals(status.code, status2.code) - Assert.assertEquals(status.errorMessage, status2.errorMessage) - Assert.assertEquals(status.eventType, status2.eventType.name) - Assert.assertEquals(status.message, status2.message) - Assert.assertEquals(status.timestamp.toString(), status2.timestamp) - } - - @Test - fun commonHeaderToJavaTest() { - val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() - - val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build() - val commonHeader2 = commonHeader.toJava() - - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) - } - - fun createCommonHeader(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader() - commonHeader.flags = createFlag() - commonHeader.originatorId = "1234" - commonHeader.requestId = "2345" - commonHeader.subRequestId = "0123" - commonHeader.timestamp = dateForTest - return commonHeader - } - - @Test - fun commonHeaderToProtoTest() { - val commonHeader = createCommonHeader() - val commonHeader2 = commonHeader.toProto() - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp) - } - - @Test - fun actionIdentifierToJavaTest() { - val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build() - val actionIdentifiers2 = actionIdentifiers.toJava() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } - - fun createActionIdentifier(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers { - val ac = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers() - ac.mode = "mode" - ac.blueprintVersion = "version" - ac.blueprintName = "name" - ac.actionName = "action" - return ac - } - - @Test - fun actionIdentifierToProtoTest() { - val actionIdentifiers = createActionIdentifier() - val actionIdentifiers2 = actionIdentifiers.toProto() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt deleted file mode 100644 index 1cafead7..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.apps.blueprintsprocessor.selfservice.api.validation - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockResourceSource -import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintValidationConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class, - BluePrintValidationConfiguration::class, MockResourceSource::class]) -class BluePrintRuntimeValidatorServiceTest { - - @Autowired - lateinit var bluePrintRuntimeValidatorService: BluePrintRuntimeValidatorService - - @Test - fun testBlueprintRuntimeValidation() { - val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService") - - bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath) - - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties deleted file mode 100644 index 6d8b62ff..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright © 2017-2018 AT&T Intellectual Property. -# -# Modifications Copyright © 2019 IBM, Bell Canada. -# -# 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. -# -blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 -blueprintsprocessor.db.primary.username=sa -blueprintsprocessor.db.primary.password= -blueprintsprocessor.db.primary.driverClassName=org.h2.Driver -blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop -blueprintsprocessor.db.primary.hibernateDDLAuto=update -blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy -blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect -# Controller Blueprints Core Configuration -blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy -blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive - -# Python executor -blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints -blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json deleted file mode 100644 index 47ace853..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "commonHeader": { - "originatorId": "System", - "requestId": "1234", - "subRequestId": "1234-12234" - }, - "actionIdentifiers": { - "blueprintName": "baseconfiguration", - "blueprintVersion": "1.0.0", - "actionName": "activate", - "mode": "sync" - }, - "payload": { - "activate-request": { - "activate-properties": { - "request-id": "1234", - "action-name": "activate", - "scope-type": "vnf-type", - "hostname": "localhost" - } - } - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json deleted file mode 100644 index 07046aa3..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "activate-request": { - "activate-properties": { - "request-id": "1234", - "action-name": "activate", - "scope-type": "vnf-type", - "hostname": "localhost" - } - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml deleted file mode 100644 index a816a06c..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml +++ /dev/null @@ -1,35 +0,0 @@ -<!--
- ~ Copyright © 2017-2018 AT&T Intellectual Property.
- ~
- ~ 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.
- -->
-
-<configuration>
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <!-- encoders are assigned the type
- ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
- </encoder>
- </appender>
-
-
- <logger name="org.springframework" level="warn"/>
- <logger name="org.hibernate" level="info"/>
- <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
-
- <root level="warn">
- <appender-ref ref="STDOUT"/>
- </root>
-
-</configuration>
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip Binary files differdeleted file mode 100644 index 90748240..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip +++ /dev/null |