Merge "Implement pgpool to front postgresql statefulset"
[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     // SDC-AAI VNFC type
69     useRule {
70       name 'SDC-AAI-vnfc-type'
71       attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
72     }
73
74     // SDC-AAI VNFC node count
75     useRule {
76       name 'SDC-AAI-vnfc-node-count'
77       attributes 'context-list.sdc.vfList[*].vnfcList[*]', 'context-list.aai.vfList[*].vnfcList[*]'
78     }
79
80     // SDC-AAI VF-Module instance
81     useRule {
82       name 'SDC-AAI-vf-module-instance-check'
83       attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
84     }
85   }
86 }
87
88 rule {
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'
93   severity    'ERROR'
94   attributes  'sdcList', 'aaiList'
95   validate    '''
96         def getVnfcTypes = { parsedData ->
97           parsedData.collect{ it.findResult{ k, v -> if(k.equals("type")) {return "$v"}}}
98         }
99
100         def slurper = new groovy.json.JsonSlurper()
101         def sdcTypes = getVnfcTypes(slurper.parseText(sdcList.toString()))
102         def aaiTypes = getVnfcTypes(slurper.parseText(aaiList.toString()))
103
104         // each type in AAI must exist in SDC
105         return aaiTypes.containsAll(sdcTypes)
106                 '''
107 }
108
109 rule {
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'
114   severity    'WARNING'
115   attributes  'sdcList', 'aaiList'
116   validate    '''
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"}})
121           }
122         }
123
124         def slurper = new groovy.json.JsonSlurper()
125         def sdcNodes = getVnfcNodes(slurper.parseText(sdcList.toString()))
126         def aaiNodes = getVnfcNodes(slurper.parseText(aaiList.toString()))
127
128         // each node in AAI must exist in SDC
129         return aaiNodes.containsAll(sdcNodes)
130                 '''
131 }
132
133 rule {
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'
138   severity    'CRITICAL'
139   attributes  'sdcList', 'aaiList'
140   validate    '''
141         def getVfModules = { parsedData ->
142           parsedData.collect{ it.findResult{ k, v -> if(k.equals("name")) {return "$v"}}}
143         }
144
145         def slurper = new groovy.json.JsonSlurper()
146         def sdcVfModules = getVfModules(slurper.parseText(sdcList.toString()))
147         def aaiVfModules = getVfModules(slurper.parseText(aaiList.toString()))
148
149         // all VF modules in AAI must exist in SDC
150         return aaiVfModules.containsAll(sdcVfModules)
151                 '''
152 }
153
154 rule {
155   name        'NDCB-AAI-attribute-comparison'
156   category    'INVALID_VALUE'
157   description 'Verify that every attribute in Network-Discovery is the same as in AAI'
158   errorText   'Some attributes in Network-Discovery are not equal to attributes in AAI'
159   severity    'ERROR'
160   attributes  'ndcbItems', 'aaiItems'
161   validate    '''
162         Closure<java.util.Map> getAttributes = { parsedData ->
163           java.util.Map attributeMap = new java.util.HashMap()
164
165           def isAttributeDataQualityOk = { attribute ->
166             attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
167           }
168
169           def addToMap = { attrKey, attrValue ->
170             java.util.Set values = attributeMap.get("$attrKey")
171             if(values == null) {
172               values = new java.util.HashSet()
173               attributeMap.put("$attrKey", values)
174             }
175             values.add("$attrValue")
176           }
177
178           def addAttributeToMap = { attribute ->
179             if(isAttributeDataQualityOk(attribute)) {
180               String key, value
181               attribute.each { k, v ->
182                 if(k.equals("name")) {key = "$v"}
183                 if(k.equals("value")) {value = "$v"}
184               }
185               addToMap("$key", "$value")
186             }
187           }
188
189           def processKeyValue = { key, value ->
190             if(value instanceof java.util.ArrayList) {
191               if(key.equals("attributeList")) {
192                 value.each {
193                   addAttributeToMap(it)
194                 }
195               }
196             } else if(!(value instanceof groovy.json.internal.LazyMap)) {
197               // only add key-value attributes, skip the rest
198               addToMap("$key", "$value")
199             }
200           }
201
202           if(parsedData instanceof java.util.ArrayList) {
203             parsedData.each {
204               it.each { key, value -> processKeyValue(key, value) }
205             }
206           } else {
207             parsedData.each { key, value -> processKeyValue(key, value) }
208           }
209           return attributeMap
210         }
211
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()))
215
216         ndcb.each{ ndcbKey, ndcbValueList ->
217           def aaiValueList = aai.get("$ndcbKey")
218           aaiValueList.each{ aaiValue ->
219             if(!ndcbValueList.any{ it == "$aaiValue" }) {
220               return false
221             }
222           }
223         }
224         return true
225         '''
226 }