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.

How to access custom properties in custom NiFi Controller Service?

Highlighted

How to access custom properties in custom NiFi Controller Service?

Explorer

I have custom controller service with few properties. Here is sample of one of them:

public static final PropertyDescriptor CONFIG_DELIMITER = new PropertyDescriptor.Builder()
        .name("Field delimiter to be used")
        .description("Field delimiter used to separate the fields in the cache data file...")
        .defaultValue(",")
        .expressionLanguageSupported(true)
        .required(true)
        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
        .build();

I have expressionLanguageSupported set to true for them with the idea of resolving them in onConfigred method of the service.

@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {
    configDelim = context.getProperty(CONFIG_DELIMITER).evaluateAttributeExpressions().getValue();
	..........    
}

I have created a custom properties file custom.properties with following content:

nifi.iSOS.MyService.delim=,

I have setup properties in my test as :

@Test
public void testService() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final MyService service = new MyService();
    runner.addControllerService("MyService", service);
    runner.setProperty(service, LookupService.CONFIG_DELIMITER , "${nifi.iSOS.MyService.delim}");
    ..........
}

I need help with 2 things:

  1. How to pass the custom properties file to the test for MyService?
  2. Is context.getProperty(CONFIG_DELIMITER).evaluateAttributeExpressions().getValue(); correct way to evaluate the value of the custom property in the controller service?

Big thank you for all the help...

2 REPLIES 2
Highlighted

Re: How to access custom properties in custom NiFi Controller Service?

1) You can't set a whole properties file during unit testing, but TestRunner has the following method:

void setVariable(String name, String value);

So just call setVariable("nifi.iSOS.MyService.delim", ",");

2) Yes that is correct.

Highlighted

Re: How to access custom properties in custom NiFi Controller Service?

Explorer

Thanks Bryan, it helped a lot.

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