Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Make Global connection to hbase in nif custom processor?

avatar
Explorer

Need to make global connection to hbase in nifi custom processor with the connection properties (/etc/hbase/conf/hbase-site.xml and /etc/hadoop/conf/core-site.xml) value read from the flow file. I tried to do that but it reads from ProcessContext value which i got in onTriggerMethod so not able to make global connection. Can any one suggest how can i do this?

1 ACCEPTED SOLUTION

avatar
Master Guru

I'm not sure I understand the question...

There is a controller service called HBaseClientService which would be the connection to HBase, and then your processor can declare a property like:

static final PropertyDescriptor HBASE_CLIENT_SERVICE = new PropertyDescriptor.Builder()
        .name("HBase Client Service")
        .description("Specifies the Controller Service to use for accessing HBase.")
        .required(true)
        .identifiesControllerService(HBaseClientService.class)
        .build();

Then in your onTrigger method you get the service by doing:

HBaseClientService clientService = context.getProperty(HBASE_CLIENT_SERVICE)
	.asControllerService(HBaseClientService.class);

You can look at how the existing HBase processors work:

https://github.com/apache/nifi/tree/master/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors

View solution in original post

3 REPLIES 3

avatar
Master Guru

I'm not sure I understand the question...

There is a controller service called HBaseClientService which would be the connection to HBase, and then your processor can declare a property like:

static final PropertyDescriptor HBASE_CLIENT_SERVICE = new PropertyDescriptor.Builder()
        .name("HBase Client Service")
        .description("Specifies the Controller Service to use for accessing HBase.")
        .required(true)
        .identifiesControllerService(HBaseClientService.class)
        .build();

Then in your onTrigger method you get the service by doing:

HBaseClientService clientService = context.getProperty(HBASE_CLIENT_SERVICE)
	.asControllerService(HBaseClientService.class);

You can look at how the existing HBase processors work:

https://github.com/apache/nifi/tree/master/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors

avatar
Explorer

Thanks for the rply i got this but my need is to make HBase connection outside onTrigger method by using the HBASE_CLIENT_SERVICE property value. Becuase onTrigger method will be called every time flowfile comes and it will go every time to make connection. Dont need to make connection every time.

avatar
Master Guru

If you want to get the HBaseClientService outside of onTrigger you can do the following...

private volatile HBaseClientService service;

@OnScheduled
public void onScheduled(ProcessContext context) {
  this.service = context.getProperty(HBASE_CLIENT_SERVICE)
           .asControllerService(HBaseClientService.class);
}	

A method annotated with @OnScheduled will be called one time when the processor is first started.

Also, keep in mind that getting the HBaseClientService every time in onTrigger is totally fine because its not making a new connection every time. The connection is made when HBaseClientService is first started, and then you would just be getting access to that existing connection each time in onTrigger.