diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 362ae1327c..08d73fc1d6 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -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" diff --git a/src/lib/orionld/forwarding/regMatchInformationArray.cpp b/src/lib/orionld/forwarding/regMatchInformationArray.cpp index f62d89df14..5a0996024c 100644 --- a/src/lib/orionld/forwarding/regMatchInformationArray.cpp +++ b/src/lib/orionld/forwarding/regMatchInformationArray.cpp @@ -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; diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_forwarding_issue_1456.test b/test/functionalTest/cases/0000_ngsild/ngsild_forwarding_issue_1456.test new file mode 100644 index 0000000000..3a751dc52c --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_forwarding_issue_1456.test @@ -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: ; 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: ; 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: ; 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 diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_new_forward_http_headers.test b/test/functionalTest/cases/0000_ngsild/ngsild_new_forward_http_headers.test index fd003c5b93..8e4c1624f4 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_new_forward_http_headers.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_new_forward_http_headers.test @@ -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 @@ -195,7 +195,7 @@ Link: