org.apache.kafka.common.config.Config Java Examples

The following examples show how to use org.apache.kafka.common.config.Config. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonSinkClickHouseConnector.java    From kafka-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public Config validate(Map<String, String> connectorConfigs) {
    ConfigDef configDef = config();
    Map<String, ConfigValue> configValues = ClickHouseConfigDef.emptyValidate(connectorConfigs, configDef);
    JdbcDataSource dataSource = ClickHouseConfigDef.clickHouseConnectValidate(configValues);
    String sinkDb = connectorConfigs.get(CLICKHOUSE_SINK_DATABASE);
    ConfigValue sinkTablesVal = configValues.get(CLICKHOUSE_SINK_TABLES);
    ConfigValue sinkLocalTablesVal = configValues.get(CLICKHOUSE_SINK_LOCAL_TABLES);
    String topics = connectorConfigs.get(TOPICS);

    validateTables(sinkTablesVal, sinkLocalTablesVal, topics);

    ClickHouseConfigDef.clusterTableExist(dataSource, sinkTablesVal, sinkDb);
    ClickHouseConfigDef.localTableExist(dataSource, sinkLocalTablesVal, sinkDb);
    ClickHouseConfigDef.validateSinkDateColumns(configValues, dataSource, sinkDb, sinkTablesVal);
    ClickHouseConfigDef.validateSourceDateColumns(configValues, dataSource, sinkTablesVal);
    ClickHouseConfigDef.validateDateFormat(configValues, dataSource, sinkTablesVal);

    if (dataSource != null) {
        dataSource.close();
    }
    return new Config(new LinkedList<>(configValues.values()));
}
 
Example #2
Source File: MySqlSinkClickHouseConnector.java    From kafka-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Config validate(Map<String, String> connectorConfigs) {
    ConfigDef configDef = config();
    Map<String, ConfigValue> configValues = ClickHouseConfigDef.emptyValidate(connectorConfigs, configDef);
    JdbcDataSource dataSource = ClickHouseConfigDef.clickHouseConnectValidate(configValues);
    tableValidate(dataSource, connectorConfigs, configValues);
    if (dataSource != null) {
        dataSource.close();
    }
    return new Config(new LinkedList<>(configValues.values()));
}
 
Example #3
Source File: Utils.java    From snowflake-kafka-connector with Apache License 2.0 5 votes vote down vote up
public static boolean isSingleFieldValid(Config result)
{
  // if any single field validation failed
  for (ConfigValue v : result.configValues())
  {
    if (!v.errorMessages().isEmpty())
    {
      return false;
    }
  }
  // if any of url, user, schema, database or password is empty
  // update error message and return false
  boolean isValidate = true;
  final String errorMsg = " must be provided";
  Map<String, ConfigValue> validateMap = validateConfigToMap(result);
  //
  for (String prop : loginPropList)
  {
    if (validateMap.get(prop).value() == null)
    {
      updateConfigErrorMessage(result, prop, errorMsg);
      isValidate = false;
    }
  }

  return isValidate;
}
 
Example #4
Source File: Utils.java    From snowflake-kafka-connector with Apache License 2.0 5 votes vote down vote up
public static Map<String, ConfigValue> validateConfigToMap(final Config result)
{
  Map<String, ConfigValue> validateMap = new HashMap<>();
  for (ConfigValue v : result.configValues())
  {
    validateMap.put(v.name(), v);
  }
  return validateMap;
}
 
Example #5
Source File: Utils.java    From snowflake-kafka-connector with Apache License 2.0 5 votes vote down vote up
public static void updateConfigErrorMessage(Config result, String key, String msg)
{
  for (ConfigValue v : result.configValues())
  {
    if (v.name().equals(key))
    {
      v.addErrorMessage(key + msg);
    }
  }
}
 
Example #6
Source File: ConnectionValidator.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
public static Optional<ConfigValue> getConfigByName(final Config config, final String name) {
  for (final ConfigValue configValue : config.configValues()) {
    if (configValue.name().equals(name)) {
      return Optional.of(configValue);
    }
  }
  return Optional.empty();
}
 
Example #7
Source File: ConnectorValidationTest.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
private void assertValidSource(final Map<String, String> properties) {
  assumeTrue(isReplicaSetOrSharded());
  Config config = new MongoSourceConnector().validate(properties);
  List<String> errorMessages =
      getConfigValue(config, MongoSourceConfig.CONNECTION_URI_CONFIG).errorMessages();
  assertTrue(errorMessages.isEmpty(), format("ErrorMessages not empty: %s", errorMessages));
}
 
Example #8
Source File: ConnectorTest.java    From snowflake-kafka-connector with Apache License 2.0 4 votes vote down vote up
private static Map<String, ConfigValue> toValidateMap(final Map<String, String> config)
{
  SnowflakeSinkConnector sinkConnector = new SnowflakeSinkConnector();
  Config result = sinkConnector.validate(config);
  return Utils.validateConfigToMap(result);
}
 
Example #9
Source File: ConnectorValidationTest.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
private void assertInvalidSource(final Map<String, String> properties) {
  Config config = new MongoSourceConnector().validate(properties);
  List<String> errorMessages =
      getConfigValue(config, MongoSourceConfig.CONNECTION_URI_CONFIG).errorMessages();
  assertFalse(errorMessages.isEmpty(), "ErrorMessages shouldn't be empty");
}
 
Example #10
Source File: ConnectorValidationTest.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
private void assertInvalidSink(final Map<String, String> properties) {
  Config config = new MongoSinkConnector().validate(properties);
  List<String> errorMessages =
      getConfigValue(config, MongoSourceConfig.CONNECTION_URI_CONFIG).errorMessages();
  assertFalse(errorMessages.isEmpty(), "ErrorMessages shouldn't be empty");
}
 
Example #11
Source File: ConnectorValidationTest.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
private void assertValidSink(final Map<String, String> properties) {
  Config config = new MongoSinkConnector().validate(properties);
  List<String> errorMessages =
      getConfigValue(config, MongoSourceConfig.CONNECTION_URI_CONFIG).errorMessages();
  assertTrue(errorMessages.isEmpty(), format("ErrorMessages not empty: %s", errorMessages));
}
 
Example #12
Source File: ConnectorValidationTest.java    From mongo-kafka with Apache License 2.0 4 votes vote down vote up
private ConfigValue getConfigValue(final Config config, final String configName) {
  return config.configValues().stream()
      .filter(cv -> cv.name().equals(configName))
      .collect(Collectors.toList())
      .get(0);
}
 
Example #13
Source File: HttpSinkConnector.java    From kafka-connect-http with Apache License 2.0 4 votes vote down vote up
@Override
public Config validate(Map<String, String> connectorConfigs) {
  // TODO cross-fields validation here: pkFields against the pkMode
  return super.validate(connectorConfigs);
}