telefonicaid / fiware-cygnus

A connector in charge of persisting context data sources into other third-party databases and storage systems, creating a historical view of the context
https://fiware-cygnus.rtfd.io/
GNU Affero General Public License v3.0
64 stars 105 forks source link

Unable to deliver event: null pointer getAttributeForNaming #1506

Closed AlvaroVega closed 5 years ago

AlvaroVega commented 6 years ago

Log

time=2018-08-13T08:57:48.885Z | lvl=INFO | corr=f40195c4-9ed6-11e8-bd97-0242ac11000f | trans=08812971-1bbd-495e-9293-96b23a3711c7 |
 srv=prueba | subsrv=/pruebasub,/pruebasub | comp=cygnus-ngsi | op=getEvents | msg=com.telefonica.iot.cygnus.handlers.NGSIRestHandl
er[312] : [NGSIRestHandler] Received data ({"subscriptionId":"5b7147da0272c939fef549f8","originator":"localhost","contextResponses"
:[{"contextElement":{"type":"prueba","isPattern":"false","id":"prueba"},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextE
lement":{"type":"myType","isPattern":"false","id":"myEntity","attributes":[{"name":"description","type":"Text","value":"My happy en
tity"},{"name":"online","type":"Boolean","value":true},{"name":"temperature","type":"Number","value":42.3}]},"statusCode":{"code":"
200","reasonPhrase":"OK"}}]})
time=2018-08-13T08:57:48.945Z | lvl=ERROR | corr=f40195c4-9ed6-11e8-bd97-0242ac11000f | trans=08812971-1bbd-495e-9293-96b23a3711c7 
| srv=prueba | subsrv=/pruebasub | comp=cygnus-ngsi | op=run | msg=org.apache.flume.SinkRunner$PollingRunner[160] : Unable to deliv
er event. Exception follows.
java.lang.NullPointerException
    at com.telefonica.iot.cygnus.interceptors.NGSIEvent.getAttributeForNaming(NGSIEvent.java:178)
    at com.telefonica.iot.cygnus.sinks.NGSISTHSink$STHAggregator.initialize(NGSISTHSink.java:290)
    at com.telefonica.iot.cygnus.sinks.NGSISTHSink.persistBatch(NGSISTHSink.java:100)
    at com.telefonica.iot.cygnus.sinks.NGSISink.processNewBatches(NGSISink.java:558)
    at com.telefonica.iot.cygnus.sinks.NGSISink.process(NGSISink.java:370)
    at org.apache.flume.sink.DefaultSinkProcessor.process(DefaultSinkProcessor.java:68)
    at org.apache.flume.SinkRunner$PollingRunner.run(SinkRunner.java:147)
    at java.lang.Thread.run(Thread.java:748)
time=2018-08-13T08:57:48.945Z | lvl=ERROR | corr=f40195c4-9ed6-11e8-bd97-0242ac11000f | trans=08812971-1bbd-495e-9293-96b23a3711c7 
| srv=prueba | subsrv=/pruebasub | comp=cygnus-ngsi | op=run | msg=org.apache.flume.SinkRunner$PollingRunner[160] : Unable to deliv
er event. Exception follows.
java.lang.NullPointerException
    at com.telefonica.iot.cygnus.interceptors.NGSIEvent.getAttributeForNaming(NGSIEvent.java:178)
    at com.telefonica.iot.cygnus.sinks.NGSIMySQLSink$MySQLAggregator.initialize(NGSIMySQLSink.java:362)
    at com.telefonica.iot.cygnus.sinks.NGSIMySQLSink$ColumnAggregator.initialize(NGSIMySQLSink.java:442)
    at com.telefonica.iot.cygnus.sinks.NGSIMySQLSink.persistBatch(NGSIMySQLSink.java:193)
    at com.telefonica.iot.cygnus.sinks.NGSISink.processNewBatches(NGSISink.java:558)
    at com.telefonica.iot.cygnus.sinks.NGSISink.process(NGSISink.java:370)
    at org.apache.flume.sink.DefaultSinkProcessor.process(DefaultSinkProcessor.java:68)
    at org.apache.flume.SinkRunner$PollingRunner.run(SinkRunner.java:147)
    at java.lang.Thread.run(Thread.java:748)
time=2018-08-13T08:57:48.945Z | lvl=ERROR | corr=f40195c4-9ed6-11e8-bd97-0242ac11000f | trans=08812971-1bbd-495e-9293-96b23a3711c7 
| srv=prueba | subsrv=/pruebasub | comp=cygnus-ngsi | op=run | msg=org.apache.flume.SinkRunner$PollingRunner[160] : Unable to deliv
er event. Exception follows.
java.lang.NullPointerException
    at com.telefonica.iot.cygnus.interceptors.NGSIEvent.getAttributeForNaming(NGSIEvent.java:178)
    at com.telefonica.iot.cygnus.sinks.NGSIMongoSink$MongoDBAggregator.initialize(NGSIMongoSink.java:187)
    at com.telefonica.iot.cygnus.sinks.NGSIMongoSink$RowAggregator.initialize(NGSIMongoSink.java:203)
    at com.telefonica.iot.cygnus.sinks.NGSIMongoSink.persistBatch(NGSIMongoSink.java:122)
    at com.telefonica.iot.cygnus.sinks.NGSISink.processNewBatches(NGSISink.java:558)
    at com.telefonica.iot.cygnus.sinks.NGSISink.process(NGSISink.java:370)
    at org.apache.flume.sink.DefaultSinkProcessor.process(DefaultSinkProcessor.java:68)
    at org.apache.flume.SinkRunner$PollingRunner.run(SinkRunner.java:147)
    at java.lang.Thread.run(Thread.java:748)
AlvaroVega commented 6 years ago

https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/interceptors/NGSIEvent.java#L175

Instead of return attrs.get(0).getName(); check attrs array:

           if (attrs && attrs.get(0)) {
                return attrs.get(0).getName(); // the CE has been filtered for having just one attribute
            } else {
                return '';
            }