aboutsummaryrefslogtreecommitdiffstats
path: root/releases/1.7.10.yaml
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2021-02-02 10:20:57 +0000
committerGerrit Code Review <gerrit@onap.org>2021-02-02 10:20:57 +0000
commit7c126ee5ce8f0eeaee409da58be9be272ec005e1 (patch)
tree3aed9df57685878cbf27ee6bed44063836e5ca85 /releases/1.7.10.yaml
parentbe3f1c8d747ab7dad3d6c76dc4c9034e83b84635 (diff)
parent8129d57ff086549a88442802514bb2930754b134 (diff)
Merge "updated line of business query to use nodes only"
Diffstat (limited to 'releases/1.7.10.yaml')
0 files changed, 0 insertions, 0 deletions
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/*
 * Copyright © 2018-2019 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.
 */

package org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor

import io.grpc.*
import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.logger
import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintDownloadInput
import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput
import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
import org.slf4j.MDC

class GrpcServerLoggingInterceptor : ServerInterceptor {
    val log = logger(GrpcServerLoggingInterceptor::class)
    val loggingService = GrpcLoggerService()

    override fun <ReqT : Any, RespT : Any> interceptCall(call: ServerCall<ReqT, RespT>,
                                                         requestHeaders: Metadata, next: ServerCallHandler<ReqT, RespT>)
            : ServerCall.Listener<ReqT> {

        val forwardingServerCall = object : ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
            override fun sendHeaders(responseHeaders: Metadata) {
                loggingService.grpResponding(requestHeaders, responseHeaders)
                super.sendHeaders(responseHeaders)
            }
        }

        return object
            : ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(
                next.startCall(forwardingServerCall, requestHeaders)) {

            override fun onMessage(message: ReqT) {
                /** Get the requestId, SubRequestId and Originator Id and set in MDS context
                 *  If you are using other GRPC services, Implement own Logging Interceptors to get tracing.
                 * */
                when (message) {
                    is ExecutionServiceInput -> {
                        val commonHeader = message.commonHeader
                                ?: throw BluePrintProcessorException("missing common header in request")
                        loggingService.grpcRequesting(call, commonHeader, next)
                    }
                    is BluePrintUploadInput -> {
                        val commonHeader = message.commonHeader
                                ?: throw BluePrintProcessorException("missing common header in request")
                        loggingService.grpcRequesting(call, commonHeader, next)
                    }
                    is BluePrintDownloadInput -> {
                        val commonHeader = message.commonHeader
                                ?: throw BluePrintProcessorException("missing common header in request")
                        loggingService.grpcRequesting(call, commonHeader, next)
                    }
                    is BluePrintRemoveInput -> {
                        val commonHeader = message.commonHeader
                                ?: throw BluePrintProcessorException("missing common header in request")
                        loggingService.grpcRequesting(call, commonHeader, next)
                    }
                    else -> {
                        loggingService.grpcRequesting(call, requestHeaders, next)
                    }
                }
                super.onMessage(message)
            }

            override fun onComplete() {
                MDC.clear()
                super.onComplete()
            }

            override fun onCancel() {
                MDC.clear()
                super.onCancel()
            }

        }
    }
}