diff options
author | Brinda Santh <bs2796@att.com> | 2019-10-18 15:23:36 -0400 |
---|---|---|
committer | Brinda Santh <bs2796@att.com> | 2019-10-22 13:03:11 -0400 |
commit | 6fd8d3dbd0c6cdd27f9ef975e4a6a45403dfb298 (patch) | |
tree | dafbe2979f200c717d48c65477385abe57505bda /ms/controllerblueprints/modules | |
parent | 10454269d97b7888f90e8147f8aa6b301039b5f9 (diff) |
Add GRPC log tracing service.
Issue-ID: CCSDK-1046
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I4ba6ed11d8fb63c21b9c49774ed733cca05c5646
Diffstat (limited to 'ms/controllerblueprints/modules')
3 files changed, 17 insertions, 7 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt index ba5815bb6..6a616cefd 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt @@ -24,11 +24,14 @@ package org.onap.ccsdk.cds.controllerblueprints.core */ object BluePrintConstants { - const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID" const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion" const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion" const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion" + const val ONAP_REQUEST_ID = "X-ONAP-RequestID" + const val ONAP_INVOCATION_ID = "X-ONAP-InvocationID" + const val ONAP_PARTNER_NAME = "X-ONAP-PartnerName" + const val STATUS_SUCCESS: String = "success" const val STATUS_PROCESSING: String = "processing" const val STATUS_FAILURE: String = "failure" diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index 1aaf9d8a4..7aa2fc86c 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -24,6 +24,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JsonParserUtils import org.slf4j.LoggerFactory import org.slf4j.helpers.MessageFormatter +import java.util.* import kotlin.reflect.KClass /** @@ -36,6 +37,13 @@ fun <T : Any> logger(clazz: T) = LoggerFactory.getLogger(clazz.javaClass)!! fun <T : KClass<*>> logger(clazz: T) = LoggerFactory.getLogger(clazz.java)!! +fun <T : Any> T?.defaultToEmpty(): String { + return this?.toString() ?: "" +} + +fun <T : Any> T?.defaultToUUID(): String { + return this?.toString() ?: UUID.randomUUID().toString() +} fun <T : Any> T.bpClone(): T { return ObjectUtils.clone(this) @@ -175,7 +183,7 @@ fun ArrayNode.asListOfString(): List<String> { fun <T> JsonNode.asType(clazzType: Class<T>): T { return JacksonUtils.readValue(this, clazzType) - ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType") + ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType") } fun JsonNode.asListOfString(): List<String> { @@ -186,8 +194,7 @@ fun JsonNode.asListOfString(): List<String> { fun <T : JsonNode> T?.returnNullIfMissing(): JsonNode? { return if (this == null || this is NullNode || this is MissingNode) { null - } - else this + } else this } fun <T : JsonNode> T?.isNullOrMissing(): Boolean { diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt index 2ddb4503d..6c92d1815 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt @@ -39,13 +39,13 @@ class MDCContextTest { @Test fun testContextCanBePassedBetweenCoroutines() { - MDC.put(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, "12345") + MDC.put(BluePrintConstants.ONAP_REQUEST_ID, "12345") runBlocking { GlobalScope.launch { - assertEquals(null, MDC.get(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID)) + assertEquals(null, MDC.get(BluePrintConstants.ONAP_REQUEST_ID)) } launch(MDCContext()) { - assertEquals("12345", MDC.get(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID), + assertEquals("12345", MDC.get(BluePrintConstants.ONAP_REQUEST_ID), "couldn't get request id") MDC.put("client_id", "client-1") |