Search in sources :

Example 26 with ConfigInfos

use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.

the class AbstractHerderTest method testGenerateResultWithConfigValuesMoreThanConfigKeysAndWithSomeErrors.

@Test
public void testGenerateResultWithConfigValuesMoreThanConfigKeysAndWithSomeErrors() {
    String name = "com.acme.connector.MyConnector";
    Map<String, ConfigDef.ConfigKey> keys = new HashMap<>();
    addConfigKey(keys, "config.a1", null);
    addConfigKey(keys, "config.b1", "group B");
    addConfigKey(keys, "config.b2", "group B");
    addConfigKey(keys, "config.c1", "group C");
    List<String> groups = Arrays.asList("groupB", "group C");
    List<ConfigValue> values = new ArrayList<>();
    addValue(values, "config.a1", "value.a1");
    addValue(values, "config.b1", "value.b1");
    addValue(values, "config.b2", "value.b2");
    addValue(values, "config.c1", "value.c1", "error c1");
    addValue(values, "config.extra1", "value.extra1");
    addValue(values, "config.extra2", "value.extra2", "error extra2");
    ConfigInfos infos = AbstractHerder.generateResult(name, keys, values, groups);
    assertEquals(name, infos.name());
    assertEquals(groups, infos.groups());
    assertEquals(values.size(), infos.values().size());
    assertEquals(2, infos.errorCount());
    assertInfoKey(infos, "config.a1", null);
    assertInfoKey(infos, "config.b1", "group B");
    assertInfoKey(infos, "config.b2", "group B");
    assertInfoKey(infos, "config.c1", "group C");
    assertNoInfoKey(infos, "config.extra1");
    assertNoInfoKey(infos, "config.extra2");
    assertInfoValue(infos, "config.a1", "value.a1");
    assertInfoValue(infos, "config.b1", "value.b1");
    assertInfoValue(infos, "config.b2", "value.b2");
    assertInfoValue(infos, "config.c1", "value.c1", "error c1");
    assertInfoValue(infos, "config.extra1", "value.extra1");
    assertInfoValue(infos, "config.extra2", "value.extra2", "error extra2");
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with ConfigInfos

use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.

the class AbstractHerder method validateClientOverrides.

private static ConfigInfos validateClientOverrides(String connName, String prefix, AbstractConfig connectorConfig, ConfigDef configDef, Class<? extends Connector> connectorClass, org.apache.kafka.connect.health.ConnectorType connectorType, ConnectorClientConfigRequest.ClientType clientType, ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) {
    int errorCount = 0;
    List<ConfigInfo> configInfoList = new LinkedList<>();
    Map<String, ConfigKey> configKeys = configDef.configKeys();
    Set<String> groups = new LinkedHashSet<>();
    Map<String, Object> clientConfigs = new HashMap<>();
    for (Map.Entry<String, Object> rawClientConfig : connectorConfig.originalsWithPrefix(prefix).entrySet()) {
        String configName = rawClientConfig.getKey();
        Object rawConfigValue = rawClientConfig.getValue();
        ConfigKey configKey = configDef.configKeys().get(configName);
        Object parsedConfigValue = configKey != null ? ConfigDef.parseType(configName, rawConfigValue, configKey.type) : rawConfigValue;
        clientConfigs.put(configName, parsedConfigValue);
    }
    ConnectorClientConfigRequest connectorClientConfigRequest = new ConnectorClientConfigRequest(connName, connectorType, connectorClass, clientConfigs, clientType);
    List<ConfigValue> configValues = connectorClientConfigOverridePolicy.validate(connectorClientConfigRequest);
    if (configValues != null) {
        for (ConfigValue validatedConfigValue : configValues) {
            ConfigKey configKey = configKeys.get(validatedConfigValue.name());
            ConfigKeyInfo configKeyInfo = null;
            if (configKey != null) {
                if (configKey.group != null) {
                    groups.add(configKey.group);
                }
                configKeyInfo = convertConfigKey(configKey, prefix);
            }
            ConfigValue configValue = new ConfigValue(prefix + validatedConfigValue.name(), validatedConfigValue.value(), validatedConfigValue.recommendedValues(), validatedConfigValue.errorMessages());
            if (configValue.errorMessages().size() > 0) {
                errorCount++;
            }
            ConfigValueInfo configValueInfo = convertConfigValue(configValue, configKey != null ? configKey.type : null);
            configInfoList.add(new ConfigInfo(configKeyInfo, configValueInfo));
        }
    }
    return new ConfigInfos(connectorClass.toString(), errorCount, new ArrayList<>(groups), configInfoList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConnectorClientConfigRequest(org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest) ConfigValue(org.apache.kafka.common.config.ConfigValue) ConfigKey(org.apache.kafka.common.config.ConfigDef.ConfigKey) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) LinkedList(java.util.LinkedList) ConfigValueInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigValueInfo) ConfigKeyInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigKeyInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)

Example 28 with ConfigInfos

use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.

the class AbstractHerder method generateResult.

// public for testing
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)) {
            configInfoList.add(new ConfigInfo(null, convertConfigValue(configValue, null)));
            errorCount += configValue.errorMessages().size();
        }
    }
    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);
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) ConfigKey(org.apache.kafka.common.config.ConfigDef.ConfigKey) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) LinkedList(java.util.LinkedList) Type(org.apache.kafka.common.config.ConfigDef.Type) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) ConfigValueInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigValueInfo) ConfigKeyInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigKeyInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)

Example 29 with ConfigInfos

use of org.apache.kafka.connect.runtime.rest.entities.ConfigInfos in project kafka by apache.

the class ConnectorPluginsResourceTest method testValidateConfigWithAlias.

@Test
public void testValidateConfigWithAlias() throws Throwable {
    Capture<Callback<ConfigInfos>> configInfosCallback = EasyMock.newCapture();
    herder.validateConnectorConfig(EasyMock.eq(props), EasyMock.capture(configInfosCallback), EasyMock.anyBoolean());
    PowerMock.expectLastCall().andAnswer((IAnswer<ConfigInfos>) () -> {
        ConfigDef connectorConfigDef = ConnectorConfig.configDef();
        List<ConfigValue> connectorConfigValues = connectorConfigDef.validate(props);
        Connector connector = new ConnectorPluginsResourceTestConnector();
        Config config = connector.validate(props);
        ConfigDef configDef = connector.config();
        Map<String, ConfigDef.ConfigKey> configKeys = configDef.configKeys();
        List<ConfigValue> configValues = config.configValues();
        Map<String, ConfigDef.ConfigKey> resultConfigKeys = new HashMap<>(configKeys);
        resultConfigKeys.putAll(connectorConfigDef.configKeys());
        configValues.addAll(connectorConfigValues);
        ConfigInfos configInfos = AbstractHerder.generateResult(ConnectorPluginsResourceTestConnector.class.getName(), resultConfigKeys, configValues, Collections.singletonList("Test"));
        configInfosCallback.getValue().onCompletion(null, configInfos);
        return null;
    });
    PowerMock.replayAll();
    // make a request to connector-plugins resource using a valid alias.
    ConfigInfos configInfos = connectorPluginsResource.validateConfigs("ConnectorPluginsResourceTest", props);
    assertEquals(CONFIG_INFOS.name(), configInfos.name());
    assertEquals(0, configInfos.errorCount());
    assertEquals(CONFIG_INFOS.groups(), configInfos.groups());
    assertEquals(new HashSet<>(CONFIG_INFOS.values()), new HashSet<>(configInfos.values()));
    PowerMock.verifyAll();
}
Also used : TestSourceConnector(org.apache.kafka.connect.runtime.TestSourceConnector) SourceConnector(org.apache.kafka.connect.source.SourceConnector) VerifiableSourceConnector(org.apache.kafka.connect.tools.VerifiableSourceConnector) MockSinkConnector(org.apache.kafka.connect.tools.MockSinkConnector) MockSourceConnector(org.apache.kafka.connect.tools.MockSourceConnector) VerifiableSinkConnector(org.apache.kafka.connect.tools.VerifiableSinkConnector) MockConnector(org.apache.kafka.connect.tools.MockConnector) Connector(org.apache.kafka.connect.connector.Connector) SchemaSourceConnector(org.apache.kafka.connect.tools.SchemaSourceConnector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) TestSinkConnector(org.apache.kafka.connect.runtime.TestSinkConnector) Callback(org.apache.kafka.connect.util.Callback) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) Config(org.apache.kafka.common.config.Config) Arrays.asList(java.util.Arrays.asList) List(java.util.List) LinkedList(java.util.LinkedList) ConfigDef(org.apache.kafka.common.config.ConfigDef) Map(java.util.Map) HashMap(java.util.HashMap) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ConfigInfos (org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)29 HashMap (java.util.HashMap)23 Test (org.junit.Test)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Map (java.util.Map)16 ConfigDef (org.apache.kafka.common.config.ConfigDef)13 ConfigValue (org.apache.kafka.common.config.ConfigValue)13 Connector (org.apache.kafka.connect.connector.Connector)13 SourceConnector (org.apache.kafka.connect.source.SourceConnector)13 List (java.util.List)12 LinkedList (java.util.LinkedList)11 ArrayList (java.util.ArrayList)10 ConfigInfo (org.apache.kafka.connect.runtime.rest.entities.ConfigInfo)9 Config (org.apache.kafka.common.config.Config)8 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)7 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)7 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)7 MockConnector (org.apache.kafka.connect.tools.MockConnector)7 MockSinkConnector (org.apache.kafka.connect.tools.MockSinkConnector)7 MockSourceConnector (org.apache.kafka.connect.tools.MockSourceConnector)7