Search in sources :

Example 1 with PartitionGrouper

use of org.apache.kafka.streams.processor.PartitionGrouper 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)

Aggregations

KafkaException (org.apache.kafka.common.KafkaException)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 LogContext (org.apache.kafka.common.utils.LogContext)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 PartitionGrouper (org.apache.kafka.streams.processor.PartitionGrouper)1