From 71616cc0a6bee9c604b35754778ec5cae7477635 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 25 Nov 2019 17:19:02 -0500 Subject: Upgrade CDS GRPC implementations. Dependent on : https://gerrit.onap.org/r/c/ccsdk/parent/+/98823 Issue-ID: CCSDK-1737 Signed-off-by: Brinda Santh Change-Id: I0b5087f7e98490d7066f389af29424aed40a6520 --- .../grpc/interceptor/GrpcClientLoggingInterceptor.kt | 11 ++++++----- .../grpc/interceptor/GrpcServerLoggingInterceptor.kt | 2 +- .../grpc/service/BasicAuthGrpcClientService.kt | 2 -- .../grpc/service/BluePrintGrpcLibPropertyService.kt | 4 ++-- .../grpc/service/TLSAuthGrpcClientService.kt | 9 ++++++--- .../grpc/service/TokenAuthGrpcClientService.kt | 11 +++++++---- 6 files changed, 22 insertions(+), 17 deletions(-) (limited to 'ms/blueprintsprocessor/modules/commons/grpc-lib/src/main') diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt index 99ac74070..43e56606f 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt @@ -42,12 +42,13 @@ class GrpcClientLoggingInterceptor : ClientInterceptor { .SimpleForwardingClientCall(channel.newCall(method, callOptions)) { override fun start(responseListener: Listener, headers: Metadata) { - val listener = object : ForwardingClientCallListener.SimpleForwardingClientCallListener(responseListener) { - override fun onMessage(message: RespT) { - loggingService.grpcInvoking(headers) - super.onMessage(message) + val listener = + object : ForwardingClientCallListener.SimpleForwardingClientCallListener(responseListener) { + override fun onMessage(message: RespT) { + loggingService.grpcInvoking(headers) + super.onMessage(message) + } } - } super.start(listener, headers) } } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt index ec0761af4..a49b96743 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt @@ -40,7 +40,7 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { requestHeaders: Metadata, next: ServerCallHandler ): - ServerCall.Listener { + ServerCall.Listener { val forwardingServerCall = object : ForwardingServerCall.SimpleForwardingServerCall(call) { override fun sendHeaders(responseHeaders: Metadata) { diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt index e3fd14c1e..f7be8c66d 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service import io.grpc.ManagedChannel import io.grpc.internal.DnsNameResolverProvider -import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties @@ -29,7 +28,6 @@ open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: val managedChannel = NettyChannelBuilder .forAddress(basicAuthGrpcClientProperties.host, basicAuthGrpcClientProperties.port) .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) // .intercept(BasicAuthClientInterceptor(basicAuthGrpcClientProperties)).usePlaintext() .build() return managedChannel diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt index 8a3c5a6a7..79da447a1 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt @@ -87,7 +87,7 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties): - BluePrintGrpcServerService { + BluePrintGrpcServerService { when (grpcServerProperties) { is TLSAuthGrpcServerProperties -> { return TLSAuthGrpcServerService(grpcServerProperties) @@ -151,7 +151,7 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } fun blueprintGrpcClientService(grpcClientProperties: GrpcClientProperties): - BluePrintGrpcClientService { + BluePrintGrpcClientService { return when (grpcClientProperties) { is TokenAuthGrpcClientProperties -> { TokenAuthGrpcClientService(grpcClientProperties) diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt index 68ca3c16b..44df5fbe5 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service import io.grpc.ManagedChannel import io.grpc.internal.DnsNameResolverProvider -import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.GrpcSslContexts import io.grpc.netty.NettyChannelBuilder import io.netty.handler.ssl.SslContext @@ -30,10 +29,14 @@ class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthG BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { + + val target = + if (tlsAuthGrpcClientProperties.port == -1) tlsAuthGrpcClientProperties.host + else "${tlsAuthGrpcClientProperties.host}:${tlsAuthGrpcClientProperties.port}" + return NettyChannelBuilder - .forAddress(tlsAuthGrpcClientProperties.host, tlsAuthGrpcClientProperties.port) + .forTarget(target) .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) .intercept(GrpcClientLoggingInterceptor()) .sslContext(sslContext()) .build() diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt index 371353db2..4c991df1f 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt @@ -25,7 +25,6 @@ import io.grpc.ManagedChannel import io.grpc.Metadata import io.grpc.MethodDescriptor import io.grpc.internal.DnsNameResolverProvider -import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLoggingInterceptor @@ -34,17 +33,21 @@ class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: Toke BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { + val target = + if (tokenAuthGrpcClientProperties.port == -1) tokenAuthGrpcClientProperties.host + else "${tokenAuthGrpcClientProperties.host}:${tokenAuthGrpcClientProperties.port}" + val managedChannel = NettyChannelBuilder - .forAddress(tokenAuthGrpcClientProperties.host, tokenAuthGrpcClientProperties.port) + .forTarget(target) .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) .intercept(GrpcClientLoggingInterceptor()) .intercept(TokenAuthClientInterceptor(tokenAuthGrpcClientProperties)).usePlaintext().build() return managedChannel } } -class TokenAuthClientInterceptor(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : ClientInterceptor { +class TokenAuthClientInterceptor(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : + ClientInterceptor { override fun interceptCall( method: MethodDescriptor, -- cgit 1.2.3-korg