From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: Formatting Code base with ktlint No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../grpc/BluePrintGrpcExtensions.kt | 2 +- .../grpc/BluePrintGrpcLibConfiguration.kt | 4 +- .../grpc/BluePrintGrpcLibData.kt | 4 +- .../interceptor/GrpcClientLoggingInterceptor.kt | 20 ++-- .../interceptor/GrpcServerLoggingInterceptor.kt | 34 +++--- .../grpc/service/BasicAuthGrpcClientService.kt | 17 ++- .../service/BluePrintGrpcLibPropertyService.kt | 27 +++-- .../grpc/service/BluePrintGrpcService.kt | 2 +- .../grpc/service/GrpcLoggerService.kt | 29 ++++-- .../grpc/service/TLSAuthGrpcClientService.kt | 29 +++--- .../grpc/service/TLSAuthGrpcServerService.kt | 18 ++-- .../grpc/service/TokenAuthGrpcClientService.kt | 30 ++++-- .../service/BluePrintGrpcLibPropertyServiceTest.kt | 114 ++++++++++++--------- .../grpc/service/BluePrintGrpcServerTest.kt | 39 +++---- .../service/MockTLSBluePrintProcessingServer.kt | 35 ++++--- 15 files changed, 234 insertions(+), 170 deletions(-) (limited to 'ms/blueprintsprocessor/modules/commons/grpc-lib') diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt index 55cf0941d..97b462a3c 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt @@ -24,4 +24,4 @@ fun Metadata.getStringKey(key: String): String? { fun Metadata.putStringKeyValue(key: String, value: String) { this.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value) -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt index c37c6263a..a3823c6ac 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt @@ -32,7 +32,7 @@ open class BluePrintGrpcLibConfiguration * Exposed Dependency Service by this GRPC Lib Module */ fun BluePrintDependencyService.grpcLibPropertyService(): BluePrintGrpcLibPropertyService = - instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) + instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) fun BluePrintDependencyService.grpcClientService(selector: String): BluePrintGrpcClientService { return grpcLibPropertyService().blueprintGrpcClientService(selector) @@ -51,4 +51,4 @@ class GRPCLibConstants { const val TYPE_BASIC_AUTH = "basic-auth" const val TYPE_TLS_AUTH = "tls-auth" } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt index 47d16fbc7..f94d918a2 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc /** GRPC Server Properties */ open class GrpcServerProperties { + lateinit var type: String var port: Int = -1 } @@ -36,6 +37,7 @@ open class TLSAuthGrpcServerProperties : GrpcServerProperties() { /** GRPC Client Properties */ open class GrpcClientProperties { + lateinit var type: String lateinit var host: String var port: Int = -1 @@ -55,4 +57,4 @@ open class TLSAuthGrpcClientProperties : GrpcClientProperties() { open class BasicAuthGrpcClientProperties : GrpcClientProperties() { lateinit var username: String lateinit var password: String -} \ No newline at end of file +} 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 f3b14b59f..99ac74070 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 @@ -16,18 +16,27 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor -import io.grpc.* +import io.grpc.CallOptions +import io.grpc.Channel +import io.grpc.ClientCall +import io.grpc.ClientInterceptor +import io.grpc.ForwardingClientCall +import io.grpc.ForwardingClientCallListener +import io.grpc.Metadata +import io.grpc.MethodDescriptor import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService import org.onap.ccsdk.cds.controllerblueprints.core.logger - class GrpcClientLoggingInterceptor : ClientInterceptor { val log = logger(GrpcClientLoggingInterceptor::class) val loggingService = GrpcLoggerService() - override fun interceptCall(method: MethodDescriptor, - callOptions: CallOptions, channel: Channel): ClientCall { + override fun interceptCall( + method: MethodDescriptor, + callOptions: CallOptions, + channel: Channel + ): ClientCall { return object : ForwardingClientCall .SimpleForwardingClientCall(channel.newCall(method, callOptions)) { @@ -42,6 +51,5 @@ class GrpcClientLoggingInterceptor : ClientInterceptor { super.start(listener, headers) } } - } -} \ No newline at end of file +} 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 e21d5d3ce..ec0761af4 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 @@ -16,7 +16,12 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor -import io.grpc.* +import io.grpc.ForwardingServerCall +import io.grpc.ForwardingServerCallListener +import io.grpc.Metadata +import io.grpc.ServerCall +import io.grpc.ServerCallHandler +import io.grpc.ServerInterceptor 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 @@ -30,9 +35,12 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { val log = logger(GrpcServerLoggingInterceptor::class) val loggingService = GrpcLoggerService() - override fun interceptCall(call: ServerCall, - requestHeaders: Metadata, next: ServerCallHandler) - : ServerCall.Listener { + override fun interceptCall( + call: ServerCall, + requestHeaders: Metadata, + next: ServerCallHandler + ): + ServerCall.Listener { val forwardingServerCall = object : ForwardingServerCall.SimpleForwardingServerCall(call) { override fun sendHeaders(responseHeaders: Metadata) { @@ -41,9 +49,10 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { } } - return object - : ForwardingServerCallListener.SimpleForwardingServerCallListener( - next.startCall(forwardingServerCall, requestHeaders)) { + return object : + ForwardingServerCallListener.SimpleForwardingServerCallListener( + next.startCall(forwardingServerCall, requestHeaders) + ) { override fun onMessage(message: ReqT) { /** Get the requestId, SubRequestId and Originator Id and set in MDS context @@ -52,22 +61,22 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { when (message) { is ExecutionServiceInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: 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") + ?: 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") + ?: 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") + ?: throw BluePrintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } else -> { @@ -86,7 +95,6 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { MDC.clear() super.onCancel() } - } } -} \ No newline at end of file +} 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 a175d8b3a..e3fd14c1e 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 @@ -22,19 +22,16 @@ import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties - -open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: BasicAuthGrpcClientProperties) - : BluePrintGrpcClientService { +open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: BasicAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { val managedChannel = NettyChannelBuilder - .forAddress(basicAuthGrpcClientProperties.host, basicAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - // .intercept(BasicAuthClientInterceptor(basicAuthGrpcClientProperties)).usePlaintext() - .build() + .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 02d5cc695..8a3c5a6a7 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 @@ -19,7 +19,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.* +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcServerProperties import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -39,7 +46,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return blueprintGrpcServerService(grpcServerProperties) } - /** GRPC Server Lib Property Service */ fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties { return when (val type = jsonNode.get("type").textValue()) { @@ -57,7 +63,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic fun grpcServerProperties(prefix: String): GrpcServerProperties { val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java) + "$prefix.type", String::class.java + ) return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { tokenAuthGrpcServerProperties(prefix) @@ -79,8 +86,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java) } - private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties) - : BluePrintGrpcServerService { + private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties): + BluePrintGrpcServerService { when (grpcServerProperties) { is TLSAuthGrpcServerProperties -> { return TLSAuthGrpcServerService(grpcServerProperties) @@ -91,7 +98,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } } - /** GRPC Client Lib Property Service */ fun blueprintGrpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService { @@ -105,10 +111,9 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return blueprintGrpcClientService(restClientProperties) } - fun grpcClientProperties(jsonNode: JsonNode): GrpcClientProperties { val type = jsonNode.get("type").returnNullIfMissing()?.textValue() - ?: BluePrintProcessorException("missing type property") + ?: BluePrintProcessorException("missing type property") return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { JacksonUtils.readValue(jsonNode, TokenAuthGrpcClientProperties::class.java)!! @@ -127,7 +132,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic fun grpcClientProperties(prefix: String): GrpcClientProperties { val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java) + "$prefix.type", String::class.java + ) return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { tokenAuthGrpcClientProperties(prefix) @@ -140,7 +146,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } else -> { throw BluePrintProcessorException("Grpc type($type) not supported") - } } } @@ -174,4 +179,4 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic private fun basicAuthGrpcClientProperties(prefix: String): BasicAuthGrpcClientProperties { return bluePrintPropertiesService.propertyBeanType(prefix, BasicAuthGrpcClientProperties::class.java) } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt index 0d9291615..e71525f0a 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt @@ -26,4 +26,4 @@ interface BluePrintGrpcServerService { interface BluePrintGrpcClientService { suspend fun channel(): ManagedChannel -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt index 6d2ba43cc..510a21581 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt @@ -36,35 +36,45 @@ import java.net.InetSocketAddress import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -import java.util.* +import java.util.UUID class GrpcLoggerService { private val log = logger(GrpcLoggerService::class) /** Used when server receives request */ - fun grpcRequesting(call: ServerCall, - headers: Metadata, next: ServerCallHandler) { + fun grpcRequesting( + call: ServerCall, + headers: Metadata, + next: ServerCallHandler + ) { val requestID = headers.getStringKey(ONAP_REQUEST_ID).defaultToUUID() val invocationID = headers.getStringKey(ONAP_INVOCATION_ID).defaultToUUID() val partnerName = headers.getStringKey(ONAP_PARTNER_NAME) ?: "UNKNOWN" grpcRequesting(requestID, invocationID, partnerName, call) } - fun grpcRequesting(call: ServerCall, - headers: CommonHeader, next: ServerCallHandler) { + fun grpcRequesting( + call: ServerCall, + headers: CommonHeader, + next: ServerCallHandler + ) { val requestID = headers.requestId.defaultToUUID() val invocationID = headers.subRequestId.defaultToUUID() val partnerName = headers.originatorId ?: "UNKNOWN" grpcRequesting(requestID, invocationID, partnerName, call) } - fun grpcRequesting(requestID: String, invocationID: String, partnerName: String, - call: ServerCall) { + fun grpcRequesting( + requestID: String, + invocationID: String, + partnerName: String, + call: ServerCall + ) { val localhost = InetAddress.getLocalHost() val clientSocketAddress = call.attributes.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) as? InetSocketAddress - ?: throw BluePrintProcessorException("failed to get client address") + ?: throw BluePrintProcessorException("failed to get client address") val serviceName = call.methodDescriptor.fullMethodName MDC.put("InvokeTimestamp", ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)) @@ -77,7 +87,6 @@ class GrpcLoggerService { log.trace("MDC Properties : ${MDC.getCopyOfContextMap()}") } - /** Used before invoking any GRPC outbound request, Inbound Invocation ID is used as request Id * for outbound Request, If invocation Id is missing then default Request Id will be generated. */ @@ -98,4 +107,4 @@ class GrpcLoggerService { log.warn("couldn't set grpc response headers", e) } } -} \ No newline at end of file +} 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 a70cbbce0..68ca3c16b 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 @@ -26,17 +26,17 @@ import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLoggingInterceptor import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthGrpcClientProperties) - : BluePrintGrpcClientService { +class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { return NettyChannelBuilder - .forAddress(tlsAuthGrpcClientProperties.host, tlsAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - .intercept(GrpcClientLoggingInterceptor()) - .sslContext(sslContext()) - .build() + .forAddress(tlsAuthGrpcClientProperties.host, tlsAuthGrpcClientProperties.port) + .nameResolverFactory(DnsNameResolverProvider()) + .loadBalancerFactory(PickFirstLoadBalancerProvider()) + .intercept(GrpcClientLoggingInterceptor()) + .sslContext(sslContext()) + .build() } fun sslContext(): SslContext { @@ -44,11 +44,14 @@ class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthG if (tlsAuthGrpcClientProperties.trustCertCollection != null) { builder.trustManager(normalizedFile(tlsAuthGrpcClientProperties.trustCertCollection!!)) } - if (tlsAuthGrpcClientProperties.clientCertChain != null - && tlsAuthGrpcClientProperties.clientPrivateKey != null) { - builder.keyManager(normalizedFile(tlsAuthGrpcClientProperties.clientCertChain!!), - normalizedFile(tlsAuthGrpcClientProperties.clientPrivateKey!!)) + if (tlsAuthGrpcClientProperties.clientCertChain != null && + tlsAuthGrpcClientProperties.clientPrivateKey != null + ) { + builder.keyManager( + normalizedFile(tlsAuthGrpcClientProperties.clientCertChain!!), + normalizedFile(tlsAuthGrpcClientProperties.clientPrivateKey!!) + ) } return builder.build() } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt index fc73d43f9..915ea1730 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt @@ -24,20 +24,21 @@ import io.netty.handler.ssl.SslContextBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile - -class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) - : BluePrintGrpcServerService { +class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) : + BluePrintGrpcServerService { override fun serverBuilder(): NettyServerBuilder { return NettyServerBuilder - .forPort(tlsAuthGrpcServerProperties.port) - .sslContext(sslContext()) + .forPort(tlsAuthGrpcServerProperties.port) + .sslContext(sslContext()) } fun sslContext(): SslContext { val sslClientContextBuilder = SslContextBuilder - .forServer(normalizedFile(tlsAuthGrpcServerProperties.certChain), - normalizedFile(tlsAuthGrpcServerProperties.privateKey)) + .forServer( + normalizedFile(tlsAuthGrpcServerProperties.certChain), + normalizedFile(tlsAuthGrpcServerProperties.privateKey) + ) tlsAuthGrpcServerProperties.trustCertCollection?.let { trustCertFile -> sslClientContextBuilder.trustManager(normalizedFile(trustCertFile)) @@ -45,5 +46,4 @@ class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthG } return GrpcSslContexts.configure(sslClientContextBuilder).build() } - -} \ No newline at end of file +} 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 601dc0e33..371353db2 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 @@ -16,31 +16,41 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service -import io.grpc.* +import io.grpc.CallOptions +import io.grpc.Channel +import io.grpc.ClientCall +import io.grpc.ClientInterceptor +import io.grpc.ForwardingClientCall +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 -class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) - : BluePrintGrpcClientService { +class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { val managedChannel = NettyChannelBuilder - .forAddress(tokenAuthGrpcClientProperties.host, tokenAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - .intercept(GrpcClientLoggingInterceptor()) - .intercept(TokenAuthClientInterceptor(tokenAuthGrpcClientProperties)).usePlaintext().build() + .forAddress(tokenAuthGrpcClientProperties.host, tokenAuthGrpcClientProperties.port) + .nameResolverFactory(DnsNameResolverProvider()) + .loadBalancerFactory(PickFirstLoadBalancerProvider()) + .intercept(GrpcClientLoggingInterceptor()) + .intercept(TokenAuthClientInterceptor(tokenAuthGrpcClientProperties)).usePlaintext().build() return managedChannel } } class TokenAuthClientInterceptor(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : ClientInterceptor { - override fun interceptCall(method: MethodDescriptor, - callOptions: CallOptions, channel: Channel): ClientCall { + override fun interceptCall( + method: MethodDescriptor, + callOptions: CallOptions, + channel: Channel + ): ClientCall { val authHeader = Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER) diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt index 13432c043..ea17b94a1 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt @@ -24,7 +24,11 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.* +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BluePrintGrpcLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration @@ -35,34 +39,38 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintGrpcLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class]) -@TestPropertySource(properties = -["blueprintsprocessor.grpcclient.sample.type=basic-auth", - "blueprintsprocessor.grpcclient.sample.host=127.0.0.1", - "blueprintsprocessor.grpcclient.sample.port=50505", - "blueprintsprocessor.grpcclient.sample.username=sampleuser", - "blueprintsprocessor.grpcclient.sample.password=sampleuser", - - "blueprintsprocessor.grpcclient.token.type=token-auth", - "blueprintsprocessor.grpcclient.token.host=127.0.0.1", - "blueprintsprocessor.grpcclient.token.port=50505", - "blueprintsprocessor.grpcclient.token.username=sampleuser", - "blueprintsprocessor.grpcclient.token.password=sampleuser", - - "blueprintsprocessor.grpcserver.tls-sample.type=tls-auth", - "blueprintsprocessor.grpcserver.tls-sample.port=50505", - "blueprintsprocessor.grpcserver.tls-sample.certChain=server1.pem", - "blueprintsprocessor.grpcserver.tls-sample.privateKey=server1.key", - "blueprintsprocessor.grpcserver.tls-sample.trustCertCollection=ca.pem", - - "blueprintsprocessor.grpcclient.tls-sample.type=tls-auth", - "blueprintsprocessor.grpcclient.tls-sample.host=127.0.0.1", - "blueprintsprocessor.grpcclient.tls-sample.port=50505", - "blueprintsprocessor.grpcclient.tls-sample.trustCertCollection=ca.pem", - "blueprintsprocessor.grpcclient.tls-sample.clientCertChain=client.pem", - "blueprintsprocessor.grpcclient.tls-sample.clientPrivateKey=client.key" -]) +@ContextConfiguration( + classes = [BluePrintGrpcLibConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class] +) +@TestPropertySource( + properties = + ["blueprintsprocessor.grpcclient.sample.type=basic-auth", + "blueprintsprocessor.grpcclient.sample.host=127.0.0.1", + "blueprintsprocessor.grpcclient.sample.port=50505", + "blueprintsprocessor.grpcclient.sample.username=sampleuser", + "blueprintsprocessor.grpcclient.sample.password=sampleuser", + + "blueprintsprocessor.grpcclient.token.type=token-auth", + "blueprintsprocessor.grpcclient.token.host=127.0.0.1", + "blueprintsprocessor.grpcclient.token.port=50505", + "blueprintsprocessor.grpcclient.token.username=sampleuser", + "blueprintsprocessor.grpcclient.token.password=sampleuser", + + "blueprintsprocessor.grpcserver.tls-sample.type=tls-auth", + "blueprintsprocessor.grpcserver.tls-sample.port=50505", + "blueprintsprocessor.grpcserver.tls-sample.certChain=server1.pem", + "blueprintsprocessor.grpcserver.tls-sample.privateKey=server1.key", + "blueprintsprocessor.grpcserver.tls-sample.trustCertCollection=ca.pem", + + "blueprintsprocessor.grpcclient.tls-sample.type=tls-auth", + "blueprintsprocessor.grpcclient.tls-sample.host=127.0.0.1", + "blueprintsprocessor.grpcclient.tls-sample.port=50505", + "blueprintsprocessor.grpcclient.tls-sample.trustCertCollection=ca.pem", + "blueprintsprocessor.grpcclient.tls-sample.clientCertChain=client.pem", + "blueprintsprocessor.grpcclient.tls-sample.clientPrivateKey=client.key" + ] +) class BluePrintGrpcLibPropertyServiceTest { @Autowired @@ -74,17 +82,26 @@ class BluePrintGrpcLibPropertyServiceTest { @Test fun testGrpcClientProperties() { val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( - "blueprintsprocessor.grpcclient.sample") + "blueprintsprocessor.grpcclient.sample" + ) as BasicAuthGrpcClientProperties assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.host, "failed to get host property" + - " in property bean") - assertNotNull(properties.port, "failed to get host property" + - " in property bean") - assertNotNull(properties.username, "failed to get host pro" + - "perty in property bean") - assertNotNull(properties.password, "failed to get host pr" + - "operty in property bean") + assertNotNull( + properties.host, "failed to get host property" + + " in property bean" + ) + assertNotNull( + properties.port, "failed to get host property" + + " in property bean" + ) + assertNotNull( + properties.username, "failed to get host pro" + + "perty in property bean" + ) + assertNotNull( + properties.password, "failed to get host pr" + + "operty in property bean" + ) } /** @@ -100,7 +117,8 @@ class BluePrintGrpcLibPropertyServiceTest { val mapper = ObjectMapper() val actualObj: JsonNode = mapper.readTree(json) val properties = bluePrintGrpcLibPropertyService.grpcClientProperties( - actualObj) as TokenAuthGrpcClientProperties + actualObj + ) as TokenAuthGrpcClientProperties assertNotNull(properties, "failed to create property bean") assertEquals(properties.host, "127.0.0.1") assertNotNull(properties.port, "50505") @@ -112,7 +130,8 @@ class BluePrintGrpcLibPropertyServiceTest { @Test fun testGrpcClientServiceBasic() { val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( - "sample") + "sample" + ) assertTrue(svc is BasicAuthGrpcClientService) } @@ -122,7 +141,8 @@ class BluePrintGrpcLibPropertyServiceTest { @Test fun testGrpcClientServiceToken() { val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService( - "token") + "token" + ) assertTrue(svc is TokenAuthGrpcClientService) } @@ -141,14 +161,14 @@ class BluePrintGrpcLibPropertyServiceTest { val mapper = ObjectMapper() val actualObj: JsonNode = mapper.readTree(json) val svc = bluePrintGrpcLibPropertyService - .blueprintGrpcClientService(actualObj) + .blueprintGrpcClientService(actualObj) assertTrue(svc is BasicAuthGrpcClientService) } @Test fun testGrpcClientTLSProperties() { val properties = bluePrintGrpcLibPropertyService - .grpcClientProperties("blueprintsprocessor.grpcclient.tls-sample") as TLSAuthGrpcClientProperties + .grpcClientProperties("blueprintsprocessor.grpcclient.tls-sample") as TLSAuthGrpcClientProperties assertNotNull(properties, "failed to create property bean") assertNotNull(properties.host, "failed to get host property in property bean") assertNotNull(properties.port, "failed to get host property in property bean") @@ -166,14 +186,14 @@ class BluePrintGrpcLibPropertyServiceTest { } """.trimIndent() val jsonProperties = bluePrintGrpcLibPropertyService - .grpcClientProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcClientProperties + .grpcClientProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcClientProperties assertNotNull(jsonProperties, "failed to create property bean from json") } @Test fun testGrpcServerTLSProperties() { val properties = bluePrintGrpcLibPropertyService - .grpcServerProperties("blueprintsprocessor.grpcserver.tls-sample") as TLSAuthGrpcServerProperties + .grpcServerProperties("blueprintsprocessor.grpcserver.tls-sample") as TLSAuthGrpcServerProperties assertNotNull(properties, "failed to create property bean") assertNotNull(properties.port, "failed to get host property in property bean") assertNotNull(properties.trustCertCollection, "failed to get trustCertCollection property in property bean") @@ -189,11 +209,11 @@ class BluePrintGrpcLibPropertyServiceTest { } """.trimIndent() val jsonProperties = bluePrintGrpcLibPropertyService - .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties + .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties assertNotNull(jsonProperties, "failed to create property bean from json") val grpcServerService = bluePrintGrpcLibPropertyService.blueprintGrpcServerService("tls-sample") assertNotNull(grpcServerService, "failed to get grpc server service") Assert.assertEquals(TLSAuthGrpcServerService::class.java, grpcServerService.javaClass) } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt index 8154d3747..026fe5af5 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcServerTest.kt @@ -30,7 +30,7 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput -import java.util.* +import java.util.UUID import kotlin.test.Test import kotlin.test.assertNotNull @@ -62,14 +62,16 @@ class BluePrintGrpcServerTest { } /** TLS Client Integration testing, GRPC TLS Junit testing is not supported. */ - //@Test + // @Test fun testGrpcTLSServerIntegration() { runBlocking { val tlsAuthGrpcClientService = TLSAuthGrpcClientService(tlsAuthGrpcClientProperties) val grpcChannel = tlsAuthGrpcClientService.channel() /** Get Send and Receive Channel for bidirectional process method*/ - val (reqChannel, resChannel) = clientCallBidiStreaming(BluePrintProcessingServiceGrpc.getProcessMethod(), - grpcChannel) + val (reqChannel, resChannel) = clientCallBidiStreaming( + BluePrintProcessingServiceGrpc.getProcessMethod(), + grpcChannel + ) launch { resChannel.consumeEach { log.info("Received Response") @@ -85,25 +87,24 @@ class BluePrintGrpcServerTest { private fun getRequest(requestId: String): ExecutionServiceInput { val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(requestId) - .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(requestId) + .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() val actionIdentifier = ActionIdentifiers.newBuilder() - .setActionName("SampleScript") - .setBlueprintName("sample-cba") - .setBlueprintVersion("1.0.0") - .setMode(ACTION_MODE_SYNC) - .build() + .setActionName("SampleScript") + .setBlueprintName("sample-cba") + .setBlueprintVersion("1.0.0") + .setMode(ACTION_MODE_SYNC) + .build() val jsonContent = """{ "key1" : "value1" }""" val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder JsonFormat.parser().merge(jsonContent, payloadBuilder) return ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() } - -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt index d5bc70c48..25828b15e 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/MockTLSBluePrintProcessingServer.kt @@ -27,7 +27,6 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessin import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput - val log = logger(MockTLSBluePrintProcessingServer::class) /** For Integration testing stat this server, Set the working path to run this method */ @@ -40,16 +39,15 @@ fun main() { privateKey = "src/test/resources/tls-manual/py-executor-key.pem" } val server = TLSAuthGrpcServerService(tlsAuthGrpcServerProperties).serverBuilder() - .intercept(GrpcServerLoggingInterceptor()) - .addService(MockTLSBluePrintProcessingServer()) - .build() + .intercept(GrpcServerLoggingInterceptor()) + .addService(MockTLSBluePrintProcessingServer()) + .build() server.start() log.info("GRPC Serve started(${server.isShutdown}) on port(${server.port})...") server.awaitTermination() } catch (e: Exception) { log.error("Failed to start tls grpc integration server", e) } - } class MockTLSBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { @@ -57,17 +55,21 @@ class MockTLSBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrin return object : StreamObserver { override fun onNext(executionServiceInput: ExecutionServiceInput) { - log.info("Received requestId(${executionServiceInput.commonHeader.requestId}) " + - "subRequestId(${executionServiceInput.commonHeader.subRequestId})") + log.info( + "Received requestId(${executionServiceInput.commonHeader.requestId}) " + + "subRequestId(${executionServiceInput.commonHeader.subRequestId})" + ) responseObserver.onNext(buildResponse(executionServiceInput)) responseObserver.onCompleted() } override fun onError(error: Throwable) { log.debug("Fail to process message", error) - responseObserver.onError(io.grpc.Status.INTERNAL + responseObserver.onError( + io.grpc.Status.INTERNAL .withDescription(error.message) - .asException()) + .asException() + ) } override fun onCompleted() { @@ -78,13 +80,12 @@ class MockTLSBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrin private fun buildResponse(input: ExecutionServiceInput): ExecutionServiceOutput { val status = Status.newBuilder().setCode(200) - .setEventType(EventType.EVENT_COMPONENT_EXECUTED) - .build() + .setEventType(EventType.EVENT_COMPONENT_EXECUTED) + .build() return ExecutionServiceOutput.newBuilder() - .setCommonHeader(input.commonHeader) - .setActionIdentifiers(input.actionIdentifiers) - .setStatus(status) - .build() - + .setCommonHeader(input.commonHeader) + .setActionIdentifiers(input.actionIdentifiers) + .setStatus(status) + .build() } -} \ No newline at end of file +} -- cgit 1.2.3-korg