1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTypeValidator {
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
lateinit var bluePrintContext: BluePrintContext
var paths: MutableList<String> = arrayListOf()
override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTypeName: String, nodeType: NodeType) {
log.trace("Validating NodeType($nodeTypeName)")
this.bluePrintRuntimeService = bluePrintRuntimeService
this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
paths.add(nodeTypeName)
val derivedFrom: String = nodeType.derivedFrom
//Check Derived From
checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom)
if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
bluePrintContext.serviceTemplate.nodeTypes?.get(derivedFrom)
?: throw BluePrintException("Failed to get derivedFrom NodeType($derivedFrom)'s for NodeType($nodeTypeName)")
}
nodeType.properties?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) }
nodeType.capabilities?.let { validateCapabilityDefinitions(nodeTypeName, nodeType) }
nodeType.requirements?.let { validateRequirementDefinitions(nodeTypeName, nodeType) }
nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) }
paths.removeAt(paths.lastIndex)
}
fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) {
check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) {
throw BluePrintException("Failed to get node type ($nodeTypeName)'s derivedFrom($derivedFrom) definition ")
}
}
open fun validateCapabilityDefinitions(nodeTypeName: String, nodeType: NodeType) {
val capabilities = nodeType.capabilities
paths.add("capabilities")
capabilities?.forEach { capabilityName, capabilityDefinition ->
paths.add(capabilityName)
validateCapabilityDefinition(nodeTypeName, nodeType, capabilityName, capabilityDefinition)
paths.removeAt(paths.lastIndex)
}
paths.removeAt(paths.lastIndex)
}
open fun validateCapabilityDefinition(nodeTypeName: String, nodeType: NodeType, capabilityName: String,
capabilityDefinition: CapabilityDefinition) {
val capabilityType = capabilityDefinition.type
check(BluePrintTypes.validCapabilityTypes.contains(capabilityType)) {
throw BluePrintException("failed to get CapabilityType($capabilityType) for NodeType($nodeTypeName)")
}
}
open fun validateRequirementDefinitions(nodeName: String, nodeType: NodeType) {
paths.add("requirements")
val requirements = nodeType.requirements
requirements?.forEach { requirementDefinitionName, requirementDefinition ->
paths.add(requirementDefinitionName)
validateRequirementDefinition(nodeName, nodeType, requirementDefinitionName, requirementDefinition)
paths.removeAt(paths.lastIndex)
}
paths.removeAt(paths.lastIndex)
}
open fun validateRequirementDefinition(nodeTypeName: String, nodeType: NodeType, requirementDefinitionName: String,
requirementDefinition: RequirementDefinition) {
log.info("validating NodeType({}) RequirementDefinition ({}) ", nodeTypeName, requirementDefinitionName)
val requirementNodeTypeName = requirementDefinition.node!!
val capabilityName = requirementDefinition.capability
val relationship = requirementDefinition.relationship!!
check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) {
throw BluePrintException("failed to get relationship($relationship) for NodeType($nodeTypeName)'s requirement($requirementDefinitionName)")
}
val relationShipNodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(requirementNodeTypeName)
?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s for requirement($requirementDefinitionName) ")
relationShipNodeType.capabilities?.get(capabilityName)
?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s " +
"capability($nodeTypeName) for NodeType ($capabilityName)'s requirement($requirementDefinitionName) ")
}
open fun validateInterfaceDefinitions(interfaces: MutableMap<String, InterfaceDefinition>) {
paths.add("interfaces")
interfaces.forEach { interfaceName, interfaceDefinition ->
paths.add(interfaceName)
interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) }
paths.removeAt(paths.lastIndex)
}
paths.removeAt(paths.lastIndex)
}
open fun validateOperationDefinitions(operations: MutableMap<String, OperationDefinition>) {
paths.add("operations")
operations.forEach { opertaionName, operationDefinition ->
paths.add(opertaionName)
operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) }
operationDefinition.inputs?.let {
bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.inputs!!)
}
operationDefinition.outputs?.let {
bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.outputs!!)
}
paths.removeAt(paths.lastIndex)
}
paths.removeAt(paths.lastIndex)
}
open fun validateImplementation(implementation: Implementation) {
checkNotEmptyOrThrow(implementation.primary)
}
}
|