diff options
Diffstat (limited to 'cba')
45 files changed, 2655 insertions, 0 deletions
diff --git a/cba/ansible-python-dg/Definitions/ansible-python.json b/cba/ansible-python-dg/Definitions/ansible-python.json new file mode 100644 index 0000000..849ee55 --- /dev/null +++ b/cba/ansible-python-dg/Definitions/ansible-python.json @@ -0,0 +1,175 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-ansible-python-dg", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": { + "ansible-remote-endpoint": { + "type": "token-auth", + "url": .MOCK_SRV, + "token": "Bearer J9gEtMDqf7P4YsJ7444fioY9VAhLDIs1" + }, + "remote-executor": { + "type": "token-auth", + "host": .CMD_EXEC_SVC, + "port": "50051", + "token": "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==" + } + }, + "topology_template": { + "workflows": { + "run-dg": { + "steps": { + "process": { + "description": "Run ansible then pass artifacts to command executor", + "target": "execute-dg", + "activities": [ + { + "call_operation": "" + } + ] + } + }, + "inputs": { + "endpoint-selector": { + "required": true, + "type": "string" + }, + "job-template-name": { + "required": true, + "type": "string" + }, + "limit": { + "required": false, + "type": "string" + }, + "inventory": { + "required": false, + "type": "string" + }, + "tags": { + "required": false, + "type": "string" + }, + "skip-tags": { + "required": false, + "type": "string" + }, + "extra-vars": { + "required": false, + "type": "json" + } + }, + "outputs": { + "execute-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "python", + "execute-command-logs" + ] + } + } + } + } + }, + "node_templates": { + "execute-dg": { + "type": "dg-generic", + "properties": { + "content": { + "get_artifact": [ + "SELF", + "dg" + ] + }, + "dependency-node-templates": [ + "ansible", + "python" + ] + }, + "artifacts": { + "dg": { + "type": "artifact-directed-graph", + "file": "Plans/ansible-python-dg.xml" + } + } + }, + "ansible": { + "type": "component-remote-ansible-executor", + "interfaces": { + "ComponentRemoteAnsibleExecutor": { + "operations": { + "process": { + "inputs": { + "endpoint-selector": "*ansible-remote-endpoint", + "job-template-name": { + "get_input": "job-template-name" + }, + "limit": { + "get_input": "limit" + }, + "inventory": { + "get_input": "inventory" + }, + "extra-vars": { + "get_input": "extra-vars" + }, + "tags": { + "get_input": "tags" + }, + "skip-tags": { + "get_input": "skip-tags" + } + } + } + } + } + } + }, + "python": { + "type": "component-remote-python-executor", + "interfaces": { + "ComponentRemotePythonExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script", + "timeout": 1800, + "operation_host": "SELF" + }, + "inputs": { + "endpoint-selector": "remote-executor", + "command": "python rt-python.py", + "dynamic-properties": { + "get_attribute": [ + "ansible", + "ansible-artifacts" + ] + }, + "packages": [ + { + "type": "pip", + "package": [ + "requests" + ] + } + ] + } + } + } + } + }, + "artifacts": { + "component-script": { + "type": "artifact-script-python", + "file": "Scripts/rt-python.py" + } + } + } + } + } +} diff --git a/cba/ansible-python-dg/Plans/ansible-python-dg.xml b/cba/ansible-python-dg/Plans/ansible-python-dg.xml new file mode 100644 index 0000000..e00f17a --- /dev/null +++ b/cba/ansible-python-dg/Plans/ansible-python-dg.xml @@ -0,0 +1,27 @@ +<service-logic + xmlns='http://www.onap.org/sdnc/svclogic' + xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' + xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='CONFIG' version='1.0.0'> + <method rpc='AnsiblePython' mode='sync'> + <block atomic="true"> + <execute plugin="ansible" method="process"> + <outcome value='failure'> + <return status="failure"> + </return> + </outcome> + <outcome value='success'> + <execute plugin="python" method="process"> + <outcome value='failure'> + <return status="failure"> + </return> + </outcome> + <outcome value='success'> + <return status='success'> + </return> + </outcome> + </execute> + </outcome> + </execute> + </block> + </method> +</service-logic>
\ No newline at end of file diff --git a/cba/ansible-python-dg/Scripts/rt-python.py b/cba/ansible-python-dg/Scripts/rt-python.py new file mode 100644 index 0000000..6bee5d3 --- /dev/null +++ b/cba/ansible-python-dg/Scripts/rt-python.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# +# Copyright (C) 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. +# + +import sys +import json + + +if __name__ == "__main__": + ansibleArtifacts = json.loads(sys.argv[1]) + interfaceName = ansibleArtifacts["topology"]["tor-8.tenlab-cloud"][0]["interface_name"] + print(interfaceName) + sys.exit(0) diff --git a/cba/ansible-python-dg/TOSCA-Metadata/TOSCA.meta b/cba/ansible-python-dg/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..844f38b --- /dev/null +++ b/cba/ansible-python-dg/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/ansible-python.json +Template-Tags: test, regression +Template-Name: RT-ansible-python-dg +Template-Version: 1.0.0 +Template-Type: DEFAULT diff --git a/cba/cli/Definitions/cli.json b/cba/cli/Definitions/cli.json new file mode 100644 index 0000000..c0070da --- /dev/null +++ b/cba/cli/Definitions/cli.json @@ -0,0 +1,113 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-cli", + "template_version": "1.0.0", + "template_tags": "test, regression" + }, + "dsl_definitions": { + "device-properties": { + "type": "basic-auth", + "host": { + "get_input": "host" + }, + "username": { + "get_input": "username" + }, + "password": { + "get_input": "password" + }, + "port": { + "get_input": "port" + }, + "logging": { + "get_input": "logging" + }, + "connectionTimeOut": { + "get_input": "connectionTimeOut" + } + } + }, + "topology_template": { + "workflows": { + "cli": { + "steps": { + "cli": { + "description": "CLI Workflow", + "target": "cli" + } + }, + "inputs": { + "resolution-key": { + "required": false, + "type": "string" + }, + "password": { + "required": true, + "type": "string" + }, + "username": { + "required": true, + "type": "string" + }, + "host": { + "required": true, + "type": "string" + }, + "port": { + "required": false, + "type": "string" + }, + "connectionTimeOut": { + "required": true, + "type": "string" + }, + "logging": { + "required": true, + "type": "boolean" + }, + "commands": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "outputs": { + "response-data": { + "type": "string", + "value": { + "get_attribute": [ + "cli", + "response-data" + ] + } + } + } + } + }, + "node_templates": { + "cli": { + "type": "component-script-executor", + "interfaces": { + "ComponentScriptExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script" + }, + "inputs": { + "script-type": "kotlin", + "script-class-reference": "cli.CliRegressionTest" + }, + "outputs": {} + } + } + } + } + } + } + } +} diff --git a/cba/cli/Scripts/kotlin/cli/cli.kt b/cba/cli/Scripts/kotlin/cli/cli.kt new file mode 100755 index 0000000..1e1ade0 --- /dev/null +++ b/cba/cli/Scripts/kotlin/cli/cli.kt @@ -0,0 +1,59 @@ +/* + * Copyright © 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. + */ + +package cli + +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.cliDeviceInfo +import org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor.getSshClientService +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor +import org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.CommandResult +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType + +open class CliRegressionTest : AbstractScriptComponentFunction() { + + private val log = logger(CliRegressionTest::class) + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + // Get Client Service + val sshClientService = getSshClientService(cliDeviceInfo("device-properties")) + sshClientService.startSession() + + // Read Commands + val timeout = bluePrintRuntimeService.getInputValue("connectionTimeOut").asText() + val commands = bluePrintRuntimeService.getInputValue("commands") + .let { JacksonUtils.getListFromJsonNode(it, String::class.java) } + + // Execute + var responsesLog: List<CommandResult>? = null + try { + responsesLog = sshClientService.executeCommands(commands, timeout.toLong()) + log.info(responsesLog.toString()) + } catch (e: Exception) { + e.message?.let { addError(it) } + } finally { + setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, responsesLog?.map { it->it.asJsonType()}.asJsonType()) + sshClientService.closeSession() + } + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Executing Recovery") + } +} diff --git a/cba/cli/TOSCA-Metadata/TOSCA.meta b/cba/cli/TOSCA-Metadata/TOSCA.meta new file mode 100755 index 0000000..7bb2d45 --- /dev/null +++ b/cba/cli/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/cli.json +Template-Tags: test, regression +Template-Name: RT-cli +Template-Version: 1.0.0 +Template-Type: DEFAULT
\ No newline at end of file diff --git a/cba/lock-device/Definitions/lock-device.json b/cba/lock-device/Definitions/lock-device.json new file mode 100644 index 0000000..c90021c --- /dev/null +++ b/cba/lock-device/Definitions/lock-device.json @@ -0,0 +1,98 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-lock-device", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": {}, + "topology_template": { + "workflows": { + "resolve-deploy-kotlin": { + "steps": { + "resolve": { + "description": "resolve vnf-id", + "target": "resource-resolution", + "on_success": [ + "execute-script" + ] + }, + "execute-script": { + "description": "Execute Kotlin Script", + "target": "execute-kotlin" + } + }, + "outputs": { + "response-data": { + "type": "string", + "value": { + "get_attribute": [ + "execute-kotlin", + "response-data" + ] + } + } + } + } + }, + "node_templates": { + "resource-resolution": { + "type": "component-resource-resolution", + "interfaces": { + "ResourceResolutionComponent": { + "operations": { + "process": { + "inputs": { + "artifact-prefix-names": [ + "base" + ], + "resolution-summary": true + } + } + } + } + }, + "artifacts": { + "base-mapping": { + "type": "artifact-mapping-resource", + "file": "Templates/base-mapping.json" + } + } + }, + "execute-kotlin": { + "type": "component-script-executor", + "interfaces": { + "ComponentScriptExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script", + "lock": { + "key": { + "get_attribute": [ + "resource-resolution", + "", + "assignment-map", + "base", + "vnf-id" + ] + }, + "acquireTimeout": { + "get_input": "lock-acquire-timeout" + } + } + }, + "inputs": { + "script-type": "kotlin", + "script-class-reference": "cba.cds.RT.ProcessOperation" + }, + "outputs": {} + } + } + } + } + } + } + } +} diff --git a/cba/lock-device/Scripts/kotlin/ProcessOperation.kt b/cba/lock-device/Scripts/kotlin/ProcessOperation.kt new file mode 100755 index 0000000..e84623a --- /dev/null +++ b/cba/lock-device/Scripts/kotlin/ProcessOperation.kt @@ -0,0 +1,49 @@ +/* + * Copyright © 2019 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.controllerblueprints.core.logger +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import kotlinx.coroutines.delay + +open class ProcessOperation : AbstractScriptComponentFunction() { + + private val log = logger(ProcessOperation::class) + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + val time : Long = 30_000 + try { + log.info("Processing for $time ms... ${executionRequest.commonHeader.requestId}") + delay(time) + log.info("Done processing ${executionRequest.commonHeader.requestId}!") + setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, "Success: ${executionRequest.commonHeader.requestId}".asJsonType()) + } catch (e: Exception) { + e.message?.let { addError(it) } + } + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, runtimeException.message!!.asJsonType()) + addError(runtimeException.message!!) + log.info("Executing Recovery") + } +} diff --git a/cba/lock-device/TOSCA-Metadata/TOSCA.meta b/cba/lock-device/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..e182865 --- /dev/null +++ b/cba/lock-device/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/lock-device.json +Template-Tags: test, regression +Template-Name: RT-lock-device +Template-Version: 1.0.0 +Template-Type: DEFAULT
\ No newline at end of file diff --git a/cba/lock-device/Templates/base-mapping.json b/cba/lock-device/Templates/base-mapping.json new file mode 100644 index 0000000..b5b64a8 --- /dev/null +++ b/cba/lock-device/Templates/base-mapping.json @@ -0,0 +1,23 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "default": "rt-vnf-xyz-123" + }, + "dictionary-name": "input-source", + "dictionary-source": "default", + "dependencies": [] + }, + { + "name": "lock-acquire-timeout", + "input-param": true, + "property": { + "type": "integer" + }, + "dictionary-name": "input-source", + "dictionary-source": "input", + "dependencies": [] + } +] diff --git a/cba/netconf/Definitions/netconf.json b/cba/netconf/Definitions/netconf.json new file mode 100644 index 0000000..74a98c1 --- /dev/null +++ b/cba/netconf/Definitions/netconf.json @@ -0,0 +1,137 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-netconf", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "topology_template": { + "workflows": { + "netconf-jython": { + "steps": { + "netconf-jython": { + "description": "deploy config", + "target": "execute-jython-netconf" + } + }, + "inputs": { + "netconf-host": { + "required": true, + "type": "string" + }, + "netconf-timeout": { + "required": true, + "type": "string" + } + }, + "outputs": { + "response-data": { + "type": "string", + "value": { + "get_attribute": [ + "execute-jython-netconf", + "response-data" + ] + } + } + } + }, + "netconf-kotlin": { + "steps": { + "netconf-kotlin": { + "description": "deploy config", + "target": "execute-kotlin-netconf" + } + }, + "inputs": { + "netconf-host": { + "required": true, + "type": "string" + }, + "netconf-timeout": { + "required": true, + "type": "string" + } + }, + "outputs": { + "response-data": { + "type": "string", + "value": { + "get_attribute": [ + "execute-kotlin-netconf", + "response-data" + ] + } + } + } + } + }, + "node_templates": { + "execute-jython-netconf": { + "type": "component-netconf-executor", + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "ComponentNetconfExecutor": { + "operations": { + "process": { + "inputs": { + "script-type": "jython", + "script-class-reference": "Scripts/python/NetconfTest.py", + "instance-dependencies": [] + } + } + } + } + } + }, + "execute-kotlin-netconf": { + "type": "component-netconf-executor", + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "ComponentNetconfExecutor": { + "operations": { + "process": { + "inputs": { + "script-type": "kotlin", + "script-class-reference": "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.ConfigDeploy", + "instance-dependencies": [] + } + } + } + } + } + }, + "netconf-device": { + "type": "vnf-netconf-device", + "capabilities": { + "netconf": { + "properties": { + "login-key": "password", + "login-account": "admin", + "target-ip-address": { + "get_input": "netconf-host" + }, + "port-number": 17830, + "connection-time-out": { + "get_input": "netconf-timeout" + } + } + } + } + } + } + } +} diff --git a/cba/netconf/Scripts/kotlin/kotlin.kt b/cba/netconf/Scripts/kotlin/kotlin.kt new file mode 100644 index 0000000..949d603 --- /dev/null +++ b/cba/netconf/Scripts/kotlin/kotlin.kt @@ -0,0 +1,63 @@ +/* + * 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 org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor + +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory + +open class ConfigDeploy : AbstractScriptComponentFunction() { + + private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!! + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + val device = netconfDevice("netconf-connection") + val client = device.netconfRpcService + val session = device.netconfSession + + val payload=""" + <configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> + <system xmlns="http://yang.juniper.net/junos-qfx/conf/system"> + <host-name operation="delete" /> + <host-name operation="create">Regression-Mock</host-name> + </system> + </configuration> + """ + + val response: MutableMap<String, Boolean> = mutableMapOf("deploySuccess" to false) + + try { + session.connect() + client.lock() + client.editConfig(payload) + client.commit() + client.unLock() + session.disconnect() + response["deploySuccess"] = true + } catch (e: Exception) { + e.message?.let { super.addError(it) } + } + + super.setAttribute("response-data", JacksonUtils.jsonNodeFromObject(response)) + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Executing Recovery") + } +} diff --git a/cba/netconf/Scripts/python/NetconfTest.py b/cba/netconf/Scripts/python/NetconfTest.py new file mode 100644 index 0000000..0c7a773 --- /dev/null +++ b/cba/netconf/Scripts/python/NetconfTest.py @@ -0,0 +1,56 @@ +# 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. +import netconf_constant +import sys +from java.lang import Exception as JavaException +from common import ResolutionHelper +from netconfclient import NetconfClient +import json +from org.onap.ccsdk.cds.blueprintsprocessor.services.execution import AbstractScriptComponentFunction +from com.fasterxml.jackson.databind import JsonNode; +from com.fasterxml.jackson.databind import ObjectMapper; + +class NetconfTest(AbstractScriptComponentFunction): + + def process(self, execution_request): + log = globals()[netconf_constant.SERVICE_LOG] + payload=""" + <configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> + <system xmlns="http://yang.juniper.net/junos-qfx/conf/system"> + <host-name operation="delete" /> + <host-name operation="create">Regression-Mock</host-name> + </system> + </configuration> + """ + responsePayload = '{"deploySuccess": false}' + + try: + nc = NetconfClient(log, self, "netconf-connection") + nc.connect() + nc.lock() + nc.edit_config(message_content=payload, config_target="candidate") + operationResponse = nc.commit() + nc.unlock() + nc.disconnect() + responsePayload = json.dumps({"deploySuccess": operationResponse.isSuccess()}) + except JavaException, err: # Ignore PyLintBear (E0001) + self.addError(err.message) + except Exception, err: + self.addError("Python error: {}".format(err)) + + self.setAttribute("response-data", ObjectMapper().readTree(responsePayload)) + return None + + def recover(self, exception): + return None
\ No newline at end of file diff --git a/cba/netconf/TOSCA-Metadata/TOSCA.meta b/cba/netconf/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..1155ae8 --- /dev/null +++ b/cba/netconf/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/netconf.json +Template-Tags: test, regression +Template-Name: RT-netconf +Template-Version: 1.0.0 +Template-Type: DEFAULT
\ No newline at end of file diff --git a/cba/py-executor/.DS_Store b/cba/py-executor/.DS_Store Binary files differnew file mode 100644 index 0000000..cd1acc1 --- /dev/null +++ b/cba/py-executor/.DS_Store diff --git a/cba/py-executor/Definitions/py-executor.json b/cba/py-executor/Definitions/py-executor.json new file mode 100644 index 0000000..7d9755b --- /dev/null +++ b/cba/py-executor/Definitions/py-executor.json @@ -0,0 +1,174 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-py-executor", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": { + "py-executor": { + "type": "tls-auth", + "host": .PY_EXEC_SVC, + "port": "50052", + "trustCertCollection": "/opt/app/onap/config/certs/py-executor/py-executor-chain.pem" + }, + "invalid-py-executor": { + "type": "tls-auth", + "host": "127.0.0.1", + "port": "12345", + "trustCertCollection": "/opt/app/onap/config/certs/py-executor/py-executor-chain.pem" + }, + "parameters": { + "hello" : "world" + } + }, + "topology_template": { + "workflows": { + "remote-python": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script", + "target": "execute-remote-python" + } + }, + "inputs": {}, + "outputs": { + "status": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-python", + "status" + ] + } + }, + "response-data": { + "type": "json", + "value": { + "get_attribute": [ + "execute-remote-python", + "response-data" + ] + } + } + } + }, + "connection-fail": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script to an invalid endpoint", + "target": "execute-connection-fail" + } + }, + "inputs": {}, + "outputs": { + "status": { + "type": "string", + "value": { + "get_attribute": [ + "execute-connection-fail", + "status" + ] + } + }, + "response-data": { + "type": "json", + "value": { + "get_attribute": [ + "execute-connection-fail", + "response-data" + ] + } + } + } + }, + "failing-remote-python": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script", + "target": "execute-failing-remote-python" + } + }, + "inputs": {}, + "outputs": { + "status": { + "type": "string", + "value": { + "get_attribute": [ + "execute-failing-remote-python", + "status" + ] + } + }, + "response-data": { + "type": "json", + "value": { + "get_attribute": [ + "execute-failing-remote-python", + "response-data" + ] + } + } + } + } + }, + "node_templates": { + "execute-remote-python": { + "type": "component-remote-script-executor", + "interfaces": { + "ComponentRemoteScriptExecutor": { + "operations": { + "process": { + "inputs": { + "selector": "*py-executor", + "blueprint-name": "RT-py-executor", + "blueprint-version": "1.0.0", + "blueprint-action": "HelloWorld", + "timeout": 1000, + "request-data": "*parameters" + } + } + } + } + } + }, + "execute-connection-fail": { + "type": "component-remote-script-executor", + "interfaces": { + "ComponentRemoteScriptExecutor": { + "operations": { + "process": { + "inputs": { + "selector": "*invalid-py-executor", + "blueprint-name": "RT-py-executor", + "blueprint-version": "1.0.0", + "blueprint-action": "HelloWorld", + "timeout": 1000 + } + } + } + } + } + }, + "execute-failing-remote-python": { + "type": "component-remote-script-executor", + "interfaces": { + "ComponentRemoteScriptExecutor": { + "operations": { + "process": { + "inputs": { + "selector": "*py-executor", + "blueprint-name": "RT-py-executor", + "blueprint-version": "1.0.0", + "blueprint-action": "FailingScript", + "timeout": 1000 + } + } + } + } + } + } + } + } +} diff --git a/cba/py-executor/Scripts/python/__init__.py b/cba/py-executor/Scripts/python/__init__.py new file mode 100644 index 0000000..0c354d8 --- /dev/null +++ b/cba/py-executor/Scripts/python/__init__.py @@ -0,0 +1,18 @@ +# +# 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. +# + +from .hello_world import * +from .failing_script import * diff --git a/cba/py-executor/Scripts/python/failing_script.py b/cba/py-executor/Scripts/python/failing_script.py new file mode 100644 index 0000000..e7a8802 --- /dev/null +++ b/cba/py-executor/Scripts/python/failing_script.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# +# 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. +# + +import logging +from blueprints_grpc import executor_utils +from blueprints_grpc.blueprint_processing_server import AbstractScriptFunction + +class FailingScript(AbstractScriptFunction): + def __init__(self): + self.logger = logging.getLogger(self.__class__.__name__) + + def process(self, execution_request): + self.logger.info("Request Received in Script : {}".format(execution_request)) + raise RuntimeError('Script raised an exception') + + def recover(self, runtime_exception, execution_request): # Ignore PyLintBear (W0613) + return None + + def send_notification(self, execution_request): + yield executor_utils.send_notification(execution_request, "I am notification") diff --git a/cba/py-executor/Scripts/python/hello_world.py b/cba/py-executor/Scripts/python/hello_world.py new file mode 100644 index 0000000..1500a3c --- /dev/null +++ b/cba/py-executor/Scripts/python/hello_world.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# +# 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. +# + +import logging +from blueprints_grpc import executor_utils +from blueprints_grpc.blueprint_processing_server import AbstractScriptFunction +import json +from google.protobuf import json_format + +class HelloWorld(AbstractScriptFunction): + def __init__(self): + self.logger = logging.getLogger(self.__class__.__name__) + + def process(self, execution_request): + self.logger.info("Request Received in Script : {}".format(execution_request)) + + inputs = json_format.MessageToJson(execution_request.payload) + response_payload_json = json.loads(inputs) + + execution_response = executor_utils.success_response(execution_request, response_payload_json, 200) + self.logger.info("Response returned : {}".format(execution_response)) + yield execution_response + + def recover(self, runtime_exception, execution_request): # Ignore PyLintBear (W0613) + return None + + def send_notification(self, execution_request): + yield executor_utils.send_notification(execution_request, "I am notification") diff --git a/cba/py-executor/TOSCA-Metadata/TOSCA.meta b/cba/py-executor/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..8389ebb --- /dev/null +++ b/cba/py-executor/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/py-executor.json +Template-Tags: test, regression +Template-Name: RT-py-executor +Template-Version: 1.0.0 +Template-Type: DEFAULT diff --git a/cba/remote-ansible/Definitions/remote-ansible.json b/cba/remote-ansible/Definitions/remote-ansible.json new file mode 100644 index 0000000..59ca6c6 --- /dev/null +++ b/cba/remote-ansible/Definitions/remote-ansible.json @@ -0,0 +1,281 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-remote-ansible", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": { + "ansible-remote-success-endpoint": { + "type": "token-auth", + "url": .MOCK_SRV_SUCCESS, + "token": "Bearer J9gEtMDqf7P4YsJ7444fioY9VAhLDIs1" + }, + "ansible-remote-failure-endpoint": { + "type": "token-auth", + "url": .MOCK_SRV_FAIL, + "token": "Bearer J9gEtMDqf7P4YsJ7444fioY9VAhLDIs1" + }, + "ansible-remote-invalid-endpoint": { + "type": "token-auth", + "url": "http://localhost:12345", + "token": "Bearer J9gEtMDqf7P4YsJ7444fioY9VAhLDIs1" + } + }, + "topology_template": { + "workflows": { + "execute-remote-ansible-success": { + "steps": { + "process": { + "description": "Execute Remote Ansible Script", + "target": "execute-remote-ansible-success", + "activities": [ + { + "call_operation": "" + } + ] + } + }, + "inputs": { + "endpoint-selector": { + "required": true, + "type": "string" + }, + "job-template-name": { + "required": true, + "type": "string" + }, + "limit": { + "required": false, + "type": "string" + }, + "inventory": { + "required": false, + "type": "string" + }, + "tags": { + "required": false, + "type": "string" + }, + "skip-tags": { + "required": false, + "type": "string" + }, + "extra-vars" : { + "required" : false, + "type" : "json" + } + }, + "outputs": { + "ansible-command-status": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-ansible-success", + "ansible-command-status" + ] + } + }, + "ansible-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-ansible-success", + "ansible-command-logs" + ] + } + } + } + }, + "connection-fail": { + "steps": { + "process": { + "description": "Execute Remote Ansible Script", + "target": "connection-fail", + "activities": [ + { + "call_operation": "" + } + ] + } + }, + "inputs": { + "endpoint-selector": { + "required": true, + "type": "string" + }, + "job-template-name": { + "required": true, + "type": "string" + }, + "limit": { + "required": false, + "type": "string" + }, + "inventory": { + "required": false, + "type": "string" + }, + "tags": { + "required": false, + "type": "string" + }, + "skip-tags": { + "required": false, + "type": "string" + }, + "extra-vars" : { + "required" : false, + "type" : "json" + } + }, + "outputs": { + "ansible-command-status": { + "type": "string", + "value": { + "get_attribute": [ + "connection-fail", + "ansible-command-status" + ] + } + }, + "ansible-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "connection-fail", + "ansible-command-logs" + ] + } + } + } + }, + "execute-remote-ansible-failure": { + "steps": { + "process": { + "description": "Execute Remote Ansible Script", + "target": "execute-remote-ansible-failure", + "activities": [ + { + "call_operation": "" + } + ] + } + }, + "inputs": { + "endpoint-selector": { + "required": true, + "type": "string" + }, + "job-template-name": { + "required": true, + "type": "string" + }, + "limit": { + "required": false, + "type": "string" + }, + "inventory": { + "required": false, + "type": "string" + }, + "tags": { + "required": false, + "type": "string" + }, + "skip-tags": { + "required": false, + "type": "string" + }, + "extra-vars" : { + "required" : false, + "type" : "json" + } + }, + "outputs": { + "ansible-command-status": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-ansible-failure", + "ansible-command-status" + ] + } + }, + "ansible-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-ansible-failure", + "ansible-command-logs" + ] + } + } + } + } + }, + "node_templates": { + "execute-remote-ansible-success": { + "type": "component-remote-ansible-executor", + "interfaces": { + "ComponentRemoteAnsibleExecutor": { + "operations": { + "process": { + "inputs": { + "endpoint-selector" : "*ansible-remote-success-endpoint", + "job-template-name": { "get_input": "job-template-name" }, + "limit": { "get_input": "limit" }, + "inventory": { "get_input": "inventory" }, + "extra-vars": { "get_input": "extra-vars" }, + "tags": { "get_input": "tags" }, + "skip-tags": { "get_input": "skip-tags" } + } + } + } + } + } + }, + "connection-fail": { + "type": "component-remote-ansible-executor", + "interfaces": { + "ComponentRemoteAnsibleExecutor": { + "operations": { + "process": { + "inputs": { + "endpoint-selector" : "*ansible-remote-invalid-endpoint", + "job-template-name": { "get_input": "job-template-name" }, + "limit": { "get_input": "limit" }, + "inventory": { "get_input": "inventory" }, + "extra-vars": { "get_input": "extra-vars" }, + "tags": { "get_input": "tags" }, + "skip-tags": { "get_input": "skip-tags" } + } + } + } + } + } + }, + "execute-remote-ansible-failure": { + "type": "component-remote-ansible-executor", + "interfaces": { + "ComponentRemoteAnsibleExecutor": { + "operations": { + "process": { + "inputs": { + "endpoint-selector" : "*ansible-remote-failure-endpoint", + "job-template-name": { "get_input": "job-template-name" }, + "limit": { "get_input": "limit" }, + "inventory": { "get_input": "inventory" }, + "extra-vars": { "get_input": "extra-vars" }, + "tags": { "get_input": "tags" }, + "skip-tags": { "get_input": "skip-tags" } + } + } + } + } + } + } + } + } + } diff --git a/cba/remote-ansible/TOSCA-Metadata/TOSCA.meta b/cba/remote-ansible/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..1b4ba50 --- /dev/null +++ b/cba/remote-ansible/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/remote-ansible.json +Template-Tags: test, regression +Template-Name: RT-remote-ansible +Template-Version: 1.0.0 +Template-Type: DEFAULT diff --git a/cba/remote-python/Definitions/remote-python.json b/cba/remote-python/Definitions/remote-python.json new file mode 100644 index 0000000..c002e9d --- /dev/null +++ b/cba/remote-python/Definitions/remote-python.json @@ -0,0 +1,229 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-remote-python", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": { + "args": { + "arg0": "remote executor regression" + }, + "remote-executor": { + "type": "token-auth", + "host": .CMD_EXEC_SVC, + "port": "50051", + "token": "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==" + }, + "remote-executor-wrong-port": { + "type": "token-auth", + "host": "127.0.0.1", + "port": "4242", + "token": "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==" + } + }, + "topology_template": { + "workflows": { + "remote-python": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script", + "target": "execute-remote-python" + } + }, + "inputs": { + "input": { + "required": false, + "type": "string" + } + }, + "outputs": { + "execute-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "execute-remote-python", + "execute-command-logs" + ] + } + }, + "execute-command-payload": { + "type": "json", + "value": { + "get_attribute": [ + "execute-remote-python", + "response-data" + ] + } + } + } + }, + "failing-remote-python": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script", + "target": "execute-failing-remote-python" + } + }, + "inputs": {}, + "outputs": { + "execute-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "execute-failing-remote-python", + "execute-command-logs" + ] + } + }, + "execute-command-payload": { + "type": "json", + "value": { + "get_attribute": [ + "execute-failing-remote-python", + "response-data" + ] + } + } + } + }, + "connection-fail": { + "steps": { + "execute-script": { + "description": "Execute Remote Python Script", + "target": "connection-fail" + } + }, + "inputs": {}, + "outputs": { + "execute-command-logs": { + "type": "string", + "value": { + "get_attribute": [ + "connection-fail", + "execute-command-logs" + ] + } + }, + "execute-command-payload": { + "type": "json", + "value": { + "get_attribute": [ + "connection-fail", + "response-data" + ] + } + } + } + } + }, + "node_templates": { + "execute-remote-python": { + "type": "component-remote-python-executor", + "interfaces": { + "ComponentRemotePythonExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script", + "timeout": 180, + "operation_host": "SELF" + }, + "inputs": { + "endpoint-selector": "remote-executor", + "command": "python EchoRemotePython.py", + "argument-properties": "*args", + "packages": [ + { + "type": "pip", + "package": [ + "requests" + ] + } + ] + } + } + } + } + }, + "artifacts": { + "component-script": { + "type": "artifact-script-python", + "file": "Scripts/python/EchoRemotePython.py" + } + } + }, + "execute-failing-remote-python": { + "type": "component-remote-python-executor", + "interfaces": { + "ComponentRemotePythonExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script", + "timeout": 180, + "operation_host": "SELF" + }, + "inputs": { + "endpoint-selector": "remote-executor", + "command": "python FailingRemotePython.py", + "argument-properties": "*args", + "packages": [ + { + "type": "pip", + "package": [ + "requests" + ] + } + ] + } + } + } + } + }, + "artifacts": { + "component-script": { + "type": "artifact-script-python", + "file": "Scripts/python/FailingRemotePython.py" + } + } + }, + "connection-fail": { + "type": "component-remote-python-executor", + "interfaces": { + "ComponentRemotePythonExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script", + "timeout": 180, + "operation_host": "SELF" + }, + "inputs": { + "endpoint-selector": "remote-executor-wrong-port", + "command": "python EchoRemotePython.py", + "argument-properties": "*args", + "packages": [ + { + "type": "pip", + "package": [ + "requests" + ] + } + ] + } + } + } + } + }, + "artifacts": { + "component-script": { + "type": "artifact-script-python", + "file": "Scripts/python/EchoRemotePython.py" + } + } + } + } + } +} diff --git a/cba/remote-python/Scripts/python/EchoRemotePython.py b/cba/remote-python/Scripts/python/EchoRemotePython.py new file mode 100644 index 0000000..5b775f2 --- /dev/null +++ b/cba/remote-python/Scripts/python/EchoRemotePython.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# +# 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. +# + +import sys +from cds_utils.payload_coder import send_response_data_payload + +def echo(arg): + print(arg) + +if __name__ == "__main__": + echo(sys.argv[1]) + resp_data = {"abc": ["xyz", "qqq"]} + send_response_data_payload(resp_data) + sys.exit(0) diff --git a/cba/remote-python/Scripts/python/FailingRemotePython.py b/cba/remote-python/Scripts/python/FailingRemotePython.py new file mode 100644 index 0000000..e8a356b --- /dev/null +++ b/cba/remote-python/Scripts/python/FailingRemotePython.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +# +# 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. +# + +import sys +from cds_utils.payload_coder import send_response_data_payload + +if __name__ == "__main__": + try: + raise Exception("Intentionally raised exception!") + except Exception as e: + print("Intentionally raised exception!") + resp_data = { + "errorMessage": "Intentionally raised exception!" + } + send_response_data_payload(resp_data) + sys.exit(1) diff --git a/cba/remote-python/TOSCA-Metadata/TOSCA.meta b/cba/remote-python/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..85fa3bd --- /dev/null +++ b/cba/remote-python/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/remote-python.json +Template-Tags: test, regression +Template-Name: RT-remote-python +Template-Version: 1.0.0 +Template-Type: DEFAULT
\ No newline at end of file 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": [] + } +] diff --git a/cba/retrieve-resolution/Definitions/retrieve-resolution.json b/cba/retrieve-resolution/Definitions/retrieve-resolution.json new file mode 100644 index 0000000..87fcdd9 --- /dev/null +++ b/cba/retrieve-resolution/Definitions/retrieve-resolution.json @@ -0,0 +1,120 @@ +{ + "metadata": { + "template_author": "Selffish", + "author-email": "test@bell.ca", + "template_name": "RT-retrieve-resolution", + "template_version": "1.0.0", + "template_tags": "Bell, CBA, test" + }, + "dsl_definitions": { + "retrieve-resolution-properties": { + "resolution-key": { + "get_input": "resolution-key" + }, + "artifact-name": { + "get_input": "artifact-name" + } + } + }, + "topology_template": { + "workflows": { + "retrieve-resolution": { + "steps": { + "resolve": { + "description": "Resolve", + "target": "resource-resolution", + "on_success": [ + "retrieve" + ] + }, + "retrieve": { + "description": "retrieve", + "target": "retrieve-resolution" + } + }, + "inputs": { + "resolution-key": { + "required": true, + "type": "string" + }, + "artifact-name": { + "required": true, + "type": "string" + }, + "template-prefix": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "outputs": { + "retrieved-values": { + "type": "list", + "entry_schema": { + "type": "string" + }, + "value": { + "get_attribute": [ + "retrieve-resolution", + "response-data" + ] + } + } + } + } + }, + "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" + } + } + }, + "retrieve-resolution": { + "type": "component-script-executor", + "interfaces": { + "ComponentScriptExecutor": { + "operations": { + "process": { + "implementation": { + "primary": "component-script" + }, + "inputs": { + "script-type": "kotlin", + "script-class-reference": "cba.cds.RT.RetrieveResolution", + "dynamic-properties": "*retrieve-resolution-properties" + } + } + } + } + } + } + } + } +} diff --git a/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties.kt b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties.kt new file mode 100644 index 0000000..dff4761 --- /dev/null +++ b/cba/retrieve-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/retrieve-resolution/Scripts/kotlin/ResolvProperties1.kt b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties1.kt new file mode 100644 index 0000000..d960f20 --- /dev/null +++ b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties1.kt @@ -0,0 +1,36 @@ +/* + * 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 + +open class ResolvProperties1Kt() : ResourceAssignmentProcessor() { + + override fun getName(): String { + return "ResolvProperties1Kt" + } + + override suspend fun processNB(resourceAssignment: ResourceAssignment) { + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "val1") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError("Failed in ResolvPropertiesKt-ResourceAssignmentProcessor : ${runtimeException.message}") + } +} diff --git a/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties2.kt b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties2.kt new file mode 100644 index 0000000..4bf7944 --- /dev/null +++ b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties2.kt @@ -0,0 +1,36 @@ +/* + * 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 + +open class ResolvProperties2Kt() : ResourceAssignmentProcessor() { + + override fun getName(): String { + return "ResolvProperties2Kt" + } + + override suspend fun processNB(resourceAssignment: ResourceAssignment) { + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "val2") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError("Failed in ResolvPropertiesKt-ResourceAssignmentProcessor : ${runtimeException.message}") + } +} diff --git a/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties3.kt b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties3.kt new file mode 100644 index 0000000..f8de27b --- /dev/null +++ b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties3.kt @@ -0,0 +1,35 @@ +/* + * 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 + +open class ResolvProperties3Kt() : ResourceAssignmentProcessor() { + + override fun getName(): String { + return "ResolvProperties3Kt" + } + override suspend fun processNB(resourceAssignment: ResourceAssignment) { + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "val3") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError("Failed in ResolvPropertiesKt-ResourceAssignmentProcessor : ${runtimeException.message}") + } +} diff --git a/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties4.kt b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties4.kt new file mode 100644 index 0000000..37e4d0b --- /dev/null +++ b/cba/retrieve-resolution/Scripts/kotlin/ResolvProperties4.kt @@ -0,0 +1,38 @@ +/* + * 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 kotlinx.coroutines.delay + +open class ResolvProperties4Kt() : ResourceAssignmentProcessor() { + + override fun getName(): String { + return "ResolvProperties4Kt" + } + + override suspend fun processNB(resourceAssignment: ResourceAssignment) { + delay(1000) + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "val4") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError("Failed in ResolvPropertiesKt-ResourceAssignmentProcessor : ${runtimeException.message}") + } +} diff --git a/cba/retrieve-resolution/Scripts/kotlin/RetrieveResolution.kt b/cba/retrieve-resolution/Scripts/kotlin/RetrieveResolution.kt new file mode 100644 index 0000000..c223498 --- /dev/null +++ b/cba/retrieve-resolution/Scripts/kotlin/RetrieveResolution.kt @@ -0,0 +1,63 @@ +/* + * 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.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedResourceResolutionsNB +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.slf4j.LoggerFactory + +open class RetrieveResolution : AbstractScriptComponentFunction() { + + private val log = LoggerFactory.getLogger(RetrieveResolution::class.java)!! + private val OCCURENCE: Int = 1 + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + + /* + * Here resolution-key comes as part of retrieve-resolution request payload. + */ + val resolution_key = getDynamicProperties("resolution-key").asText() + log.info("Got the resolution_key: $resolution_key from RetrieveResolution") + + /* + * Here artifact_name comes as part of retrieve-resolution request payload. + */ + val artifact_name = getDynamicProperties("artifact-name").asText() + log.info("Got the artifact_name: $artifact_name from RetrieveResolution") + + val output: List<ResourceResolution> = storedResourceResolutionsNB(resolution_key, artifact_name, OCCURENCE) + val sortedValueOutput = output.sortedBy { it.value }.map { it -> it.value } + + val result = storedContentFromResolvedArtifactNB(resolution_key, artifact_name) + val returnVal = mutableMapOf( + "resolved-template" to result.asJsonType(), + "retrieved-resolution" to mutableListOf(sortedValueOutput).asJsonType() + ).asJsonType() + + log.info("Return Val: \n$returnVal\n") + // Return the response. + setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, returnVal) + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Executing Recovery") + } +} diff --git a/cba/retrieve-resolution/TOSCA-Metadata/TOSCA.meta b/cba/retrieve-resolution/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..03f9368 --- /dev/null +++ b/cba/retrieve-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/retrieve-resolution.json +Template-Tags: test, regression +Template-Name: RT-retrieve-resolution +Template-Version: 1.0.0 +Template-Type: DEFAULT
\ No newline at end of file diff --git a/cba/retrieve-resolution/Templates/hello-world-template.vtl b/cba/retrieve-resolution/Templates/hello-world-template.vtl new file mode 100644 index 0000000..38f1c5f --- /dev/null +++ b/cba/retrieve-resolution/Templates/hello-world-template.vtl @@ -0,0 +1,7 @@ +{ + "input": "${v_input}", + "kotlin1": "${v_kotlin1}", + "kotlin2": "${v_kotlin2}", + "kotlin3": "${v_kotlin3}", + "kotlin4": "${v_kotlin4}" +} diff --git a/cba/retrieve-resolution/Templates/hello-world-velocity-mapping.json b/cba/retrieve-resolution/Templates/hello-world-velocity-mapping.json new file mode 100644 index 0000000..93c4704 --- /dev/null +++ b/cba/retrieve-resolution/Templates/hello-world-velocity-mapping.json @@ -0,0 +1,52 @@ +[ + { + "name": "v_input", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "input-source", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "v_kotlin1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "kotlin-script-1", + "dictionary-source": "capability", + "dependencies": [] + }, + { + "name": "v_kotlin2", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "kotlin-script-2", + "dictionary-source": "capability", + "dependencies": [] + }, + { + "name": "v_kotlin3", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "kotlin-script-3", + "dictionary-source": "capability", + "dependencies": [] + }, + { + "name": "v_kotlin4", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "kotlin-script-4", + "dictionary-source": "capability", + "dependencies": [] + } +] |