Search in sources :

Example 96 with ValidationResult

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

the class ThriftConnectionPool method createMultipleFilesExistValidator.

/**
 * Validates that one or more files exist, as specified in a single property.
 *
 * @return a validator which describes the result of the validation
 */
public static final Validator createMultipleFilesExistValidator() {
    return new Validator() {

        @Override
        public ValidationResult validate(String subject, String input, ValidationContext context) {
            final String[] files = input.split(",");
            for (String filename : files) {
                try {
                    final File file = new File(filename.trim());
                    final boolean valid = file.exists() && file.isFile();
                    if (!valid) {
                        final String message = "File " + file + " does not exist or is not a file";
                        return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation(message).build();
                    }
                } catch (SecurityException e) {
                    final String message = "Unable to access " + filename + " due to " + e.getMessage();
                    return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation(message).build();
                }
            }
            return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
        }
    };
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) File(java.io.File) Validator(org.apache.nifi.components.Validator) ValidationContext(org.apache.nifi.components.ValidationContext)

Example 97 with ValidationResult

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

the class TdchExportHiveToTeradataTest method testTeradataStagingTable.

@Test
public void testTeradataStagingTable() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    TdchConnectionService tdchConnectionService = new DummyTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertValid(tdchConnectionService);
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "hive_table");
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "teradata_db.teradata_table");
    runner.assertValid();
    Assert.assertEquals(null, runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE_NAME).getDefaultValue());
    Assert.assertFalse(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE_NAME).isRequired());
    Assert.assertTrue(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE_NAME).isExpressionLanguageSupported());
    ValidationResult result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE, "td_staging_table");
    Assert.assertTrue(result.isValid());
    result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE, "");
    Assert.assertFalse(result.isValid());
    runner.removeProperty(TdchExportHiveToTeradata.TERADATA_STAGING_TABLE);
    runner.assertValid();
}
Also used : DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) TestRunner(org.apache.nifi.util.TestRunner) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 98 with ValidationResult

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

the class StandardControllerServiceNode method verifyCanEnable.

@Override
public void verifyCanEnable(final Set<ControllerServiceNode> ignoredReferences) {
    if (getState() != ControllerServiceState.DISABLED) {
        throw new IllegalStateException(getControllerServiceImplementation().getIdentifier() + " cannot be enabled because it is not disabled");
    }
    final Set<String> ids = new HashSet<>();
    for (final ControllerServiceNode node : ignoredReferences) {
        ids.add(node.getIdentifier());
    }
    final Collection<ValidationResult> validationResults = getValidationErrors(ids);
    for (final ValidationResult result : validationResults) {
        if (!result.isValid()) {
            throw new IllegalStateException(getControllerServiceImplementation().getIdentifier() + " cannot be enabled because it is not valid: " + result);
        }
    }
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) HashSet(java.util.HashSet)

Example 99 with ValidationResult

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

the class ListenSMTP method customValidate.

@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    List<ValidationResult> results = new ArrayList<>();
    String clientAuth = validationContext.getProperty(CLIENT_AUTH).getValue();
    SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null && !StringUtils.hasText(clientAuth)) {
        results.add(new ValidationResult.Builder().subject(CLIENT_AUTH.getDisplayName()).explanation(CLIENT_AUTH.getDisplayName() + " must be provided when using " + SSL_CONTEXT_SERVICE.getDisplayName()).valid(false).build());
    } else if (sslContextService == null && StringUtils.hasText(clientAuth)) {
        results.add(new ValidationResult.Builder().subject(SSL_CONTEXT_SERVICE.getDisplayName()).explanation(SSL_CONTEXT_SERVICE.getDisplayName() + " must be provided when selecting " + CLIENT_AUTH.getDisplayName()).valid(false).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 100 with ValidationResult

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

the class ExecuteFlumeSinkTest method testValidators.

@Test
public void testValidators() {
    TestRunner runner = TestRunners.newTestRunner(ExecuteFlumeSink.class);
    Collection<ValidationResult> results;
    ProcessContext pc;
    results = new HashSet<>();
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        logger.debug(vr.toString());
        Assert.assertTrue(vr.toString().contains("is invalid because Sink Type is required"));
    }
    // non-existent class
    results = new HashSet<>();
    runner.setProperty(ExecuteFlumeSink.SINK_TYPE, "invalid.class.name");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        logger.debug(vr.toString());
        Assert.assertTrue(vr.toString().contains("is invalid because unable to load sink"));
    }
    // class doesn't implement Sink
    results = new HashSet<>();
    runner.setProperty(ExecuteFlumeSink.SINK_TYPE, AvroSource.class.getName());
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        logger.debug(vr.toString());
        Assert.assertTrue(vr.toString().contains("is invalid because unable to create sink"));
    }
    results = new HashSet<>();
    runner.setProperty(ExecuteFlumeSink.SINK_TYPE, NullSink.class.getName());
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(0, results.size());
}
Also used : AvroSource(org.apache.flume.source.AvroSource) NullSink(org.apache.flume.sink.NullSink) TestRunner(org.apache.nifi.util.TestRunner) ValidationResult(org.apache.nifi.components.ValidationResult) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) MockProcessContext(org.apache.nifi.util.MockProcessContext) Test(org.junit.Test)

Aggregations

ValidationResult (org.apache.nifi.components.ValidationResult)179 Test (org.junit.Test)80 ArrayList (java.util.ArrayList)64 TestRunner (org.apache.nifi.util.TestRunner)46 ValidationContext (org.apache.nifi.components.ValidationContext)37 MockProcessContext (org.apache.nifi.util.MockProcessContext)26 TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)23 Validator (org.apache.nifi.components.Validator)21 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)20 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)18 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)18 HashSet (java.util.HashSet)18 ProcessContext (org.apache.nifi.processor.ProcessContext)15 File (java.io.File)12 HashMap (java.util.HashMap)12 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