...
Simple Rule
Code Block |
---|
| rule |
entity {
name 'POA-EVENT'
name indexing {
indices 'vnfdefault-namerules'
}
category validation {
'INVALID_NAME' useRule description{
'Invalid naming convention' errorText name 'Invalid name - attribute does not match xxxxxnnnvbc (where x = alphanumeric and n = numeric)'
severity 'MINOR'NDCB-AAI-attribute-comparison'
attributes 'context-list.sdc.vfList[*].name'
}
}
}
rule {
name attributes 'vnf-name'
validatecategory 'name != null && name.matches("[a-z,0-9]{5}[0-9]{3}vbc")'
} |
Complex Rule
The following example defines a rule that :
- accepts two attributes
- uses expandable error text
- uses a triple-quoted
validate
section to allow multiple lines - defines multiple closures
Code Block |
---|
|
rule {
name 'NDCB-AAI-attribute-comparison'
category 'Attribute Mismatch'
description 'Verify that all attributes in Network-Discovery are the same as in AAI'
errorText 'Error found with attribute "{0}"; value "{1}" does not exist in Network-Discovery'
severity 'ERROR'
attributes 'ndcbItems', 'aaiItems'
validate ''''INVALID_NAME'
description 'Invalid naming convention'
errorText 'Invalid name - attribute does not match xxxxxnnnvbc (where x = alphanumeric and n = numeric)'
severity 'MINOR'
attributes 'name'
validate 'name != null && name.matches("[a-z,0-9]{5}[0-9]{3}vbc")'
} |
Complex Rule
The following example defines a rule that :
- accepts two attributes
- uses expandable error text
- uses a triple-quoted
validate
section to allow multiple lines - defines multiple closures
Code Block |
---|
language | groovy |
---|
collapse | true |
---|
|
entity {
name 'POA-EVENT'
indexing {
indices 'default-rules'
}
validation {
useRule {
name 'NDCB-AAI-attribute-comparison'
attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
}
}
}
rule {
name 'NDCB-AAI-attribute-comparison'
category 'Attribute Mismatch'
description 'Verify that all attributes in Network-Discovery are the same as in AAI'
errorText 'Error found with attribute "{0}"; value "{1}" does not exist in Network-Discovery'
severity 'ERROR'
attributes 'ndcbItems', 'aaiItems'
validate '''
Closure<java.util.Map> getAttributes = { parsedData ->
java.util.Map attributeMap = new java.util.HashMap()
def isAttributeDataQualityOk = { attribute ->
attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
}
def addToMap = { attrKey, attrValue ->
java.util.Set values = attributeMap.get("$attrKey")
if(values == null) {
values = new java.util.HashSet()
attributeMap.put("$attrKey", values)
}
values.add("$attrValue")
}
def addAttributeToMap = { attribute ->
if(isAttributeDataQualityOk(attribute)) {
String key, value
attribute.each { k, v ->
if(k.equals("name")) {key = "$v"}
if(k.equals("value")) {value = "$v"}
}
addToMap("$key", "$value")
}
}
def processKeyValue = { key, value ->
if(value instanceof java.util.ArrayList) {
if(key.equals("attributeList")) {
value.each {
Closure<java.util.Map> getAttributes = { parsedData -> addAttributeToMap(it)
java.util.Map attributeMap = new java.util.HashMap() }
def isAttributeDataQualityOk = { attribute -> }
attribute.findResult{ k, v} ->else if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
!(value instanceof groovy.json.internal.LazyMap)) {
} // only add def addToMap = { attrKey, attrValue ->
key-value attributes, skip the rest
java.util.Set values = attributeMap.get("$attrKey")
if(values == null) {addToMap("$key", "$value")
}
values = new java.util.HashSet() }
attributeMap.put("$attrKey", values)
if(parsedData instanceof java.util.ArrayList) {
} parsedData.each {
values.add("$attrValue") it.each { key, value -> }
processKeyValue(key, value) }
def addAttributeToMap = {}
attribute -> } else {
if(isAttributeDataQualityOk(attribute)) { parsedData.each { key, value -> String processKeyValue(key, value) }
}
attribute.each { k, v -> return attributeMap
}
if(k.equals("name")) {key = "$v"} def slurper = new groovy.json.JsonSlurper()
java.util.Map ndcb = if(k.equals("value"getAttributes(slurper.parseText(ndcbItems.toString()))
{value = "$v"} java.util.Map aai }= getAttributes(slurper.parseText(aaiItems.toString()))
boolean result = true
addToMap("$key", "$value") List<String> details = new ArrayList<>();
} ndcb.any{ ndcbKey, }
ndcbValueList ->
def processKeyValueaaiValueList = { key, value ->
aai.get("$ndcbKey")
if(value instanceof java.util.ArrayList) aaiValueList.each{ aaiValue ->
if(key.equals("attributeList")!ndcbValueList.any{ it == "$aaiValue" }) {
result = false
value.each { details.add("$ndcbKey")
addAttributeToMap(it) details.add("$aaiValue")
} }
}
} else if(!(value instanceof groovy.json.internal.LazyMap)result == false) {
// onlybreak addout key-value attributes, skip the restof 'any' loop
addToMap("$key", "$value")return true
}
} }
} return new Tuple2(result, details)
if(parsedData instanceof java.util.ArrayList) { '''
} |
Data-Dictionary rule
The following example defines a rule that uses the data-dictionary interfaced defined here.
Code Block |
---|
language | groovy |
---|
collapse | true |
---|
|
entity {
name 'POA-EVENT'
parsedData.eachindexing {
indices 'default-rules'
}
validation {
it.each { key, valueuseRule -> processKeyValue(key, value) }{
name 'Data-Dictionary validate VF type'
} attributes 'context-list.ndcb.vfList[*].vfModuleList[*].networkList[*].type'
}
}
else}
{
rule {
name parsedData.each { key, value 'Data-> processKeyValue(key, value) }Dictionary validate VF type'
category 'INVALID_VALUE'
} description 'Validate all VF type values return attributeMap
}against data-dictionary'
errorText 'VF type def slurper = new groovy.json.JsonSlurper()[{0}] failed data-dictionary validation: {1}'
severity java.util.Map ndcb = getAttributes(slurper.parseText(ndcbItems.toString()))
'ERROR'
attributes 'typeList'
java.util.Mapvalidate aai = getAttributes(slurper.parseText(aaiItems.toString()))
'''
boolean resultsuccess = true
List<String> details = new ArrayList<>();
ndcbtypeList.any {
ndcbKey, ndcbValueList -> def aaiValueList = aai.get("$ndcbKey"if(!success) {
aaiValueList.each{ aaiValue -> // break out if(!ndcbValueList.any{ it == "$aaiValue" }) {of 'any' loop
return false
result = false }
details.add("$ndcbKey") def result = org.onap.aai.validation.ruledriven.rule.builtin.DataDictionary.validate("instance", details.add("$aaiValue"vfModuleNetworkType", "type", "$it")
}
if(!result.isEmpty()) {
} success = false
if(result == false) { // break out of 'any' loopdetails.add("$it")
return truedetails.add("$result")
}
}
return new Tuple2(resultsuccess, details)
'''
}
|
Entity Configuration
The entity
configuration element defines which rules are applied to a specific entity type. The configuration is comprised of the following properties:
...