2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.core.validation
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
27 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateValidator
28 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
29 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
31 open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator {
33 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
35 var bluePrintContext: BluePrintContext? = null
36 var error: BluePrintValidationError? = null
38 override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
39 log.trace("Validating Topology Template..")
40 this.bluePrintContext = bluePrintContext
44 topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) }
45 // Validate Node Templates
46 topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) }
48 topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) }
51 @Throws(BluePrintException::class)
52 fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) {
53 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext!!, error!!, inputs)
57 @Throws(BluePrintException::class)
58 fun validateNodeTemplates(nodeTemplates: MutableMap<String, NodeTemplate>) {
60 nodeTemplates.forEach { nodeTemplateName, nodeTemplate ->
61 // Validate Single Node Template
62 bluePrintTypeValidatorService.validateNodeTemplate(bluePrintContext!!, error!!, nodeTemplateName, nodeTemplate)
66 @Throws(BluePrintException::class)
67 open fun validateWorkflows(workflows: MutableMap<String, Workflow>) {
69 workflows.forEach { workflowName, workflow ->
70 // Validate Single workflow
71 bluePrintTypeValidatorService.validateWorkflow(bluePrintContext!!, error!!, workflowName, workflow)