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.grpc.interceptor
19 import io.grpc.ForwardingServerCall
20 import io.grpc.ForwardingServerCallListener
21 import io.grpc.Metadata
22 import io.grpc.ServerCall
23 import io.grpc.ServerCallHandler
24 import io.grpc.ServerInterceptor
25 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService
26 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
27 import org.onap.ccsdk.cds.controllerblueprints.core.logger
28 import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintDownloadInput
29 import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintRemoveInput
30 import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput
31 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
34 class GrpcServerLoggingInterceptor : ServerInterceptor {
36 val log = logger(GrpcServerLoggingInterceptor::class)
37 val loggingService = GrpcLoggerService()
39 override fun <ReqT : Any, RespT : Any> interceptCall(
40 call: ServerCall<ReqT, RespT>,
41 requestHeaders: Metadata,
42 next: ServerCallHandler<ReqT, RespT>
44 ServerCall.Listener<ReqT> {
46 val forwardingServerCall = object : ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
47 override fun sendHeaders(responseHeaders: Metadata) {
48 loggingService.grpResponding(requestHeaders, responseHeaders)
49 super.sendHeaders(responseHeaders)
54 ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(
55 next.startCall(forwardingServerCall, requestHeaders)
58 override fun onMessage(message: ReqT) {
59 /** Get the requestId, SubRequestId and Originator Id and set in MDS context
60 * If you are using other GRPC services, Implement own Logging Interceptors to get tracing.
63 is ExecutionServiceInput -> {
64 val commonHeader = message.commonHeader
65 ?: throw BlueprintProcessorException("missing common header in request")
66 loggingService.grpcRequesting(call, commonHeader, next)
68 is BlueprintUploadInput -> {
69 val commonHeader = message.commonHeader
70 ?: throw BlueprintProcessorException("missing common header in request")
71 loggingService.grpcRequesting(call, commonHeader, next)
73 is BlueprintDownloadInput -> {
74 val commonHeader = message.commonHeader
75 ?: throw BlueprintProcessorException("missing common header in request")
76 loggingService.grpcRequesting(call, commonHeader, next)
78 is BlueprintRemoveInput -> {
79 val commonHeader = message.commonHeader
80 ?: throw BlueprintProcessorException("missing common header in request")
81 loggingService.grpcRequesting(call, commonHeader, next)
84 loggingService.grpcRequesting(call, requestHeaders, next)
87 super.onMessage(message)
90 override fun onComplete() {
95 override fun onCancel() {