@Override public Config validate(Map<String, String> connectorConfigs) { Configuration config = Configuration.from(connectorConfigs); // First, validate all of the individual fields, which is easy since don't make any of the fields invisible ... Map<String, ConfigValue> results = config.validate(MongoDbConnectorConfig.EXPOSED_FIELDS); // Get the config values for each of the connection-related fields ... ConfigValue hostsValue = results.get(MongoDbConnectorConfig.HOSTS.name()); ConfigValue userValue = results.get(MongoDbConnectorConfig.USER.name()); ConfigValue passwordValue = results.get(MongoDbConnectorConfig.PASSWORD.name()); // If there are no errors on any of these ... if (hostsValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty()) { // Try to connect to the database ... try (ConnectionContext connContext = new ConnectionContext(config)) { try ( MongoClient client = connContext.clientFor(connContext.hosts()) ) { client.listDatabaseNames(); } } catch (MongoException e) { hostsValue.addErrorMessage("Unable to connect: " + e.getMessage()); } } return new Config(new ArrayList<>(results.values())); } }
protected ConfigValue configValue(Config config, String fieldName) { return config.configValues().stream().filter(value -> value.name().equals(fieldName)).findFirst().orElse(null); }
return new Config(new ArrayList<>(results.values()));
@Test public void shouldValidateMinimalConfiguration() throws Exception { Configuration config = TestHelper.defaultConfig().build(); Config validateConfig = new PostgresConnector().validate(config.asMap()); validateConfig.configValues().forEach(configValue -> assertTrue("Unexpected error for: " + configValue.name(), configValue.errorMessages().isEmpty())); }
return new Config(new ArrayList<>(results.values()));
protected ConfigValue configValue(Config config, String fieldName) { return config.configValues().stream().filter(value -> value.name().equals(fieldName)).findFirst().orElse(null); }
/** * Validate the connector configuration values against configuration definitions. * @param connectorConfigs the provided configuration values * @return List of Config, each Config contains the updated configuration information given * the current configuration values. */ public Config validate(Map<String, String> connectorConfigs) { ConfigDef configDef = config(); if (null == configDef) { throw new ConnectException( String.format("%s.config() must return a ConfigDef that is not null.", this.getClass().getName()) ); } List<ConfigValue> configValues = configDef.validate(connectorConfigs); return new Config(configValues); }
configValues.addAll(config.configValues()); return generateResult(connType, configKeys, configValues, new ArrayList<>(allGroups)); } finally {
return new Config(new ArrayList<>(results.values()));
@Test public void shouldValidateMinimalConfiguration() throws Exception { Configuration config = TestHelper.defaultConfig().build(); Config validateConfig = new PostgresConnector().validate(config.asMap()); validateConfig.configValues().forEach(configValue -> assertTrue("Unexpected error for: " + configValue.name(), configValue.errorMessages().isEmpty())); }