The entities consistency script analyze the contents of the entities database in orion DBs and check several consistency rules, reporting violations found.
Ref: entity document database model
This script is designed to work with Python 3. Install the dependencies in the requirements.txt
file before using it.
Usage of virtual env is recommended.
Run entities_consistency.py -h
for arguments details.
- Rules 1x: DB inconsistencies (use to be severe problems)
- Rules 2x: Syntax restrictions
- Rules 9x: Usage of legacy features
Each entity in DB has an _id
field with three subfields:
id
type
servicePath
The following fields are mandatory:
attrNames
creDate
modDate
It is not an exhaustive check of every field in the database model, but some entities created/updated with old Orion versions may be missing them.
The following subfields are mandatory for every attribute:
mdNames
creDate
modDate
It is not an exhaustive check of every field in the database model, but some entities created/updated with old Orion versions may be missing them.
For each item in attrNames
array there is a corresponding key in attrs
object and the other way around.
For every attribute, for each item in mdNames
array there is a corresponding key in md
object and the other way around.
In MongoDB JSON objects are stored taking order into account, so DB allows to have a document with
_id
equal to {"id": "E", "type": "T", "servicePath": "/"}
and at the same time have another document with _id
equal to {"type": "T", "id": "E", "servicePath": "/"}
without violating _id
uniqueness constraint.
This rule checks that this is not happening in the entities collection.
Check that location in consistent. In particular:
- As much as one attribute with
geo:point
,geo:line
,geo:box
,geo:polygon
orgeo:json
type (withoutignoreTypes
and withoutnull
value). - If one of such attribute is found, check the
location
field is found and its content is consistent - If none of such attribute is found, check no
location
field is not found- If the location of the entity is defined using deprecated
location
metadata it will be detected as this case. Additional rules in the 9x group can help to diagnose this situation.
- If the location of the entity is defined using deprecated
This rule is for location inconsistencies. For usage of deprecated geo types, there are additional rules in the 9x group.
Check if lastCorrelator
is included.
This field was introduced in Orion 1.8.0 (released in September 11th, 2017).
Check identifiers syntax restrictions for this case.
Check identifiers syntax restrictions for this case.
Check servicePath documentation
Check identifiers syntax restrictions for this case.
Check identifiers syntax restrictions for this case.
Check identifiers syntax restrictions for this case.
Check identifiers syntax restrictions for this case.
Check usage of deprecated geo-location types, i.e:
geo:point
geo:line
geo:box
geo:polygon
Suggested action is to:
- Change attribute type to
geo:json
- Set the attribute value to the same GeoJSON in
location.coords
field
Note this rule doesn't check location consistency for this case (e.g. more than one geo-location attribute in the same entity). That's done by another rule in the 1x group.
Check usage of location
in more than one attribute of the same entity.
Note this rule doesn't check location consistency for this case (that's done by another rule in the 1x group).
The value of the location
metadata should be WGS84
or WSG84
.
Additional consideration:
- Entities attributes may have
location
metadata with values different fromWGS84
orWSG84
if created using NGSIv2. That would be a false positive in this rule validation - This rule doesn't check location consistency for this case (that's done by another rule in the 1x group).
Checks usage of redundant location
metadata, i.e. when at the same time a geo:
type is used in the
same attribute.
Suggested action is to remove the location
metadata.
Additional, considerations:
- This rule assumes only one
location
is in the entity (i.e. Rule 91 is not violated). If that doesn't occur, only the first occurrence is taken into account. - This rule doesn't check location consistency for this case (that's done by another rule in the 1x group).
Checks usage of not redundant location
metadata, i.e. when at the same time the type of the attribute is nog geo:
.
same attribute.
Suggested action is to:
- Change attribute type to
geo:json
- Set the attribute value to the same GeoJSON in
location.coords
field - Remove the
location
metadata from the attribute
Additional, considerations:
- This rule assumes only one
location
is in the entity (i.e. Rule 91 is not violated). If that doesn't occur, only the first occurrence is taken into account. - This rule doesn't check location consistency for this case (that's done by another rule in the 1x group).
You can test the entities_consistency.py
script this qy:
- Populate
orion-validation
DB with testing document. To do so, copy-paste the content of thevalidation_data.js
inmongosh
- Run
test_entities_consistency.py
test and check the log output
You can also run test_entities_consistenct.py
under coverage to check every rule is covering all the possible validation cases.