Details
-
Type: Monitor
-
Status: Closed
-
Priority: Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: 2021
-
Component/s: FIWARE-TECH-HELP
-
Labels:
-
HD-Chapter:Data
-
HD-Enabler:Orion
Description
Created question in FIWARE Q/A platform on 21-12-2015 at 16:12
Please, ANSWER this question AT http://stackoverflow.com/questions/34399054/subscription-to-cb-working-but-not-visible
Question:
Subscription to CB working but not visible
Description:
I have an entity represented on the Context Broker with severall attributes (such as temperature, humidity etc...). I have a MySql database that persists the values from that entity by row. So in order to persist that info i have to make a subscription from cygnus. The problem here is that the information is being presisted but when i run the command (curl http://localhost:1026/v2/subscription) i get the output: [] as if any subscription was being made. If i do the command echo 'db.csubs.count()' | mongo orion --quiet it even shows the output 0.
Running OS: Centos 6
My Orion Context Broker Version: 0.26.0
Orion runs as a service:
/usr/bin/contextBroker -port 1026 -logDir /var/log/contextBroker -pidpath /var/run/contextBroker/contextBroker.pid -dbhost localhost -db orion -multiservice
So from the first step. Let's assume i don't have any subscription made to the database. I run the command:
/usr/cygnus/bin/cygnus-flume-ng agent --conf /usr/cygnus/conf/ -f /usr/cygnus/conf/agent_a1.conf -n cygnusagent -Dflume.root.logger=INFO,console
to ensure that a flume agent is running.
python2.7 SetSubscription.py bus temperature http://188.???.??.???:5050/notify
The python script is the one provided in the fiware-figway folder provided in the github repository.
import requests, json, re
from collections import Counter
import ConfigParser
import io
import sys
CONFIG_FILE = "../config.ini"
NUM_ARG=len(sys.argv)
COMMAND=sys.argv[0]
if NUM_ARG==4:
ENTITY_ID=sys.argv[1]
ENTITY_ATTR=sys.argv[2]
SERVER_URL=sys.argv[3]
else:
print 'Usage: 'COMMAND' [ENTITY ID] [ATTRIBUTE] [SERVER URL]'
print ' ENTITY ID = Entity you want to watch for changes/updates.'
print ' ATTRIBUTE = Attribute whose change will trigger notifications. In this example script only this attribute will be notified.'
print ' SERVER URL = (Local) Server listening for notifications.Example: http://myserver.domain.com:10000'
print ' It has to be a reachable address:port for the ContextBroker. If you are behind a NAT/Firewall contact your network admin.'
print
sys.exit(2)
- Load the configuration file
with open(CONFIG_FILE,'r+') as f:
sample_config = f.read()
config = ConfigParser.RawConfigParser(allow_no_value=True)
config.readfp(io.BytesIO(sample_config))
CB_HOST=config.get('contextbroker', 'host')
CB_PORT=config.get('contextbroker', 'port')
CB_FIWARE_SERVICE=config.get('contextbroker', 'fiware_service')
CB_AAA=config.get('contextbroker', 'OAuth')
if CB_AAA == "yes":
TOKEN=config.get('user', 'token')
TOKEN_SHOW=TOKEN[1:5]+"**********************************************************************"+TOKEN[-5:]
else:
TOKEN="NULL"
TOKEN_SHOW="NULL"
NODE_ID=config.get('local', 'host_id')
f.close()
CB_URL = "http://"CB_HOST":"+CB_PORT
MIN_INTERVAL = "PT5S"
DURATION = "P1M"
ENTITY_TYPE = ""
ENTITY_ATTR_WATCH = ENTITY_ATTR
ENTITY_ATTR_NOTIFY = ENTITY_ATTR
PAYLOAD = '{ \
"entities": [ \
\
], \
"attributes": [ \
"'ENTITY_ATTR_NOTIFY'" \
], \
"reference": "'SERVER_URL'", \
"duration": "'DURATION'", \
"notifyConditions": [ \
\
], \
"throttling": "'MIN_INTERVAL'" \
}'
HEADERS =
{'content-type': 'application/json', 'accept': 'application/json' , 'Fiware-Service': CB_FIWARE_SERVICE ,'X-Auth-Token' : TOKEN}#HEADERS =
{'content-type': 'application/json', 'Fiware-Service': CB_FIWARE_SERVICE ,'X-Auth-Token' : TOKEN}HEADERS_SHOW =
{'content-type': 'application/json', 'accept': 'application/json' , 'Fiware-Service': CB_FIWARE_SERVICE , 'X-Auth-Token' : TOKEN_SHOW}URL = CB_URL + '/v1/subscribeContext'
print "* Asking to "+URL
print "* Headers: "+str(HEADERS_SHOW)
print "* Sending PAYLOAD: "
print json.dumps(json.loads(PAYLOAD), indent=4)
print
print "..."
r = requests.post(URL, data=PAYLOAD, headers=HEADERS)
print
print "* Status Code: "+str(r.status_code)
print
print r.text
Now everytime that i make a change in the values, the value is changed and it is presisted in the database.
If you need any more information feel free to ask!
EDIT:
The payload "Asking to ", "Headers: " and "Sending payload":
- Asking to http://188.???.??.???:1026/v1/subscribeContext
- Headers: {'Fiware-Service': 'fiwarefinal', 'content-type': 'application/json', 'accept': 'application/json', 'X-Auth-Token': 'NULL'}
- Sending PAYLOAD:
{
"reference": "http://localhost:5050/notify",
"throttling": "PT5S",
"entities": [ { "type": "", "id": "bus1", "isPattern": "false" }],
{ "condValues": [ "temperature" ], "type": "ONCHANGE" }
"attributes": [
"temperature"
],
"duration": "P1M",
"notifyConditions": []
}
...
- Status Code: 200
{
"subscribeResponse" :
}
2015-12-22 09:41|UPDATED status: transition Finish| # answers= 1, accepted answer= True