diff options
41 files changed, 935 insertions, 95 deletions
@@ -21,7 +21,8 @@ **/*.jsonld
**/.checkstyle
**/.gitignore
-
+ +**/*.log
**/*py.class
**/.DS_Store
diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/SampleResourceAssignmentProcessorScript.py b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/SampleResourceAssignmentProcessorScript.py deleted file mode 100644 index f9b53309..00000000 --- a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/SampleResourceAssignmentProcessorScript.py +++ /dev/null @@ -1,13 +0,0 @@ -from resource_assignment_processor_function import JythonComponentFunction -from blueprint_constants import * - - -class SampleJythonComponentNode(JythonComponentFunction): - - def process(self, execution_request): - print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH - return None - - def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH - return None diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json index 637b589f..84c78c62 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json +++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json @@ -251,7 +251,14 @@ "properties": { "login-key": "sample-key", "login-account": "sample-account", - "target-ip-address": "localhost", + "target-ip-address": { + "get_attribute": [ + "resource-assignment", + "", + "assignment-params", + "$.ipAddress" + ] + }, "port-number": 830, "connection-time-out": 30 } diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json index c8871214..d2d32e81 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json +++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json @@ -11,6 +11,14 @@ "input": { "type": "source-input", "properties": {} + }, + "capability": { + "type": "source-capability", + "properties": { + "type": "JYTHON-COMPONENT", + "instance-name": "SampleRAProcessor", + "instance-dependencies": [] + } } } }, diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py index 0a583dc5..89048121 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py +++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py @@ -1,12 +1,18 @@ from abstract_blueprint_function import AbstractPythonComponentFunction from blueprint_constants import * + class SamplePythonComponentNode(AbstractPythonComponentFunction): + def __init__(self): + AbstractPythonComponentFunction.__init__(self) + def process(self, execution_request): - print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH + AbstractPythonComponentFunction.process(self, execution_request) + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH return None def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + AbstractPythonComponentFunction.recover(self, runtime_exception, execution_request) + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH return None diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SampleRAProcessor.py b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SampleRAProcessor.py index 9729f04f..30b9ff95 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SampleRAProcessor.py +++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SampleRAProcessor.py @@ -4,10 +4,26 @@ from blueprint_constants import * class SampleRAProcessor(AbstractRAProcessor): + def __init__(self): + AbstractRAProcessor.__init__(self) + def process(self, execution_request): - print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH + + AbstractRAProcessor.process(self, execution_request) + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH + if self.ra_valid is True: + value = self.resolve_values_script(execution_request, self.value_to_resolve) + self.set_resource_data_value(execution_request, value) + else: + raise BluePrintProcessorException("Error on resource assignment. Message = " + self.error_message) return None def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + AbstractRAProcessor.recover(self, runtime_exception, execution_request) + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH return None + + def resolve_values_script(self, execution_request, value_to_resolve): + # TODO : DO business logic here + print "Resolve value for " + value_to_resolve + " here..." + return "test_python" diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/activation-blueprint.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/activation-blueprint.json new file mode 100755 index 00000000..168732c1 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/activation-blueprint.json @@ -0,0 +1,128 @@ +{ + "tosca_definitions_version" : "controller_blueprint_1_0_0", + "metadata" : { + "template_author" : "Alexis de Talhouët", + "author-email" : "adetalhouet89@gmail.com", + "user-groups" : "ADMIN, OPERATION", + "template_name" : "capability_python", + "template_version" : "1.0.0", + "template_tags" : "test" + }, + "imports" : [ { + "file" : "Definitions/data_types.json" + }, { + "file" : "Definitions/relationship_types.json" + }, { + "file" : "Definitions/artifact_types.json" + }, { + "file" : "Definitions/node_types.json" + }, { + "file" : "Definitions/policy_types.json" + } ], + "topology_template" : { + "inputs" : { + "request-id" : { + "required" : true, + "type" : "string" + }, + "action-name" : { + "required" : true, + "type" : "string" + } + }, + "workflows" : { + "assign-activate" : { + "steps" : { + "activate-process" : { + "description" : "Resource Assign and Netconf Activation Workflow", + "target" : "assign-activate-process", + "activities" : [ { + "call_operation" : "" + } ] + } + }, + "inputs" : { + "assign-activate-properties" : { + "description" : "Dynamic PropertyDefinition for workflow(assign-activate).", + "required" : true, + "type" : "dt-assign-activate-properties" + } + } + } + }, + "node_templates" : { + "assign-activate-process" : { + "type" : "dg-generic", + "properties" : { + "content" : { + "get_artifact" : [ "SELF", "dg-assign-activate-process" ] + }, + "dependency-node-templates" : [ "resource-assignment", "activate-jython" ] + }, + "artifacts" : { + "dg-assign-activate-process" : { + "type" : "artifact-directed-graph", + "file" : "Plans/CONFIG_AssignActivateNetconf_1.0.0.xml" + } + } + }, + "resource-assignment" : { + "type" : "component-resource-resolution", + "interfaces" : { + "ResourceResolutionComponent" : { + "operations" : { + "process" : { + "inputs" : { + "artifact-prefix-names" : [ "baseconfig" ] + }, + "outputs" : { + "resource-assignment-params" : { + "get_attribute" : [ "SELF", "assignment-params" ] + }, + "status" : "success" + } + } + } + } + }, + "artifacts" : { + "baseconfig-template" : { + "type" : "artifact-template-velocity", + "file" : "Templates/baseconfig-template.vtl" + }, + "baseconfig-mapping" : { + "type" : "artifact-mapping-resource", + "file" : "Definitions/baseconfig-mapping.json" + } + } + }, + "activate-jython" : { + "type" : "component-jython-executor", + "interfaces" : { + "ComponentJythonExecutor" : { + "operations" : { + "process" : { + "implementation" : { + "primary" : "component-script" + }, + "inputs" : { + "instance-dependencies" : [ ] + }, + "outputs" : { + "response-data" : "", + "status" : "" + } + } + } + } + }, + "artifacts" : { + "component-script" : { + "type" : "artifact-script-jython", + "file" : "Scripts/SamplePythonComponentNode.py" + } + } + } + } + } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/artifact_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/artifact_types.json new file mode 100755 index 00000000..aa5295e4 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/artifact_types.json @@ -0,0 +1,28 @@ +{ + "artifact_types" : { + "artifact-directed-graph" : { + "description" : "Directed Graph File", + "version" : "1.0.0", + "derived_from" : "tosca.artifacts.Implementation", + "file_ext" : [ "json", "xml" ] + }, + "artifact-mapping-resource" : { + "description" : "Resource Mapping File used along with Configuration template", + "version" : "1.0.0", + "derived_from" : "tosca.artifacts.Implementation", + "file_ext" : [ "json" ] + }, + "artifact-script-jython" : { + "description" : "Jython Script File", + "version" : "1.0.0", + "derived_from" : "tosca.artifacts.Implementation", + "file_ext" : [ "py" ] + }, + "artifact-template-velocity" : { + "description" : " Velocity Template used for Configuration", + "version" : "1.0.0", + "derived_from" : "tosca.artifacts.Implementation", + "file_ext" : [ "vtl" ] + } + } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/baseconfig-mapping.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/baseconfig-mapping.json new file mode 100755 index 00000000..de6c2411 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/baseconfig-mapping.json @@ -0,0 +1,23 @@ +[ + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "capability", + "dependencies": [ + ] + }, + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + } +] diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/data_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/data_types.json new file mode 100755 index 00000000..98a8e4b7 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/data_types.json @@ -0,0 +1,17 @@ +{ + "data_types" : { + "dt-assign-activate-properties" : { + "description" : "Dynamic DataType definition for workflow(assign-activate).", + "version" : "1.0.0", + "properties" : { + "vnf-id" : { + "type" : "string" + }, + "service-instance-id" : { + "type" : "string" + } + }, + "derived_from" : "tosca.datatypes.Dynamic" + } + } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/node_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/node_types.json new file mode 100755 index 00000000..b40c8cb3 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/node_types.json @@ -0,0 +1,183 @@ +{ + "node_types" : { + "component-jython-executor" : { + "description" : "This is Jython Execution Component.", + "version" : "1.0.0", + "capabilities" : { + "component-node" : { + "type" : "tosca.capabilities.Node" + } + }, + "interfaces" : { + "ComponentJythonExecutor" : { + "operations" : { + "process" : { + "inputs" : { + "instance-dependencies" : { + "description" : "Instance Names to Inject to Jython Script.", + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "string" + } + } + }, + "outputs" : { + "response-data" : { + "description" : "Execution Response Data in JSON format.", + "required" : false, + "type" : "string" + }, + "status" : { + "description" : "Status of the Component Execution ( success or failure )", + "required" : true, + "type" : "string" + } + } + } + } + } + }, + "derived_from" : "tosca.nodes.component.Jython" + }, + "component-resource-resolution" : { + "description" : "This is Resource Assignment Component API", + "version" : "1.0.0", + "attributes" : { + "assignment-params" : { + "required" : true, + "type" : "string" + } + }, + "capabilities" : { + "component-node" : { + "type" : "tosca.capabilities.Node" + } + }, + "interfaces" : { + "ResourceResolutionComponent" : { + "operations" : { + "process" : { + "inputs" : { + "template-name" : { + "description" : "Service Template Name.", + "required" : true, + "type" : "string" + }, + "template-version" : { + "description" : "Service Template Version.", + "required" : true, + "type" : "string" + }, + "resource-type" : { + "description" : "Request type.", + "required" : true, + "type" : "string" + }, + "template-names" : { + "description" : "Name of the artifact Node Templates, to get the template Content.", + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "string" + } + }, + "artifact-prefix-names" : { + "description" : "Template , Resource Assignment Artifact Prefix names", + "required" : false, + "type" : "list", + "entry_schema" : { + "type" : "string" + } + }, + "request-id" : { + "description" : "Request Id, Unique Id for the request.", + "required" : false, + "type" : "string" + }, + "resource-id" : { + "description" : "Resource Id.", + "required" : false, + "type" : "string" + }, + "action-name" : { + "description" : "Action Name of the process", + "required" : false, + "type" : "string" + } + }, + "outputs" : { + "resource-assignment-params" : { + "required" : true, + "type" : "string" + }, + "status" : { + "required" : true, + "type" : "string" + } + } + } + } + } + }, + "derived_from" : "tosca.nodes.Component" + }, + "dg-generic" : { + "description" : "This is Generic Directed Graph Type", + "version" : "1.0.0", + "properties" : { + "content" : { + "required" : true, + "type" : "string" + }, + "dependency-node-templates" : { + "description" : "Dependent Step Components NodeTemplate name.", + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "string" + } + } + }, + "derived_from" : "tosca.nodes.DG" + }, + "source-input" : { + "description" : "This is Input Resource Source Node Type", + "version" : "1.0.0", + "properties" : { + "key" : { + "required" : false, + "type" : "string" + }, + "key-dependencies" : { + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "string" + } + } + }, + "derived_from" : "tosca.nodes.ResourceSource" + }, + "tosca.nodes.Component" : { + "description" : "This is default Component Node", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.DG" : { + "description" : "This is Directed Graph Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.ResourceSource" : { + "description" : "TOSCA base type for Resource Sources", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.component.Jython" : { + "description" : "This is Jython Component", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + } + } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/policy_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/policy_types.json new file mode 100755 index 00000000..1e44cc70 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/policy_types.json @@ -0,0 +1,3 @@ +{ + "policy_types" : { } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/relationship_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/relationship_types.json new file mode 100755 index 00000000..4ddd7a57 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/relationship_types.json @@ -0,0 +1,3 @@ +{ + "relationship_types" : { } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/resources_definition_types.json b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/resources_definition_types.json new file mode 100755 index 00000000..d2c470fe --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Definitions/resources_definition_types.json @@ -0,0 +1,51 @@ +{ + "service-instance-id" : { + "tags" : "service-instance-id, tosca.datatypes.Root, data_type", + "name" : "service-instance-id", + "property" : { + "description" : "To be provided", + "type" : "string" + }, + "updated-by" : "Singal, Kapil <ks220y@att.com>", + "sources" : { + "input" : { + "type" : "source-input", + "properties" : { } + }, + "primary-db": { + "type": "source-primary-db", + "properties": { + "query": "SELECT artifact_name FROM BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"", + "input-key-mapping": { + }, + "output-key-mapping": { + "service-instance-id": "artifact_name" + } + } + }, + "capability": { + "type": "source-capability", + "properties": { + "type": "JYTHON-COMPONENT", + "instance-name": "SampleRAProcessor", + "instance-dependencies": [] + } + } + } + }, + "vnf-id" : { + "tags" : "vnf-id", + "name" : "vnf-id", + "property" : { + "description" : "vnf-id", + "type" : "string" + }, + "updated-by" : "Singal, Kapil <ks220y@att.com>", + "sources" : { + "input" : { + "type" : "source-input", + "properties" : { } + } + } + } +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Plans/CONFIG_AssignActivateNetconf_1.0.0.xml b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Plans/CONFIG_AssignActivateNetconf_1.0.0.xml new file mode 100755 index 00000000..eb41b7df --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Plans/CONFIG_AssignActivateNetconf_1.0.0.xml @@ -0,0 +1,42 @@ +<!-- + ~ Copyright © 2017-2018 AT&T Intellectual Property. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ 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. + --> + +<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='ResourceAssignAndActivate' mode='sync'> + <block atomic="true"> + <execute plugin="resource-assignment" method="process"> + <outcome value='failure'> + <return status="failure"> + </return> + </outcome> + <outcome value='success'> + <execute plugin="activate-jython" 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/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts new file mode 100755 index 00000000..f1da6140 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts @@ -0,0 +1,44 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.* +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive + +open class ScriptResourceAssignmentProcessor : ResourceAssignmentProcessor() { + + lateinit var resourceAssignment: ResourceAssignment + + override fun getName(): String { + return "resource-assignment-processor-custom-capability" + } + + override fun process(resourceAssignment: ResourceAssignment) { + this.resourceAssignment = resourceAssignment + } + + override fun prepareResponse(): ResourceAssignment { + return resourceAssignment + } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + TODO("To Implement") + } + +}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ScriptComponent.cba.kts b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ScriptComponent.cba.kts new file mode 100755 index 00000000..184c4933 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/kotlin/ScriptComponent.cba.kts @@ -0,0 +1,46 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode + +open class SampleKotlinComponent : BlueprintFunctionNode<String, String> { + + override fun getName(): String { + return "my Name" + } + + override fun prepareRequest(executionRequest: String): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun process(executionRequest: String) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun recover(runtimeException: RuntimeException, executionRequest: String) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun prepareResponse(): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun apply(t: String): String { + return "Successfully Executed Scripts" + } +} diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/DefaultGetNetConfig.py b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/DefaultGetNetConfig.py new file mode 100755 index 00000000..e2f5655a --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/DefaultGetNetConfig.py @@ -0,0 +1,48 @@ +import netconf_constant +from netconfclient import NetconfClient +from java.lang import Exception +from abstract_blueprint_function import AbstractPythonComponentFunction +from org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor import NetconfRpcService + + + +class DefaultGetNetConfig(AbstractPythonComponentFunction): + def process(self, execution_request): + try: + log = globals()[netconf_constant.SERVICE_LOG] + print(globals()) + #requestId = globals()[netconf_constant.PARAM_REQUEST_ID] + requestId = '1234' + + bluePrintRuntimeService = globals()['bluePrintRuntimeService'] + + capabilityProperty = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device","netconf") + + log.info("capabilityProperty {}",capabilityProperty) + netconfService = NetconfRpcService() + nc = NetconfClient(log, netconfService) + + nc.connect(netconfService.getNetconfDeviceInfo(capabilityProperty)) + runningConfigTemplate = "runningconfig-template" + + runningConfigMessageId = "get-config-" + requestId + + deviceResponse = nc.getConfig(messageId=runningConfigMessageId, + filter=runningConfigTemplate) + + log.info("Get Running Config Response {} ", deviceResponse.responseMessage) + if(deviceResponse !='null') : + status = deviceResponse.status + responseData = "{}" + if (deviceResponse.status != netconf_constant.STATUS_SUCCESS and deviceResponse.errorMessage != 'null'): + errorMessage = "Get Running Config Failure ::"+ deviceResponse.errorMessage + + except Exception, err: + log.info("Exception in the script {}",err.getMessage()) + status = netconf_constant.STATUS_FAILURE + errorMessage = "Get Running Config Failure ::"+err.getMessage() + + def recover(self, runtime_exception, execution_request): + print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + return None + diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SamplePythonComponentNode.py b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SamplePythonComponentNode.py new file mode 100755 index 00000000..89048121 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SamplePythonComponentNode.py @@ -0,0 +1,18 @@ +from abstract_blueprint_function import AbstractPythonComponentFunction +from blueprint_constants import * + + +class SamplePythonComponentNode(AbstractPythonComponentFunction): + + def __init__(self): + AbstractPythonComponentFunction.__init__(self) + + def process(self, execution_request): + AbstractPythonComponentFunction.process(self, execution_request) + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH + return None + + def recover(self, runtime_exception, execution_request): + AbstractPythonComponentFunction.recover(self, runtime_exception, execution_request) + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH + return None diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SampleRAProcessor.py b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SampleRAProcessor.py new file mode 100755 index 00000000..30b9ff95 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Scripts/python/SampleRAProcessor.py @@ -0,0 +1,29 @@ +from abstract_ra_processor import AbstractRAProcessor +from blueprint_constants import * + + +class SampleRAProcessor(AbstractRAProcessor): + + def __init__(self): + AbstractRAProcessor.__init__(self) + + def process(self, execution_request): + + AbstractRAProcessor.process(self, execution_request) + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH + if self.ra_valid is True: + value = self.resolve_values_script(execution_request, self.value_to_resolve) + self.set_resource_data_value(execution_request, value) + else: + raise BluePrintProcessorException("Error on resource assignment. Message = " + self.error_message) + return None + + def recover(self, runtime_exception, execution_request): + AbstractRAProcessor.recover(self, runtime_exception, execution_request) + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH + return None + + def resolve_values_script(self, execution_request, value_to_resolve): + # TODO : DO business logic here + print "Resolve value for " + value_to_resolve + " here..." + return "test_python" diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/TOSCA-Metadata/TOSCA.meta b/components/model-catalog/blueprint-model/test-blueprint/capability_python/TOSCA-Metadata/TOSCA.meta new file mode 100755 index 00000000..9066e484 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/TOSCA-Metadata/TOSCA.meta @@ -0,0 +1,8 @@ +TOSCA-Meta-File-Version: 1.0.0 +CSAR-Version: 1.0 +Created-By: Brinda Santh M +Entry-Definitions: Definitions/activation-blueprint.json +Template-Tags: Brinda Santh, activation-blueprint + +Name: Plans/ActivateProcess.bpmn +Content-Type: application/vnd.oasis.bpmn diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_python/Templates/baseconfig-template.vtl b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Templates/baseconfig-template.vtl new file mode 100755 index 00000000..9cbaec11 --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_python/Templates/baseconfig-template.vtl @@ -0,0 +1,4 @@ +{ + "service-instance-id": "$service-instance-id", + "vnf-id": "$vnf-id" +}
\ No newline at end of file diff --git a/components/scripts/python/ccsdk_blueprints/abstract_blueprint_function.py b/components/scripts/python/ccsdk_blueprints/abstract_blueprint_function.py index 0ddab16e..1ffa75d4 100644 --- a/components/scripts/python/ccsdk_blueprints/abstract_blueprint_function.py +++ b/components/scripts/python/ccsdk_blueprints/abstract_blueprint_function.py @@ -1,11 +1,15 @@ from org.onap.ccsdk.apps.blueprintsprocessor.services.execution import AbstractComponentFunction + class AbstractPythonComponentFunction(AbstractComponentFunction): + def __init__(self): + AbstractComponentFunction.__init__(self) + def process(self, execution_request): - print "Processing calling.." + print "Processing calling from parent..." return None def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + print "Recovering calling from parent..." return None diff --git a/components/scripts/python/ccsdk_blueprints/abstract_ra_processor.py b/components/scripts/python/ccsdk_blueprints/abstract_ra_processor.py index f7d54ea8..2cacaf52 100644 --- a/components/scripts/python/ccsdk_blueprints/abstract_ra_processor.py +++ b/components/scripts/python/ccsdk_blueprints/abstract_ra_processor.py @@ -1,12 +1,49 @@ from org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor import ResourceAssignmentProcessor +from blueprint_constants import * +from org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils import ResourceAssignmentUtils +from org.onap.ccsdk.apps.controllerblueprints.core import BluePrintProcessorException +from java.lang import Exception class AbstractRAProcessor(ResourceAssignmentProcessor): + def __init__(self): + ResourceAssignmentProcessor.__init__(self) + self.status = PROPERTY_BLUEPRINT_STATUS_SUCCESS + self.error_message = None + self.ra_valid = False + self.value_to_resolve = None + def process(self, execution_request): - print "Processing calling.." - return None + print "Processing calling from parent..." + try: + self.ra_valid = self.validate(execution_request) + self.value_to_resolve = execution_request.name + except Exception, e: + self.status = PROPERTY_BLUEPRINT_STATUS_FAILURE + self.error_message = "Get Running python scripting Failure :" + e.getMessage() def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + print "Recovering calling from parent.." + return None + + def set_resource_data_value(self, execution_request, value): + try: + if value is not None: + ResourceAssignmentUtils.Companion.setResourceDataValue(execution_request, self.raRuntimeService, value) + else: + ResourceAssignmentUtils.Companion.setFailedResourceDataValue(execution_request, "Fail to resole value") + except BluePrintProcessorException, err: + raise BluePrintProcessorException("Error on resource assignment. Message = " + err.message) + return None + + @staticmethod + def validate(ra): + if ra.name is None or ra.name is None: + raise Exception("Failed getting value for template key (" + ra.name + ") and " + + "dictionary key (" + ra.dictionaryName + + ") of type (" + ra.type + ")") + else: + pass + return True diff --git a/components/scripts/python/ccsdk_blueprints/blueprint_constants.py b/components/scripts/python/ccsdk_blueprints/blueprint_constants.py index 2ec95f31..50246773 100644 --- a/components/scripts/python/ccsdk_blueprints/blueprint_constants.py +++ b/components/scripts/python/ccsdk_blueprints/blueprint_constants.py @@ -6,6 +6,9 @@ PROPERTY_BLUEPRINT_INPUTS_DATA= "blueprint-inputs-data" PROPERTY_BLUEPRINT_CONTEXT= "blueprint-context" PROPERTY_BLUEPRINT_NAME= "template_name" PROPERTY_BLUEPRINT_VERSION= "template_version" +PROPERTY_BLUEPRINT_USER_SYSTEM= "System" +PROPERTY_BLUEPRINT_STATUS_SUCCESS= "success" +PROPERTY_BLUEPRINT_STATUS_FAILURE= "failure" METADATA_USER_GROUPS = "user-groups" METADATA_TEMPLATE_NAME = "template_name" diff --git a/components/scripts/python/ccsdk_blueprints/blueprint_runtime_service.py b/components/scripts/python/ccsdk_blueprints/blueprint_runtime_service.py index 022b4724..7c7beff7 100644 --- a/components/scripts/python/ccsdk_blueprints/blueprint_runtime_service.py +++ b/components/scripts/python/ccsdk_blueprints/blueprint_runtime_service.py @@ -11,3 +11,11 @@ class BluePrintRuntimeService: def setNodeTemplatePropertyValue(self, nodeTemplateName, propertyName, value): return self.bps.setNodeTemplatePropertyValue(nodeTemplateName, propertyName, value) + + def put_resolution_store(self, ra_name, value): + self.bps.putResolutionStore(ra_name, value) + return None + + def put_dictionary_store(self, ra_dictionary_name, value): + self.bps.putResolutionStore(ra_dictionary_name, value) + return None diff --git a/components/scripts/python/ccsdk_blueprints/resource_assignment_utils.py b/components/scripts/python/ccsdk_blueprints/resource_assignment_utils.py deleted file mode 100644 index 53cc5d70..00000000 --- a/components/scripts/python/ccsdk_blueprints/resource_assignment_utils.py +++ /dev/null @@ -1,14 +0,0 @@ -class ResourceAssignmentUtils: - - - @classmethod - def set_ressource_data_value(cls, ra, runtime_exception, value): - print "Set resource here..." - # TODO - return None - - @staticmethod - def set_ressource_value(ra, runtime_exception, value): - print "Set resource here..." - # TODO - return None
\ No newline at end of file diff --git a/components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py b/components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py index 62665dc8..a1e6c5d3 100644 --- a/components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py +++ b/components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py @@ -1,12 +1,18 @@ from abstract_blueprint_function import AbstractPythonComponentFunction from blueprint_constants import * + class SampleBlueprintComponent(AbstractPythonComponentFunction): + def __init__(self): + AbstractPythonComponentFunction.__init__(self) + def process(self, execution_request): - print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH + super(SamplePythonComponentNode, self).process(execution_request) + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH return None def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + super(SamplePythonComponentNode, self).recover(runtime_exception, execution_request) + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH return None diff --git a/components/scripts/python/ccsdk_blueprints/sample_ra_processor_function.py b/components/scripts/python/ccsdk_blueprints/sample_ra_processor_function.py index 8f68bfec..6ec5d82a 100644 --- a/components/scripts/python/ccsdk_blueprints/sample_ra_processor_function.py +++ b/components/scripts/python/ccsdk_blueprints/sample_ra_processor_function.py @@ -1,12 +1,18 @@ from abstract_ra_processor import AbstractRAProcessor +from blueprint_constants import * class SampleRAProcessorFunction(AbstractRAProcessor): + def __init__(self): + AbstractRAProcessor.__init__(self) + def process(self, execution_request): - print "Processing calling.." + AbstractRAProcessor.process(self, execution_request) + print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH return None def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + AbstractRAProcessor.recover(self, runtime_exception, execution_request) + print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH return None diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt index 8e52a9f4..f6103a4d 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt @@ -44,9 +44,9 @@ class BlueprintJythonServiceTest { val dependencies: MutableMap<String, Any> = hashMapOf() - val content = JacksonUtils.getContent("./../../../../components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py") + val content = JacksonUtils.getContent("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py") - val abstractComponentFunction = blueprintJythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SampleBlueprintComponent", content, dependencies) + val abstractComponentFunction = blueprintJythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SamplePythonComponentNode", content, dependencies) assertNotNull(abstractComponentFunction, "failed to get python component") diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt index f884456e..64281264 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt @@ -86,7 +86,7 @@ class CapabilityResourceAssignmentProcessorTest { fun `test jython capability`() { val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python") val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) @@ -100,8 +100,8 @@ class CapabilityResourceAssignmentProcessorTest { capabilityResourceAssignmentProcessor.resourceDictionaries = resourceDefinitions val resourceAssignment = ResourceAssignment().apply { - name = "country" - dictionaryName = "country" + name = "service-instance-id" + dictionaryName = "service-instance-id" dictionarySource = "capability" property = PropertyDefinition().apply { type = "string" diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json index 9d834433..d3780e0a 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json @@ -1,13 +1,14 @@ { - "tags": "country", - "name": "country", - "updated-by": "brindasanth@onap.com", + "tags": "service-instance-id, tosca.datatypes.Root, data_type", + "name": "service-instance-id", "property": { - "description": "description", + "description": "To be provided", "type": "string" }, + "updated-by": "Singal, Kapil <ks220y@att.com>", "sources": { "capability": { + "type": "source-capability", "properties": { "type": "JYTHON-COMPONENT", "instance-name": "SampleRAProcessor", diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py deleted file mode 100644 index bcf450e8..00000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/python/SampleResourceAssignmentProcessorScript.py +++ /dev/null @@ -1,13 +0,0 @@ -from resource_assignment_processor_function import AbstractJythonComponentFunction -from blueprint_constants import * - - -class SampleJythonComponentNode(AbstractJythonComponentFunction): - - def process(self, execution_request): - print "Processing calling.." + PROPERTY_BLUEPRINT_BASE_PATH - return None - - def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH - return None diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml index 44ec746c..56ea7bb5 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml @@ -1,17 +1,17 @@ <!-- ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ http://www.apache.org/licenses/LICENSE-2.0 ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. --> <configuration> diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt index a2101251..0c8209f4 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -44,6 +44,7 @@ object BluePrintConstants { const val DATA_TYPE_NULL: String = "null" const val DATA_TYPE_LIST: String = "list" const val DATA_TYPE_MAP: String = "map" + const val DATA_TYPE_JSON: String = "json" const val USER_SYSTEM: String = "System" diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt index 4509cccf..0889fddc 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,6 +110,7 @@ object BluePrintTypes { validTypes.add(BluePrintConstants.DATA_TYPE_NULL) validTypes.add(BluePrintConstants.DATA_TYPE_LIST) validTypes.add(BluePrintConstants.DATA_TYPE_MAP) + validTypes.add(BluePrintConstants.DATA_TYPE_JSON) return validTypes } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt index 81b7acb5..cb75e2c2 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt @@ -27,6 +27,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.data.* import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JsonParserUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils /** @@ -95,11 +96,11 @@ If Property Assignment is Expression. } /* - get_property: [ <modelable_entity_name>, <optional_req_or_cap_name>, <property_name>, + get_attribute: [ <modelable_entity_name>, <optional_req_or_cap_name>, <property_name>, <nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ] */ fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode { - val valueNode: JsonNode + var valueNode: JsonNode val attributeName = attributeExpression.attributeName val subAttributeName: String? = attributeExpression.subAttributeName @@ -114,24 +115,20 @@ If Property Assignment is Expression. if (!attributeExpression.modelableEntityName.equals("SELF", true)) { attributeNodeTemplateName = attributeExpression.modelableEntityName } - /* Enable in ONAP Dublin Release - val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName) - ?: throw BluePrintException(format("failed to get attribute definitions for node template " + - "({})'s property name ({}) ", nodeTemplateName, attributeName)) - - var attributeDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!! - log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) - */ + var attributeDefinition: AttributeDefinition = bluePrintContext + .nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName) + ?: throw BluePrintException("failed to get attribute definitions for node template ($attributeNodeTemplateName)'s attribute name ($attributeName) ") valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(attributeNodeTemplateName, attributeName) - ?: throw BluePrintException(format("failed to get node template ({})'s attribute ({}) ", nodeTemplateName, attributeName)) + ?: throw BluePrintException("failed to get node template ($attributeNodeTemplateName)'s attribute name ($attributeName) ") } } -// subPropertyName?.let { -// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) -// } + if (subAttributeName != null) { + if (valueNode.isObject || valueNode.isArray) + valueNode = JsonParserUtils.parse(valueNode, subAttributeName) + } return valueNode } @@ -140,7 +137,7 @@ If Property Assignment is Expression. <nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ] */ fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode { - val valueNode: JsonNode + var valueNode: JsonNode val propertyName = propertyExpression.propertyName val subPropertyName: String? = propertyExpression.subPropertyName @@ -160,9 +157,10 @@ If Property Assignment is Expression. // Check it it is a nested expression valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) -// subPropertyName?.let { -// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) -// } + if (subPropertyName != null) { + if (valueNode.isObject || valueNode.isArray) + valueNode = JsonParserUtils.parse(valueNode, subPropertyName) + } return valueNode } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt new file mode 100644 index 00000000..4bdaaa56 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtils.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + + +import com.fasterxml.jackson.databind.JsonNode +import com.jayway.jsonpath.Configuration +import com.jayway.jsonpath.JsonPath +import com.jayway.jsonpath.Option +import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider +import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider + +class JsonParserUtils { + companion object { + + //TODO("Optimise this") + val JACKSON_JSON_NODE_CONFIGURATION = Configuration.builder() + .mappingProvider(JacksonMappingProvider()).jsonProvider(JacksonJsonNodeJsonProvider()).build() + + val PATH_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST).build() + + fun paths(jsonContent: String, expression: String): List<String> { + return JsonPath.using(PATH_CONFIGURATION).parse(jsonContent).read(expression) + } + + fun paths(jsonNode: JsonNode, expression: String): List<String> { + return paths(jsonNode.toString(), expression) + } + + fun parse(jsonContent: String, expression: String): JsonNode { + return JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).read(expression) + } + + fun parse(jsonNode: JsonNode, expression: String): JsonNode { + return parse(jsonNode.toString(), expression) + } + + fun parseNSet(jsonContent: String, expression: String, value: JsonNode): JsonNode { + return JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).set(expression, value).json() + } + + fun parseNSet(jsonNode: JsonNode, expression: String, valueNode: JsonNode): JsonNode { + return parseNSet(jsonNode.toString(), expression, valueNode) + } + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt index d0bd3cf3..92e9247a 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -65,10 +65,18 @@ class BluePrintRuntimeServiceTest { BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(), "data/default-context.json", executionContext) + val assignmentParams = "{\n" + + " \"ipAddress\": \"127.0.0.1\",\n" + + " \"hostName\": \"vnf-host\"\n" + + " }" + + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", + JacksonUtils.jsonNode(assignmentParams)) + val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device", "netconf") assertNotNull(capProperties, "Failed to populate capability property values") - assertEquals(capProperties["target-ip-address"], JacksonUtils.jsonNodeFromObject("localhost"), "Failed to populate parameter target-ip-address") + assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address") assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number") } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt new file mode 100644 index 00000000..1f003999 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JsonParserUtilsTest.kt @@ -0,0 +1,33 @@ +/* + * Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import kotlin.test.assertEquals + +class JsonParserUtilsTest { + + @Test + fun `test parse Node`() { + val dataNode = JacksonUtils.jsonNodeFromClassPathFile("data/default-context.json") + + val parsedNode = JsonParserUtils.parse(dataNode, "$.request-id") + + assertEquals(parsedNode, "12345".asJsonPrimitive(), "failed to parse json request-id") + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json index 3968626b..9f733f0f 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json @@ -1,7 +1,7 @@ { - "request-id" : "12345", - "hostname" : "localhost", + "request-id": "12345", + "hostname": "localhost", "template_name": "baseconfiguration", "template_version": "1.0.0", - "action-name" : "sample-action" + "action-name": "sample-action" }
\ No newline at end of file |