Validating Processor Properties

A Processor is not able to be started if its configuration is not valid. Validation of a Processor property can be achieved by setting a Validator on a PropertyDescriptor or by restricting the allowable values for a property via the PropertyDescriptor.Builder's allowableValues method or identifiesControllerService method.

In addition, if a property is dependent on another property (by means of the PropertyDescriptor.Builder's `dependsOn method) and the dependency is not satisfied, then the Property will be validated.

For example, consider the following two Property Descriptors:


         PropertyDescriptor USE_FILE = new PropertyDescriptor.Buildler()
    .name("Use File")
    .displayName("Use File")
    .required(true)
    .allowableValues("true", "false")
    .defaultValue("true")
    .build();
      

         PropertyDescriptor FILE = new PropertyDescriptor.Builder()
    .name("File to Use")
    .displayName("File to Use")
    .required(true)
    .addValidator(StandardValidators.FILE_EXISTS_VALIDATOR)
    .dependsOn(USE_FILE, "true")
    .build();
      

In this case, if the "Use File" property is set to true, then the Processor will not be valid unless the "File to Use" property is set to a valid filename. If "Use File" is set to true and "File to Use" does not have a value set, the Processor will be invalid (because the "File to Use" property is required). If "Use File" is set to true and "File to Use" has a value set but the specified file does not exist, the Processor will also be invalid because the "File to Use" property is invalid according to the Validator.

However, if the "Use File" property is set to false, then the "File to Use" property is said to have a dependency that is not satisfied. As a result, the "File to Use" property will not be considered in the validation. Therefore, if "Use File" is set to false and "File to Use" has no value said, the Processor will still be valid (even though "File to Use" is required, it is only required if "Use File" is true). Likewise, if "File to Use" is set to a non-existent filename such as /file/that/does/not/exist, the Processor will still be valid so long as the "Use File" property is set to false.

Furthermore, the "File to Use" property will not even be shown in the NiFi UI unless "Use File" is set to true.

There are times, though, when validating a Processor's properties individually is not sufficient. For this purpose, the AbstractProcessor exposes a customValidate method. The method takes a single argument of type ValidationContext. The return value of this method is a Collection of ValidationResult objects that describe any problems that were found during validation. Only those ValidationResult objects whose isValid method returns false should be returned. This method will be invoked only if all properties are valid according to their associated Validators and Allowable Values. I.e., this method will be called only if all properties are valid in-and-of themselves, and this method allows for validation of a Processor's configuration as a whole.