summaryrefslogtreecommitdiffstats
path: root/cba/resource-resolution
diff options
context:
space:
mode:
Diffstat (limited to 'cba/resource-resolution')
-rw-r--r--cba/resource-resolution/Definitions/resource-resolution.json98
-rw-r--r--cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt64
-rw-r--r--cba/resource-resolution/Scripts/python/ResolvProperties.py40
-rw-r--r--cba/resource-resolution/TOSCA-Metadata/TOSCA.meta8
-rw-r--r--cba/resource-resolution/Templates/hello-world-jinja-mapping.json127
-rw-r--r--cba/resource-resolution/Templates/hello-world-template.jinja20
-rw-r--r--cba/resource-resolution/Templates/hello-world-template.vtl16
-rw-r--r--cba/resource-resolution/Templates/hello-world-velocity-mapping.json105
8 files changed, 478 insertions, 0 deletions
diff --git a/cba/resource-resolution/Definitions/resource-resolution.json b/cba/resource-resolution/Definitions/resource-resolution.json
new file mode 100644
index 0000000..1e38953
--- /dev/null
+++ b/cba/resource-resolution/Definitions/resource-resolution.json
@@ -0,0 +1,98 @@
+{
+ "metadata": {
+ "template_author": "Selffish",
+ "author-email": "test@bell.ca",
+ "template_name": "RT-resource-resolution",
+ "template_version": "1.0.0",
+ "template_tags": "Bell, CBA, test"
+ },
+ "dsl_definitions": {
+ "rest-endpoint": {
+ "type": "token-auth",
+ "url": .MOCK_SRV,
+ "token": "NoTokenRequired"
+ },
+ "db-endpoint": {
+ "type": "maria-db",
+ "url": .DB_URL,
+ "username": "sdnctl",
+ "password": "sdnctl"
+ }
+ },
+ "topology_template": {
+ "workflows": {
+ "resource-resolution": {
+ "steps": {
+ "helloworld": {
+ "description": "Component resource resolution regression test",
+ "target": "resource-resolution"
+ }
+ },
+ "inputs": {
+ "resolution-key": {
+ "required": true,
+ "type": "string"
+ },
+ "template-prefix": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ }
+ },
+ "outputs": {
+ "meshed-template": {
+ "type": "json",
+ "value": {
+ "get_attribute": [
+ "resource-resolution",
+ "assignment-params"
+ ]
+ }
+ }
+ }
+ }
+ },
+ "node_templates": {
+ "resource-resolution": {
+ "type": "component-resource-resolution",
+ "interfaces": {
+ "ResourceResolutionComponent": {
+ "operations": {
+ "process": {
+ "inputs": {
+ "artifact-prefix-names": {
+ "get_input": "template-prefix"
+ },
+ "store-result": true,
+ "resolution-key": {
+ "get_input": "resolution-key"
+ }
+ }
+ }
+ }
+ }
+ },
+ "artifacts": {
+ "helloworld-velocity-template": {
+ "type": "artifact-template-velocity",
+ "file": "Templates/hello-world-template.vtl"
+ },
+ "helloworld-velocity-mapping": {
+ "type": "artifact-mapping-resource",
+ "file": "Templates/hello-world-velocity-mapping.json"
+ },
+ "helloworld-jinja-template": {
+ "type": "artifact-template-jinja",
+ "file": "Templates/hello-world-template.jinja"
+ },
+ "helloworld-jinja-mapping": {
+ "type": "artifact-mapping-resource",
+ "file": "Templates/hello-world-jinja-mapping.json"
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt b/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt
new file mode 100644
index 0000000..dff4761
--- /dev/null
+++ b/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2020 Bell Canada.
+ *
+ * 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 cba.cds.RT
+
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+
+open class ResolvPropertiesKt() : ResourceAssignmentProcessor() {
+
+ private val log = LoggerFactory.getLogger(ResolvPropertiesKt::class.java)!!
+
+ override fun getName(): String {
+ return "ResolvPropertiesKt"
+ }
+
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
+
+ var retValue = "undefined"
+ val resourceAssignmentNames = listOf<String>("j_kotlin","v_kotlin")
+
+ try {
+ if(resourceAssignment.name == "from_suspend_function") {
+ retValue = getResolvedValue(resourceAssignment)
+ }
+ if(resourceAssignmentNames.contains(resourceAssignment.name)) {
+ retValue = "ok"
+ }
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, retValue)
+
+ } catch (e: Exception) {
+ log.error(e.message, e)
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "ERROR")
+
+ throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments, cause: ${e.message}", e)
+ }
+ }
+
+ /*
+ * CCSDK-2150 : https://jira.onap.org/browse/CCSDK-2150
+ */
+ suspend fun getResolvedValue(resourceAssignment: ResourceAssignment): String {
+ return "ok"
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError("Failed in ResolvPropertiesKt-ResourceAssignmentProcessor : ${runtimeException.message}")
+ }
+}
diff --git a/cba/resource-resolution/Scripts/python/ResolvProperties.py b/cba/resource-resolution/Scripts/python/ResolvProperties.py
new file mode 100644
index 0000000..ac063cd
--- /dev/null
+++ b/cba/resource-resolution/Scripts/python/ResolvProperties.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2019 IBM, Bell Canada.
+#
+# 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.
+from abstract_ra_processor import AbstractRAProcessor
+from blueprint_constants import *
+
+class ResolvProperties(AbstractRAProcessor):
+
+ def process(self, resource_assignment):
+
+ resource_assignment_names = ["v_python","j_python"]
+ script_value = "undefined"
+
+ try:
+ if resource_assignment.name in resource_assignment_names :
+ script_value = "ok"
+ # set value for resource getting currently resolved
+ self.set_resource_data_value(resource_assignment, script_value)
+ except JavaException, err: # Ignore PyLintBear (E0001)
+ log.error("Java Exception in the script {}", err)
+ self.set_resource_data_value(resource_assignment, "ERROR")
+ except Exception, err:
+ log.error("Python Exception in the script {}", err)
+ self.set_resource_data_value(resource_assignment, "ERROR")
+ return None
+
+ def recover(self, runtime_exception, resource_assignment):
+ log.error("Exception in the script {}", runtime_exception)
+ print self.addError(runtime_exception.cause.message)
+ return None
diff --git a/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta b/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta
new file mode 100644
index 0000000..bb9b59a
--- /dev/null
+++ b/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta
@@ -0,0 +1,8 @@
+TOSCA-Meta-File-Version: 1.0.0
+CSAR-Version: 1.0
+Created-By: Selffish
+Entry-Definitions: Definitions/resource-resolution.json
+Template-Tags: test, regression
+Template-Name: RT-resource-resolution
+Template-Version: 1.0.0
+Template-Type: DEFAULT \ No newline at end of file
diff --git a/cba/resource-resolution/Templates/hello-world-jinja-mapping.json b/cba/resource-resolution/Templates/hello-world-jinja-mapping.json
new file mode 100644
index 0000000..8b3e4d0
--- /dev/null
+++ b/cba/resource-resolution/Templates/hello-world-jinja-mapping.json
@@ -0,0 +1,127 @@
+[
+ {
+ "name": "j_default",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "default": "ok"
+ },
+ "dictionary-name": "input-source",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "j_input",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "input-source",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "j_python",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "properties-capability-source",
+ "dictionary-source": "capability",
+ "dependencies": []
+ },
+ {
+ "name": "j_kotlin",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "kotlin-script",
+ "dictionary-source": "capability",
+ "dependencies": []
+ },
+ {
+ "name": "from_suspend_function",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "kotlin-script",
+ "dictionary-source": "capability",
+ "dependencies": []
+ },
+ {
+ "name": "j_db",
+ "input-param": true,
+ "property": {
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "dictionary-name": "RT-db",
+ "dictionary-source": "processor-db"
+ },
+ {
+ "name": "j_get",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-get",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "j_get_id",
+ "input-param": false,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-get-id",
+ "dictionary-source": "sdnc",
+ "dependencies": [
+ "j_get"
+ ]
+ },
+ {
+ "name": "j_post",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-post",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "j_put",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-put",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "j_patch",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-patch",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "j_del",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-delete",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ }
+]
diff --git a/cba/resource-resolution/Templates/hello-world-template.jinja b/cba/resource-resolution/Templates/hello-world-template.jinja
new file mode 100644
index 0000000..27c614e
--- /dev/null
+++ b/cba/resource-resolution/Templates/hello-world-template.jinja
@@ -0,0 +1,20 @@
+{
+ "default": "{{ j_default }}",
+ "input": "{{ j_input }}",
+ "script": {
+ "python": "{{ j_python }}",
+ "kotlin": {
+ "base": "{{ j_kotlin }}"
+ "from suspend function": "{{ from_suspend_function }}"
+ }
+ },
+ "db": "{{ j_db[0].value }}",
+ "rest": {
+ "GET": "{{j_get}}",
+ "GET_ID": "{{j_get_id}}",
+ "POST": "{{j_post}}",
+ "PUT": "{{j_put}}",
+ "PATCH": "{{j_patch}}",
+ "DELETE": "{{j_del}}"
+ }
+}
diff --git a/cba/resource-resolution/Templates/hello-world-template.vtl b/cba/resource-resolution/Templates/hello-world-template.vtl
new file mode 100644
index 0000000..f821770
--- /dev/null
+++ b/cba/resource-resolution/Templates/hello-world-template.vtl
@@ -0,0 +1,16 @@
+{
+ "default": "${v_default}",
+ "input": "${v_input}",
+ "script": {
+ "python": "${v_python}",
+ "kotlin": "${v_kotlin}"
+ },
+ "db": "${v_db.get(0).value}",
+ "rest": {
+ "GET": "${v_get}",
+ "POST": "${v_post}",
+ "PUT": "${v_put}",
+ "PATCH": "${v_patch}",
+ "DELETE": "${v_del}"
+ }
+}
diff --git a/cba/resource-resolution/Templates/hello-world-velocity-mapping.json b/cba/resource-resolution/Templates/hello-world-velocity-mapping.json
new file mode 100644
index 0000000..4314908
--- /dev/null
+++ b/cba/resource-resolution/Templates/hello-world-velocity-mapping.json
@@ -0,0 +1,105 @@
+[
+ {
+ "name": "v_default",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "default": "ok"
+ },
+ "dictionary-name": "input-source",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "v_input",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "input-source",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "v_python",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "properties-capability-source",
+ "dictionary-source": "capability",
+ "dependencies": []
+ },
+ {
+ "name": "v_kotlin",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "kotlin-script",
+ "dictionary-source": "capability",
+ "dependencies": []
+ },
+ {
+ "name": "v_db",
+ "input-param": true,
+ "property": {
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "dictionary-name": "RT-db",
+ "dictionary-source": "processor-db"
+ },
+ {
+ "name": "v_get",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-get",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "v_post",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-post",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "v_put",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-put",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "v_patch",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-patch",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ },
+ {
+ "name": "v_del",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "RT-rest-delete",
+ "dictionary-source": "sdnc",
+ "dependencies": []
+ }
+]