8000 FIX alterationType with entityDelete not working if condition.attrs is empty by fgalan · Pull Request #4326 · telefonicaid/fiware-orion · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FIX alterationType with entityDelete not working if condition.attrs is empty #4326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- Add: subject.condition.notifyOnMetadataChange field to subscriptions, so only-metadata changes doesn't trigger notifications (#3727)
- Add: new simplifiedNormalized and simplifiedKeyvalues for attrsFormat (#4286)
- Add: -mqttTimeout (env var ORION_MQTT_TIMEOUT) for MQTT broker connection timeout
- Fix: alterationType with entityDelete not working if condition.attrs is empty (#4326)
- Fix: $set/$unset update operator not working properly when the key has dots (#4315)
- Fix: queue workers deadlock when MQTT broker was not responding to connection attemp
- Fix: Ngsiv2-AttrsFormat header set to "normalized" in NGSI patching custom notification
Expand Down
4 changes: 3 additions & 1 deletion doc/manuals.jp/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ Orion は階層スコープをサポートしているため、エンティテ
- `entityUpdate`: 通知をトリガーする更新が更新であったが、実際の変更ではなかった場合
- `entityChange`: 通知をトリガーする更新が実際の変更を伴う更新であった場合、または実際の変更ではなく
`forcedUpdate` が使用された場合
- `entityDelete`: 通知をトリガーする更新がエンティティの削除操作であった場合
- `entityDelete`: 通知をトリガーする更新がエンティティの削除操作であった場合。この場合、
[`condition`](#subscriptionsubjectcondition) 内の `attrs` フィールドは無視されます (エンティティを削除する通常
の方法、たとえば `DELETE /v2/entities/E` には属性が含まれないことに注意してください)

通常の属性と同様に、`q` フィルタと `orderBy` (`alterationType` を除く) で使用できます。
ただし、リソース URLs では使用できません。
Expand Down
5 changes: 4 additions & 1 deletion doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,10 @@ subscription is triggered. At the present moment, the following alteration types
and it actually changes (or if it is not an actual update, but `forcedUpdate` option is used
in the update request)
* `entityCreate`: notification is sent whenever a entity covered by the subscription is created
* `entityDelete`: notification is sent whenever a entity covered by the subscription is deleted
* `entityDelete`: notification is sent whenever a entity covered by the subscription is deleted.
In this case, the `attrs` field within [`condition`](#subscriptionsubjectcondition) is
ignored (note that usual way of deleting entities, e.g. `DELETE /v2/entities/E` doesn't include
any attribute).

For instance:

Expand Down
4 changes: 2 additions & 2 deletions src/lib/cache/subCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ static bool subMatch
// case of ONANYCHANGE subscriptions).
//
// Depending of the alteration type, we use the list of attributes in the request or the list
// with effective modifications
// with effective modifications. Note that EntityDelete doesn't check the list
if (targetAltType == ngsiv2::EntityUpdate)
{
if (!attributeMatch(cSubP, attributes))
Expand All @@ -501,7 +501,7 @@ static bool subMatch
return false;
}
}
else
else if ((targetAltType == ngsiv2::EntityChange) || (targetAltType == ngsiv2::EntityCreate))
{
if (!attributeMatch(cSubP, attrsWithModifiedValue) &&
!(cSubP->notifyOnMetadataChange && attributeMatch(cSubP, attrsWithModifiedMd)))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,15 +1684,15 @@ static bool addTriggeredSubscriptions_noCache
bool notifyOnMetadataChange = sub.hasField(CSUB_NOTIFYONMETADATACHANGE)? getBoolFieldF(sub, CSUB_NOTIFYONMETADATACHANGE) : true;

// Depending of the alteration type, we use the list of attributes in the request or the list
// with effective modifications
// with effective modifications. Note that EntityDelete doesn't check the list
if (targetAltType == ngsiv2::EntityUpdate)
{
if (!condValueAttrMatch(sub, attributes))
{
continue;
}
}
else
else if ((targetAltType == ngsiv2::EntityChange) || (targetAltType == ngsiv2::EntityCreate))
{
if (!condValueAttrMatch(sub, attrsWithModifiedValue) && !(notifyOnMetadataChange && condValueAttrMatch(sub, attrsWithModifiedMd)))
{
Expand Down
< 6D40 /tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# Copyright 2022 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--
Subscription alterationType entityDelete with condition.attrs

--SHELL-INIT--
dbInit CB
brokerStart CB 0-255
accumulatorStart --pretty-print

--SHELL--

#
# This .test is a copy of cases/1494_subscription_alteration_types/sub_alteration_type_entity_delete.test
# but adding conditions.attrs in the subscription created in step 01
#
# 01. Create subscription for entity type T with entityDelete
# 02. Create entity E/T (no notif)
# 03. Update entity E/T without actual change (no notif)
# 04. Update entity E/T with actual change (no notif)
# 05. Delete entity E/T (notif)
# 06. Dump accumulator: see E/T notification with alterationType entityDelete
#

echo "01. Create subscription for entity type T with entityDelete"
echo "==========================================================="
payload='{
"subject": {
"entities": [
{
"idPattern" : ".*",
"type": "T"
}
],
"condition": {
"alterationTypes": [ "entityDelete" ],
"attrs": [ "A" ]
}
},
"notification": {
"http": {
"url": "http://127.0.0.1:'${LISTENER_PORT}'/notify"
},
"attrs": [ "alterationType", "*" ]
}
}'
orionCurl --url /v2/subscriptions --payload "$payload"
echo
echo


echo "02. Create entity E/T (no notif)"
echo "================================"
payload='{
"id": "E",
"type": "T",
"A": {
"value": 1,
"type": "Number"
}
}'
orionCurl --url /v2/entities --payload "${payload}"
echo
echo


echo "03. Update entity E/T without actual change (no notif)"
echo "======================================================"
payload='{
"A": {
"value": 1,
"type": "Number"
}
}'
orionCurl --url /v2/entities/E/attrs --payload "${payload}"
echo
echo


echo "04. Update entity E/T with actual change (no notif)"
echo "==================================================="
payload='{
"A": {
"value": 2,
"type": "Number"
}
}'
orionCurl --url /v2/entities/E/attrs --payload "${payload}"
echo
echo


echo "05. Delete entity E/T (notif)"
echo "============================="
orionCurl --url /v2/entities/E -X DELETE
echo
echo


echo "06. Dump accumulator: see E/T notification with alterationType entityDelete"
echo "==========================================================================="
accumulatorDump
echo
echo


--REGEXPECT--
01. Create subscription for entity type T with entityDelete
===========================================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/subscriptions/REGEX([0-9a-f]{24})
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



02. Create entity E/T (no notif)
================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/entities/E?type=T
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



03. Update entity E/T without actual change (no notif)
======================================================
HTTP/1.1 204 No Content
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



04. Update entity E/T with actual change (no notif)
===================================================
HTTP/1.1 204 No Content
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



05. Delete entity E/T (notif)
=============================
HTTP/1.1 204 No Content
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



06. Dump accumulator: see E/T notification with alterationType entityDelete
===========================================================================
POST http://127.0.0.1:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 192
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
Ngsiv2-Attrsformat: normalized
Host: 127.0.0.1:REGEX(\d+)
Accept: application/json
Content-Type: application/json; charset=utf-8
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1

{
"data": [
{
"A": {
"metadata": {},
"type": "Number",
"value": 2
},
"alterationType": {
"metadata": {},
"type": "Text",
"value": "entityDelete"
},
"id": "E",
"type": "T"
}
],
"subscriptionId": "REGEX([0-9a-f]{24})"
}
=======================================


--TEARDOWN--
brokerStop CB
accumulatorStop
dbDrop CB
0