diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-01-09 16:57:48 -0500 |
---|---|---|
committer | Alexis de Talhouët <alexis.de_talhouet@bell.ca> | 2019-01-11 14:17:31 +0000 |
commit | 423afe7b0c6282e3f22a912066185aa6f83e029c (patch) | |
tree | 9130691628ca32ac8b788f3c78027eede90f60b2 /components/core/src/main/kotlin | |
parent | 158912e6bbaaeda6e1f764b83da0ee253e9011a1 (diff) |
Add support for workflow validation
Also, add support for mock in Kotlin using
https://mockk.io/
Change-Id: Ia85e1180e09e9d08a02de515b1cc4158c3bccd5c
Issue-ID: CCSDK-717
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'components/core/src/main/kotlin')
3 files changed, 28 insertions, 4 deletions
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 index 9767b2e1..663c1fe6 100644 --- 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 @@ -502,7 +502,7 @@ class InterfaceAssignment { 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 {
+open class NodeTemplate { @get:JsonIgnore
var id: String? = null
var description: String? = null
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 index bc1f4b43..1a6d096d 100644 --- 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 @@ -148,7 +148,7 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates
fun nodeTemplateByName(name: String): NodeTemplate =
- nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name) ")
+ nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? {
return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap()
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt index 1a138c3a..f55449ef 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt @@ -19,7 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.core.validation import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowValidator import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService @@ -42,14 +45,35 @@ open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ // Step Validation Start paths.add("steps") - workflow.steps?.forEach { stepName, _ -> + workflow.steps?.forEach { stepName, step -> paths.add(stepName) paths.joinToString(BluePrintConstants.PATH_DIVIDER) - // TODO("Step Validation") + + // Validate target + step.target?.let { + try { + val nodeTemplate = bluePrintRuntimeService.bluePrintContext().nodeTemplateByName(it) + + val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom + + check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG) { + "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected is " + + "'${BluePrintConstants.MODEL_TYPE_NODE_DG}'" + } + } catch (e: Exception) { + bluePrintRuntimeService.getBluePrintError() + .addError("Failed to validate Workflow($workflowName)'s step($stepName)'s " + + "definition", paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) + } + } paths.removeAt(paths.lastIndex) } paths.removeAt(paths.lastIndex) // Step Validation Ends paths.removeAt(paths.lastIndex) + + workflow.inputs?.let { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!) + } } }
\ No newline at end of file |