markap14 commented on code in PR #7874:
URL: https://github.com/apache/nifi/pull/7874#discussion_r1367027814
##########
nifi-api/src/main/java/org/apache/nifi/migration/PropertyConfiguration.java:
##########
@@ -128,10 +128,83 @@ default Optional<String>
getPropertyValue(PropertyDescriptor descriptor) {
return getPropertyValue(descriptor.getName());
}
+ /**
+ * Returns an optional value representing the "raw" value of the property
with the given name. The "raw" value is
+ * the value before any parameters are substituted.
+ *
+ * @param propertyName the name of the property
+ * @return an empty optional if the value is null or unset, else an
Optional representing the configured value
+ */
+ Optional<String> getRawPropertyValue(String propertyName);
+
+ /**
+ * Returns an optional value representing the "raw" value of the property
identified by the given descriptor. The "raw" value is
+ * the value before any parameters are substituted.
+ *
+ * @param descriptor the descriptor that identifies the property
+ * @return an empty optional if the value is null or unset, else an
Optional representing the configured value
+ */
+ default Optional<String> getRawPropertyValue(PropertyDescriptor
descriptor) {
+ return getRawPropertyValue(descriptor.getName());
+ }
+
/**
* Returns a map containing all of the configured properties
* @return a Map containing the names and values of all configured
properties
*/
Map<String, String> getProperties();
+ /**
+ * Returns a map containing all of the raw property values
+ *
+ * @return a Map containing the names and values of all configured
properties
+ */
+ Map<String, String> getRawProperties();
+
+ /**
+ * <p>
+ * Creates a new Controller Service of the given type and configures it
with the given property values. Note that if a Controller Service
+ * already exists within the same scope and with the same implementation
and configuration, a new service may not be created and instead
+ * the existing service may be used.
+ * </p>
+ *
+ * <p>
+ * This allows for properties that were previously defined in the
extension to be moved to a Controller Service. For example,
+ * consider a Processor that has "Username" and "Password" properties. In
the next version of the Processor, we want to support
+ * multiple types of authentication, and we delegate the authentication to
a Controller Service. Consider that the Controller Service
+ * implementation we wish to use has a classname of {@code
org.apache.nifi.services.authentication.UsernamePassword}. We might then
+ * use this method as such:
+ * </p>
+ *
+ * <pre><code>
+ * // Create a new Controller Service ofo type
org.apache.nifi.services.authentication.UsernamePassword whose Username and
Password
+ * // properties match those currently configured for this Processor.
+ * final Map<String, String> serviceProperties =
Map.of("Username", propertyConfiguration.getRawPropertyValue("Username"),
+ * "Password",
propertyConfiguration.getRawPropertyValue("Password"));
+ * final String serviceId =
propertyConfiguration.createControllerService("org.apache.nifi.services.authentication.UsernamePassword",
serviceProperties);
+ *
+ * // Set our Authentication Service property to point to this new
service.
+ * propertyConfiguration.setProperty(AUTHENTICATION_SERVICE,
serviceId);
+ *
+ * // Remove the Username and Password properties from this Processor,
since we are now going to use then Authentication Service.
+ * propertyConfiguration.removeProperty("Username");
+ * propertyConfiguration.removeProperty("Password");
+ * </code></pre>
+ *
+ * <p>
+ * Note the use of {@link #getRawPropertyValue(String)} here instead of
{@link #getPropertyValue(String)}. Because we want to set
+ * the new Controller Service's value to the same value as is currently
configured for the Processor's "Username" and "Password" properties,
+ * we use {@link #getRawPropertyValue(String)}. This ensures that if the
Processor is configured using Parameters, those Parameter
+ * references are still held by the Controller Service.
+ * </p>
+ *
+ * <p>
+ * Also note that this method expects the classname of the implementation,
not the classname of the interface.
+ * </p>
+ *
+ * @param implementationClassName the fully qualified classname of the
Controller Service implementation
+ * @param serviceProperties the property values to configure the
newly created Controller Service with
+ * @return an identifier for the Controller Service
+ */
+ String createControllerService(String implementationClassName, Map<String,
String> serviceProperties);
Review Comment:
Yeah, agreed. I don't love that it is needing to provide an explicit
implementation of the service, but at the same time - the whole point is to
allow backward compatibility and so it makes sense to declare that a specific
implementation is what is necessary. Since it does not affect what is allowed
to be configured, I think it's fair game.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]