-
Notifications
You must be signed in to change notification settings - Fork 2
/
destroy_tidb2ms.go
122 lines (99 loc) · 3.82 KB
/
destroy_tidb2ms.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
// 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 manager
import (
"context"
"errors"
"fmt"
// "github.com/fatih/color"
"github.com/joomcode/errorx"
// "github.com/luyomo/OhMyTiUP/pkg/aws/clusterutil"
operator "github.com/luyomo/OhMyTiUP/pkg/aws/operation"
"github.com/luyomo/OhMyTiUP/pkg/aws/spec"
"github.com/luyomo/OhMyTiUP/pkg/aws/task"
"github.com/luyomo/OhMyTiUP/pkg/ctxt"
"github.com/luyomo/OhMyTiUP/pkg/executor"
//"github.com/luyomo/OhMyTiUP/pkg/logger/log"
"github.com/luyomo/OhMyTiUP/pkg/meta"
// "github.com/luyomo/OhMyTiUP/pkg/tui"
"github.com/luyomo/OhMyTiUP/pkg/utils"
perrs "github.com/pingcap/errors"
)
// DestroyCluster destroy the cluster.
func (m *Manager) DestroyTiDB2MSCluster(name string, gOpt operator.Options, destroyOpt operator.Options, skipConfirm bool) error {
_, err := m.meta(name)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) &&
!errors.Is(perrs.Cause(err), spec.ErrMultipleTiSparkMaster) &&
!errors.Is(perrs.Cause(err), spec.ErrMultipleTisparkWorker) {
return err
}
clusterType := "ohmytiup-tidb2ms"
sexecutor, err := executor.New(executor.SSHTypeNone, false, executor.SSHConfig{Host: "127.0.0.1", User: utils.CurrentUser()}, []string{})
if err != nil {
return err
}
t0 := task.NewBuilder().
DestroyTransitGateways(&sexecutor).
DestroyDMSService(&sexecutor, "dmsservice").
// DestroyVpcPeering(&sexecutor).
BuildAsStep(fmt.Sprintf(" - Prepare %s:%d", "127.0.0.1", 22))
builder := task.NewBuilder().
ParallelStep("+ Destroying tidb2ms solution service ... ...", false, t0)
t := builder.Build()
ctx := context.WithValue(context.Background(), "clusterName", name)
ctx = context.WithValue(ctx, "clusterType", clusterType)
if err := t.Execute(ctxt.New(ctx, 1)); err != nil {
if errorx.Cast(err) != nil {
// FIXME: Map possible task errors and give suggestions.
return err
}
return err
}
var destroyTasks []*task.StepDisplay
//var auroraInfo, msInfo task.ClusterInfo
var msInfo task.ClusterInfo
t1 := task.NewBuilder().
DestroyEC2Nodes(&sexecutor, "tidb").
BuildAsStep(fmt.Sprintf(" - Destroying EC2 nodes cluster %s ", name))
destroyTasks = append(destroyTasks, t1)
t2 := task.NewBuilder().
DestroyAurora().
BuildAsStep(fmt.Sprintf(" - Destroying aurora db cluster %s ", name))
destroyTasks = append(destroyTasks, t2)
t3 := task.NewBuilder().
DestroySqlServer(&sexecutor, "sqlserver", &msInfo).
BuildAsStep(fmt.Sprintf(" - Destroying sqlserver cluster %s ", name))
destroyTasks = append(destroyTasks, t3)
t4 := task.NewBuilder().
DestroyEC2Nodes(&sexecutor, "workstation").
BuildAsStep(fmt.Sprintf(" - Destroying workstation cluster %s ", name))
destroyTasks = append(destroyTasks, t4)
t5 := task.NewBuilder().
DestroyCloudFormation(&sexecutor).
BuildAsStep(fmt.Sprintf(" - Destroying cloudformation %s ", name))
destroyTasks = append(destroyTasks, t5)
builder = task.NewBuilder().
ParallelStep("+ Destroying all the componets", false, destroyTasks...)
t = builder.Build()
tailctx := context.WithValue(context.Background(), "clusterName", name)
tailctx = context.WithValue(tailctx, "clusterType", clusterType)
if err := t.Execute(ctxt.New(tailctx, 5)); err != nil {
if errorx.Cast(err) != nil {
// FIXME: Map possible task errors and give suggestions.
return err
}
return err
}
return nil
}