Reputation: 410
I am relatively new to NiFi in general. I am working on a custom controller service. I also have a cassandra connection provider controller service set up in my flow.
My question is, how do I get the session from the existing cassandra connection provider in my custom controller service as a property (or otherwise) so I can use the connection to write/run queries from my custom controller service?
I have something I built that compiles and I thought would work but is not quite there.
In my pom for the custom controller service I add the dependency:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-cassandra-services-api</artifactId>
<version>1.13.2</version>
</dependency>
Which allows me to add a property descriptor to my custom controller service:
public static final PropertyDescriptor CONNECTION_PROVIDER_SERVICE = new PropertyDescriptor.Builder()
.name("cassandra-connection-provider")
.displayName("Cassandra Connection Provider")
.description("Specifies the Cassandra connection providing controller service.")
.required(true)
.identifiesControllerService(CassandraSessionProviderService.class)
.build();
When I add the custom controller service to my flow, the property is there but empty. It does not show my existing cassandra connection provider as an option and I cannot create one either. It just says: "No controller service types found that are applicable for this property."
I suspect the problem has something to do with my custom controller service's property wanting a CassandraSessionProviderService.class from my project, not the one that exists in the nifi bundles already because the tooltip on the property says it is expecting it to be from my project whereas the existing one is from the nifi-cassandra-services project. Even if I add a second dependency on the nifi-cassandra-services module, it allows me to create the connection provider service, but it is a version from my project, not the standard so that does not work since it will no longer work with the standard processors.
I guess as a general question, is it possible, and if so how would I set up dependencies properly to use the standard controller service bundles inside custom controller services?
Upvotes: 0
Views: 508
Reputation: 410
I think I've figured it out. Adding the -api dependency was good enough, since it was an interface, to allow compilation and is needed like mentioned above. But you also have to have the -api-nar dependency in the custom controller service's -api-nar module.
Like this:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-cassandra-services-api-nar</artifactId>
<version>1.13.2</version>
<type>nar</type>
</dependency>
The nar pom will probably already have a nar dependency on nifi-standard-services-api-nar
though and when you compile there will be an error saying you can only have one nar dependency. This is due to the nar hierarchy requirments. Can read more here: https://github.com/apache/nifi/blob/main/nifi-docs/src/main/asciidoc/developer-guide.adoc if interested (it is toward the bottom.)
But basically what I think this means is you get rid of the nifi-standard-services-api-nar
dependency in favor of the nifi-cassandra-services-api-nar
because the cassandra nar already references the standard services nar. So you are creating that parent-child hierarchy by adding cassandra service bundle as the nar dependency. This should then compile and allow the cassandra connection service to be referenced in the custom controller service.
Upvotes: 1