Skip to content

Commit

Permalink
HTTP notifications on incoming dds samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Nov 21, 2024
1 parent 5141932 commit 3b551cd
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/lib/orionld/dds/ddsNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern "C"
#include "orionld/common/traceLevels.h" // KT_T trace levels
#include "orionld/common/tenantList.h" // tenant0
#include "orionld/context/orionldContextItemExpand.h" // orionldContextItemExpand
#include "orionld/notifications/orionldAlterationsTreat.h" // orionldAlterationsTreat
#include "orionld/serviceRoutines/orionldPutAttribute.h" // orionldPutAttribute
#include "orionld/dds/kjTreeLog.h" // kjTreeLog2
#include "orionld/dds/ddsConfigTopicToAttribute.h" // ddsConfigTopicToAttribute
Expand Down Expand Up @@ -133,4 +134,8 @@ void ddsNotification(const char* typeName, const char* topicName, const char* js
// Except of course, if it is registered and exists elsewhere
//
orionldPutAttribute();

// Do what's needed from the function requestCompleted
if (orionldState.alterations != NULL)
orionldAlterationsTreat(orionldState.alterations);
}
2 changes: 1 addition & 1 deletion src/lib/orionld/notifications/notificationSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ static KjNode* notificationTree(OrionldAlterationMatch* matchList)
apiEntityP = matchP->altP->finalApiEntityP; // Temporary !!!

// If the entity is already in "data", and, it's not a BATCH Operation, skip - already there
if (orionldState.serviceP->isBatchOp == false)
if ((orionldState.serviceP == NULL) || (orionldState.serviceP->isBatchOp == false))
{
KjNode* idP = kjLookup(apiEntityP, "id");
if (idP == NULL)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/orionld/notifications/subCacheAlterationMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,21 @@ static bool entityIdMatch(CachedSubscription* subP, const char* entityId, int eI
//
static bool entityTypeMatch(CachedSubscription* subP, const char* entityType, int eItems)
{
LM_T(LmtSubCacheMatch, ("Sub '%s': checking entity type", subP->subscriptionId));
for (int ix = 0; ix < eItems; ++ix)
{
EntityInfo* eiP = subP->entityIdInfos[ix];
const char* eType = eiP->entityType.c_str();

LM_T(LmtSubCacheMatch, ("Sub '%s': matching incoming entity type '%s' to the subs '%s'", subP->subscriptionId, entityType, eType));
if (strcmp(entityType, eType) == 0)
return true;

if ((eType[0] == '*') && (eType[1] == 0))
return true;
}

LM_T(LmtSubCacheMatch, ("Sub '%s': no match due to Entity Type", subP->subscriptionId));
LM_T(LmtSubCacheMatch, ("Sub '%s': no match due to Entity Type ('%s')", subP->subscriptionId, entityType));
return false;
}

Expand Down
169 changes: 163 additions & 6 deletions test/functionalTest/cases/0000_dds/dds_notifications.test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ the test client publishes on DDS, the broker receives DDS notifications and crea
$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.orionld
$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.ftClient
dbInit CB
orionldStart CB -mongocOnly -wip dds
orionldStart CB -mongocOnly -wip dds -t 0-255
ftClientStart -t 0-5000

--SHELL--
Expand All @@ -39,9 +39,14 @@ ftClientStart -t 0-5000
# 04. Ask FT to publish an entity urn:E4 on topic 'P4'
# 05. Query the broker for all its entities, see all three (urn:ngsi-ld:camera:cam1, urn:ngsi-ld:arm:arm1, and the default entity))
#
# 06. Create a subscription for entity type 'Camera'
# 07. Ask FT to publish an entity urn:E1 on topic 'P1' - to provoke a notification to ftClient
# 08. Ping broker to make sure it's still OK (issue XXX says it dies)
# 09. Dump the ftClient to see the notification
#
# Later:
# 06. Kill the broker and empty its databae, then restart the broker again
# 07. Query the broker for all its entities, see all three - should be present due to the DDS discovery
# 11. Kill the broker and empty its databae, then restart the broker again
# 12. Query the broker for all its entities, see all three - should be present due to the DDS discovery
#

echo "01. Ask FT to publish an entity urn:E1 on topic 'P1'"
Expand Down Expand Up @@ -93,7 +98,53 @@ echo
echo


# echo "06. Kill the broker and empty its database, then restart the broker again"
echo "06. Create a subscription for entity type 'Camera'"
echo "=================================================="
payload='{
"id": "urn:s1",
"type": "Subscription",
"entities": [
{
"type": "Camera"
}
],
"notification": {
"endpoint": {
"uri": "http://127.0.0.1:'${FT_PORT}'/notify"
}
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "07. Ask FT to publish an entity urn:E1 on topic 'P1' - to provoke a notification to ftClient"
echo "============================================================================================"
payload='{
"s": "def"
}'
orionCurl --url '/dds/pub?ddsTopicType=xyz&entityId=urn:E1&entityType=T&ddsTopicName=P1' --port $FT_PORT --payload "$payload"
echo
echo


echo "08. Ping broker to make sure it's still OK (issue XXX says it dies)"
echo "==================================================================="
orionCurl --url /ngsi-ld/ex/v1/version
echo
echo


echo "09. Dump the ftClient to see the notification"
echo "============================================="
sleep .5
orionCurl --url /dump --port $FT_PORT --noPayloadCheck
echo
echo


# echo "11. Kill the broker and empty its database, then restart the broker again"
# echo "========================================================================="
# brokerStop
# dbInit CB > /dev/null
Expand All @@ -103,7 +154,7 @@ echo
# echo


# echo "07. Query the broker for all its entities, see all three - should be present due to the DDS discovery "
# echo "12. Query the broker for all its entities, see all three - should be present due to the DDS discovery "
# echo "======================================================================================================"
# orionCurl --url /ngsi-ld/v1/entities?local=true
# echo
Expand Down Expand Up @@ -275,7 +326,113 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


06. Create a subscription for entity type 'Camera'
==================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:s1



07. Ask FT to publish an entity urn:E1 on topic 'P1' - to provoke a notification to ftClient
============================================================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



08. Ping broker to make sure it's still OK (issue XXX says it dies)
===================================================================
HTTP/1.1 200 OK
Content-Length: REGEX(.*)
Content-Type: application/json
Date: REGEX(.*)

{
"Core Context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)",
"Next File Descriptor": REGEX(.*),
"Orion-LD version": "REGEX(.*)",
"based on orion": "REGEX(.*)",
"boost version": "REGEX(.*)",
"branch": "REGEX(.*)",
"bson version": "REGEX(.*)",
"cached subscriptions": 1,
"kalloc version": "REGEX(.*)",
"kbase version": "REGEX(.*)",
"khash version": "REGEX(.*)",
"kjson version": "REGEX(.*)",
"libcurl version": "REGEX(.*)",
"libuuid version": "REGEX(.*)",
"microhttpd version": "REGEX(.*)",
"mongoc version": "REGEX(.*)",
"mongocpp version": "REGEX(.*)",
"mongodb server version": "REGEX(.*)",
"openssl version": "REGEX(.*)",
"rapidjson version": "REGEX(.*)"
}


09. Dump the ftClient to see the notification
=============================================
HTTP/1.1 200 OK
Content-Length: 1262
Date: REGEX(.*)

POST /notify?subscriptionId=urn:s1
Content-Length: 560
Content-Type: application/json
User-Agent: orionld/REGEX(.*)
Host: REGEX(.*)
Accept: application/json
Ngsild-Attribute-Format: Normalized
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"id": "urn:ngsi-ld:Notification:REGEX(.*)",
"type": "Notification",
"subscriptionId": "urn:s1",
"notifiedAt": "202REGEX(.*)",
"data": [
{
"id": "urn:ngsi-ld:camera:cam1",
"type": "Camera",
"ddsType": {
"type": "Property",
"value": "fastdds"
},
"shutterSpeed": {
"type": "Property",
"value": {
"b": false,
"f": 0,
"i": 0,
"ia": [
0,
0
],
"s": "def"
},
"xId": {
"type": "Property",
"value": "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0"
},
"participantId": {
"type": "Property",
"value": "REGEX(.*)"
},
"publishedAt": {
"type": "Property",
"value": REGEX(.*)
}
}
}
]
}



--TEARDOWN--
ftClientStop
brokerStop
#dbDrop CB
dbDrop CB

0 comments on commit 3b551cd

Please sign in to comment.