Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin: include ReplicaAssignment in ListTopics() #1274

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (ca *clusterAdmin) ListTopics() (map[string]TopicDetail, error) {
NumPartitions: int32(len(topic.Partitions)),
}
if len(topic.Partitions) > 0 {
topicDetails.ReplicaAssignment = map[int32][]int32{}
for _, partition := range topic.Partitions {
topicDetails.ReplicaAssignment[partition.ID] = partition.Replicas
}
topicDetails.ReplicationFactor = int16(len(topic.Partitions[0].Replicas))
}
topicsDetailsMap[topic.Name] = topicDetails
Expand Down
4 changes: 4 additions & 0 deletions admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func TestClusterAdminListTopics(t *testing.T) {
if err != nil {
t.Fatal(err)
}

if topic.ReplicaAssignment == nil || topic.ReplicaAssignment[0][0] != 1 {
t.Fatal(errors.New("replica assignment not found in response"))
}
}

func TestClusterAdminDeleteTopic(t *testing.T) {
Expand Down
12 changes: 10 additions & 2 deletions mockresponses.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,25 @@ func (mmr *MockMetadataResponse) For(reqBody versionedDecoder) encoder {
for addr, brokerID := range mmr.brokers {
metadataResponse.AddBroker(addr, brokerID)
}

// Generate set of replicas
replicas := []int32{}

for _, brokerID := range mmr.brokers {
replicas = append(replicas, brokerID)
}

if len(metadataRequest.Topics) == 0 {
for topic, partitions := range mmr.leaders {
for partition, brokerID := range partitions {
metadataResponse.AddTopicPartition(topic, partition, brokerID, nil, nil, ErrNoError)
metadataResponse.AddTopicPartition(topic, partition, brokerID, replicas, replicas, ErrNoError)
}
}
return metadataResponse
}
for _, topic := range metadataRequest.Topics {
for partition, brokerID := range mmr.leaders[topic] {
metadataResponse.AddTopicPartition(topic, partition, brokerID, nil, nil, ErrNoError)
metadataResponse.AddTopicPartition(topic, partition, brokerID, replicas, replicas, ErrNoError)
}
}
return metadataResponse
Expand Down