2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
20 import io.grpc.stub.StreamObserver
21 import kotlinx.coroutines.runBlocking
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
23 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.toJava
24 import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
25 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
26 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput
27 import org.slf4j.LoggerFactory
28 import org.springframework.security.access.prepost.PreAuthorize
29 import org.springframework.stereotype.Service
32 open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration,
33 private val executionServiceHandler: ExecutionServiceHandler)
34 : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
35 private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java)
37 @PreAuthorize("hasRole('USER')")
39 responseObserver: StreamObserver<ExecutionServiceOutput>): StreamObserver<ExecutionServiceInput> {
41 return object : StreamObserver<ExecutionServiceInput> {
42 override fun onNext(executionServiceInput: ExecutionServiceInput) {
45 executionServiceHandler.process(executionServiceInput.toJava(), responseObserver)
47 } catch (e: Exception) {
52 override fun onError(error: Throwable) {
53 log.debug("Fail to process message", error)
54 responseObserver.onError(io.grpc.Status.INTERNAL
55 .withDescription(error.message)
59 override fun onCompleted() {