Search in sources :

Example 1 with ConnectorClientConfigRequest

use of org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest in project kafka by apache.

the class Worker method connectorClientConfigOverrides.

private static Map<String, Object> connectorClientConfigOverrides(ConnectorTaskId id, ConnectorConfig connConfig, Class<? extends Connector> connectorClass, String clientConfigPrefix, ConnectorType connectorType, ConnectorClientConfigRequest.ClientType clientType, ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) {
    Map<String, Object> clientOverrides = connConfig.originalsWithPrefix(clientConfigPrefix);
    ConnectorClientConfigRequest connectorClientConfigRequest = new ConnectorClientConfigRequest(id.connector(), connectorType, connectorClass, clientOverrides, clientType);
    List<ConfigValue> configValues = connectorClientConfigOverridePolicy.validate(connectorClientConfigRequest);
    List<ConfigValue> errorConfigs = configValues.stream().filter(configValue -> configValue.errorMessages().size() > 0).collect(Collectors.toList());
    // These should be caught when the herder validates the connector configuration, but just in case
    if (errorConfigs.size() > 0) {
        throw new ConnectException("Client Config Overrides not allowed " + errorConfigs);
    }
    return clientOverrides;
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext) SinkUtils(org.apache.kafka.connect.util.SinkUtils) JsonConverterConfig(org.apache.kafka.connect.json.JsonConverterConfig) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) LoggerFactory(org.slf4j.LoggerFactory) ConnectorType(org.apache.kafka.connect.health.ConnectorType) OffsetStorageWriter(org.apache.kafka.connect.storage.OffsetStorageWriter) ErrorHandlingMetrics(org.apache.kafka.connect.runtime.errors.ErrorHandlingMetrics) CloseableOffsetStorageReader(org.apache.kafka.connect.storage.CloseableOffsetStorageReader) ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) Converter(org.apache.kafka.connect.storage.Converter) Map(java.util.Map) DeadLetterQueueReporter(org.apache.kafka.connect.runtime.errors.DeadLetterQueueReporter) OffsetBackingStore(org.apache.kafka.connect.storage.OffsetBackingStore) OffsetStorageReader(org.apache.kafka.connect.storage.OffsetStorageReader) ClassLoaderUsage(org.apache.kafka.connect.runtime.isolation.Plugins.ClassLoaderUsage) ConnectUtils(org.apache.kafka.connect.util.ConnectUtils) TopicCreationGroup(org.apache.kafka.connect.util.TopicCreationGroup) Time(org.apache.kafka.common.utils.Time) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) ConfigValue(org.apache.kafka.common.config.ConfigValue) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) Task(org.apache.kafka.connect.connector.Task) JsonConverter(org.apache.kafka.connect.json.JsonConverter) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) SourceTask(org.apache.kafka.connect.source.SourceTask) OffsetStorageReaderImpl(org.apache.kafka.connect.storage.OffsetStorageReaderImpl) Connector(org.apache.kafka.connect.connector.Connector) ConfigProvider(org.apache.kafka.common.config.provider.ConfigProvider) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TopicAdmin(org.apache.kafka.connect.util.TopicAdmin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) LogReporter(org.apache.kafka.connect.runtime.errors.LogReporter) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) HeaderConverter(org.apache.kafka.connect.storage.HeaderConverter) WorkerErrantRecordReporter(org.apache.kafka.connect.runtime.errors.WorkerErrantRecordReporter) MetricGroup(org.apache.kafka.connect.runtime.ConnectMetrics.MetricGroup) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) ExecutorService(java.util.concurrent.ExecutorService) SinkTask(org.apache.kafka.connect.sink.SinkTask) Utils(org.apache.kafka.common.utils.Utils) Callback(org.apache.kafka.connect.util.Callback) Logger(org.slf4j.Logger) ConnectorClientConfigRequest(org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) ClusterConfigState(org.apache.kafka.connect.runtime.distributed.ClusterConfigState) MetricNameTemplate(org.apache.kafka.common.MetricNameTemplate) TimeUnit(java.util.concurrent.TimeUnit) ConnectException(org.apache.kafka.connect.errors.ConnectException) RetryWithToleranceOperator(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator) Collections(java.util.Collections) ConnectorClientConfigRequest(org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest) ConfigValue(org.apache.kafka.common.config.ConfigValue) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 2 with ConnectorClientConfigRequest

use of org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest 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)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ConfigValue (org.apache.kafka.common.config.ConfigValue)2 ConnectorClientConfigRequest (org.apache.kafka.connect.connector.policy.ConnectorClientConfigRequest)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 AdminClientConfig (org.apache.kafka.clients.admin.AdminClientConfig)1 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)1