Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctl: add a message if the scheduler does not exist #8503

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tools/pd-ctl/pdctl/command/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,16 @@
cmd.Println(cmd.UsageString())
return
}

exist, err := checkSchedulerExist(cmd, schedulerName)
if err != nil {
return

Check warning on line 647 in tools/pd-ctl/pdctl/command/scheduler.go

View check run for this annotation

Codecov / codecov/patch

tools/pd-ctl/pdctl/command/scheduler.go#L647

Added line #L647 was not covered by tests
}
if !exist {
cmd.Printf("Failed! scheduler %s not found.\n", schedulerName)
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
return
}

storeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
cmd.Println(err)
Expand Down Expand Up @@ -768,8 +778,17 @@
cmd.Println(cmd.Usage())
return
}
exist, err := checkSchedulerExist(cmd, schedulerName)
if err != nil {
return

Check warning on line 783 in tools/pd-ctl/pdctl/command/scheduler.go

View check run for this annotation

Codecov / codecov/patch

tools/pd-ctl/pdctl/command/scheduler.go#L783

Added line #L783 was not covered by tests
}
if !exist {
cmd.Printf("Failed! scheduler %s not found.\n", schedulerName)
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
return
}

path := path.Join(schedulerConfigPrefix, "/", schedulerName, "delete", args[0])
_, err := doRequest(cmd, path, http.MethodDelete, http.Header{})
_, err = doRequest(cmd, path, http.MethodDelete, http.Header{})
if err != nil {
cmd.Println(err)
return
Expand Down
8 changes: 7 additions & 1 deletion tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {

for idx := range schedulers {
checkStorePause([]uint64{}, schedulers[idx])

// will fail because the scheduler is not existed
args = []string{"-u", pdAddr, "scheduler", "config", schedulers[idx], "add-store", "3"}
output := mustExec(re, cmd, args, nil)
re.Contains(output, fmt.Sprintf("Failed! scheduler %s not found", schedulers[idx]))

// scheduler add command
args = []string{"-u", pdAddr, "scheduler", "add", schedulers[idx], "2"}
expected = map[string]bool{
Expand Down Expand Up @@ -315,7 +321,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil)
re.Contains(echo, "Success!")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil)
re.Contains(echo, "404")
re.Contains(echo, "Failed! scheduler evict-leader-scheduler not found")
lhy1024 marked this conversation as resolved.
Show resolved Hide resolved
testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server.
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "evict-leader-scheduler"}, nil)
return strings.Contains(echo, "[404] scheduler not found")
Expand Down
Loading