From 052b7bd78ad4808f6eac31553c12cee7569eaefb Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 4 Sep 2018 20:24:35 +0000 Subject: Controller Blueprints Microservice Refactor controller blueprint core and resource dictionary modules to components module. Change-Id: If5ba5e35e9c95bc19bc78fb10bd62d6551ba7aca Issue-ID: CCSDK-514 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../Definitions/activation-blueprint.json | 411 ++++++++++++++ .../Mappings/baseconfig-mapping.json | 3 + .../baseconfiguration/Plans/ActivateProcess.bpmn | 66 +++ .../Scripts/SamplePythonComponentNode.py | 8 + .../baseconfiguration/Scripts/__init__.py | 0 .../baseconfiguration/TOSCA-Metadata/TOSCA.meta | 8 + .../Templates/baseconfig-template.vtl | 1 + .../load/blueprints/baseconfiguration/__init__.py | 0 .../Definitions/sample-nodetype.json | 34 ++ .../Definitions/simple-baseconfig.json | 345 ++++++++++++ .../Mappings/baseconfig-mapping.json | 3 + .../simple-baseconfig/Plans/ActivateProcess.bpmn | 66 +++ .../Scripts/SamplePythonComponentNode.py | 8 + .../simple-baseconfig/Scripts/__init__.py | 0 .../simple-baseconfig/TOSCA-Metadata/TOSCA.meta | 8 + .../Templates/base-config-template.vtl | 40 ++ .../Templates/baseconfig-template.vtl | 1 + .../Templates/licence-template.vtl | 4 + .../load/blueprints/simple-baseconfig/__init__.py | 0 .../artifact_type/artifact-bpmn-camunda.json | 8 + .../artifact_type/artifact-directed-graph.json | 9 + .../artifact_type/artifact-mapping-resource.json | 8 + .../artifact_type/artifact-script-python.json | 8 + .../artifact_type/artifact-template-velocity.json | 8 + .../tosca.artifacts.Implementation.json | 5 + .../model_type/data_type/datatype-property.json | 27 + .../data_type/datatype-resource-assignment.json | 46 ++ .../load/model_type/data_type/dt-license-key.json | 11 + .../load/model_type/data_type/dt-v4-aggregate.json | 15 + .../data_type/tosca.datatypes.Credential.json | 31 ++ .../node_type/artifact-config-template.json | 37 ++ .../node_type/component-config-generator.json | 72 +++ .../node_type/component-netconf-executor.json | 79 +++ .../node_type/component-resource-assignment.json | 68 +++ .../model_type/node_type/dg-activate-netconf.json | 66 +++ .../model_type/node_type/dg-config-generator.json | 65 +++ .../node_type/dg-resource-assign-activate.json | 70 +++ .../node_type/dg-resource-assignment.json | 65 +++ .../model_type/node_type/vnf-netconf-device.json | 42 ++ components/core/pom.xml | 68 +++ .../core/BluePrintConstants.kt | 142 +++++ .../core/BluePrintException.kt | 49 ++ .../core/BluePrintProcessorException.kt | 49 ++ .../controllerblueprints/core/BluePrintTypes.kt | 91 +++ .../core/ConfigModelConstant.kt | 44 ++ .../controllerblueprints/core/CustomFunctions.kt | 75 +++ .../core/data/BluePrintExpressionData.kt | 70 +++ .../core/data/BluePrintModel.kt | 612 +++++++++++++++++++++ .../core/factory/BluePrintEnhancerFactory.kt | 45 ++ .../core/factory/BluePrintParserFactory.kt | 51 ++ .../core/factory/BluePrintValidatorFactory.kt | 45 ++ .../core/service/BluePrintChainedService.kt | 117 ++++ .../core/service/BluePrintContext.kt | 177 ++++++ .../core/service/BluePrintEnhancerService.kt | 259 +++++++++ .../core/service/BluePrintExpressionService.kt | 176 ++++++ .../core/service/BluePrintParserService.kt | 62 +++ .../core/service/BluePrintRepoService.kt | 98 ++++ .../core/service/BluePrintRuntimeService.kt | 278 ++++++++++ .../core/service/BluePrintValidatorService.kt | 360 ++++++++++++ .../core/service/PropertyAssignmentService.kt | 200 +++++++ .../core/utils/BluePrintMetadataUtils.kt | 95 ++++ .../core/utils/BluePrintRuntimeUtils.kt | 55 ++ .../core/utils/JacksonReactorUtils.kt | 108 ++++ .../core/utils/JacksonUtils.kt | 248 +++++++++ .../core/utils/ResourceResolverUtils.kt | 62 +++ .../core/utils/ServiceTemplateUtils.kt | 44 ++ .../core/utils/TopologicalSortingUtils.kt | 131 +++++ .../core/CustomFunctionsTest.kt | 35 ++ .../core/service/BluePrintContextTest.kt | 70 +++ .../core/service/BluePrintEnhancerServiceTest.kt | 41 ++ .../core/service/BluePrintExpressionServiceTest.kt | 109 ++++ .../core/service/BluePrintParserFactoryTest.kt | 42 ++ .../core/service/BluePrintRepoFileServiceTest.kt | 57 ++ .../core/service/BluePrintRuntimeServiceTest.kt | 131 +++++ .../BluePrintValidatorDefaultServiceTest.kt | 49 ++ .../core/utils/BluePrintMetadataUtilsTest.kt | 40 ++ .../core/utils/JacksonReactorUtilsTest.kt | 51 ++ .../core/utils/JacksonUtilsTest.kt | 93 ++++ .../core/utils/TopologicalSortingUtilsTest.kt | 36 ++ .../src/test/resources/componentnode/default.json | 100 ++++ .../core/src/test/resources/data/alltype-data.json | 10 + .../src/test/resources/data/default-context.json | 5 + .../resources/dictionary/dictionary_schema.json | 261 +++++++++ .../src/test/resources/properties/convert.json | 33 ++ .../src/test/resources/properties/default.json | 16 + components/parent/pom.xml | 299 ++++++++++ components/pom.xml | 45 ++ .../node_type/source-component-java.json | 31 ++ .../load/model_type/node_type/source-db.json | 44 ++ .../load/model_type/node_type/source-default.json | 18 + .../load/model_type/node_type/source-input.json | 18 + .../load/model_type/node_type/source-rest.json | 61 ++ .../node_type/tosca.nodes.ResourceSource.json | 5 + .../load/resource_dictionary/db-source.json | 26 + .../load/resource_dictionary/default-source.json | 18 + .../load/resource_dictionary/input-source.json | 19 + .../load/resource_dictionary/mdsal-source.json | 36 ++ components/resource-dict/pom.xml | 49 ++ .../resource/dict/ResourceAssignmentProcessor.kt | 34 ++ .../resource/dict/ResourceDefinition.kt | 100 ++++ .../resource/dict/ResourceDictionaryConstants.kt | 34 ++ .../service/ResourceAssignmentEnhancerService.kt | 86 +++ .../service/ResourceAssignmentValidationService.kt | 151 +++++ .../dict/service/ResourceDefinitionRepoService.kt | 61 ++ .../service/ResourceDefinitionValidationService.kt | 114 ++++ .../dict/utils/BulkResourceSequencingUtils.kt | 109 ++++ .../resource/dict/utils/ResourceDictionaryUtils.kt | 78 +++ .../resource/dict/ResourceDefinitionTest.java | 60 ++ .../ResourceAssignmentEnhancerServiceTest.java | 48 ++ .../ResourceAssignmentValidationServiceTest.kt | 57 ++ .../service/ResourceDefinitionRepoServiceTest.java | 36 ++ .../ResourceDefinitionValidationServiceTest.java | 56 ++ .../utils/BulkResourceSequencingUtilsTest.java | 37 ++ .../dict/utils/ResourceDictionaryUtilsTest.java | 99 ++++ .../resources/data/resource-assignment-input.json | 10 + .../src/test/resources/enrich/simple-enrich.json | 37 ++ .../src/test/resources/validation/cyclic.json | 111 ++++ .../src/test/resources/validation/duplicate.json | 110 ++++ .../src/test/resources/validation/success.json | 110 ++++ 119 files changed, 8943 insertions(+) create mode 100644 components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json create mode 100644 components/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json create mode 100644 components/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn create mode 100644 components/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py create mode 100644 components/core/load/blueprints/baseconfiguration/Scripts/__init__.py create mode 100644 components/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta create mode 100644 components/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl create mode 100644 components/core/load/blueprints/baseconfiguration/__init__.py create mode 100644 components/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json create mode 100644 components/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json create mode 100644 components/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json create mode 100644 components/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn create mode 100644 components/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py create mode 100644 components/core/load/blueprints/simple-baseconfig/Scripts/__init__.py create mode 100644 components/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta create mode 100644 components/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl create mode 100644 components/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl create mode 100644 components/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl create mode 100644 components/core/load/blueprints/simple-baseconfig/__init__.py create mode 100644 components/core/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 components/core/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 components/core/load/model_type/artifact_type/artifact-mapping-resource.json create mode 100644 components/core/load/model_type/artifact_type/artifact-script-python.json create mode 100644 components/core/load/model_type/artifact_type/artifact-template-velocity.json create mode 100644 components/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json create mode 100644 components/core/load/model_type/data_type/datatype-property.json create mode 100644 components/core/load/model_type/data_type/datatype-resource-assignment.json create mode 100644 components/core/load/model_type/data_type/dt-license-key.json create mode 100644 components/core/load/model_type/data_type/dt-v4-aggregate.json create mode 100644 components/core/load/model_type/data_type/tosca.datatypes.Credential.json create mode 100644 components/core/load/model_type/node_type/artifact-config-template.json create mode 100644 components/core/load/model_type/node_type/component-config-generator.json create mode 100644 components/core/load/model_type/node_type/component-netconf-executor.json create mode 100644 components/core/load/model_type/node_type/component-resource-assignment.json create mode 100644 components/core/load/model_type/node_type/dg-activate-netconf.json create mode 100644 components/core/load/model_type/node_type/dg-config-generator.json create mode 100644 components/core/load/model_type/node_type/dg-resource-assign-activate.json create mode 100644 components/core/load/model_type/node_type/dg-resource-assignment.json create mode 100644 components/core/load/model_type/node_type/vnf-netconf-device.json create mode 100644 components/core/pom.xml create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt create mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt create mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt create mode 100644 components/core/src/test/resources/componentnode/default.json create mode 100644 components/core/src/test/resources/data/alltype-data.json create mode 100644 components/core/src/test/resources/data/default-context.json create mode 100644 components/core/src/test/resources/dictionary/dictionary_schema.json create mode 100644 components/core/src/test/resources/properties/convert.json create mode 100644 components/core/src/test/resources/properties/default.json create mode 100644 components/parent/pom.xml create mode 100644 components/pom.xml create mode 100644 components/resource-dict/load/model_type/node_type/source-component-java.json create mode 100644 components/resource-dict/load/model_type/node_type/source-db.json create mode 100644 components/resource-dict/load/model_type/node_type/source-default.json create mode 100644 components/resource-dict/load/model_type/node_type/source-input.json create mode 100644 components/resource-dict/load/model_type/node_type/source-rest.json create mode 100644 components/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json create mode 100644 components/resource-dict/load/resource_dictionary/db-source.json create mode 100644 components/resource-dict/load/resource_dictionary/default-source.json create mode 100644 components/resource-dict/load/resource_dictionary/input-source.json create mode 100644 components/resource-dict/load/resource_dictionary/mdsal-source.json create mode 100644 components/resource-dict/pom.xml create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java create mode 100644 components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java create mode 100644 components/resource-dict/src/test/resources/data/resource-assignment-input.json create mode 100644 components/resource-dict/src/test/resources/enrich/simple-enrich.json create mode 100644 components/resource-dict/src/test/resources/validation/cyclic.json create mode 100644 components/resource-dict/src/test/resources/validation/duplicate.json create mode 100644 components/resource-dict/src/test/resources/validation/success.json diff --git a/components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json new file mode 100644 index 000000000..635e177a1 --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json @@ -0,0 +1,411 @@ +{ + "metadata": { + "template_author": "Brinda Santh Muthuramalingam", + "author-email": "brindasanth@gmail.com", + "user-groups" : "ADMIN, OPERATION", + "template_name": "baseconfiguration", + "template_version": "1.0.0", + "template_tags": "brinda, tosca" + }, + "topology_template": { + "inputs": { + "request-id": { + "required": true, + "type": "string" + }, + "action-name": { + "required": true, + "type": "string" + }, + "scope-type": { + "required": true, + "type": "string" + }, + "hostname": { + "required": true, + "type": "string" + } + }, + "node_templates": { + "activate-process": { + "type": "bpmn-activate", + "properties": { + "process-name": { "get_input" : "action-name" }, + "version" : { "get_property" : ["SELF", "process-name"] }, + "content": { "get_artifact" : ["SELF", "activate-process"] } + }, + "artifacts": { + "activate-process": { + "type": "artifact-bpmn-camunda", + "file": "Plans/ActivateProcess.bpmn" + } + } + }, + "resource-assignment": { + "type": "component-resource-assignment", + "properties":{ + "request-id": ["1234", "1234"] + }, + "interfaces": { + "DefaultComponentNode": { + "operations": { + "process": { + "inputs": { + "action-name": { "get_input" : "action-name" }, + "resource-type": "vnf-type", + "request-id": { "get_input" : "request-id" }, + "resource-id": { "get_input" : "hostname" }, + "template-content": { "get_artifact" : ["SELF", "baseconfig-template"] }, + "mapping-content": { "get_artifact" : ["SELF", "baseconfig-mapping"] } + }, + "outputs": { + "resource-assignment-params": "", + "status": "" + } + } + } + } + }, + "artifacts": { + "baseconfig-template": { + "type": "artifact-template-velocity", + "file": "Templates/baseconfig-template.vtl" + }, + "baseconfig-mapping": { + "type": "artifact-mapping-resource", + "file": "Mappings/baseconfig-mapping.json" + } + } + }, + "resource-assignment-py": { + "type": "component-resource-assignment", + "properties":{ + "request-id": ["1234", "1234"] + }, + "interfaces": { + "DefaultComponentNode": { + "operations": { + "process": { + "implementation" :{ + "primary" : "component-script" + }, + "inputs": { + "action-name": { "get_input" : "action-name" } + }, + "outputs": { + "resource-assignment-params": "", + "status": "" + } + } + } + } + }, + "artifacts": { + "component-script": { + "type": "artifact-script-python", + "file": "Scripts/baseconfig-template.vtl" + } + } + } + }, + "workflows":{ + "activate-process":{ + "steps" : { + "call-resource-assignment" : { + "description" : "Invoke Resource Assignment Component", + "target" : "resource-assignment", + "activities" : [ + { + "call_operation": "ResourceAssignmentNode.process" + } + ], + "on_success" : [ + "download-baseconfig" + ] + }, + "download-baseconfig" : { + "description" : "Call Download Base Config Component", + "target" : "activate-netconf", + "activities" : [ + { + "call_operation": "NetconfTransactionNode.process" + } + ], + "on_success" : [ + "download-licence" + ] + }, + "download-licence" : { + "description" : "Call Download Licence Component", + "target" : "activate-netconf", + "activities" : [ + { + "call_operation": "NetconfTransactionNode.process" + } + ] + } + } + } + } + }, + "artifact_types": { + "artifact-template-velocity": { + "description": " Velocity Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "vtl" + ], + "derived_from": "tosca.artifacts.Implementation" + }, + "artifact-mapping-resource": { + "description": " Velocity Template Resource Mapping File used along with Configuration template", + "version": "1.0.0", + "file_ext": [ + "json" + ], + "derived_from": "tosca.artifacts.Implementation" + }, + "artifact-script-kotlin": { + "description": " Kotlin Script Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "kt" + ], + "derived_from": "tosca.artifacts.Implementation" + }, + "artifact-script-python": { + "description": " Kotlin Script Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "py" + ], + "derived_from": "tosca.artifacts.Implementation" + }, + "artifact-bpmn-camunda": { + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" + }, + "artifact-component-jar": { + "description": "Component Jar", + "version": "1.0.0", + "file_ext": [ + "jar" + ], + "derived_from": "tosca.artifacts.Implementation" + } + }, + "node_types": { + "bpmn-activate": { + "description": "This is BPMN Activate node type", + "version": "1.0.0", + "properties": { + "content": { + "required": false, + "type": "string" + }, + "process-name": { + "required": false, + "type": "string" + }, + "version": { + "required": false, + "type": "string", + "default" : "LATEST" + } + }, + "derived_from": "tosca.nodes.Component" + }, + "tosca.nodes.Component": { + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "properties": { + "type": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": false, + "type": "string" + } + }, + "interfaces": { + "DefaultOperation": { + "operations": { + "validate": { + "inputs": { + "action-name": { + "description": "validate for action", + "required": false, + "type": "string" + } + } + } + } + } + }, + "artifacts" :{ + "component-jar": { + "description": "Component Jar", + "type": "artifact-component-jar", + "file": "Component/basecomponent.jar" + } + }, + "derived_from": "tosca.nodes.Root" + }, + "tosca.nodes.component.Python": { + "description": "This is Resource Assignment Python Component API", + "version": "1.0.0", + "properties": { + "type": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": false, + "type": "string" + } + }, + "interfaces": { + "DefaultOperation": { + "operations": { + "validate": { + "inputs": { + "action-name": { + "description": "validate for action", + "required": false, + "type": "string" + } + } + } + } + } + }, + "artifacts" :{ + "component-jar": { + "description": "Component Jar", + "type": "artifact-component-jar", + "file": "Component/basecomponent.jar" + } + }, + "derived_from": "tosca.nodes.Root" + }, + "component-resource-assignment": { + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "properties": { + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + } + }, + "interfaces": { + "DefaultComponentNode": { + "operations": { + "process": { + "inputs": { + "action-name": { + "description": "Recipe Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "resource-type": { + "required": false, + "type": "string" + }, + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + }, + "resource-id": { + "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", + "required": true, + "type": "string" + }, + "template-content": { + "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", + "required": true, + "type": "string" + }, + "mapping-content": { + "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", + "required": true, + "type": "string" + } + }, + "outputs": { + "resource-assignment-params": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" + }, + "component-resource-assignment-python": { + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "properties": { + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + } + }, + "interfaces": { + "DefaultComponentNode": { + "operations": { + "process": { + "inputs": { + "action-name": { + "description": "Recipe Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + } + }, + "outputs": { + "resource-assignment-params": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.component.Python" + } + }, + "data_types": { + "sample-property" : { + "description": "This is sample data type", + "version": "1.0.0", + "properties": { + "content": { + "required": false, + "type": "string" + }, + "process-name": { + "required": false, + "type": "string" + }, + "version": { + "required": false, + "type": "string", + "default" : "LATEST" + } + }, + "derived_from" : "tosca.datatypes.Root" + } + } +} \ No newline at end of file diff --git a/components/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json b/components/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json new file mode 100644 index 000000000..6abfb51bd --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json @@ -0,0 +1,3 @@ +{ + "assignments": "Sample Assignments" +} \ No newline at end of file diff --git a/components/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn b/components/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn new file mode 100644 index 000000000..5e94c0f8e --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn @@ -0,0 +1,66 @@ + + + + + SequenceFlow_0l0dq58 + + + SequenceFlow_1ay0k6p + + + + + + + + + + SequenceFlow_0l0dq58 + SequenceFlow_1ay0k6p + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py b/components/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py new file mode 100644 index 000000000..eb198c79a --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py @@ -0,0 +1,8 @@ +from com.brvith.orchestrator.core.interfaces import ComponentNode + +class SamplePythonComponentNode(ComponentNode): + def prepare(self, context, componentContext): + return None + + def prepare(self, context, componentContext): + return None \ No newline at end of file diff --git a/components/core/load/blueprints/baseconfiguration/Scripts/__init__.py b/components/core/load/blueprints/baseconfiguration/Scripts/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/components/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta b/components/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 000000000..fb38c1594 --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/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/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl b/components/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl new file mode 100644 index 000000000..026c59176 --- /dev/null +++ b/components/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl @@ -0,0 +1 @@ +This is Sample Velocity Template \ No newline at end of file diff --git a/components/core/load/blueprints/baseconfiguration/__init__.py b/components/core/load/blueprints/baseconfiguration/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/components/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json b/components/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json new file mode 100644 index 000000000..6d469ea84 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json @@ -0,0 +1,34 @@ +{ + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "properties": { + "type": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": false, + "type": "string" + } + }, + "interfaces": { + "DefaultOperation": { + "operations": { + "validate": { + "inputs": { + "action-name": { + "description": "validate for action", + "required": false, + "type": "string" + } + } + } + } + } + }, + "artifacts" :{ + "component-jar": { + "description": "Component Jar", + "type": "artifact-component-jar", + "file": "Component/basecomponent.jar" + } + }, + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json b/components/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json new file mode 100644 index 000000000..e78f32f02 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json @@ -0,0 +1,345 @@ +{ + "metadata": { + "template_author": "Brinda Santh", + "template_name": "simple-baseconfig", + "template_version": "1.0.0", + "service-type": "Sample Service", + "release": "1806", + "vnf-type": "VPE" + }, + "topology_template": { + "inputs": { + "request-id": { + "required": true, + "type": "string" + }, + "service-instance-id": { + "required": true, + "type": "string" + }, + "scope-type": { + "required": true, + "type": "string" + }, + "action-name": { + "required": true, + "type": "string" + }, + "hostname": { + "required": true, + "type": "string" + } + }, + "node_templates": { + "vpe-netconf-device": { + "capabilities": { + "netconf": { + "properties": { + "login-key": "sdnc", + "login-account": "sndc-local", + "source": "local", + "target-ip-address": "{\"get_attribute\":\"lo0-local-ipv4-address\"}", + "port-number": 22, + "connection-time-out": 30 + } + } + }, + "type": "vnf-netconf-device" + }, + "activate-netconf-component": { + "capabilities": { + "component-node": {} + }, + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "vpe-netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { + "operations": { + "process": { + "inputs": { + "action-name": "{ \"get_input\" : \"action-name\" }", + "service-template-name": "{ \"get_attribute\" : \"template_name\" }", + "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", + "resource-type": "vnf-type", + "request-id": "{ \"get_input\" : \"request-id\" }", + "resource-id": "{ \"get_input\" : \"hostname\" }", + "execution-script": "execution-script" + }, + "outputs": { + "response-data": "{ \"get_attribute\" : \"netconf-executor-baseconfig.response-data\" }", + "status": "{ \"get_attribute\" : \"netconf-executor-baseconfig.status\" }" + }, + "implementation" : { + "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" + } + } + } + } + }, + "type": "component-netconf-executor" + }, + "resource-assignment-ra-component": { + "capabilities": { + "component-node": {} + }, + "interfaces": { + "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "operations": { + "process": { + "inputs": { + "template-names": [ + "base-config-template", + "licence-template" + ], + "action-name": "{ \"get_input\" : \"action-name\" }", + "service-template-name": "{ \"get_attribute\" : \"template_name\" }", + "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", + "resource-type": "vnf-type", + "request-id": "{ \"get_input\" : \"request-id\" }", + "resource-id": "{ \"get_input\" : \"hostname\" }" + }, + "outputs": { + "resource-assignment-params": "success", + "status": "status" + } + } + } + } + }, + "type": "component-resource-assignment" + }, + "resource-assignment-action": { + "properties": { + "mode": "sync", + "version": "LATEST", + "is-start-flow": "false" + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "resource-assignment-ra-component", + "relationship": "tosca.relationships.DependsOn" + } + }, + "capabilities": { + "dg-node": {}, + "content": { + "properties": { + "type": "json" + } + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignment": { + "inputs": { + "params": [] + } + } + } + } + }, + "type": "dg-resource-assignment" + }, + "activate-action": { + "properties": { + "mode": "sync", + "version": "LATEST", + "is-start-flow": "false" + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "activate-netconf-component", + "relationship": "tosca.relationships.DependsOn" + } + }, + "capabilities": { + "dg-node": {}, + "content": { + "properties": { + "type": "json" + } + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ActivateNetconf": { + "inputs": { + "params": [] + } + } + } + } + }, + "type": "dg-activate-netconf" + }, + "base-config-template": { + "capabilities": { + "content": { + "properties": { + "content": "db://base-config-template" + } + }, + "mapping": { + "properties": { + "mapping": [ + { + "name": "bundle-mac", + "property": { + "description": "", + "required": true, + "type": "string", + "status": "", + "constraints": [ + {} + ], + "entry_schema": { + "type": "" + } + }, + "input-param": false, + "dictionary-name": "bundle-mac", + "dictionary-source": "db", + "dependencies": [ + "hostname" + ], + "version": 0 + }, + { + "name": "wan-aggregate-ipv4-addresses", + "property": { + "description": "", + "required": true, + "type": "list", + "status": "", + "constraints": [ + {} + ], + "entry_schema": { + "type": "dt-v4-aggregate" + } + }, + "input-param": false, + "dictionary-name": "wan-aggregate-ipv4-addresses", + "dictionary-source": "mdsal", + "dependencies": [ + "service-instance-id", + "oam-network-role", + "oam-v4-ip-type ", + "oam-vm-type" + ], + "version": 0 + }, + { + "name": "hostname", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "hostname", + "dictionary-source": "input", + "version": 0, + "input-param": false + }, + { + "name": "service", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service", + "dictionary-source": "input", + "version": 0, + "input-param": false + }, + { + "name": "service-instance-id", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "version": 0, + "input-param": false + } + ] + } + } + }, + "properties": { + "action-names": [ + "resource-assignment-action" + ] + }, + "type": "artifact-config-template" + }, + "licence-template": { + "capabilities": { + "content": { + "properties": { + "content": "db://licence-template" + } + }, + "mapping": { + "properties": { + "mapping": [ + { + "name": "licenses", + "property": { + "description": "", + "required": true, + "type": "list", + "status": "", + "constraints": [ + {} + ], + "entry_schema": { + "type": "dt-license-key" + } + }, + "input-param": false, + "dictionary-name": "licenses", + "dictionary-source": "mdsal", + "dependencies": [ + "service-instance-id" + ], + "version": 0 + }, + { + "name": "service-instance-id", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "version": 0, + "input-param": false + } + ] + } + } + }, + "properties": { + "action-names": [ + "resource-assignment-action" + ] + }, + "type": "artifact-config-template" + } + } + }, + "node_types": { + }, + "data_types": { + } +} \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json b/components/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json new file mode 100644 index 000000000..6abfb51bd --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json @@ -0,0 +1,3 @@ +{ + "assignments": "Sample Assignments" +} \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn b/components/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn new file mode 100644 index 000000000..5e94c0f8e --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn @@ -0,0 +1,66 @@ + + + + + SequenceFlow_0l0dq58 + + + SequenceFlow_1ay0k6p + + + + + + + + + + SequenceFlow_0l0dq58 + SequenceFlow_1ay0k6p + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py b/components/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py new file mode 100644 index 000000000..eb198c79a --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py @@ -0,0 +1,8 @@ +from com.brvith.orchestrator.core.interfaces import ComponentNode + +class SamplePythonComponentNode(ComponentNode): + def prepare(self, context, componentContext): + return None + + def prepare(self, context, componentContext): + return None \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Scripts/__init__.py b/components/core/load/blueprints/simple-baseconfig/Scripts/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/components/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta b/components/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 000000000..d7ae5e8a2 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/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/simple-baseconfig.json +Template-Tags: vrr-test, Brinda Santh + +Name: Plans/ActivateProcess.bpmn +Content-Type: application/vnd.oasis.bpmn diff --git a/components/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl b/components/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl new file mode 100644 index 000000000..92dba1024 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl @@ -0,0 +1,40 @@ + + + + ${group-name} + + + <*> + + + + + + 224.0.1.40/32 + + + 224.0.1.39/32 + + + 224.0.0.0/4 + + + + + + + + + + <*> + + 1000 + + + + + + + + + \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl b/components/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl new file mode 100644 index 000000000..026c59176 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl @@ -0,0 +1 @@ +This is Sample Velocity Template \ No newline at end of file diff --git a/components/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl b/components/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl new file mode 100644 index 000000000..626974f27 --- /dev/null +++ b/components/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl @@ -0,0 +1,4 @@ + + + + diff --git a/components/core/load/blueprints/simple-baseconfig/__init__.py b/components/core/load/blueprints/simple-baseconfig/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/components/core/load/model_type/artifact_type/artifact-bpmn-camunda.json b/components/core/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 000000000..ac76b4f4f --- /dev/null +++ b/components/core/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/components/core/load/model_type/artifact_type/artifact-directed-graph.json b/components/core/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 000000000..7ab3a5434 --- /dev/null +++ b/components/core/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/components/core/load/model_type/artifact_type/artifact-mapping-resource.json b/components/core/load/model_type/artifact_type/artifact-mapping-resource.json new file mode 100644 index 000000000..0a3261b09 --- /dev/null +++ b/components/core/load/model_type/artifact_type/artifact-mapping-resource.json @@ -0,0 +1,8 @@ +{ + "description": " Velocity Template Resource Mapping File used along with Configuration template", + "version": "1.0.0", + "file_ext": [ + "json" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/components/core/load/model_type/artifact_type/artifact-script-python.json b/components/core/load/model_type/artifact_type/artifact-script-python.json new file mode 100644 index 000000000..b48d2b628 --- /dev/null +++ b/components/core/load/model_type/artifact_type/artifact-script-python.json @@ -0,0 +1,8 @@ +{ + "description": " Kotlin Script Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "py" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/components/core/load/model_type/artifact_type/artifact-template-velocity.json b/components/core/load/model_type/artifact_type/artifact-template-velocity.json new file mode 100644 index 000000000..9395d3970 --- /dev/null +++ b/components/core/load/model_type/artifact_type/artifact-template-velocity.json @@ -0,0 +1,8 @@ +{ + "description": " Velocity Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "vtl" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/components/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json b/components/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json new file mode 100644 index 000000000..5a7c95684 --- /dev/null +++ b/components/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for implementation artifacts", + "version": "1.0.0", + "derived_from": "tosca.artifacts.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/data_type/datatype-property.json b/components/core/load/model_type/data_type/datatype-property.json new file mode 100644 index 000000000..5584b10ea --- /dev/null +++ b/components/core/load/model_type/data_type/datatype-property.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0", + "description": "This is Entry point Input Data Type, which is dynamic datatype, The parameter names will be populated during the Design time for each inputs", + "properties": { + "type": { + "required": true, + "type": "string" + }, + "description": { + "required": false, + "type": "string" + }, + "required": { + "required": false, + "type": "boolean" + }, + "default": { + "required": false, + "type": "string" + }, + "entry_schema": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/data_type/datatype-resource-assignment.json b/components/core/load/model_type/data_type/datatype-resource-assignment.json new file mode 100644 index 000000000..cc9816ebb --- /dev/null +++ b/components/core/load/model_type/data_type/datatype-resource-assignment.json @@ -0,0 +1,46 @@ +{ + "version": "1.0.0", + "description": "This is Resource Assignment Data Type", + "properties": { + "property": { + "required": true, + "type": "datatype-property" + }, + "input-param": { + "required": true, + "type": "boolean" + }, + "dictionary-name": { + "required": false, + "type": "string" + }, + "dictionary-source": { + "required": false, + "type": "string" + }, + "dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + }, + "status": { + "required": false, + "type": "string" + }, + "message": { + "required": false, + "type": "string" + }, + "updated-date": { + "required": false, + "type": "string" + }, + "updated-by": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/data_type/dt-license-key.json b/components/core/load/model_type/data_type/dt-license-key.json new file mode 100644 index 000000000..e9c312b79 --- /dev/null +++ b/components/core/load/model_type/data_type/dt-license-key.json @@ -0,0 +1,11 @@ +{ + "version": "1.0.0", + "description": "This is dt-plicense-key Data Type", + "properties": { + "license-key": { + "required": true, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/data_type/dt-v4-aggregate.json b/components/core/load/model_type/data_type/dt-v4-aggregate.json new file mode 100644 index 000000000..842a7f805 --- /dev/null +++ b/components/core/load/model_type/data_type/dt-v4-aggregate.json @@ -0,0 +1,15 @@ +{ + "version": "1.0.0", + "description": "This is dt-v4-aggregate Data Type", + "properties": { + "ipv4-address": { + "required": true, + "type": "string" + }, + "ipv4-plen": { + "required": false, + "type": "integer" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/data_type/tosca.datatypes.Credential.json b/components/core/load/model_type/data_type/tosca.datatypes.Credential.json new file mode 100644 index 000000000..820a55168 --- /dev/null +++ b/components/core/load/model_type/data_type/tosca.datatypes.Credential.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.0", + "description": "Credential", + "properties": { + "protocol": { + "required": false, + "type": "string" + }, + "token_type": { + "required": true, + "type": "string", + "default" : "password" + }, + "token": { + "required": false, + "type": "string" + }, + "keys": { + "required": false, + "type": "list", + "entry_schema": { + "type": "string" + } + }, + "user": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/artifact-config-template.json b/components/core/load/model_type/node_type/artifact-config-template.json new file mode 100644 index 000000000..be9bbfc0e --- /dev/null +++ b/components/core/load/model_type/node_type/artifact-config-template.json @@ -0,0 +1,37 @@ +{ + "description": "This is Configuration Velocity Template", + "version": "1.0.0", + "properties": { + "action-names": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "capabilities": { + "content": { + "type": "tosca.capability.Content", + "properties": { + "content": { + "required": true, + "type": "string" + } + } + }, + "mapping": { + "type": "tosca.capability.Mapping", + "properties": { + "mapping": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-resource-assignment" + } + } + } + } + }, + "derived_from": "tosca.nodes.Artifact" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/component-config-generator.json b/components/core/load/model_type/node_type/component-config-generator.json new file mode 100644 index 000000000..764f9e890 --- /dev/null +++ b/components/core/load/model_type/node_type/component-config-generator.json @@ -0,0 +1,72 @@ +{ + "description": "This is Generate Configuration Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "interfaces": { + "org-openecomp-sdnc-config-generator-service-ConfigGeneratorNode": { + "operations": { + "process": { + "inputs": { + "template-data": { + "description": "Conditional : JSON string which is used to mash with template. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "template-content": { + "description": "Conditional : Dynamic Template used to generate Configuration.", + "required": false, + "type": "string" + }, + "resource-type": { + "description": "Conditional : resource-type used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + }, + "resource-id": { + "description": "Conditional : Id used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "action-name": { + "description": "Conditional : Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "template-name": { + "description": "Conditional : Name of the Artifact Node Template, to get the template Content. If template-content is present, then content wont be reterived from the Artifact Node Template.", + "required": true, + "type": "string" + } + }, + "outputs": { + "generated-config": { + "description": "Generated Configuration for the Template adn Resource Data", + "required": true, + "type": "string" + }, + "mask-info": { + "description": "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.apps.controllerblueprints.core.data.custom.MaskInfo ", + "required": false, + "type": "string" + }, + "status": { + "description": "Status of the Component Execution ( success or failure )", + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/component-netconf-executor.json b/components/core/load/model_type/node_type/component-netconf-executor.json new file mode 100644 index 000000000..aed667aaf --- /dev/null +++ b/components/core/load/model_type/node_type/component-netconf-executor.json @@ -0,0 +1,79 @@ +{ + "description": "This is Netconf Transaction Configuration Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "vnf-netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { + "operations": { + "process": { + "inputs": { + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + }, + "service-template-name": { + "description": "Service Template Name", + "required": true, + "type": "string" + }, + "service-template-version": { + "description": "Service Template Version", + "required": true, + "type": "string" + }, + "action-name": { + "description": "Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "resource-type": { + "description": "Resource Type to get from Database, Either (message & mask-info ) or( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "resource-id": { + "description": "Resource Id to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "reservation-id": { + "description": "Reservation Id used to send to NPM", + "required": false, + "type": "string" + }, + "execution-script": { + "description": "Python Script to Execute for this Component action, It should refer any one of Prython Artifact Definition for this Node Template.", + "required": true, + "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" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/component-resource-assignment.json b/components/core/load/model_type/node_type/component-resource-assignment.json new file mode 100644 index 000000000..34c028482 --- /dev/null +++ b/components/core/load/model_type/node_type/component-resource-assignment.json @@ -0,0 +1,68 @@ +{ + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "interfaces": { + "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "operations": { + "process": { + "inputs": { + "service-template-name": { + "description": "Service Template Name.", + "required": true, + "type": "string" + }, + "service-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" + } + }, + "request-id": { + "description": "Request Id, Unique Id for the request.", + "required": true, + "type": "string" + }, + "resource-id": { + "description": "Resource Id.", + "required": true, + "type": "string" + }, + "action-name": { + "description": "Action Name of the process", + "required": true, + "type": "string" + } + }, + "outputs": { + "resource-assignment-params": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/dg-activate-netconf.json b/components/core/load/model_type/node_type/dg-activate-netconf.json new file mode 100644 index 000000000..c638df00c --- /dev/null +++ b/components/core/load/model_type/node_type/dg-activate-netconf.json @@ -0,0 +1,66 @@ +{ + "description": "This is Download Netconf Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": "false" + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + }, + "content": { + "type": "tosca.capability.Content", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "json" + }, + "content": { + "required": true, + "type": "string" + } + } + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-netconf-executor", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ActivateNetconf": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/dg-config-generator.json b/components/core/load/model_type/node_type/dg-config-generator.json new file mode 100644 index 000000000..28bace0f0 --- /dev/null +++ b/components/core/load/model_type/node_type/dg-config-generator.json @@ -0,0 +1,65 @@ +{ + "description": "This is Activate DG for Config Generator Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": "false" + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + }, + "content": { + "type": "tosca.capability.Content", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "json" + }, + "content": { + "required": true, + "type": "string" + } + } + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-config-generator", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "GenerateConfiguration": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/dg-resource-assign-activate.json b/components/core/load/model_type/node_type/dg-resource-assign-activate.json new file mode 100644 index 000000000..e98fa5a67 --- /dev/null +++ b/components/core/load/model_type/node_type/dg-resource-assign-activate.json @@ -0,0 +1,70 @@ +{ + "description": "This is Resource Assign and Activate Netconf Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": "false" + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + }, + "content": { + "type": "tosca.capability.Content", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "json" + }, + "content": { + "required": false, + "type": "string" + } + } + } + }, + "requirements": { + "ra-component": { + "capability": "component-node", + "node": "component-resource-assignment", + "relationship": "tosca.relationships.DependsOn" + }, + "netconf-component": { + "capability": "component-node", + "node": "component-netconf-executor", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignAndActivate": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/dg-resource-assignment.json b/components/core/load/model_type/node_type/dg-resource-assignment.json new file mode 100644 index 000000000..36fbb6861 --- /dev/null +++ b/components/core/load/model_type/node_type/dg-resource-assignment.json @@ -0,0 +1,65 @@ +{ + "description": "This is Resource Assignment Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": "false" + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + }, + "content": { + "type": "tosca.capability.Content", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "json" + }, + "content": { + "required": false, + "type": "string" + } + } + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-resource-assignment", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignment": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/components/core/load/model_type/node_type/vnf-netconf-device.json b/components/core/load/model_type/node_type/vnf-netconf-device.json new file mode 100644 index 000000000..54573bade --- /dev/null +++ b/components/core/load/model_type/node_type/vnf-netconf-device.json @@ -0,0 +1,42 @@ +{ + "description": "This is VNF Device with Netconf Capability", + "version": "1.0.0", + "capabilities": { + "netconf": { + "type": "tosca.capability.Netconf", + "properties": { + "login-key": { + "required": true, + "type": "string", + "default": "sdnc" + }, + "login-account": { + "required": true, + "type": "string", + "default": "sdnc-tacacs" + }, + "source": { + "required": true, + "type": "string", + "default": "npm" + }, + "target-ip-address": { + "required": true, + "type": "string" + }, + "port-number": { + "required": true, + "type": "integer", + "default": 830 + }, + "connection-time-out": { + "required": false, + "type": "integer", + "default": 30 + } + } + } + }, + "derived_from": "tosca.nodes.Vnf" + +} diff --git a/components/core/pom.xml b/components/core/pom.xml new file mode 100644 index 000000000..fc6624e72 --- /dev/null +++ b/components/core/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + org.onap.ccsdk.apps.components + parent + 0.3.0-SNAPSHOT + ../parent + + org.onap.ccsdk.apps.controllerblueprints + core + Controller Blueprints Core + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.module + jackson-module-jsonSchema + + + io.projectreactor + reactor-core + + + org.yaml + snakeyaml + + + org.jetbrains.kotlin + kotlin-test + test + + + junit + junit + + + + + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt new file mode 100644 index 000000000..4ae1f4d5d --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -0,0 +1,142 @@ +/* + * 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. + * 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 +/** + * BluePrintConstants + * + * @author Brinda Santh + */ +object BluePrintConstants { + + const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID" + const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion" + const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion" + const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion" + + const val TYPE_DEFAULT: String = "default" + + const val DATA_TYPE_STRING: String = "string" + const val DATA_TYPE_INTEGER: String = "integer" + const val DATA_TYPE_FLOAT: String = "float" + const val DATA_TYPE_BOOLEAN: String = "boolean" + const val DATA_TYPE_TIMESTAMP: String = "timestamp" + const val DATA_TYPE_NULL: String = "null" + const val DATA_TYPE_LIST: String = "list" + const val DATA_TYPE_MAP: String = "map" + + const val USER_SYSTEM: String = "System" + + const val MODEL_CONTENT_TYPE_JSON: String = "JSON" + const val MODEL_CONTENT_TYPE_YAML: String = "YAML" + const val MODEL_CONTENT_TYPE_YANG: String = "YANG" + const val MODEL_CONTENT_TYPE_SCHEMA: String = "SCHEMA" + + const val PATH_DIVIDER: String = "/" + const val PATH_INPUTS: String = "inputs" + const val PATH_NODE_WORKFLOWS: String = "workflows" + const val PATH_NODE_TEMPLATES: String = "node_templates" + const val PATH_CAPABILITIES: String = "capabilities" + const val PATH_REQUIREMENTS: String = "requirements" + const val PATH_INTERFACES: String = "interfaces" + const val PATH_OPERATIONS: String = "operations" + const val PATH_OUTPUTS: String = "outputs" + const val PATH_PROPERTIES: String = "properties" + const val PATH_ATTRIBUTES: String = "attributes" + const val PATH_ARTIFACTS: String = "artifacts" + + const val MODEL_DIR_MODEL_TYPE: String = "model_type" + + const val MODEL_DEFINITION_TYPE_NODE_TYPE: String = "node_type" + const val MODEL_DEFINITION_TYPE_ARTIFACT_TYPE: String = "artifact_type" + const val MODEL_DEFINITION_TYPE_CAPABILITY_TYPE: String = "capability_type" + const val MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE: String = "relationship_type" + const val MODEL_DEFINITION_TYPE_DATA_TYPE: String = "data_type" + + const val MODEL_TYPE_DATATYPES_ROOT: String = "tosca.datatypes.Root" + const val MODEL_TYPE_NODES_ROOT: String = "tosca.nodes.Root" + const val MODEL_TYPE_GROUPS_ROOT: String = "tosca.groups.Root" + const val MODEL_TYPE_RELATIONSHIPS_ROOT: String = "tosca.relationships.Root" + const val MODEL_TYPE_ARTIFACTS_ROOT: String = "tosca.artifacts.Root" + const val MODEL_TYPE_CAPABILITIES_ROOT: String = "tosca.capabilities.Root" + const val MODEL_TYPE_INTERFACES_ROOT: String = "tosca.interfaces.Root" + + const val MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON = "tosca.relationships.DependsOn" + const val MODEL_TYPE_RELATIONSHIPS_HOSTED_ON = "tosca.relationships.HostedOn" + const val MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO = "tosca.relationships.ConnectsTo" + const val MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo" + const val MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo" + + const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG" + const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component" + const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf" + @Deprecated("Artifacts will be attached to Node Template") + const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" + const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource" + + const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java" + const val MODEL_TYPE_NODES_COMPONENT_BUNDLE: String = "tosca.nodes.component.Bundle" + const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script" + const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python" + const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript" + + const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" + + const val EXPRESSION_GET_INPUT: String = "get_input" + const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute" + const val EXPRESSION_GET_ARTIFACT: String = "get_artifact" + const val EXPRESSION_GET_PROPERTY: String = "get_property" + const val EXPRESSION_GET_OPERATION_OUTPUT: String = "get_operation_output" + const val EXPRESSION_GET_NODE_OF_TYPE: String = "get_nodes_of_type" + + const val PROPERTY_BLUEPRINT_PROCESS_ID: String = "blueprint-process-id" + const val PROPERTY_BLUEPRINT_BASE_PATH: String = "blueprint-basePath" + const val PROPERTY_BLUEPRINT_RUNTIME: String = "blueprint-runtime" + const val PROPERTY_BLUEPRINT_INPUTS_DATA: String = "blueprint-inputs-data" + const val PROPERTY_BLUEPRINT_CONTEXT: String = "blueprint-context" + const val PROPERTY_BLUEPRINT_NAME: String = "template_name" + const val PROPERTY_BLUEPRINT_VERSION: String = "template_version" + + const val TOSCA_METADATA_ENTRY_DEFINITION_FILE: String = "TOSCA-Metadata/TOSCA.meta" + const val TOSCA_PLANS_DIR: String = "Plans" + const val TOSCA_SCRIPTS_DIR: String = "Scripts" + const val TOSCA_MAPPINGS_DIR: String = "Mappings" + const val TOSCA_TEMPLATES_DIR: String = "Templates" + + const val METADATA_USER_GROUPS = "user-groups" + const val METADATA_TEMPLATE_NAME = "template_name" + const val METADATA_TEMPLATE_VERSION = "template_version" + const val METADATA_TEMPLATE_AUTHOR = "template_author" + const val METADATA_TEMPLATE_TAGS = "template_tags" + + const val PAYLOAD_CONTENT = "payload-content" + const val PAYLOAD_DATA = "payload-data" + const val SELECTOR = "selector" + const val PROPERTY_CURRENT_INTERFACE = "current-interface" + const val PROPERTY_CURRENT_OPERATION = "current-operation" + const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation" + + const val PROPERTY_ACTION_NAME = "action" + + const val OPERATION_PROCESS = "process" + const val OPERATION_PREPARE = "prepare" + + const val BLUEPRINT_RETRIEVE_TYPE_DB = "db" + const val BLUEPRINT_RETRIEVE_TYPE_FILE = "file" + const val BLUEPRINT_RETRIEVE_TYPE_REPO = "repo" + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt new file mode 100644 index 000000000..5c386c214 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core +/** + * + * + * @author Brinda Santh + */ +class BluePrintException : Exception { + + var code: Int = 100 + + constructor(cause: Throwable) : super(cause) + constructor(message: String) : super(message) + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) + : super(String.format(message, *args), cause) { + this.code = code + } +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt new file mode 100644 index 000000000..50717031d --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt @@ -0,0 +1,49 @@ +/* + * 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. + * 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 +/** + * + * + * @author Brinda Santh + */ +class BluePrintProcessorException : Exception { + var code: Int = 100 + + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(message: String) : super(message) + constructor(cause: Throwable) : super(cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) + : super(String.format(message, *args), cause) { + this.code = code + } +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt new file mode 100644 index 000000000..33c811f4a --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -0,0 +1,91 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core + +/** + * + * + * @author Brinda Santh + */ +object BluePrintTypes { + + @JvmStatic + fun validModelTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + return validTypes + } + + @JvmStatic + fun validPropertyTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_STRING) + validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) + validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) + validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) + validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) + validTypes.add(BluePrintConstants.DATA_TYPE_NULL) + validTypes.add(BluePrintConstants.DATA_TYPE_LIST) + return validTypes + } + + @JvmStatic + fun validPrimitiveTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_STRING) + validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) + validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) + validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) + validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) + validTypes.add(BluePrintConstants.DATA_TYPE_NULL) + return validTypes + } + + @JvmStatic + fun validCollectionTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_LIST) + validTypes.add(BluePrintConstants.DATA_TYPE_MAP) + return validTypes + } + + @JvmStatic + fun validCommands(): List { + return listOf(BluePrintConstants.EXPRESSION_GET_INPUT, + BluePrintConstants.EXPRESSION_GET_ATTRIBUTE, + BluePrintConstants.EXPRESSION_GET_PROPERTY, + BluePrintConstants.EXPRESSION_GET_ARTIFACT, + BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT, + BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE) + } + + @JvmStatic + fun rootNodeTypes(): List { + return listOf(BluePrintConstants.MODEL_TYPE_NODES_ROOT) + } + + @JvmStatic + fun rootDataTypes(): List { + return listOf(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT) + } + + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt new file mode 100644 index 000000000..845922040 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -0,0 +1,44 @@ +/* + * 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. + * 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 + +/** + * + * + * @author Brinda Santh + */ +object ConfigModelConstant { + + const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON" + const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE" + + const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" + + const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" + + const val MODEL_TYPE_CAPABILITY_NETCONF = "tosca.capability.Netconf" + const val MODEL_TYPE_CAPABILITY_SSH = "tosca.capability.Ssh" + const val MODEL_TYPE_CAPABILITY_SFTP = "tosca.capability.Sftp" + const val MODEL_TYPE_CAPABILITY_CHEF = "tosca.capability.Chef" + const val MODEL_TYPE_CAPABILITY_ANSIBLEF = "tosca.capability.Ansible" + + const val CAPABILITY_PROPERTY_MAPPING = "mapping" + + const val PROPERTY_RECIPE_NAMES = "action-names" + +} diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt new file mode 100644 index 000000000..7302f2b96 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt @@ -0,0 +1,75 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core + +import org.slf4j.helpers.MessageFormatter +import java.io.File +import java.io.InputStream +import kotlin.reflect.KClass + +/** + * + * + * @author Brinda Santh + */ + +fun format(message: String, vararg args: Any?) : String{ + if(args != null && args.isNotEmpty()){ + return MessageFormatter.arrayFormat(message, args).message + } + return message +} + +fun MutableMap.getCastOptionalValue(key: String, valueType: KClass): T? { + if (containsKey(key)) { + return get(key) as? T + } else { + return null + } +} + +fun MutableMap.getCastValue(key: String, valueType: KClass): T { + if (containsKey(key)) { + return get(key) as T + } else { + throw BluePrintException("couldn't find the key " + key) + } +} + +fun checkNotEmpty(value : String?) : Boolean{ + return value != null && value.isNotEmpty() +} + +fun checkNotEmptyNThrow(value : String?, message : String? = value.plus(" is null/empty ")) : Boolean{ + val notEmpty = value != null && value.isNotEmpty() + if(!notEmpty){ + throw BluePrintException(message!!) + } + return notEmpty +} + +fun InputStream.toFile(path: String) : File { + val file = File(path) + file.outputStream().use { this.copyTo(it) } + return file +} + + + + + + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt new file mode 100644 index 000000000..c0eb13f92 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.data + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ObjectNode +/** + * + * + * @author Brinda Santh + */ +data class ExpressionData( + var isExpression: Boolean = false, + var valueNode: JsonNode, + var expressionNode: ObjectNode? = null, + var inputExpression: InputExpression? = null, + var propertyExpression: PropertyExpression? = null, + var attributeExpression: AttributeExpression? = null, + var artifactExpression: ArtifactExpression? = null, + var operationOutputExpression: OperationOutputExpression? = null, + var command: String? = null +) + +data class InputExpression( + var propertyName: String +) + +data class PropertyExpression( + var modelableEntityName: String = "SELF", + var reqOrCapEntityName: String? = null, + var propertyName: String, + var subPropertyName: String? = null +) + +data class AttributeExpression( + var modelableEntityName: String = "SELF", + var reqOrCapEntityName: String? = null, + var attributeName: String, + var subAttributeName: String? = null +) + +data class ArtifactExpression( + val modelableEntityName: String = "SELF", + val artifactName: String, + val location: String? = "LOCAL_FILE", + val remove: Boolean? = false +) + +data class OperationOutputExpression( + val modelableEntityName: String = "SELF", + val interfaceName: String, + val operationName: String, + val propertyName: String +) + + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt new file mode 100644 index 000000000..ef8bbf2d6 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -0,0 +1,612 @@ +/* + * 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. + * 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.data + +import com.fasterxml.jackson.annotation.JsonIgnore +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.ApiModelProperty + +/** + * + * + * @author Brinda Santh + */ +open class EntityType { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var version: String = "1.0.0" + var metadata: MutableMap? = null + @get:JsonProperty("derived_from") + lateinit var derivedFrom: String + var attributes: MutableMap? = null + var properties: MutableMap? = null +} + +/* + 5.3.2 tosca.datatypes.Credential + The Credential type is a complex TOSCA data Type used when describing + authorization credentials used to access network accessible resources. + */ +class Credential { + @get:JsonIgnore + var id: String? = null + var protocol: String? = null + @get:JsonProperty("token_type") + lateinit var tokenType: String + lateinit var token: String + var keys: MutableMap? = null + lateinit var user: String +} + +/* +3.5.2 Constraint clause +A constraint clause defines an operation along with one or more compatible values that can be used to define a constraint on a property or parameter’s allowed values when it is defined in a TOSCA Service Template or one of its entities. + */ +class ConstraintClause { + @get:JsonProperty("equal") + var equal: JsonNode? = null + @get:JsonProperty("greater_than") + var greaterThan: Any? = null + @get:JsonProperty("greater_or_equal") + var greaterOrEqual: Any? = null + @get:JsonProperty("less_than") + var lessThan: Any? = null + @get:JsonProperty("less_or_equal") + var lessOrEqual: Any? = null + @get:JsonProperty("in_range") + var inRange: Any? = null + @get:JsonProperty("valid_values") + var validValues: MutableList? = null + @get:JsonProperty("length") + var length: Any? = null + @get:JsonProperty("min_length") + var minLength: Any? = null + @get:JsonProperty("max_length") + var maxLength: Any? = null + var pattern: String? = null + var schema: String? = null +} + +/* +3.5.4 Node Filter definition +A node filter definition defines criteria for selection of a TOSCA Node Template based upon the template’s property values, capabilities and capability properties. + */ + +class NodeFilterDefinition { + var properties: MutableMap? = null + var capabilities : MutableList? = null +} + +/* +3.5.5 Repository definition + A repository definition defines a named external repository which contains deployment + and implementation artifacts that are referenced within the TOSCA Service Template. +*/ +class RepositoryDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + lateinit var url: String + var credential: Credential? = null +} + + +/* +3.5.6 Artifact definition +An artifact definition defines a named, typed file that can be associated with Node Type +or Node Template and used by orchestration engine to facilitate deployment and implementation of interface operations. + */ +class ArtifactDefinition { + @get:JsonIgnore + var id: String? = null + var type: String? = null + var file: String? = null + var repository: String? = null + var description: String? = null + @get:JsonProperty("deploy_Path") + var deployPath: String? = null + var properties: MutableMap? = null + var content: String? = null + @Deprecated("Mapping content is define by the Type") + var mappingContent: String? = null +} + + +/* +3.5.7 Import definition +An import definition is used within a TOSCA Service Template to locate and uniquely name +another TOSCA Service Template file which has type and template definitions to be imported (included) +and referenced within another Service Template. + */ +class ImportDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var file: String + var repository: String? = null + @get:JsonProperty("namespace_uri") + var namespaceUri: String? = null + @get:JsonProperty("namespace_prefix") + var namespacePrefix: String? = null +} + +/* +3.5.8 Property definition A property definition defines a named, typed value and related data that can be associated with an +entity defined in this specification (e.g., Node Types, Relationship Types, Capability Types, etc.). +Properties are used by template authors to provide input values to TOSCA entities which indicate their “desired state” when they are +instantiated. The value of a property can be retrieved using the get_property function within TOSCA Service Templates. + */ +class PropertyDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var required: Boolean? = null + lateinit var type: String + @get:JsonProperty("default") + var defaultValue: JsonNode? = null + var status: String? = null + var constraints: MutableList? = null + @get:JsonProperty("entry_schema") + var entrySchema: EntrySchema? = null + @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") + var value: JsonNode? = null +} + + +/* +3.5.10 Attribute definition + +An attribute definition defines a named, typed value that can be associated with an entity defined in this +specification (e.g., a Node, Relationship or Capability Type). Specifically, it is used to expose the +“actual state” of some property of a TOSCA entity after it has been deployed and instantiated +(as set by the TOSCA orchestrator). Attribute values can be retrieved via the get_attribute function +from the instance model and used as values to other entities within TOSCA Service Templates. + */ + +class AttributeDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + lateinit var type: String + @JsonProperty("default") + var defaultValue: JsonNode? = null + var status: String? = null + @JsonProperty("entry_schema") + var entrySchema: String? = null +} + +/* +3.5.13 Operation definition +An operation definition defines a named function or procedure that can be bound to an implementation artifact (e.g., a script). + */ +class OperationDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var implementation: Implementation? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null +} + +class Implementation { + lateinit var primary: String + var dependencies: MutableList? = null +} + +/* +3.5.14 Interface definition +An interface definition defines a named interface that can be associated with a Node or Relationship Type + */ +class InterfaceDefinition { + @get:JsonIgnore + var id: String? = null + var type: String? = null + var operations: MutableMap? = null + var inputs: MutableMap? = null +} + +/* +3.5.15 Event Filter definition +An event filter definition defines criteria for selection of an attribute, for the purpose of monitoring it, within a TOSCA entity, or one its capabilities. + */ +class EventFilterDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var node: String + var requirement: String? = null + var capability: String? = null +} + +/* +3.5.16 Trigger definition TODO +A trigger definition defines the event, condition and action that is used to “trigger” a policy it is associated with. + */ +class TriggerDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + @get:JsonProperty("event_type") + lateinit var eventType: String + @get:JsonProperty("target_filter") + var targetFilter: EventFilterDefinition? = null + var condition: ConditionClause? = null + var constraint: ConditionClause? = null + var method: String? = null + lateinit var action: String +} + +/* + 3.5.17 Workflow activity definition + A workflow activity defines an operation to be performed in a TOSCA workflow. Activities allows to: + · Delegate the workflow for a node expected to be provided by the orchestrator + · Set the state of a node + · Call an operation defined on a TOSCA interface of a node, relationship or group + · Inline another workflow defined in the topology (to allow reusability) + */ +class Activity { + var delegate: String? = null + @get:JsonProperty("set_state") + var setState: String? = null + @get:JsonProperty("call_operation") + var callOperation: String? = null + var inlines: ArrayList? = null +} + +/* +3.5.20 Workflow precondition definition +A workflow condition can be used as a filter or precondition to check if a workflow can be processed or not based on the state of the instances of a TOSCA topology deployment. When not met, the workflow will not be triggered. + */ +class PreConditionDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var target: String + @get:JsonProperty("target_relationship") + lateinit var targetRelationship: String + lateinit var condition: ArrayList +} + +/* +3.5.21 Workflow step definition +A workflow step allows to define one or multiple sequenced activities in a workflow and how they are connected to other steps in the workflow. They are the building blocks of a declarative workflow. + */ +class Step { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var target: String? = null + @JsonProperty("target_relationship") + var targetRelationship: String? = null + @JsonProperty("operation_host") + var operationHost: String? = null + var activities: ArrayList? = null + @get:JsonProperty("on_success") + var onSuccess: ArrayList? = null + @get:JsonProperty("on_failure") + var onFailure: ArrayList? = null +} + +/* +3.6.2 Capability definition +A capability definition defines a named, typed set of data that can be associated with Node Type or Node Template to describe a transparent capability or feature of the software component the node describes. + */ + +class CapabilityDefinition { + @get:JsonIgnore + var id: String? = null + var type: String? = null + var description: String? = null + var properties: MutableMap? = null + @get:JsonProperty("valid_source_types") + var validSourceTypes: MutableList? = null + var occurrences: MutableList? = null +} + +/* +3.6.3 Requirement definition +The Requirement definition describes a named requirement (dependencies) of a TOSCA Node Type or Node template which needs to be fulfilled by a matching Capability definition declared by another TOSCA modelable entity. The requirement definition may itself include the specific name of the fulfilling entity (explicitly) or provide an abstract type, along with additional filtering characteristics, that a TOSCA orchestrator can use to fulfill the capability at runtime (implicitly). + */ +class RequirementDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var capability: String? = null + var node: String? = null + var relationship: String? = null + var occurrences: MutableList? = null +} + +/* +3.6.4 Artifact Type +An Artifact Type is a reusable entity that defines the type of one or more files that are used to define implementation or deployment artifacts that are referenced by nodes or relationships on their operations. + */ +class ArtifactType : EntityType() { + @get:JsonProperty("mime_type") + var mimeType: String? = null + @get:JsonProperty("file_ext") + var fileExt: MutableList? = null + +} + +/* +3.6.6 Data Type +A Data Type definition defines the schema for new named datatypes in TOSCA. + */ + +class DataType : EntityType(){ + var constraints: MutableList? = null +} + +/* +3.6.9 Node Type +A Node Type is a reusable entity that defines the type of one or more Node Templates. As such, a Node Type defines the structure of observable properties via a Properties Definition, the Requirements and Capabilities of the node as well as its supported interfaces. + + */ + +class NodeType : EntityType() { + var capabilities: MutableMap? = null + var requirements: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null +} + +/* +3.6.8 Requirement Type +A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose. The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types along with a named Feature notation. + */ + +class RequirementType : EntityType() { + var requirements: MutableMap? = null + var capabilities: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null +} + +/* +3.6.10 Relationship Type +A Relationship Type is a reusable entity that defines the type of one or more relationships between Node Types or Node Templates. +*/ + +class RelationshipType : EntityType() { + var interfaces: MutableMap? = null + @get:JsonProperty("valid_target_types") + var validTargetTypes: ArrayList? = null +} + +/* +3.6.11 Group Type +A Group Type defines logical grouping types for nodes, typically for different management purposes. +Groups can effectively be viewed as logical nodes that are not part of the physical deployment topology + of an application, yet can have capabilities and the ability to attach policies and interfaces + that can be applied (depending on the group type) to its member nodes. + */ + +class GroupType : EntityType() { + var members: MutableList? = null + var requirements: ArrayList? = null + var capabilities: MutableMap? = null + var interfaces: MutableMap? = null + +} + +/* + 3.6.12 Policy Type + A Policy Type defines a type of requirement that affects or governs an application or service’s + topology at some stage of its lifecycle, but is not explicitly part of the topology itself + (i.e., it does not prevent the application or service from being deployed or run if it did not exist). + */ +class PolicyType : EntityType(){ + lateinit var targets: MutableList +} + +/* +3.7.1 Capability assignment +A capability assignment allows node template authors to assign values to properties and attributes for a named capability definition that is part of a Node Template’s type definition. + */ +class CapabilityAssignment { + @get:JsonIgnore + var id: String? = null + var attributes: MutableMap? = null + var properties: MutableMap? = null +} + +/* +3.7.4 Relationship Template +A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. + */ +class GroupDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var type: String + var description: String? = null + var metadata : MutableMap? = null + var properties : MutableMap? = null + var members = ArrayList() + var interfaces : MutableMap?= null +} + +/* +3.7.6 Policy definition +A policy definition defines a policy that can be associated with a TOSCA topology or top-level entity definition (e.g., group definition, node template, etc.). + */ +class PolicyDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var type: String + var description: String? = null + var metadata: MutableMap? = null + var properties: MutableMap? = null + var targets: MutableList? = null +} + + +/* +3.8 Topology Template definition +This section defines the topology template of a cloud application. The main ingredients of the topology template are node templates representing components of the application and relationship templates representing links between the components. These elements are defined in the nested node_templates section and the nested relationship_templates sections, respectively. Furthermore, a topology template allows for defining input parameters, output parameters as well as grouping of node templates. + */ +class TopologyTemplate { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var inputs: MutableMap? = null + @get:JsonProperty("node_templates") + var nodeTemplates: MutableMap? = null + @get:JsonProperty("relationship_templates") + var relationshipTemplates: MutableMap? = null + var policies: MutableMap? = null + var outputs: MutableMap? = null + @get:JsonProperty("substitution_mappings") + var substitutionMappings: Any? = null + var workflows: MutableMap? = null +} + +class SubstitutionMapping { + @get:JsonProperty("node_type") + lateinit var nodeType: String + lateinit var capabilities: ArrayList + lateinit var requirements: ArrayList +} + +class EntrySchema { + lateinit var type: String + var constraints: MutableList? = null +} + +class InterfaceAssignment { + @get:JsonIgnore + var id: String? = null + var operations: MutableMap? = null + var inputs: MutableMap? = null +} + +/* +3.7.3 Node Template +A Node Template specifies the occurrence of a manageable software component as part of an application’s topology model which is defined in a TOSCA Service Template. A Node template is an instance of a specified Node Type and can provide customized properties, constraints or operations which override the defaults provided by its Node Type and its implementations. + */ + +class NodeTemplate { + @get:JsonIgnore + var id: String? = null + var description: String? = null + lateinit var type: String + var metadata: MutableMap? = null + var directives: MutableList? = null + //@get:JsonSerialize(using = PropertyDefinitionValueSerializer::class) + var properties: MutableMap? = null + var attributes: MutableMap? = null + var capabilities: MutableMap? = null + var requirements: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null + @get:JsonProperty("node_filter") + var nodeFilter: NodeFilterDefinition? = null + var copy: String? = null +} + +class OperationAssignment { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var implementation: Implementation? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null +} + +/* +3.7.4 Relationship Template +A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. + */ + +class RelationshipTemplate { + var type: String? = null + var description: String? = null + var metadata: MutableMap? = null + var properties: MutableMap? = null + var attributes: MutableMap? = null + var interfaces: MutableMap? = null + var copy: String? = null +} + +/* +3.7.2 Requirement assignment +A Requirement assignment allows template authors to provide either concrete names of TOSCA templates or provide abstract selection criteria for providers to use to find matching TOSCA templates that are used to fulfill a named requirement’s declared TOSCA Node Type. + */ + +class RequirementAssignment { + @get:JsonIgnore + var id: String? = null + var capability: String? = null + var node: String? = null + //Relationship Type or Relationship Template + var relationship: String? = null +} + + +class Workflow { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var steps: MutableMap? = null + var preconditions: ArrayList? = null + var inputs: MutableMap? = null +} + + +class ConditionClause { + var and: ArrayList>? = null + var or: ArrayList>? = null + @get:JsonProperty("assert") + var assertConditions: ArrayList>? = null +} + +/* +3.9 Service Template definition +A TOSCA Service Template (YAML) document contains element definitions of building blocks for cloud application, or complete models of cloud applications. This section describes the top-level structural elements (TOSCA keynames) along with their grammars, which are allowed to appear in a TOSCA Service Template document. + */ + +class ServiceTemplate { + @get:JsonIgnore + var id: String? = null + @get:JsonProperty("tosca_definitions_version") + var toscaDefinitionsVersion: String = "controller_blueprint_1_0_0" + var metadata: MutableMap? = null + var description: String? = null + @get:JsonProperty("dsl_definitions") + var dslDefinitions: MutableMap? = null + var repositories: MutableMap? = null + var imports: MutableList? = null + @get:JsonProperty("artifact_types") + var artifactTypes: MutableMap? = null + @get:JsonProperty("data_types") + var dataTypes: MutableMap? = null + @get:JsonProperty("node_types") + var nodeTypes: MutableMap? = null + @get:JsonProperty("policy_types") + var policyTypes: PolicyType? = null + @get:JsonProperty("topology_template") + var topologyTemplate: TopologyTemplate? = null +} + +class ToscaMetaData { + lateinit var toscaMetaFileVersion: String + lateinit var csarVersion: String + lateinit var createdBy: String + lateinit var entityDefinitions: String + var templateTags: String? = null +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt new file mode 100644 index 000000000..d796597be --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.factory + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager + + +/** + * BluePrintEnhancerFactory + * @author Brinda Santh + * + */ + +object BluePrintEnhancerFactory { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + var bluePrintEnhancerServices: MutableMap = HashMap() + + fun register(key: String, bluePrintEnhancerService: BluePrintEnhancerService) { + bluePrintEnhancerServices[key] = bluePrintEnhancerService + } + + /** + * Called by clients to get a Blueprint Parser for the Blueprint parser type + */ + fun instance(key: String): BluePrintEnhancerService? { + return bluePrintEnhancerServices.get(key) + } +} diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt new file mode 100644 index 000000000..83233abc1 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.factory + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintParserDefaultService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintParserService +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager + +/** + * + * BluePrintParserFactory + * @author Brinda Santh + */ + +object BluePrintParserFactory { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + var bluePrintParserServices: MutableMap = HashMap() + + init { + log.info("Initialised default BluePrintParser Service ") + bluePrintParserServices.put(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT, BluePrintParserDefaultService()) + } + + fun register(key:String, bluePrintParserService: BluePrintParserService){ + bluePrintParserServices.put(key, bluePrintParserService) + } + + /** + * Called by clients to get a Blueprint Parser for the Blueprint parser type + */ + fun instance(key : String) : BluePrintParserService? { + return bluePrintParserServices.get(key) + } +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt new file mode 100644 index 000000000..63f788a2f --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.factory + + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorService + +/** + * + * + * @author Brinda Santh + */ + +object BluePrintValidatorFactory { + + var bluePrintValidatorServices: MutableMap = HashMap() + + init { + bluePrintValidatorServices[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT] = BluePrintValidatorDefaultService() + } + + fun register(key:String, bluePrintValidatorService: BluePrintValidatorService){ + bluePrintValidatorServices[key] = bluePrintValidatorService + } + + fun instance(key : String) : BluePrintValidatorService?{ + return bluePrintValidatorServices[key] + } + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt new file mode 100644 index 000000000..065176342 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt @@ -0,0 +1,117 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +/** + * + * + * @author Brinda Santh + */ +class BluePrintChainedService { + var bpc : BluePrintContext + + constructor(bpc : BluePrintContext){ + this.bpc = bpc + } + + fun nodeTypeChained(nodeTypeName: String): NodeType { + + val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) + val attributes = hashMapOf() + val properties = hashMapOf() + val requirements = hashMapOf() + val capabilities = hashMapOf() + val interfaces = hashMapOf() + val artifacts = hashMapOf() + + recNodeTypesChained(nodeTypeName).forEach { nodeType -> + + val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes + if (subAttributes != null) { + attributes.putAll(subAttributes) + } + + val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties + if (subProperties != null) { + properties.putAll(subProperties) + } + + val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements + if (subRequirements != null) { + requirements.putAll(subRequirements) + } + val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities + if (subCapabilities != null) { + capabilities.putAll(subCapabilities) + } + val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces + if (subInterfaces != null) { + interfaces.putAll(subInterfaces) + } + + val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts + if (subArtifacts != null) { + artifacts.putAll(subArtifacts) + } + } + nodeType.attributes = attributes + nodeType.properties = properties + nodeType.requirements = requirements + nodeType.capabilities = capabilities + nodeType.interfaces = interfaces + nodeType.artifacts = artifacts + return nodeType + } + + fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { + val nodeType = bpc.nodeTypeByName(nodeTypeName) + val properties = hashMapOf() + + recNodeTypesChained(nodeTypeName).forEach { nodeType -> + val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties + if (subProperties != null) { + properties.putAll(subProperties) + } + } + return properties + } + + private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList? = arrayListOf()): MutableList { + val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) + nodeType.id = nodeTypeName + val derivedFrom: String = nodeType.derivedFrom + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + recNodeTypesChained(derivedFrom, nodeTypes) + } + nodeTypes!!.add(nodeType) + return nodeTypes + } + + private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList? = arrayListOf()): MutableList { + val dataType: DataType = bpc.dataTypeByName(dataTypeName)!! + dataType.id = dataTypeName + val derivedFrom: String = dataType.derivedFrom + if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) { + recDataTypesChained(derivedFrom, dataTypes) + } + dataTypes!!.add(dataType) + return dataTypes + } + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt new file mode 100644 index 000000000..875cbea61 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -0,0 +1,177 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +/** + * + * + * @author Brinda Santh + */ +class BluePrintContext(serviceTemplate: ServiceTemplate) { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + val serviceTemplate: ServiceTemplate = serviceTemplate + + val imports: List? = serviceTemplate.imports + + val metadata: MutableMap? = serviceTemplate.metadata + + val dataTypes: MutableMap? = serviceTemplate.dataTypes + + val inputs: MutableMap? = serviceTemplate.topologyTemplate?.inputs + + val workflows: MutableMap? = serviceTemplate.topologyTemplate?.workflows + + fun blueprintJson(pretty: Boolean = false): String = print("json", pretty) + + fun blueprintYaml(pretty: Boolean = false): String = print("yaml", pretty) + + private fun print(type: String? = "json", pretty: Boolean = false): String { + return JacksonUtils.getJson(serviceTemplate, pretty) + } + + // Workflow + fun workflowByName(name: String): Workflow? = workflows?.get(name) + + // Data Type + fun dataTypeByName(name: String): DataType? = dataTypes?.get(name) + + // Artifact Type + val artifactTypes: MutableMap? = serviceTemplate.artifactTypes + + // Node Type Methods + val nodeTypes: MutableMap? = serviceTemplate.nodeTypes + + fun nodeTypeByName(name: String): NodeType = + nodeTypes?.get(name) ?: throw BluePrintException(String.format("Failed to get node type for the name : %s", name)) + + fun nodeTypeDerivedFrom(name: String): MutableMap? { + return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() + } + + fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? { + return nodeTypeByName(nodeTypeName).interfaces?.values?.first() + } + + fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? { + return nodeTypeInterface(nodeTypeName, interfaceName)?.operations?.get(operationName) + } + + fun interfaceNameForNodeType(nodeTypeName: String): String? { + return nodeTypeByName(nodeTypeName).interfaces?.keys?.first() + } + + fun nodeTypeInterfaceOperationInputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.inputs + } + + fun nodeTypeInterfaceOperationOutputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.outputs + } + + // Node Template Methods + val nodeTemplates: MutableMap? = serviceTemplate.topologyTemplate?.nodeTemplates + + fun nodeTemplateByName(name: String): NodeTemplate = + nodeTemplates?.get(name) ?: throw BluePrintException("Failed to get node template for the name " + name) + + fun nodeTemplateForNodeType(name: String): MutableMap? { + return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() + } + + fun nodeTemplateNodeType(nodeTemplateName: String): NodeType { + val nodeTemplateType: String = nodeTemplateByName(nodeTemplateName).type + return nodeTypeByName(nodeTemplateType) + } + + fun nodeTemplateProperty(nodeTemplateName: String, propertyName: String): Any? { + return nodeTemplateByName(nodeTemplateName).properties?.get(propertyName) + } + + fun nodeTemplateArtifacts(nodeTemplateName: String): MutableMap? { + return nodeTemplateByName(nodeTemplateName).artifacts + } + + fun nodeTemplateArtifact(nodeTemplateName: String, artifactName: String): ArtifactDefinition? { + return nodeTemplateArtifacts(nodeTemplateName)?.get(artifactName) + } + + fun nodeTemplateFirstInterface(nodeTemplateName: String): InterfaceAssignment? { + return nodeTemplateByName(nodeTemplateName).interfaces?.values?.first() + } + + fun nodeTemplateFirstInterfaceName(nodeTemplateName: String): String? { + return nodeTemplateByName(nodeTemplateName).interfaces?.keys?.first() + } + + fun nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName: String): String? { + return nodeTemplateFirstInterface(nodeTemplateName)?.operations?.keys?.first() + } + + fun nodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.inputs + } + + fun nodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.outputs + } + + fun nodeTemplateInterface(nodeTemplateName: String, interfaceName: String): InterfaceAssignment? { + return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName) + } + + + fun nodeTemplateInterfaceOperation(nodeTemplateName: String, interfaceName: String, operationName: String): OperationAssignment? { + return nodeTemplateInterface(nodeTemplateName, interfaceName)?.operations?.get(operationName) + } + + fun nodeTemplateCapability(nodeTemplateName: String, capabilityName: String): CapabilityAssignment? { + return nodeTemplateByName(nodeTemplateName).capabilities?.get(capabilityName) + } + + fun nodeTemplateRequirement(nodeTemplateName: String, requirementName: String): RequirementAssignment? { + return nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName) + } + + fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate { + val nodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node + ?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName)) + return nodeTemplateByName(nodeTemplateName) + } + + fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? { + return nodeTemplateCapability(nodeTemplateName, capabilityName)?.properties?.get(propertyName) + } + + // Chained Functions + + fun nodeTypeChained(nodeTypeName: String): NodeType { + return BluePrintChainedService(this).nodeTypeChained(nodeTypeName) + } + + fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { + return BluePrintChainedService(this).nodeTypeChainedProperties(nodeTypeName) + } + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt new file mode 100644 index 000000000..f38c317e7 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt @@ -0,0 +1,259 @@ +/* + * 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. + * 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.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.format +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils +import java.io.Serializable + +/** + * BluePrintEnhancerService + * @author Brinda Santh + * + */ +interface BluePrintEnhancerService : Serializable { + + @Throws(BluePrintException::class) + fun enhance(content: String): ServiceTemplate + + /** + * Read Blueprint from CSAR structure Directory + */ + @Throws(BluePrintException::class) + fun enhance(fileName: String, basePath: String): ServiceTemplate + + @Throws(BluePrintException::class) + fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate + + @Throws(BluePrintException::class) + fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) + + @Throws(BluePrintException::class) + fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) + + @Throws(BluePrintException::class) + fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) +} + +open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerDefaultService::class.toString()) + + lateinit var serviceTemplate: ServiceTemplate + + @Throws(BluePrintException::class) + override fun enhance(content: String): ServiceTemplate { + return JacksonReactorUtils.readValueFromFile(content, ServiceTemplate::class.java).map { serviceTemplate -> + enhance(serviceTemplate!!) + }.block()!! + } + + @Throws(BluePrintException::class) + override fun enhance(fileName: String, basePath: String): ServiceTemplate { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + @Throws(BluePrintException::class) + override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate { + this.serviceTemplate = serviceTemplate + initialCleanUp() + enrichTopologyTemplate(serviceTemplate) + + // log.info("Enriched Blueprint :\n {}", JacksonUtils.getJson(serviceTemplate, true)) + return this.serviceTemplate + } + + open fun initialCleanUp() { + serviceTemplate.artifactTypes?.clear() + serviceTemplate.nodeTypes?.clear() + serviceTemplate.dataTypes?.clear() + + serviceTemplate.artifactTypes = HashMap() + serviceTemplate.nodeTypes = HashMap() + serviceTemplate.dataTypes = HashMap() + + } + + @Throws(BluePrintException::class) + open fun enrichTopologyTemplate(serviceTemplate: ServiceTemplate) { + serviceTemplate.topologyTemplate?.let { topologyTemplate -> + enrichTopologyTemplateInputs(topologyTemplate) + enrichTopologyTemplateNodeTemplates(topologyTemplate) + } + } + + @Throws(BluePrintException::class) + open fun enrichTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { + topologyTemplate.inputs?.let { inputs -> + enrichPropertyDefinitions(inputs) + } + } + + open fun enrichTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { + topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> + enrichNodeTemplate(nodeTemplateName, nodeTemplate) + } + } + + @Throws(BluePrintException::class) + override fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val nodeTypeName = nodeTemplate.type + // Get NodeType from Repo and Update Service Template + val nodeType = populateNodeType(nodeTypeName) + + // Enrich NodeType + enrichNodeType(nodeTypeName, nodeType) + + //Enrich Node Template Artifacts + enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate) + } + + @Throws(BluePrintException::class) + override fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { + + // NodeType Property Definitions + enrichNodeTypeProperties(nodeTypeName, nodeType) + + //NodeType Requirement + enrichNodeTypeRequirements(nodeTypeName, nodeType) + + //NodeType Capability + enrichNodeTypeCapabilityProperties(nodeTypeName, nodeType) + + //NodeType Interface + enrichNodeTypeInterfaces(nodeTypeName, nodeType) + } + + open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { + nodeType.properties?.let { enrichPropertyDefinitions(nodeType.properties!!) } + } + + open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { + + nodeType.requirements?.forEach { _, requirementDefinition -> + // Populate Requirement Node + requirementDefinition.node?.let { requirementNodeTypeName -> + // Get Requirement NodeType from Repo and Update Service Template + val requirementNodeType = populateNodeType(requirementNodeTypeName) + + enrichNodeType(requirementNodeTypeName, requirementNodeType) + } + } + } + + open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { + nodeType.capabilities?.forEach { capabilityDefinitionName, capabilityDefinition -> + capabilityDefinition.properties?.let { properties -> + enrichPropertyDefinitions(properties) + } + } + } + + open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) { + nodeType.interfaces?.forEach { interfaceName, interfaceObj -> + // Populate Node type Interface Operation + log.info("*** ** Enriching NodeType: {} Interface {}", nodeTypeName, interfaceName) + populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) + + } + } + + open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) { + + interfaceObj.operations?.forEach { operationName, operation -> + enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation) + enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation) + } + } + + open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { + operation.inputs?.let { inputs -> + enrichPropertyDefinitions(inputs) + } + } + + open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { + operation.outputs?.let { inputs -> + enrichPropertyDefinitions(inputs) + } + } + + open fun enrichPropertyDefinitions(properties: MutableMap) { + + properties.forEach { propertyName, propertyDefinition -> + enrichPropertyDefinition(propertyName, propertyDefinition) + } + } + + @Throws(BluePrintException::class) + override fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) { + val propertyType = propertyDefinition.type + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + val entrySchema = propertyDefinition.entrySchema + ?: throw BluePrintException(format("Entry Schema is missing for collection property : {}", propertyName)) + + if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { + populateDataTypes(entrySchema.type) + } + } else { + populateDataTypes(propertyType) + } + + } + + open fun enrichNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { + + nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> + val artifactTypeName = artifactDefinition.type + ?: throw BluePrintException(format("Artifact type is missing for NodeTemplate({}) artifact({})", nodeTemplateName, artifactDefinitionName)) + + // Populate Artifact Type + populateArtifactType(artifactTypeName) + } + } + + open fun populateNodeType(nodeTypeName: String): NodeType { + val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)?.block() + ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName)) + serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) + return nodeType + } + + open fun populateArtifactType(artifactTypeName: String): ArtifactType { + val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)?.block() + ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName)) + serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) + return artifactType + } + + open fun populateDataTypes(dataTypeName: String): DataType { + val dataType = bluePrintRepoService.getDataType(dataTypeName)?.block() + ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName)) + serviceTemplate.dataTypes?.put(dataTypeName, dataType) + return dataType + } + +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt new file mode 100644 index 000000000..19d515e0e --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt @@ -0,0 +1,176 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +/** + * + * + * @author Brinda Santh + */ +object BluePrintExpressionService { + val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getExpressionData(propertyAssignment: Any): ExpressionData { + val propertyAssignmentNode: JsonNode = JacksonUtils.jsonNodeFromObject(propertyAssignment) + return getExpressionData(propertyAssignmentNode) + } + + @JvmStatic + fun getExpressionData(propertyAssignmentNode: JsonNode): ExpressionData { + log.trace("Assignment Data/Expression : {}", propertyAssignmentNode) + val expressionData = ExpressionData(valueNode = propertyAssignmentNode) + if (propertyAssignmentNode is ObjectNode) { + + val commands: Set = propertyAssignmentNode.fieldNames().asSequence().toList().intersect(BluePrintTypes.validCommands()) + if (commands.isNotEmpty()) { + expressionData.isExpression = true + expressionData.command = commands.first() + expressionData.expressionNode = propertyAssignmentNode + + when (expressionData.command) { + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT -> { + expressionData.inputExpression = populateInputExpression(propertyAssignmentNode) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> { + expressionData.attributeExpression = populateAttributeExpression(propertyAssignmentNode) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY -> { + expressionData.propertyExpression = populatePropertyExpression(propertyAssignmentNode) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> { + expressionData.operationOutputExpression = populateOperationOutputExpression(propertyAssignmentNode) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT -> { + expressionData.artifactExpression = populateArtifactExpression(propertyAssignmentNode) + } + } + } + } + return expressionData + } + + @JvmStatic + fun populateInputExpression(jsonNode: JsonNode): InputExpression { + return InputExpression(propertyName = jsonNode.first().textValue()) + } + + @JvmStatic + fun populatePropertyExpression(jsonNode: JsonNode): PropertyExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + check(arrayNode.size() >= 2) { + throw BluePrintException(String.format("missing property expression, " + + "it should be [ , , , " + + ", ..., ] , but present {}", jsonNode)) + } + var reqOrCapEntityName: String? = null + var propertyName = "" + var subProperty: String? = null + when { + arrayNode.size() == 2 -> propertyName = arrayNode[1].textValue() + arrayNode.size() == 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + } + arrayNode.size() > 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + val propertyPaths: List = arrayNode.filterIndexed { index, obj -> + index >= 3 + }.map { it.textValue() } + subProperty = propertyPaths.joinToString("/") + } + } + + return PropertyExpression(modelableEntityName = arrayNode[0].asText(), + reqOrCapEntityName = reqOrCapEntityName, + propertyName = propertyName, + subPropertyName = subProperty + ) + } + + @JvmStatic + fun populateAttributeExpression(jsonNode: JsonNode): AttributeExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + check(arrayNode.size() >= 3) { + throw BluePrintException(String.format("missing attribute expression, " + + "it should be [ , , ," + + " , ..., ] , but present {}", jsonNode)) + } + + var reqOrCapEntityName: String? = null + var propertyName = "" + var subProperty: String? = null + if (arrayNode.size() == 2) { + propertyName = arrayNode[1].textValue() + } else if (arrayNode.size() == 3) { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + } else if (arrayNode.size() > 3) { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + val propertyPaths: List = arrayNode.filterIndexed { index, obj -> + index >= 3 + }.map { it.textValue() } + subProperty = propertyPaths.joinToString("/") + } + return AttributeExpression(modelableEntityName = arrayNode[0].asText(), + reqOrCapEntityName = reqOrCapEntityName, + attributeName = propertyName, + subAttributeName = subProperty + ) + } + + @JvmStatic + fun populateOperationOutputExpression(jsonNode: JsonNode): OperationOutputExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + + check(arrayNode.size() >= 4) { + throw BluePrintException(String.format("missing operation output expression, " + + "it should be (, , , ) , but present {}", jsonNode)) + } + return OperationOutputExpression(modelableEntityName = arrayNode[0].asText(), + interfaceName = arrayNode[1].asText(), + operationName = arrayNode[2].asText(), + propertyName = arrayNode[3].asText() + ) + } + + @JvmStatic + fun populateArtifactExpression(jsonNode: JsonNode): ArtifactExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + + check(arrayNode.size() >= 2) { + throw BluePrintException(String.format("missing artifact expression, " + + "it should be [ , , , ] , but present {}", jsonNode)) + } + return ArtifactExpression(modelableEntityName = arrayNode[0].asText(), + artifactName = arrayNode[1].asText(), + location = arrayNode[2]?.asText() ?: "LOCAL_FILE", + remove = arrayNode[3]?.asBoolean() ?: false + ) + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt new file mode 100644 index 000000000..43267ff1b --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt @@ -0,0 +1,62 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.io.Serializable + +/** + * + * + * @author Brinda Santh + */ +interface BluePrintParserService : Serializable { + fun readBlueprint(content: String) : BluePrintContext + fun readBlueprintFile(fileName: String) : BluePrintContext + /** + * Read Blueprint from CSAR structure Directory + */ + fun readBlueprintFile(fileName: String, basePath : String) : BluePrintContext +} + +class BluePrintParserDefaultService : BluePrintParserService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + var basePath : String = javaClass.classLoader.getResource(".").path + + override fun readBlueprint(content: String): BluePrintContext { + return BluePrintContext(ServiceTemplateUtils.getServiceTemplateFromContent(content)) + } + + override fun readBlueprintFile(fileName: String): BluePrintContext { + return readBlueprintFile(fileName, basePath ) + } + + override fun readBlueprintFile(fileName: String, basePath : String): BluePrintContext { + val rootFilePath: String = StringBuilder().append(basePath).append(File.separator).append(fileName).toString() + val rootServiceTemplate : ServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) + // TODO("Nested Lookup Implementation based on Import files") + return BluePrintContext(rootServiceTemplate) + } + + +} diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt new file mode 100644 index 000000000..a7c14adfe --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -0,0 +1,98 @@ +/* + * 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. + * 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.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils +import reactor.core.publisher.Mono +import java.io.Serializable + +/** + * BluePrintRepoFileService + * @author Brinda Santh + * + */ + +interface BluePrintRepoService : Serializable { + + @Throws(BluePrintException::class) + fun getNodeType(nodeTypeName: String): Mono? + + @Throws(BluePrintException::class) + fun getDataType(dataTypeName: String): Mono? + + @Throws(BluePrintException::class) + fun getArtifactType(artifactTypeName: String): Mono? + + @Throws(BluePrintException::class) + fun getRelationshipType(relationshipTypeName: String): Mono? + + @Throws(BluePrintException::class) + fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? + +} + + +open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString()) + + private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val extension = ".json" + + override fun getDataType(dataTypeName: String): Mono? { + val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(dataTypeName).plus(extension) + return getModelType(fileName, DataType::class.java) + } + + override fun getNodeType(nodeTypeName: String): Mono? { + val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension) + return getModelType(fileName, NodeType::class.java) + } + + override fun getArtifactType(artifactTypeName: String): Mono? { + val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(artifactTypeName).plus(extension) + return getModelType(fileName, ArtifactType::class.java) + } + + override fun getRelationshipType(relationshipTypeName: String): Mono? { + val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(relationshipTypeName).plus(extension) + return getModelType(fileName, RelationshipType::class.java) + } + + override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? { + val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(capabilityDefinitionName).plus(extension) + return getModelType(fileName, CapabilityDefinition::class.java) + } + + private fun getModelType(fileName: String, valueType: Class): Mono { + return JacksonReactorUtils.readValueFromFile(fileName, valueType) + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt new file mode 100644 index 000000000..ce0bceeea --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -0,0 +1,278 @@ +/* + * 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. + * 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.service + + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +/** + * + * + * @author Brinda Santh + */ +open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRuntimeService::class.toString()) + + /* + Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing + */ + open fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { + log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) + val propertyAssignmentValue: MutableMap = hashMapOf() + + val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) + + val propertyAssignments: MutableMap = + nodeTemplate.properties as MutableMap + + // Get the Node Type Definitions + val nodeTypeProperties: MutableMap = + bluePrintContext.nodeTypeChainedProperties(nodeTemplate.type)!! + + // Iterate Node Type Properties + nodeTypeProperties.forEach { nodeTypePropertyName, nodeTypeProperty -> + // Get the Express or Value for the Node Template + val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName] + + var resolvedValue: JsonNode = NullNode.getInstance() + if (propertyAssignment != null) { + // Resolve the Expressing + val propertyAssignmentExpression = PropertyAssignmentService(context, this) + resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) + } else { + // Assign default value to the Operation + nodeTypeProperty.defaultValue?.let { defaultValue -> + resolvedValue = defaultValue + } + } + // Set for Return of method + propertyAssignmentValue[nodeTypePropertyName] = resolvedValue + } + log.info("resolved property definition for node template ({}), values ({})", nodeTemplateName, propertyAssignmentValue) + return propertyAssignmentValue + } + + open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, + interfaceName: String, operationName: String): MutableMap { + log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + + "operationName({})", nodeTemplateName, interfaceName, operationName) + + val propertyAssignmentValue: MutableMap = hashMapOf() + + val propertyAssignments: MutableMap = + bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) as? MutableMap + ?: throw BluePrintException(String.format("failed to get input definitions for node template (%s), " + + "interface name (%s), operationName(%s)", nodeTemplateName, interfaceName, operationName)) + + val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type + + val nodeTypeInterfaceOperationInputs: MutableMap = + bluePrintContext.nodeTypeInterfaceOperationInputs(nodeTypeName, interfaceName, operationName) + ?: throw BluePrintException(String.format("failed to get input definitions for node type (%s), " + + "interface name (%s), operationName(%s)", nodeTypeName, interfaceName, operationName)) + + log.info("input definition for node template ({}), values ({})", nodeTemplateName, propertyAssignments) + + // Iterate Node Type Properties + nodeTypeInterfaceOperationInputs.forEach { nodeTypePropertyName, nodeTypeProperty -> + // Get the Express or Value for the Node Template + val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName] + + var resolvedValue: JsonNode = NullNode.getInstance() + if (propertyAssignment != null) { + // Resolve the Expressing + val propertyAssignmentExpression = PropertyAssignmentService(context, this) + resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) + } else { + // Assign default value to the Operation + nodeTypeProperty.defaultValue?.let { + resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + } + } + // Set for Return of method + propertyAssignmentValue[nodeTypePropertyName] = resolvedValue + } + log.info("resolved input assignments for node template ({}), values ({})", nodeTemplateName, propertyAssignmentValue) + + return propertyAssignmentValue + } + + + open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, + interfaceName: String, operationName: String, componentContext: MutableMap) { + log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + + "operationName({})", nodeTemplateName, interfaceName, operationName) + + val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type + + val nodeTypeInterfaceOperationOutputs: MutableMap = + bluePrintContext.nodeTypeInterfaceOperationOutputs(nodeTypeName, interfaceName, operationName) + ?: throw BluePrintException(String.format("failed to get input definitions for node type (%s), " + + "interface name (%s), operationName(%s)", nodeTypeName, interfaceName, operationName)) + + // Iterate Node Type Properties + nodeTypeInterfaceOperationOutputs.forEach { nodeTypePropertyName, nodeTypeProperty -> + + val operationOutputPropertyName: String = StringBuilder().append(nodeTemplateName) + .append(".").append(interfaceName) + .append(".").append(operationName) + .append(".").append(nodeTypePropertyName).toString() + // Get the Value from component context + val resolvedValue: JsonNode = componentContext[operationOutputPropertyName] as? JsonNode + ?: NullNode.getInstance() + // Store operation output values into context + setNodeTemplateOperationPropertyValue(nodeTemplateName, interfaceName, operationName, nodeTypePropertyName, resolvedValue) + log.debug("resolved output assignments for node template ({}), property name ({}), value ({})", nodeTemplateName, nodeTypePropertyName, resolvedValue) + } + } + + open fun resolveNodeTemplateArtifact(nodeTemplateName: String, + artifactName: String): String { + val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) + + val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName) + ?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template" + , artifactName)) + val propertyAssignmentExpression = PropertyAssignmentService(context, this) + return propertyAssignmentExpression.artifactContent(artifactDefinition) + } + + + open fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + log.trace("setting input path ({}), values ({})", path, value) + context[path] = value + } + + open fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS).append(BluePrintConstants.PATH_DIVIDER).append(workflowName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + context[path] = value + } + + open fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { + + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + context[path] = value + } + + open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + log.trace("setting operation property path ({}), values ({})", path, value) + context[path] = value + } + + open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + context[path] = value + } + + open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + context[path] = value + } + + + open fun getInputValue(propertyName: String): JsonNode { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return context[path] as? JsonNode ?: NullNode.instance + } + + open fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return context[path] as JsonNode + } + + open fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return context[path] as JsonNode + } + + open fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return context[path] as JsonNode + } + + open fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return context[path] as JsonNode + } + + open fun assignInputs(jsonNode: JsonNode) { + log.info("assignInputs from input JSON ({})", jsonNode.toString()) + bluePrintContext.inputs?.forEach { propertyName, property -> + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() + setInputValue(propertyName, property, valueNode) + } + } + + open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { + log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) + bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property -> + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() + setWorkflowInputValue(workflowName, propertyName, valueNode) + } + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt new file mode 100644 index 000000000..34399fdd2 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -0,0 +1,360 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.Serializable + +/** + * + * + * @author Brinda Santh + */ +interface BluePrintValidatorService : Serializable { + + @Throws(BluePrintException::class) + fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) + + @Throws(BluePrintException::class) + fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) +} + +open class BluePrintValidatorDefaultService : BluePrintValidatorService { + + val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorDefaultService::class.toString()) + + lateinit var bluePrintContext: BluePrintContext + lateinit var serviceTemplate: ServiceTemplate + lateinit var properties: MutableMap + var message: StringBuilder = StringBuilder() + private val separator: String = BluePrintConstants.PATH_DIVIDER + var paths: MutableList = arrayListOf() + + @Throws(BluePrintException::class) + override fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) { + validateBlueprint(bluePrintContext.serviceTemplate,properties) + } + + @Throws(BluePrintException::class) + override fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) { + this.bluePrintContext = BluePrintContext(serviceTemplate) + this.serviceTemplate = serviceTemplate + this.properties = properties + try { + message.appendln("-> Config Blueprint") + serviceTemplate.metadata?.let { validateMetadata(serviceTemplate.metadata!!) } + serviceTemplate.artifactTypes?.let { validateArtifactTypes(serviceTemplate.artifactTypes!!) } + serviceTemplate.dataTypes?.let { validateDataTypes(serviceTemplate.dataTypes!!) } + serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } + serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } + } catch (e: Exception) { + log.error("validation failed in the path : {}", paths.joinToString(separator), e) + log.error("validation trace message :{} ", message) + throw BluePrintException(e, + format("failed to validate blueprint on path ({}) with message {}" + , paths.joinToString(separator), e.message)) + } + } + + @Throws(BluePrintException::class) + open fun validateMetadata(metaDataMap: MutableMap) { + paths.add("metadata") + + val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME] + val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION] + val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS] + val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + + Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata") + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateArtifactTypes(artifactTypes: MutableMap) { + paths.add("artifact_types") + artifactTypes.forEach { artifactName, artifactType -> + paths.add(artifactName) + message.appendln("--> Artifact Type :" + paths.joinToString(separator)) + artifactType.properties?.let { validatePropertyDefinitions(artifactType.properties!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateDataTypes(dataTypes: MutableMap) { + paths.add("dataTypes") + dataTypes.forEach { dataTypeName, dataType -> + paths.add(dataTypeName) + message.appendln("--> Data Type :" + paths.joinToString(separator)) + dataType.properties?.let { validatePropertyDefinitions(dataType.properties!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTypes(nodeTypes: MutableMap) { + paths.add("nodeTypes") + nodeTypes.forEach { nodeTypeName, nodeType -> + // Validate Single Node Type + validateNodeType(nodeTypeName,nodeType) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeType(nodeTypeName: String, nodeType: NodeType) { + paths.add(nodeTypeName) + message.appendln("--> Node Type :" + paths.joinToString(separator)) + val derivedFrom: String = nodeType.derivedFrom + //Check Derived From + checkValidNodeTypesDerivedFrom(derivedFrom) + + nodeType.properties?.let { validatePropertyDefinitions(nodeType.properties!!) } + nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) { + paths.add("topology") + message.appendln("--> Topology Template") + topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) } + topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) } + topologyTemplate.workflows?.let { validateWorkFlows(topologyTemplate.workflows!!) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateInputs(inputs: MutableMap) { + paths.add("inputs") + message.appendln("---> Input :" + paths.joinToString(separator)) + validatePropertyDefinitions(inputs) + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTemplates(nodeTemplates: MutableMap) { + paths.add("nodeTemplates") + nodeTemplates.forEach { nodeTemplateName, nodeTemplate -> + validateNodeTemplate(nodeTemplateName, nodeTemplate) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) { + paths.add(nodeTemplateName) + message.appendln("---> Node Template :" + paths.joinToString(separator)) + val type: String = nodeTemplate.type + + val nodeType: NodeType = serviceTemplate.nodeTypes?.get(type) + ?: throw BluePrintException(format("Failed to get node type definition for node template : {}", nodeTemplateName)) + + nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeTemplate.capabilities!!) } + nodeTemplate.requirements?.let { validateRequirementAssignments(nodeTemplate.requirements!!) } + nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeTemplate.interfaces!!) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateWorkFlows(workflows: MutableMap) { + paths.add("workflows") + workflows.forEach { workflowName, workflow -> + + // Validate Single workflow + validateWorkFlow(workflowName, workflow) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateWorkFlow(workflowName:String, workflow: Workflow) { + paths.add(workflowName) + message.appendln("---> Workflow :" + paths.joinToString(separator)) + // Step Validation Start + paths.add("steps") + workflow.steps?.forEach { stepName, step -> + paths.add(stepName) + message.appendln("----> Steps :" + paths.joinToString(separator)) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + // Step Validation Ends + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validatePropertyDefinitions(properties: MutableMap) { + paths.add("properties") + properties.forEach { propertyName, propertyDefinition -> + paths.add(propertyName) + val dataType: String = propertyDefinition.type + when { + BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { + // Do Nothing + } + BluePrintTypes.validCollectionTypes().contains(dataType) -> { + val entrySchemaType: String = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Entry schema for data type ({}) for the property ({}) not found", dataType, propertyName)) + checkPrimitiveOrComplex(entrySchemaType, propertyName) + } + else -> checkPropertyDataType(dataType, propertyName) + } + message.appendln("property " + paths.joinToString(separator) + " of type " + dataType) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyDefinition, propertyAssignment) + } + } + } + + @Throws(BluePrintException::class) + open fun validateArtifactDefinitions(artifacts: MutableMap) { + paths.add("artifacts") + artifacts.forEach { artifactName, artifactDefinition -> + paths.add(artifactName) + message.appendln("Validating artifact " + paths.joinToString(separator)) + val type: String = artifactDefinition.type + ?: throw BluePrintException("type is missing for artifact definition :" + artifactName) + // Check Artifact Type + checkValidArtifactType(type) + + val file: String = artifactDefinition.file + ?: throw BluePrintException(format("file is missing for artifact definition : {}", artifactName)) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignments(capabilities: MutableMap) { + + } + + @Throws(BluePrintException::class) + open fun validateRequirementAssignments(requirements: MutableMap) { + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceAssignments(interfaces: MutableMap) { + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceDefinitions(interfaces: MutableMap) { + paths.add("interfaces") + interfaces.forEach { interfaceName, interfaceDefinition -> + paths.add(interfaceName) + message.appendln("Validating : " + paths.joinToString(separator)) + interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateOperationDefinitions(operations: MutableMap) { + paths.add("operations") + operations.forEach { opertaionName, operationDefinition -> + paths.add(opertaionName) + message.appendln("Validating : " + paths.joinToString(separator)) + operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } + operationDefinition.inputs?.let { validatePropertyDefinitions(operationDefinition.inputs!!) } + operationDefinition.outputs?.let { validatePropertyDefinitions(operationDefinition.outputs!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateImplementation(implementation: Implementation) { + checkNotEmptyNThrow(implementation.primary) + } + + @Throws(BluePrintException::class) + open fun checkValidNodeType(nodeType : String) { + + } + + @Throws(BluePrintException::class) + open fun checkValidArtifactType(artifactType: String) { + + serviceTemplate.artifactTypes?.containsKey(artifactType) + ?: throw BluePrintException(format("Failed to node type definition for artifact definition : {}", artifactType)) + } + + @Throws(BluePrintException::class) + open fun checkValidNodeTypesDerivedFrom(derivedFrom: String) { + + } + + private fun checkPropertyValue(propertyDefinition: PropertyDefinition, jsonNode: JsonNode) { + //log.info("validating path ({}), Property {}, value ({})", paths, propertyDefinition, jsonNode) + } + + private fun checkPropertyDataType(dataType: String, propertyName: String): Boolean { + if (checkDataType(dataType)) { + return true + } else { + throw BluePrintException(format("Data type ({}) for the property ({}) not found", dataType, propertyName)) + } + } + + private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean { + if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { + return true + } else { + throw BluePrintException(format("Data type ({}) for the property ({}) is not valid", dataType)) + } + } + + private fun checkDataType(key: String): Boolean { + return serviceTemplate.dataTypes?.containsKey(key) ?: false + } + + private fun checkNodeType(key: String): Boolean { + return serviceTemplate.nodeTypes?.containsKey(key) ?: false + } + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt new file mode 100644 index 000000000..ece09d6e2 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt @@ -0,0 +1,200 @@ +/* + * 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. + * 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.service + + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +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.ResourceResolverUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +/** + * + * + * @author Brinda Santh + */ +class PropertyAssignmentService(var context: MutableMap, + var bluePrintRuntimeService: BluePrintRuntimeService) { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + private var bluePrintContext: BluePrintContext = bluePrintRuntimeService.bluePrintContext + +/* + +If Property Assignment is Expression. + Get the Expression + Recurssely resolve the expression + */ + + fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String, + assignment: Any): JsonNode { + val valueNode: JsonNode + log.trace("Assignment ({})", assignment) + val expressionData = BluePrintExpressionService.getExpressionData(assignment) + + if (expressionData.isExpression) { + valueNode = resolveExpression(nodeTemplateName, assignmentName, expressionData) + } else { + valueNode = expressionData.valueNode + } + return valueNode + } + + fun resolveExpression(nodeTemplateName: String, propName: String, expressionData: ExpressionData): JsonNode { + + var valueNode: JsonNode = NullNode.getInstance() + + if(expressionData.isExpression) { + val command = expressionData.command!! + + when(command){ + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT ->{ + valueNode = bluePrintRuntimeService.getInputValue(expressionData.inputExpression?.propertyName!!) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE ->{ + valueNode = resolveAttributeExpression(nodeTemplateName, expressionData.attributeExpression!!) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY ->{ + valueNode = resolvePropertyExpression(nodeTemplateName, expressionData.propertyExpression!!) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT ->{ + valueNode = resolveOperationOutputExpression(nodeTemplateName, expressionData.operationOutputExpression!!) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT ->{ + valueNode = resolveArtifactExpression(nodeTemplateName, expressionData.artifactExpression!!) + } + org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE ->{ + + } + else ->{ + throw BluePrintException(String.format("for property ({}), command ({}) is not supported ", propName, command)) + } + } + } + return valueNode + } + + /* + get_property: [ , , , + , ..., ] + */ + fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode { + val valueNode: JsonNode + + val attributeName = attributeExpression.attributeName + val subAttributeName: String? = attributeExpression.subAttributeName + + var attributeNodeTemplateName = nodeTemplateName + if (!attributeExpression.modelableEntityName.equals("SELF", true)) { + attributeNodeTemplateName = attributeExpression.modelableEntityName + } + + val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName) + ?: throw BluePrintException(String.format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, attributeName)) + + var propertyDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!! + + log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) + + // Check it it is a nested expression + valueNode = resolveAssignmentExpression(attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) + +// subPropertyName?.let { +// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) +// } + return valueNode + } + + /* + get_property: [ , , , + , ..., ] + */ + fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode { + val valueNode: JsonNode + + val propertyName = propertyExpression.propertyName + val subPropertyName: String? = propertyExpression.subPropertyName + + var propertyNodeTemplateName = nodeTemplateName + if (!propertyExpression.modelableEntityName.equals("SELF", true)) { + propertyNodeTemplateName = propertyExpression.modelableEntityName + } + + val nodeTemplatePropertyExpression = bluePrintContext.nodeTemplateByName(propertyNodeTemplateName).properties?.get(propertyName) + ?: throw BluePrintException(format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, propertyName)) + + var propertyDefinition: PropertyDefinition = bluePrintContext.nodeTemplateNodeType(propertyNodeTemplateName).properties?.get(propertyName)!! + + log.info("node template name ({}), property Name ({}) resolved value ({})", propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) + + // Check it it is a nested expression + valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) + +// subPropertyName?.let { +// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) +// } + return valueNode + } + + /* + get_operation_output: , , , + */ + fun resolveOperationOutputExpression(nodeTemplateName: String, operationOutputExpression: OperationOutputExpression): JsonNode { + var outputNodeTemplateName = nodeTemplateName + if (!operationOutputExpression.modelableEntityName.equals("SELF", true)) { + outputNodeTemplateName = operationOutputExpression.modelableEntityName + } + return bluePrintRuntimeService.getNodeTemplateOperationOutputValue(outputNodeTemplateName, + operationOutputExpression.interfaceName, operationOutputExpression.operationName, + operationOutputExpression.propertyName) + } + + /* + get_artifact: [ , , , ] + */ + fun resolveArtifactExpression(nodeTemplateName: String, artifactExpression: ArtifactExpression): JsonNode { + + var artifactNodeTemplateName = nodeTemplateName + if (!artifactExpression.modelableEntityName.equals("SELF", true)) { + artifactNodeTemplateName = artifactExpression.modelableEntityName + } + val artifactDefinition: ArtifactDefinition = bluePrintContext.nodeTemplateByName(artifactNodeTemplateName) + .artifacts?.get(artifactExpression.artifactName) + ?: throw BluePrintException(String.format("failed to get artifact definitions for node template ({})'s " + + "artifact name ({}) ", nodeTemplateName, artifactExpression.artifactName)) + + return JacksonUtils.jsonNodeFromObject(artifactContent(artifactDefinition)) + } + + fun artifactContent(artifactDefinition: ArtifactDefinition): String { + val bluePrintBasePath: String = context[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] as? String + ?: throw BluePrintException(String.format("failed to get property (%s) from context", org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)) + + if (artifactDefinition.repository != null) { + TODO() + } else if (artifactDefinition.file != null) { + return ResourceResolverUtils.getFileContent(artifactDefinition.file!!, bluePrintBasePath) + } + return "" + } +} + diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt new file mode 100644 index 000000000..b7f9fc7e6 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -0,0 +1,95 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.nio.charset.Charset + +object BluePrintMetadataUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun toscaMetaData(basePath: String): ToscaMetaData { + val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus("TOSCA-Metadata/TOSCA.meta") + return toscaMetaDataFromMetaFile(toscaMetaPath) + } + + @JvmStatic + fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { + val toscaMetaData = ToscaMetaData() + val lines: MutableList = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset()) + lines.forEach { line -> + if (line.contains(":")) { + val keyValue = line.split(":") + if (keyValue.size == 2) { + val value: String = keyValue[1].trim() + when (keyValue[0]) { + "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value + "CSAR-Version" -> toscaMetaData.csarVersion = value + "Created-By" -> toscaMetaData.createdBy = value + "Entry-Definitions" -> toscaMetaData.entityDefinitions = value + "Template-Tags" -> toscaMetaData.templateTags = value + } + } + } + + } + return toscaMetaData + } + + /* + fun getBluePrintContext(blueprintBasePath: String): BluePrintContext { + + val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator) + .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString() + + val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile) + + log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions) + + return BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath) + } + + fun getBluePrintRuntime(requestId: String, blueprintBasePath: String): BluePrintRuntimeService { + + val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator) + .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString() + + val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile) + + log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions) + + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath) + + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath + context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = requestId + + val bluePrintRuntimeService: BluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) + + return bluePrintRuntimeService + } + */ +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt new file mode 100644 index 000000000..07b819ffe --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt @@ -0,0 +1,55 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager + +/** + * + * + * @author Brinda Santh + */ +object BluePrintRuntimeUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + fun assignInputsFromFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap) { + val jsonNode: JsonNode = JacksonUtils.jsonNodeFromFile(fileName) + return assignInputs(bluePrintContext, jsonNode, context) + } + + fun assignInputsFromContent(bluePrintContext: BluePrintContext, content: String, context: MutableMap) { + val jsonNode: JsonNode = JacksonUtils.jsonNode(content) + return assignInputs(bluePrintContext, jsonNode, context) + } + + fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap) { + log.info("assignInputs from input JSON ({})", jsonNode.toString()) + bluePrintContext.inputs?.forEach { propertyName, property -> + val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) + log.trace("setting input path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt new file mode 100644 index 000000000..0ed901702 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt @@ -0,0 +1,108 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import reactor.core.publisher.Mono +import reactor.core.publisher.toMono + +object JacksonReactorUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getContent(fileName: String): Mono { + return JacksonUtils.getContent(fileName).toMono() + } + + @JvmStatic + fun getClassPathFileContent(fileName: String): Mono { + return JacksonUtils.getClassPathFileContent(fileName).toMono() + } + + @JvmStatic + fun readValue(content: String, valueType: Class): Mono { + return Mono.just(jacksonObjectMapper().readValue(content, valueType)) + } + + @JvmStatic + fun jsonNode(content: String): Mono { + return Mono.just(jacksonObjectMapper().readTree(content)) + } + + @JvmStatic + fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono { + return Mono.just(JacksonUtils.getJson(any, pretty)) + } + + @JvmStatic + fun getListFromJson(content: String, valueType: Class): Mono> { + val objectMapper = jacksonObjectMapper() + val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) + return objectMapper.readValue>(content, javaType).toMono() + } + + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): Mono { + return getContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun readValueFromClassPathFile(fileName: String, valueType: Class): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun jsonNodeFromFile(fileName: String): Mono { + return getContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun jsonNodeFromClassPathFile(fileName: String): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): Mono> { + return getContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): Mono> { + return getClassPathFileContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt new file mode 100644 index 000000000..5075e7261 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -0,0 +1,248 @@ +/* + * 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. + * 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.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.apache.commons.io.FileUtils +import org.apache.commons.io.IOUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.format +import java.io.File +import java.nio.charset.Charset + +/** + * + * + * @author Brinda Santh + */ +object JacksonUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + inline fun readValue(content: String): T = + jacksonObjectMapper().readValue(content, T::class.java) + + @JvmStatic + fun readValue(content: String, valueType: Class): T? { + return jacksonObjectMapper().readValue(content, valueType) + } + + @JvmStatic + fun getContent(fileName: String): String { + return File(fileName).readText(Charsets.UTF_8) + } + + @JvmStatic + fun getClassPathFileContent(fileName: String): String { + return IOUtils.toString(JacksonUtils::class.java.classLoader + .getResourceAsStream(fileName), Charset.defaultCharset()) + } + + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): T? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return readValue(content, valueType) + } + + @JvmStatic + fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { + val content: String = getClassPathFileContent(fileName) + return readValue(content, valueType) + } + + @JvmStatic + fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java) + + @JvmStatic + fun jsonNodeFromClassPathFile(fileName: String): JsonNode { + val content: String = getClassPathFileContent(fileName) + return jsonNode(content) + } + + @JvmStatic + fun jsonNodeFromFile(fileName: String): JsonNode { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return jsonNode(content) + } + + @JvmStatic + fun jsonNode(content: String): JsonNode { + return jacksonObjectMapper().readTree(content) + } + + @JvmStatic + fun getJson(any: kotlin.Any): String { + return getJson(any, false) + } + + @JvmStatic + fun getJson(any: kotlin.Any, pretty: Boolean = false): String { + val objectMapper = jacksonObjectMapper() + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) + if (pretty) { + objectMapper.enable(SerializationFeature.INDENT_OUTPUT) + } + return objectMapper.writeValueAsString(any) + } + + @JvmStatic + fun getListFromJson(content: String, valueType: Class): List? { + val objectMapper = jacksonObjectMapper() + val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) + return objectMapper.readValue>(content, javaType) + } + + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): List? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return getListFromJson(content, valueType) + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): List? { + val content: String = getClassPathFileContent(fileName) + return getListFromJson(content, valueType) + } + + @JvmStatic + fun getMapFromJson(content: String, valueType: Class): MutableMap? { + val objectMapper = jacksonObjectMapper() + val typeRef = object : TypeReference>() {} + return objectMapper.readValue(content, typeRef) + } + + @JvmStatic + fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { + if (BluePrintTypes.validPrimitiveTypes().contains(type)) { + return checkJsonNodeValueOfPrimitiveType(type, jsonNode) + } else if (BluePrintTypes.validCollectionTypes().contains(type)) { + return checkJsonNodeValueOfCollectionType(type, jsonNode) + } + return false + } + + @JvmStatic + fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean { + when (primitiveType) { + BluePrintConstants.DATA_TYPE_STRING -> return jsonNode.isTextual + BluePrintConstants.DATA_TYPE_BOOLEAN -> return jsonNode.isBoolean + BluePrintConstants.DATA_TYPE_INTEGER -> return jsonNode.isInt + BluePrintConstants.DATA_TYPE_FLOAT -> return jsonNode.isDouble + BluePrintConstants.DATA_TYPE_TIMESTAMP -> return jsonNode.isTextual + else -> return false + } + } + + @JvmStatic + fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean { + when (type) { + BluePrintConstants.DATA_TYPE_LIST -> return jsonNode.isArray + BluePrintConstants.DATA_TYPE_MAP -> return jsonNode.isContainerNode + else -> return false + } + + } +/* + @JvmStatic + fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { + objectNode.put(key, value as Boolean) + } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { + objectNode.put(key, value as Int) + } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { + objectNode.put(key, value as Float) + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) { + objectNode.put(key, value as String) + } else { + objectNode.put(key, value as String) + } + } + + @JvmStatic + fun populatePrimitiveValues(value: Any, primitiveType: String, objectNode: ArrayNode) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { + objectNode.add(value as Boolean) + } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { + objectNode.add(value as Int) + } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { + objectNode.add(value as Float) + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) { + objectNode.add(value as String) + } else { + objectNode.add(value as String) + } + } + + @JvmStatic + fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { + objectNode.put(key, false) + } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { + objectNode.put(key, 0) + } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { + objectNode.put(key, 0.0) + } else { + objectNode.put(key, "") + } + } + + @JvmStatic + fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { + arrayNode.add(false) + } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { + arrayNode.add(0) + } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { + arrayNode.add(0.0) + } else { + arrayNode.add("") + } + } + + @JvmStatic + fun populateJsonNodeValues(key: String, nodeValue: JsonNode?, type: String, objectNode: ObjectNode) { + if (nodeValue == null || nodeValue is NullNode) { + objectNode.set(key, nodeValue) + } else if (BluePrintTypes.validPrimitiveTypes().contains(type)) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN == type) { + objectNode.put(key, nodeValue.asBoolean()) + } else if (BluePrintConstants.DATA_TYPE_INTEGER == type) { + objectNode.put(key, nodeValue.asInt()) + } else if (BluePrintConstants.DATA_TYPE_FLOAT == type) { + objectNode.put(key, nodeValue.floatValue()) + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == type) { + objectNode.put(key, nodeValue.asText()) + } else { + objectNode.put(key, nodeValue.asText()) + } + } else { + objectNode.set(key, nodeValue) + } + } + */ +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt new file mode 100644 index 000000000..bc0d9b4c6 --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt @@ -0,0 +1,62 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.net.URL +import java.nio.charset.Charset +/** + * + * + * @author Brinda Santh + */ +object ResourceResolverUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getFileContent(filename : String, basePath : String?): String { + log.trace("file ({}), basePath ({}) ", filename, basePath) + try{ + var resolvedFileName : String = filename + if(filename.startsWith("http", true) + || filename.startsWith("https", true)){ + val givenUrl : String = URL(filename).toString() + val systemUrl : String = File(".").toURI().toURL().toString() + log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl) + if(givenUrl.startsWith(systemUrl)){ + + } + }else{ + if(!filename.startsWith("/")){ + if (checkNotEmpty(basePath)) { + resolvedFileName = basePath.plus(File.separator).plus(filename) + }else{ + resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) + } + } + } + return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset()) + }catch (e : Exception){ + throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath) + } + } +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt new file mode 100644 index 000000000..0d739357c --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt @@ -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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import java.io.File +import java.nio.charset.Charset + +/** + * + * + * @author Brinda Santh + */ +object ServiceTemplateUtils { + + @JvmStatic + fun getServiceTemplate(fileName: String): ServiceTemplate { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + return getServiceTemplateFromContent(content) + } + + + @JvmStatic + fun getServiceTemplateFromContent(content: String): ServiceTemplate { + return JacksonUtils.readValue(content) + } + + +} \ No newline at end of file diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt new file mode 100644 index 000000000..dcafa974c --- /dev/null +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt @@ -0,0 +1,131 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import java.util.* + +/** + * + * + * @author Brinda Santh + */ +class TopologicalSortingUtils { + + private val neighbors: MutableMap> = hashMapOf() + + val isDag: Boolean + get() = topSort() != null + + override fun toString(): String { + val s = StringBuffer() + for (v in neighbors.keys) + s.append("\n " + v + " -> " + neighbors[v]) + return s.toString() + } + + fun getNeighbors(): Map> { + return neighbors + } + + fun add(vertex: V) { + if (neighbors.containsKey(vertex)) + return + neighbors[vertex] = arrayListOf() + } + + operator fun contains(vertex: V): Boolean { + return neighbors.containsKey(vertex) + } + + fun add(from: V, to: V) { + this.add(from) + this.add(to) + neighbors[from]?.add(to) + } + + fun remove(from: V, to: V) { + if (!(this.contains(from) && this.contains(to))) + throw IllegalArgumentException("Nonexistent vertex") + neighbors[from]?.remove(to) + } + + fun outDegree(): Map { + var result: MutableMap = hashMapOf() + for (v in neighbors.keys) + result[v] = neighbors[v]!!.size + return result + } + + + fun inDegree(): MutableMap { + val result = HashMap() + for (v in neighbors.keys) + result[v] = 0 // All in-degrees are 0 + for (from in neighbors.keys) { + for (to in neighbors[from]!!) { + result[to] = result[to]!! + 1 // Increment in-degree + } + } + return result + } + + fun topSort(): List? { + val degree = inDegree() + // Determine all vertices with zero in-degree + val zeroVerts = Stack() // Stack as good as any here + for (v in degree.keys) { + if (degree[v] == 0) zeroVerts.push(v) + } + // Determine the topological order + val result = ArrayList() + while (!zeroVerts.isEmpty()) { + val v = zeroVerts.pop() // Choose a vertex with zero in-degree + result.add(v) // Vertex v is next in topol order + // "Remove" vertex v by updating its neighbors + for (neighbor in neighbors[v]!!) { + degree[neighbor] = degree[neighbor]!! - 1 + // Remember any vertices that now have zero in-degree + if (degree[neighbor] == 0) zeroVerts.push(neighbor) + } + } + // Check that we have used the entire graph (if not, there was a cycle) + return if (result.size != neighbors.size) null else result + } + + + fun bfsDistance(start: V): Map<*, *> { + var distance: MutableMap = hashMapOf() + // Initially, all distance are infinity, except start node + for (v in neighbors.keys) + distance[v] = -1 + distance[start] = 0 + // Process nodes in queue order + val queue = LinkedList() + queue.offer(start) // Place start node in queue + while (!queue.isEmpty()) { + val v = queue.remove() + val vDist = distance[v]!! + // Update neighbors + for (neighbor in neighbors[v]!!) { + if (distance[neighbor] != null) continue // Ignore if already done + distance[neighbor] = vDist + 1 + queue.offer(neighbor) + } + } + return distance + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt new file mode 100644 index 000000000..128b7f576 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt @@ -0,0 +1,35 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core + +import org.junit.Test +import kotlin.test.assertEquals +/** + * + * + * @author Brinda Santh + */ +class CustomFunctionsTest { + @Test + fun testFormat(): Unit { + val returnValue : String = format("This is {} for times {}", "test", 2) + assertEquals("This is test for times 2", returnValue, "Failed to format String") + + val returnValue1 : String = format("This is test for times 2") + assertEquals("This is test for times 2", returnValue1, "Failed to format empty args") + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt new file mode 100644 index 000000000..7a74ca476 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + + +import org.apache.commons.io.FileUtils +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.nio.charset.Charset +import kotlin.test.assertNotNull +/** + * + * + * @author Brinda Santh + */ +class BluePrintContextTest { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + lateinit var bluePrintContext: BluePrintContext + + @Before + fun setUp() { + + val basepath = "load/blueprints" + + bluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + } + + @Test + fun testBluePrintContextFromContent() { + val fileName = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json" + val content : String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + val bpContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprint(content) + assertNotNull(bpContext, "Failed to get blueprint content") + assertNotNull(bpContext.serviceTemplate, "Failed to get blueprint content's service template") + } + + @Test + fun testChainedProperty() { + val nodeType = bluePrintContext.nodeTypeChained("component-resource-assignment") + assertNotNull(nodeType, "Failed to get chained node type") + log.trace("Properties {}", JacksonUtils.getJson(nodeType, true)) + } + + +} diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt new file mode 100644 index 000000000..8e6d5efdf --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt @@ -0,0 +1,41 @@ +/* + * 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. + * 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.service + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils + +/** + * BluePrintEnhancerServiceTest + * @author Brinda Santh + * + */ + +class BluePrintEnhancerServiceTest { + val basePath = "load/model_type" + + @Test + fun testEnrichBlueprint() { + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + val bluePrintEnhancerService: BluePrintEnhancerService = BluePrintEnhancerDefaultService(bluePrintEnhancerRepoFileService) + + val serviceTemplate = ServiceTemplateUtils.getServiceTemplate("load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json") + bluePrintEnhancerService.enhance(serviceTemplate) + + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt new file mode 100644 index 000000000..911a891a8 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt @@ -0,0 +1,109 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ExpressionData +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +/** + * + * + * @author Brinda Santh + */ +class BluePrintExpressionServiceTest { + @Test + fun testInputExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.inputExpression, " Failed to populate input expression data") + assertEquals("input-name", expressionData.inputExpression?.propertyName, "Failed to get propertyName from expression data") + } + + @Test + fun testPropertyExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data") + assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName") + + val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }") + val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression") + assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data") + assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName") + assertEquals("resource/name",expressionData1.propertyExpression?.subPropertyName, " Failed to populate nested subPropertyName expression data") + } + + @Test + fun testAttributeExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data") + assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("attribute-name", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName") + assertEquals("resource/name",expressionData.attributeExpression?.subAttributeName, " Failed to populate nested subAttributeName expression data") + } + + + @Test + fun testOutputOperationExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data") + assertEquals("SELF", expressionData.operationOutputExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("interface-name", expressionData.operationOutputExpression?.interfaceName, " Failed to get expected interfaceName") + assertEquals("operation-name", expressionData.operationOutputExpression?.operationName, " Failed to get expected operationName") + assertEquals("output-property-name", expressionData.operationOutputExpression?.propertyName, " Failed to get expected propertyName") + } + + + @Test + fun testArtifactExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName") + + + val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }") + val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData1.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData1.artifactExpression?.artifactName, " Failed to get expected artifactName") + assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location") + assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove") + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt new file mode 100644 index 000000000..5a5557d75 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt @@ -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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintParserFactoryTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @Test + fun testBluePrintJson() { + val basepath = "load/blueprints" + + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + log.trace("Blue Print {}",bluePrintContext.blueprintJson(true)) + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt new file mode 100644 index 000000000..88aea919e --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -0,0 +1,57 @@ +/* + * 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. + * 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.service + +import org.junit.Test +import java.io.FileNotFoundException +import kotlin.test.assertNotNull + +/** + * BluePrintRepoFileServiceTest + * @author Brinda Santh + * + */ +class BluePrintRepoFileServiceTest { + + private val basePath = "load/model_type" + private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + + @Test + fun testGetDataType() { + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block() + assertNotNull(dataType, "Failed to get DataType from repo") + } + + @Test + fun testGetNodeType() { + val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block() + assertNotNull(nodeType, "Failed to get NodeType from repo") + } + + @Test + fun testGetArtifactType() { + val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block() + assertNotNull(nodeType, "Failed to get ArtifactType from repo") + } + + @Test(expected = FileNotFoundException::class) + fun testModelNotFound() { + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block() + assertNotNull(dataType, "Failed to get DataType from repo") + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt new file mode 100644 index 000000000..5d24b072f --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -0,0 +1,131 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromFile +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintRuntimeServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + val basepath = "load/blueprints" + + + @Before + fun setUp(): Unit { + + } + + @Test + fun testResolveNodeTemplateProperties() { + log.info("************************ testResolveNodeTemplateProperties **********************") + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") + val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) + + val inputDataPath = "src/test/resources/data/default-context.json" + + val inputNode: JsonNode = jsonNodeFromFile(inputDataPath) + bluePrintRuntimeService.assignInputs(inputNode) + + val propContext: MutableMap = bluePrintRuntimeService.resolveNodeTemplateProperties("activate-process") + log.info("Context {}" ,bluePrintRuntimeService.context) + + assertNotNull(propContext, "Failed to populate interface property values") + assertEquals(propContext.get("process-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter process-name") + assertEquals(propContext.get("version"), jsonNodeFromObject("sample-action"), "Failed to populate parameter version") + } + + @Test + fun testResolveNodeTemplateInterfaceOperationInputs() { + log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************") + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") + + val inputDataPath = "src/test/resources/data/default-context.json" + BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context) + + + val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) + + log.info("Prepared Context {}" ,context) + + val inContext: MutableMap = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment", + "DefaultComponentNode", "process") + + log.trace("In Context {}" ,inContext) + + assertNotNull(inContext, "Failed to populate interface input property values") + assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name") + assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name") + assertEquals(inContext.get("template-content"), jsonNodeFromObject("This is Sample Velocity Template"), "Failed to populate parameter action-name") + + } + + @Test + fun testResolveNodeTemplateInterfaceOperationOutputs() { + log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************") + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") + + val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) + + val componentContext: MutableMap = hashMapOf() + val successValue : JsonNode= jsonNodeFromObject("Success") + componentContext["resource-assignment.DefaultComponentNode.process.status"] = successValue + componentContext["resource-assignment.DefaultComponentNode.process.resource-assignment-params"] = null + + bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment", + "DefaultComponentNode", "process", componentContext) + + assertEquals(NullNode.instance, + context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/resource-assignment-params"), + "Failed to get operation property resource-assignment-params") + + assertEquals(successValue, + context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/status"), + "Failed to get operation property status") + + + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt new file mode 100644 index 000000000..b05fcb61b --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager + +/** + * + * + * @author Brinda Santh + */ +class BluePrintValidatorDefaultServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + val basepath = "load/blueprints" + + @Before + fun setUp(): Unit { + + } + + @Test + fun testValidateBluePrint() { + val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! + .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) + val properties : MutableMap = hashMapOf() + val validatorService = BluePrintValidatorDefaultService() + validatorService.validateBlueprint(bluePrintContext.serviceTemplate,properties) + log.info("Validation Message {}", properties) + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt new file mode 100644 index 000000000..ddb39a2d6 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData +import kotlin.test.assertNotNull + +class BluePrintMetadataUtilsTest { + + @Test + fun testToscaMetaData(){ + + val basePath : String = "load/blueprints/baseconfiguration" + + val toscaMetaData : ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) + assertNotNull(toscaMetaData, "Missing Tosca Definition Object") + assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") + assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") + assertNotNull(toscaMetaData.createdBy, "Missing Created by") + assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") + assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") + + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt new file mode 100644 index 000000000..d13caa52c --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import java.io.FileNotFoundException +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class JacksonReactorUtilsTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + @Test + fun testReadValues() { + + val serviceTemplate = JacksonReactorUtils.readValueFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json", + ServiceTemplate::class.java).block() + + assertNotNull(serviceTemplate, "Failed to simple transform Service Template") + assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance") + + val jsonContent = JacksonReactorUtils.getJson(serviceTemplate!!, true).block() + assertNotNull(jsonContent, "Failed to get json content") + + val jsonNode = JacksonReactorUtils.jsonNodeFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json") + .block() + assertNotNull(jsonContent, "Failed to get json Node") + } + + @Test(expected = FileNotFoundException::class) + fun testReadValuesFailure() { + JacksonReactorUtils.jsonNodeFromFile("load/blueprints/not-found.json") + .block() + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt new file mode 100644 index 000000000..a5a630e3c --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt @@ -0,0 +1,93 @@ +/* + * 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. + * 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.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** + * JacksonUtilsTest + * @author Brinda Santh + * ${DATA} + */ +class JacksonUtilsTest { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + val basePath = "load/blueprints" + + @Test + fun testReadValues() { + val content = ResourceResolverUtils.getFileContent("baseconfiguration/Definitions/activation-blueprint.json", basePath) + val serviceTemplate = JacksonUtils.readValue(content, ServiceTemplate::class.java) + assertNotNull(serviceTemplate, "Failed to simple transform Service Template") + assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance") + + val jsonContent = JacksonUtils.getJson(serviceTemplate!!, true) + assertNotNull(jsonContent, "Failed to get json content") + } + + @Test + fun testJsonNodeFromClassPathFile() { + val filePath = "data/default-context.json" + JacksonUtils.jsonNodeFromClassPathFile(filePath) + } + + @Test + fun testJsonNodeFromFile() { + val filePath = basePath + "/baseconfiguration/Definitions/activation-blueprint.json" + JacksonUtils.jsonNodeFromFile(filePath) + } + + @Test + fun testGetListFromJson() { + val content = "[\"good\",\"boy\" ]" + val nodeType = JacksonUtils.getListFromJson(content, String::class.java) + assertNotNull(nodeType, "Failed to get String array from content") + } + + + @Test + fun testJsonValue() { + val filePath = "data/alltype-data.json" + val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath) + assertNotNull(rootJson, "Failed to get all type data json node") + val intValue = rootJson.get("intValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value") + val floatValue = rootJson.get("floatValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value") + val stringValue = rootJson.get("stringValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value") + val booleanValue = rootJson.get("booleanValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value") + val arrayStringValue = rootJson.get("arrayStringValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value") + val mapValue = rootJson.get("mapValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value") + + assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed") + + + } +} \ No newline at end of file diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt new file mode 100644 index 000000000..3fa4f75d9 --- /dev/null +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.core.utils + +import org.junit.Test + +class TopologicalSortingUtilsTest { + + @Test + fun testSorting(): Unit { + val graph: TopologicalSortingUtils = TopologicalSortingUtils() + graph.add("bundle-id", "bundle-mac") + graph.add("bundle-id", "bundle-ip") + graph.add("bundle-mac", "bundle-ip") + graph.add("bundle-ip", "bundle-mac") + + println("The current graph: " + graph) + println("In-degrees: " + graph.inDegree()) + println("Out-degrees: " + graph.outDegree()) + println("A topological sort of the vertices: " + graph.topSort()) + } +} \ No newline at end of file diff --git a/components/core/src/test/resources/componentnode/default.json b/components/core/src/test/resources/componentnode/default.json new file mode 100644 index 000000000..b7265fcd1 --- /dev/null +++ b/components/core/src/test/resources/componentnode/default.json @@ -0,0 +1,100 @@ +{ + "metadata": { + "template_author": "bs2796", + "vendor": "Juniper", + "os": "XXX", + "service-type": "AVPN", + "vnf-type": "VRR", + "action": "Base Configuration", + "sub-action": "Generate Configuration", + "template_name": "VRR-baseconfiguration", + "template_version": "1.0.0" + }, + "topology_template": { + "inputs": { + "service-instance-id": { + "required": true, + "type": "string" + }, + "vnf-id": { + "required": true, + "type": "string" + }, + "service": { + "required": true, + "type": "string" + }, + "region": { + "required": true, + "type": "string" + }, + "bundle-id": { + "required": true, + "type": "string" + }, + "bundle-mac": { + "required": true, + "type": "string" + } + }, + "node_templates": { + "generate-configuration": { + "type": "mock-component-generateConfig", + "interfaces": { + "org-openecomp-sdnc-config-params-service-MockComponentNode": { + "operations": { + "process": { + "inputs": { + "entity-type": "vnf-type", + "template-content": "sample-template", + "entity-id": "{ \"get_input\" : \"vnf-id\" }" + }, + "outputs": { + "mergedData": "merged Data", + "status": "status" + } + } + } + } + } + } + } + }, + "node_types": { + "mock-component-generateConfig": { + "interfaces": { + "org-openecomp-sdnc-config-params-service-MockComponentNode": { + "operations": { + "process": { + "inputs": { + "entity-type": { + "required": false, + "type": "string" + }, + "template-content": { + "required": false, + "type": "string" + }, + "entity-id": { + "required": true, + "type": "string" + } + }, + "outputs": { + "generated-config": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" + } + } +} diff --git a/components/core/src/test/resources/data/alltype-data.json b/components/core/src/test/resources/data/alltype-data.json new file mode 100644 index 000000000..055b09658 --- /dev/null +++ b/components/core/src/test/resources/data/alltype-data.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/components/core/src/test/resources/data/default-context.json b/components/core/src/test/resources/data/default-context.json new file mode 100644 index 000000000..fcd4cbe26 --- /dev/null +++ b/components/core/src/test/resources/data/default-context.json @@ -0,0 +1,5 @@ +{ + "request-id" : "12345", + "hostname" : "localhost", + "action-name" : "sample-action" +} \ No newline at end of file diff --git a/components/core/src/test/resources/dictionary/dictionary_schema.json b/components/core/src/test/resources/dictionary/dictionary_schema.json new file mode 100644 index 000000000..d03170050 --- /dev/null +++ b/components/core/src/test/resources/dictionary/dictionary_schema.json @@ -0,0 +1,261 @@ +{ + "type": "object", + "properties": { + "resource-path": { + "type": "string", + "required": true + }, + "description": { + "type": "string" + }, + "updated-by": { + "type": "string" + }, + "data-type": { + "type": "string", + "required": true + }, + "source": { + "type": "object", + "required": true, + "properties": { + "input": { + "type": "object", + "properties": { + "key": { + "type": "string" + } + } + }, + "component": { + "type": "object", + "properties": { + "name": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "default": { + "type": "any" + }, + "aai": { + "type": "any" + }, + "mdsal": { + "type": "object", + "properties": { + "path": { + "type": "string", + "required": true + }, + "url-path": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "type": { + "type": "string", + "required": true + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "base": { + "type": "string", + "required": true + } + } + }, + "network-resource-discovery": { + "type": "object", + "properties": { + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "db": { + "type": "object", + "properties": { + "query": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "type": { + "type": "string", + "required": true + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "base": { + "type": "string", + "required": true + } + } + }, + "policy": { + "type": "object", + "properties": { + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "candidate-dependency": { + "type": "object", + "properties": { + "input": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "component": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "aai": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "mdsal": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "network-resource-discovery": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "db": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "policy": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + }, + "tags": { + "type": "string" + }, + "default": { + "type": "any" + }, + "name": { + "type": "string", + "required": true + }, + "valid-values": { + "type": "string" + }, + "resource-type": { + "type": "string", + "required": true + }, + "sample-value": { + "type": "string" + }, + "entry-schema": { + "type": "string" + } + } +} diff --git a/components/core/src/test/resources/properties/convert.json b/components/core/src/test/resources/properties/convert.json new file mode 100644 index 000000000..cb7d08e44 --- /dev/null +++ b/components/core/src/test/resources/properties/convert.json @@ -0,0 +1,33 @@ +{ + "type": "sdnc-component-getResourceAssignment", + "interfaces": { + "ResourceAssignmentService": { + "operations": { + "getResourceAssignment": { + "inputs": { + "assignment-mappings": [ + { + "name": "service-name", + "mapping-field": "service", + "mapping-category": "SDN", + "required": true + }, + { + "name": "region-name", + "mapping-field": "region", + "mapping-category": "SDN", + "required": true + } + ], + "pre-data": "{ \"get_attribute\" : \"get-resource-assignment.config-params\" }", + "prifix": "get-resource-assignment" + }, + "outputs": { + "resource-assignment-status": "success", + "resource-assignment-params": "{ \"set_value\" : \"get-resource-assignment.config-params\" }" + } + } + } + } + } +} diff --git a/components/core/src/test/resources/properties/default.json b/components/core/src/test/resources/properties/default.json new file mode 100644 index 000000000..0ac97f907 --- /dev/null +++ b/components/core/src/test/resources/properties/default.json @@ -0,0 +1,16 @@ +{ + "default": "{ \"get_input\" : \"loopback-default\" }", + "domain": "ethernet", + "criteria": [ + { + "value": "attga301me1", + "type": "complex", + "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" + }, + { + "value": "{ \"get_input\" : \"host-ip-address\" }", + "type": "simple", + "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" + } + ] +} diff --git a/components/parent/pom.xml b/components/parent/pom.xml new file mode 100644 index 000000000..cbbeeffc1 --- /dev/null +++ b/components/parent/pom.xml @@ -0,0 +1,299 @@ + + + + 4.0.0 + + org.onap.ccsdk.apps + components + 0.3.0-SNAPSHOT + + org.onap.ccsdk.apps.components + parent + App Components Parent + pom + + 2.0.4.RELEASE + 5.0.8.RELEASE + 1.2.60 + 1.0.0 + 26.0-jre + 2.9.2 + 1.4.197 + 1.2.2-SNAPSHOT + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + com.att.eelf + eelf-core + ${eelf.version} + + + org.onap.logging-analytics + logging-slf4j + ${onap.logger.slf4j} + + + + + io.springfox + springfox-swagger2 + ${springfox.swagger2.version} + + + io.springfox + springfox-swagger-ui + ${springfox.swagger2.version} + + + + org.apache.commons + commons-lang3 + 3.2.1 + + + commons-collections + commons-collections + 3.2.2 + + + commons-io + commons-io + 2.6 + + + org.apache.velocity + velocity + 1.7 + + + com.google.guava + guava + ${guava.version} + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + + + + com.h2database + h2 + ${h2database.version} + + + + + + org.onap.ccsdk.apps.controllerblueprints + core + ${project.version} + + + org.onap.ccsdk.apps.controllerblueprints + service + ${project.version} + + + org.onap.ccsdk.apps.controllerblueprints + application + ${project.version} + + + org.onap.ccsdk.apps.controllerblueprints + resource-dict + ${project.version} + + + + + org.powermock + powermock-api-mockito2 + 1.7.4 + test + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + + + + + + + com.att.eelf + eelf-core + + + org.onap.logging-analytics + logging-slf4j + + + org.apache.commons + commons-lang3 + + + commons-collections + commons-collections + + + commons-io + commons-io + + + com.jayway.jsonpath + json-path + + + com.google.guava + guava + + + io.springfox + springfox-swagger2 + + + io.springfox + springfox-swagger-ui + + + org.jetbrains.kotlin + kotlin-stdlib + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + + compile + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/main/java + + + + + test-compile + + test-compile + + + + ${project.basedir}/src/test/kotlin + ${project.basedir}/src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + diff --git a/components/pom.xml b/components/pom.xml new file mode 100644 index 000000000..aada3eb1d --- /dev/null +++ b/components/pom.xml @@ -0,0 +1,45 @@ + + + + + + org.onap.ccsdk.apps + ccsdk-apps + 0.3.0-SNAPSHOT + + 4.0.0 + org.onap.ccsdk.apps + components + App Components Root + pom + + UTF-8 + UTF-8 + yyyyMMdd'T'HHmmss'Z' + ${maven.build.timestamp} + 1.8 + 1.8 + 1.8 + + + parent + core + resource-dict + + + diff --git a/components/resource-dict/load/model_type/node_type/source-component-java.json b/components/resource-dict/load/model_type/node_type/source-component-java.json new file mode 100644 index 000000000..95a9801dc --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-component-java.json @@ -0,0 +1,31 @@ +{ + "description": "This is Custom Java Component Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default" : "DYNAMIC", + "constraints": [ + { + "validValues": [ + "DYNAMIC" + ] + } + ] + }, + "class-name": { + "required": true, + "type": "string", + "description" : "Fully Qualified Class Name ( + . + )" + }, + "key-dependencies": { + "required": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/source-db.json b/components/resource-dict/load/model_type/node_type/source-db.json new file mode 100644 index 000000000..661a9503b --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-db.json @@ -0,0 +1,44 @@ +{ + "description": "This is Database Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": true, + "type": "string", + "constraints": [ + { + "valid_values": [ + "SQL", + "PLSQL" + ] + } + ] + }, + "query": { + "required": true, + "type": "string" + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/source-default.json b/components/resource-dict/load/model_type/node_type/source-default.json new file mode 100644 index 000000000..13e234e1b --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-default.json @@ -0,0 +1,18 @@ +{ + "description": "This is Default 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" +} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/source-input.json b/components/resource-dict/load/model_type/node_type/source-input.json new file mode 100644 index 000000000..126ea30bd --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-input.json @@ -0,0 +1,18 @@ +{ + "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" +} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/source-rest.json b/components/resource-dict/load/model_type/node_type/source-rest.json new file mode 100644 index 000000000..f8dd8b6fc --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-rest.json @@ -0,0 +1,61 @@ +{ + "description": "This is Rest Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "JSON", + "constraints": [ + { + "valid_values": [ + "JSON" + ] + } + ] + }, + "url-path": { + "required": true, + "type": "string" + }, + "path": { + "required": true, + "type": "string" + }, + "expression-type": { + "required": false, + "type": "string", + "default": "JSON_PATH", + "constraints": [ + { + "valid_values": [ + "JSON_PATH", + "JSON_POINTER" + ] + } + ] + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json b/components/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 000000000..2ef553e24 --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for Resource Sources", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/db-source.json b/components/resource-dict/load/resource_dictionary/db-source.json new file mode 100644 index 000000000..92b16a212 --- /dev/null +++ b/components/resource-dict/load/resource_dictionary/db-source.json @@ -0,0 +1,26 @@ +{ + "name": "db-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "resource-type": "ONAP", + "resource-path": "vnf/bundle-id", + "updated-by": "brindasanth@onap.com", + "tags": "bundle-id, brindasanth@onap.com", + "sources": { + "db": { + "type": "source-db", + "properties": { + "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } + } + } + } +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/default-source.json b/components/resource-dict/load/resource_dictionary/default-source.json new file mode 100644 index 000000000..1c47f37b2 --- /dev/null +++ b/components/resource-dict/load/resource_dictionary/default-source.json @@ -0,0 +1,18 @@ +{ + "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", + "name": "default-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "resource-type": "ONAP", + "resource-path": "vnf/v4-ip-type", + "sources": { + "default": { + "type": "source-default", + "properties": { + } + } + } +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/input-source.json b/components/resource-dict/load/resource_dictionary/input-source.json new file mode 100644 index 000000000..676d92f86 --- /dev/null +++ b/components/resource-dict/load/resource_dictionary/input-source.json @@ -0,0 +1,19 @@ +{ + "name": "input-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "resource-path": "action-name", + "resource-type": "ONAP", + "updated-by": "brindasanth@onap.com", + "tags": null, + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "action-name" + } + } + } +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/mdsal-source.json b/components/resource-dict/load/resource_dictionary/mdsal-source.json new file mode 100644 index 000000000..b49146a0e --- /dev/null +++ b/components/resource-dict/load/resource_dictionary/mdsal-source.json @@ -0,0 +1,36 @@ +{ + "tags": "oam-local-ipv4-address", + "name": "mdsal-source", + "property" :{ + "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "resource-type": "ATT", + "resource-path": "vnf/oam-local-ipv4-address", + "sources": { + "mdsal": { + "type": "source-rest", + "properties": { + "type": "JSON", + "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", + "path": "/v4-assigned-ip-list/0/v4-ip-prefix", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "network-role": "network-role", + "v4-ip-type": "v4-ip-type", + "vm-type": "vm-type" + }, + "output-key-mapping": { + "oam-local-ipv4-address": "v4-ip-prefix" + }, + "key-dependencies": [ + "service-instance-id", + "network-role", + "v4-ip-type", + "vm-type" + ] + } + } + } +} \ No newline at end of file diff --git a/components/resource-dict/pom.xml b/components/resource-dict/pom.xml new file mode 100644 index 000000000..7eecb5ee4 --- /dev/null +++ b/components/resource-dict/pom.xml @@ -0,0 +1,49 @@ + + + + + 4.0.0 + + org.onap.ccsdk.apps.components + parent + 0.3.0-SNAPSHOT + ../parent + + org.onap.ccsdk.apps.controllerblueprints + resource-dict + Controller Blueprints Resource Dictionary + + + + org.onap.ccsdk.apps.controllerblueprints + core + + + org.jetbrains.kotlin + kotlin-test + test + + + + + + diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt new file mode 100644 index 000000000..a6802f677 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt @@ -0,0 +1,34 @@ +/* + * 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.resource.dict + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException + +interface ResourceAssignmentProcessor { + + @Throws(BluePrintProcessorException::class) + fun validate(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun process(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun errorHandle(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun reTrigger(resourceAssignment: ResourceAssignment, context : MutableMap) +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt new file mode 100644 index 000000000..0808073f8 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -0,0 +1,100 @@ +/* + * 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.resource.dict + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonProperty +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import java.io.Serializable +import java.util.* + +open class ResourceDefinition { + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property", required = true) + lateinit var property: PropertyDefinition + + var tags: String? = null + + @JsonProperty(value = "updated-by") + lateinit var updatedBy: String + + @JsonProperty(value = "resource-type", required = true) + lateinit var resourceType: String + + @JsonProperty(value = "resource-path", required = true) + lateinit var resourcePath: String + + @JsonProperty(value = "sources", required = true) + lateinit var sources: MutableMap +} + +open class ResourceAssignment { + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property") + var property: PropertyDefinition? = null + + @JsonProperty("input-param") + var inputParameter: Boolean = false + + @JsonProperty("dictionary-name") + var dictionaryName: String? = null + + @JsonProperty("dictionary-source") + var dictionarySource: String? = null + + @JsonProperty("dependencies") + var dependencies: MutableList? = null + + @JsonProperty("version") + var version: Int = 0 + + @JsonProperty("status") + var status: String? = null + + @JsonProperty("message") + var message: String? = null + + @JsonProperty("updated-date") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var updatedDate: Date? = null + + @JsonProperty("updated-by") + var updatedBy: String? = null + + override fun toString(): String { + return StringBuilder() + .append("[") + .append("name=", name) + .append(", dictionaryName=", dictionaryName) + .append(", dictionarySource=", dictionarySource) + .append("]") + .toString() + } +} + +/** + * Interface for Source Definitions (ex Input Source, + * Default Source, Database Source, Rest Sources, etc) + */ +interface ResourceSource : Serializable diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt new file mode 100644 index 000000000..aa6a9fb65 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -0,0 +1,34 @@ +/* + * 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.resource.dict +/** + * ResourceDictionaryConstants + * + * @author Brinda Santh + */ +object ResourceDictionaryConstants { + const val SOURCE_INPUT = "input" + const val SOURCE_DEFAULT = "default" + const val SOURCE_DB = "db" + + const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" + + const val PROPERTY_TYPE = "type" + const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" + const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" + const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies" +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt new file mode 100644 index 000000000..c5a78a9c9 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt @@ -0,0 +1,86 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import com.att.eelf.configuration.EELFManager + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentEnhancerService { + + @Throws(BluePrintException::class) + fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + resourceAssignments: List) + + @Throws(BluePrintException::class) + fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate +} + +/** + * ResourceAssignmentEnhancerDefaultService. + * + * @author Brinda Santh + */ +open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) + : ResourceAssignmentEnhancerService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) + + /** + * Get the defined source instance from the ResourceAssignment, + * then get the NodeType of the Sources assigned + */ + override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + resourceAssignments: List) { + + // Iterate the Resource Assignment and + resourceAssignments.map { resourceAssignment -> + val dictionaryName = resourceAssignment.dictionaryName!! + val dictionarySource = resourceAssignment.dictionarySource!! + log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name, + dictionaryName, dictionarySource) + // Get the Resource Definition from Repo + val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) + + val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) + + // Enrich as NodeTemplate + bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!) + } + } + + override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { + val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService) + bluePrintEnhancerService.serviceTemplate = ServiceTemplate() + bluePrintEnhancerService.initialCleanUp() + enhanceBluePrint(bluePrintEnhancerService, resourceAssignments) + return bluePrintEnhancerService.serviceTemplate + } + + private fun getResourceDefinition(name: String): ResourceDefinition { + return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!! + } +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt new file mode 100644 index 000000000..228b39e29 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -0,0 +1,151 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +import java.io.Serializable + +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceAssignments: List): Boolean +} + +/** + * ResourceAssignmentValidationDefaultService. + * + * @author Brinda Santh + */ +open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) + + open var resourceAssignmentMap: Map = hashMapOf() + open val validationMessage = StrBuilder() + + override fun validate(resourceAssignments: List): Boolean { + try { + validateSources(resourceAssignments) + validateTemplateNDictionaryKeys(resourceAssignments) + validateCyclicDependency(resourceAssignments) + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") + } + } catch (e: Exception) { + throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString(), e) + } + return true + } + + open fun validateSources(resourceAssignments: List) { + log.info("validating resource assignment sources") + } + + open fun validateTemplateNDictionaryKeys(resourceAssignments: List) { + + resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap() + + val duplicateKeyNames = resourceAssignments.groupBy { it.name } + .filter { it.value.size > 1 } + .map { it.key } + + if (duplicateKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames)) + } + + val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName } + .filter { it.value.size > 1 } + .map { it.key } + if (duplicateDictionaryKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames)) + } + + val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten() + + log.info("Resource assignment definitions : {}", resourceAssignmentMap.keys) + log.info("Resource assignment Dictionary dependencies : {}", dependenciesNames) + + val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct() + if (notPresentDictionaries.isNotEmpty()) { + validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries)) + } + + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") + } + } + + open fun validateCyclicDependency(resourceAssignments: List) { + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + val topologySorting = TopologicalSortingUtils() + + resourceAssignmentMap.map { it.value }.map { resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + resourceAssignment.dependencies!!.map { + log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) + topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) + } + } else { + topologySorting.add(startResourceAssignment, resourceAssignment) + } + } + + if (!topologySorting.isDag) { + val graph = getTopologicalGraph(topologySorting) + validationMessage.appendln("Cyclic Dependency :$graph") + } + } + + open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils): String { + val s = StringBuilder() + val neighbors = topologySorting.getNeighbors() + + neighbors.forEach { v, vs -> + if (v.name == "*") { + s.append("\n * -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } else { + s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } + } + return s.toString() + } + + +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt new file mode 100644 index 000000000..d51338caf --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import reactor.core.publisher.Mono +/** + * ResourceDefinitionRepoService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionRepoService : BluePrintRepoService { + + fun getResourceDefinition(resourceDefinitionName: String): Mono? +} + +/** + * ResourceDefinitionFileRepoService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionFileRepoService : BluePrintRepoFileService, + ResourceDefinitionRepoService { + + private var resourceDefinitionPath: String + private val extension = ".json" + + constructor(basePath: String) : this(basePath, + basePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(BluePrintConstants.MODEL_DIR_MODEL_TYPE)) + + constructor(basePath: String, modelTypePath: String) : super(modelTypePath) { + resourceDefinitionPath = basePath.plus("/resource_dictionary") + } + + override fun getResourceDefinition(resourceDefinitionName: String): Mono? { + + val fileName = resourceDefinitionPath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(resourceDefinitionName).plus(extension) + + return JacksonReactorUtils.readValueFromFile(fileName, ResourceDefinition::class.java) + } +} diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt new file mode 100644 index 000000000..14855d4b6 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt @@ -0,0 +1,114 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import com.att.eelf.configuration.EELFManager +import java.io.Serializable +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceDefinition: ResourceDefinition) + +} +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) + + override fun validate(resourceDefinition: ResourceDefinition) { + Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") + log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) + + resourceDefinition.sources.forEach { (name, nodeTemplate) -> + val sourceType = nodeTemplate.type + + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() + ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType)) + + // Validate Property Name, expression, values and Data Type + validateNodeTemplateProperties(nodeTemplate, sourceNodeType) + } + } + + + open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + } + + + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) + } else { + throw BluePrintException(format("property({}) of expression ({}) is not supported", + propertyName, propertyAssignment)) + } + } + } + + open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid : Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + bluePrintRepoService.getDataType(propertyType) + ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", + propertyName, propertyType)) + isValid = true + } + + check(isValid) { + throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", + propertyName, propertyType, propertyAssignment)) + } + } +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt new file mode 100644 index 000000000..747639c89 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -0,0 +1,109 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils + +import com.att.eelf.configuration.EELFLogger +import org.apache.commons.collections.CollectionUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +import java.util.ArrayList +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +object BulkResourceSequencingUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BulkResourceSequencingUtils::class.java) + + @JvmStatic + fun process(resourceAssignments: MutableList): List> { + val resourceAssignmentMap: MutableMap = hashMapOf() + val sequenceBatchResourceAssignment = ArrayList>() + log.info("Assignments ({})", resourceAssignments) + // Prepare Map + resourceAssignments.forEach { resourceAssignment -> + log.trace("Processing Key ({})", resourceAssignment.name) + resourceAssignmentMap.put(resourceAssignment.name, resourceAssignment) + } + + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + // Preepare Sorting Map + val topologySorting = TopologicalSortingUtils() + resourceAssignmentMap.forEach { _, resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + for (dependency in resourceAssignment.dependencies!!) { + topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment) + } + } else { + topologySorting.add(startResourceAssignment, resourceAssignment) + } + } + + val sequencedResourceAssignments: MutableList = topologySorting.topSort()!! as MutableList + log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) + + var batchResourceAssignment: MutableList? = null + var batchAssignmentName: MutableList? = null + + // Prepare Sorting + sequencedResourceAssignments.forEachIndexed { index, resourceAssignment -> + + var previousResourceAssignment: ResourceAssignment? = null + + if (index > 0) { + previousResourceAssignment = sequencedResourceAssignments[index - 1] + } + + var dependencyPresence = false + if (batchAssignmentName != null && resourceAssignment.dependencies != null) { + dependencyPresence = CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.dependencies) + } + + log.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.name, + batchAssignmentName, resourceAssignment.dependencies, dependencyPresence) + + if (previousResourceAssignment != null && resourceAssignment.dictionarySource != null + && resourceAssignment.dictionarySource!!.equals(previousResourceAssignment.dictionarySource, true) + && !dependencyPresence) { + batchResourceAssignment!!.add(resourceAssignment) + batchAssignmentName!!.add(resourceAssignment.name) + } else { + if (batchResourceAssignment != null) { + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + log.trace("Created old Set ({})", batchAssignmentName) + } + batchResourceAssignment = arrayListOf() + batchResourceAssignment!!.add(resourceAssignment) + + batchAssignmentName = arrayListOf() + batchAssignmentName!!.add(resourceAssignment.name) + } + + if (index == sequencedResourceAssignments.size - 1) { + log.trace("Created old Set ({})", batchAssignmentName) + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + } + } + log.info("Batched Sequence : ({})", sequenceBatchResourceAssignment) + + return sequenceBatchResourceAssignment + } + +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt new file mode 100644 index 000000000..a3456cd43 --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -0,0 +1,78 @@ +/* + * 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.resource.dict.utils + +import com.att.eelf.configuration.EELFLogger +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.apache.commons.collections.MapUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import com.att.eelf.configuration.EELFManager + + +object ResourceDictionaryUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils::class.java) + + @JvmStatic + fun populateSourceMapping(resourceAssignment: ResourceAssignment, + resourceDefinition: ResourceDefinition) { + + if (StringUtils.isBlank(resourceAssignment.dictionarySource)) { + + if (MapUtils.isNotEmpty(resourceDefinition.sources)) { + val source = findFirstSource(resourceDefinition.sources) + + // Populate and Assign First Source + if (StringUtils.isNotBlank(source)) { + // Set Dictionary Source + resourceAssignment.dictionarySource = source + } else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + log.info("auto map resourceAssignment : {}", resourceAssignment) + }else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + } + } + + @JvmStatic + fun findFirstSource(sources: Map): String? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } + + @JvmStatic + fun assignInputs(data: JsonNode, context: MutableMap) { + log.trace("assignInputs from input JSON ({})", data.toString()) + data.fields().forEach { field -> + val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key) + log.trace("setting path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } +} \ No newline at end of file diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java new file mode 100644 index 000000000..fde800057 --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -0,0 +1,60 @@ +/* + * 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. + * 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.resource.dict; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDefinitionTest { + private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); + private String basePath = "load/resource_dictionary"; + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); + } +} diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java new file mode 100644 index 000000000..57c8509d1 --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; + +import java.util.List; + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +public class ResourceAssignmentEnhancerServiceTest { + + @Test + public void testEnhanceBluePrint() throws BluePrintException { + + List resourceAssignments = JacksonReactorUtils + .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block(); + Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); + ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); + ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = + new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService); + ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); + Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); + } +} + diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt new file mode 100644 index 000000000..6216d5bf0 --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -0,0 +1,57 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +/** + * ResourceAssignmentValidationServiceTest. + * + * @author Brinda Santh + */ +class ResourceAssignmentValidationServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) + @Test + fun testValidateSuccess() { + log.info("**************** testValidateSuccess *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + val result = resourceAssignmentValidator.validate(assignments!!) + Assert.assertTrue("Failed to Validate", result) + } + + @Test(expected = BluePrintException::class) + fun testValidateDuplicate() { + log.info(" **************** testValidateDuplicate *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } + + @Test(expected = BluePrintException::class) + fun testValidateCyclic() { + log.info(" **************** testValidateCyclic *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } +} \ No newline at end of file diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java new file mode 100644 index 000000000..1772277df --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDefinitionRepoServiceTest { + + @Test + public void testGetResourceDefinition() throws Exception{ + ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); + ResourceDefinition resourceDefinition = resourceDefinitionRepoService + .getResourceDefinition("db-source").block(); + Assert.assertNotNull("Failed to get Resource Definition db-source", resourceDefinition); + + NodeType nodeType = resourceDefinitionRepoService.getNodeType("source-db").block(); + Assert.assertNotNull("Failed to get Node Type source-db", resourceDefinition); + } +} \ No newline at end of file diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java new file mode 100644 index 000000000..ef305627f --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java @@ -0,0 +1,56 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDefinitionValidationServiceTest { + private String basePath = "load/model_type"; + private String dictionaryPath = "load/resource_dictionary"; + private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); + + @Test + public void testValidateSource() throws Exception { + + String inputFileName = dictionaryPath + "/db-source.json"; + testValidate(inputFileName); + + String dbFileName = dictionaryPath + "/db-source.json"; + testValidate(dbFileName); + + String defaultFileName = dictionaryPath + "/default-source.json"; + testValidate(defaultFileName); + + String restFileName = dictionaryPath + "/mdsal-source.json"; + testValidate(restFileName); + } + + private void testValidate(String fileName) throws Exception { + + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); + + ResourceDefinitionValidationService resourceDictionaryValidationService = + new ResourceDefinitionDefaultValidationService(bluePrintRepoFileService); + resourceDictionaryValidationService.validate(resourceDefinition); + Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); + } +} diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java new file mode 100644 index 000000000..c7444dbae --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import java.util.List; +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +public class BulkResourceSequencingUtilsTest { + + @Test + public void testProcess(){ + List assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); + Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); + BulkResourceSequencingUtils.process(assignments); + } +} \ No newline at end of file diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..13bf8195e --- /dev/null +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,99 @@ +/* + * 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. + * 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.resource.dict.utils; + + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.HashMap; +import java.util.Map; +/** + * ResourceDictionaryUtilsTest. + * + * @author Brinda Santh + */ +public class ResourceDictionaryUtilsTest { + private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void testPopulateSourceMapping() { + + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("sample-assignment"); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + Map sources = new HashMap<>(); + resourceDefinition.setSources(sources); + // To Check Empty Source + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); + + // To Check First Source + resourceAssignment.setDictionarySource(null); + sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); + + // To Check Assigned Source + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource()); + + } + + @Test + public void testFindFirstSource() { + //To check if Empty Source + Map sources = new HashMap<>(); + String firstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertNull("Source populated, which is not expected.", firstSource); + + // TO check the first Source + sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); + String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); + + // TO check the multiple Source + sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate()); + String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); + + } + + @Test + public void testAssignInputs() { + JsonNode data = JacksonUtils.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); + Map context = new HashMap<>(); + ResourceDictionaryUtils.assignInputs(data, context); + String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); + log.info("populated context {}", context); + Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); + + } + + +} diff --git a/components/resource-dict/src/test/resources/data/resource-assignment-input.json b/components/resource-dict/src/test/resources/data/resource-assignment-input.json new file mode 100644 index 000000000..d79c90682 --- /dev/null +++ b/components/resource-dict/src/test/resources/data/resource-assignment-input.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/components/resource-dict/src/test/resources/enrich/simple-enrich.json b/components/resource-dict/src/test/resources/enrich/simple-enrich.json new file mode 100644 index 000000000..641da80a2 --- /dev/null +++ b/components/resource-dict/src/test/resources/enrich/simple-enrich.json @@ -0,0 +1,37 @@ +[ + { + "name": "rs-db-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "db-source", + "dictionary-source": "db", + "dependencies": [ + "input-source" + ] + }, + { + "name": "ra-default-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "default-source", + "dictionary-source": "default", + "dependencies": [] + }, + { + "name": "ra-input-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "input-source", + "dictionary-source": "input", + "dependencies": [] + } +] diff --git a/components/resource-dict/src/test/resources/validation/cyclic.json b/components/resource-dict/src/test/resources/validation/cyclic.json new file mode 100644 index 000000000..d837dc5d8 --- /dev/null +++ b/components/resource-dict/src/test/resources/validation/cyclic.json @@ -0,0 +1,111 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac", + "managed-ip1" + ] + } +] diff --git a/components/resource-dict/src/test/resources/validation/duplicate.json b/components/resource-dict/src/test/resources/validation/duplicate.json new file mode 100644 index 000000000..330324cda --- /dev/null +++ b/components/resource-dict/src/test/resources/validation/duplicate.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] diff --git a/components/resource-dict/src/test/resources/validation/success.json b/components/resource-dict/src/test/resources/validation/success.json new file mode 100644 index 000000000..3215d06d7 --- /dev/null +++ b/components/resource-dict/src/test/resources/validation/success.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] -- cgit 1.2.3-korg