2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.controllerblueprints.validation
20 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTypeValidatorService
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintWorkflowValidator
24 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
25 import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils
26 import org.slf4j.LoggerFactory
27 import org.springframework.beans.factory.config.ConfigurableBeanFactory
28 import org.springframework.context.annotation.Scope
29 import org.springframework.stereotype.Service
31 @Service("default-workflow-validator")
32 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
33 open class BlueprintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BlueprintTypeValidatorService) : BlueprintWorkflowValidator {
35 private val log = LoggerFactory.getLogger(BlueprintServiceTemplateValidatorImpl::class.toString())
36 lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*>
38 var paths: MutableList<String> = arrayListOf()
40 override fun validate(bluePrintRuntimeService: BlueprintRuntimeService<*>, workflowName: String, workflow: Workflow) {
41 log.info("Validating Workflow($workflowName)")
43 this.bluePrintRuntimeService = bluePrintRuntimeService
45 paths.add(workflowName)
46 paths.joinToString(BlueprintConstants.PATH_DIVIDER)
48 // Validate Workflow Inputs
49 validateInputs(workflow)
51 // Validate Workflow outputs
52 validateOutputs(workflow)
54 // Step Validation Start
56 workflow.steps?.forEach { stepName, step ->
58 paths.joinToString(BlueprintConstants.PATH_DIVIDER)
63 val nodeTemplate = bluePrintRuntimeService.bluePrintContext().nodeTemplateByName(it)
65 val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom
68 nodeTypeDerivedFrom == BlueprintConstants.MODEL_TYPE_NODE_WORKFLOW ||
69 nodeTypeDerivedFrom == BlueprintConstants.MODEL_TYPE_NODE_COMPONENT
71 "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected " +
72 "'${BlueprintConstants.MODEL_TYPE_NODE_WORKFLOW}' or '${BlueprintConstants.MODEL_TYPE_NODE_COMPONENT}'"
74 } catch (e: Exception) {
75 bluePrintRuntimeService.getBlueprintError()
77 "Failed to validate Workflow($workflowName)'s step($stepName)'s " +
79 paths.joinToString(BlueprintConstants.PATH_DIVIDER), e.message!!,
80 "BlueprintWorkflowValidatorImpl"
85 paths.removeAt(paths.lastIndex)
86 // Step Validation Ends
87 paths.removeAt(paths.lastIndex)
89 paths.removeAt(paths.lastIndex)
92 private fun validateInputs(workflow: Workflow) {
93 workflow.inputs?.let {
94 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!)
98 private fun validateOutputs(workflow: Workflow) {
99 workflow.outputs?.let {
101 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.outputs!!)
103 PropertyAssignmentValidationUtils(bluePrintRuntimeService.bluePrintContext())
104 .validatePropertyDefinitionNAssignments(workflow.outputs!!)
106 // Validate Value or Expression
107 workflow.outputs?.forEach { propertyName, propertyDefinition ->