aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Fontaine <julien.fontaine@bell.ca>2020-06-10 11:30:37 -0400
committerkuldipr <kuldip.rai@amdocs.com>2022-05-19 16:06:30 -0400
commit0948c5b1bf6b9c4fcae9c794172ecb4e98db6831 (patch)
tree5f2d746afcf5e9f4a8af64fc95b5561424f2d2e2
parentc3943fbc70105c4ce38d66c7cbe227ddec35d535 (diff)
Override Request ID in MDC Context
Issue-ID: CCSDK-3676 Signed-off-by: kuldipr <kuldip.rai@amdocs.com> Change-Id: I6b0a816fcb40e149be1818f9edc9d4839f1a4cf6
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt17
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt3
2 files changed, 16 insertions, 4 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 611c0855d..b1d8abd16 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
@@ -29,6 +29,7 @@ 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.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_INVOCATION_ID
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.ONAP_ORIGINATOR_ID
@@ -107,8 +108,12 @@ class RestLoggerService {
}
}
-/** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */
+/**
+ * Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context.
+ * @param executionServiceInput (Optional) Used to override values populated in the MDC Context
+ */
suspend fun <T> mdcWebCoroutineScope(
+ executionServiceInput: ExecutionServiceInput? = null,
block: suspend CoroutineScope.() -> T
) = coroutineScope {
val reactorContext = this.coroutineContext[ReactorContext]
@@ -118,12 +123,20 @@ suspend fun <T> mdcWebCoroutineScope(
!reactorContext.context.isEmpty &&
reactorContext.context.hasKey(MDCContext)
) {
- val mdcContext = reactorContext.context.get<MDCContext>(MDCContext)
+ val mdcContext = if (executionServiceInput != null) {
+ // MDC Context with overridden request ID
+ MDC.put("RequestID", executionServiceInput.commonHeader.requestId)
+ MDCContext(MDC.getCopyOfContextMap())
+ } else {
+ // Default MDC Context
+ reactorContext.context.get(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()
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
index bb7ecc6ad..9e0a7ee71 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -91,8 +91,7 @@ open class ExecutionServiceController {
suspend fun process(
@ApiParam(value = "ExecutionServiceInput payload.", required = true)
@RequestBody executionServiceInput: ExecutionServiceInput
- ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope {
-
+ ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope(executionServiceInput) {
if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
throw httpProcessorException(
ErrorCatalogCodes.GENERIC_FAILURE,