-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
125 lines (100 loc) · 3.3 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"log"
"strings"
"github.com/nlnwa/veidemann-reset/internal/file"
"github.com/nlnwa/veidemann-reset/internal/redis"
"github.com/nlnwa/veidemann-reset/internal/rethinkdb"
"github.com/nlnwa/veidemann-reset/internal/scylla"
"github.com/nlnwa/veidemann-reset/internal/version"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)
func main() {
// configuration defaults
rethinkdbUser := "admin"
rethinkdbPassword := "rethinkdb"
rethinkdbName := "veidemann"
rethinkdbHost := "localhost"
rethinkdbPort := 28015
redisHost := "redis-master"
redisPort := 6379
scyllaHosts := []string{"scylla-client"}
scyllaKeyspace := "v7n_v3_dev"
directories := []string{
"/warcs",
"/validwarcs",
"/invalidwarcs",
"/backup/oos",
}
tables := map[string][]string{
"veidemann": {
"crawled_content",
"events",
"executions",
"job_executions",
"uri_queue",
},
}
flag.StringVar(&rethinkdbHost, "rethinkdb-host", rethinkdbHost, "RethinkDb hostname")
flag.IntVar(&rethinkdbPort, "rethinkdb-port", rethinkdbPort, "RethinkDb port")
flag.StringVar(&rethinkdbName, "rethinkdb-name", rethinkdbName, "RethinkDb database name")
flag.StringVar(&rethinkdbUser, "rethinkdb-user", rethinkdbUser, "RethinkDb user")
flag.StringVar(&rethinkdbPassword, "rethinkdb-password", rethinkdbPassword, "RethinkDb password")
flag.StringVar(&redisHost, "redis-host", redisHost, "Redis host")
flag.IntVar(&redisPort, "redis-port", redisPort, "Redis port")
flag.StringSliceVar(&scyllaHosts, "scylla-hosts", scyllaHosts, "List of db hosts")
flag.StringVar(&scyllaKeyspace, "scylla-keyspace", scyllaKeyspace, "Name of keyspace")
flag.StringSliceVar(&directories, "directories", directories, "directories to clean")
flag.Parse()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
err := viper.BindPFlags(flag.CommandLine)
if err != nil {
log.Fatal(err)
}
rethinkdbUser = viper.GetString("rethinkdb-user")
rethinkdbPassword = viper.GetString("rethinkdb-password")
rethinkdbName = viper.GetString("rethinkdb-name")
rethinkdbHost = viper.GetString("rethinkdb-host")
rethinkdbPort = viper.GetInt("rethinkdb-port")
rethinkdbOptions := rethinkdb.Options{
Name: rethinkdbName,
Host: rethinkdbHost,
Port: rethinkdbPort,
Username: rethinkdbUser,
Password: rethinkdbPassword,
}
redisHost = viper.GetString("redis-host")
redisPort = viper.GetInt("redis-port")
scyllaHosts = viper.GetStringSlice("scylla-hosts")
scyllaKeyspace = viper.GetString("scylla-keyspace")
directories = viper.GetStringSlice("directories")
log.Printf("Veidemann reset, version: %s\n", version.Version)
// Delete files
file.NewDirectoryCleaner(directories).RemoveFiles()
// Empty RethinkDB tables
rethinkClient := rethinkdb.NewClient(rethinkdbOptions)
err = rethinkClient.Connect()
if err != nil {
panic(err)
}
defer rethinkClient.Disconnect()
rethinkClient.Clean(tables)
// Flush redis
redisClient, err := redis.NewClient(redisHost, redisPort)
if err != nil {
panic(err)
}
defer redisClient.Close()
redisClient.Flush()
// Drop scylla keyspace
scyllaClient := scylla.NewClient(scyllaHosts...)
err = scyllaClient.Connect()
if err != nil {
panic(err)
}
defer scyllaClient.Disconnect()
scyllaClient.Drop(scyllaKeyspace)
log.Printf("Veidemann reset completed successfully")
}