Skip to content

Commit

Permalink
Full support for GET /info/sourceIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Sep 3, 2024
1 parent 660c6bb commit e6b7c53
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## New Features:
* Distributed subscriptions: subordinate subscriptions are DELETED when their "father" is deleted.
* Support for the URL parameter 'csf' in GET /ngsi-ld/v1/csourceRegistrations
* Support for the URL parameter 'orderBy' (must be an attribute) in GET //ngsi-ld/v1/entities, but only if 'local' is set. (This is not NGSI-LD standard. Yet ...)
* Support for the URL parameter 'orderBy' (must be an attribute) in GET /ngsi-ld/v1/entities, but only if 'local' is set. (This is not NGSI-LD standard. Yet ...)
- Also supporting sorting on entity id, type, and modifiedAt
- One more URL parameter '?reverse=true' to reverse the sorting order
* Rudimentary support for GET /info/sourceIdentity
* Support for GET /ngsi-ld/v1/info/sourceIdentity

## Notes
* Lots of improvements for subordinate subscriptions - still not 100% ready, but a lot better.
57 changes: 53 additions & 4 deletions src/lib/orionld/serviceRoutines/orionldGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,37 @@ extern "C"
#include "logMsg/logMsg.h" // LM_*

#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/numberToDate.h" // numberToDate
#include "orionld/serviceRoutines/orionldGetVersion.h" // orionldGetVersion
#include "orionld/serviceRoutines/orionldGetInfo.h" // Own Interface



// ----------------------------------------------------------------------------
//
// uptimeRender -
//
static void uptimeRender(int uptime, char* buf, int bufLen)
{
int seconds = uptime % 60;
uptime = uptime / 60;

int minutes = uptime % 60;
uptime = uptime / 60;

int hours = uptime / 24;
uptime = uptime / 24;

int days = uptime;

if (days > 0)
snprintf(buf, bufLen - 1, "P%dDT%02dH%02dM%02dS", days, hours, minutes, seconds);
else
snprintf(buf, bufLen - 1, "PT%02dH%02dM%02dS", hours, minutes, seconds);
}



// ----------------------------------------------------------------------------
//
// orionldGetInfo -
Expand All @@ -43,18 +70,40 @@ bool orionldGetInfo(void)
{
static int runNo = 1;
char id[128];
int uptime = orionldState.requestTime - startTime;
char uptimeV[64];
char currentTimeV[64];
KjNode* extras;

// id
snprintf(id, sizeof(id) - 1, "urn:ngsi-ld:cs:%06d", runNo);
++runNo;

KjNode* infoP = kjObject(orionldState.kjsonP, NULL);
KjNode* idP = kjString(orionldState.kjsonP, "id", id);
KjNode* typeP = kjString(orionldState.kjsonP, "type", "ContextSourceIdentity");
KjNode* aliasP = kjString(orionldState.kjsonP, "contextSourceAlias", brokerId);
// uptime
uptimeRender(uptime, uptimeV, sizeof(uptimeV));

// current time
numberToDate(orionldState.requestTime, currentTimeV, sizeof(currentTimeV));

// extras
orionldGetVersion();
extras = orionldState.responseTree;

KjNode* infoP = kjObject(orionldState.kjsonP, NULL);
KjNode* idP = kjString(orionldState.kjsonP, "id", id);
KjNode* typeP = kjString(orionldState.kjsonP, "type", "ContextSourceIdentity");
KjNode* uptimeP = kjString(orionldState.kjsonP, "contextSourceUptime", uptimeV);
KjNode* currentP = kjString(orionldState.kjsonP, "contextSourceTimeAt", currentTimeV);
KjNode* aliasP = kjString(orionldState.kjsonP, "contextSourceAlias", brokerId);

kjChildAdd(infoP, idP);
kjChildAdd(infoP, typeP);
kjChildAdd(infoP, uptimeP);
kjChildAdd(infoP, currentP);
kjChildAdd(infoP, aliasP);
kjChildAdd(infoP, extras);

extras->name = (char*) "contextSourceExtras";

orionldState.responseTree = infoP;

Expand Down
37 changes: 32 additions & 5 deletions test/functionalTest/cases/0000_ngsild/ngsild_get_info.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ orionldStart CB -troe -brokerId urn:B1 -experimental

echo "01. GET /ngsi-ld/info/sourceIdentity"
echo "===================================="
orionCurl --url /ngsi-ld/v1/info/sourceIdentity
orionCurl --url /ngsi-ld/v1/info/sourceIdentity --noPayloadCheck
echo
echo

Expand All @@ -44,17 +44,44 @@ echo
01. GET /ngsi-ld/info/sourceIdentity
====================================
HTTP/1.1 200 OK
Content-Length: 105
Content-Length: REGEX(.*)
Content-Type: application/json
Date: REGEX(.*)

{
"contextSourceAlias": "urn:B1",
"id": "urn:ngsi-ld:cs:000001",
"type": "ContextSourceIdentity"
"id": "urn:ngsi-ld:cs:000001",
"type": "ContextSourceIdentity",
"contextSourceUptime": "PTREGEX(.*)",
"contextSourceTimeAt": "202REGEX(.*)Z",
"contextSourceAlias": "urn:B1",
"contextSourceExtras": {
"Orion-LD version": REGEX(.*),
"based on orion": REGEX(.*),
"kbase version": REGEX(.*),
"kalloc version": REGEX(.*),
"khash version": REGEX(.*),
"kjson version": "0.8.2",
"microhttpd version": "0.9.75-0",
"rapidjson version": REGEX(.*),
"libcurl version": REGEX(.*),
"libuuid version": REGEX(.*),
"mongocpp version": "REGEX((1.1.2|1.1.3))",
"mongoc version": "1.24.2",
"bson version": "1.24.2",
"mongodb server version": "REGEX(.*)",
"boost version": REGEX(.*),
"openssl version": REGEX(.*),
"postgres libpq version": "REGEX(.*)",
"postgres server version": "12.REGEX(.*)",
"branch": REGEX(.*),
"cached subscriptions": 0,
"Core Context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)",
"Next File Descriptor": REGEX(.*)
}
}



--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit e6b7c53

Please sign in to comment.