在FIWARE Orion Context Broker中获取属性时发生冲突错误

时间:2018-12-10 17:38:33

标签: spring-boot attributes fiware fiware-orion id

注册了上下文提供程序后,我无法获得任何实体属性。我不断收到相同的409冲突错误。如何防止两个具有相同ID的对象并将它们合并为一个?


设置

按照以下命令,我已经完成了整个Orion Context Broker的所有设置和运行:

docker pull mongo:3.6
docker pull fiware/orion:2.0.0
docker network create fiware_default

docker run -d --name=mongo-db --network=fiware_default \
  --expose=27017 mongo:3.6 --bind_ip_all --smallfiles
docker run -d --name fiware-orion -h orion --network=fiware_default \
  -p 1026:1026  fiware/orion:2.0.0 -dbhost mongo-db

实体

我添加了一个带有curl的汽车实体:

 curl -iX POST \
  'http://localhost:1026/v2/entities' \
  -H 'Content-Type: application/json' \
  -d '
{
    "id": "urn:ngsi-ld:Car:001",
    "type": "Car",
    "brandName": {
        "type": "Property",
        "value": "Mercedes"
    },
    "location": {
        "type": "geo:json",
        "value": {
             "type": "Point",
             "coordinates": [0.00, 0.00]
        }
    },
    "name": {
        "type": "Text",
        "value": "MyCar"
    }
}'

此外,我还注册了上下文提供程序:

 curl -iX POST \
  'http://localhost:1026/v2/registrations' \
  -H 'Content-Type: application/json' \
  -d '
{
  "description": "Temperature",
  "dataProvided": {
    "entities": [
      {
        "id": "urn:ngsi-ld:Car:001",
        "type": "Car"
      }
    ],
    "attrs": [
      "temperature"
    ]
  },
  "provider": {
    "http": {
      "url": "http://192.168.xxx.xxx:8080/api/cars/temperature/1"
    },
     "legacyForwarding": true
  }
}'

上下文提供者

我在http://192.168.xxx.xxx:8080/api/cars/temperature/1/queryContext本地公开了Context Provider(由用Java 10编写的SpringBoot应用程序公开)。 JSON数据(以html正文返回)为NSGI v1格式,如下所示:

   {
  "contextResponses": [
    {
      "contextElement": {
        "attributes": [
          {
            "name": "temperature",
            "type": "float",
            "value": "-10"
          }
        ],
        "id": "urn:nsgi-ld:Car:001",
        "isPattern": "false",
        "type": "Car"
      },
      "statusCode": {
        "code": "200",
        "reasonPhrase": "OK"
      }
    }
  ]
}

问题

当我进行此查询时:

curl GET 'http://localhost:1026/v2/entities?type=Car&options=keyValues'

我收到具有相同ID的对象列表:

[{"id":"urn:ngsi-ld:Car:001","type":"Car","brandName":"Mercedes","location":,"name":"MyCar"},{"id":"urn:nsgi-ld:Car:001","type":"Car","temperature":"-10"}]

1)当我尝试获取位置属性时:

curl -iX GET 'http://localhost:1026/v2/entities/urn:ngsi-ld:Car:001/attrs/location/value'

我得到回应:

HTTP/1.1 409 Conflict
Connection: Keep-Alive
Content-Length: 98
Content-Type: application/json
Fiware-Correlator: 509119fa-fd27-11e8-922c-0242ac130003
Date: Tue, 11 Dec 2018 09:29:53 GMT 

 {
        "error": "TooManyResults",
        "description": "More than one matching entity. Please refine your query"
    }

2)我注意到我可以通过ID删除实体:

curl -iX DELETE 'http://localhost:1026/v2/entities/urn:ngsi-ld:Car:001'

3)然后,我可以获取不存在的物体的温度:

curl -iX GET 'http://localhost:1026/v2/entities/urn:ngsi-ld:Car:001/attrs/temperature/value'

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 5
Content-Type: text/plain
Fiware-Correlator: 0de19b36-fd2a-11e8-8abe-0242ac130003
Date: Tue, 11 Dec 2018 09:49:29 GMT

"-10"

我希望能够从实体(urn:ngsi-ld:Car:001)的属性(位置)和上下文提供程序(温度)中获取属性,但是看起来该实体已经莫名其妙地分成了两个具有相同ID(和相同类型)的实体。

我应该怎么做才能防止这种id冲突?注册上下文提供者时,如何防止两个对象具有相同的ID?

0 个答案:

没有答案