Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Simple Rule

Code Block
languagegroovy
collapsetrue
entityrule {
    name        'vnfPOA-nameEVENT'
  indexing {
 category   indices 'INVALID_NAMEdefault-rules'
  }
  validation description{
 'Invalid naming convention'
 useRule {
  errorText   'Invalid name 'vnf-name'
 attribute does not match xxxxxnnnvbc (where x = alphanumeric and n = numeric)'
attributes 'context-list.sdc.vfList[*].name'
    }
  }
}


rule {
    name    severity    'MINORvnf-name'
    category  attributes  'nameINVALID_NAME'
    validatedescription 'Invalid naming convention'
 '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
 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
languagegroovy
collapsetrue
entity {
  name 'POA-EVENT'
  indexing {
    indices 'default-rules'
  }
  validation {
    useRule {
      name 'NDCB-AAI-attribute-comparison
Code Block
languagegroovy
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 ->
     attributes 'context-list.ndcb.vfList[*].vfModuleList[*]', 'context-list.aai.vfList[*].vfModuleList[*]'
    }
  }
}


rule {
  name     java.util.Map attributeMap = new java.util.HashMap()
 'NDCB-AAI-attribute-comparison'
  category    'Attribute Mismatch'
  description def'Verify isAttributeDataQualityOkthat =all {attributes attributein ->
      Network-Discovery are the same as in AAI'
  errorText   'Error found with attribute.findResult{ k, v -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
          }

          def addToMap = { attrKey, attrValue ->
   "{0}"; value "{1}" does not exist in Network-Discovery'
  severity    'ERROR'
  attributes  'ndcbItems', 'aaiItems'
  validate    '''
        Closure<java.util.Map> getAttributes = { parsedData ->
          java.util.SetMap valuesattributeMap = new attributeMapjava.util.getHashMap("$attrKey")

          def isAttributeDataQualityOk if(values == null) {= { attribute ->
            attribute.findResult{ k, valuesv = new java.util.HashSet()
              attributeMap.put("$attrKey", values)
  -> if(k.equals("dataQuality") ) {return v.get("status")}}.equals("ok")
          }

          def  values.add("$attrValue")
    addToMap = { attrKey, attrValue ->
      }

          def addAttributeToMap = { attribute ->java.util.Set values = attributeMap.get("$attrKey")
            if(isAttributeDataQualityOk(attribute)values == null) {
              values String= key, valuenew java.util.HashSet()
              attribute.each { k, v ->
attributeMap.put("$attrKey", values)
            }
            if(kvalues.equalsadd("name$attrValue"))
  {key = "$v"}
      }

          if(k.equals("value")) {valuedef addAttributeToMap = "$v"}
{ attribute ->
            }
if(isAttributeDataQualityOk(attribute)) {
              String addToMap("$key"key, "$value")value
            }
  attribute.each { k, v ->
    }

          def processKeyValue = if(k.equals("name")) { key, value ->= "$v"}
            if(value instanceof java.util.ArrayList) {
              if(keyk.equals("attributeListvalue")) {
value = "$v"}
              value.each {}
                  addAttributeToMap(it)
    addToMap("$key", "$value")
            }
              }

          def processKeyValue = { key, value ->
          } else if(!(value instanceof groovyjava.json.internal.LazyMap)util.ArrayList) {
              // only add key-value attributes, skip the rest
if(key.equals("attributeList")) {
                 addToMap("$key", "$value")
value.each {
                  addAttributeToMap(it)
                }
              }

            } else if(!(parsedDatavalue instanceof groovy.json.internal.LazyMap)) java.util.ArrayList){
              // only add key-value attributes, skip the rest
              addToMap("$key", "$value")
            }
          }

          if(parsedData instanceof java.util.ArrayList) {
            parsedData.each {
              it.each { key, value -> processKeyValue(key, value) }
            }
          } else {
            parsedData.each { key, value -> processKeyValue(key, value) }
          }
          return attributeMap
        }

        def slurper = new groovy.json.JsonSlurper()
        java.util.Map ndcb = getAttributes(slurper.parseText(ndcbItems.toString()))
        java.util.Map aai = getAttributes(slurper.parseText(aaiItems.toString()))

        boolean result = true
        List<String> details = new ArrayList<>();
        ndcb.any{ ndcbKey, ndcbValueList ->
          def aaiValueList = aai.get("$ndcbKey")
          aaiValueList.each{ aaiValue ->
            if(!ndcbValueList.any{ it == "$aaiValue" }) {
              result = false
              details.add("$ndcbKey")
              details.add("$aaiValue")
            }
          }
          if(result == false) {
            // break out of 'any' loop
            return true
          }
        }
        return new Tuple2(result, details)
        '''
}

Data-Dictionary rule

The following example defines a rule that uses the data-dictionary interfaced defined here.

By default, the URI template is configured as "/commonModelElements/{0}~{1}~1.0/validateInstance"

With the arguments used for calling validate() below, the resulting URL would be: [ddict-host:port]/commonModelElements/instance~vfModuleNetworkType~1.0/validateInstance

And the body would be:  {"type" : "some-value"}

Code Block
languagegroovy
collapsetrue
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:

...