/
ossinsight_aurora.go
265 lines (224 loc) · 8.08 KB
/
ossinsight_aurora.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package command
import (
//"context"
// "os"
"path"
"strconv"
"github.com/luyomo/OhMyTiUP/pkg/aws/manager"
operator "github.com/luyomo/OhMyTiUP/pkg/aws/operation"
"github.com/luyomo/OhMyTiUP/pkg/aws/spec"
"github.com/luyomo/OhMyTiUP/pkg/set"
"github.com/luyomo/OhMyTiUP/pkg/tui"
"github.com/luyomo/OhMyTiUP/pkg/utils"
perrs "github.com/pingcap/errors"
"github.com/spf13/cobra"
)
func newOssInsightCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "ossinsight <sub_command>",
Short: "ossinsight aurora",
}
cmd.AddCommand(
newOssInsightDeploy(),
newListOssInsightCmd(),
newDestroyOssInsightCmd(),
newOssInsightCountTables(),
newOssInsightGithubEventsVolumeAdjust(),
newOssInsightTestCase(),
)
return cmd
}
// Input: private key file
//
// cluster name -> If does not exist, give error message
//
// Flow: 1. Extract cluster info(workstation public key / user)
// 2. Access aurora from workstation
// 3. Extract ddl from oss insight s3
// 4. Generate db objects from ddl file
// 5. Run command to import data into db
func newOssInsightDeploy() *cobra.Command {
opt := manager.OssInsightDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "deploy <cluster-name> <num-of-million>",
Short: "Deploy an ossinsight on aurora for demo",
Long: "Deploy an ossinsight on aurora for demo. SSH connection will be used to deploy files, as well as creating system users for running the service.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 2)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
numOfMillions := 0
if numOfMillions, err = strconv.Atoi(args[1]); err != nil {
return err
}
return cm.OssInsightDeploy(clusterName, numOfMillions, opt, postDeployHook, skipConfirm, gOpt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newOssInsightGithubEventsVolumeAdjust() *cobra.Command {
opt := manager.OssInsightDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "adjust-github-events-volume <cluster-name> <num-of-million>",
Short: "Adjust the data volume to specified number",
Long: "Adjust the data volume to specified number. SSH connection will be used to deploy files, as well as creating system users for running the service.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 2)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
numOfMillions := 0
if numOfMillions, err = strconv.Atoi(args[1]); err != nil {
return err
}
return cm.OssInsightAdjustGithubEventsValume(clusterName, numOfMillions, opt, postDeployHook, skipConfirm, gOpt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newOssInsightCountTables() *cobra.Command {
opt := manager.OssInsightDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "count <cluster-name>",
Short: "Count all tables",
Long: "Count all the tables in the ossinsight database.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.OssInsightCountTables(clusterName, opt, postDeployHook, skipConfirm, gOpt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newOssInsightTestCase() *cobra.Command {
opt := manager.OssInsightDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "test <cluster-name> <number-execution> <query-pattern>",
Short: "performance test",
Long: `Example: test aurotest 10 count
query-pattern:
- count: Count github_events
- mouthly_rank: ... ...
- dynamicTrends.BarChartRace: ... ...
- dynamicTrends.HistoricalRanking ... ...
- dynamicTrends.TopTen ... ...
`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 3)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
numExeTime := 0
if numExeTime, err = strconv.Atoi(args[1]); err != nil {
return err
}
queryType := args[2]
return cm.OssInsightTestCase(clusterName, numExeTime, queryType, opt, postDeployHook, skipConfirm, gOpt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newListOssInsightCmd() *cobra.Command {
opt := manager.DeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "list <cluster-name>",
Short: "List all clusters or cluster of aurora db",
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.ListAuroraCluster(clusterName, opt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
// fmt.Printf("The option is <%#v> \n", opt)
return cmd
}
func newDestroyOssInsightCmd() *cobra.Command {
destroyOpt := operator.Options{}
cmd := &cobra.Command{
Use: "destroy <cluster-name>",
Short: "Destroy a specified cluster",
Long: `Destroy a specified cluster, which will clean the deployment binaries and data.
You can retain some nodes and roles data when destroy cluster, eg:
$ tiup cluster destroy <cluster-name> --retain-role-data prometheus
$ tiup cluster destroy <cluster-name> --retain-node-data 172.16.13.11:9000
$ tiup cluster destroy <cluster-name> --retain-node-data 172.16.13.12`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Help()
}
clusterName := args[0]
clusterReport.ID = scrubClusterName(clusterName)
teleCommand = append(teleCommand, scrubClusterName(clusterName))
// Validate the retained roles to prevent unexpected deleting data
if len(destroyOpt.RetainDataRoles) > 0 {
validRoles := set.NewStringSet(spec.AllComponentNames()...)
for _, role := range destroyOpt.RetainDataRoles {
if !validRoles.Exist(role) {
return perrs.Errorf("role name `%s` invalid", role)
}
}
}
return cm.DestroyAuroraCluster(clusterName, gOpt, destroyOpt, skipConfirm)
},
}
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained")
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataRoles, "retain-role-data", nil, "Specify the roles whose data will be retained")
cmd.Flags().BoolVar(&destroyOpt.Force, "force", false, "Force will ignore remote error while destroy the cluster")
return cmd
}