FIWARE / tutorials.Historic-Context-NIFI

:blue_book: FIWARE 302: Persisting Context Data using Apache NIFI
https://fiware-draco.rtfd.io/
MIT License
4 stars 3 forks source link

Issue with MongoDB example on NGSI-LD fiware-draco-> org.json.JSONException: JSONObject["metadata"] #3

Open glompos21 opened 3 years ago

glompos21 commented 3 years ago

log from fiware-orion

time=Monday 28 Jun 15:07:28 2021.213Z | lvl=TMP | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldMhdConnectionInit.cpp[494]:orionldMhdConnectionInit | msg=------------------------- Servicing NGSI-LD request 3791: POST /ngsi-ld/v1/entityOperations/upsert/ --------------------------

time=Monday 28 Jun 15:07:38 2021.067Z | lvl=INFO | corr=N/A | trans=1624892255-360-00000000375 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[620]:httpRequestSendWithCurl | msg=Notification Successfully Sent to http://draco:5050/v2/notify

log from fiware-draco

2021-06-28 15:07:34,516 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.ngsi.NGSIToMongo NGSIToMongo[id=45007d62-fe1d-3e62-d1a0-f5649b10e89c] Failed to insert StandardFlowFileRecord[uuid=5c9744df-4189-4eac-ba67-2717add484dc,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1624892701155-1, container=default, section=1], offset=55845, length=1138],offset=0,name=5c9744df-4189-4eac-ba67-2717add484dc,size=1138] into MongoDB due to org.json.JSONException: JSONObject["metadata"] not found.: org.json.JSONException: JSONObject["metadata"] not found. org.json.JSONException: JSONObject["metadata"] not found. at org.json.JSONObject.get(JSONObject.java:572) at org.apache.nifi.processors.ngsi.ngsi.utils.NGSIUtils.getEventFromFlowFile(NGSIUtils.java:58) at org.apache.nifi.processors.ngsi.AbstractMongoProcessor.persistFlowFile(AbstractMongoProcessor.java:315) at org.apache.nifi.processors.ngsi.NGSIToMongo.onTrigger(NGSIToMongo.java:78) at org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27) at org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1173) at org.apache.nifi.controller.tasks.ConnectableTask.invoke(ConnectableTask.java:214) at org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:117) at org.apache.nifi.engine.FlowEngine$2.run(FlowEngine.java:110) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

curl -X GET 'http://localhost:1026/ngsi-ld/v1/subscriptions/' -H 'NGSILD-Tenant: openiot' [ { "id": "urn:ngsi-ld:Subscription:60d9e487092e510f2d732417", "type": "Subscription", "description": "Notify me of all changes", "entities": [ { "type": "Device" }, { "type": "Tractor" } ], "notification": { "format": "normalized", "endpoint": { "uri": "http://draco:5050/v2/notify", "accept": "application/json" }, "timesSent": 2353, "lastNotification": "2021-06-28T15:28:18.195Z" }, "@context": "http://context-provider:3000/data-models/ngsi-context.jsonld" } ]

jason-fox commented 3 years ago

Draco 1.3.6 has limited NSGI-LD support. With the 1.3.6 release, only the Postgres sink has an NGSI-LD option:

Screenshot 2021-06-30 at 18 18 01

The other sinks such as Mongo-DB are limited to NGSI-v2 only:

Screenshot 2021-06-30 at 18 18 31

The error you are getting is because your Mongo sink is expecting an NGSI-v2 subscription payload (including metadata) , not an NGSI-LD one which uses properties-of-properties. If you are using Orion-LD, you can work around this by changing the format attribute in the subscription:

e.g. :

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/subscriptions/' \
-H 'Content-Type: application/ld+json' \
-H 'NGSILD-Tenant: openiot' \
--data-raw '{
  "description": "Notify me of all changes",
  "type": "Subscription",
  "entities" : [{"type" :"Device"}, {"type": "Tractor"}],
  "notification": {
    "format": "x-ngsiv2-normalized",
    "endpoint": {
      "uri": "http://draco:5050/v2/notify",
      "accept": "application/json"
    }
  },
   "@context": "http://context-provider:3000/data-models/ngsi-context.jsonld"
}'

Note that until the missing syncs are available in a new Docker image (Draco 1.3.6) the NGSI-LD branch of the tutorial will not be published in the NGSI-LD tutorials documentation