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

The list of entity ids (url param) is now part of the forwarded message on a pre-defined entity map #1488

Merged
merged 1 commit into from
Dec 5, 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
30 changes: 19 additions & 11 deletions src/lib/logMsg/traceLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,45 @@ typedef enum TraceLevels
LmtRegCache = 60, // Registration Cache

//
// Distributed Operations
// Distributed Operations - requests
//
LmtDistOpMsgs = 70, // Deprecated, still in use though ...
LmtDistOpRequest, // ONLY the verb, path, and body of a distributed request
LmtDistOpResponse, // ONLY the body and status code of the response to a distributed request
LmtDistOp207, // Merging of the final 207 response
LmtDistOpRequest = 70, // ONLY the verb, path, and body of a distributed request
LmtDistOpRequestHeaders, // HTTP headers of distributed requests
LmtDistOpRequestParams, // URL parameters of distributed requests

//
// Distributed Operations - responses
//
LmtDistOpResponse = 80, // ONLY the body and status code of the response to a distributed request
LmtDistOpResponseBuf, // Specific debugging of the incoming response of a distributed message
LmtDistOpResponseDetail, // Details on responses to distributed requests
LmtDistOpResponseHeaders, // HTTP headers of responses to distributed requests
LmtDistOpRequestHeaders, // HTTP headers of request of distributed requests
LmtDistOpList, // Linked list of DistOps

//
// Distributed Operations - misc
//
LmtDistOpList = 90, // Linked list of DistOps
LmtDistOpAttributes, // The union of attributes URL-Param / Registered Attributes
LmtDistOpMerge, // Merge of responses from forwsrded requests (GET /entities)
LmtDistOpLoop, // Loop detection in forwarded messages
LmtDistOp207, // Merging of the final 207 response

//
// Context
//
LmtContexts = 82, // Contexts
LmtContexts = 100, // Contexts
LmtContextTree, // Context Tree
LmtContextCache, // Context Cache
LmtContextDownload, // Context Download
LmtCoreContext, // Core Context

// GeoJSON
LmtGeoJSON = 90, // GeoJSON ... everything (for now)
LmtGeoJSON = 110, // GeoJSON ... everything (for now)

//
// Pernot sub-cache
//
LmtPernot = 100, // Periodic Notification Subscription cache
LmtPernot = 120, // Periodic Notification Subscription cache
LmtPernotLoop, // Pernot loop, when each sub is triggered in time
LmtPernotLoopTimes, // Pernot loop, details on timestamps
LmtPernotFlush, // Pernot flush to DB
Expand All @@ -111,7 +119,7 @@ typedef enum TraceLevels
//
// Pagination
//
LmtEntityMap = 110, // The arrays of registrations per entity - distributed GET /entities
LmtEntityMap = 130, // The arrays of registrations per entity - distributed GET /entities
LmtEntityMapRetrieve, // Retrieval of an entity map
LmtEntityMapDetail, // Details of the entity-registration maps

Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/forwarding/distOpRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ DistOp* distOpRequests(char* entityId, char* entityType, DistOpType operation, K
// Send the forwarded request and await all responses
if ((distOpP->regP != NULL) && (distOpP->error == false))
{
if (distOpSend(distOpP, dateHeader, xff, false) == 0)
if (distOpSend(distOpP, dateHeader, xff, false, NULL) == 0)
{
distOpP->error = false;
orionldState.distOp.requests += 1;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/orionld/forwarding/distOpResponses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void entityResponseAccumulate(DistOp* distOpP, KjNode* responseBody, KjNode* suc
}
else if (httpResponseCode == 0)
{
LM_T(LmtDistOpMsgs, ("%s: Seems like the request wasn't even sent ... (%s)", distOpP->regP->regId, distOpP->regP->ipAndPort));
LM_T(LmtDistOpResponse, ("%s: Seems like the request wasn't even sent ... (%s)", distOpP->regP->regId, distOpP->regP->ipAndPort));

int statusCode = 500;
const char* title = "Unable to send distributed request";
Expand All @@ -292,9 +292,9 @@ void entityResponseAccumulate(DistOp* distOpP, KjNode* responseBody, KjNode* suc
distOpFailure(responseBody, distOpP, title, detail, statusCode, NULL);
}
else if (httpResponseCode == 200)
LM_T(LmtDistOpMsgs, ("Reg %s: unexpected status code %d (using the accumulator?)", distOpP->regP->regId, httpResponseCode));
LM_W(("%s: unexpected status code %d (using the accumulator?)", distOpP->regP->regId, httpResponseCode));
else
LM_W(("Reg %s: unexpected status code %d", distOpP->regP->regId, httpResponseCode));
LM_W(("%s: unexpected status code %d", distOpP->regP->regId, httpResponseCode));
}


Expand Down
31 changes: 26 additions & 5 deletions src/lib/orionld/forwarding/distOpSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ extern "C"

#include "logMsg/logMsg.h" // LM_*

#include "common/globals.h" // NGSI_LD_V1
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/tenantList.h" // tenant0
#include "orionld/context/orionldCoreContext.h" // orionldCoreContextP
#include "orionld/context/orionldContextItemAliasLookup.h" // orionldContextItemAliasLookup
#include "orionld/q//qRender.h" // qRender
#include "orionld/forwarding/DistOp.h" // DistOp
#include "orionld/forwarding/distOpSend.h" // Own interface

Expand Down Expand Up @@ -153,7 +155,7 @@ char* urlCompose(ForwardUrlParts* urlPartsP, KjNode* endpointP)
//
// uriParamAdd -
//
void uriParamAdd(ForwardUrlParts* urlPartsP, const char* key, const char* value, int totalLen)
static void uriParamAdd(ForwardUrlParts* urlPartsP, const char* key, const char* value, int totalLen)
{
SList* sListP = (SList*) kaAlloc(&orionldState.kalloc, sizeof(SList));

Expand All @@ -171,6 +173,8 @@ void uriParamAdd(ForwardUrlParts* urlPartsP, const char* key, const char* value,
sListP->sLen = snprintf(sListP->sP, sLen, "%s=%s", key, value);
}

LM_T(LmtDistOpRequestParams, ("DistOp Request URL Param: %s", sListP->sP));

sListP->next = NULL;

if (urlPartsP->params == NULL)
Expand Down Expand Up @@ -325,7 +329,7 @@ void bodyCompact(DistOpType operation, KjNode* requestBody, OrionldContext* fwdC
//
// distOpSend -
//
bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedForHeader, bool local)
bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedForHeader, bool local, const char* entityIds)
{
//
// Figure out the @context to use for the forwarded request
Expand Down Expand Up @@ -389,6 +393,7 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
//
// Add URI Params
//
LM_T(LmtDistOpRequestParams, ("%s: ---- URL Parameters for %s ------------------------", distOpP->regP->regId, distOpP->id));
if (orionldState.verb == GET)
{
if (distOpP->attrsParam != NULL)
Expand All @@ -405,12 +410,26 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
else
uriParamAdd(&urlParts, "options=sysAttrs", NULL, 16);

if ((distOpP->operation == DoQueryEntity) && (distOpP->entityId != NULL))
uriParamAdd(&urlParts, "id", distOpP->entityId, -1);
if (distOpP->operation == DoQueryEntity)
{
if (entityIds != NULL)
uriParamAdd(&urlParts, "id", entityIds, -1);
else if (distOpP->entityId != NULL)
uriParamAdd(&urlParts, "id", distOpP->entityId, -1);
}

if (local == true)
uriParamAdd(&urlParts, "local=true", NULL, 10);

if (distOpP->qNode != NULL)
{
char buf[256];
qRender(distOpP->qNode, NGSI_LD_V1, buf, sizeof(buf), NULL);
LM_T(LmtDistOpRequestParams, ("DistOp %s has a Q: %s", distOpP->regP->regId, buf));
if (orionldState.uriParams.q != NULL)
LM_T(LmtDistOpRequestParams, ("The initial request alsao has a 'q'"));
}

//
// If we know the Entity Type, we pass that piece of information as well
//
Expand All @@ -433,6 +452,8 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
LM_T(LmtDistOpRequestHeaders, ("%s: orionldState.uriParams.q: '%s'", distOpP->regP->regId, orionldState.uriParams.qCopy));
}

LM_T(LmtDistOpRequestParams, ("%s: ---- End of URL Parameters -----------------", distOpP->regP->regId));

//
// Compose the entire URL and pass it to CURL
//
Expand Down Expand Up @@ -585,7 +606,7 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
struct curl_slist* sP = headers;
while (sP != NULL)
{
LM_T(LmtDistOpMsgs, ("FWD: Added header '%s'", sP->data));
LM_T(LmtDistOpRequest, ("FWD: Added header '%s'", sP->data));
sP = sP->next;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/forwarding/distOpSend.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
//
// distOpSend -
//
extern bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedForHeader, bool local);
extern bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedForHeader, bool local, const char* entityIds);

#endif // SRC_LIB_ORIONLD_FORWARDING_DISTOPSEND_H_
4 changes: 2 additions & 2 deletions src/lib/orionld/forwarding/distOpsSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int distOpsSend(DistOp* distOpList, bool local)
{
distOpP->onlyIds = true;

if (distOpSend(distOpP, dateHeader, xff, local) == 0)
if (distOpSend(distOpP, dateHeader, xff, local, NULL) == 0)
distOpP->error = false;
else
distOpP->error = true;
Expand Down Expand Up @@ -118,7 +118,7 @@ int distOpsSend2(DistOpListItem* distOpList)
{
distOpP->onlyIds = false;

if (distOpSend(distOpP, dateHeader, xff, false) == 0)
if (distOpSend(distOpP, dateHeader, xff, false, doItemP->entityIds) == 0)
distOpP->error = false;
else
distOpP->error = true;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldDeleteAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static DistOp* distributedDelete(KjNode* responseBody, char* entityId, char* ent
char dateHeader[70];
snprintf(dateHeader, sizeof(dateHeader), "Date: %s", orionldState.requestTimeString);

if (distOpSend(distOpP, dateHeader, xff, false) == 0)
if (distOpSend(distOpP, dateHeader, xff, false, NULL) == 0)
{
++forwards;
distOpP->error = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldDeleteEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static DistOp* distributedDelete(char* entityId, char* entityTypeExpanded, char*
char dateHeader[70];
snprintf(dateHeader, sizeof(dateHeader), "Date: %s", orionldState.requestTimeString);

if (distOpSend(distOpP, dateHeader, xff, false) == 0)
if (distOpSend(distOpP, dateHeader, xff, false, NULL) == 0)
{
++forwards;
distOpP->error = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldGetEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool orionldGetEntity(void)
if (distOpP->regP != NULL)
{
LM_T(LmtDistOpAttributes, ("distOp::attrsParam: '%s'", distOpP->attrsParam));
if (distOpSend(distOpP, dateHeader, xff, false) == 0)
if (distOpSend(distOpP, dateHeader, xff, false, NULL) == 0)
{
++forwards;
distOpP->error = false;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ static bool attributeLookup(KjNode* dbAttrsP, char* attrName)
//
void rawResponse(DistOp* distOpList, const char* what)
{
LM_T(LmtDistOpMsgs, ("=============== rawResponse: %s", what));
LM_T(LmtSR, ("=============== rawResponse: %s", what));
for (DistOp* distOpP = distOpList; distOpP != NULL; distOpP = distOpP->next)
{
if (distOpP->rawResponse != NULL)
LM_T(LmtDistOpMsgs, ("%s: rawResponse: '%s'", distOpP->regP->regId, distOpP->rawResponse));
LM_T(LmtSR, ("%s: rawResponse: '%s'", distOpP->regP->regId, distOpP->rawResponse));
else
LM_T(LmtDistOpMsgs, ("%s: rawResponse: NULL", distOpP->regP->regId));
LM_T(LmtSR, ("%s: rawResponse: NULL", distOpP->regP->regId));
}
LM_T(LmtDistOpMsgs, ("===================================================================="));
LM_T(LmtSR, ("===================================================================="));
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldPatchEntity2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ bool orionldPatchEntity2(void)
{
char body[1024];
kjFastRender(distOpP->requestBody, body);
LM_T(LmtDistOpMsgs, ("Registration '%s': %s", distOpP->regP->regId, body));
LM_T(LmtSR, ("Registration '%s': %s", distOpP->regP->regId, body));
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldPostBatchDelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ bool orionldPostBatchDelete(void)
char dateHeader[70];
snprintf(dateHeader, sizeof(dateHeader), "Date: %s", orionldState.requestTimeString);

if (distOpSend(distReqP, dateHeader, xff, false) == 0)
if (distOpSend(distReqP, dateHeader, xff, false, NULL) == 0)
{
++forwards;
distReqP->error = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,46 +629,6 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
},
"id": "urn:cp3:entities:E34",
"type": "T"
},
{
"A1": {
"type": "Property",
"value": "E36:A1"
},
"id": "urn:cp3:entities:E35",
"type": "T"
},
{
"A1": {
"type": "Property",
"value": "E37:A1"
},
"id": "urn:cp3:entities:E36",
"type": "T"
},
{
"A1": {
"type": "Property",
"value": "E38:A1"
},
"id": "urn:cp3:entities:E37",
"type": "T"
},
{
"A1": {
"type": "Property",
"value": "E39:A1"
},
"id": "urn:cp3:entities:E38",
"type": "T"
},
{
"A1": {
"type": "Property",
"value": "E40:A1"
},
"id": "urn:cp3:entities:E39",
"type": "T"
}
]

Expand Down
Loading