Skip to content

Commit

Permalink
Merge pull request telefonicaid#4463 from telefonicaid/bug/4460_overl…
Browse files Browse the repository at this point in the history
…oging_runtime_error_fwd_update

FIX forwarding logic
  • Loading branch information
AlvaroVega authored Dec 22, 2023
2 parents cdde24a + 7e3d43b commit 565a595
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Add: notification.mqtt.retain and notification.mqttCustom.retain flag for MQTT retain in notifications (#4388)
- Add: notification payload in INFO log traces (#4449)
- Fix: correctly detect JSON attribute and metadata value changes in subscription triggering logic (#4211, #4434, #643)
- Fix: update forwarding was not working when entity type is not included in the request (#4460)
- Fix: DateTime and geo:json types were not supported in custom notifications using ngsi patching (#4435)
- Fix: logDeprecate not working correctly (`geo:json` wrongly considered as deprecated)
- Fix: improve error traces (#4387)
Expand Down
9 changes: 5 additions & 4 deletions src/lib/ngsi10/UpdateContextRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,17 @@ ContextAttribute* UpdateContextRequest::attributeLookup(Entity* eP, const std::s
{
Entity* enP = entityVector[ceIx];

if ((enP->id != eP->id) || (enP->type != eP->type))
// empty type in request (enP) is always a match
if ((enP->id != eP->id) || ((enP->type != "") && (enP->type != eP->type)))
{
continue;
}

Entity* eP = entityVector[ceIx];
Entity* eVItemP = entityVector[ceIx];

for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx)
for (unsigned int aIx = 0; aIx < eVItemP->attributeVector.size(); ++aIx)
{
ContextAttribute* aP = eP->attributeVector[aIx];
ContextAttribute* aP = eVItemP->attributeVector[aIx];

if (aP->name == attributeName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Copyright 2023 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Update forwarding was not working when entity type is not included in the request

--SHELL-INIT--
dbInit CB
dbInit CP1
brokerStart CB
brokerStart CP1

--SHELL--

#
# 01. Create device:wt:13 attribute profile_config in CP1
# 02. Create device:wt:13 attribute profile in CB
# 03. Register device:wt:13 attribute profile_config in CB, provApp: CP1
# 04. Update device:wt:13 attribute profile_config in CB
# 05. Check no Runtime Error occur
# 06. Query device:wt:13 attribute profile_config in CP1
#

echo "01. Create device:wt:13 attribute profile_config in CP1"
echo "======================================================="
payload='{
"id": "device:wt:13",
"type": "Device",
"profile_config": {
"type": "command",
"value": "init"
}
}'
orionCurl --url /v2/entities --payload "$payload" --port $CP1_PORT
echo
echo


echo "02. Create device:wt:13 attribute profile in CB"
echo "==============================================="
payload='{
"id": "device:wt:13",
"type": "Device",
"profile": {
"type": "Text",
"value": "prof01"
}
}'
orionCurl --url /v2/entities --payload "$payload"
echo
echo


echo "03. Register device:wt:13 attribute profile_config in CB, provApp: CP1"
echo "======================================================================"
payload='{
"dataProvided": {
"entities": [
{
"type": "Device",
"id": "device:wt:13"
}
],
"attrs": [ "profile_config" ]
},
"provider": {
"http": {
"url": "http://localhost:'${CP1_PORT}'/v2"
}
}
}'
orionCurl --url /v2/registrations --payload "$payload"
echo
echo


echo "04. Update device:wt:13 attribute profile_config in CB"
echo "======================================================"
payload='{
"type": "command",
"value": "foobar"
}'
orionCurl --url /v2/entities/device:wt:13/attrs/profile_config --payload "$payload" -X PUT
echo
echo


echo "05. Check no Runtime Error occur"
echo "================================"
cat /tmp/contextBroker.log | grep "Runtime Error" | wc -l
echo
echo


echo "06. Query device:wt:13 attribute profile_config in CP1 and see foobar"
echo "====================================================================="
orionCurl --url /v2/entities/device:wt:13 --port $CP1_PORT
echo
echo



--REGEXPECT--
01. Create device:wt:13 attribute profile_config in CP1
=======================================================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/device:wt:13?type=Device
Content-Length: 0



02. Create device:wt:13 attribute profile in CB
===============================================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/device:wt:13?type=Device
Content-Length: 0



03. Register device:wt:13 attribute profile_config in CB, provApp: CP1
======================================================================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/registrations/REGEX([0-9a-f\-]{24})
Content-Length: 0



04. Update device:wt:13 attribute profile_config in CB
======================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



05. Check no Runtime Error occur
================================
0


06. Query device:wt:13 attribute profile_config in CP1 and see foobar
=====================================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 104

{
"id": "device:wt:13",
"profile_config": {
"metadata": {},
"type": "command",
"value": "foobar"
},
"type": "Device"
}


--TEARDOWN--
brokerStop CB
brokerStop CP1
dbDrop CB
dbDrop CP1

0 comments on commit 565a595

Please sign in to comment.