当使用类型创建实体,然后创建具有相同id但空类型的实体时,contextbroker响应正常,但不创建实体。
但是如果创建的顺序相反,首先是具有空id的实体,然后是具有类型的实体,上下文代理响应为ok并且列出了实体。
#/bin/bash
HOST=localhost
SERVICE=Service123
SUBSERVICE=/Subservice123
#Create an entity with id and type
CREATE=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
-d '
{
"id": "firstID",
"type": "firstType",
"attributes": []
}')
#List the entities
LIST=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
)
echo $CREATE
echo "**********************"
echo $LIST
#Create an entity with the same ID but different type
CREATE=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
-d '
{
"id": "firstID",
"type": "",
"attributes": []
}')
#List the entityies
LIST=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
)
echo
echo "Second Iteration"
echo
echo $CREATE
echo "**********************"
echo $LIST
#/bin/bash
HOST=localhost
SERVICE=Service1234
SUBSERVICE=/Subservice1234
#Create an entity with id and type
CREATE=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
-d '
{
"id": "firstID",
"type": "",
"attributes": []
}')
#List the entities
LIST=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
)
echo $CREATE
echo "**********************"
echo $LIST
#Create an entity with the same ID but different type
CREATE=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
-d '
{
"id": "firstID",
"type": "fistType",
"attributes": []
}')
#List the entityies
LIST=$(\
curl http://$HOST:1026/v1/contextEntities \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: $SERVICE" \
-H "Fiware-ServicePath: $SUBSERVICE" \
)
echo
echo "Second Iteration"
echo
echo $CREATE
echo "**********************"
echo $LIST
答案 0 :(得分:0)
虽然看起来很奇怪,但脚本1根据CB定义的功能正常工作。 type =""的含义在第二个POST中,不会导致id为firstID且没有类型"的实体。但是"任何具有id firstID的实体,无论其类型如何" (见context broker manual)。因此,假设已经有一个实体匹配"任何具有id firstID的实体,无论其类型如何" (即在第一个POST中创建的,具有id firstID并且类型为firstType)请求不会被解释为创建而是作为更新(来自Orion用户手册:"当前Orion Context Broker版本解释APPEND [POST on on如果实体已存在"),则该URL等于APPEND updateContext]为UPDATE。
有一种含义"实体没有类型",使用!exists过滤器。如果更改script1
中的以下第35行curl http://$HOST:1026/v1/contextEntities \
这个
curl http://$HOST:1026/v1/contextEntities?!exist=entity::type \
您将在最后创建2个实体(一个具有类型,另一个没有它)。