411cdb4d3dd1439cc0864dd0de132eaff2ad0cdd
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.core.validation
18
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
30
31 open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator {
32
33     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
34
35     var bluePrintContext: BluePrintContext? = null
36     var error: BluePrintValidationError? = null
37
38     override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
39         log.trace("Validating Topology Template..")
40         this.bluePrintContext = bluePrintContext
41         this.error = error
42
43         // Validate Inputs
44         topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) }
45         // Validate Node Templates
46         topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) }
47         // Validate Workflow
48         topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) }
49     }
50
51     @Throws(BluePrintException::class)
52     fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) {
53         bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext!!, error!!, inputs)
54     }
55
56
57     @Throws(BluePrintException::class)
58     fun validateNodeTemplates(nodeTemplates: MutableMap<String, NodeTemplate>) {
59
60         nodeTemplates.forEach { nodeTemplateName, nodeTemplate ->
61             // Validate Single Node Template
62             bluePrintTypeValidatorService.validateNodeTemplate(bluePrintContext!!, error!!, nodeTemplateName, nodeTemplate)
63         }
64     }
65
66     @Throws(BluePrintException::class)
67     open fun validateWorkflows(workflows: MutableMap<String, Workflow>) {
68
69         workflows.forEach { workflowName, workflow ->
70             // Validate Single workflow
71             bluePrintTypeValidatorService.validateWorkflow(bluePrintContext!!, error!!, workflowName, workflow)
72         }
73     }
74
75 }