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 com.att.eelf.configuration.EELFLogger
21 import com.att.eelf.configuration.EELFManager
22 import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
25 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowValidator
27 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
28 import org.springframework.beans.factory.config.ConfigurableBeanFactory
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Service
32 @Service("default-workflow-validator")
33 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
34 open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintWorkflowValidator {
36 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
37 lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
39 var paths: MutableList<String> = arrayListOf()
41 override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, workflowName: String, workflow: Workflow) {
42 log.info("Validating Workflow($workflowName)")
44 this.bluePrintRuntimeService = bluePrintRuntimeService
47 paths.add(workflowName)
48 paths.joinToString(BluePrintConstants.PATH_DIVIDER)
50 // Validate Workflow Inputs
51 validateInputs(workflow)
53 // Validate Workflow outputs
54 validateOutputs(workflow)
56 // Step Validation Start
58 workflow.steps?.forEach { stepName, step ->
60 paths.joinToString(BluePrintConstants.PATH_DIVIDER)
65 val nodeTemplate = bluePrintRuntimeService.bluePrintContext().nodeTemplateByName(it)
67 val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom
69 check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG
70 || nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_COMPONENT) {
71 "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected " +
72 "'${BluePrintConstants.MODEL_TYPE_NODE_DG}' or '${BluePrintConstants.MODEL_TYPE_NODE_COMPONENT}'"
74 } catch (e: Exception) {
75 bluePrintRuntimeService.getBluePrintError()
76 .addError("Failed to validate Workflow($workflowName)'s step($stepName)'s " +
77 "definition", paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!)
82 paths.removeAt(paths.lastIndex)
83 // Step Validation Ends
84 paths.removeAt(paths.lastIndex)
86 paths.removeAt(paths.lastIndex)
89 private fun validateInputs(workflow: Workflow) {
90 workflow.inputs?.let {
91 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!)
95 private fun validateOutputs(workflow: Workflow) {
96 workflow.outputs?.let {
98 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.outputs!!)
100 PropertyAssignmentValidationUtils(bluePrintRuntimeService.bluePrintContext())
101 .validatePropertyDefinitionNAssignments(workflow.outputs!!)
103 // Validate Value or Expression
104 workflow.outputs?.forEach { propertyName, propertyDefinition ->