conwetlab / FIWARE-CKAN-Extensions

This repository includes the documentation and links to the different CKAN extensions developed within FIWARE
GNU Affero General Public License v3.0
8 stars 7 forks source link

Right_time_context doesn't send FiwareService and FiwareServicePath headers in requests to Orion #15

Open agaldemas opened 5 years ago

agaldemas commented 5 years ago

I made a test with Right_time_context, towards Orion: configured a dataset with format fiware-ngsi the tenant and service path are both filled with value in the interface, but are not transmitted to Orion in request: log result from Orion:

orion_1 | time=Monday 11 Feb 16:09:23 2019.266Z | lvl=WARN | corr=6572ca14-2e17-11e9-a839-0242ac14000c | trans=1549831530-835-00000000529 | from=172.20.0.20 | srv=<default> | subsrv=<default> | comp=Orion | op=AlarmManager.cpp[405]:badInput | msg=Raising alarm BadInput 172.20.0.20: bad verb for url '/v2/entities

for fiwareService: srv=<default> 
for servicepath: subsrv=<default>

instead of: | srv=testservice | subsrv=/# | I traced the request sent by ckan right_time_context (with : http-echo).

And here is the request translated in json:

{
    "path": "/v2/entities/",
    "headers": {
        "host": "http-trace:3000",
        "connection": "keep-alive",
        "accept-encoding": "gzip, deflate",
        "accept": "*/*",
        "user-agent": "python-requests/2.11.1"
    },
    "method": "GET",
    "body": {},
    "fresh": false,
    "hostname": "http-trace",
    "ip": "::ffff:172.20.0.20",
    "ips": [],
    "protocol": "http",
    "query": {},
    "subdomains": [],
    "xhr": false
}

As you can see it miss:( tenant and service path declared and visible in the interface (don't worry Orion is case unsensitive for header parameter keys)

FIWARE-Service: testservice
FIWARE-ServicePath: /#

They are not in the header, then Orion can't find any entity. I re-build the image from Dockerfile, to check if I was missing an update, but same problem I got a look in the plugin code and saw there was lines to set headers in right_time_context/controller.py file, to set headers, before sending the request:

        if resource.get('tenant', '') != '':
            headers['FIWARE-Service'] = resource['tenant']
        if resource.get('service_path', '') != '':
            headers['FIWARE-ServicePath'] = resource['service_path']

the problem is either in requests.get(), or tenant & service_path are not taken from resource object ? strange...

agaldemas commented 5 years ago

What I don't understand is that if I introduce a log.error to print headers it's never displayed, or if I remove controller.py and controller.pyc in right_time_context directory and restart the container, ckan doesn't complain like if the file is not used at all ? Have someone any explanation on this strange behavior ?

agaldemas commented 5 years ago

OK, I finally manage to query Orion with ckan right_time_context, by using the NGSI view type, the headers are sent in the request... meaning that the query is done differently with text view (using another module inside ckan, strange behavior...

agaldemas commented 5 years ago

This should be indicated clearly in the user documentation, which is not the case...

fdelavega commented 5 years ago

Well, the point is that the plugin is only used to save the query as dataset resource. Is the NGSI view the one that executes the query and displays the data, other views will not work as they are not NGSI aware