I'm trying to connect cygnus (1.4.0_SNAPSHOT) to cartodb. I run it locally, and I use a script to send a notification to cygnus. The script runs Ok, but cygnus says:
ERROR sinks.NGSISink: Persistence error (The query 'INSERT INTO jcarneroatos.x002fpeoplelocation (recvtime,fiwareservicepath,entityid,entitytype,the_geom) VALUES ('2016-10-31T19:04:00.994Z','/peoplelocation','Person:1','Person',ST_SetSRID(ST_MakePoint({"coordinates":[-4.423032856,36.721290055]), 4326))' could not be executed. CartoDB response: 400 Bad Request)
Anyone knows what could be happening? Below I put my config files for information, thanks!
My username at CARTO is "jcarneroatos", and the domain is https://jcarneroatos.carto.com. This is the script I'm using to simulate the notification from Orion Context Broker:
#/bin/bash
HOST=localhost
PORT=5050
SERVICE=jcarneroatos
SUBSERVICE=/peoplelocation
#send notification
NOTIFICATION=$(\
curl http://$HOST:$PORT/notify \
-v -s -S \
--header "Content-Type: application/json; charset=utf-8" \
--header 'Accept: application/json' \
--header "Fiware-Service: $SERVICE" \
--header "Fiware-ServicePath: $SUBSERVICE" \
-d '
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"metadatas": [
{
"name": "location",
"type": "string",
"value": "WGS84"
}
],
"name": "location",
"type": "geo:json",
"value": {
"coordinates": [
-4.423032856,
36.721290055
],
"type": "Point"
}
}
],
"id": "Person:1",
"isPattern": "false",
"type": "Person"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
],
"originator": "localhost",
"subscriptionId": "58178396634ded66caac35b2"
}')
if [ -z "$NOTIFICATION" ]; then
echo "Ok"
else
echo $NOTIFICATION
fi
This is the structure of the dataset at cartodb:
x002fpeoplelocation
cartodb_id | the_geom | entityid | entitytype | fiwareservicepath | recvtime
number | geometry | string | string | string | date
This is the cygnus config file:
cygnusagent.sources = http-source
cygnusagent.sinks = cartodb-sink
cygnusagent.channels =cartodb-channel
cygnusagent.sources.http-source.channels = cartodb-channel
cygnusagent.sources.http-source.type = org.apache.flume.source.http.HTTPSource
cygnusagent.sources.http-source.port = 5050
cygnusagent.sources.http-source.handler = com.telefonica.iot.cygnus.handlers.NGSIRestHandler
cygnusagent.sources.http-source.handler.notification_target = /notify
cygnusagent.sources.http-source.handler.default_service = jcarneroatos
cygnusagent.sources.http-source.handler.default_service_path = /peoplelocation
cygnusagent.sources.http-source.interceptors = ts gi
cygnusagent.sources.http-source.interceptors.ts.type = timestamp
cygnusagent.sources.http-source.interceptors.gi.type = com.telefonica.iot.cygnus.interceptors.NGSIGroupingInterceptor$Builder
cygnusagent.sources.http-source.interceptors.gi.grouping_rules_conf_file = /home/cygnus/APACHE_FLUME_HOME/conf/grouping_rules.conf
cygnusagent.sinks.cartodb-sink.type = com.telefonica.iot.cygnus.sinks.NGSICartoDBSink
cygnusagent.sinks.cartodb-sink.channel = cartodb-channel
cygnusagent.sinks.cartodb-sink.enable_grouping = false
cygnusagent.sinks.cartodb-sink.enable_name_mappings = false
cygnusagent.sinks.cartodb-sink.enable_lowercase = false
cygnusagent.sinks.cartodb-sink.data_model = dm-by-service-path
cygnusagent.sinks.cartodb-sink.keys_conf_file = /home/cygnus/APACHE_FLUME_HOME/conf/cartodb_keys.conf
cygnusagent.sinks.cartodb-sink.flip_coordinates = false
cygnusagent.sinks.cartodb-sink.enable_raw = true
cygnusagent.sinks.cartodb-sink.enable_distance = false
cygnusagent.sinks.cartodb-sink.batch_size = 100
cygnusagent.sinks.cartodb-sink.batch_timeout = 30
cygnusagent.sinks.cartodb-sink.batch_ttl = 10
cygnusagent.sinks.cartodb-sink.backend.max_conns = 500
cygnusagent.sinks.cartodb-sink.backend.max_conns_per_route = 100
cygnusagent.channels.cartodb-channel.type = memory
cygnusagent.channels.cartodb-channel.capacity = 1000
cygnusagent.channels.cartodb-channel.transactionCapacity = 100
And finally the cartodb_keys.conf file (without key):
{
"cartodb_keys": [
{
"username": "jcarneroatos",
"endpoint": "https://jcarneroatos.carto.com",
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
Update: After executing Cygnus in DEBUG mode and check the logs, it seems that CARTO is returning:
{"error":["syntax error at or near \"{\""]}
This the complete log: http://pastebin.com/p9VyUU8n
Finally, after offline discussion with @Javi Carnero, we found there was a bug in Cygnus code related to the way Carto differentiates among "enterprise" and "personal" accounts. First ones allow for PostgreSQL schemas per user under the enterprise organization, while second ones have "hardcoded" schemas named
public
. Since the notified FIWARE service was used as the schema name, Cygnus was not properly working for "personal" accounts.Such a bug has been fixed:
At the moment of writting this, the bug is fixed in
master
branch. By the end of sprint/month Cygnus 1.7.0 will be released, including this fix.Please observe my previous answer is perfectly valid if you have an "enterprise" account. Anyway, I'll edit it in order to explain this.
The problem is
geo:json
type is not currently supported byNGSICartoDBSink
. This sink understands ceratain ways of notifying geolocated attributes, according to Orion Context Broker specification; these ones:geo:point
type, and sending the coordinates in the value field with format"latitude, longitude"
.location
metadata, of typestring
and valueWGS84
, and sending the coordinates in the value field with format"latitude, longitude"
.Please observe:
location
metadata is deprecated in Orion, nevertheless it can be still used.While
geo:json
is supported (I'll start working on that, it could be ready during this sprint/month), I'll recommend you to use thegeo:point
type.EDIT 1
I'm adding here an example of Cygnus execution, when receiving a notification involving a geolocated attribute (
geo:point
type).Cygnus version:
Cygnus configuration:
Create the table:
Script simulating a notification:
Script execution:
Cygnus logs upon notification reception:
Getting the data:
EDIT 2
This answer is only valid if you own an "enterprise" Carto account. Please, see my other answer to this question.