Search in sources :

Example 11 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class ListenBeats method customValidate.

@Override
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    final List<ValidationResult> results = new ArrayList<>();
    final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
        results.add(new ValidationResult.Builder().explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly").valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    }
    return results;
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 12 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class TestReportLineageToAtlas method validateAtlasUrls.

@Test
public void validateAtlasUrls() throws Exception {
    final ReportLineageToAtlas reportingTask = new ReportLineageToAtlas();
    final MockProcessContext processContext = new MockProcessContext(reportingTask);
    final MockValidationContext validationContext = new MockValidationContext(processContext);
    processContext.setProperty(ATLAS_NIFI_URL, "http://nifi.example.com:8080/nifi");
    processContext.setProperty(ATLAS_USER, "admin");
    processContext.setProperty(ATLAS_PASSWORD, "admin");
    BiConsumer<Collection<ValidationResult>, Consumer<ValidationResult>> assertResults = (rs, a) -> {
        assertTrue(rs.iterator().hasNext());
        for (ValidationResult r : rs) {
            logger.info("{}", r);
            final String subject = r.getSubject();
            if (ATLAS_URLS.getDisplayName().equals(subject)) {
                a.accept(r);
            }
        }
    };
    // Default setting.
    assertResults.accept(reportingTask.validate(validationContext), r -> assertTrue("Atlas URLs is required", !r.isValid()));
    // Invalid URL.
    processContext.setProperty(ATLAS_URLS, "invalid");
    assertResults.accept(reportingTask.validate(validationContext), r -> assertTrue("Atlas URLs is invalid", !r.isValid()));
    // Valid URL
    processContext.setProperty(ATLAS_URLS, "http://atlas.example.com:21000");
    assertTrue(processContext.isValid());
    // Valid URL with Expression
    processContext.setProperty(ATLAS_URLS, "http://atlas.example.com:${literal(21000)}");
    assertTrue(processContext.isValid());
    // Valid URLs
    processContext.setProperty(ATLAS_URLS, "http://atlas1.example.com:21000, http://atlas2.example.com:21000");
    assertTrue(processContext.isValid());
    // Invalid and Valid URLs
    processContext.setProperty(ATLAS_URLS, "invalid, http://atlas2.example.com:21000");
    assertResults.accept(reportingTask.validate(validationContext), r -> assertTrue("Atlas URLs is invalid", !r.isValid()));
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ATLAS_NIFI_URL(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_NIFI_URL) Consumer(java.util.function.Consumer) MockValidationContext(org.apache.nifi.util.MockValidationContext) ATLAS_USER(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_USER) MockProcessContext(org.apache.nifi.util.MockProcessContext) ATLAS_URLS(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_URLS) BiConsumer(java.util.function.BiConsumer) ATLAS_PASSWORD(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_PASSWORD) ValidationResult(org.apache.nifi.components.ValidationResult) Consumer(java.util.function.Consumer) BiConsumer(java.util.function.BiConsumer) MockValidationContext(org.apache.nifi.util.MockValidationContext) Collection(java.util.Collection) ValidationResult(org.apache.nifi.components.ValidationResult) MockProcessContext(org.apache.nifi.util.MockProcessContext) Test(org.junit.Test)

Example 13 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class TestRegexClusterResolver method testEmptyPattern.

@Test
public void testEmptyPattern() {
    final Map<String, String> properties = new HashMap<>();
    final String propertyName = RegexClusterResolver.PATTERN_PROPERTY_PREFIX + "Cluster1";
    properties.put(propertyName, "");
    setupMock(properties);
    final RegexClusterResolver resolver = new RegexClusterResolver();
    final Collection<ValidationResult> validationResults = resolver.validate(validationContext);
    Assert.assertEquals(1, validationResults.size());
    final ValidationResult validationResult = validationResults.iterator().next();
    Assert.assertEquals(propertyName, validationResult.getSubject());
    try {
        resolver.configure(context);
        Assert.fail("Configure method should fail, too");
    } catch (IllegalArgumentException e) {
    }
}
Also used : HashMap(java.util.HashMap) ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 14 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class AbstractCredentialsStrategy method validate.

@Override
public Collection<ValidationResult> validate(final ValidationContext validationContext, final CredentialsStrategy primaryStrategy) {
    boolean thisIsSelectedStrategy = this == primaryStrategy;
    String requiredMessageFormat = "property %1$s must be set with %2$s";
    String excludedMessageFormat = "property %1$s cannot be used with %2$s";
    String failureFormat = thisIsSelectedStrategy ? requiredMessageFormat : excludedMessageFormat;
    Collection<ValidationResult> validationFailureResults = null;
    for (PropertyDescriptor requiredProperty : requiredProperties) {
        boolean requiredPropertyIsSet = validationContext.getProperty(requiredProperty).isSet();
        if (requiredPropertyIsSet != thisIsSelectedStrategy) {
            String message = String.format(failureFormat, requiredProperty.getDisplayName(), primaryStrategy.getName());
            if (validationFailureResults == null) {
                validationFailureResults = new ArrayList<ValidationResult>();
            }
            validationFailureResults.add(new ValidationResult.Builder().subject(requiredProperty.getDisplayName()).valid(false).explanation(message).build());
        }
    }
    return validationFailureResults;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 15 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class StandardProcessorTestRunner method assertNotValid.

@Override
public void assertNotValid(final ControllerService service) {
    final StateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
        throw new IllegalStateException("Controller Service has not been added to this TestRunner via the #addControllerService method");
    }
    final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service);
    final Collection<ValidationResult> results = context.getControllerService(service.getIdentifier()).validate(validationContext);
    for (final ValidationResult result : results) {
        if (!result.isValid()) {
            return;
        }
    }
    Assert.fail("Expected Controller Service " + service + " to be invalid but it is valid");
}
Also used : MockStateManager(org.apache.nifi.state.MockStateManager) StateManager(org.apache.nifi.components.state.StateManager) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext)

Aggregations

ValidationResult (org.apache.nifi.components.ValidationResult)153 ArrayList (java.util.ArrayList)63 Test (org.junit.Test)56 ValidationContext (org.apache.nifi.components.ValidationContext)36 MockProcessContext (org.apache.nifi.util.MockProcessContext)26 TestRunner (org.apache.nifi.util.TestRunner)21 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)20 Validator (org.apache.nifi.components.Validator)20 HashSet (java.util.HashSet)18 ProcessContext (org.apache.nifi.processor.ProcessContext)15 HashMap (java.util.HashMap)12 File (java.io.File)11 Collection (java.util.Collection)11 SSLContextService (org.apache.nifi.ssl.SSLContextService)11 Map (java.util.Map)10 List (java.util.List)9 ComponentLog (org.apache.nifi.logging.ComponentLog)9 IOException (java.io.IOException)8 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)8 KerberosCredentialsService (org.apache.nifi.kerberos.KerberosCredentialsService)8