From d3cdace51db473c93540229da3a0fd061120957c Mon Sep 17 00:00:00 2001 From: SantoshB Date: Thu, 15 Oct 2020 14:57:57 +0530 Subject: cds-bash script package Issue-ID: CCSDK-2913 Change-Id: I2f97b0c78314019d5002e8563c4e433ae5e816b9 Signed-off-by: SantoshB Signed-off-by: mrichomme --- .../Definitions/resource-resolution.json | 99 ++++++++++++++++++ .../Scripts/kotlin/ResolvProperties.kt | 49 +++++++++ .../Scripts/python/ResolvProperties.py | 40 +++++++ .../resource-resolution/TOSCA-Metadata/TOSCA.meta | 8 ++ .../Templates/hello-world-jinja-mapping.json | 115 +++++++++++++++++++++ .../Templates/hello-world-template.jinja | 19 ++++ .../Templates/hello-world-template.vtl | 16 +++ .../Templates/hello-world-velocity-mapping.json | 105 +++++++++++++++++++ 8 files changed, 451 insertions(+) create mode 100644 cds-regression-test/cba/resource-resolution/Definitions/resource-resolution.json create mode 100644 cds-regression-test/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt create mode 100644 cds-regression-test/cba/resource-resolution/Scripts/python/ResolvProperties.py create mode 100644 cds-regression-test/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta create mode 100644 cds-regression-test/cba/resource-resolution/Templates/hello-world-jinja-mapping.json create mode 100644 cds-regression-test/cba/resource-resolution/Templates/hello-world-template.jinja create mode 100644 cds-regression-test/cba/resource-resolution/Templates/hello-world-template.vtl create mode 100644 cds-regression-test/cba/resource-resolution/Templates/hello-world-velocity-mapping.json (limited to 'cds-regression-test/cba/resource-resolution') diff --git a/cds-regression-test/cba/resource-resolution/Definitions/resource-resolution.json b/cds-regression-test/cba/resource-resolution/Definitions/resource-resolution.json new file mode 100644 index 0000000..af804a2 --- /dev/null +++ b/cds-regression-test/cba/resource-resolution/Definitions/resource-resolution.json @@ -0,0 +1,99 @@ +{ + "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": "http://cds-regression-mockserver", + "token": "NoTokenRequired" + }, + "db-endpoint": { + "type": "maria-db", + "url": "jdbc:mysql://cds-db:3306/sdnctl", + "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, + "force-resolution": 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" + } + } + } + } + } +} diff --git a/cds-regression-test/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt b/cds-regression-test/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt new file mode 100644 index 0000000..5dd8a86 --- /dev/null +++ b/cds-regression-test/cba/resource-resolution/Scripts/kotlin/ResolvProperties.kt @@ -0,0 +1,49 @@ +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("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/cds-regression-test/cba/resource-resolution/Scripts/python/ResolvProperties.py b/cds-regression-test/cba/resource-resolution/Scripts/python/ResolvProperties.py new file mode 100644 index 0000000..4397a67 --- /dev/null +++ b/cds-regression-test/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 as err: + # print("Java Exception in the script {}", err) + # self.set_resource_data_value(resource_assignment, "ERROR") + except Exception as err: + print("Python Exception in the script {}", err) + # self.set_resource_data_value(resource_assignment, "ERROR") + return None + + def recover(self, runtime_exception): + print("Exception in the script {}", runtime_exception) + # print self.addError(runtime_exception.cause.message) + return None diff --git a/cds-regression-test/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta b/cds-regression-test/cba/resource-resolution/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..bb9b59a --- /dev/null +++ b/cds-regression-test/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/cds-regression-test/cba/resource-resolution/Templates/hello-world-jinja-mapping.json b/cds-regression-test/cba/resource-resolution/Templates/hello-world-jinja-mapping.json new file mode 100644 index 0000000..395e7a1 --- /dev/null +++ b/cds-regression-test/cba/resource-resolution/Templates/hello-world-jinja-mapping.json @@ -0,0 +1,115 @@ +[ + { + "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_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/cds-regression-test/cba/resource-resolution/Templates/hello-world-template.jinja b/cds-regression-test/cba/resource-resolution/Templates/hello-world-template.jinja new file mode 100644 index 0000000..19947b5 --- /dev/null +++ b/cds-regression-test/cba/resource-resolution/Templates/hello-world-template.jinja @@ -0,0 +1,19 @@ +{ + "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}}", + "POST": "{{j_post}}", + "PUT": "{{j_put}}", + "PATCH": "{{j_patch}}", + "DELETE": "{{j_del}}" + } +} diff --git a/cds-regression-test/cba/resource-resolution/Templates/hello-world-template.vtl b/cds-regression-test/cba/resource-resolution/Templates/hello-world-template.vtl new file mode 100644 index 0000000..f821770 --- /dev/null +++ b/cds-regression-test/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/cds-regression-test/cba/resource-resolution/Templates/hello-world-velocity-mapping.json b/cds-regression-test/cba/resource-resolution/Templates/hello-world-velocity-mapping.json new file mode 100644 index 0000000..4314908 --- /dev/null +++ b/cds-regression-test/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": [] + } +] -- cgit 1.2.3-korg