use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class StandardProcessorTestRunner method setProperty.
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) {
final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
if (serviceStateManager == null) {
throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
}
final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);
final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service);
final ValidationResult validationResult = property.validate(value, validationContext);
final String oldValue = updatedProps.get(property);
updatedProps.put(property, value);
configuration.setProperties(updatedProps);
if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
service.onPropertyModified(property, oldValue, value);
}
return validationResult;
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class TestStandardProcessorTestRunner method testControllerServiceUpdateShouldCallOnSetProperty.
@Test
public void testControllerServiceUpdateShouldCallOnSetProperty() {
// Arrange
final ControllerService testService = new SimpleTestService();
final AddAttributeProcessor proc = new AddAttributeProcessor();
final TestRunner runner = TestRunners.newTestRunner(proc);
final String serviceIdentifier = "test";
final String pdName = "name";
final String pdValue = "exampleName";
try {
runner.addControllerService(serviceIdentifier, testService);
} catch (InitializationException e) {
fail(e.getMessage());
}
assertFalse("onPropertyModified has been called", ((SimpleTestService) testService).isOpmCalled());
// Act
ValidationResult vr = runner.setProperty(testService, pdName, pdValue);
// Assert
assertTrue(vr.isValid());
ControllerServiceConfiguration csConf = ((MockProcessContext) runner.getProcessContext()).getConfiguration(serviceIdentifier);
PropertyDescriptor propertyDescriptor = testService.getPropertyDescriptor(pdName);
String retrievedPDValue = csConf.getProperties().get(propertyDescriptor);
assertEquals(pdValue, retrievedPDValue);
assertTrue("onPropertyModified has not been called", ((SimpleTestService) testService).isOpmCalled());
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class ReportLineageToAtlas method customValidate.
@Override
protected Collection<ValidationResult> customValidate(ValidationContext context) {
final Collection<ValidationResult> results = new ArrayList<>();
final boolean isSSLContextServiceSet = context.getProperty(SSL_CONTEXT_SERVICE).isSet();
final ValidationResult.Builder invalidSSLService = new ValidationResult.Builder().subject(SSL_CONTEXT_SERVICE.getDisplayName()).valid(false);
parseAtlasUrls(context.getProperty(ATLAS_URLS), input -> {
final ValidationResult.Builder builder = new ValidationResult.Builder().subject(ATLAS_URLS.getDisplayName()).input(input);
try {
final URL url = new URL(input);
if ("https".equalsIgnoreCase(url.getProtocol()) && !isSSLContextServiceSet) {
results.add(invalidSSLService.explanation("required by HTTPS Atlas access").build());
} else {
results.add(builder.explanation("Valid URI").valid(true).build());
}
} catch (Exception e) {
results.add(builder.explanation("Contains invalid URI: " + e).valid(false).build());
}
});
final String atlasAuthNMethod = context.getProperty(ATLAS_AUTHN_METHOD).getValue();
final AtlasAuthN atlasAuthN = getAtlasAuthN(atlasAuthNMethod);
results.addAll(atlasAuthN.validate(context));
clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(context)));
if (context.getProperty(ATLAS_CONF_CREATE).asBoolean()) {
Stream.of(ATLAS_CONF_DIR, ATLAS_DEFAULT_CLUSTER_NAME, KAFKA_BOOTSTRAP_SERVERS).filter(p -> !context.getProperty(p).isSet()).forEach(p -> results.add(new ValidationResult.Builder().subject(p.getDisplayName()).explanation("required to create Atlas configuration file.").valid(false).build()));
validateKafkaProperties(context, results, isSSLContextServiceSet, invalidSSLService);
}
return results;
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class ReportLineageToAtlas method validateKafkaProperties.
private void validateKafkaProperties(ValidationContext context, Collection<ValidationResult> results, boolean isSSLContextServiceSet, ValidationResult.Builder invalidSSLService) {
final String kafkaSecurityProtocol = context.getProperty(KAFKA_SECURITY_PROTOCOL).getValue();
if ((SEC_SSL.equals(kafkaSecurityProtocol) || SEC_SASL_SSL.equals(kafkaSecurityProtocol)) && !isSSLContextServiceSet) {
results.add(invalidSSLService.explanation("required by SSL Kafka connection").build());
}
final String explicitPrincipal = context.getProperty(NIFI_KERBEROS_PRINCIPAL).evaluateAttributeExpressions().getValue();
final String explicitKeytab = context.getProperty(NIFI_KERBEROS_KEYTAB).evaluateAttributeExpressions().getValue();
final KerberosCredentialsService credentialsService = context.getProperty(ReportLineageToAtlas.KERBEROS_CREDENTIALS_SERVICE).asControllerService(KerberosCredentialsService.class);
String principal;
String keytab;
if (credentialsService == null) {
principal = explicitPrincipal;
keytab = explicitKeytab;
} else {
principal = credentialsService.getPrincipal();
keytab = credentialsService.getKeytab();
}
if (SEC_SASL_PLAINTEXT.equals(kafkaSecurityProtocol) || SEC_SASL_SSL.equals(kafkaSecurityProtocol)) {
if (!context.getProperty(KAFKA_KERBEROS_SERVICE_NAME).isSet()) {
results.add(new ValidationResult.Builder().subject(KAFKA_KERBEROS_SERVICE_NAME.getDisplayName()).explanation("Required by Kafka SASL authentication.").valid(false).build());
}
if (keytab == null || principal == null) {
results.add(new ValidationResult.Builder().subject("Kerberos Authentication").explanation("Keytab and Principal are required for Kerberos authentication with Apache Kafka.").valid(false).build());
}
}
}
use of org.apache.nifi.components.ValidationResult in project nifi by apache.
the class RegexClusterResolver method validate.
@Override
public Collection<ValidationResult> validate(ValidationContext validationContext) {
final List<ValidationResult> validationResults = new ArrayList<>();
consumeConfigurations(validationContext.getAllProperties(), (clusterNamePatterns, patterns) -> {
}, (entry, e) -> {
final ValidationResult result = new ValidationResult.Builder().subject(entry.getKey()).input(entry.getValue()).explanation(e.getMessage()).valid(false).build();
validationResults.add(result);
});
return validationResults;
}
Aggregations