-
Notifications
You must be signed in to change notification settings - Fork 9
/
admin_groups.go
52 lines (48 loc) · 1.07 KB
/
admin_groups.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package kafkactl
import (
"fmt"
"github.com/Shopify/sarama"
)
func (kc *KClient) RemoveGroup(name string) (errMsg error) {
var brokerErr error
var found bool
var code int16
var returnCode int16
request := sarama.DeleteGroupsRequest{
Groups: []string{name},
}
for _, broker := range kc.brokers {
response, errd := broker.DeleteGroups(&request)
if errd == nil {
for _, v := range response.GroupErrorCodes {
var err error
if found, returnCode, err = catchedErrCode(v); !found {
return nil
}
if returnCode > code {
code = returnCode
errMsg = err
}
}
} else {
brokerErr = errd
}
}
if brokerErr != nil {
errMsg = brokerErr
}
return
}
func catchedErrCode(kerror sarama.KError) (bool, int16, error) {
code := int16(kerror)
if code > 0 {
if code == 68 {
return true, code, fmt.Errorf("Error Code %v Returned: NON_EMPTY_GROUP", code)
}
if code == 69 {
return true, code, fmt.Errorf("Error Code %v Returned: GROUP_ID_NOT_FOUND", code)
}
return true, code, fmt.Errorf("%v", kerror.Error())
}
return false, code, nil
}