telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 265 forks source link

Simplify registrations database model #4611

Open fgalan opened 3 weeks ago

fgalan commented 3 weeks ago

Registration documents are this way:

 {
   "_id": ObjectId("5149f60cf0075f2fabca43da"),
   "format": "JSON",
   "fwdMode": "all",
   "expiration": 1360232760,
   "contextRegistration": [
       {
           "entities": [
               {
                   "id": "E1",
                   "type": "T1",
                   "isPattern": "false"
               },
               {
                   "id": "E2",
                   "type": "T2",
                   "isPattern": "false"
               }
           ],
           "attrs": [
               {
                   "name": "A1",
                   "type": "TA1"
               },
               {
                   "name": "A2",
                   "type": "TA2"
               }
           ],
           "providingApplication": "http://foo.bar/notif"
      },
      "status": "active"
    }
  ]
 }

The contextRegistration is always mono-item. It is a vector due to NGSIv1 legacy.

It would be better to simplify to:

 {
   "_id": ObjectId("5149f60cf0075f2fabca43da"),
   "format": "JSON",
   "fwdMode": "all",
   "expiration": 1360232760,
   "entities": [
       {
           "id": "E1",
           "type": "T1",
           "isPattern": "false"
       },
       {
           "id": "E2",
           "type": "T2",
           "isPattern": "false"
       }
   ],
   "attrs": [
       {
           "name": "A1",
           "type": "TA1"
       },
       {
          "name": "A2",
          "type": "TA2"
       }
   ],
   "providingApplication": "http://foo.bar/notif",
   "status": "active"
}

In addition, isPattern should be also removed.

This issue should be addressed after https://github.com/telefonicaid/fiware-orion/issues/4610 (the format field will be removed as part of that issue).

A DB migration script would be probably needed.

fgalan commented 3 weeks ago

Look for FIXME #4611 marks in the code.

fgalan commented 3 weeks ago

registrationsQuery() logic should be changed

fgalan commented 3 weeks ago

A DB migration script would be probably needed.

In this sense a new Rule Rxx should be added to https://github.com/telefonicaid/fiware-orion/tree/master/scripts/oriondb_consistency to detect situations in which contextRegistration vector has more than one element. The migration could be the autofix action for that rule.

fgalan commented 2 weeks ago

In addition, in the structure:

       {
           "id": "E1",
           "type": "T1",
           "isPattern": "false"
       },

isPattern (with a string value) is ugly.

Maybe more natural to use "pattern": true|false: