aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/blueprints
diff options
context:
space:
mode:
authorBrinda Santh <bs2796@att.com>2019-12-18 15:19:58 -0500
committerKAPIL SINGAL <ks220y@att.com>2019-12-19 20:48:38 +0000
commit10c2988b51c764e62d8eeed52b254d363512eb24 (patch)
tree2c93f00798168375d083ee35fed74cfe49669d02 /ms/blueprintsprocessor/modules/blueprints
parent20b07e37990f1926d7b3cb45542b76c0336f9f19 (diff)
Cluster communication channels
Add NATS property and library services both . NATS Messaging Services with Token Auth and TLS Auth implementation Docker Compose for NATS Streaming instance. Documentation : https://docs.nats.io/ Issue-ID: CCSDK-2007 Signed-off-by: Brinda Santh <bs2796@att.com> Change-Id: Ieebaa8f2b18ae89d02a4f38a8027eda495a9db43
Diffstat (limited to 'ms/blueprintsprocessor/modules/blueprints')
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt29
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ClusterUtils.kt9
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt11
3 files changed, 37 insertions, 12 deletions
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
index 5189d0758..4ab3d6f86 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
@@ -56,9 +56,13 @@ fun <T : Any> T.bpClone(): T {
return ObjectUtils.clone(this)
}
+fun String.splitCommaAsList(): List<String> {
+ return this.split(",").map { it.trim() }.toList()
+}
+
fun String.isJson(): Boolean {
return ((this.trim().startsWith("{") && this.trim().endsWith("}")) ||
- (this.trim().startsWith("[") && this.trim().endsWith("]")))
+ (this.trim().startsWith("[") && this.trim().endsWith("]")))
}
fun Any.asJsonString(intend: Boolean? = false): String {
@@ -126,29 +130,25 @@ fun String.asJsonType(bpDataType: String): JsonNode {
}
/**
- * Utility to convert Complex or Primitive object to Json Type.
+ * Utility to convert Complex or Primitive object or ByteArray to Json Type.
*/
fun <T : Any?> T.asJsonType(): JsonNode {
return if (this == null || this is MissingNode || this is NullNode) {
NullNode.instance
} else {
when (this) {
- is JsonNode ->
- this
+ is JsonNode -> this
+ is ByteArray -> JacksonUtils.objectMapper.reader().readTree(this.inputStream())
is String -> {
if (this.isJson())
this.jsonAsJsonType()
else
TextNode(this)
}
- is Boolean ->
- BooleanNode.valueOf(this)
- is Int ->
- IntNode.valueOf(this.toInt())
- is Double ->
- DoubleNode.valueOf(this.toDouble())
- else ->
- JacksonUtils.jsonNodeFromObject(this)
+ is Boolean -> BooleanNode.valueOf(this)
+ is Int -> IntNode.valueOf(this.toInt())
+ is Double -> DoubleNode.valueOf(this.toDouble())
+ else -> JacksonUtils.jsonNodeFromObject(this)
}
}
}
@@ -188,6 +188,11 @@ fun ArrayNode.asListOfString(): List<String> {
return JacksonUtils.getListFromJsonNode(this, String::class.java)
}
+fun JsonNode.asByteArray(): ByteArray {
+ val writer = JacksonUtils.objectMapper.writer()
+ return writer.writeValueAsBytes(this)
+}
+
fun <T> JsonNode.asType(clazzType: Class<T>): T {
return JacksonUtils.readValue(this, clazzType)
?: throw BluePrintException("couldn't convert JsonNode of type $clazzType")
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ClusterUtils.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ClusterUtils.kt
index d3d621093..d5ffe6b7f 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ClusterUtils.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ClusterUtils.kt
@@ -16,6 +16,7 @@
package org.onap.ccsdk.cds.controllerblueprints.core.utils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import java.net.InetAddress
object ClusterUtils {
@@ -25,4 +26,12 @@ object ClusterUtils {
val ip = InetAddress.getLocalHost()
return ip.hostName
}
+
+ fun clusterId(): String {
+ return System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_ID) ?: "cds-cluster"
+ }
+
+ fun clusterNodeId(): String {
+ return System.getProperty(BluePrintConstants.PROPERTY_CLUSTER_NODE_ID) ?: "cds-controller"
+ }
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
index 3ae87b32d..7ac9b8649 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
@@ -68,6 +68,17 @@ class CustomFunctionsTest {
}
@Test
+ fun testByteArrayJsonType() {
+ val jsonNode = """{"Name" :"Value"}""".jsonAsJsonType()
+
+ val byteArray = jsonNode.asByteArray()
+ assertNotNull(byteArray, "failed to get ByteArray form Json")
+
+ val reverseJsonNode = byteArray.asJsonType()
+ assertNotNull(reverseJsonNode, "failed to get Json type from ByteArray")
+ }
+
+ @Test
fun testAsJsonType() {
val nullReturnValue: JsonNode = null.asJsonType()
assertEquals(NullNode.instance, nullReturnValue)