2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
19 import io.grpc.ServerBuilder
20 import io.grpc.stub.StreamObserver
21 import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
22 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status
23 import org.onap.ccsdk.cds.controllerblueprints.core.logger
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
28 private val log = logger(MockBluePrintProcessingServer::class)
31 class MockBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
33 override fun process(responseObserver: StreamObserver<ExecutionServiceOutput>): StreamObserver<ExecutionServiceInput> {
35 return object : StreamObserver<ExecutionServiceInput> {
36 override fun onNext(executionServiceInput: ExecutionServiceInput) {
37 log.info("Received requestId(${executionServiceInput.commonHeader.requestId}) " +
38 "subRequestId(${executionServiceInput.commonHeader.subRequestId})")
39 responseObserver.onNext(buildNotification(executionServiceInput))
40 responseObserver.onNext(buildResponse(executionServiceInput))
41 responseObserver.onCompleted()
44 override fun onError(error: Throwable) {
45 log.debug("Fail to process message", error)
46 responseObserver.onError(io.grpc.Status.INTERNAL
47 .withDescription(error.message)
51 override fun onCompleted() {
58 private fun buildNotification(input: ExecutionServiceInput): ExecutionServiceOutput {
59 val status = Status.newBuilder()
60 .setEventType(EventType.EVENT_COMPONENT_NOTIFICATION)
62 return ExecutionServiceOutput.newBuilder()
63 .setCommonHeader(input.commonHeader)
64 .setActionIdentifiers(input.actionIdentifiers)
69 private fun buildResponse(input: ExecutionServiceInput): ExecutionServiceOutput {
71 val status = Status.newBuilder().setCode(200)
72 .setEventType(EventType.EVENT_COMPONENT_EXECUTED)
74 return ExecutionServiceOutput.newBuilder()
75 .setCommonHeader(input.commonHeader)
76 .setActionIdentifiers(input.actionIdentifiers)
83 /** For Integration testing stat this server */
86 val server = ServerBuilder
88 .addService(MockBluePrintProcessingServer())
91 log.info("GRPC Serve started(${server.isShutdown}) on port(${server.port})...")
92 server.awaitTermination()
93 } catch (e: Exception) {