Skip to content
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

More/jsonld contexts #1562

Merged
merged 2 commits into from
Feb 21, 2024
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
3 changes: 3 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
* Support for the new URL parameter "format" for output formats (normalized, concise, simplified)
* Fixed a possible crash for TRoE and attributes of type Vocab/Json/Language
* Modified the @context hosting feature to be according to API spec
* Support for URI param 'kind' for GET Contexts
* Improved counters for GET Context/Contexts
* API spec compliance for GET Context/Contexts
1 change: 1 addition & 0 deletions src/lib/logMsg/traceLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef enum TraceLevels
LmtContexts = 100, // Contexts
LmtContextTree, // Context Tree
LmtContextCache, // Context Cache
LmtContextCacheStats, // Context Cache Statistics
LmtContextDownload, // Context Download
LmtCoreContext, // Core Context

Expand Down
2 changes: 2 additions & 0 deletions src/lib/orionld/common/orionldState.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ typedef struct OrionldUriParams
bool entityMap;
char* format;

OrionldContextKind kind;

double observedAtAsDouble;
uint64_t mask;
} OrionldUriParams;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/context/orionldContextCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ OrionldContext* orionldContextCreate(const char* url, OrionldContextOrigin origi
}

contextP->keyValues = keyValues;
contextP->lookups = 0;
contextP->lookups = 1;

return contextP;
}
5 changes: 5 additions & 0 deletions src/lib/orionld/context/orionldContextFromUrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ OrionldContext* orionldContextFromUrl(char* url, char* id)

if (contextP != NULL)
{
contextP->usedAt = orionldState.requestTime;

contextP->lookups += 1;
LM_T(LmtContextCacheStats, ("Context '%s': %d lookups", url, contextP->lookups));

LM_T(LmtContextDownload, ("Found already downloaded URL '%s'", url));
return contextP;
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/orionld/context/orionldContextItemAliasLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ char* orionldContextItemAliasLookup
if (contextItemPP != NULL)
*contextItemPP = NULL;

if (contextP == NULL)
contextP = orionldCoreContextP;

// 1. Is it the default URL?
if (strncmp(longName, orionldDefaultUrl, orionldDefaultUrlLen) == 0)
{
orionldCoreContextP->compactions += 1;
return (char*) &longName[orionldDefaultUrlLen];
}

// 2. Found in Core Context?
contextItemP = orionldContextItemValueLookup(orionldCoreContextP, longName);
Expand Down Expand Up @@ -91,5 +96,6 @@ char* orionldContextItemAliasLookup
*contextItemPP = contextItemP;

// Return the short name
contextP->compactions += 1;
return contextItemP->name;
}
4 changes: 4 additions & 0 deletions src/lib/orionld/context/orionldContextItemExpand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ char* orionldContextItemExpand
if (contextItemPP != NULL)
*contextItemPP = NULL;

orionldCoreContextP->expansions += 1; // Really, @vocab expansions of the core context

return longName;
}

Expand All @@ -106,5 +108,7 @@ char* orionldContextItemExpand
if (contextItemPP != NULL)
*contextItemPP = contextItemP;

contextP->expansions += 1; // Really, @vocab expansions of the core context

return contextItemP->id;
}
15 changes: 10 additions & 5 deletions src/lib/orionld/context/orionldContextItemLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ OrionldContextItem* orionldContextItemLookup(OrionldContext* contextP, const cha
}
}

if (valueMayBeCompactedP != NULL)
if (itemP != NULL)
{
if ((itemP->type != NULL) && (strcmp(itemP->type, "@vocab") == 0))
*valueMayBeCompactedP = true;
else
*valueMayBeCompactedP = false;
contextP->expansions += 1;

if (valueMayBeCompactedP != NULL)
{
if ((itemP->type != NULL) && (strcmp(itemP->type, "@vocab") == 0))
*valueMayBeCompactedP = true;
else
*valueMayBeCompactedP = false;
}
}

return itemP;
Expand Down
39 changes: 23 additions & 16 deletions src/lib/orionld/contextCache/orionldContextCacheGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C"
#include "logMsg/logMsg.h" // LM_*
#include "logMsg/traceLevels.h" // Lmt*

#include "orionld/types/OrionldContext.h" // OrionldContext, orionldOriginToString
#include "orionld/types/OrionldContext.h" // OrionldContext, orionldOriginToString, OrionldContextKind
#include "orionld/types/OrionldContextItem.h" // OrionldContextItem
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/numberToDate.h" // numberToDate
Expand Down Expand Up @@ -67,35 +67,39 @@ KjNode* orionldContextWithDetails(OrionldContext* contextP)

KjNode* contextObjP = kjObject(orionldState.kjsonP, NULL);

KjNode* urlStringP = kjString(orionldState.kjsonP, "URL", contextP->url);
KjNode* idStringP = kjString(orionldState.kjsonP, "localId", (contextP->id == NULL)? "None" : contextP->id);
KjNode* kindP = kjString(orionldState.kjsonP, "kind", orionldKindToString(contextP->kind));
KjNode* createdAtP = kjString(orionldState.kjsonP, "createdAt", createdAtString);
KjNode* extraInfoP = kjObject(orionldState.kjsonP, "extraInfo");
KjNode* typeStringP = kjString(orionldState.kjsonP, "type", contextP->keyValues? "hash-table" : "array");
KjNode* originP = kjString(orionldState.kjsonP, "origin", orionldOriginToString(contextP->origin));
KjNode* urlStringP = kjString(orionldState.kjsonP, "URL", contextP->url);
KjNode* idStringP = kjString(orionldState.kjsonP, "localId", (contextP->id == NULL)? "None" : contextP->id);
KjNode* kindP = kjString(orionldState.kjsonP, "kind", orionldKindToString(contextP->kind));
KjNode* createdAtP = kjString(orionldState.kjsonP, "createdAt", createdAtString);
KjNode* extraInfoP = kjObject(orionldState.kjsonP, "extraInfo");
KjNode* typeStringP = kjString(orionldState.kjsonP, "type", (contextP->keyValues == true)? "hash-table" : "array");
KjNode* originP = kjString(orionldState.kjsonP, "origin", orionldOriginToString(contextP->origin));
KjNode* compactionsP = kjInteger(orionldState.kjsonP, "compactions", contextP->compactions);
KjNode* expansionsP = kjInteger(orionldState.kjsonP, "expansions", contextP->expansions);

kjChildAdd(contextObjP, urlStringP);
kjChildAdd(contextObjP, idStringP);
kjChildAdd(contextObjP, kindP);
kjChildAdd(contextObjP, createdAtP);
kjChildAdd(contextObjP, extraInfoP);
kjChildAdd(extraInfoP, typeStringP);
kjChildAdd(extraInfoP, originP);


if (contextP != orionldCoreContextP)
{
KjNode* usedAtP = kjString(orionldState.kjsonP, "lastUsage", lastUseString);
KjNode* lookupsP = kjInteger(orionldState.kjsonP, "numberOfHits", contextP->lookups);

KjNode* usedAtP = kjString(orionldState.kjsonP, "lastUsage", lastUseString);
KjNode* lookupsP = kjInteger(orionldState.kjsonP, "numberOfHits", contextP->lookups);
kjChildAdd(contextObjP, usedAtP);
kjChildAdd(contextObjP, lookupsP);
}

kjChildAdd(extraInfoP, typeStringP);
kjChildAdd(extraInfoP, originP);
kjChildAdd(extraInfoP, compactionsP);
kjChildAdd(extraInfoP, expansionsP);

if (contextP->parent != NULL)
{
KjNode* parentP = kjString(orionldState.kjsonP, "parent", contextP->parent);

kjChildAdd(extraInfoP, parentP);
}

Expand Down Expand Up @@ -155,15 +159,18 @@ KjNode* orionldContextWithDetails(OrionldContext* contextP)
//
// orionldContextCacheGet -
//
KjNode* orionldContextCacheGet(KjNode* arrayP, bool details)
KjNode* orionldContextCacheGet(KjNode* arrayP, bool details, OrionldContextKind kind)
{
for (int ix = 0; ix < orionldContextCacheSlotIx; ix++)
{
OrionldContext* contextP = orionldContextCacheArray[ix];
OrionldContext* contextP = orionldContextCacheArray[ix];

if (contextP == NULL)
continue;

if ((kind != OrionldContextUnknownKind) && (contextP->kind != kind))
continue;

if (details == true)
{
KjNode* contextObjP = orionldContextWithDetails(contextP);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/orionld/contextCache/orionldContextCacheGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ extern "C"
#include "kjson/KjNode.h" // KjNode
}

#include "orionld/types/OrionldContext.h" // OrionldContextKind



// -----------------------------------------------------------------------------
//
// orionldContextCacheGet -
//
extern KjNode* orionldContextCacheGet(KjNode* arrayP, bool details);
extern KjNode* orionldContextCacheGet(KjNode* arrayP, bool details, OrionldContextKind kind);

#endif // SRC_LIB_ORIONLD_CONTEXTCACHE_ORIONLDCONTEXTCACHEGET_H_
7 changes: 1 addition & 6 deletions src/lib/orionld/contextCache/orionldContextCacheLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ OrionldContext* orionldContextCacheLookup(const char* url)

if (strcmp(url, orionldContextCache[ix]->url) == 0)
contextP = orionldContextCache[ix];

if ((orionldContextCache[ix]->id != NULL) && (strcmp(url, orionldContextCache[ix]->id) == 0))
else if ((orionldContextCache[ix]->id != NULL) && (strcmp(url, orionldContextCache[ix]->id) == 0))
contextP = orionldContextCache[ix];

if (contextP != NULL)
{
contextP->usedAt = orionldState.requestTime;
contextP->lookups += 1;
return contextP;
}
}

return NULL;
Expand Down
1 change: 0 additions & 1 deletion src/lib/orionld/dbModel/dbModelToApiSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ KjNode* dbModelToApiSubscription
}



//
// origin
//
Expand Down
12 changes: 12 additions & 0 deletions src/lib/orionld/mhd/mhdConnectionInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,18 @@ MHD_Result orionldUriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char*
orionldState.uriParams.subscriptionId = (char*) value;
orionldState.uriParams.mask |= ORIONLD_URIPARAM_SUBSCRIPTION_ID;
}
else if (strcmp(key, "kind") == 0)
{
orionldState.uriParams.kind = orionldKindFromString(value);

if (orionldState.uriParams.kind == OrionldContextUnknownKind)
{
orionldError(OrionldBadRequestData, "Invalid value for uri parameter /kind/", value, 400);
return MHD_YES;
}

orionldState.uriParams.mask |= ORIONLD_URIPARAM_KIND;
}
else if (strcmp(key, "location") == 0)
{
if (strcmp(value, "true") == 0)
Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/service/orionldServiceInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceS
serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS;
serviceP->uriParams |= ORIONLD_URIPARAM_LOCATION;
serviceP->uriParams |= ORIONLD_URIPARAM_URL;
serviceP->uriParams |= ORIONLD_URIPARAM_KIND;

serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldGetContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool orionldGetContexts(void)

orionldState.noLinkHeader = true; // We don't want the Link header for context requests

orionldState.responseTree = orionldContextCacheGet(contextTree, orionldState.uriParams.details);
orionldState.responseTree = orionldContextCacheGet(contextTree, orionldState.uriParams.details, orionldState.uriParams.kind);

return true;
}
1 change: 1 addition & 0 deletions src/lib/orionld/types/OrionLdRestService.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ typedef struct OrionLdRestServiceSimplifiedVector
#define ORIONLD_URIPARAM_ENTITYMAP (UINT64_C(1) << 39)
#define ORIONLD_URIPARAM_FORMAT (UINT64_C(1) << 40)
#define ORIONLD_URIPARAM_EXPAND_VALUES (UINT64_C(1) << 41)
#define ORIONLD_URIPARAM_KIND (UINT64_C(1) << 42)



Expand Down
4 changes: 3 additions & 1 deletion src/lib/orionld/types/OrionldContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ typedef struct OrionldContext
bool coreContext;
double createdAt;
double usedAt;
int lookups;
int compactions; // Number of compactions done with this @context
int expansions; // Number of expansions done with this @context
int lookups; // Number of NGSI-LD requests done using this @context
bool keyValues;
OrionldContextInfo context;
OrionldContextOrigin origin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ Link: <http://localhost:7080/jsonldContexts/schema_lab_fiware_org_ld_context.jso
04. Get all contexts from the context cache
===========================================
HTTP/1.1 200 OK
Content-Length: 1855
Content-Length: 2000
Content-Type: application/json
Date: REGEX(.*)

Expand All @@ -739,6 +739,8 @@ Date: REGEX(.*)
"extraInfo": {
"type": "hash-table",
"origin": "Downloaded",
"compactions": 5,
"expansions": 286,
"hash-table": {
"instanceId": "https://uri.etsi.org/ngsi-ld/instanceId",
"notifiedAt": "https://uri.etsi.org/ngsi-ld/notifiedAt",
Expand All @@ -756,6 +758,8 @@ Date: REGEX(.*)
"extraInfo": {
"type": "hash-table",
"origin": "Downloaded",
"compactions": 0,
"expansions": 26,
"hash-table": {
"roadClosed": "https://uri.fiware.org/ns/data-models#roadClosed",
"copyMachineOrService": "https://uri.fiware.org/ns/data-models#copyMachineOrService",
Expand All @@ -765,7 +769,7 @@ Date: REGEX(.*)
}
},
"lastUsage": "202REGEX(.*)",
"numberOfHits": 0
"numberOfHits": 1
},
{
"URL": "http://localhost:7080/jsonldContexts/schema_lab_fiware_org_ld_context.jsonld",
Expand All @@ -775,12 +779,14 @@ Date: REGEX(.*)
"extraInfo": {
"type": "array",
"origin": "Downloaded",
"compactions": 25,
"expansions": 27,
"URLs": [
"https://fiware.github.io/data-models/context.jsonld"
]
},
"lastUsage": "202REGEX(.*)",
"numberOfHits": 10
"numberOfHits": 2
}
]

Expand Down Expand Up @@ -990,7 +996,7 @@ Link: <http://localhost:7080/jsonldContexts/schema_lab_fiware_org_ld_context.jso
07. Get all contexts from the context cache
===========================================
HTTP/1.1 200 OK
Content-Length: 1855
Content-Length: 2001
Content-Type: application/json
Date: REGEX(.*)

Expand All @@ -1003,6 +1009,8 @@ Date: REGEX(.*)
"extraInfo": {
"type": "hash-table",
"origin": "Downloaded",
"compactions": 10,
"expansions": 291,
"hash-table": {
"instanceId": "https://uri.etsi.org/ngsi-ld/instanceId",
"notifiedAt": "https://uri.etsi.org/ngsi-ld/notifiedAt",
Expand All @@ -1020,6 +1028,8 @@ Date: REGEX(.*)
"extraInfo": {
"type": "hash-table",
"origin": "Downloaded",
"compactions": 0,
"expansions": 52,
"hash-table": {
"roadClosed": "https://uri.fiware.org/ns/data-models#roadClosed",
"copyMachineOrService": "https://uri.fiware.org/ns/data-models#copyMachineOrService",
Expand All @@ -1029,7 +1039,7 @@ Date: REGEX(.*)
}
},
"lastUsage": "202REGEX(.*)",
"numberOfHits": 0
"numberOfHits": 1
},
{
"URL": "http://localhost:7080/jsonldContexts/schema_lab_fiware_org_ld_context.jsonld",
Expand All @@ -1039,12 +1049,14 @@ Date: REGEX(.*)
"extraInfo": {
"type": "array",
"origin": "Downloaded",
"compactions": 50,
"expansions": 54,
"URLs": [
"https://fiware.github.io/data-models/context.jsonld"
]
},
"lastUsage": "202REGEX(.*)",
"numberOfHits": 21
"numberOfHits": 3
}
]

Expand Down
Loading
Loading