2 * ============LICENSE_START===================================================
3 * Copyright (c) 2018 Amdocs
4 * ============================================================================
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.
16 * ============LICENSE_END=====================================================
22 indices 'default-rules'
26 // NDCB-AAI comparison: Context level
28 name 'NDCB-AAI-attribute-comparison'
29 attributes 'context-list.ndcb', 'context-list.aai'
32 // NDCB-AAI comparison: Service entity
34 name 'NDCB-AAI-attribute-comparison'
35 attributes 'context-list.ndcb.service', 'context-list.aai.service'
38 // NDCB-AAI comparison: VF list
40 name 'NDCB-AAI-attribute-comparison'
41 attributes 'context-list.ndcb.vfList[*]', 'context-list.aai.vfList[*]'
44 // NDCB-AAI comparison: VF-Module list
46 name 'NDCB-AAI-attribute-comparison'
47 attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
50 // NDCB-AAI comparison: VNFC list
52 name 'NDCB-AAI-attribute-comparison'
53 attributes 'context-list.ndcb.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
56 // NDCB-AAI comparison: VM list
58 name 'NDCB-AAI-attribute-comparison'
59 attributes 'context-list.ndcb.vfList[*].vfModuleList[*].vmList[*]', 'context-list.aai.vfList[*].vfModuleList[*].vmList[*]'
62 // NDCB-AAI comparison: Network list
64 name 'NDCB-AAI-attribute-comparison'
65 attributes 'context-list.ndcb.vfList[*].vfModuleList[*].networkList[*]', 'context-list.aai.vfList[*].vfModuleList[*].networkList[*]'
70 name 'SDC-AAI-vnfc-type'
71 attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
74 // SDC-AAI VNFC node count
76 name 'SDC-AAI-vnfc-node-count'
77 attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
80 // SDC-AAI VF-Module instance
82 name 'SDC-AAI-vf-module-instance-check'
83 attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
89 name 'SDC-AAI-vnfc-type'
90 category 'INVALID_VALUE'
91 description 'Validate that each VNFC instance in AAI conforms to a VNFC type defined in SDC model'
92 errorText 'AAI VNFC instance includes non-specified type in design SDC model'
94 attributes 'sdcList', 'aaiList'
96 def getVnfcTypes = { parsedData ->
97 parsedData.collect{ it.findResult{ k, v -> if(k.equals("type")) {return "$v"}}}
100 def slurper = new groovy.json.JsonSlurper()
101 def sdcTypes = getVnfcTypes(slurper.parseText(sdcList.toString()))
102 def aaiTypes = getVnfcTypes(slurper.parseText(aaiList.toString()))
104 // each type in AAI must exist in SDC
105 return aaiTypes.containsAll(sdcTypes)
110 name 'SDC-AAI-vnfc-node-count'
111 category 'INVALID_VALUE'
112 description 'Validate that for each VNFC node defined in SDC model, there is at least one VNFC instance in AAI'
113 errorText 'Design has specified types but not all of them exist in AAI'
115 attributes 'sdcList', 'aaiList'
117 def getVnfcNodes = { parsedData ->
118 parsedData.collect { new Tuple2(
119 it.findResult{ k, v -> if(k.equals("name")) {return "$v"}},
120 it.findResult{ k, v -> if(k.equals("type")) {return "$v"}})
124 def slurper = new groovy.json.JsonSlurper()
125 def sdcNodes = getVnfcNodes(slurper.parseText(sdcList.toString()))
126 def aaiNodes = getVnfcNodes(slurper.parseText(aaiList.toString()))
128 // each node in AAI must exist in SDC
129 return aaiNodes.containsAll(sdcNodes)
134 name 'SDC-AAI-vf-module-instance-check'
135 category 'INVALID_VALUE'
136 description 'Validate that each VF module instance in AAI conforms to a VF module defined in SDC service model'
137 errorText 'One or more AAI VF module instance(s) not defined in SDC model'
139 attributes 'sdcList', 'aaiList'
141 def getVfModules = { parsedData ->
142 parsedData.collect{ it.findResult{ k, v -> if(k.equals("name")) {return "$v"}}}
145 def slurper = new groovy.json.JsonSlurper()
146 def sdcVfModules = getVfModules(slurper.parseText(sdcList.toString()))
147 def aaiVfModules = getVfModules(slurper.parseText(aaiList.toString()))
149 // all VF modules in AAI must exist in SDC
150 return aaiVfModules.containsAll(sdcVfModules)
155 name 'NDCB-AAI-attribute-comparison'
156 category 'INVALID_VALUE'
157 description 'Verify that all attributes in Network-Discovery are the same as in AAI'
158 errorText 'Error found with attribute "{0}"; value "{1}" does not exist in Network-Discovery'
160 attributes 'ndcbItems', 'aaiItems'
162 Closure<java.util.Map> getAttributes = { parsedData ->
163 java.util.Map attributeMap = new java.util.HashMap()
165 def isAttributeDataQualityOk = { attribute ->
166 attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
169 def addToMap = { attrKey, attrValue ->
170 java.util.Set values = attributeMap.get("$attrKey")
172 values = new java.util.HashSet()
173 attributeMap.put("$attrKey", values)
175 values.add("$attrValue")
178 def addAttributeToMap = { attribute ->
179 if(isAttributeDataQualityOk(attribute)) {
181 attribute.each { k, v ->
182 if(k.equals("name")) {key = "$v"}
183 if(k.equals("value")) {value = "$v"}
185 addToMap("$key", "$value")
189 def processKeyValue = { key, value ->
190 if(value instanceof java.util.ArrayList) {
191 if(key.equals("attributeList")) {
193 addAttributeToMap(it)
196 } else if(!(value instanceof groovy.json.internal.LazyMap)) {
197 // only add key-value attributes, skip the rest
198 addToMap("$key", "$value")
202 if(parsedData instanceof java.util.ArrayList) {
204 it.each { key, value -> processKeyValue(key, value) }
207 parsedData.each { key, value -> processKeyValue(key, value) }
212 def slurper = new groovy.json.JsonSlurper()
213 java.util.Map ndcb = getAttributes(slurper.parseText(ndcbItems.toString()))
214 java.util.Map aai = getAttributes(slurper.parseText(aaiItems.toString()))
216 boolean result = true
217 List<String> details = new ArrayList<>();
218 ndcb.any{ ndcbKey, ndcbValueList ->
219 def aaiValueList = aai.get("$ndcbKey")
220 aaiValueList.each{ aaiValue ->
221 if(!ndcbValueList.any{ it == "$aaiValue" }) {
223 details.add("$ndcbKey")
224 details.add("$aaiValue")
227 if(result == false) {
228 // break out of 'any' loop
232 return new Tuple2(result, details)