value = parseType(key.name, props.get(key.name), key.type); } catch (ConfigException e) { config.addErrorMessage(e.getMessage()); config.addErrorMessage("Missing required configuration \"" + key.name + "\" which has no default value."); } else { value = key.defaultValue; key.validator.ensureValid(key.name, value); } catch (ConfigException e) { config.addErrorMessage(e.getMessage());
public Map<String, ConfigValue> validateAll(Map<String, String> props) { Map<String, ConfigValue> configValues = new HashMap<>(); for (String name: configKeys.keySet()) { configValues.put(name, new ConfigValue(name)); } List<String> undefinedConfigKeys = undefinedDependentConfigs(); for (String undefinedConfigKey: undefinedConfigKeys) { ConfigValue undefinedConfigValue = new ConfigValue(undefinedConfigKey); undefinedConfigValue.addErrorMessage(undefinedConfigKey + " is referred in the dependents, but not defined."); undefinedConfigValue.visible(false); configValues.put(undefinedConfigKey, undefinedConfigValue); } Map<String, Object> parsed = parseForValidate(props, configValues); return validate(parsed, configValues); }
private void validate(String name, Map<String, Object> parsed, Map<String, ConfigValue> configs) { if (!configKeys.containsKey(name)) { return; } ConfigKey key = configKeys.get(name); ConfigValue value = configs.get(name); if (key.recommender != null) { try { List<Object> recommendedValues = key.recommender.validValues(name, parsed); List<Object> originalRecommendedValues = value.recommendedValues(); if (!originalRecommendedValues.isEmpty()) { Set<Object> originalRecommendedValueSet = new HashSet<>(originalRecommendedValues); recommendedValues.removeIf(o -> !originalRecommendedValueSet.contains(o)); } value.recommendedValues(recommendedValues); value.visible(key.recommender.visible(name, parsed)); } catch (ConfigException e) { value.addErrorMessage(e.getMessage()); } } configs.put(name, value); for (String dependent: key.dependents) { validate(dependent, parsed, configs); } }
value.addErrorMessage(problem); }); value.addErrorMessage(e.getMessage());
@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())); } }
logger.info("Failed testing connection for {} with user '{}'", connection.connectionString(), connection.username()); hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage());
} catch (SQLException e) { logger.info("Failed testing connection for {} with user '{}'", jdbcContext.connectionString(), mysql.username()); hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage()); } finally { jdbcContext.shutdown();
/** * Validate the supplied fields in this configuration. Extra fields not described by the supplied {@code fields} parameter * are not validated. * * @param fields the fields * @return the {@link ConfigValue} for each of the fields; never null */ default Map<String, ConfigValue> validate(Field.Set fields) { // Create a map of configuration values for each field ... Map<String, ConfigValue> configValuesByFieldName = new HashMap<>(); fields.forEach(field -> { configValuesByFieldName.put(field.name(), new ConfigValue(field.name())); }); // If any dependents don't exist ... fields.forEachMissingDependent(missingDepedent -> { ConfigValue undefinedConfigValue = new ConfigValue(missingDepedent); undefinedConfigValue.addErrorMessage(missingDepedent + " is referred in the dependents, but not defined."); undefinedConfigValue.visible(false); configValuesByFieldName.put(missingDepedent, undefinedConfigValue); }); // Now validate each top-level field ... fields.forEachTopLevelField(field -> { field.validate(this, fields::fieldWithName, configValuesByFieldName); }); return configValuesByFieldName; }
@Override protected Map<String, ConfigValue> validateBasicConnectorConfig(Connector connector, ConfigDef configDef, Map<String, String> config) { Map<String, ConfigValue> validatedConfig = super.validateBasicConnectorConfig(connector, configDef, config); if (connector instanceof SinkConnector) { ConfigValue validatedName = validatedConfig.get(ConnectorConfig.NAME_CONFIG); String name = (String) validatedName.value(); if (workerGroupId.equals(SinkUtils.consumerGroupId(name))) { validatedName.addErrorMessage("Consumer group for sink connector named " + name + " conflicts with Connect worker group " + workerGroupId); } } return validatedConfig; }
public static ConfigInfos generateResult(String connType, Map<String, ConfigKey> configKeys, List<ConfigValue> configValues, List<String> groups) { int errorCount = 0; List<ConfigInfo> configInfoList = new LinkedList<>(); Map<String, ConfigValue> configValueMap = new HashMap<>(); for (ConfigValue configValue: configValues) { String configName = configValue.name(); configValueMap.put(configName, configValue); if (!configKeys.containsKey(configName)) { configValue.addErrorMessage("Configuration is not defined: " + configName); configInfoList.add(new ConfigInfo(null, convertConfigValue(configValue, null))); } } for (Map.Entry<String, ConfigKey> entry : configKeys.entrySet()) { String configName = entry.getKey(); ConfigKeyInfo configKeyInfo = convertConfigKey(entry.getValue()); Type type = entry.getValue().type; ConfigValueInfo configValueInfo = null; if (configValueMap.containsKey(configName)) { ConfigValue configValue = configValueMap.get(configName); configValueInfo = convertConfigValue(configValue, type); errorCount += configValue.errorMessages().size(); } configInfoList.add(new ConfigInfo(configKeyInfo, configValueInfo)); } return new ConfigInfos(connType, errorCount, groups, configInfoList); }
value.addErrorMessage(problem); }); value.addErrorMessage(e.getMessage());
logger.info("Failed testing connection for {} with user '{}'", connection.connectionString(), connection.username()); hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage());
/** * Validate the supplied fields in this configuration. Extra fields not described by the supplied {@code fields} parameter * are not validated. * * @param fields the fields * @return the {@link ConfigValue} for each of the fields; never null */ default Map<String, ConfigValue> validate(Field.Set fields) { // Create a map of configuration values for each field ... Map<String, ConfigValue> configValuesByFieldName = new HashMap<>(); fields.forEach(field -> { configValuesByFieldName.put(field.name(), new ConfigValue(field.name())); }); // If any dependents don't exist ... fields.forEachMissingDependent(missingDepedent -> { ConfigValue undefinedConfigValue = new ConfigValue(missingDepedent); undefinedConfigValue.addErrorMessage(missingDepedent + " is referred in the dependents, but not defined."); undefinedConfigValue.visible(false); configValuesByFieldName.put(missingDepedent, undefinedConfigValue); }); // Now validate each top-level field ... fields.forEachTopLevelField(field -> { field.validate(this, fields::fieldWithName, configValuesByFieldName); }); return configValuesByFieldName; }
validator.accept(config); } catch (Exception ex) { result.get(validator.name).addErrorMessage(ex.getMessage());
validator.accept(config); } catch (Exception ex) { result.get(validator.name).addErrorMessage(ex.getMessage());