summaryrefslogtreecommitdiff
path: root/kafka/admin/new_topic.py
blob: 645ac383ae56e5144b0e952038dd27eb726d0bd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import absolute_import

from kafka.errors import IllegalArgumentError


class NewTopic(object):
    """ A class for new topic creation
    Arguments:
        name (string): name of the topic
        num_partitions (int): number of partitions
            or -1 if replica_assignment has been specified
        replication_factor (int): replication factor or -1 if
            replica assignment is specified
        replica_assignment (dict of int: [int]): A mapping containing
            partition id and replicas to assign to it.
        topic_configs (dict of str: str): A mapping of config key
            and value for the topic.
    """

    def __init__(
            self,
            name,
            num_partitions,
            replication_factor,
            replica_assignments=None,
            topic_configs=None,
    ):
        if not (num_partitions == -1 or replication_factor == -1) ^ (replica_assignments is None):
            raise IllegalArgumentError('either num_partitions/replication_factor or replica_assignment must be specified')
        self.name = name
        self.num_partitions = num_partitions
        self.replication_factor = replication_factor
        self.replica_assignments = replica_assignments or {}
        self.topic_configs = topic_configs or {}