Merge "ZooKeeper and Kafka deployment changes"
[oom.git] / kubernetes / pomba / charts / pomba-validation-service / resources / bundleconfig / etc / rules / poa-event / default-rules.groovy
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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=====================================================
17  */
18
19 entity {
20     name 'POA-EVENT'
21     indexing {
22         indices 'default-rules'
23     }
24   validation {
25
26     // NDCB-AAI comparison: Context level
27     useRule {
28       name 'NDCB-AAI-attribute-comparison'
29       attributes 'context-list.ndcb', 'context-list.aai'
30     }
31
32     // NDCB-AAI comparison: Service entity
33     useRule {
34       name 'NDCB-AAI-attribute-comparison'
35       attributes 'context-list.ndcb.service', 'context-list.aai.service'
36     }
37
38     // NDCB-AAI comparison: VF list
39     useRule {
40       name 'NDCB-AAI-attribute-comparison'
41       attributes 'context-list.ndcb.vfList[*]', 'context-list.aai.vfList[*]'
42     }
43
44     // NDCB-AAI comparison: VF-Module list
45     useRule {
46       name 'NDCB-AAI-attribute-comparison'
47       attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
48     }
49
50     // NDCB-AAI comparison: VNFC list
51     useRule {
52       name 'NDCB-AAI-attribute-comparison'
53       attributes 'context-list.ndcb.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
54     }
55
56     // NDCB-AAI comparison: VM list
57     useRule {
58       name 'NDCB-AAI-attribute-comparison'
59       attributes 'context-list.ndcb.vfList[*].vfModuleList[*].vmList[*]', 'context-list.aai.vfList[*].vfModuleList[*].vmList[*]'
60     }
61
62     // NDCB-AAI comparison: Network list
63     useRule {
64       name 'NDCB-AAI-attribute-comparison'
65       attributes 'context-list.ndcb.vfList[*].vfModuleList[*].networkList[*]', 'context-list.aai.vfList[*].vfModuleList[*].networkList[*]'
66     }
67
68     // SDNC-AAI comparison: Context level
69     useRule {
70       name 'SDNC-AAI-attribute-comparison'
71       attributes 'context-list.sdnc', 'context-list.aai'
72     }
73
74     // SDNC-AAI comparison: Service entity
75     useRule {
76       name 'SDNC-AAI-attribute-comparison'
77       attributes 'context-list.sdnc.service', 'context-list.aai.service'
78     }
79
80     // SDNC-AAI comparison: VF list
81     useRule {
82       name 'SDNC-AAI-attribute-comparison'
83       attributes 'context-list.sdnc.vfList[*]', 'context-list.aai.vfList[*]'
84     }
85
86     // SDNC-AAI comparison: VF-Module list
87     useRule {
88       name 'SDNC-AAI-attribute-comparison'
89       attributes 'context-list.sdnc.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
90     }
91
92     // SDNC-AAI comparison: VNFC list
93     useRule {
94       name 'SDNC-AAI-attribute-comparison'
95       attributes 'context-list.sdnc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
96     }
97
98     // SDNC-AAI comparison: VM list
99     useRule {
100       name 'SDNC-AAI-attribute-comparison'
101       attributes 'context-list.sdnc.vfList[*].vfModuleList[*].vmList[*]', 'context-list.aai.vfList[*].vfModuleList[*].vmList[*]'
102     }
103
104     // SDNC-AAI comparison: Network list
105     useRule {
106       name 'SDNC-AAI-attribute-comparison'
107       attributes 'context-list.sdnc.vfList[*].vfModuleList[*].networkList[*]', 'context-list.aai.vfList[*].vfModuleList[*].networkList[*]'
108     }
109
110     // SDNC-NDCB comparison: Context level
111     useRule {
112       name 'SDNC-NDCB-attribute-comparison'
113       attributes 'context-list.sdnc', 'context-list.ndcb'
114     }
115
116     // SDNC-NDCB comparison: Service entity
117     useRule {
118       name 'SDNC-NDCB-attribute-comparison'
119       attributes 'context-list.sdnc.service', 'context-list.ndcb.service'
120     }
121
122     // SDNC-NDCB comparison: VF list
123     useRule {
124       name 'SDNC-NDCB-attribute-comparison'
125       attributes 'context-list.sdnc.vfList[*]', 'context-list.ndcb.vfList[*]'
126     }
127
128     // SDNC-NDCB comparison: VF-Module list
129     useRule {
130       name 'SDNC-NDCB-attribute-comparison'
131       attributes 'context-list.sdnc.vfList[*].vfModuleList[*]', 'context-list.ndcb.vfList[*].vfModuleList[*]'
132     }
133
134     // SDNC-NDCB comparison: VNFC list
135     useRule {
136       name 'SDNC-NDCB-attribute-comparison'
137       attributes 'context-list.sdnc.vfList[*].vnfcList[*]', 'context-list.ndcb.vfList[*].vnfcList[*]'
138     }
139
140     // SDNC-NDCB comparison: VM list
141     useRule {
142       name 'SDNC-NDCB-attribute-comparison'
143       attributes 'context-list.sdnc.vfList[*].vfModuleList[*].vmList[*]', 'context-list.ndcb.vfList[*].vfModuleList[*].vmList[*]'
144     }
145
146     // SDNC-NDCB comparison: Network list
147     useRule {
148       name 'SDNC-NDCB-attribute-comparison'
149       attributes 'context-list.sdnc.vfList[*].vfModuleList[*].networkList[*]', 'context-list.ndcb.vfList[*].vfModuleList[*].networkList[*]'
150     }
151
152     // SDC-AAI VNFC type
153     useRule {
154       name 'SDC-AAI-vnfc-type'
155       attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
156     }
157
158     // SDC-AAI VNFC node count
159     useRule {
160       name 'SDC-AAI-vnfc-node-count'
161       attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
162     }
163
164     // SDC-AAI VF-Module instance
165     useRule {
166       name 'SDC-AAI-vf-module-instance-check'
167       attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
168     }
169   }
170 }
171
172 rule {
173   name        'SDC-AAI-vnfc-type'
174   category    'VNFC Consistency'
175   description 'Validate that each VNFC instance in AAI conforms to a VNFC type defined in SDC model'
176   errorText   'AAI VNFC instance includes non-specified type in design SDC model'
177   severity    'ERROR'
178   attributes  'sdcList', 'aaiList'
179   validate    '''
180         def getVnfcTypes = { parsedData ->
181           parsedData.collect{ it.findResult{ k, v -> if(k.equals("type")) {return "$v"}}}
182         }
183
184         def slurper = new groovy.json.JsonSlurper()
185         def sdcTypes = getVnfcTypes(slurper.parseText(sdcList.toString()))
186         def aaiTypes = getVnfcTypes(slurper.parseText(aaiList.toString()))
187
188         // each type in AAI must exist in SDC
189         return sdcTypes.containsAll(aaiTypes)
190                 '''
191 }
192
193 rule {
194   name        'SDC-AAI-vnfc-node-count'
195   category    'VNFC Consistency'
196   description 'Validate that for each VNFC node defined in SDC model, there is at least one VNFC instance in AAI'
197   errorText   'Design has specified types but not all of them exist in AAI'
198   severity    'WARNING'
199   attributes  'sdcList', 'aaiList'
200   validate    '''
201         def getVnfcNodes = { parsedData ->
202           parsedData.collect { new Tuple2(
203               it.findResult{ k, v -> if(k.equals("name")) {return "$v"}},
204               it.findResult{ k, v -> if(k.equals("type")) {return "$v"}})
205           }
206         }
207
208         def slurper = new groovy.json.JsonSlurper()
209         def sdcNodes = getVnfcNodes(slurper.parseText(sdcList.toString()))
210         def aaiNodes = getVnfcNodes(slurper.parseText(aaiList.toString()))
211
212         // each node in AAI must exist in SDC
213         return aaiNodes.containsAll(sdcNodes)
214                 '''
215 }
216
217 rule {
218   name        'SDC-AAI-vf-module-instance-check'
219   category    'VF Consistency'
220   description 'Validate that each VF module instance in AAI conforms to a VF module defined in SDC service model'
221   errorText   'One or more AAI VF module instance(s) not defined in SDC model'
222   severity    'CRITICAL'
223   attributes  'sdcList', 'aaiList'
224   validate    '''
225         def getVfModules = { parsedData ->
226           parsedData.collect{ it.findResult{ k, v -> if(k.equals("name")) {return "$v"}}}
227         }
228
229         def slurper = new groovy.json.JsonSlurper()
230         def sdcVfModules = getVfModules(slurper.parseText(sdcList.toString()))
231         def aaiVfModules = getVfModules(slurper.parseText(aaiList.toString()))
232
233         // all VF modules in AAI must exist in SDC
234         return aaiVfModules.containsAll(sdcVfModules)
235                 '''
236 }
237
238 rule {
239   name        'NDCB-AAI-attribute-comparison'
240   category    'Attribute Mismatch'
241   description 'Verify that all attributes in Network-Discovery are the same as in AAI'
242   errorText   'Error found with attribute "{0}"; Network-Discovery value does not match AAI value "{1}"'
243   severity    'ERROR'
244   attributes  'ndcbItems', 'aaiItems'
245   validate    '''
246         Closure<java.util.Map> getAttributes = { parsedData ->
247           java.util.Map attributeMap = new java.util.HashMap()
248
249           def isAttributeDataQualityOk = { attribute ->
250             attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
251           }
252
253           def addToMap = { attrKey, attrValue ->
254             java.util.Set values = attributeMap.get("$attrKey")
255             if(values == null) {
256               values = new java.util.HashSet()
257               attributeMap.put("$attrKey", values)
258             }
259             values.add("$attrValue")
260           }
261
262           def addAttributeToMap = { attribute ->
263             if(isAttributeDataQualityOk(attribute)) {
264               String key, value
265               attribute.each { k, v ->
266                 if(k.equals("name")) {key = "$v"}
267                 if(k.equals("value")) {value = "$v"}
268               }
269               addToMap("$key", "$value")
270             }
271           }
272
273           def processKeyValue = { key, value ->
274             if(value instanceof java.util.ArrayList) {
275               if(key.equals("attributeList")) {
276                 value.each {
277                   addAttributeToMap(it)
278                 }
279               }
280             } else if(!(value instanceof groovy.json.internal.LazyMap)) {
281               // only add key-value attributes, skip the rest
282               addToMap("$key", "$value")
283             }
284           }
285
286           if(parsedData instanceof java.util.ArrayList) {
287             parsedData.each {
288               it.each { key, value -> processKeyValue(key, value) }
289             }
290           } else {
291             parsedData.each { key, value -> processKeyValue(key, value) }
292           }
293           return attributeMap
294         }
295
296         def slurper = new groovy.json.JsonSlurper()
297         java.util.Map ndcb = getAttributes(slurper.parseText(ndcbItems.toString()))
298         java.util.Map aai = getAttributes(slurper.parseText(aaiItems.toString()))
299
300         boolean result = true
301         List<String> details = new ArrayList<>();
302         ndcb.any{ ndcbKey, ndcbValueList ->
303           def aaiValueList = aai.get("$ndcbKey")
304           aaiValueList.each{ aaiValue ->
305             if(!ndcbValueList.any{ it == "$aaiValue" }) {
306               result = false
307               details.add("$ndcbKey")
308               details.add("$aaiValue")
309             }
310           }
311           if(result == false) {
312             // break out of 'any' loop
313             return true
314           }
315         }
316         return new Tuple2(result, details)
317         '''
318 }
319
320 rule {
321   name        'SDNC-AAI-attribute-comparison'
322   category    'Attribute Mismatch'
323   description 'Verify that all attributes in SDN-C are the same as in AAI'
324   errorText   'Error found with attribute "{0}"; SDN-C value does not match AAI value "{1}"'
325   severity    'ERROR'
326   attributes  'sdncItems', 'aaiItems'
327   validate    '''
328         Closure<java.util.Map> getAttributes = { parsedData ->
329           java.util.Map attributeMap = new java.util.HashMap()
330
331           def isAttributeDataQualityOk = { attribute ->
332             attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
333           }
334
335           def addToMap = { attrKey, attrValue ->
336             java.util.Set values = attributeMap.get("$attrKey")
337             if(values == null) {
338               values = new java.util.HashSet()
339               attributeMap.put("$attrKey", values)
340             }
341             values.add("$attrValue")
342           }
343
344           def addAttributeToMap = { attribute ->
345             if(isAttributeDataQualityOk(attribute)) {
346               String key, value
347               attribute.each { k, v ->
348                 if(k.equals("name")) {key = "$v"}
349                 if(k.equals("value")) {value = "$v"}
350               }
351               addToMap("$key", "$value")
352             }
353           }
354
355           def processKeyValue = { key, value ->
356             if(value instanceof java.util.ArrayList) {
357               if(key.equals("attributeList")) {
358                 value.each {
359                   addAttributeToMap(it)
360                 }
361               }
362             } else if(!(value instanceof groovy.json.internal.LazyMap)) {
363               // only add key-value attributes, skip the rest
364               addToMap("$key", "$value")
365             }
366           }
367
368           if(parsedData instanceof java.util.ArrayList) {
369             parsedData.each {
370               it.each { key, value -> processKeyValue(key, value) }
371             }
372           } else {
373             parsedData.each { key, value -> processKeyValue(key, value) }
374           }
375           return attributeMap
376         }
377
378         def slurper = new groovy.json.JsonSlurper()
379         java.util.Map sdnc = getAttributes(slurper.parseText(sdncItems.toString()))
380         java.util.Map aai = getAttributes(slurper.parseText(aaiItems.toString()))
381
382         boolean result = true
383         List<String> details = new ArrayList<>();
384         sdnc.any{ sdncKey, sdncValueList ->
385           def aaiValueList = aai.get("$sdncKey")
386           aaiValueList.each{ aaiValue ->
387             if(!sdncValueList.any{ it == "$aaiValue" }) {
388               result = false
389               details.add("$sdncKey")
390               details.add("$aaiValue")
391             }
392           }
393           if(result == false) {
394             // break out of 'any' loop
395             return true
396           }
397         }
398         return new Tuple2(result, details)
399         '''
400 }
401
402
403 rule {
404   name        'SDNC-NDCB-attribute-comparison'
405   category    'Attribute Mismatch'
406   description 'Verify that all attributes in SDN-C are the same as in Network Discovery'
407   errorText   'Error found with attribute "{0}"; SDN-C value does not match Network-Discovery value "{1}"'
408   severity    'ERROR'
409   attributes  'sdncItems', 'ndcbItems'
410   validate    '''
411         Closure<java.util.Map> getAttributes = { parsedData ->
412           java.util.Map attributeMap = new java.util.HashMap()
413
414           def isAttributeDataQualityOk = { attribute ->
415             attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
416           }
417
418           def addToMap = { attrKey, attrValue ->
419             java.util.Set values = attributeMap.get("$attrKey")
420             if(values == null) {
421               values = new java.util.HashSet()
422               attributeMap.put("$attrKey", values)
423             }
424             values.add("$attrValue")
425           }
426
427           def addAttributeToMap = { attribute ->
428             if(isAttributeDataQualityOk(attribute)) {
429               String key, value
430               attribute.each { k, v ->
431                 if(k.equals("name")) {key = "$v"}
432                 if(k.equals("value")) {value = "$v"}
433               }
434               addToMap("$key", "$value")
435             }
436           }
437
438           def processKeyValue = { key, value ->
439             if(value instanceof java.util.ArrayList) {
440               if(key.equals("attributeList")) {
441                 value.each {
442                   addAttributeToMap(it)
443                 }
444               }
445             } else if(!(value instanceof groovy.json.internal.LazyMap)) {
446               // only add key-value attributes, skip the rest
447               addToMap("$key", "$value")
448             }
449           }
450
451           if(parsedData instanceof java.util.ArrayList) {
452             parsedData.each {
453               it.each { key, value -> processKeyValue(key, value) }
454             }
455           } else {
456             parsedData.each { key, value -> processKeyValue(key, value) }
457           }
458           return attributeMap
459         }
460
461         def slurper = new groovy.json.JsonSlurper()
462         java.util.Map sdnc = getAttributes(slurper.parseText(sdncItems.toString()))
463         java.util.Map ndcb = getAttributes(slurper.parseText(ndcbItems.toString()))
464
465         boolean result = true
466         List<String> details = new ArrayList<>();
467         sdnc.any{ sdncKey, sdncValueList ->
468           def ndcbValueList = ndcb.get("$sdncKey")
469           ndcbValueList.each{ ndcbValue ->
470             if(!sdncValueList.any{ it == "$ndcbValue" }) {
471               result = false
472               details.add("$sdncKey")
473               details.add("$ndcbValue")
474             }
475           }
476           if(result == false) {
477             // break out of 'any' loop
478             return true
479           }
480         }
481         return new Tuple2(result, details)
482         '''
483 }