aboutsummaryrefslogtreecommitdiffstats
path: root/components/core/src
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-09-05 23:40:46 +0000
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-09-05 23:40:46 +0000
commit50eeeb8ec7bf3dc6c1d43f82f340b4abbec964de (patch)
tree39e0ddad0cfd80b3c7aac64e9a47daf523ef49f3 /components/core/src
parentcb7b049aa0ae2a0eda114a5793a1af4db51b148f (diff)
Controller Blueprints Microservice
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>
Diffstat (limited to 'components/core/src')
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt2
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt27
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt129
3 files changed, 115 insertions, 43 deletions
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
index 4ae1f4d5..ffad8e56 100644
--- 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
@@ -94,6 +94,8 @@ object BluePrintConstants {
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_ARTIFACT_TYPE_IMPLEMENTATION ="tosca.artifacts.Implementation"
+
const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"
const val EXPRESSION_GET_INPUT: String = "get_input"
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
index 33c811f4..af3966aa 100644
--- 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
@@ -24,6 +24,33 @@ package org.onap.ccsdk.apps.controllerblueprints.core
object BluePrintTypes {
@JvmStatic
+ val validNodeTypeDerivedFroms: MutableList<String> = arrayListOf(
+ BluePrintConstants.MODEL_TYPE_NODES_ROOT,
+ BluePrintConstants.MODEL_TYPE_NODE_DG,
+ BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
+ BluePrintConstants.MODEL_TYPE_NODE_VNF,
+ BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT,
+ BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
+ BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA,
+ BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_BUNDLE,
+ BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_SCRIPT,
+ BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_PYTHON,
+ BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT
+ )
+
+ @JvmStatic
+ val validArtifactTypeDerivedFroms: MutableList<String> = arrayListOf(
+ BluePrintConstants.MODEL_TYPE_ARTIFACTS_ROOT,
+ BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION
+ )
+
+ @JvmStatic
+ val validDataTypeDerivedFroms: MutableList<String> = arrayListOf(
+ BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT,
+ BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC
+ )
+
+ @JvmStatic
fun validModelTypes(): List<String> {
val validTypes: MutableList<String> = arrayListOf()
validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
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
index 34399fdd..a3b68e0d 100644
--- 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
@@ -23,6 +23,7 @@ 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 org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import java.io.Serializable
/**
@@ -52,7 +53,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
@Throws(BluePrintException::class)
override fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>) {
- validateBlueprint(bluePrintContext.serviceTemplate,properties)
+ validateBlueprint(bluePrintContext.serviceTemplate, properties)
}
@Throws(BluePrintException::class)
@@ -121,7 +122,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
paths.add("nodeTypes")
nodeTypes.forEach { nodeTypeName, nodeType ->
// Validate Single Node Type
- validateNodeType(nodeTypeName,nodeType)
+ validateNodeType(nodeTypeName, nodeType)
}
paths.removeAt(paths.lastIndex)
}
@@ -132,7 +133,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
message.appendln("--> Node Type :" + paths.joinToString(separator))
val derivedFrom: String = nodeType.derivedFrom
//Check Derived From
- checkValidNodeTypesDerivedFrom(derivedFrom)
+ checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom)
nodeType.properties?.let { validatePropertyDefinitions(nodeType.properties!!) }
nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) }
@@ -140,6 +141,13 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
}
@Throws(BluePrintException::class)
+ open fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) {
+ check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) {
+ throw BluePrintException(format("Failed to get node type ({})'s derived from({}) definition ", nodeTypeName, derivedFrom))
+ }
+ }
+
+ @Throws(BluePrintException::class)
open fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) {
paths.add("topology")
message.appendln("--> Topology Template")
@@ -167,7 +175,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
}
@Throws(BluePrintException::class)
- open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) {
+ open fun validateNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) {
paths.add(nodeTemplateName)
message.appendln("---> Node Template :" + paths.joinToString(separator))
val type: String = nodeTemplate.type
@@ -184,6 +192,25 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
}
@Throws(BluePrintException::class)
+ open fun validateArtifactDefinitions(artifacts: MutableMap<String, ArtifactDefinition>) {
+ paths.add("artifacts")
+ artifacts.forEach { artifactDefinitionName, artifactDefinition ->
+ paths.add(artifactDefinitionName)
+ message.appendln("Validating artifact " + paths.joinToString(separator))
+ val type: String = artifactDefinition.type
+ ?: throw BluePrintException("type is missing for artifact definition :" + artifactDefinitionName)
+ // Check Artifact Type
+ checkValidArtifactType(artifactDefinitionName, type)
+
+ val file: String = artifactDefinition.file
+ ?: throw BluePrintException(format("file is missing for artifact definition : {}", artifactDefinitionName))
+
+ paths.removeAt(paths.lastIndex)
+ }
+ paths.removeAt(paths.lastIndex)
+ }
+
+ @Throws(BluePrintException::class)
open fun validateWorkFlows(workflows: MutableMap<String, Workflow>) {
paths.add("workflows")
workflows.forEach { workflowName, workflow ->
@@ -195,7 +222,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
}
@Throws(BluePrintException::class)
- open fun validateWorkFlow(workflowName:String, workflow: Workflow) {
+ open fun validateWorkFlow(workflowName: String, workflow: Workflow) {
paths.add(workflowName)
message.appendln("---> Workflow :" + paths.joinToString(separator))
// Step Validation Start
@@ -239,31 +266,20 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
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)
- }
+
+ validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment)
+
}
}
@Throws(BluePrintException::class)
- open fun validateArtifactDefinitions(artifacts: MutableMap<String, ArtifactDefinition>) {
- 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)
+ open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition,
+ propertyAssignment: JsonNode) {
+ // Check and Validate if Expression Node
+ val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)
+ if (!expressionData.isExpression) {
+ checkPropertyValue(propertyName, propertyDefinition, propertyAssignment)
}
- paths.removeAt(paths.lastIndex)
}
@Throws(BluePrintException::class)
@@ -313,34 +329,65 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
}
@Throws(BluePrintException::class)
- open fun checkValidNodeType(nodeType : String) {
+ open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) {
+
+ val artifactType = serviceTemplate.artifactTypes?.get(artifactTypeName)
+ ?: throw BluePrintException(format("Failed to artifact type for artifact definition : {}", artifactDefinitionName))
+ checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom)
}
@Throws(BluePrintException::class)
- open fun checkValidArtifactType(artifactType: String) {
-
- serviceTemplate.artifactTypes?.containsKey(artifactType)
- ?: throw BluePrintException(format("Failed to node type definition for artifact definition : {}", artifactType))
+ open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) {
+ check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) {
+ throw BluePrintException(format("Failed to get artifact type ({})'s derived from({}) definition ", artifactTypeName, derivedFrom))
+ }
}
@Throws(BluePrintException::class)
- open fun checkValidNodeTypesDerivedFrom(derivedFrom: String) {
-
+ open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) {
+ check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) {
+ throw BluePrintException(format("Failed to get data type ({})'s derived from({}) definition ", dataTypeName, derivedFrom))
+ }
}
- private fun checkPropertyValue(propertyDefinition: PropertyDefinition, jsonNode: JsonNode) {
- //log.info("validating path ({}), Property {}, value ({})", paths, propertyDefinition, jsonNode)
- }
+ open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, 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)
+ val entrySchemaType = propertyDefinition.entrySchema?.type
+ ?: throw BluePrintException(format("Failed to get Entry Schema type for the collection property ({})", propertyName))
+
+ if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) {
+ checkPropertyDataType(entrySchemaType, propertyName)
+ }
- 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))
+ checkPropertyDataType(propertyType, propertyName)
+ isValid = true
+ }
+
+ check(isValid) {
+ throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})",
+ propertyName, propertyType, propertyAssignment))
}
}
+ private fun checkPropertyDataType(dataType: String, propertyName: String) {
+
+ val dataType = serviceTemplate.dataTypes?.get(dataType)
+ ?: throw BluePrintException(format("Data type ({}) for the property ({}) not found", dataType, propertyName))
+
+ checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom)
+
+ }
+
private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean {
if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {
return true
@@ -353,8 +400,4 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
return serviceTemplate.dataTypes?.containsKey(key) ?: false
}
- private fun checkNodeType(key: String): Boolean {
- return serviceTemplate.nodeTypes?.containsKey(key) ?: false
- }
-
} \ No newline at end of file