diff options
author | Brinda Santh <bs2796@att.com> | 2020-02-01 18:47:59 -0500 |
---|---|---|
committer | Brinda Santh <bs2796@att.com> | 2020-02-01 18:47:59 -0500 |
commit | c6da9f5aaa7c29644ead22d5ba5fc8ef3ec5811a (patch) | |
tree | 60d328afa8a7516dec7a2da20bdcc76ee8644bf6 /ms/blueprintsprocessor/modules/commons/rest-lib/src | |
parent | 5c094c6adc53d958b2079de67d9d26242e10d7ef (diff) |
Expose rest API with non blocking call.
Convert Mono and Flux to coroutines
Convert reactor mdc to coroutine mdc
Issue-ID: CCSDK-2052
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: Ic58c0b74866d28fd2d803b96626b08f8e8b2db56
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src')
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index 313710745..846a94a09 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -21,10 +21,12 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.InternalCoroutinesApi +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.handleCoroutineException import kotlinx.coroutines.newCoroutineContext import kotlinx.coroutines.reactor.ReactorContext import kotlinx.coroutines.reactor.asCoroutineContext +import kotlinx.coroutines.withContext import org.apache.http.message.BasicHeader import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID @@ -95,6 +97,32 @@ class RestLoggerService { } /** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */ +suspend fun <T> mdcWebCoroutineScope( + block: suspend CoroutineScope.() -> T +) = coroutineScope { + val reactorContext = this.coroutineContext[ReactorContext] + /** Populate MDC context only if present in Reactor Context */ + val newContext = if (reactorContext != null && + !reactorContext.context.isEmpty && + reactorContext.context.hasKey(MDCContext) + ) { + val mdcContext = reactorContext.context.get<MDCContext>(MDCContext) + if (mdcContext != null) + newCoroutineContext(this.coroutineContext + reactorContext + mdcContext) + else + newCoroutineContext(this.coroutineContext + reactorContext) + } else this.coroutineContext + // Execute the block with new and old context + withContext(newContext) { + block() + } +} + +@Deprecated( + message = "Now CDS supports Coruoutin rest controller", + replaceWith = ReplaceWith("mdcWebCoroutineScope") +) +/** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */ @UseExperimental(InternalCoroutinesApi::class) fun <T> monoMdc( context: CoroutineContext = EmptyCoroutineContext, |