From cd6dea2cbab604fcc699e45678929516de203f0d Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Tue, 22 Oct 2024 10:00:11 +0200 Subject: [PATCH 1/3] Not fixed but slightly improved the error of issue #1698 --- CHANGES_NEXT_RELEASE | 2 +- src/lib/orionld/db/dbEntityTypesGet.cpp | 13 + .../orionld/service/orionldServiceInit.cpp | 2 + .../cases/0000_ngsild/ngsild_issue_1698.test | 261 ++++++++++++++++++ 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 6fd7bd35e7..587f939752 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,5 +1,5 @@ ## Fixed Issues: - #0000: nada + #1698: Not fixed, but making it almost usable. Real fix coming soon. Needs a complete rewrite. ## New Features: * Support for ... diff --git a/src/lib/orionld/db/dbEntityTypesGet.cpp b/src/lib/orionld/db/dbEntityTypesGet.cpp index 7078e53597..303879613a 100644 --- a/src/lib/orionld/db/dbEntityTypesGet.cpp +++ b/src/lib/orionld/db/dbEntityTypesGet.cpp @@ -337,6 +337,19 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details) } } + // + // See issue #1698 + // I'd really need to rewrite the whole function. + // As cfreyth correctly comments, the pagination limit/offet are about entities (as mongocEntitiesGet is used) + // and NOT entity types. + // + // As a quick and dirty fix: + // * Allow limit/offset + // * Set default limit to 1000 (unless set to anything else by the user) + // + if (orionldState.uriParams.limit == 20) + orionldState.uriParams.limit = 1000; // Default limit of 20 is changed to 1000 + // // GET local types - i.e. from the "entities" collection // diff --git a/src/lib/orionld/service/orionldServiceInit.cpp b/src/lib/orionld/service/orionldServiceInit.cpp index 2929d7430d..5c899979c6 100644 --- a/src/lib/orionld/service/orionldServiceInit.cpp +++ b/src/lib/orionld/service/orionldServiceInit.cpp @@ -444,6 +444,8 @@ static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceS } else if (serviceP->serviceRoutine == orionldGetEntityTypes) { + serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT; + serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET; serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS; } else if (serviceP->serviceRoutine == orionldGetEntityType) diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test b/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test new file mode 100644 index 0000000000..4f28a29ab6 --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test @@ -0,0 +1,261 @@ +# 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 + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Entity pagination + +--SHELL-INIT-- +dbInit CB +orionldStart CB -experimental + +--SHELL-- + +# +# 01. Create 100 entities of types T001-T100 +# 02. GET the first 10 types +# 03. GET the next 10 types +# 04. GET all (1000 is the pagination limit for entities in GET /types) +# + +echo "01. Create 100 entities of types T001-T100" +echo "==========================================" +typeset -i eNo +eNo=1 + +while [ $eNo -le 100 ] +do + eId=$(printf "urn:E%03d" $eNo) + eType=$(printf "T%03d" $eNo) + eNo=$eNo+1 + + payload='{ + "id": "'$eId'", + "type": "'$eType'", + "A1": { + "type": "Property", + "value": "E'$eNo':A1" + } + }' + orionCurl --url /ngsi-ld/v1/entities --payload "$payload" | grep 'Location:' +done | wc +echo +echo + + +echo "02. GET the first 10 types" +echo "==========================" +orionCurl --url /ngsi-ld/v1/types?limit=10 +echo +echo + + +echo "03. GET the next 10 types" +echo "=========================" +orionCurl --url "/ngsi-ld/v1/types?limit=10&offset=10" +echo +echo + + +echo "04. GET all (1000 is the pagination limit for entities in GET /types)" +echo "=====================================================================" +orionCurl --url /ngsi-ld/v1/types +echo +echo + + +--REGEXPECT-- +01. Create 100 entities of types T001-T100 +========================================== + 100 200 4000 + + +02. GET the first 10 types +========================== +HTTP/1.1 200 OK +Content-Length: 179 +Content-Type: application/json +Date: REGEX(.*) +Link: Date: Tue, 22 Oct 2024 17:15:49 +0200 Subject: [PATCH 2/3] Copying two libs from build stage --- docker/Dockerfile-ubi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/Dockerfile-ubi b/docker/Dockerfile-ubi index b422ee5105..947bcd4eaf 100644 --- a/docker/Dockerfile-ubi +++ b/docker/Dockerfile-ubi @@ -29,6 +29,10 @@ COPY --from=build-stage /usr/bin/orionld /usr/bin COPY --from=build-stage /usr/local/lib/* /usr/lib64/ COPY --from=build-stage /usr/local/lib64/* /usr/lib64/ COPY --from=build-stage /opt/orion/ldcontexts/ /opt/orion/ldcontexts/ +COPY --from=build-stage /usr/lib64/libtinyxml2.so.6 /usr/lib64/ +COPY --from=build-stage /usr/lib64/libtinyxml2.so /usr/lib64/ +COPY --from=build-stage /usr/lib64/libyaml-cpp.so.0.6 /usr/lib64/ +COPY --from=build-stage /usr/lib64/libyaml-cpp.so /usr/lib64/ COPY docker/other-places.repo /etc/yum.repos.d/ COPY docker/ubi.repo /etc/yum.repos.d/ From a8bbc3675043d86b05db672995577196e95468f2 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Tue, 22 Oct 2024 17:20:14 +0200 Subject: [PATCH 3/3] Dockerfile-ubi authors --- docker/Dockerfile-ubi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile-ubi b/docker/Dockerfile-ubi index 947bcd4eaf..e3f39d4544 100644 --- a/docker/Dockerfile-ubi +++ b/docker/Dockerfile-ubi @@ -14,9 +14,9 @@ RUN /tmp/build.sh -b FROM registry.access.redhat.com/ubi8/ubi -LABEL authors="Ken Zangelin - ken.zangelin@fiware.org, Stefan Wiedemann - stefan.wiedemann@fiware.org" \ +LABEL authors="Ken Zangelin - ken.zangelin@fiware.org, Jose Ignacio Carretero - joseignacio.carretero@fiware.org" \ description="Orion-LD is a Context Broker which supports both the NGSI-LD and the NGSI-v2 APIs." \ - maintainer="ken.zangelin@fiware.org,stefan.wiedemann@fiware.org" \ + maintainer="ken.zangelin@fiware.org,joseignacio.carretero@fiware.org@fiware.org" \ vendor="FIWARE Foundation e.V." \ documentation="https://github.com/FIWARE/context.Orion-LD/tree/develop/doc" \ name="FIWARE Orion-LD" \