...
Simple Rule
Code Block |
---|
language | groovy |
---|
collapse | true |
---|
|
entityrule {
name 'vnfPOA-nameEVENT'
indexing {
category indices 'INVALID_NAMEdefault-rules'
}
validation description{
'Invalid naming convention'
useRule {
errorText 'Invalid name 'NDCB-AAI- attribute-comparison'
does not match xxxxxnnnvbc (where x = alphanumeric and n = numeric)'
severity 'MINOR'
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
'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 {
addAttributeToMap(it)
}
}
|
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 '''
Closure<java.util.Map> getAttributes = { parsedData ->
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("$attrKeyaddToMap("$key", "$value")
}
if(values == null) {
}
values =if(parsedData newinstanceof java.util.HashSet(ArrayList) {
attributeMap.put("$attrKey", values)parsedData.each {
}
it.each { key, value -> processKeyValue(key, value) }
values.add("$attrValue")
}
} else def{
addAttributeToMap = { attribute ->
parsedData.each { key, value -> if(isAttributeDataQualityOk(attribute)processKeyValue(key, value) {}
}
String key, value
return attributeMap
}
attribute.each { k, v ->
def slurper = new groovy.json.JsonSlurper()
java.util.Map ndcb = if(k.equals("name")) {key = "$v"}getAttributes(slurper.parseText(ndcbItems.toString()))
java.util.Map aai if(k.equals("value")) {value = "$v"}= getAttributes(slurper.parseText(aaiItems.toString()))
boolean result = }true
List<String> details = new addToMap("$key", "$value")ArrayList<>();
ndcb.any{ ndcbKey, ndcbValueList }->
}
def aaiValueList = aai.get("$ndcbKey")
def processKeyValue = aaiValueList.each{ key, valueaaiValue ->
if(value instanceof java.util.ArrayList!ndcbValueList.any{ it == "$aaiValue" }) {
if(key.equals("attributeList")) {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 rest
of 'any' loop
addToMap("$key", "$value")
return true
}
}
return new if(parsedData instanceof java.util.ArrayList)Tuple2(result, details)
'''
} |
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 {
it.each { key, value -> processKeyValue(key, value) }
indices 'default-rules'
}
validation {
useRule }{
name 'Data-Dictionary validate VF }type'
else {
attributes 'context-list.ndcb.vfList[*].vfModuleList[*].networkList[*].type'
}
parsedData.each { key, value -> processKeyValue(key, value) }
}
}
rule {
name 'Data-Dictionary validate VF }type'
category 'INVALID_VALUE'
return attributeMap
description 'Validate all VF type values 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'
validate java.util.Map 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 ->
// if(!ndcbValueList.any{ it == "$aaiValue" }) {
break out of 'any' loop
result =return false
}
details.add("$ndcbKey")
def result details.add("$aaiValue= org.onap.aai.validation.ruledriven.rule.builtin.DataDictionary.validate("instance", "vfModuleNetworkType", "type", "$it")
}if(!result.isEmpty()) {
}
success = false
if(result == false) {
// break out of 'any' loop
details.add("$it")
return true
details.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:
...