| 43 | } |
| 44 | |
| 45 | func (c *Client) ElectLeaders( |
| 46 | ctx context.Context, |
| 47 | req *ElectLeadersRequest, |
| 48 | ) (*ElectLeadersResponse, error) { |
| 49 | partitions32 := []int32{} |
| 50 | for _, partition := range req.Partitions { |
| 51 | partitions32 = append(partitions32, int32(partition)) |
| 52 | } |
| 53 | |
| 54 | protoResp, err := c.roundTrip( |
| 55 | ctx, |
| 56 | req.Addr, |
| 57 | &electleaders.Request{ |
| 58 | TopicPartitions: []electleaders.RequestTopicPartitions{ |
| 59 | { |
| 60 | Topic: req.Topic, |
| 61 | PartitionIDs: partitions32, |
| 62 | }, |
| 63 | }, |
| 64 | TimeoutMs: int32(req.Timeout.Milliseconds()), |
| 65 | }, |
| 66 | ) |
| 67 | if err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | apiResp := protoResp.(*electleaders.Response) |
| 71 | |
| 72 | resp := &ElectLeadersResponse{ |
| 73 | Error: makeError(apiResp.ErrorCode, ""), |
| 74 | } |
| 75 | |
| 76 | for _, topicResult := range apiResp.ReplicaElectionResults { |
| 77 | for _, partitionResult := range topicResult.PartitionResults { |
| 78 | resp.PartitionResults = append( |
| 79 | resp.PartitionResults, |
| 80 | ElectLeadersResponsePartitionResult{ |
| 81 | Partition: int(partitionResult.PartitionID), |
| 82 | Error: makeError(partitionResult.ErrorCode, partitionResult.ErrorMessage), |
| 83 | }, |
| 84 | ) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return resp, nil |
| 89 | } |