Search in sources :

Example 81 with ConfigException

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

the class StreamsPartitionAssignor method configure.

/**
 * We need to have the PartitionAssignor and its StreamThread to be mutually accessible
 * since the former needs later's cached metadata while sending subscriptions,
 * and the latter needs former's returned assignment when adding tasks.
 * @throws KafkaException if the stream thread is not specified
 */
@Override
public void configure(final Map<String, ?> configs) {
    final StreamsConfig streamsConfig = new StreamsConfig(configs);
    // Setting the logger with the passed in client thread name
    logPrefix = String.format("stream-thread [%s] ", streamsConfig.getString(CommonClientConfigs.CLIENT_ID_CONFIG));
    final LogContext logContext = new LogContext(logPrefix);
    log = logContext.logger(getClass());
    final Object o = configs.get(StreamsConfig.InternalConfig.TASK_MANAGER_FOR_PARTITION_ASSIGNOR);
    if (o == null) {
        final KafkaException fatalException = new KafkaException("TaskManager is not specified");
        log.error(fatalException.getMessage(), fatalException);
        throw fatalException;
    }
    if (!(o instanceof TaskManager)) {
        final KafkaException fatalException = new KafkaException(String.format("%s is not an instance of %s", o.getClass().getName(), TaskManager.class.getName()));
        log.error(fatalException.getMessage(), fatalException);
        throw fatalException;
    }
    taskManager = (TaskManager) o;
    numStandbyReplicas = streamsConfig.getInt(StreamsConfig.NUM_STANDBY_REPLICAS_CONFIG);
    partitionGrouper = streamsConfig.getConfiguredInstance(StreamsConfig.PARTITION_GROUPER_CLASS_CONFIG, PartitionGrouper.class);
    final String userEndPoint = streamsConfig.getString(StreamsConfig.APPLICATION_SERVER_CONFIG);
    if (userEndPoint != null && !userEndPoint.isEmpty()) {
        try {
            final String host = getHost(userEndPoint);
            final Integer port = getPort(userEndPoint);
            if (host == null || port == null)
                throw new ConfigException(String.format("%s Config %s isn't in the correct format. Expected a host:port pair" + " but received %s", logPrefix, StreamsConfig.APPLICATION_SERVER_CONFIG, userEndPoint));
        } catch (final NumberFormatException nfe) {
            throw new ConfigException(String.format("%s Invalid port supplied in %s for config %s", logPrefix, userEndPoint, StreamsConfig.APPLICATION_SERVER_CONFIG));
        }
        this.userEndPoint = userEndPoint;
    }
    internalTopicManager = new InternalTopicManager(taskManager.adminClient, streamsConfig);
    copartitionedTopicsValidator = new CopartitionedTopicsValidator(logPrefix);
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) PartitionGrouper(org.apache.kafka.streams.processor.PartitionGrouper) KafkaException(org.apache.kafka.common.KafkaException) ConfigException(org.apache.kafka.common.config.ConfigException) StreamsConfig(org.apache.kafka.streams.StreamsConfig)

Example 82 with ConfigException

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

the class MockProducerInterceptor method configure.

@Override
public void configure(Map<String, ?> configs) {
    // ensure this method is called and expected configs are passed in
    Object o = configs.get(APPEND_STRING_PROP);
    if (o == null)
        throw new ConfigException("Mock producer interceptor expects configuration " + APPEND_STRING_PROP);
    if (o instanceof String)
        appendStr = (String) o;
    // clientId also must be in configs
    Object clientIdValue = configs.get(ProducerConfig.CLIENT_ID_CONFIG);
    if (clientIdValue == null)
        throw new ConfigException("Mock producer interceptor expects configuration " + ProducerConfig.CLIENT_ID_CONFIG);
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException)

Example 83 with ConfigException

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

the class KafkaOffsetBackingStore method configure.

@Override
public void configure(final WorkerConfig config) {
    String topic = config.getString(DistributedConfig.OFFSET_STORAGE_TOPIC_CONFIG);
    if (topic == null || topic.trim().length() == 0)
        throw new ConfigException("Offset storage topic must be specified");
    data = new HashMap<>();
    Map<String, Object> originals = config.originals();
    Map<String, Object> producerProps = new HashMap<>(originals);
    producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    producerProps.put(ProducerConfig.RETRIES_CONFIG, Integer.MAX_VALUE);
    Map<String, Object> consumerProps = new HashMap<>(originals);
    consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    Map<String, Object> adminProps = new HashMap<>(originals);
    NewTopic topicDescription = TopicAdmin.defineTopic(topic).compacted().partitions(config.getInt(DistributedConfig.OFFSET_STORAGE_PARTITIONS_CONFIG)).replicationFactor(config.getShort(DistributedConfig.OFFSET_STORAGE_REPLICATION_FACTOR_CONFIG)).build();
    offsetLog = createKafkaBasedLog(topic, producerProps, consumerProps, consumedCallback, topicDescription, adminProps);
}
Also used : HashMap(java.util.HashMap) ConfigException(org.apache.kafka.common.config.ConfigException) NewTopic(org.apache.kafka.clients.admin.NewTopic) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer)

Example 84 with ConfigException

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

the class KafkaStatusBackingStore method configure.

@Override
public void configure(final WorkerConfig config) {
    this.topic = config.getString(DistributedConfig.STATUS_STORAGE_TOPIC_CONFIG);
    if (this.topic == null || this.topic.trim().length() == 0)
        throw new ConfigException("Must specify topic for connector status.");
    Map<String, Object> originals = config.originals();
    Map<String, Object> producerProps = new HashMap<>(originals);
    producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    // we handle retries in this class
    producerProps.put(ProducerConfig.RETRIES_CONFIG, 0);
    Map<String, Object> consumerProps = new HashMap<>(originals);
    consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    Map<String, Object> adminProps = new HashMap<>(originals);
    NewTopic topicDescription = TopicAdmin.defineTopic(topic).compacted().partitions(config.getInt(DistributedConfig.STATUS_STORAGE_PARTITIONS_CONFIG)).replicationFactor(config.getShort(DistributedConfig.STATUS_STORAGE_REPLICATION_FACTOR_CONFIG)).build();
    Callback<ConsumerRecord<String, byte[]>> readCallback = new Callback<ConsumerRecord<String, byte[]>>() {

        @Override
        public void onCompletion(Throwable error, ConsumerRecord<String, byte[]> record) {
            read(record);
        }
    };
    this.kafkaLog = createKafkaBasedLog(topic, producerProps, consumerProps, readCallback, topicDescription, adminProps);
}
Also used : HashMap(java.util.HashMap) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) ConfigException(org.apache.kafka.common.config.ConfigException) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Callback(org.apache.kafka.connect.util.Callback) NewTopic(org.apache.kafka.clients.admin.NewTopic) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) StringSerializer(org.apache.kafka.common.serialization.StringSerializer)

Example 85 with ConfigException

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

the class FileStreamSourceConnector method start.

@Override
public void start(Map<String, String> props) {
    AbstractConfig parsedConfig = new AbstractConfig(CONFIG_DEF, props);
    filename = parsedConfig.getString(FILE_CONFIG);
    List<String> topics = parsedConfig.getList(TOPIC_CONFIG);
    if (topics.size() != 1) {
        throw new ConfigException("'topic' in FileStreamSourceConnector configuration requires definition of a single topic");
    }
    topic = topics.get(0);
    batchSize = parsedConfig.getInt(TASK_BATCH_SIZE_CONFIG);
}
Also used : AbstractConfig(org.apache.kafka.common.config.AbstractConfig) ConfigException(org.apache.kafka.common.config.ConfigException)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4