summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json9
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml18
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt1
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt34
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt60
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt10
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt33
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json6
10 files changed, 143 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 993ab740..f116f6b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,7 +21,8 @@
**/*.jsonld
**/.checkstyle
**/.gitignore
-
+
+**/*.log
**/*py.class
**/.DS_Store
diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
index 637b589f..84c78c62 100644
--- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
+++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
@@ -251,7 +251,14 @@
"properties": {
"login-key": "sample-key",
"login-account": "sample-account",
- "target-ip-address": "localhost",
+ "target-ip-address": {
+ "get_attribute": [
+ "resource-assignment",
+ "",
+ "assignment-params",
+ "$.ipAddress"
+ ]
+ },
"port-number": 830,
"connection-time-out": 30
}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml
index 44ec746c..56ea7bb5 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml
@@ -1,17 +1,17 @@
<!--
~ Copyright © 2017-2018 AT&T Intellectual Property.
~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
~
- ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ http://www.apache.org/licenses/LICENSE-2.0
~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
-->
<configuration>
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index a2101251..0c8209f4 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -44,6 +44,7 @@ object BluePrintConstants {
const val DATA_TYPE_NULL: String = "null"
const val DATA_TYPE_LIST: String = "list"
const val DATA_TYPE_MAP: String = "map"
+ const val DATA_TYPE_JSON: String = "json"
const val USER_SYSTEM: String = "System"
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
index 4509cccf..0889fddc 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -109,6 +110,7 @@ object BluePrintTypes {
validTypes.add(BluePrintConstants.DATA_TYPE_NULL)
validTypes.add(BluePrintConstants.DATA_TYPE_LIST)
validTypes.add(BluePrintConstants.DATA_TYPE_MAP)
+ validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
return validTypes
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
index 81b7acb5..cb75e2c2 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
@@ -27,6 +27,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.format
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JsonParserUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils
/**
@@ -95,11 +96,11 @@ If Property Assignment is Expression.
}
/*
- get_property: [ <modelable_entity_name>, <optional_req_or_cap_name>, <property_name>,
+ get_attribute: [ <modelable_entity_name>, <optional_req_or_cap_name>, <property_name>,
<nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ]
*/
fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode {
- val valueNode: JsonNode
+ var valueNode: JsonNode
val attributeName = attributeExpression.attributeName
val subAttributeName: String? = attributeExpression.subAttributeName
@@ -114,24 +115,20 @@ If Property Assignment is Expression.
if (!attributeExpression.modelableEntityName.equals("SELF", true)) {
attributeNodeTemplateName = attributeExpression.modelableEntityName
}
- /* Enable in ONAP Dublin Release
- val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName)
- ?: throw BluePrintException(format("failed to get attribute definitions for node template " +
- "({})'s property name ({}) ", nodeTemplateName, attributeName))
-
- var attributeDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!!
- log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)
- */
+ var attributeDefinition: AttributeDefinition = bluePrintContext
+ .nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)
+ ?: throw BluePrintException("failed to get attribute definitions for node template ($attributeNodeTemplateName)'s attribute name ($attributeName) ")
valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(attributeNodeTemplateName, attributeName)
- ?: throw BluePrintException(format("failed to get node template ({})'s attribute ({}) ", nodeTemplateName, attributeName))
+ ?: throw BluePrintException("failed to get node template ($attributeNodeTemplateName)'s attribute name ($attributeName) ")
}
}
-// subPropertyName?.let {
-// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName))
-// }
+ if (subAttributeName != null) {
+ if (valueNode.isObject || valueNode.isArray)
+ valueNode = JsonParserUtils.parse(valueNode, subAttributeName)
+ }
return valueNode
}
@@ -140,7 +137,7 @@ If Property Assignment is Expression.
<nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ]
*/
fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode {
- val valueNode: JsonNode
+ var valueNode: JsonNode
val propertyName = propertyExpression.propertyName
val subPropertyName: String? = propertyExpression.subPropertyName
@@ -160,9 +157,10 @@ If Property Assignment is Expression.
// Check it it is a nested expression
valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression)
-// subPropertyName?.let {
-// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName))
-// }
+ if (subPropertyName != null) {
+ if (valueNode.isObject || valueNode.isArray)
+ valueNode = JsonParserUtils.parse(valueNode, subPropertyName)
+ }
return valueNode
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt
new file mode 100644
index 00000000..4bdaaa56
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.utils
+
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.jayway.jsonpath.Configuration
+import com.jayway.jsonpath.JsonPath
+import com.jayway.jsonpath.Option
+import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider
+import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider
+
+class JsonParserUtils {
+ companion object {
+
+ //TODO("Optimise this")
+ val JACKSON_JSON_NODE_CONFIGURATION = Configuration.builder()
+ .mappingProvider(JacksonMappingProvider()).jsonProvider(JacksonJsonNodeJsonProvider()).build()
+
+ val PATH_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST).build()
+
+ fun paths(jsonContent: String, expression: String): List<String> {
+ return JsonPath.using(PATH_CONFIGURATION).parse(jsonContent).read(expression)
+ }
+
+ fun paths(jsonNode: JsonNode, expression: String): List<String> {
+ return paths(jsonNode.toString(), expression)
+ }
+
+ fun parse(jsonContent: String, expression: String): JsonNode {
+ return JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).read(expression)
+ }
+
+ fun parse(jsonNode: JsonNode, expression: String): JsonNode {
+ return parse(jsonNode.toString(), expression)
+ }
+
+ fun parseNSet(jsonContent: String, expression: String, value: JsonNode): JsonNode {
+ return JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).set(expression, value).json()
+ }
+
+ fun parseNSet(jsonNode: JsonNode, expression: String, valueNode: JsonNode): JsonNode {
+ return parseNSet(jsonNode.toString(), expression, valueNode)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
index d0bd3cf3..92e9247a 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
@@ -65,10 +65,18 @@ class BluePrintRuntimeServiceTest {
BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
"data/default-context.json", executionContext)
+ val assignmentParams = "{\n" +
+ " \"ipAddress\": \"127.0.0.1\",\n" +
+ " \"hostName\": \"vnf-host\"\n" +
+ " }"
+
+ bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
+ JacksonUtils.jsonNode(assignmentParams))
+
val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",
"netconf")
assertNotNull(capProperties, "Failed to populate capability property values")
- assertEquals(capProperties["target-ip-address"], JacksonUtils.jsonNodeFromObject("localhost"), "Failed to populate parameter target-ip-address")
+ assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt
new file mode 100644
index 00000000..1f003999
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.utils
+
+import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import kotlin.test.assertEquals
+
+class JsonParserUtilsTest {
+
+ @Test
+ fun `test parse Node`() {
+ val dataNode = JacksonUtils.jsonNodeFromClassPathFile("data/default-context.json")
+
+ val parsedNode = JsonParserUtils.parse(dataNode, "$.request-id")
+
+ assertEquals(parsedNode, "12345".asJsonPrimitive(), "failed to parse json request-id")
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json
index 3968626b..9f733f0f 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json
@@ -1,7 +1,7 @@
{
- "request-id" : "12345",
- "hostname" : "localhost",
+ "request-id": "12345",
+ "hostname": "localhost",
"template_name": "baseconfiguration",
"template_version": "1.0.0",
- "action-name" : "sample-action"
+ "action-name": "sample-action"
} \ No newline at end of file