-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelZookeeperTopic.go
More file actions
70 lines (61 loc) · 1.42 KB
/
delZookeeperTopic.go
File metadata and controls
70 lines (61 loc) · 1.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"os"
"io"
"bufio"
"time"
"github.com/samuel/go-zookeeper/zk"
"strconv"
)
func main() {
f, _ := os.Open("topic")
buf := bufio.NewReader(f)
var path []string
for {
a, _, err := buf.ReadLine()
if err == io.EOF {
break
} else if err != nil {
}
path = append(path, string(a))
}
var hosts = []string{"***:2181"} //server端host
conn, _, err := zk.Connect(hosts, time.Second*1000)
if err != nil {
fmt.Println(err.Error())
}
for _, val := range path {
topicPath := "/brokers/topics/" + val
basePath := "/brokers/topics/" + val + "/partitions/"
for i := 0; i < 3; i++ {
pathNode := basePath + strconv.Itoa(i)
_, _, _, err = conn.ExistsW(pathNode)
if err != nil {
fmt.Sprintf("node does not exist: %s",pathNode)
}
pathState := pathNode + "/state"
_, _, _, err = conn.ExistsW(pathState)
if err != nil {
fmt.Sprintf("node does not exist: %s",pathState)
}
err = conn.Delete(pathState, -1)
if err != nil {
fmt.Sprintf("node does not exist: %s",pathState)
}
err = conn.Delete(pathNode, -1)
if err != nil {
fmt.Sprintf("node does not exist: %s",pathNode)
}
}
partPath := "/brokers/topics/" + val + "/partitions"
err = conn.Delete(partPath, -1)
if err != nil {
fmt.Sprintf("node does not exist: %s",basePath)
}
err = conn.Delete(topicPath, -1)
if err != nil {
fmt.Sprintf("node does not exist: %s",topicPath)
}
}
}