telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md
GNU Affero General Public License v3.0
210 stars 265 forks source link

Orion incorrectly report error when passing from 0 locatations to 1 location in entity update #3706

Closed fgalan closed 4 years ago

fgalan commented 4 years ago

Having this entity at DB (note there is no location):

> db.entities.find({"_id.id": "ES0021000001111111AA", "_id.servicePath": "/energia"})
{ "_id" : { "id" : "ES0021000001111111AA", "type" : "SupplyPoint", "servicePath" : "/energia" }, "attrNames" : [ "TimeInstant", "period", "seasonId", "name", "supplier", "address", "areaServed", "dateMaxPowerConsumption", "distributor", "electricityRateName", "energyConsumed", "invoiceNumber", "location", "maxPowerConsumption", "maximumPowerAvailableP1", "reactiveEnergyConsumed", "reactiveEnergyConsumedQ1", "reactiveEnergyConsumedQ2", "reactiveEnergyConsumedQ3", "reactiveEnergyConsumedQ4", "cif", "maximumPowerAvailableP2", "maximumPowerAvailableP3", "maximumPowerAvailableP4", "maximumPowerAvailableP5", "maximumPowerAvailableP6" ], "attrs" : { "TimeInstant" : { "value" : 1599206400, "type" : "DateTime", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599206401 }, "period" : { "type" : "Number", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "60", "mdNames" : [ ] }, "seasonId" : { "value" : 1, "type" : "Number", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599143883 }, "name" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "Punto de suministro 1", "mdNames" : [ ] }, "supplier" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "Iberdrola", "mdNames" : [ ] }, "address" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "Avenida de España, 2", "mdNames" : [ ] }, "areaServed" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "Ayuntamiento de Alcobendas", "mdNames" : [ ] }, "dateMaxPowerConsumption" : { "value" : 1601237698, "type" : "DateTime", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599144602 }, "distributor" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "i-DE", "mdNames" : [ ] }, "electricityRateName" : { "type" : "Text", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "2.0A", "mdNames" : [ ] }, "energyConsumed" : { "value" : 0.9163858596629744, "type" : "Number", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599206401 }, "invoiceNumber" : { "value" : 3191227030215627, "type" : "Number", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599144602 }, "location" : { "value" : { "type" : "Point", "coordinates" : [ -3.643898967, 40.543613027 ] }, "type" : "StructuredValue", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1603273111.6492305 }, "maxPowerConsumption" : { "value" : 1.0115844994877388, "type" : "Number", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599144602 }, "maximumPowerAvailableP1" : { "value" : "5", "type" : "Text", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1603263879.509865 }, "reactiveEnergyConsumed" : { "value" : 0.3122130027578168, "type" : "Number", "mdNames" : [ ], "creDate" : 1599057349, "modDate" : 1599206401 }, "reactiveEnergyConsumedQ1" : { "type" : "Number", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "0", "mdNames" : [ ] }, "reactiveEnergyConsumedQ2" : { "type" : "Number", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "0", "mdNames" : [ ] }, "reactiveEnergyConsumedQ3" : { "type" : "Number", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "0", "mdNames" : [ ] }, "reactiveEnergyConsumedQ4" : { "type" : "Number", "creDate" : 1599057349, "modDate" : 1599057349, "value" : "0", "mdNames" : [ ] }, "cif" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5097947, "modDate" : 1603263879.5097947 }, "maximumPowerAvailableP2" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5098703, "modDate" : 1603263879.5098703 }, "maximumPowerAvailableP3" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5098755, "modDate" : 1603263879.5098755 }, "maximumPowerAvailableP4" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5098822, "modDate" : 1603263879.5098822 }, "maximumPowerAvailableP5" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5098858, "modDate" : 1603263879.5098858 }, "maximumPowerAvailableP6" : { "value" : "", "type" : "Text", "mdNames" : [ ], "creDate" : 1603263879.5098898, "modDate" : 1603263879.5098898 } }, "creDate" : 1599057349, "modDate" : 1603273111.6493506, "lastCorrelator" : "2e7b6c36-1381-11eb-a1f0-0242ac110013" }

With this upgrade (adding a location field):

curl -X POST localhost:10026/v2/entities/ES0021000001111111AA/attrs -s -S -H 'Content-Type: application/json' -H 'fiware-service: desarrollo_mb3' -H 'fiware-servicepath: /energia' -d @- <<EOF
{"areaServed":{"value":"Ayuntamiento de Alcobendas"},"name":{"value":"Punto de suministro 1"},"address":{"value":"Avenida de España, 2"},"location":{"value":{"type":"Point","coordinates":[-3.643898968,40.543613027]},"type":"geo:json"},"electricityRateName":{"value":"2.0A"},"maximumPowerAvailableP1":{"value":"5"},"maximumPowerAvailableP2":{"value":""},"maximumPowerAvailableP3":{"value":""},"maximumPowerAvailableP4":{"value":""},"maximumPowerAvailableP5":{"value":""},"maximumPowerAvailableP6":{"value":""},"distributor":{"value":"i-DE"},"supplier":{"value":"Iberdrola"}}
EOF

We get this error:

{"error":"NoResourcesAvailable","description":"You cannot use more than one geo location attribute when creating an entity [see Orion user manual]"}

And this in log traces:

time=Wednesday 21 Oct 09:43:30 2020.349Z | lvl=WARN | corr=e0854e42-1381-11eb-8ef2-0242ac110013 | trans=1602838577-171-00000001111 | from=172.17.0.1 | srv=desarrollo_mb3 | subsrv=/energia | comp=Orion | op=AlarmManager.cpp[405]:badInput | msg=Raising alarm BadInput 172.17.0.1: attempt to define a geo location attribute [location] when another one has been previously defined []

Note that [] has no sense here...

fgalan commented 4 years ago

CC: @fjperalta

fgalan commented 4 years ago

PR https://github.com/telefonicaid/fiware-orion/pull/3710