|
|
@ -39,11 +39,13 @@ public class PartitionsSpec extends Message { |
|
|
|
private final int numPartitions; |
|
|
|
private final int numPartitions; |
|
|
|
private final short replicationFactor; |
|
|
|
private final short replicationFactor; |
|
|
|
private final Map<Integer, List<Integer>> partitionAssignments; |
|
|
|
private final Map<Integer, List<Integer>> partitionAssignments; |
|
|
|
|
|
|
|
private final Map<String, String> configs; |
|
|
|
|
|
|
|
|
|
|
|
@JsonCreator |
|
|
|
@JsonCreator |
|
|
|
public PartitionsSpec(@JsonProperty("numPartitions") int numPartitions, |
|
|
|
public PartitionsSpec(@JsonProperty("numPartitions") int numPartitions, |
|
|
|
@JsonProperty("replicationFactor") short replicationFactor, |
|
|
|
@JsonProperty("replicationFactor") short replicationFactor, |
|
|
|
@JsonProperty("partitionAssignments") Map<Integer, List<Integer>> partitionAssignments) { |
|
|
|
@JsonProperty("partitionAssignments") Map<Integer, List<Integer>> partitionAssignments, |
|
|
|
|
|
|
|
@JsonProperty("configs") Map<String, String> configs) { |
|
|
|
this.numPartitions = numPartitions; |
|
|
|
this.numPartitions = numPartitions; |
|
|
|
this.replicationFactor = replicationFactor; |
|
|
|
this.replicationFactor = replicationFactor; |
|
|
|
HashMap<Integer, List<Integer>> partMap = new HashMap<>(); |
|
|
|
HashMap<Integer, List<Integer>> partMap = new HashMap<>(); |
|
|
@ -60,6 +62,11 @@ public class PartitionsSpec extends Message { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this.partitionAssignments = Collections.unmodifiableMap(partMap); |
|
|
|
this.partitionAssignments = Collections.unmodifiableMap(partMap); |
|
|
|
|
|
|
|
if (configs == null) { |
|
|
|
|
|
|
|
this.configs = Collections.emptyMap(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.configs = Collections.unmodifiableMap(new HashMap<>(configs)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@JsonProperty |
|
|
|
@JsonProperty |
|
|
@ -90,15 +97,25 @@ public class PartitionsSpec extends Message { |
|
|
|
return partitionAssignments; |
|
|
|
return partitionAssignments; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@JsonProperty |
|
|
|
|
|
|
|
public Map<String, String> configs() { |
|
|
|
|
|
|
|
return configs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public NewTopic newTopic(String topicName) { |
|
|
|
public NewTopic newTopic(String topicName) { |
|
|
|
|
|
|
|
NewTopic newTopic; |
|
|
|
if (partitionAssignments.isEmpty()) { |
|
|
|
if (partitionAssignments.isEmpty()) { |
|
|
|
int effectiveNumPartitions = numPartitions <= 0 ? |
|
|
|
int effectiveNumPartitions = numPartitions <= 0 ? |
|
|
|
DEFAULT_NUM_PARTITIONS : numPartitions; |
|
|
|
DEFAULT_NUM_PARTITIONS : numPartitions; |
|
|
|
short effectiveReplicationFactor = replicationFactor <= 0 ? |
|
|
|
short effectiveReplicationFactor = replicationFactor <= 0 ? |
|
|
|
DEFAULT_REPLICATION_FACTOR : replicationFactor; |
|
|
|
DEFAULT_REPLICATION_FACTOR : replicationFactor; |
|
|
|
return new NewTopic(topicName, effectiveNumPartitions, effectiveReplicationFactor); |
|
|
|
newTopic = new NewTopic(topicName, effectiveNumPartitions, effectiveReplicationFactor); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return new NewTopic(topicName, partitionAssignments); |
|
|
|
newTopic = new NewTopic(topicName, partitionAssignments); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!configs.isEmpty()) { |
|
|
|
|
|
|
|
newTopic.configs(configs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return newTopic; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|