Skip to content

Commit

Permalink
DistOps for Purge Entities
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Apr 9, 2024
1 parent 446085d commit 30767ef
Show file tree
Hide file tree
Showing 19 changed files with 512 additions and 215 deletions.
10 changes: 5 additions & 5 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* #1573: pagination not working when entities have the exact same creation date (sort also by entity id)
* #1583: If a 'q' contains an ampersand, that ampersand needs to be forwarded as a semicolon
* #1593: Modify the type of an entity in a Replace operation (only working in legacy mode)
* Fixed a possible crash for TRoE and attributes of type Vocab/Json/Language
* Forbidden to DELETE the Core Context !!! (it can be reloaded)
* Bug fix: JSON NULL literal is no longer forwarded!

## New Features:
* Support for attributes of type VocabularyProperty
* Support for attributes of type JsonProperty
* Support for the new URL parameter "format" for output formats (normalized, concise, simplified)
* Support for JsonProperty attribute type
* Fixed a possible crash for TRoE and attributes of type Vocab/Json/Language
* Forbidden to DELETE the Core Context !!! (it can be reloaded)
* Bug fix: JSON NULL literal is no longer forwarded!

* New service: DELETE /ngsi-ld/v1/entities (URL param 'type' only - the rest are missing still)

## Notes
* TRoE is still not prepared for attributes of type Vocab/Json/Language, so, attributes of those types are not stored in the historical database
* Modified the @context hosting feature to be according to API spec
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ SET (ORION_LIBS
orionld_serviceRoutines
orionld_distOp
orionld_regMatch
orionld_distOp
orionld_troe
orionld_kjTree
orionld_mqtt
Expand Down
17 changes: 11 additions & 6 deletions src/lib/orionld/distOp/distOpSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ extern "C"

#include "orionld/types/DistOp.h" // DistOp
#include "orionld/types/ApiVersion.h" // API_VERSION_NGSILD_V1
#include "orionld/types/OrionLdRestService.h" // OrionLdRestService
#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/serviceRoutines/orionldDeleteAttribute.h" // orionldDeleteAttribute
#include "orionld/distOp/distOpSend.h" // Own interface


Expand Down Expand Up @@ -469,9 +471,9 @@ 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 == HTTP_GET)
if ((orionldState.verb == HTTP_GET) || (orionldState.verb == HTTP_DELETE))
{
if (distOpP->attrsParam != NULL)
if ((distOpP->attrsParam != NULL) && (orionldState.serviceP->serviceRoutine != orionldDeleteAttribute))
uriParamAdd(&urlParts, distOpP->attrsParam, NULL, distOpP->attrsParamLen);

//
Expand All @@ -480,10 +482,13 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
//
// There is one exception though - when only the entity ids are wanted as output
//
if (distOpP->onlyIds == true)
uriParamAdd(&urlParts, "onlyIds=true", NULL, 12);
else
uriParamAdd(&urlParts, "options=sysAttrs", NULL, 16);
if (orionldState.verb == HTTP_GET)
{
if (distOpP->onlyIds == true)
uriParamAdd(&urlParts, "onlyIds=true", NULL, 12);
else
uriParamAdd(&urlParts, "options=sysAttrs", NULL, 16);
}

if (distOpP->operation == DoQueryEntity)
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/payloadCheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ SET (SOURCES
pCheckRegistrationManagement.cpp
pCheckTenant.cpp
pCheckScope.cpp
pCheckQueryParams.cpp
)

# Include directories
Expand Down
126 changes: 126 additions & 0 deletions src/lib/orionld/payloadCheck/pCheckQueryParams.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
*
* Copyright 2024 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#include "logMsg/logMsg.h" // LM_*

#include "orionld/types/QNode.h" // QNode
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/orionldError.h" // orionldError
#include "orionld/q/qLex.h" // qLex
#include "orionld/q/qParse.h" // qParse
#include "orionld/payloadCheck/pCheckGeo.h" // pCheckGeo
#include "orionld/payloadCheck/pCheckQueryParams.h" // Own interface



// ----------------------------------------------------------------------------
//
// qCheck -
//
static QNode* qCheck(char* qString)
{
QNode* qList;
char* title;
char* detail;

qList = qLex(qString, true, &title, &detail);
if (qList == NULL)
{
orionldError(OrionldBadRequestData, "Invalid Q-Filter", detail, 400);
LM_RE(NULL, ("Error (qLex: %s: %s)", title, detail));
}

QNode* qNode = qParse(qList, NULL, true, true, &title, &detail); // 3rd parameter: forDb=true
if (qNode == NULL)
{
orionldError(OrionldBadRequestData, title, detail, 400);
LM_E(("Error (qParse: %s: %s) - but, the subscription will be inserted in the sub-cache without 'q'", title, detail));
}

return qNode;
}



// -----------------------------------------------------------------------------
//
// pCheckQueryParams -
//
bool pCheckQueryParams
(
char* id,
char* type,
char* idPattern,
char* q,
char* geometry,
char* attrs,
bool local,
EntityMap* entityMap,
QNode** qNodeP,
OrionldGeoInfo* geoInfoP
)
{
//
// URI param validity check
//

if ((id == NULL) &&
(idPattern == NULL) &&
(type == NULL) &&
(geometry == NULL) &&
(attrs == NULL) &&
(q == NULL) &&
(local == false) &&
(orionldState.in.entityMap == NULL))
{
orionldError(OrionldBadRequestData,
"Too broad query",
"Need at least one of: entity-id, entity-type, geo-location, attribute-list, Q-filter, local=true, or an entity map",
400);

return false;
}


//
// If ONE or ZERO types in URI param 'type', the prepared array isn't used, just a simple char-pointer (named "type")
//
if (orionldState.in.typeList.items == 0) type = (char*) ".*";
else if (orionldState.in.typeList.items == 1) type = orionldState.in.typeList.array[0];

if (pCheckGeo(geoInfoP, orionldState.uriParams.geometry, orionldState.uriParams.georel, orionldState.uriParams.coordinates, orionldState.uriParams.geoproperty) == false)
return false;

QNode* qNode = NULL;
if (orionldState.uriParams.q != NULL)
{
qNode = qCheck(orionldState.uriParams.q);
if (qNode == NULL)
return false;
}

*qNodeP = qNode;

return true;
}
55 changes: 55 additions & 0 deletions src/lib/orionld/payloadCheck/pCheckQueryParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_
#define SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_

/*
*
* Copyright 2024 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
extern "C"
{
#include "kjson/KjNode.h" // KjNode
}

#include "orionld/types/TreeNode.h" // TreeNode



// -----------------------------------------------------------------------------
//
// pCheckQueryParams -
//
extern bool pCheckQueryParams
(
char* id,
char* type,
char* idPattern,
char* q,
char* geometry,
char* attrs,
bool local,
EntityMap* entityMap,
QNode** qNodeP,
OrionldGeoInfo* geoInfoP
);

#endif // SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_
1 change: 1 addition & 0 deletions src/lib/orionld/regMatch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SET (SOURCES
regMatchInformationItemForQuery.cpp
regMatchAttributesForQuery.cpp
regMatchEntityInfoForQuery.cpp
regMatchForEntitiesQuery.cpp
)

# Include directories
Expand Down
96 changes: 96 additions & 0 deletions src/lib/orionld/regMatch/regMatchForEntitiesQuery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright 2024 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#include "logMsg/logMsg.h" // LM_*

#include "orionld/types/DistOp.h" // DistOp
#include "orionld/types/RegistrationMode.h" // RegistrationMode
#include "orionld/types/DistOpType.h" // DistOpType
#include "orionld/types/StringArray.h" // StringArray
#include "orionld/types/RegCache.h" // RegCache
#include "orionld/types/RegCacheItem.h" // RegCacheItem
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/regMatch/regMatchOperation.h" // regMatchOperation
#include "orionld/regMatch/regMatchInformationArrayForQuery.h" // regMatchInformationArrayForQuery
#include "orionld/distOp/viaMatch.h" // viaMatch
#include "orionld/distOp/distOpListsMerge.h" // distOpListsMerge
#include "orionld/regMatch/regMatchForEntitiesQuery.h" // Own interface



// -----------------------------------------------------------------------------
//
// regMatchForEntitiesquery -
//
DistOp* regMatchForEntitiesQuery
(
RegistrationMode regMode,
DistOpType opType,
StringArray* idListP,
StringArray* typeListP,
StringArray* attrListP
)
{
DistOp* distOpList = NULL;

LM_W(("Looping over regCache of tenant '%s' (cache at %p, first reg at %p)", orionldState.tenantP->mongoDbName, orionldState.tenantP->regCache, orionldState.tenantP->regCache->regList));
for (RegCacheItem* regP = orionldState.tenantP->regCache->regList; regP != NULL; regP = regP->next)
{
LM_W(("In Loop"));
if ((regP->mode & regMode) == 0)
{
LM_T(LmtRegMatch, ("%s: No Reg Match due to RegistrationMode ('%s' vs '%s')", regP->regId, registrationModeToString(regP->mode), registrationModeToString(regMode)));
continue;
}

if (regMatchOperation(regP, opType) == false)
{
LM_T(LmtRegMatch, ("%s: No Reg Match due to Operation (operation == '%s')", regP->regId, distOpTypeToString(opType)));
continue;
}

// Loop detection
if (viaMatch(orionldState.in.via, regP->hostAlias) == true)
{
LM_T(LmtRegMatch, ("%s: No Reg Match due to Loop (Via)", regP->regId));
continue;
}

DistOp* distOpP = regMatchInformationArrayForQuery(regP, idListP, typeListP, attrListP);
if (distOpP == NULL)
{
LM_T(LmtRegMatch, ("%s: No Reg Match due to Information Array", regP->regId));
continue;
}

//
// Add distOpP to the linked list (distOpList)
//
LM_T(LmtRegMatch, ("%s: Reg Match !", regP->regId));

distOpList = distOpListsMerge(distOpList, distOpP);
}

return distOpList;
}
Loading

0 comments on commit 30767ef

Please sign in to comment.