github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/protocol/incrementalalterconfigs/incrementalalterconfigs.go (about) 1 package incrementalalterconfigs 2 3 import ( 4 "errors" 5 "strconv" 6 7 "github.com/segmentio/kafka-go/protocol" 8 ) 9 10 const ( 11 resourceTypeBroker int8 = 4 12 ) 13 14 func init() { 15 protocol.Register(&Request{}, &Response{}) 16 } 17 18 // Detailed API definition: https://kafka.apache.org/protocol#The_Messages_IncrementalAlterConfigs 19 type Request struct { 20 Resources []RequestResource `kafka:"min=v0,max=v0"` 21 ValidateOnly bool `kafka:"min=v0,max=v0"` 22 } 23 24 type RequestResource struct { 25 ResourceType int8 `kafka:"min=v0,max=v0"` 26 ResourceName string `kafka:"min=v0,max=v0"` 27 Configs []RequestConfig `kafka:"min=v0,max=v0"` 28 } 29 30 type RequestConfig struct { 31 Name string `kafka:"min=v0,max=v0"` 32 ConfigOperation int8 `kafka:"min=v0,max=v0"` 33 Value string `kafka:"min=v0,max=v0,nullable"` 34 } 35 36 func (r *Request) ApiKey() protocol.ApiKey { return protocol.IncrementalAlterConfigs } 37 38 func (r *Request) Broker(cluster protocol.Cluster) (protocol.Broker, error) { 39 // Check that at most only one broker is being updated. 40 // 41 // TODO: Support updating multiple brokers in a single request. 42 brokers := map[string]struct{}{} 43 for _, resource := range r.Resources { 44 if resource.ResourceType == resourceTypeBroker { 45 brokers[resource.ResourceName] = struct{}{} 46 } 47 } 48 if len(brokers) > 1 { 49 return protocol.Broker{}, 50 errors.New("Updating more than one broker in a single request is not supported yet") 51 } 52 53 for _, resource := range r.Resources { 54 if resource.ResourceType == resourceTypeBroker { 55 brokerID, err := strconv.Atoi(resource.ResourceName) 56 if err != nil { 57 return protocol.Broker{}, err 58 } 59 60 return cluster.Brokers[int32(brokerID)], nil 61 } 62 } 63 64 return cluster.Brokers[cluster.Controller], nil 65 } 66 67 type Response struct { 68 ThrottleTimeMs int32 `kafka:"min=v0,max=v0"` 69 Responses []ResponseAlterResponse `kafka:"min=v0,max=v0"` 70 } 71 72 type ResponseAlterResponse struct { 73 ErrorCode int16 `kafka:"min=v0,max=v0"` 74 ErrorMessage string `kafka:"min=v0,max=v0,nullable"` 75 ResourceType int8 `kafka:"min=v0,max=v0"` 76 ResourceName string `kafka:"min=v0,max=v0"` 77 } 78 79 func (r *Response) ApiKey() protocol.ApiKey { return protocol.IncrementalAlterConfigs }