Skip to content

Commit e1cf7c4

Browse files
committed
[clean] add stop container step before clean container
1 parent a603d9b commit e1cf7c4

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,22 @@
202202
],
203203
"showLog": true,
204204
},
205+
{
206+
"name": "dingoadm clean -f",
207+
"type": "go",
208+
"request": "launch",
209+
"mode": "auto",
210+
"program": "${workspaceFolder}/cmd/dingoadm/main.go",
211+
"env": {
212+
"CGO_ENABLED": "1",
213+
"PATH": "/opt/rh/gcc-toolset-13/root/usr/bin:${env:PATH}"
214+
},
215+
"args": [
216+
"clean",
217+
"-f",
218+
],
219+
"showLog": true,
220+
},
205221
{
206222
"name": "dingoadm mount mdsv2 vfs_v2",
207223
"type": "go",

cli/command/clean.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ func genCleanPlaybook(dingoadm *cli.DingoAdm,
130130
}
131131

132132
steps := CLEAN_PLAYBOOK_STEPS
133+
// check if options's only item include container
134+
if utils.Contains(options.only, comm.CLEAN_ITEM_CONTAINER) {
135+
// add stop service step before clean service step
136+
steps = append([]int{playbook.STOP_SERVICE}, steps...)
137+
}
138+
133139
pb := playbook.NewPlaybook(dingoadm)
134140
for _, step := range steps {
135141
pb.AddStep(&playbook.PlaybookStep{
@@ -160,7 +166,7 @@ func runClean(dingoadm *cli.DingoAdm, options cleanOptions) error {
160166
// 3) confirm by user
161167
// 3) force stop
162168
if options.force {
163-
dingoadm.WriteOut(tui.PromptCancelOpetation("clean service"))
169+
dingoadm.WriteOutln(tui.PromptForceOpetation("clean service"))
164170
return pb.Run()
165171
}
166172

internal/task/step/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ func (s *RemoveContainer) Execute(ctx *context.Context) error {
269269
return PostHandle(s.Success, s.Out, out, err, errno.ERR_REMOVE_CONTAINER_FAILED.FD("(%s rm CONTAINER)", s.ExecWithEngine))
270270
}
271271

272+
// ListContainers list containers by `docker ps [OPTIONS]`
273+
// e.g. docker ps --filter "id=<container_id>" --quiet --all
272274
func (s *ListContainers) Execute(ctx *context.Context) error {
273275
cli := ctx.Module().DockerCli().ListContainers()
274276
if len(s.Format) > 0 {

internal/task/task/common/clean_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
tui "github.com/dingodb/dingoadm/internal/tui/common"
4444
"github.com/dingodb/dingoadm/internal/utils"
4545
"github.com/dingodb/dingoadm/pkg/module"
46+
"github.com/fatih/color"
4647
)
4748

4849
const (
@@ -144,6 +145,7 @@ func NewCleanServiceTask(dingoadm *cli.DingoAdm, dc *topology.DeployConfig) (*ta
144145
if containerId == comm.CLEANED_CONTAINER_ID {
145146
// container has removed, no need to clean
146147
dingoadm.Storage().SetContainId(serviceId, comm.CLEANED_CONTAINER_ID)
148+
dingoadm.WriteOutln("%s clean service: host=%s role=%s ", color.YellowString("[SKIP]"), dc.GetHost(), dc.GetRole())
147149
return nil, nil
148150
}
149151
if dingoadm.IsSkip(dc) {
@@ -193,7 +195,7 @@ func NewCleanServiceTask(dingoadm *cli.DingoAdm, dc *topology.DeployConfig) (*ta
193195
Files: files,
194196
ExecOptions: dingoadm.ExecOptions(),
195197
})
196-
if clean[comm.CLEAN_ITEM_CONTAINER] == true {
198+
if clean[comm.CLEAN_ITEM_CONTAINER] {
197199

198200
// var status string
199201
// t.AddStep(&step.InspectContainer{

internal/tui/common/prompt.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ to watch the formatting progress.
7272
`
7373
PROMPT_CANCEL_OPERATION = `[x] {{.operation}} canceled`
7474

75+
PROMPT_FORCE_OPERATION = `[!] {{.operation}} will be forced`
76+
7577
DEFAULT_CONFIRM_PROMPT = "Do you want to continue?"
7678
)
7779

@@ -227,6 +229,12 @@ func PromptErrorCode(code int, description, clue, logpath string) string {
227229
return prompt.Build()
228230
}
229231

232+
func PromptForceOpetation(operation string) string {
233+
prompt := NewPrompt(color.YellowString(PROMPT_FORCE_OPERATION))
234+
prompt.data["operation"] = operation
235+
return prompt.Build()
236+
}
237+
230238
func PromptCancelOpetation(operation string) string {
231239
prompt := NewPrompt(color.YellowString(PROMPT_CANCEL_OPERATION))
232240
prompt.data["operation"] = operation

0 commit comments

Comments
 (0)