Controller Blueprints Microservice
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 5 Sep 2018 23:40:46 +0000 (23:40 +0000)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 5 Sep 2018 23:40:46 +0000 (23:40 +0000)
Add Property Assign validation and Data Type Entry schema validation.

Change-Id: Ifa40f62f848d06381ab83d7f1c9e7c6526f5edf0
Issue-ID: CCSDK-484
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
14 files changed:
components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json
components/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json
components/core/load/model_type/node_type/component-resource-assignment.json
components/core/load/model_type/node_type/dg-activate-netconf.json
components/core/load/model_type/node_type/dg-config-generator.json
components/core/load/model_type/node_type/dg-resource-assign-activate.json
components/core/load/model_type/node_type/dg-resource-assignment.json
components/core/load/model_type/node_type/tosca.nodes.Component.json [new file with mode: 0644]
components/core/load/model_type/node_type/tosca.nodes.DG.json [new file with mode: 0644]
components/core/load/model_type/node_type/tosca.nodes.Vnf.json [new file with mode: 0644]
components/core/load/model_type/node_type/tosca.nodes.component.Python.json [new file with mode: 0644]
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt

index 635e177..7b9b7dd 100644 (file)
@@ -44,7 +44,7 @@
       "resource-assignment": {\r
         "type": "component-resource-assignment",\r
         "properties":{\r
-          "request-id": ["1234", "1234"]\r
+          "request-id": "1234"\r
         },\r
         "interfaces": {\r
           "DefaultComponentNode": {\r
@@ -80,7 +80,7 @@
       "resource-assignment-py": {\r
         "type": "component-resource-assignment",\r
         "properties":{\r
-          "request-id": ["1234", "1234"]\r
+          "request-id": "1234"\r
         },\r
         "interfaces": {\r
           "DefaultComponentNode": {\r
     "tosca.nodes.component.Python": {\r
       "description": "This is Resource Assignment Python Component API",\r
       "version": "1.0.0",\r
-      "properties": {\r
-        "type": {\r
-          "description": "Request Id used to store the generated configuration, in the database along with the template-name",\r
-          "required": false,\r
-          "type": "string"\r
-        }\r
-      },\r
-      "interfaces": {\r
-        "DefaultOperation": {\r
-          "operations": {\r
-            "validate": {\r
-              "inputs": {\r
-                "action-name": {\r
-                  "description": "validate for action",\r
-                  "required": false,\r
-                  "type": "string"\r
-                }\r
-              }\r
-            }\r
-          }\r
-        }\r
-      },\r
-      "artifacts" :{\r
-        "component-jar": {\r
-          "description": "Component Jar",\r
-          "type": "artifact-component-jar",\r
-          "file": "Component/basecomponent.jar"\r
-        }\r
-      },\r
       "derived_from": "tosca.nodes.Root"\r
     },\r
     "component-resource-assignment": {\r
index e78f32f..65028ac 100644 (file)
         "properties": {\r
           "mode": "sync",\r
           "version": "LATEST",\r
-          "is-start-flow": "false"\r
+          "is-start-flow": false\r
         },\r
         "requirements": {\r
           "component-dependency": {\r
         "properties": {\r
           "mode": "sync",\r
           "version": "LATEST",\r
-          "is-start-flow": "false"\r
+          "is-start-flow": false\r
         },\r
         "requirements": {\r
           "component-dependency": {\r
index 34c0284..03f3c28 100644 (file)
@@ -7,7 +7,7 @@
     }\r
   },\r
   "interfaces": {\r
-    "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": {\r
+    "org-onap-sdnc-config-assignment-service-ConfigAssignmentNode": {\r
       "operations": {\r
         "process": {\r
           "inputs": {\r
index c638df0..a9d16ed 100644 (file)
@@ -15,7 +15,7 @@
                "is-start-flow": {
                        "required": false,
                        "type": "boolean",
-                       "default": "false"
+                       "default": false
                }
        },
        "capabilities": {
index 28bace0..6794b3c 100644 (file)
@@ -15,7 +15,7 @@
                "is-start-flow": {\r
                        "required": false,\r
                        "type": "boolean",\r
-                       "default": "false"\r
+                       "default": false\r
                }\r
        },\r
        "capabilities": {\r
index e98fa5a..22a4d81 100644 (file)
@@ -15,7 +15,7 @@
                "is-start-flow": {\r
                        "required": false,\r
                        "type": "boolean",\r
-                       "default": "false"\r
+                       "default": false\r
                }\r
        },\r
        "capabilities": {\r
index 36fbb68..7c01faa 100644 (file)
@@ -15,7 +15,7 @@
                "is-start-flow": {\r
                        "required": false,\r
                        "type": "boolean",\r
-                       "default": "false"\r
+                       "default": false\r
                }\r
        },\r
        "capabilities": {\r
diff --git a/components/core/load/model_type/node_type/tosca.nodes.Component.json b/components/core/load/model_type/node_type/tosca.nodes.Component.json
new file mode 100644 (file)
index 0000000..bc4827b
--- /dev/null
@@ -0,0 +1,5 @@
+{\r
+  "description": "This is default Component Node",\r
+  "version": "1.0.0",\r
+  "derived_from": "tosca.nodes.Root"\r
+}
\ No newline at end of file
diff --git a/components/core/load/model_type/node_type/tosca.nodes.DG.json b/components/core/load/model_type/node_type/tosca.nodes.DG.json
new file mode 100644 (file)
index 0000000..86728cf
--- /dev/null
@@ -0,0 +1,5 @@
+{\r
+  "description": "This is Directed Graph Node Type",\r
+  "version": "1.0.0",\r
+  "derived_from": "tosca.nodes.Root"\r
+}
\ No newline at end of file
diff --git a/components/core/load/model_type/node_type/tosca.nodes.Vnf.json b/components/core/load/model_type/node_type/tosca.nodes.Vnf.json
new file mode 100644 (file)
index 0000000..acb1f2f
--- /dev/null
@@ -0,0 +1,5 @@
+{\r
+  "description": "This is VNF Node Type",\r
+  "version": "1.0.0",\r
+  "derived_from": "tosca.nodes.Root"\r
+}
\ No newline at end of file
diff --git a/components/core/load/model_type/node_type/tosca.nodes.component.Python.json b/components/core/load/model_type/node_type/tosca.nodes.component.Python.json
new file mode 100644 (file)
index 0000000..7b67c8c
--- /dev/null
@@ -0,0 +1,5 @@
+{\r
+  "description": "This is Python Component",\r
+  "version": "1.0.0",\r
+  "derived_from": "tosca.nodes.Root"\r
+}
\ No newline at end of file
index 4ae1f4d..ffad8e5 100644 (file)
@@ -94,6 +94,8 @@ object BluePrintConstants {
     const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python"\r
     const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript"\r
 \r
+    const val MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION ="tosca.artifacts.Implementation"\r
+\r
     const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"\r
 \r
     const val EXPRESSION_GET_INPUT: String = "get_input"\r
index 33c811f..af3966a 100644 (file)
@@ -23,6 +23,33 @@ package org.onap.ccsdk.apps.controllerblueprints.core
  */\r
 object BluePrintTypes {\r
 \r
+    @JvmStatic\r
+    val validNodeTypeDerivedFroms: MutableList<String> = arrayListOf(\r
+            BluePrintConstants.MODEL_TYPE_NODES_ROOT,\r
+            BluePrintConstants.MODEL_TYPE_NODE_DG,\r
+            BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,\r
+            BluePrintConstants.MODEL_TYPE_NODE_VNF,\r
+            BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT,\r
+            BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,\r
+            BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA,\r
+            BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_BUNDLE,\r
+            BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_SCRIPT,\r
+            BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_PYTHON,\r
+            BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT\r
+    )\r
+\r
+    @JvmStatic\r
+    val validArtifactTypeDerivedFroms: MutableList<String> = arrayListOf(\r
+            BluePrintConstants.MODEL_TYPE_ARTIFACTS_ROOT,\r
+            BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION\r
+    )\r
+\r
+    @JvmStatic\r
+    val validDataTypeDerivedFroms: MutableList<String> = arrayListOf(\r
+            BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT,\r
+            BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC\r
+    )\r
+\r
     @JvmStatic\r
     fun validModelTypes(): List<String> {\r
         val validTypes: MutableList<String> = arrayListOf()\r
index 34399fd..a3b68e0 100644 (file)
@@ -23,6 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.*
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
 import com.att.eelf.configuration.EELFLogger\r
 import com.att.eelf.configuration.EELFManager\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import java.io.Serializable\r
 \r
 /**\r
@@ -52,7 +53,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
 \r
     @Throws(BluePrintException::class)\r
     override fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>) {\r
-        validateBlueprint(bluePrintContext.serviceTemplate,properties)\r
+        validateBlueprint(bluePrintContext.serviceTemplate, properties)\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
@@ -121,7 +122,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("nodeTypes")\r
         nodeTypes.forEach { nodeTypeName, nodeType ->\r
             // Validate Single Node Type\r
-            validateNodeType(nodeTypeName,nodeType)\r
+            validateNodeType(nodeTypeName, nodeType)\r
         }\r
         paths.removeAt(paths.lastIndex)\r
     }\r
@@ -132,13 +133,20 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         message.appendln("--> Node Type :" + paths.joinToString(separator))\r
         val derivedFrom: String = nodeType.derivedFrom\r
         //Check Derived From\r
-        checkValidNodeTypesDerivedFrom(derivedFrom)\r
+        checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom)\r
 \r
         nodeType.properties?.let { validatePropertyDefinitions(nodeType.properties!!) }\r
         nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) }\r
         paths.removeAt(paths.lastIndex)\r
     }\r
 \r
+    @Throws(BluePrintException::class)\r
+    open fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) {\r
+        check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) {\r
+            throw BluePrintException(format("Failed to get node type ({})'s  derived from({}) definition ", nodeTypeName, derivedFrom))\r
+        }\r
+    }\r
+\r
     @Throws(BluePrintException::class)\r
     open fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) {\r
         paths.add("topology")\r
@@ -167,7 +175,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) {\r
+    open fun validateNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) {\r
         paths.add(nodeTemplateName)\r
         message.appendln("---> Node Template :" + paths.joinToString(separator))\r
         val type: String = nodeTemplate.type\r
@@ -183,6 +191,25 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.removeAt(paths.lastIndex)\r
     }\r
 \r
+    @Throws(BluePrintException::class)\r
+    open fun validateArtifactDefinitions(artifacts: MutableMap<String, ArtifactDefinition>) {\r
+        paths.add("artifacts")\r
+        artifacts.forEach { artifactDefinitionName, artifactDefinition ->\r
+            paths.add(artifactDefinitionName)\r
+            message.appendln("Validating artifact " + paths.joinToString(separator))\r
+            val type: String = artifactDefinition.type\r
+                    ?: throw BluePrintException("type is missing for artifact definition :" + artifactDefinitionName)\r
+            // Check Artifact Type\r
+            checkValidArtifactType(artifactDefinitionName, type)\r
+\r
+            val file: String = artifactDefinition.file\r
+                    ?: throw BluePrintException(format("file is missing for artifact definition : {}", artifactDefinitionName))\r
+\r
+            paths.removeAt(paths.lastIndex)\r
+        }\r
+        paths.removeAt(paths.lastIndex)\r
+    }\r
+\r
     @Throws(BluePrintException::class)\r
     open fun validateWorkFlows(workflows: MutableMap<String, Workflow>) {\r
         paths.add("workflows")\r
@@ -195,7 +222,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun validateWorkFlow(workflowName:String, workflow: Workflow) {\r
+    open fun validateWorkFlow(workflowName: String, workflow: Workflow) {\r
         paths.add(workflowName)\r
         message.appendln("---> Workflow :" + paths.joinToString(separator))\r
         // Step Validation Start\r
@@ -239,31 +266,20 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         properties.forEach { propertyName, propertyAssignment ->\r
             val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName]\r
                     ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName))\r
-            // Check and Validate if Expression Node\r
-            val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)\r
-            if (!expressionData.isExpression) {\r
-                checkPropertyValue(propertyDefinition, propertyAssignment)\r
-            }\r
+\r
+            validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment)\r
+\r
         }\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun validateArtifactDefinitions(artifacts: MutableMap<String, ArtifactDefinition>) {\r
-        paths.add("artifacts")\r
-        artifacts.forEach { artifactName, artifactDefinition ->\r
-            paths.add(artifactName)\r
-            message.appendln("Validating artifact " + paths.joinToString(separator))\r
-            val type: String = artifactDefinition.type\r
-                    ?: throw BluePrintException("type is missing for artifact definition :" + artifactName)\r
-            // Check Artifact Type\r
-            checkValidArtifactType(type)\r
-\r
-            val file: String = artifactDefinition.file\r
-                    ?: throw BluePrintException(format("file is missing for artifact definition : {}", artifactName))\r
-\r
-            paths.removeAt(paths.lastIndex)\r
+    open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition,\r
+                                        propertyAssignment: JsonNode) {\r
+        // Check and Validate if Expression Node\r
+        val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)\r
+        if (!expressionData.isExpression) {\r
+            checkPropertyValue(propertyName, propertyDefinition, propertyAssignment)\r
         }\r
-        paths.removeAt(paths.lastIndex)\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
@@ -313,34 +329,65 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun checkValidNodeType(nodeType : String) {\r
+    open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) {\r
+\r
+        val artifactType = serviceTemplate.artifactTypes?.get(artifactTypeName)\r
+                ?: throw BluePrintException(format("Failed to artifact type for artifact definition : {}", artifactDefinitionName))\r
 \r
+        checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom)\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun checkValidArtifactType(artifactType: String) {\r
-\r
-        serviceTemplate.artifactTypes?.containsKey(artifactType)\r
-                ?: throw BluePrintException(format("Failed to node type definition for artifact definition : {}", artifactType))\r
+    open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) {\r
+        check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) {\r
+            throw BluePrintException(format("Failed to get artifact type ({})'s  derived from({}) definition ", artifactTypeName, derivedFrom))\r
+        }\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
-    open fun checkValidNodeTypesDerivedFrom(derivedFrom: String) {\r
-\r
+    open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) {\r
+        check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) {\r
+            throw BluePrintException(format("Failed to get data type ({})'s  derived from({}) definition ", dataTypeName, derivedFrom))\r
+        }\r
     }\r
 \r
-    private fun checkPropertyValue(propertyDefinition: PropertyDefinition, jsonNode: JsonNode) {\r
-        //log.info("validating path ({}), Property {}, value ({})", paths, propertyDefinition, jsonNode)\r
-    }\r
+    open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) {\r
+        val propertyType = propertyDefinition.type\r
+        val isValid: Boolean\r
+\r
+        if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) {\r
+            isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment)\r
+\r
+        } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {\r
+\r
+            isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)\r
+            val entrySchemaType = propertyDefinition.entrySchema?.type\r
+                    ?: throw BluePrintException(format("Failed to get Entry Schema type for the collection property ({})", propertyName))\r
+\r
+            if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) {\r
+                checkPropertyDataType(entrySchemaType, propertyName)\r
+            }\r
 \r
-    private fun checkPropertyDataType(dataType: String, propertyName: String): Boolean {\r
-        if (checkDataType(dataType)) {\r
-            return true\r
         } else {\r
-            throw BluePrintException(format("Data type ({}) for the property ({}) not found", dataType, propertyName))\r
+            checkPropertyDataType(propertyType, propertyName)\r
+            isValid = true\r
+        }\r
+\r
+        check(isValid) {\r
+            throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})",\r
+                    propertyName, propertyType, propertyAssignment))\r
         }\r
     }\r
 \r
+    private fun checkPropertyDataType(dataType: String, propertyName: String) {\r
+\r
+        val dataType = serviceTemplate.dataTypes?.get(dataType)\r
+                ?: throw BluePrintException(format("Data type ({}) for the property ({}) not found", dataType, propertyName))\r
+\r
+        checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom)\r
+\r
+    }\r
+\r
     private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean {\r
         if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {\r
             return true\r
@@ -353,8 +400,4 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         return serviceTemplate.dataTypes?.containsKey(key) ?: false\r
     }\r
 \r
-    private fun checkNodeType(key: String): Boolean {\r
-        return serviceTemplate.nodeTypes?.containsKey(key) ?: false\r
-    }\r
-\r
 }
\ No newline at end of file