Sawtooth tx processor: There is no state data at the address specified - hyperledger-sawtooth

After saving some value into an sawtooth address, I try to recover it via the rest-api but it responds "There is no state data at the address specified". Here are the steps I've done:
From the tx processor (python sdk) I call "set_state", and check that my address is in returned list.
// address = 7749f2d822961a489fac22690b773c1b613c890197bf65090d3c468f4ba8964b98c555
// value = 327 bytes
addresses = context.set_state({address: value})
//addresses contains the given address
Due to this error, as a validation, I read the value using "get_state", right after that previous line of the tx processor. I can successfully get the value I writed.
state_entries = context.get_state([address])
//state_entries contains the given address
Later from a web client I make a request to the rest-api at 'http://rest-api:8008/state/ADDRESS' (where the address is the one previously set). But the response says "Unable to find entry at address". This is the full response:
sawtooth-nmso-web-client | size: 0,
sawtooth-nmso-web-client | timeout: 0,
sawtooth-nmso-web-client | [Symbol(Body internals)]: {
sawtooth-nmso-web-client | body: PassThrough {
sawtooth-nmso-web-client | _readableState: [ReadableState],
sawtooth-nmso-web-client | readable: true,
sawtooth-nmso-web-client | _events: [Object: null prototype],
sawtooth-nmso-web-client | _eventsCount: 2,
sawtooth-nmso-web-client | _maxListeners: undefined,
sawtooth-nmso-web-client | _writableState: [WritableState],
sawtooth-nmso-web-client | writable: false,
sawtooth-nmso-web-client | allowHalfOpen: true,
sawtooth-nmso-web-client | _transformState: [Object],
sawtooth-nmso-web-client | [Symbol(kCapture)]: false
sawtooth-nmso-web-client | },
sawtooth-nmso-web-client | disturbed: false,
sawtooth-nmso-web-client | error: null
sawtooth-nmso-web-client | },
sawtooth-nmso-web-client | [Symbol(Response internals)]: {
sawtooth-nmso-web-client | url: 'http://rest-api:8008/state/7749f2d822961a489fac22690b773c1b613c890197bf65090d3c468f4ba8964b98c555',
sawtooth-nmso-web-client | status: 404,
sawtooth-nmso-web-client | statusText: 'Not Found',
sawtooth-nmso-web-client | headers: Headers { [Symbol(map)]: [Object: null prototype] },
sawtooth-nmso-web-client | counter: 0
sawtooth-nmso-web-client | }
sawtooth-nmso-web-client | }
sawtooth-nmso-web-client | UserClient.js > request_to_rest_api > response.json: {
sawtooth-nmso-web-client | error: {
sawtooth-nmso-web-client | code: 75,
sawtooth-nmso-web-client | message: 'There is no state data at the address specified.',
sawtooth-nmso-web-client | title: 'State Not Found'
sawtooth-nmso-web-client | }
sawtooth-nmso-web-client | }
Anyone knows what I'm doing wrong? Thanks

Related

How to change values from writable basic Datatypes on an OPC UA Server with FIWARE OPC UA AGENT

GOAL
Change writable values on the OPC UA Server by using the Fiware OPC UA Agent.
My test implementation
Adding the NodeId "7:PLC1_7:G_Communication_7:fi_heartbeat_i" to the "command" and "contextSubscription" sections in the config.json file. The value data type of the NodeId is Int16, but because this value is supposed to be written, I assume that "command" must be used as the type. Unfortunately, more detailed information cannot be found in the manual fiware opcua agent.
Start a new test environment with OpcUa Agent, Orion Context broker and mongodb.
Expectet behavior
The value on the server is updated when a request is sent to the Context Broker.
Current behaviour
The value of the parameter is read out correctly but with an incorrect data type (string instead of integer).
The value of the parameter is not updated when a request is sent to the Orion Context Broker.
additional informations
config.json
{
"logLevel" : "DEBUG",
"contextBroker" : {
"host" : "orion",
"port" : 1026
},
"server" : {
"port" : 4001,
"baseRoot" : "/"
},
"deviceRegistry" : {
"type" : "memory"
},
"mongodb" : {
"host" : "iotmongo",
"port" : "27017",
"db" : "iotagent",
"retries" : 5,
"retryTime" : 5
},
"providerUrl" : "http://iotopcua:4001",
"pollingExpiration" : "200000",
"pollingDaemonFrequency" : "20000",
"deviceRegistrationDuration" : "P1M",
"defaultType" : null,
"browseServerOptions" : null,
"service" : "test",
"subservice" : "/test",
"types" : {
"g_communication" : {
"service" : "test",
"subservice" : "/test",
"active" : [{
"name" : "7:PLC1_7:G_Communication_7:fo_smartControllerActive_b",
"type" : "Boolean"
} ],
"lazy" : [ ],
"commands" : [{
"name" : "7:PLC1_7:G_Communication_7:fi_heartbeat_i",
"type" : "Command"
}]
}
},
"contexts" : [ {
"id" : "plant",
"type" : "g_communication",
"service" : "test",
"subservice" : "/test",
"polling" : null,
"mappings" : [{
"ocb_id" : "7:PLC1_7:G_Communication_7:fo_smartControllerActive_b",
"opcua_id" : "ns=7;s=G_Communication.fo_smartControllerActive_b",
"object_id" : null,
"inputArguments" : []
} ]
}],
"contextSubscriptions" : [{
"id" : "plant",
"type" : "g_communication",
"mappings" : [{
"ocb_id" : "7:PLC1_7:G_Communication_7:fi_heartbeat_i",
"opcua_id" : "ns=7;s=G_Communication.fi_heartbeat_i",
"object_id" : "ns=7;s=G_Communication",
"inputArguments" : [{
"type": "Number"
}]
}]
}]
}
List Entities
curl 'http://localhost:1026/v2/entities/plant/' -H 'fiware-service: test' -H 'fiwate-servicepath: /test' | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 684 100 684 0 0 13751 0 --:--:-- --:--:-- --:--:-- 13959
{
"7:PLC1_7:G_Communication_7:fi_heartbeat_i": {
"metadata": {
"ServerTimestamp": {
"type": "ISO8601",
"value": "null"
},
"SourceTimestamp": {
"type": "ISO8601",
"value": "null"
}
},
"type": "string",
"value": "4"
},
"7:PLC1_7:G_Communication_7:fi_heartbeat_i_info": {
"metadata": {},
"type": "commandResult",
"value": " "
},
"7:PLC1_7:G_Communication_7:fi_heartbeat_i_status": {
"metadata": {},
"type": "commandStatus",
"value": "UNKNOWN"
},
"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b": {
"metadata": {
"ServerTimestamp": {
"type": "ISO8601",
"value": "2021-05-04T07:38:01.150Z"
},
"SourceTimestamp": {
"type": "ISO8601",
"value": "2021-05-04T07:37:59.934Z"
}
},
"type": "Boolean",
"value": false
},
"id": "plant",
"type": "g_communication"
}
Registrations
curl 'http://localhost:1026/v2/registrations' -H 'fiware-service: test' -H 'fiwate-servicepath: /test' | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 320 100 320 0 0 46049 0 --:--:-- --:--:-- --:--:-- 53333
[
{
"dataProvided": {
"attrs": [
"7:PLC1_7:G_Communication_7:fi_heartbeat_i"
],
"entities": [
{
"id": "plant",
"type": "g_communication"
}
]
},
"expires": "2021-06-03T07:37:38.00Z",
"id": "6090f9c254b918756abf1a7d",
"provider": {
"http": {
"url": "http://iotopcua:4001"
},
"legacyForwarding": true,
"supportedForwardingMode": "all"
},
"status": "active"
}
]
Test communication with iotopcua
curl "http://iotopcua:4001/version"
{"libVersion":"2.12.0-next","port":4001,"baseRoot":"/"}
Request for update
curl -X PUT \
'http://localhost:1026/v2/entities/plant/attrs/7:PLC1_7:G_Communication_7:fi_heartbeat_i?type=g_communication' \
-H 'content-type: application/json' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test' \
-d '{
"value": 2
}'
Log OCB
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=logMsg.h[1844]:lmTransactionStart | msg=Starting transaction from 0.0.0.0:54232/v2/entities/plant/attrs/7:PLC1_7:G_Communication_7:fi_heartbeat_i
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=rest.cpp[874]:servicePathSplit | msg=Service Path 0: '/test'
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=connectionOperations.cpp[244]:collectionCount | msg=Database Operation Successful (count: { _id.id: "plant", _id.type: "g_communication", _id.servicePath: "/test" })
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=connectionOperations.cpp[94]:collectionQuery | msg=Database Operation Successful (query: { _id.id: "plant", _id.type: "g_communication", _id.servicePath: "/test" })
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=connectionOperations.cpp[182]:collectionRangedQuery | msg=Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities.id: "plant", contextRegistration.entities.type: "g_communication" }, { contextRegistration.entities.id: ".*", contextRegistration.entities.isPattern: "true", contextRegistration.entities.type: { $in: [ "g_communication" ] } }, { contextRegistration.entities.id: ".*", contextRegistration.entities.isPattern: "true", contextRegistration.entities.type: { $exists: false } } ], expiration: { $gt: 1620114947 }, contextRegistration.attrs.name: { $in: [ "7:PLC1_7:G_Communication_7:fi_heartbeat_i" ] }, servicePath: "/test" }, orderby: { _id: 1 } })
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=logMsg.h[1844]:lmTransactionStart | msg=Starting transaction to http://iotopcua:4001//updateContext
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=httpRequestSend.cpp[550]:httpRequestSendWithCurl | msg=Sending message 4 to HTTP server: sending message of 458 bytes to HTTP server
from=10.1.17.1 | srv=test | subsrv=/test | comp=Orion | op=logMsg.h[1844]:lmTransactionStart | msg=Starting transaction from 10.1.17.1:58162/v1/updateContext
from=10.1.17.1 | srv=test | subsrv=/test | comp=Orion | op=rest.cpp[874]:servicePathSplit | msg=Service Path 0: '/test'
from=10.1.17.1 | srv=test | subsrv=/test | comp=Orion | op=connectionOperations.cpp[94]:collectionQuery | msg=Database Operation Successful (query: { _id.id: "plant", _id.type: "g_communication", _id.servicePath: "/test" })
from=10.1.17.1 | srv=test | subsrv=/test | comp=Orion | op=connectionOperations.cpp[454]:collectionUpdate | msg=Database Operation Successful (update: <{ _id.id: "plant", _id.type: "g_communication", _id.servicePath: "/test" }, { $set: { attrs.7:PLC1_7:G_Communication_7:fi_heartbeat_i_status: { value: "PENDING", type: "commandStatus", mdNames: [], creDate: 1620113858, modDate: 1620114947 }, modDate: 1620114947, lastCorrelator: "2324ca1e-acae-11eb-a4f7-226cad26e2cc" }, $unset: { location: 1, expDate: 1 } }>)
from=10.1.17.1 | srv=test | subsrv=/test | comp=Orion | op=logMsg.h[1874]:lmTransactionEnd | msg=Transaction ended
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=httpRequestSend.cpp[570]:httpRequestSendWithCurl | msg=Notification Successfully Sent to http://iotopcua:4001//updateContext
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=httpRequestSend.cpp[579]:httpRequestSendWithCurl | msg=Notification response OK, http code: 200
from=0.0.0.0 | srv=test | subsrv=/test | comp=Orion | op=logMsg.h[1874]:lmTransactionEnd | msg=Transaction ended
Log OPCUA Client
time=2021-05-04T07:55:47.191Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.GenericMiddlewares | msg=Request for path [//updateContext] from [iotopcua:4001]
time=2021-05-04T07:55:47.191Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.GenericMiddlewares | msg=Body:
{
"contextElements": [
{
"type": "g_communication",
"isPattern": "false",
"id": "plant",
"attributes": [
{
"name": "7:PLC1_7:G_Communication_7:fi_heartbeat_i",
"type": "Number",
"value": 2
}
]
}
],
"updateAction": "UPDATE"
}
time=2021-05-04T07:55:47.193Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.ContextServer | msg=Handling update from [iotopcua:4001]
time=2021-05-04T07:55:47.193Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.ContextServer | msg=[object Object]
time=2021-05-04T07:55:47.194Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.InMemoryGroupRegister | msg=Looking for device params ["service","subservice","type"]
time=2021-05-04T07:55:47.194Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.DeviceService | msg=deviceData after merge with conf: {"id":"plant","name":"plant","type":"g_communication","active":[{"name":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b","type":"Boolean","object_id":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b"}],"service":"test","subservice":"/test","polling":null,"endpoint":"opc.tcp://109.68.106.155:48050","registrationId":"6090f9c254b918756abf1a7d","creationDate":1620113858802}
time=2021-05-04T07:55:47.194Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.DeviceService | msg=deviceData before merge with conf: {"id":"plant","name":"plant","type":"g_communication","active":[{"name":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b","type":"Boolean","object_id":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b"}],"lazy":[],"commands":[{"name":"7:PLC1_7:G_Communication_7:fi_heartbeat_i","type":"Command","object_id":"7:PLC1_7:G_Communication_7:fi_heartbeat_i"}],"service":"test","subservice":"/test","polling":null,"endpoint":"opc.tcp://109.68.106.155:48050","registrationId":"6090f9c254b918756abf1a7d","creationDate":1620113858802,"internalAttributes":null,"staticAttributes":[],"subscriptions":[]}
time=2021-05-04T07:55:47.195Z | lvl=INFO | corr=n/a | trans=n/a | op=Index.CommandContextHandler | comp=iotAgent-OPCUA | srv=test | subsrv=/test | msg=method to call =[{"objectId":"ns=7;s=G_Communication","methodId":"ns=7;s=G_Communication.fi_heartbeat_i","inputArguments":[{"type":"Number"}]}]
time=2021-05-04T07:55:47.879Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=executeWithDeviceInfo entityName plant type undefined apikey undefined attributes [{"name":"7:PLC1_7:G_Communication_7:fi_heartbeat_i_status","type":"commandStatus","value":"PENDING"}] deviceInformation {"id":"plant","name":"plant","type":"g_communication","active":[{"name":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b","type":"Boolean","object_id":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b"}],"lazy":[],"commands":[{"name":"7:PLC1_7:G_Communication_7:fi_heartbeat_i","type":"Command","object_id":"7:PLC1_7:G_Communication_7:fi_heartbeat_i"}],"service":"test","subservice":"/test","polling":null,"endpoint":"opc.tcp://109.68.106.155:48050","registrationId":"6090f9c254b918756abf1a7d","creationDate":1620113858802,"internalAttributes":null,"staticAttributes":[],"subscriptions":[]}
time=2021-05-04T07:55:47.879Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=error {"name":"DEVICE_GROUP_NOT_FOUND","message":"Couldn\t find device group","code":404} in get group device
time=2021-05-04T07:55:47.880Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=typeInformation {"id":"plant","name":"plant","type":"g_communication","active":[{"name":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b","type":"Boolean","object_id":"7:PLC1_7:G_Communication_7:fo_smartControllerActive_b"}],"lazy":[],"commands":[{"name":"7:PLC1_7:G_Communication_7:fi_heartbeat_i","type":"Command","object_id":"7:PLC1_7:G_Communication_7:fi_heartbeat_i"}],"service":"test","subservice":"/test","polling":null,"endpoint":"opc.tcp://109.68.106.155:48050","registrationId":"6090f9c254b918756abf1a7d","creationDate":1620113858802,"internalAttributes":null,"staticAttributes":[],"subscriptions":[]}
time=2021-05-04T07:55:47.880Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=Updating device value in the Context Broker at [http://orion:1026/v1/updateContext]
time=2021-05-04T07:55:47.880Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=Using the following request:
{
"url": "http://orion:1026/v1/updateContext",
"method": "POST",
"headers": {
"fiware-service": "test",
"fiware-servicepath": "/test"
},
"json": {
"contextElements": [
{
"type": "g_communication",
"isPattern": "false",
"id": "plant",
"attributes": [
{
"name": "7:PLC1_7:G_Communication_7:fi_heartbeat_i_status",
"type": "commandStatus",
"value": "PENDING"
}
]
}
],
"updateAction": "UPDATE"
}
}
time=2021-05-04T07:55:47.886Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=Received the following request from the CB:
{
"contextResponses": [
{
"contextElement": {
"type": "g_communication",
"isPattern": "false",
"id": "plant",
"attributes": [
{
"name": "7:PLC1_7:G_Communication_7:fi_heartbeat_i_status",
"type": "commandStatus",
"value": ""
}
]
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
time=2021-05-04T07:55:47.886Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.NGSIService | msg=Value updated successfully
time=2021-05-04T07:55:47.886Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.ContextServer | msg=Update action from [iotopcua:4001] handled successfully.
time=2021-05-04T07:55:47.886Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.ContextServer | msg=Generated update response: {"contextResponses":[{"contextElement":{"attributes":[{"name":"7:PLC1_7:G_Communication_7:fi_heartbeat_i","type":"Number","value":""}],"id":"plant","isPattern":false,"type":"g_communication"},"statusCode":{"code":200,"reasonPhrase":"OK"}}]}
time=2021-05-04T07:55:47.887Z | lvl=DEBUG | corr=n/a | trans=n/a | op=IoTAgentNGSI.DomainControl | msg=response-time: 697
as far as i can tell, i think the error resides in your contextSubscription snippet inside your config.json which should look like :
"contextSubscriptions": [{
"id": "plant",
"type": "g_communication",
"service": "test",
"subservice": "/test",
"mappings": [{
"ocb_id": "7:PLC1_7:G_Communication_7:fi_heartbeat_i",
"opcua_id": "ns=7;s=G_Communication.fi_heartbeat_i",
"object_id": "ns=7;s=G_Communication",
"inputArguments": [{
"dataType": 4,
"type": "Intensity"
}]
}]
}]
Could you please give it a try?

Is Orion compatible with AWS DocumentDB

I am trying to connect Orion with AWS DocumentDB but it's not getting connected. However I tried two other FIWARE components IoTAgent and Sth-Comet with DocumentDB and both are working fine.
Same hostname and credential are working for IoTAgent and Sth-Comet. I also checked for the connectivity, which is fine, as IoTAgent and Sth-Comet are in same network. I also checked from a different mongo host in same network and this also worked. Below is the error that I am getting for Orion.
time=2021-02-18T07:03:46.293Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongoConnectionPool.cpp[180]:mongoConnect | msg=Database Startup Error (cannot connect to mongo - doing 100 retries with a 1000 millisecond interval)
Is there any possibility that Orion is not compatible with AWS DocumentDB?
Update1:
bash-4.2$ ps ax | grep contextBroker
1 ? Ss 0:00 /usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -disableFileLog -dbhost xxxxxxxxxxxxxxxxxx.docdb.amazonaws.com -db admin -dbuser test -dbpwd xxxxxxxxxx
Update2:
Earlier, I was using Orion docker images by pulling directly from dockerhub and that was not working. So this time, I build two docker images by building source code of version 2.4.2 and 2.5.2. Now, I was able to connect with AWS DocuemntDB with these docker images but getting a different error as below.
time=2021-02-23T06:10:41.982Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=safeMongo.cpp[360]:getField | msg=Runtime Error (field '_id' is missing in BSONObj <{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported" }> from caller mongoSubCacheItemInsert:83)
time=2021-02-23T06:10:41.982Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: error retrieving _id field in doc: '{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported" }'
Below is the Orion version
contextBroker --version
2.5.0-next (git version: 3984f9fc30e90fa04682131ca4516b4d277eb27e)
curl -X GET 'http://localhost:1026/version'
{
"orion" : {
"version" : "2.5.0-next",
"uptime" : "0 d, 0 h, 4 m, 56 s",
"git_hash" : "3984f9fc30e90fa04682131ca4516b4d277eb27e",
"compile_time" : "Mon Feb 22 17:39:30 UTC 2021",
"compiled_by" : "root",
"compiled_in" : "4c7575c7c27f",
"release_date" : "Mon Feb 22 17:39:30 UTC 2021",
"doc" : "https://fiware-orion.rtfd.io/",
"libversions": {
"boost": "1_53",
"libcurl": "libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0",
"libmicrohttpd": "0.9.70",
"openssl": "1.0.2k",
"rapidjson": "1.1.0",
"mongodriver": "legacy-1.1.2"
}
}
}
I am also able to connect to DocumentDB from Orion Pod using Mongo Shell.
mongo --host xxxxxxxxxxxxxxxxxx.docdb.amazonaws.com:27017 --username xxxx --password xxxx
rs0:PRIMARY> show dbs;
rs0:PRIMARY>
I am also able to create entries using below command and it creates a DB and collection in DocumentDB:
curl localhost:1026/v2/entities -s -S --header 'Content-Type: application/json' \
> -X POST -d #- <<EOF
> {
> "id": "Room2",
> "type": "Room",
> "temperature": {
> "value": 23,
> "type": "Number"
> },
> "pressure": {
> "value": 720,
> "type": "Number"
> }
> }
> EOF
rs0:PRIMARY> show dbs;
orion 0.000GB
But I am not able to get that data using orion API and after executing this command it getting exited from container with a empty response. I have checked the same with Orion version 2.4.2 and 2.5.2 with DocumentDB 4.0 and 3.6.
[root#orion-docdb-7748fd9c85-gbjz7 /]# curl localhost:1026/v2/entities/Room2 -s -S --header 'Accept: application/json' | python -mjson.tool
curl: (52) Empty reply from server
command terminated with exit code 137
At the end, still getting same error in logs.
time=2021-02-23T06:16:04.564Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=safeMongo.cpp[360]:getField | msg=Runtime Error (field '_id' is missing in BSONObj <{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported" }> from caller mongoSubCacheItemInsert:83)
time=2021-02-23T06:16:04.564Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: error retrieving _id field in doc: '{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported" }'
Update3:
I have added -noCache and deployed again. Below are the commands output and logs for your reference.
Process check:
#ps ax | grep contextBroker
1 ? Ssl 0:00 /usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -disableFileLog -dbhost xxxxxxxxxxxxxxxxxx.docdb.amazonaws.com -dbuser xxxxxxxx -dbpwd xxxxxxxx -logLevel DEBUG -noCache
Entries in DB:
rs0:PRIMARY> show dbs
orion 0.000GB
rs0:PRIMARY> use orion
switched to db orion
rs0:PRIMARY> show collections
entities
rs0:PRIMARY> db.entities.find()
{ "_id" : { "id" : "Room2", "type" : "Room", "servicePath" : "/" }, "attrNames" : [ "temperature", "pressure" ], "attrs" : { "temperature" : { "type" : "Number", "creDate" : 1614323032.671698, "modDate" : 1614323032.671698, "value" : 23, "mdNames" : [ ] }, "pressure" : { "type" : "Number", "creDate" : 1614323032.671698, "modDate" : 1614323032.671698, "value" : 720, "mdNames" : [ ] } }, "creDate" : 1614323032.671698, "modDate" : 1614323032.671698, "lastCorrelator" : "c8a73f40-7800-11eb-bd9b-bea9c419835d" }
Orion Pod Logs:
time=2021-02-26T06:46:33.966Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[1008]:main | msg=start command line </usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -disableFileLog -dbhost -dbhost xxxxxxxxxxxxxxxxxx.docdb.amazonaws.com -dbuser xxxxxxxx -dbpwd xxxxxxxx -logLevel DEBUG -noCache>
time=2021-02-26T06:46:33.966Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[1076]:main | msg=Orion Context Broker is running
time=2021-02-26T06:46:34.280Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=MongoGlobal.cpp[243]:mongoInit | msg=Connected to mongo at xxxxxxxxxxxxxxxxxx.docdb.amazonaws.com/orion, as user 'xxxxxxx' (poolsize: 10)
time=2021-02-26T06:46:34.282Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[1202]:main | msg=Startup completed
time=2021-02-26T07:03:24.546Z | lvl=INFO | corr=b7e44e5a-7800-11eb-9531-bea9c419835d | trans=1614321993-966-00000000001 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=logTracing.cpp[79]:logInfoRequestWithoutPayload | msg=Request received: GET /version, response code: 200
time=2021-02-26T07:03:52.672Z | lvl=ERROR | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=safeMongo.cpp[360]:getField | msg=Runtime Error (field '_id' is missing in BSONObj <{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported", operationTime: Timestamp 1614323032|1 }> from caller processContextElement:3493)
time=2021-02-26T07:03:52.672Z | lvl=ERROR | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: error retrieving _id field in doc: '{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported", operationTime: Timestamp 1614323032|1 }'
time=2021-02-26T07:03:52.782Z | lvl=ERROR | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=AlarmManager.cpp[235]:dbErrorReset | msg=Releasing alarm DatabaseError
time=2021-02-26T07:03:52.790Z | lvl=ERROR | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=safeMongo.cpp[360]:getField | msg=Runtime Error (field '_id' is missing in BSONObj <{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported", operationTime: Timestamp 1614323032|1 }> from caller addTriggeredSubscriptions_noCache:1408)
time=2021-02-26T07:03:52.790Z | lvl=ERROR | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: error retrieving _id field in doc: '{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported", operationTime: Timestamp 1614323032|1 }'
time=2021-02-26T07:03:52.791Z | lvl=INFO | corr=c8a73f40-7800-11eb-bd9b-bea9c419835d | trans=1614321993-966-00000000002 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=logTracing.cpp[130]:logInfoRequestWithPayload | msg=Request received: POST /v2/entities, request payload (148 bytes): { "id": "Room2", "type": "Room", "temperature": { "value": 23, "type": "Number" }, "pressure": { "value": 720, "type": "Number" }}, response code: 201
time=2021-02-26T07:03:58.479Z | lvl=ERROR | corr=cc1d5934-7800-11eb-a28d-bea9c419835d | trans=1614321993-966-00000000003 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=AlarmManager.cpp[235]:dbErrorReset | msg=Releasing alarm DatabaseError
time=2021-02-26T07:03:58.479Z | lvl=ERROR | corr=cc1d5934-7800-11eb-a28d-bea9c419835d | trans=1614321993-966-00000000003 | from=127.0.0.1 | srv=<none> | subsrv=<none> | comp=Orion | op=safeMongo.cpp[360]:getField | msg=Runtime Error (field '_id' is missing in BSONObj <{ ok: 0.0, code: 303, errmsg: "Legacy opcodes are not supported", operationTime: Timestamp 1614323038|1 }> from caller ContextElementResponse:109)
terminate called after throwing an instance of 'mongo::AssertionException'
what(): assertion src/mongo/bson/bsonelement.cpp:392
Pod exited and restarted during API call:
curl localhost:1026/v2/entities/Room2 -s -S --header 'Accept: application/json' | python -mjson.tool
command terminated with exit code 137
The following message shown in log traces is pretty significant
"Legacy opcodes are not supported"
Although the MongoDB driver used by Orion 2.5.2 and before works with official MongoDB version up to 4.4, probably it is not the case with MongoDB "clones" like AWS DocumentDB.
We are in the process to change the legacy driver used by Orion to a new one. Once this change lands in Orion master branch, I'd suggest to test it (using :latest dockerhub tag). In the meanwhile, as a workaround, I'd suggest to use a official MongoDB database.
EDIT: the process to change the MongoDB driver has finished and Orion is using the new driver since version 3.0.0. I think it would be a good idea to test with this new version and see how it goes. I can help with the test if you provide me with the access information (see here).

Perseo front end is showing this errors in the logs: msg=missing subservice header msg=missing service header

Using perseo cep, I set a rule to it. I get this message in the Perseo fron End's Log: http://perseo-core:8080/perseo-core/rules returns {"code":200,"body":{}}. Then when I modify an attribute, in the Perseo Core's Log I see this message: msg=Firing Rule: MapEventBean. So far, so good, but then again in the Perseo FE's log I get the message: msg=missing subservice header msg=missing service header, and it is not updating my entity.
This is the log:
time=2019-05-11T14:30:48.774Z | lvl=INFO | corr=n/a | trans=n/a | op=checkRequest | comp=perseo-fe | srv=n/a | subsrv=n/a | msg=missing subservice header
time=2019-05-11T14:30:48.774Z | lvl=INFO | corr=n/a | trans=n/a | op=checkRequest | comp=perseo-fe | srv=n/a | subsrv=n/a | msg=missing service header
time=2019-05-11T14:30:48.774Z | lvl=INFO | corr=5229c32c-362a-43f6-acda-11d6d8198261; perseocep=21 | trans=5229c32c-362a-43f6-acda-11d6d8198261 | op=/version | path=/version | comp=perseo-fe | srv=unknownt | subsrv=/ | from=::1 | msg=incoming request {"method":"GET","url":"/version","headers":{"host":"localhost:9090","user-agent":"curl/7.52.1","accept":"/"},"body":{},"subservice":"/","service":"unknownt"}
time=2019-05-11T14:30:48.774Z | lvl=INFO | corr=5229c32c-362a-43f6-acda-11d6d8198261; perseocep=21 | trans=5229c32c-362a-43f6-acda-11d6d8198261 | op=/version | path=/version | comp=perseo-fe | srv=unknownt | subsrv=/ | from=::1 | msg=sending
Mi Rule:
{
"name": "pruebaUpdate",
"text": "select ev.temperature? as temperature, ev.id? as id, \"pruebaUpdate\" as ruleName from pattern [every ev=iotEvent(cast(cast(temperature?,String),float) > 45 and type=\"AirQualityObserved\")]",
"action": [{
"type": "update",
"parameters": {
"id":"${id}",
"type":"AirQualityObserved",
"version": "2",
"attributes":[
{
"name": "abnormal",
"type": "boolean",
"value": "true"
}
]
}
}]
}
I want to update one attribute when other attribute is higher than a value, that attribute is in some entities but not in other of the same type. I am not getting to update that attribute.
msg=missing subservice header, msg=missing service header typically mean that the incoming request doesn't have the fiware-service and fiware-servicepath HTTP headers in which multitenancy is based. The FIWARE multitenancy model is described here.
Placing the rule in the correct place I didn't get the error of "missing service subservice". I registered the rule with http://perseo-fe-ip:9090/rules and I fixed the problems.

No resultset returned where clause node js mysql?

I am trying to search a mysql database by passing a token number and I want to return the id that is attached with that token from the database.
I have tried but I cant see any resultset and I am clueless as what am I doing wrong.
This is what I tried so far.
checkifuniquenumberexists:function(num){
con.connect(function (err) {
if (err) throw err;
console.log("Connected!");
var post = {"token": num};
var query = con.query('select id from uniquereviewtoken where token in (?)', post, function (err, result,fields) {
// Neat!
//console.log(query);
console.log("error", err);
console.log("result", result.length);
console.log("fields",fields);
return result;
});
});
Is there anything wrong with mysql syntax?
This is what I am getting in my logs
1|service | undefined
1|service | Connected!
1|service | error null
1|service | result 0
1|service | fields [ FieldPacket {
1|service | catalog: 'def',
1|service | db: 'review',
1|service | table: 'uniquereviewtoken',
1|service | orgTable: 'uniquereviewtoken',
1|service | name: 'id',
1|service | orgName: 'id',
1|service | charsetNr: 63,
1|service | length: 50,
1|service | type: 3,
1|service | flags: 16899,
1|service | decimals: 0,
1|service | default: undefined,
1|service | zeroFill: false,
1|service | protocol41: true },
1|service | FieldPacket {
1|service | catalog: 'def',
1|service | db: 'review',
1|service | table: 'uniquereviewtoken',
1|service | orgTable: 'uniquereviewtoken',
1|service | name: 'token',
1|service | orgName: 'token',
1|service | charsetNr: 33,
1|service | length: 3000,
1|service | type: 253,
1|service | flags: 4097,
1|service | decimals: 0,
1|service | default: undefined,
1|service | zeroFill: false,
1|service | protocol41: true } ]
You don't need post object.
Ref: https://www.npmjs.com/package/mysql#preparing-queries
checkifuniquenumberexists: function(num) {
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var query = con.query('select id from uniquereviewtoken where token in (?)', num, function(err, result, fields) {
// Neat!
//console.log(query);
console.log("error", err);
console.log("result", result.length);
console.log("fields", fields);
return result;
});
});

Sails.js associations

I am beginning with sails.js and I am completely lost with my sql queries.
I have the following tables :
genres
+-----------+--------------+------+-----+
| Field | Type | Null | Key |
+-----------+--------------+------+-----+
| id | int(6) | NO | PRI |
| name | varchar(100) | NO | |
| slug | varchar(255) | NO | |
| type | varchar(32) | NO | |
| parent_id | int(11) | YES | MUL |
+-----------+--------------+------+-----+
genres_radios
+----------+--------+------+-----+
| Field | Type | Null | Key |
+----------+--------+------+-----+
| genre_id | int(6) | NO | MUL |
| radio_id | int(6) | NO | MUL |
+----------+--------+------+-----+
radios
+-----------+--------------+------+-----+
| Field | Type | Null | Key |
+-----------+--------------+------+-----+
| id | int(5) | NO | PRI |
| name | varchar(100) | NO | |
| slug | varchar(100) | NO | |
| url | varchar(100) | NO | |
+-----------+--------------+------+-----+
I want to retrieve the radios and their associated genres. I managed to do it using the Model.query("Select * FROM ...") but I'd like to do it using the populate method. I had a look at the docs, but I am a bit confused with the "via", "through", ...
Well if you've followed the Sails.js Model documentation and the many-many association docs your models should look something like:
// api/models/genre.js
module.exports = {
attributes : {
name : {
type: 'string'
},
slug : {
type: 'string'
},
type : {
type: 'string'
},
radios : {
collection: 'radio',
via: 'genres'
}
}
}
// api/models/radio.js
module.exports = {
attributes : {
name : {
type: 'string'
},
slug : {
type: 'string'
},
url : {
type: 'string'
},
genres : {
collection: 'genre',
via: 'radios'
}
}
}
The many-many lookup table will be created for you internally by waterline. All you need to get the genres for your radio is populate the "genres" attribute.
Radio.findOne({name:"RadioName"}).populate("genres").then(function(radio){
console.log(radio); //radio.genres will have all the genres associated with this radio.
})
I really do recommend looking at the many-many association docs. They have exactly what you need.
This should do it :
// api/models/Genres.js
module.exports = {
attributes : {
name : {
type: 'string'
},
slug : {
type: 'string'
},
type : {
type: 'string'
},
radios : {
collection: 'Radios',
through: 'genres_radios'
}
}
}
// api/models/Radios.js
module.exports = {
attributes : {
name : {
type: 'string'
},
slug : {
type: 'string'
},
url : {
type: 'string'
},
genres : {
collection: 'genre',
through: 'genres_radios'
}
}
}
// api/models/Genres_radios.js
module.exports = {
attributes = {
'Genre_id': {
columnName:'genre_id',
type:'integer',
foreignKey:'true',
references:'genres',
on:'id',
via:'genres'
},
'Radio_id': {
columnName:'radio_id',
type:'integer',
foreignKey:'true',
references:'radios',
on:'id',
via:'radios'
}
}
}
And then you can make the following request :
Radio.findOne({name:"RadioName"}).populate("genres").then(function(radio){
console.log(radio);
})