1
votes

We found an issue while testing the tourguide application https://github.com/Fiware/tutorials.TourGuide-App.

If we try to get an attribute value from a restaurant:

curl  <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide'

we get the attribute value as expected:

{"reviewCount":1,"ratingValue":3}

But if we try to update the value following the instructions for update an attribute value http://fiware.github.io/context.Orion/api/v2/:

curl -v -X PUT <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value?Type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"reviewCount": 1,"ratingValue": 10}'

we get a 404 error.

If we follows the detailed instructions for update an attribute a JSON in the API cookbook http://fiware.github.io/context.Orion/api/v2/cookbook/

curl -v -X PUT <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"value": {"reviewCount": 1,"ratingValue": 10}}'

We also get a 404 error.

Steps to replicate:

Information about orion version:

<orion>
   <version>0.28.0</version>
    <uptime>0 d, 1 h, 12 m, 25 s</uptime>
    <git_hash>aaf8020a5de680b6d7e0c00c70cf425bcc4f39c8</git_hash>
    <compile_time>Mon Mar 21 13:20:37 UTC 2016</compile_time>
    <compiled_by>root</compiled_by>
    <compiled_in>838a42ae8431</compiled_in>
</orion>

Updated

In order to use the last version of Orion CB available at Docker, we have updated the docker-compose of the tourguide application and we get the same errors.

This is the information about the last version:

{
  "orion" : {
  "version" : "1.0.0-next",
  "uptime" : "0 d, 0 h, 8 m, 20 s",
  "git_hash" : "9a35f04739a4236711bdf5b48152eaa21c3377b2",
  "compile_time" : "Wed Apr 20 11:41:57 UTC 2016",
  "compiled_by" : "root",
  "compiled_in" : "838a42ae8431"
 }
}

We have executed the Context Broker in debug mode, and if we perform:

curl -v -X PUT orion:1026/v2/Entities/Elizalde/attrs/aggregateRating/value?type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:HuUUHhQ6Qh8myI3o3uI2rYeOIK1Ym1' --header 'Fiware-service: tourguide' -d '{"reviewCount": 1,"ratingValue": 10}'

we get this output:

orion_1        | DEBUG@07:33:12  rest.cpp[955]: 
orion_1        | DEBUG@07:33:12  rest.cpp[956]: --------------------- Serving request PUT /v2/Entities/Elizalde/attrs/aggregateRating/value -----------------
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   User-Agent: curl/7.35.0
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Host: orion:1026
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Accept: */*
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Content-Type: application/json
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   x-auth-token: HuUUHhQ6Qh8myI3o3uI2rYeOIK1Ym1
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Fiware-service: tourguide
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Content-Length: 36
orion_1        | DEBUG@07:33:12  sem.cpp[276]: transactionIdSet taking the 'trans' semaphore for 'changing the transaction id'
orion_1        | DEBUG@07:33:12  sem.cpp[297]: transactionIdSet has the 'trans' semaphore
orion_1        | DEBUG@07:33:12  sem.cpp[373]: transactionIdSet gives the 'trans' semaphore for 'changing the transaction id'
orion_1        | INFO@07:33:12  logMsg.h[1805]: Starting transaction from 172.17.0.1:48854/v2/Entities/Elizalde/attrs/aggregateRating/value
orion_1        | DEBUG@07:33:12  rest.cpp[225]: URI parameter:   type: Restaurant
orion_1        | DEBUG@07:33:12  rest.cpp[1059]: Got 36 of payload of 36 bytes
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  RestService.cpp[411]: Parsing payload for URL '/v2/Entities/Elizalde/attrs/aggregateRating/value', method 'PUT', service vector index: 12
orion_1        | DEBUG@07:33:12  RestService.cpp[413]: Parsing payload '{"reviewCount": 1,"ratingValue": 10}'
orion_1        | DEBUG@07:33:12  RestService.cpp[101]: parsing data for service 'EntityAttributeValueRequest'. Method: 'PUT'
orion_1        | DEBUG@07:33:12  RestService.cpp[102]: outFormat: JSON
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001720
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001800
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001910
orion_1        | DEBUG@07:33:12  RestService.cpp[127]: result: 'OK'
orion_1        | DEBUG@07:33:12  RestService.cpp[128]: outFormat: JSON
orion_1        | DEBUG@07:33:12  RestService.cpp[415]: payloadParse returns 'OK'
orion_1        | DEBUG@07:33:12  RestService.cpp[437]: Treating service PUT /v2/Entities/Elizalde/attrs/aggregateRating/value
orion_1        | DEBUG@07:33:12  RestService.cpp[483]: tenant: 'tourguide'
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[309]: Creating a ContextAttribute: compoundValueP at 0x7f0754001720 for attribute 'aggregateRating' at 0x7f0754001c20
orion_1        | DEBUG@07:33:12  sem.cpp[147]: mongoUpdateContext taking the 'req' semaphore for 'ngsi10 update request'
orion_1        | DEBUG@07:33:12  sem.cpp[168]: mongoUpdateContext has the 'req' semaphore
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^\/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[203]: count() in 'orion-tourguide.entities' collection: '{ _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[210]: Database Operation Successful (count: { _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } })
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[65]: query() in 'orion-tourguide.entities' collection: '{ _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[79]: Database Operation Successful (query: { _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } })
orion_1        | DEBUG@07:33:12  MongoCommonUpdate.cpp[2891]: Docs found: 0
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[342]: Creating a string ContextAttribute 'aggregateRating':'none':'', setting its compound to NULL
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1514]: Entity discovery: {id: Elizalde, type: Restaurant}
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1526]: Attribute discovery: 'aggregateRating'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^\/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1566]: Offset: 0, Limit: 0, Details: false
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[134]: query() in 'orion-tourguide.registrations' collection limit=0, offset=0: '{ query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, contextRegistration.attrs.name: { $in: [ "aggregateRating" ] }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[153]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, contextRegistration.attrs.name: { $in: [ "aggregateRating" ] }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } })
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1514]: Entity discovery: {id: Elizalde, type: Restaurant}
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^\/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1566]: Offset: 0, Limit: 0, Details: false
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[134]: query() in 'orion-tourguide.registrations' collection limit=0, offset=0: '{ query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[153]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } })
orion_1        | DEBUG@07:33:12  sem.cpp[353]: mongoUpdateContext gives the 'req' semaphore for 'ngsi10 update request'
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001720: name: 'TOP', path '/' at 0x7f0754001720 (with 2 children)
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[234]: Deleting child 0, at 0x7f0754001800
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001800: name: 'reviewCount', path '/reviewCount' at 0x7f0754001800 (with 0 children)
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[234]: Deleting child 1, at 0x7f0754001910
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001910: name: 'ratingValue', path '/ratingValue' at 0x7f0754001910 (with 0 children)
orion_1        | DEBUG@07:33:12  restReply.cpp[67]: Response 76: responding with 0 bytes, Status Code 404
orion_1        | DEBUG@07:33:12  restReply.cpp[68]: Response payload: ''
orion_1        | DEBUG@07:33:12  UpdateContextResponse.cpp[77]: destroyed
orion_1        | DEBUG@07:33:12  RegisterContextResponse.cpp[56]: destroyed
orion_1        | INFO@07:33:12  logMsg.h[1889]: Transaction ended
1

1 Answers

0
votes

I have tried to reproduce your problem in a limited environment (just creating the entity 'Elizalde') but without success. For me it works just fine ...

First of all, the following line:
/v2/Entities/Elizalde/attrs/aggregateRating/value?Type=Restaurant is incorrect. It must be .../value?type=Restaurant, as the URI params are case sensitive.

Using Type instead of type means that Type is ignored and type is not present, so the PUT will attack ALL entities called Elizalde, regardless of their types. You probably have only ONE, so that's 'OK'. If you have more than one entity called Elizalde, you would get a 409 (Conflict) as response, and this is not your case, as you are seeing a 404 (Not Found).

Now, I don't know why you get a 404. In my simple test, everything works (I am using the latest version of the broker, but that shouldn't really change anything).

To try to troubleshoot your problem, I would suggest for you to have the broker started in verbose mode (using -t0-255 -logLevel DEBUG) and post the output from the broker when receiving the PUT request that fails.

Also, to narrow it down a little, you might want to use the script that I put together to test this in my machine (hoping it will fail in your machine - for me it works):

echo "01. Create Entity Elizalde, type Restaurant, with compound attribute 'aggregateRating'"
echo "======================================================================================"
curl -X POST localhost:1026/v2/Entities  -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"id": "Elizalde", "type": "Restaurant", "aggr\
egateRating": { "value": { "reviewCount": 1, "ratingValue": 10 }}}'
echo
echo

echo "02. Create Entity Elizalde, type Restaurant2, with compound attribute 'aggregateRating'"
echo "======================================================================================"
curl -X POST localhost:1026/v2/Entities  -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"id": "Elizalde", "type": "Restaurant2", "agg\
regateRating": { "value": { "reviewCount": 1, "ratingValue": 10 }}}'
echo
echo

echo "03. Get Entity Elizalde, see ratingValue == 10"
echo "=============================================="
curl localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo

echo "04. Change value of aggregateRating, setting ratingValue to 20 (was 10)"
echo "======================================================================="
curl -X PUT localhost:1026/v2/Entities/Elizalde/attrs/aggregateRating/value?type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide'\
 -d '{"reviewCount": 1,"ratingValue": 20}'
echo
echo

echo "05. Get Entity Elizalde, see ratingValue == 20"
echo "=============================================="
curl localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo

echo "06. Delete Elizalde, type Restaurant"
echo "===================================="
curl -X DELETE localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo

echo "07. Delete Elizalde, type Restaurant2"
echo "====================================="
curl -X DELETE localhost:1026/v2/Entities/Elizalde
echo
echo

echo "08. Intent to Get Entity Elizalde - nothing found"
echo "================================================="
curl localhost:1026/v2/Entities/Elizalde
echo
echo

Clean the database before starting this test.

[ If you change type=Restaurant for Type=Restaurant in step 04, you should see a 409, as there are two entities with id Elizalde ]

The version of the broker I have used is:

"version" : "1.0.0-next",
"uptime" : "0 d, 0 h, 54 m, 42 s",
"git_hash" : "70cc445d0555cbed50134452ae9858a7ddc05d7e",
"compile_time" : "Wed Apr 20 12:35:23 CEST 2016",
"compiled_by" : "kz",
"compiled_in" : "hoppe"

git hash: 70cc445d0555cbed50134452ae9858a7ddc05d7e