Fiware 查询按关系筛选的实体时如何避免注册结果

Fiware 查询按关系筛选的实体时如何避免注册结果,fiware,fiware-orion,Fiware,Fiware Orion,我已经和docker一起部署了物联网堆栈。这些是用过的容器: fiware/orion:2.0.0 fiware/IoAgent json:1.8.0 [与问题无关的其他容器…] 查阅的文件: 步骤1:我已在Orion上下文代理上注册了以下实体: curl -X POST \ http://localhost:1026/v2/op/update/ \ -H 'Content-Type: application/json' \ -H 'fiware-service: tes

我已经和docker一起部署了物联网堆栈。这些是用过的容器:

  • fiware/orion:2.0.0
  • fiware/IoAgent json:1.8.0
[与问题无关的其他容器…]

查阅的文件:


步骤1:我已在Orion上下文代理上注册了以下实体:

curl -X POST \
  http://localhost:1026/v2/op/update/ \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: test' \
  -H 'fiware-servicepath: /' \
  -d '{
  "actionType": "append",
  "entities": [{
      "type": "Area",
      "id": "first:Area:001",
      "name": {
          "type": "Text",
          "value": "First area"
      }
  }, {
      "type": "Area",
      "id": "second:Area:002",
      "name": {
          "type": "Text",
          "value": "Second area"
      }
  }]
}'
curl -X POST \
http://localhost:4041/iot/devices \
-H 'Content-Type: application/json' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /' \
-d '{
    "devices": [{
        "device_id": "device001",
        "entity_name": "first:Area:001:IoTDevice:001",
        "entity_type": "IoTDevice",
        "transport": "HTTP",
        "protocol": "IoTA-JSON",
        "endpoint": "http://context-producer:3000/iot/iot-device/device001",
        "commands": [{
            "name": "ping",
            "type": "command"
        }],
        "attributes": [{
            "object_id": "c",
            "name": "count",
            "type": "Number"
        }],
        "static_attributes": [{
                "name": "refArea",
                "type": "Relationship",
                "value": "first:Area:001"
            },
            {
                "name": "name",
                "type": "Text",
                "value": "IoT Device 001"
            }
        ]
    }]
}'

步骤2:我已在物联网代理上注册了与区域相关的以下设备:区域:001

curl -X POST \
  http://localhost:1026/v2/op/update/ \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: test' \
  -H 'fiware-servicepath: /' \
  -d '{
  "actionType": "append",
  "entities": [{
      "type": "Area",
      "id": "first:Area:001",
      "name": {
          "type": "Text",
          "value": "First area"
      }
  }, {
      "type": "Area",
      "id": "second:Area:002",
      "name": {
          "type": "Text",
          "value": "Second area"
      }
  }]
}'
curl -X POST \
http://localhost:4041/iot/devices \
-H 'Content-Type: application/json' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /' \
-d '{
    "devices": [{
        "device_id": "device001",
        "entity_name": "first:Area:001:IoTDevice:001",
        "entity_type": "IoTDevice",
        "transport": "HTTP",
        "protocol": "IoTA-JSON",
        "endpoint": "http://context-producer:3000/iot/iot-device/device001",
        "commands": [{
            "name": "ping",
            "type": "command"
        }],
        "attributes": [{
            "object_id": "c",
            "name": "count",
            "type": "Number"
        }],
        "static_attributes": [{
                "name": "refArea",
                "type": "Relationship",
                "value": "first:Area:001"
            },
            {
                "name": "name",
                "type": "Text",
                "value": "IoT Device 001"
            }
        ]
    }]
}'

请求1:当您执行步骤2时,在Orion上下文代理上自动生成注册类型实体

curl -X GET \
http://localhost:1026/v2/registrations/ \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /'
结果:

[
    {
        "id": "5bd6dbb2bef7081490c96eb2",
        "dataProvided": {
            "entities": [
                {
                    "id": "first:Area:001:IoTDevice:001",
                    "type": "IoTDevice"
                }
            ],
            "attrs": [
                "ping"
            ]
        },
        "provider": {
            "http": {
                "url": "http://iotagent-json:4041"
            },
            "supportedForwardingMode": "all",
            "legacyForwarding": true
        },
        "status": "active"
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "TimeInstant": " ",
        "count": 0,
        "name": "IoT Device 001",
        "ping_info": " ",
        "ping_status": "UNKNOWN",
        "refArea": "first:Area:001",
        "ping": ""
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "ping": ""
    }
]

测试1:获取与区域相关的设备类型实体第一:区域:001

curl -X GET \
'http://localhost:1026/v2/entities?options=keyValues&q=refArea==first:Area:001' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /'
curl -X GET \
'http://localhost:1026/v2/entities?options=keyValues&q=refArea==second:Area:001' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /'
正常预期结果:

[
    {
        "id": "5bd6dbb2bef7081490c96eb2",
        "dataProvided": {
            "entities": [
                {
                    "id": "first:Area:001:IoTDevice:001",
                    "type": "IoTDevice"
                }
            ],
            "attrs": [
                "ping"
            ]
        },
        "provider": {
            "http": {
                "url": "http://iotagent-json:4041"
            },
            "supportedForwardingMode": "all",
            "legacyForwarding": true
        },
        "status": "active"
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "TimeInstant": " ",
        "count": 0,
        "name": "IoT Device 001",
        "ping_info": " ",
        "ping_status": "UNKNOWN",
        "refArea": "first:Area:001",
        "ping": ""
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "ping": ""
    }
]

测试2:获取与区域相关的物联网设备类型实体第二:区域:001

curl -X GET \
'http://localhost:1026/v2/entities?options=keyValues&q=refArea==first:Area:001' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /'
curl -X GET \
'http://localhost:1026/v2/entities?options=keyValues&q=refArea==second:Area:001' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /'
错误意外结果:

[
    {
        "id": "5bd6dbb2bef7081490c96eb2",
        "dataProvided": {
            "entities": [
                {
                    "id": "first:Area:001:IoTDevice:001",
                    "type": "IoTDevice"
                }
            ],
            "attrs": [
                "ping"
            ]
        },
        "provider": {
            "http": {
                "url": "http://iotagent-json:4041"
            },
            "supportedForwardingMode": "all",
            "legacyForwarding": true
        },
        "status": "active"
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "TimeInstant": " ",
        "count": 0,
        "name": "IoT Device 001",
        "ping_info": " ",
        "ping_status": "UNKNOWN",
        "refArea": "first:Area:001",
        "ping": ""
    }
]
[
    {
        "id": "first:Area:001:IoTDevice:001",
        "type": "IoTDevice",
        "ping": ""
    }
]
预期结果为[]或空,但查询返回的结果似乎来自注册类型
实体。仅当插入具有command类型属性的设备时,才会发生这种情况。例如,ping命令

那么,如何避免这种情况呢?

根据:

查询转发不支持查询筛选(例如
GET/v2/entities?q=temperature>40
)。首先,Orion在转发给CPr的
POST/v1/queryContext
操作中不包括过滤器。其次,Orion在将CPr结果反馈给客户之前不会过滤这些结果。已创建与此限制相对应的问题:

这可能是问题的原因


虽然问题已经解决,但解决方法是在客户端进行筛选(在您的情况下,通过
refrea==second:Area:001
)。

谢谢,@fgalan,我通过简单地检查每个结果是否具有“name”属性,减少了此问题的影响。我会注意一个解决办法。