Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Make Global connection to hbase in nif custom processor?

Solved Go to solution

Make Global connection to hbase in nif custom processor?

New Contributor

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

Accepted Solutions

Re: Make Global connection to hbase in nif custom processor?

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

3 REPLIES 3

Re: Make Global connection to hbase in nif custom processor?

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

Re: Make Global connection to hbase in nif custom processor?

New Contributor

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.

Re: Make Global connection to hbase in nif custom processor?

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.

Don't have an account?
Coming from Hortonworks? Activate your account here