telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 264 forks source link

Error getting an entity that has an attribute of type StructuredValue #3360

Closed perezmlal closed 5 years ago

perezmlal commented 5 years ago

STEP 1: Update or append entity with an attribute of type StructuredValue

curl --request POST \
  --url http://localhost:1026/v2/entities/test_entity001/attrs \
  --header 'Content-Type: application/json' \
  --header 'fiware-service: default' \
  --header 'fiware-servicepath: /' \
  --data '{"example_attr":{"type":"StructuredValue","value":{"exampleField":"exampleValue"}}}

WHEN: Retrieve an entity by ID test_entity001 or List entities

curl --request GET \
  --url http://localhost:1026/v2/entities/test_entity001 \
  --header 'fiware-service: default' \
  --header 'fiware-servicepath: /'

THEN: The response does not contains the value for the attribute example_attr

{
    "id": "test_entity001",
    "type": "TestType",
    "TimeInstant": {
        "type": "ISO8601",
        "value": "2018-11-28T16:59:25.00Z",
        "metadata": {}
    },
    "example_attr": {
        "type": "StructuredValue",
        "metadata": {}
    }
}

UPDATE:

I've deployed the iot stack with docker. These are the used containers:

[other containers not involved in the issue ...]

Documentation consulted: FIWARE-NGSI v2 Specification


GIVEN: A simple entity

{
    "id": "test_entity001",
    "type": "TestType",
    "TimeInstant": {
        "type": "ISO8601",
        "value": "2018-11-28T16:59:25.00Z",
        "metadata": {}
    }
}

WHEN: update or append that entity with an attribute of type StructuredValue

curl --request POST \
  --url http://localhost:1026/v2/entities/test_entity001/attrs \
  --header 'Content-Type: application/json' \
  --header 'fiware-service: default' \
  --header 'fiware-servicepath: /' \
  --data '{"example_attr":{"type":"StructuredValue","value":{"exampleField":"exampleValue"}}}

THEN: Retrieve an entity by ID test_entity001 or List entities

curl --request GET \
  --url http://localhost:1026/v2/entities/test_entity001 \
  --header 'fiware-service: default' \
  --header 'fiware-servicepath: /'

AND: The response does not contains the value for the attribute example_attr

{
    "id": "test_entity001",
    "type": "TestType",
    "TimeInstant": {
        "type": "ISO8601",
        "value": "2018-11-28T16:59:25.00Z",
        "metadata": {}
    },
    "example_attr": {
        "type": "StructuredValue",
        "metadata": {}
    }
}
fgalan commented 5 years ago

I have conducted a similar test.

Create the entity with:

$ curl --request POST \
   --url http://localhost:1026/v2/entities \
   --header 'Content-Type: application/json' \
   --data '{"id": "test_entity001", "type": "T", "example_attr":{"type":"StructuredValue","value":{"exampleField":"whatever"}}}'

Update the entity with:

$ curl --request POST \
   --url http://localhost:1026/v2/entities/test_entity001/attrs \
   --header 'Content-Type: application/json' \
   --data '{"example_attr":{"type":"StructuredValue","value":{"exampleField":"exampleValue"}}}'

Get the entity:

$ curl --request GET \
   --url http://localhost:1026/v2/entities/test_entity001

Result is correct:

{"id":"test_entity001","type":"T","example_attr":{"type":"StructuredValue","value":{"exampleField":"exampleValue"},"metadata":{}}}

Note I haven't include fiware-service and fiware-servicepath to make requests simpler, but I will conduct the same tests using them. In the meanwhile, could you conduct a test like mine (i.e. without headers and running CB without -multiservice) in order to check if you get the same result?

In addition it would be useful to know:

fgalan commented 5 years ago

The exact Orion version you ares using (contextBroker --version provides that information)

For the record, mine is: 2.0.0-next (git version: 0d4e4bedf1ac59834087614514ad2bbce7893e96)

perezmlal commented 5 years ago

Thanks @fgalan I will check if it works running CB without -multiservice.

Currently i run a Orion with the following docker-compose


version: "3.7"
services:
orion:
    image: fiware/orion:2.0.0
    container_name: orion
    restart: always
    depends_on:
      - mongo-orion
    ports:
      - "30000:1026"
    command: -corsOrigin __ALL -corsMaxAge 600 -dbhost mongo-orion
perezmlal commented 5 years ago

I confirm that the problem appears when you use the iot-agent service to create a device with commands array like:

{
    "devices": [
        {
            "device_id": "sensor002",
            "entity_name": "sensor002",
            "entity_type": "TestType",
            "transport": "HTTP",
            "protocol": "IoTA-JSON",
            "endpoint": "http://simulator:3000/iot/test-type/sensor002",
            "commands": [
                {
                    "name": "ping",
                    "type": "command"
                }
            ],
            "attributes": [
                {
                    "object_id": "status",
                    "name": "status",
                    "type": "Text"
                }
            ],
            "static_attributes": [
                {
                    "name": "name",
                    "type": "Text",
                    "value": "Sensor 001"
                }
            ]
        }
    ]
}

And then when you add a new attribute of type StructuredValue and you request its value. The value for that attribute is not present.

So I am closing this issue and create a new one with the detailed spec.

fgalan commented 5 years ago

Ok. Maybe it would be useful to add the link to the new issue here, for traceability.

perezmlal commented 5 years ago

Ok. Maybe it would be useful to add the link to the new issue here, for traceability.

https://github.com/telefonicaid/fiware-orion/issues/3363