Skip to content

Commit

Permalink
Merge pull request #1457 from FIWARE/issue/1456
Browse files Browse the repository at this point in the history
Fixed issue #1456
  • Loading branch information
kzangeli authored Oct 24, 2023
2 parents a6db0e0 + dd95063 commit 4aaf82b
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Fixed issues:
* #280 - Highly experimental feature for subscriptions: allowing a wildcard as value for entity type, to not filter on entity type
* #280 - Implemented Periodic Notifications (subscriptions with a 'timeInterval')
* #280 - New CLI (hidden) for extra field in notifications (trigger: "VERB URL PATH"): -triggerOperation
* #1456 - Bug fix - entity id+type duplicated in forwarded request of "Create Entity"
16 changes: 11 additions & 5 deletions src/lib/orionld/forwarding/regMatchInformationArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ DistOp* regMatchInformationArray
// If we get this far, then it's a match
if (operation == DoCreateEntity)
{
KjNode* entityIdP = kjString(orionldState.kjsonP, "id", entityId);
KjNode* entityTypeP = kjString(orionldState.kjsonP, "type", entityType);
if (kjLookup(attrUnion, "id") == NULL)
{
KjNode* entityIdP = kjString(orionldState.kjsonP, "id", entityId);
kjChildAdd(attrUnion, entityIdP);
}

kjChildAdd(attrUnion, entityIdP);
kjChildAdd(attrUnion, entityTypeP);
if (kjLookup(attrUnion, "type") == NULL)
{
KjNode* entityTypeP = kjString(orionldState.kjsonP, "type", entityType);
kjChildAdd(attrUnion, entityTypeP);
}
}

DistOp* distOpP = (DistOp*) kaAlloc(&orionldState.kalloc, sizeof(DistOp));
DistOp* distOpP = (DistOp*) kaAlloc(&orionldState.kalloc, sizeof(DistOp));

distOpP->regP = regP;
distOpP->requestBody = attrUnion;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
# Copyright 2023 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

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Replication of an entity

--SHELL-INIT--
dbInit CB
dbInit CP1
orionldStart CB -experimental -forwarding -t 70-79,231
orionldStart CP1 -experimental

--SHELL--
#
# 01. Register entities of type IE in CB, for replication in CP1
# 02. Create an entity E1, of type IE - have it created locally AND in CP1
# 03. GET E1 in CB, with local=true
# 04. GET E1 in CP1, with local=true
# 05. PATCH urn:ngsi-ld:IE:001/totalRAM in CB
# 06. GET the entity E1 from CP1 - see totalRAM changed
#

echo "01. Register entities of type IE in CB, for replication in CP1"
echo "=============================================================="
payload='{
"id": "urn:R1",
"type": "ContextSourceRegistration",
"information": [
{
"entities": [
{
"type": "IE"
}
]
}
],
"endpoint": "http://localhost:'$CP1_PORT'",
"mode": "inclusive",
"operations": [ "updateOps", "redirectionOps" ]
}'
orionCurl --url /ngsi-ld/v1/csourceRegistrations --payload "$payload"
echo
echo



echo "02. Create an entity E1, of type IE - have it created locally AND in CP1"
echo "========================================================================"
payload='{
"id": "urn:ngsi-ld:IE:001",
"type": "IE",
"domain": {
"type": "Relationship",
"object": "urn:ngsi-ld:Domain:01"
},
"totalRAM": {
"type": "Property",
"value": 32
},
"cPUCores": {
"type": "Property",
"value": 4
},
"avgPowerConsumption": {
"type": "Property",
"value": 50
},
"realTimeCapable": {
"type": "Property",
"value": true
},
"currentRAM": {
"type": "Property",
"value": 45
},
"currentCPUUsage": {
"type": "Property",
"value": 2
},
"currentPowerConsumption": {
"type": "Property",
"value": 9
}
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload"
echo
echo


echo "03. GET E1 in CB, with local=true"
echo "================================="
orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:IE:001?local=true
echo
echo


echo "04. GET E1 in CP1, with local=true"
echo "=================================="
orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:IE:001?local=true --port $CP1_PORT
echo
echo


echo "05. PATCH urn:ngsi-ld:IE:001/totalRAM in CB"
echo "==========================================="
payload='{
"value": 5,
"origin": "Changed in CB"
}'
orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:IE:001/attrs/totalRAM --payload "$payload" -X PATCH
echo
echo


echo "06. GET the entity E1 from CP1 - see totalRAM changed"
echo "====================================================="
orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:IE:001 --port $CP1_PORT
echo
echo


--REGEXPECT--
01. Register entities of type IE in CB, for replication in CP1
==============================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/csourceRegistrations/urn:R1



02. Create an entity E1, of type IE - have it created locally AND in CP1
========================================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:ngsi-ld:IE:001



03. GET E1 in CB, with local=true
=================================
HTTP/1.1 200 OK
Content-Length: 440
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"avgPowerConsumption": {
"type": "Property",
"value": 50
},
"cPUCores": {
"type": "Property",
"value": 4
},
"currentCPUUsage": {
"type": "Property",
"value": 2
},
"currentPowerConsumption": {
"type": "Property",
"value": 9
},
"currentRAM": {
"type": "Property",
"value": 45
},
"domain": {
"object": "urn:ngsi-ld:Domain:01",
"type": "Relationship"
},
"id": "urn:ngsi-ld:IE:001",
"realTimeCapable": {
"type": "Property",
"value": true
},
"totalRAM": {
"type": "Property",
"value": 32
},
"type": "IE"
}


04. GET E1 in CP1, with local=true
==================================
HTTP/1.1 200 OK
Content-Length: 440
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"avgPowerConsumption": {
"type": "Property",
"value": 50
},
"cPUCores": {
"type": "Property",
"value": 4
},
"currentCPUUsage": {
"type": "Property",
"value": 2
},
"currentPowerConsumption": {
"type": "Property",
"value": 9
},
"currentRAM": {
"type": "Property",
"value": 45
},
"domain": {
"object": "urn:ngsi-ld:Domain:01",
"type": "Relationship"
},
"id": "urn:ngsi-ld:IE:001",
"realTimeCapable": {
"type": "Property",
"value": true
},
"totalRAM": {
"type": "Property",
"value": 32
},
"type": "IE"
}


05. PATCH urn:ngsi-ld:IE:001/totalRAM in CB
===========================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



06. GET the entity E1 from CP1 - see totalRAM changed
=====================================================
HTTP/1.1 200 OK
Content-Length: 492
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"avgPowerConsumption": {
"type": "Property",
"value": 50
},
"cPUCores": {
"type": "Property",
"value": 4
},
"currentCPUUsage": {
"type": "Property",
"value": 2
},
"currentPowerConsumption": {
"type": "Property",
"value": 9
},
"currentRAM": {
"type": "Property",
"value": 45
},
"domain": {
"object": "urn:ngsi-ld:Domain:01",
"type": "Relationship"
},
"id": "urn:ngsi-ld:IE:001",
"realTimeCapable": {
"type": "Property",
"value": true
},
"totalRAM": {
"origin": {
"type": "Property",
"value": "Changed in CB"
},
"type": "Property",
"value": 5
},
"type": "IE"
}


--TEARDOWN--
brokerStop CB
brokerStop CP1
dbDrop CB
dbDrop CP1
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Location: /ngsi-ld/v1/entities/urn:E1
03. Dump the accumulator to see all the HTTP headers of the forwarded request
=============================================================================
POST http://REGEX(.*)/ngsi-ld/v1/entities
Content-Length: 51
Content-Length: 26
User-Agent: orionld/REGEX(.*)
Host: REGEX(.*)
Accept: application/json
Expand Down Expand Up @@ -195,7 +195,7 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
06. Dump the accumulator to see all the HTTP headers of the forwarded request
=============================================================================
POST http://REGEX(.*)/ngsi-ld/v1/entities
Content-Length: 87
Content-Length: 62
User-Agent: orionld/REGEX(.*)
Host: REGEX(.*)
Accept: application/ld+json
Expand Down

0 comments on commit 4aaf82b

Please sign in to comment.