Search in sources :

Example 41 with ValidationResult

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

the class ExtractText method customValidate.

@Override
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    final List<ValidationResult> problems = new ArrayList<>(super.customValidate(validationContext));
    // If the capture group zero is not going to be included, each dynamic property must have at least one group
    final boolean includeCaptureGroupZero = validationContext.getProperty(INCLUDE_CAPTURE_GROUP_ZERO).getValue().equalsIgnoreCase("true");
    getLogger().debug("Include capture group zero is " + includeCaptureGroupZero);
    if (!includeCaptureGroupZero) {
        final Validator oneGroupMinimumValidator = StandardValidators.createRegexValidator(1, 40, true);
        for (Map.Entry<PropertyDescriptor, String> prop : validationContext.getProperties().entrySet()) {
            PropertyDescriptor pd = prop.getKey();
            if (pd.isDynamic()) {
                String value = validationContext.getProperty(pd).getValue();
                getLogger().debug("Evaluating dynamic property " + pd.getDisplayName() + " (" + pd.getName() + ") with value " + value);
                ValidationResult result = oneGroupMinimumValidator.validate(pd.getDisplayName(), value, validationContext);
                getLogger().debug("Validation result: " + result.toString());
                if (!result.isValid()) {
                    problems.add(result);
                }
            }
        }
    }
    return problems;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) HashMap(java.util.HashMap) Map(java.util.Map) Validator(org.apache.nifi.components.Validator)

Example 42 with ValidationResult

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

the class FetchDistributedMapCache method customValidate.

@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    PropertyValue cacheEntryIdentifier = validationContext.getProperty(PROP_CACHE_ENTRY_IDENTIFIER);
    boolean elPresent = false;
    try {
        elPresent = cacheEntryIdentifier.isExpressionLanguagePresent();
    } catch (NullPointerException npe) {
    // Unfortunate workaround to a mock framework bug (NIFI-4590)
    }
    if (elPresent) {
        // This doesn't do a full job of validating against the requirement that Put Cache Value In Attribute must be set if multiple
        // Cache Entry Identifiers are supplied (if Expression Language is used). The user could conceivably have a comma-separated list of EL statements,
        // or a single EL statement with commas inside it but that evaluates to a single item.
        results.add(new ValidationResult.Builder().valid(true).explanation("Contains Expression Language").build());
    } else {
        if (!validationContext.getProperty(FetchDistributedMapCache.PROP_PUT_CACHE_VALUE_IN_ATTRIBUTE).isSet()) {
            String identifierString = cacheEntryIdentifier.getValue();
            if (identifierString.contains(",")) {
                results.add(new ValidationResult.Builder().valid(false).explanation("Multiple Cache Entry Identifiers specified without Put Cache Value In Attribute set").build());
            }
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) PropertyValue(org.apache.nifi.components.PropertyValue) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 43 with ValidationResult

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

the class PutSplunk method customValidate.

@Override
protected Collection<ValidationResult> customValidate(final ValidationContext context) {
    final Collection<ValidationResult> results = new ArrayList<>();
    final String protocol = context.getProperty(PROTOCOL).getValue();
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (UDP_VALUE.getValue().equals(protocol) && sslContextService != null) {
        results.add(new ValidationResult.Builder().explanation("SSL can not be used with UDP").valid(false).subject("SSL Context").build());
    }
    return results;
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 44 with ValidationResult

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

the class RedisStateProvider method customValidate.

@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    final List<ValidationResult> results = new ArrayList<>(RedisUtils.validate(validationContext));
    final RedisType redisType = RedisType.fromDisplayName(validationContext.getProperty(RedisUtils.REDIS_MODE).getValue());
    if (redisType != null && redisType == RedisType.CLUSTER) {
        results.add(new ValidationResult.Builder().subject(RedisUtils.REDIS_MODE.getDisplayName()).valid(false).explanation(RedisUtils.REDIS_MODE.getDisplayName() + " is configured in clustered mode, and this service requires a non-clustered Redis").build());
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) RedisType(org.apache.nifi.redis.RedisType)

Example 45 with ValidationResult

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

the class TestAvroSchemaRegistry method validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties.

@Test
public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() throws Exception {
    String schemaName = "fooSchema";
    ConfigurationContext configContext = mock(ConfigurationContext.class);
    Map<PropertyDescriptor, String> properties = new HashMap<>();
    PropertyDescriptor fooSchema = new PropertyDescriptor.Builder().name(schemaName).dynamic(true).build();
    // NOTE: name of record and name of first field are not Avro-compliant, verified below
    String fooSchemaText = "{\"namespace\": \"example.avro\", " + "\"type\": \"record\", " + "\"name\": \"$User\", " + "\"fields\": [ " + "{\"name\": \"@name\", \"type\": [\"string\", \"null\"]}, " + "{\"name\": \"favorite_number\",  \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"foo\",  \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]} " + "]" + "}";
    PropertyDescriptor barSchema = new PropertyDescriptor.Builder().name("barSchema").dynamic(false).build();
    properties.put(fooSchema, fooSchemaText);
    properties.put(barSchema, "");
    AvroSchemaRegistry delegate = new AvroSchemaRegistry();
    delegate.getSupportedPropertyDescriptors().forEach(prop -> properties.put(prop, prop.getDisplayName()));
    when(configContext.getProperties()).thenReturn(properties);
    ValidationContext validationContext = mock(ValidationContext.class);
    when(validationContext.getProperties()).thenReturn(properties);
    PropertyValue propertyValue = mock(PropertyValue.class);
    when(validationContext.getProperty(AvroSchemaRegistry.VALIDATE_FIELD_NAMES)).thenReturn(propertyValue);
    // Strict parsing
    when(propertyValue.asBoolean()).thenReturn(true);
    Collection<ValidationResult> results = delegate.customValidate(validationContext);
    assertTrue(results.stream().anyMatch(result -> !result.isValid()));
    // Non-strict parsing
    when(propertyValue.asBoolean()).thenReturn(false);
    results = delegate.customValidate(validationContext);
    results.forEach(result -> assertTrue(result.isValid()));
}
Also used : ValidationContext(org.apache.nifi.components.ValidationContext) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SchemaNotFoundException(org.apache.nifi.schema.access.SchemaNotFoundException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) PropertyValue(org.apache.nifi.components.PropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Map(java.util.Map) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ValidationResult(org.apache.nifi.components.ValidationResult) Mockito.mock(org.mockito.Mockito.mock) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) PropertyValue(org.apache.nifi.components.PropertyValue) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext) Test(org.junit.Test)

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