hermannpencole / nifi-config

Automatically deploy and configure Template on Nifi
Apache License 2.0
55 stars 39 forks source link

Null reference exception configuring a feed #26

Closed ennui93 closed 6 years ago

ennui93 commented 6 years ago

Looks like cd0eb20abeb8d75432d339ed307adb0fe161b351 introduced an issue whereby one will receive a null reference exception in the updateConfig phase, even when a connections element is present in the configuration.

$ java -jar nifi-config/target/nifi-deploy-config-1.1.14-SNAPSHOT.jar -nifi http://localhost:8079/nifi-api -branch "root > website > user_registrations" -conf ~/Documents/nifi-config/user_registrations_feed.json -m extractConfig
2017-11-20 16:05:13 | INFO  | [main] c.g.h.n.c.Main:96 - Starting config_nifi 1.1.14-SNAPSHOT on mode extractConfig
2017-11-20 16:05:14 | INFO  | [main] c.g.h.n.c.Main:124 - Communicate with nifi 1.0.0
2017-11-20 16:05:14 | INFO  | [main] c.g.h.n.c.Main:135 - The group configuration root > website > user_registrations is extrated on file ~/Documents/nifi-config/user_registrations_feed.json

$ java -jar nifi-config/target/nifi-deploy-config-1.1.14-SNAPSHOT.jar -nifi http://localhost:8079/nifi-api -branch "root > website > user_registrations" -m undeploy
2017-11-20 16:06:04 | INFO  | [main] c.g.h.n.c.Main:96 - Starting config_nifi 1.1.14-SNAPSHOT on mode undeploy
2017-11-20 16:06:05 | INFO  | [main] c.g.h.n.c.Main:124 - Communicate with nifi 1.0.0
2017-11-20 16:06:05 | INFO  | [main] c.g.h.n.c.s.ProcessorService:50 -  GetFile (d9f4653d-015f-1000-f71a-87b0a6ae3d0b) is already 
2017-11-20 16:06:05 | INFO  | [main] c.g.h.n.c.s.PortService:56 -  from_website (d9f6a2b8-015f-1000-ed97-684068c8c8b3) is already 
2017-11-20 16:06:05 | INFO  | [main] c.g.h.n.c.s.TemplateService:92 - [root, website, user_registrations] is stopped
2017-11-20 16:06:05 | INFO  | [main] c.g.h.n.c.Main:143 - The group root > website > user_registrations is deleted

$ java -jar nifi-config/target/nifi-deploy-config-1.1.14-SNAPSHOT.jar -nifi http://localhost:8079/nifi-api -branch "root > website > user_registrations" -conf ~/Documents/nifi-config/user_registrations_feed.xml -m deployTemplate
2017-11-20 16:06:23 | INFO  | [main] c.g.h.n.c.Main:96 - Starting config_nifi 1.1.14-SNAPSHOT on mode deployTemplate
2017-11-20 16:06:24 | INFO  | [main] c.g.h.n.c.Main:124 - Communicate with nifi 1.0.0
2017-11-20 16:06:25 | INFO  | [main] c.g.h.n.c.Main:139 - Template ~/Documents/nifi-config/user_registrations_feed.xml is installed on the group root > website > user_registrations

$ java -jar nifi-config/target/nifi-deploy-config-1.1.14-SNAPSHOT.jar -nifi http://localhost:8079/nifi-api -branch "root > website > user_registrations" -conf ~/Documents/nifi-config/user_registrations_feed.json -m updateConfig
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.Main:96 - Starting config_nifi 1.1.14-SNAPSHOT on mode updateConfig
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.Main:124 - Communicate with nifi 1.0.0
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.UpdateProcessorService:67 - Processing : user_registrations_feed.json
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.ProcessorService:50 -  GetFile (d9f4653d-015f-1000-8fa4-48c78110d6a2) is already 
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.PortService:56 -  from_website (d9f6a2b8-015f-1000-2de8-f95eeedcce19) is already 
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.UpdateProcessorService:77 - [root, website, user_registrations] is stopped
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.UpdateProcessorService:169 - Update processor : GetFile
2017-11-20 16:06:36 | INFO  | [main] c.g.h.n.c.s.UpdateProcessorService:199 - Updated : GetFile
Exception in thread "main" java.lang.NullPointerException
    at com.github.hermannpencole.nifi.config.service.CreateRouteService.createRoutes(CreateRouteService.java:316)
    at com.github.hermannpencole.nifi.config.service.UpdateProcessorService.updateByBranch(UpdateProcessorService.java:94)
    at com.github.hermannpencole.nifi.config.Main.main(Main.java:129)

This occurs because the InputStreamReader instance reader has read to the end of the stream at https://github.com/hermannpencole/nifi-config/blob/master/src/main/java/com/github/hermannpencole/nifi/config/service/UpdateProcessorService.java#L93 reads to the end of the stream and is no longer able to deserialize the configuration.

Template above is just a GetFile processor leading to an output port. See https://gist.githubusercontent.com/ennui93/dac1f2cff8301e268659539c6cc3f2d0/raw/d3723bad0a8854e86bcfcc169297b6f6d367944b/user_registrations_feed.xml

ennui93 commented 6 years ago

Looks like 4996e8f51db359d387a71bf8c53d02e25be49079 fixes the issue. Thanks! 👍