Search in sources :

Example 51 with ConfigDef

use of org.apache.kafka.common.config.ConfigDef in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorPluginsResourceTest method testValidateConfigWithSingleErrorDueToMissingConnectorClassname.

@Test
public void testValidateConfigWithSingleErrorDueToMissingConnectorClassname() throws Throwable {
    herder.validateConnectorConfig(EasyMock.eq(partialProps));
    PowerMock.expectLastCall().andAnswer(new IAnswer<ConfigInfos>() {

        @Override
        public ConfigInfos answer() {
            ConfigDef connectorConfigDef = ConnectorConfig.configDef();
            List<ConfigValue> connectorConfigValues = connectorConfigDef.validate(partialProps);
            Connector connector = new ConnectorPluginsResourceTestConnector();
            Config config = connector.validate(partialProps);
            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);
            return AbstractHerder.generateResult(ConnectorPluginsResourceTestConnector.class.getName(), resultConfigKeys, configValues, Collections.singletonList("Test"));
        }
    });
    PowerMock.replayAll();
    // This call to validateConfigs does not throw a BadRequestException because we've mocked
    // validateConnectorConfig.
    ConfigInfos configInfos = connectorPluginsResource.validateConfigs(ConnectorPluginsResourceTestConnector.class.getSimpleName(), partialProps);
    assertEquals(PARTIAL_CONFIG_INFOS.name(), configInfos.name());
    assertEquals(PARTIAL_CONFIG_INFOS.errorCount(), configInfos.errorCount());
    assertEquals(PARTIAL_CONFIG_INFOS.groups(), configInfos.groups());
    assertEquals(new HashSet<>(PARTIAL_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) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) Config(org.apache.kafka.common.config.Config) 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)

Example 52 with ConfigDef

use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.

the class SaslChannelBuilderTest method testClientChannelBuilderWithBrokerConfigs.

/**
 * Verify that unparsed broker configs don't break clients. This is to ensure that clients
 * created by brokers are not broken if broker configs are passed to clients.
 */
@Test
public void testClientChannelBuilderWithBrokerConfigs() throws Exception {
    Map<String, Object> configs = new HashMap<>();
    CertStores certStores = new CertStores(false, "client", "localhost");
    configs.putAll(certStores.getTrustingConfig(certStores));
    configs.put(SaslConfigs.SASL_KERBEROS_SERVICE_NAME, "kafka");
    configs.putAll(new ConfigDef().withClientSaslSupport().parse(configs));
    for (Field field : BrokerSecurityConfigs.class.getFields()) {
        if (field.getName().endsWith("_CONFIG"))
            configs.put(field.get(BrokerSecurityConfigs.class).toString(), "somevalue");
    }
    SaslChannelBuilder plainBuilder = createChannelBuilder(SecurityProtocol.SASL_PLAINTEXT, "PLAIN");
    plainBuilder.configure(configs);
    SaslChannelBuilder gssapiBuilder = createChannelBuilder(SecurityProtocol.SASL_PLAINTEXT, "GSSAPI");
    gssapiBuilder.configure(configs);
    SaslChannelBuilder oauthBearerBuilder = createChannelBuilder(SecurityProtocol.SASL_PLAINTEXT, "OAUTHBEARER");
    oauthBearerBuilder.configure(configs);
    SaslChannelBuilder scramBuilder = createChannelBuilder(SecurityProtocol.SASL_PLAINTEXT, "SCRAM-SHA-256");
    scramBuilder.configure(configs);
    SaslChannelBuilder saslSslBuilder = createChannelBuilder(SecurityProtocol.SASL_SSL, "PLAIN");
    saslSslBuilder.configure(configs);
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ConfigDef(org.apache.kafka.common.config.ConfigDef) BrokerSecurityConfigs(org.apache.kafka.common.config.internals.BrokerSecurityConfigs) Test(org.junit.jupiter.api.Test)

Example 53 with ConfigDef

use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.

the class ConfigurationControlManager method getConfigValueDefault.

String getConfigValueDefault(ConfigResource.Type type, String key) {
    ConfigDef configDef = configDefs.get(type);
    if (configDef == null) {
        return null;
    }
    ConfigKey configKey = configDef.configKeys().get(key);
    if (configKey == null || !configKey.hasDefault()) {
        return null;
    }
    return ConfigDef.convertToString(configKey.defaultValue, configKey.type);
}
Also used : ConfigKey(org.apache.kafka.common.config.ConfigDef.ConfigKey) ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 54 with ConfigDef

use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.

the class ConnectorConfigTest method testEnrichedConfigDef.

@Test
public void testEnrichedConfigDef() {
    String alias = "hdt";
    String prefix = ConnectorConfig.TRANSFORMS_CONFIG + "." + alias + ".";
    Map<String, String> props = new HashMap<>();
    props.put(ConnectorConfig.TRANSFORMS_CONFIG, alias);
    props.put(prefix + "type", HasDuplicateConfigTransformation.class.getName());
    ConfigDef def = ConnectorConfig.enrich(MOCK_PLUGINS, new ConfigDef(), props, false);
    assertEnrichedConfigDef(def, prefix, HasDuplicateConfigTransformation.MUST_EXIST_KEY, ConfigDef.Type.BOOLEAN);
    assertEnrichedConfigDef(def, prefix, PredicatedTransformation.PREDICATE_CONFIG, ConfigDef.Type.STRING);
    assertEnrichedConfigDef(def, prefix, PredicatedTransformation.NEGATE_CONFIG, ConfigDef.Type.BOOLEAN);
}
Also used : HashMap(java.util.HashMap) ConfigDef(org.apache.kafka.common.config.ConfigDef) Test(org.junit.Test)

Example 55 with ConfigDef

use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.

the class JaasOptionsUtils method getSslClientConfig.

public Map<String, ?> getSslClientConfig() {
    ConfigDef sslConfigDef = new ConfigDef();
    sslConfigDef.withClientSslSupport();
    AbstractConfig sslClientConfig = new AbstractConfig(sslConfigDef, options);
    return sslClientConfig.values();
}
Also used : AbstractConfig(org.apache.kafka.common.config.AbstractConfig) ConfigDef(org.apache.kafka.common.config.ConfigDef)

Aggregations

ConfigDef (org.apache.kafka.common.config.ConfigDef)69 Config (org.apache.kafka.common.config.Config)29 Test (org.junit.Test)28 Connector (org.apache.kafka.connect.connector.Connector)27 SourceConnector (org.apache.kafka.connect.source.SourceConnector)26 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)24 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)23 HashMap (java.util.HashMap)20 ConfigValue (org.apache.kafka.common.config.ConfigValue)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 TaskConfig (org.apache.kafka.connect.runtime.TaskConfig)17 Map (java.util.Map)14 SinkConnectorConfig (org.apache.kafka.connect.runtime.SinkConnectorConfig)14 WorkerConfig (org.apache.kafka.connect.runtime.WorkerConfig)13 List (java.util.List)12 ArrayList (java.util.ArrayList)10 Herder (org.apache.kafka.connect.runtime.Herder)10 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)10 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)10 AbstractConfig (org.apache.kafka.common.config.AbstractConfig)9