Search in sources :

Example 56 with ConfigDef

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

the class ConnectorConfig method enrich.

/**
 * Returns an enriched {@link ConfigDef} building upon the {@code ConfigDef}, using the current configuration specified in {@code props} as an input.
 * <p>
 * {@code requireFullConfig} specifies whether required config values that are missing should cause an exception to be thrown.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ConfigDef enrich(Plugins plugins, ConfigDef baseConfigDef, Map<String, String> props, boolean requireFullConfig) {
    ConfigDef newDef = new ConfigDef(baseConfigDef);
    new EnrichablePlugin<Transformation<?>>("Transformation", TRANSFORMS_CONFIG, TRANSFORMS_GROUP, (Class) Transformation.class, props, requireFullConfig) {

        @SuppressWarnings("rawtypes")
        @Override
        protected Set<PluginDesc<Transformation<?>>> plugins() {
            return plugins.transformations();
        }

        @Override
        protected ConfigDef initialConfigDef() {
            // All Transformations get these config parameters implicitly
            return super.initialConfigDef().define(PredicatedTransformation.PREDICATE_CONFIG, Type.STRING, "", Importance.MEDIUM, "The alias of a predicate used to determine whether to apply this transformation.").define(PredicatedTransformation.NEGATE_CONFIG, Type.BOOLEAN, false, Importance.MEDIUM, "Whether the configured predicate should be negated.");
        }

        @Override
        protected Stream<Map.Entry<String, ConfigDef.ConfigKey>> configDefsForClass(String typeConfig) {
            return super.configDefsForClass(typeConfig).filter(entry -> {
                // The implicit parameters mask any from the transformer with the same name
                if (PredicatedTransformation.PREDICATE_CONFIG.equals(entry.getKey()) || PredicatedTransformation.NEGATE_CONFIG.equals(entry.getKey())) {
                    log.warn("Transformer config {} is masked by implicit config of that name", entry.getKey());
                    return false;
                } else {
                    return true;
                }
            });
        }

        @Override
        protected ConfigDef config(Transformation<?> transformation) {
            return transformation.config();
        }

        @Override
        protected void validateProps(String prefix) {
            String prefixedNegate = prefix + PredicatedTransformation.NEGATE_CONFIG;
            String prefixedPredicate = prefix + PredicatedTransformation.PREDICATE_CONFIG;
            if (props.containsKey(prefixedNegate) && !props.containsKey(prefixedPredicate)) {
                throw new ConfigException("Config '" + prefixedNegate + "' was provided " + "but there is no config '" + prefixedPredicate + "' defining a predicate to be negated.");
            }
        }
    }.enrich(newDef);
    new EnrichablePlugin<Predicate<?>>("Predicate", PREDICATES_CONFIG, PREDICATES_GROUP, (Class) Predicate.class, props, requireFullConfig) {

        @Override
        protected Set<PluginDesc<Predicate<?>>> plugins() {
            return plugins.predicates();
        }

        @Override
        protected ConfigDef config(Predicate<?> predicate) {
            return predicate.config();
        }
    }.enrich(newDef);
    return newDef;
}
Also used : Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) Range.atLeast(org.apache.kafka.common.config.ConfigDef.Range.atLeast) Type(org.apache.kafka.common.config.ConfigDef.Type) LoggerFactory(org.slf4j.LoggerFactory) PluginDesc(org.apache.kafka.connect.runtime.isolation.PluginDesc) ArrayList(java.util.ArrayList) Transformation(org.apache.kafka.connect.transforms.Transformation) HashSet(java.util.HashSet) ToleranceType(org.apache.kafka.connect.runtime.errors.ToleranceType) Locale(java.util.Locale) Width(org.apache.kafka.common.config.ConfigDef.Width) Map(java.util.Map) Importance(org.apache.kafka.common.config.ConfigDef.Importance) LinkedHashSet(java.util.LinkedHashSet) ConfigDef(org.apache.kafka.common.config.ConfigDef) Utils(org.apache.kafka.common.utils.Utils) ValidString.in(org.apache.kafka.common.config.ConfigDef.ValidString.in) Logger(org.slf4j.Logger) ConnectRecord(org.apache.kafka.connect.connector.ConnectRecord) Set(java.util.Set) ConfigException(org.apache.kafka.common.config.ConfigException) Collectors(java.util.stream.Collectors) List(java.util.List) NonEmptyStringWithoutControlChars.nonEmptyStringWithoutControlChars(org.apache.kafka.common.config.ConfigDef.NonEmptyStringWithoutControlChars.nonEmptyStringWithoutControlChars) Stream(java.util.stream.Stream) Predicate(org.apache.kafka.connect.transforms.predicates.Predicate) AbstractConfig(org.apache.kafka.common.config.AbstractConfig) ConnectException(org.apache.kafka.connect.errors.ConnectException) Modifier(java.lang.reflect.Modifier) Collections(java.util.Collections) Transformation(org.apache.kafka.connect.transforms.Transformation) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ConfigException(org.apache.kafka.common.config.ConfigException) Predicate(org.apache.kafka.connect.transforms.predicates.Predicate) Stream(java.util.stream.Stream) ConfigDef(org.apache.kafka.common.config.ConfigDef) Map(java.util.Map)

Example 57 with ConfigDef

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

the class TopicCreationConfig method defaultGroupConfigDef.

public static ConfigDef defaultGroupConfigDef() {
    int orderInGroup = 0;
    ConfigDef configDef = new ConfigDef();
    configDef.define(INCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, ".*", new ConfigDef.NonNullValidator(), ConfigDef.Importance.LOW, INCLUDE_REGEX_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, "Inclusion Topic Pattern for " + DEFAULT_TOPIC_CREATION_GROUP).define(EXCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), new ConfigDef.NonNullValidator(), ConfigDef.Importance.LOW, EXCLUDE_REGEX_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, "Exclusion Topic Pattern for " + DEFAULT_TOPIC_CREATION_GROUP).define(REPLICATION_FACTOR_CONFIG, ConfigDef.Type.SHORT, ConfigDef.NO_DEFAULT_VALUE, REPLICATION_FACTOR_VALIDATOR, ConfigDef.Importance.LOW, REPLICATION_FACTOR_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, "Replication Factor for Topics in " + DEFAULT_TOPIC_CREATION_GROUP).define(PARTITIONS_CONFIG, ConfigDef.Type.INT, ConfigDef.NO_DEFAULT_VALUE, PARTITIONS_VALIDATOR, ConfigDef.Importance.LOW, PARTITIONS_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, "Partition Count for Topics in " + DEFAULT_TOPIC_CREATION_GROUP);
    return configDef;
}
Also used : ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 58 with ConfigDef

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

the class TopicCreationConfig method configDef.

public static ConfigDef configDef(String group, short defaultReplicationFactor, int defaultParitionCount) {
    int orderInGroup = 0;
    ConfigDef configDef = new ConfigDef();
    configDef.define(INCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), REGEX_VALIDATOR, ConfigDef.Importance.LOW, INCLUDE_REGEX_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, "Inclusion Topic Pattern for " + group).define(EXCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), REGEX_VALIDATOR, ConfigDef.Importance.LOW, EXCLUDE_REGEX_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, "Exclusion Topic Pattern for " + group).define(REPLICATION_FACTOR_CONFIG, ConfigDef.Type.SHORT, defaultReplicationFactor, REPLICATION_FACTOR_VALIDATOR, ConfigDef.Importance.LOW, REPLICATION_FACTOR_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, "Replication Factor for Topics in " + group).define(PARTITIONS_CONFIG, ConfigDef.Type.INT, defaultParitionCount, PARTITIONS_VALIDATOR, ConfigDef.Importance.LOW, PARTITIONS_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, "Partition Count for Topics in " + group);
    return configDef;
}
Also used : ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 59 with ConfigDef

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

the class QuotaConfigs method userConfigs.

public static ConfigDef userConfigs() {
    ConfigDef configDef = new ConfigDef();
    ScramMechanism.mechanismNames().forEach(mechanismName -> {
        configDef.define(mechanismName, ConfigDef.Type.STRING, null, ConfigDef.Importance.MEDIUM, "User credentials for SCRAM mechanism " + mechanismName);
    });
    buildUserClientQuotaConfigDef(configDef);
    return configDef;
}
Also used : ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 60 with ConfigDef

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

the class QuotaConfigs method clientConfigs.

public static ConfigDef clientConfigs() {
    ConfigDef configDef = new ConfigDef();
    buildUserClientQuotaConfigDef(configDef);
    return configDef;
}
Also used : 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