diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 9bde859a90..48ec5fb936 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -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. diff --git a/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp b/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp index a1a9d1332e..ea32a7a9f2 100644 --- a/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp +++ b/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp @@ -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 - @@ -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; diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test b/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test index 101c1fd47d..bcd1dcea91 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test @@ -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 @@ -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