FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
50 stars 43 forks source link

Cannot obtain entity data from data provider by type #1705

Open son-phamngoc opened 1 day ago

son-phamngoc commented 1 day ago

Hello, I have a problem that need your support.

I have 2 Orion-LD instances: 1st works as context broker, and 2nd works as data provider. Firstly, I created an entity urn:ngsi-ld:Building:office001 at data provider.

curl -X POST 'http://localhost:21026/ngsi-ld/v1/entities/' \
-H 'Content-Type: application/ld+json' \
--data-raw '{
    "id": "urn:ngsi-ld:Building:office001",
    "type": "Building",
    "category": {
        "type": "Property",
        "value": "office"
    },
    "address": {
        "type": "Property",
        "value": {
            "streetAddress": "519 Orion street",
            "addressRegion": "Region1",
            "addressLocality": "Local1",
            "postalCode": "99999"
        }
    },
    "name": {
        "type": "Property",
        "value": "Office 1"
    },
    "@context": [
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld"
    ]
}'

Next, I created a registration that data provider can provide entity type "Building" for context broker.

curl -X POST 'http://localhost:1026/ngsi-ld/v1/csourceRegistrations' \
-H 'Content-Type: application/json' \
-H '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"' \
-d ' {
    "id": "urn:ngsi-ld:ContextSourceRegistration:reg001",
    "type": "ContextSourceRegistration",
    "information": [
        {
            "entities": [
                {
                    "type": "Building"
                }
            ]
        }
    ],
    "endpoint": "http://orionld-prvd2:1026",
    "mode": "exclusive",
    "operations": [
        "federationOps"
    ]
}'

After that, I queried to context broker to obtain Building entities.

curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/' -H 'Accept: application/ld+json' \
-H '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"' \
-d 'type=Building' | jq .

I expected to obtain entity urn:ngsi-ld:Building:office001 but it gave me an empty result.

If I register a specific entity provided by data provider, I can obtain that entity by id.

curl -X POST 'http://localhost:1026/ngsi-ld/v1/csourceRegistrations' \
-H 'Content-Type: application/json' \
-H '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"' \
-d ' {
    "id": "urn:ngsi-ld:ContextSourceRegistration:reg002",
    "type": "ContextSourceRegistration",
    "information": [
        {
            "entities": [
                {
                    "type": "Building", "id": "urn:ngsi-ld:Building:office001"
                }
            ]
        }
    ],
    "endpoint": "http://orionld-prvd2:1026",
    "mode": "exclusive",
    "operations": [
        "federationOps"
    ]
}'

I also can get data by registering entity with propertyNames.

curl -X POST 'http://localhost:1026/ngsi-ld/v1/csourceRegistrations' \
-H 'Content-Type: application/json' \
-H '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"' \
-d ' {
    "id": "urn:ngsi-ld:ContextSourceRegistration:reg003",
    "type": "ContextSourceRegistration",
    "information": [
        {
            "entities": [
                {
                    "type": "Building",
                    "id": "urn:ngsi-ld:Building:office001"
                }
            ],
            "propertyNames": [
                "name"
            ]
        }
    ],
    "endpoint": "http://orionld-prvd2:1026",
    "mode": "inclusive",
    "operations": [
        "federationOps"
    ]
}'

The problem only occurs with registration and querying by entity type.

I tried with Scorpio and it worked well with registration and querying by entity type. I also checked this issue https://github.com/FIWARE/context.Orion-LD/issues/1585 and saw that Orion-LD worked with that case. So, I think this is a bug of Orion-LD. Could you help me to confirm it? Please tell me if I did any wrong step.

Many thanks in advance.

kzangeli commented 22 hours ago

Hello there. My guess is that this registration failed:

{
    "id": "urn:ngsi-ld:ContextSourceRegistration:reg001",
    "type": "ContextSourceRegistration",
    "information": [
        {
            "entities": [
                {
                    "type": "Building"
                }
            ]
        }
    ],
    "endpoint": "http://orionld-prvd2:1026",
    "mode": "exclusive",
    "operations": [
        "federationOps"
    ]
}

For Exclusive registrations you must specify the entity id AND attributes (entity type is always mandatory). If not, it's a too wide exclusive registration and that is not allowed. Both Scorpio and Orion-LD are supposed to give an error for that. 400 Bad Request and then more info in "title" and "detail" in the payload response body.

Make sure you check the result of the registration creation attempt. If no error is provoked, that would be a bug.

Thanks for reporting!