Skip to content

Commit

Permalink
fix empty http response in scheduler (#2869) (#2871)
Browse files Browse the repository at this point in the history
* cherry pick #2869 to release-4.0

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

* fix conflict

Signed-off-by: lhy1024 <admin@liudos.us>

* fix conflict

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: lhy1024 <admin@liudos.us>
  • Loading branch information
ti-srebot and lhy1024 authored Sep 1, 2020
1 parent 6403e70 commit 00920b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions plugin/scheduler_example/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
id = (uint64)(idFloat)
if _, exists = handler.config.StoreIDWitRanges[id]; !exists {
if err := handler.config.cluster.BlockStore(id); err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
}
Expand All @@ -277,7 +277,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
handler.config.BuildWithArgs(args)
err := handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
}
handler.rd.JSON(w, http.StatusOK, nil)
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R
return
}

handler.rd.JSON(w, http.StatusInternalServerError, errors.New("the config does not exist"))
handler.rd.JSON(w, http.StatusInternalServerError, errors.New("the config does not exist").Error())
}

func newEvictLeaderHandler(config *evictLeaderSchedulerConfig) http.Handler {
Expand Down
12 changes: 6 additions & 6 deletions server/schedulers/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
id = (uint64)(idFloat)
if _, exists = handler.config.StoreIDWithRanges[id]; !exists {
if err := handler.config.cluster.BlockStore(id); err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
}
Expand All @@ -316,7 +316,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
handler.config.BuildWithArgs(args)
err := handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
handler.rd.JSON(w, http.StatusOK, nil)
Expand All @@ -340,15 +340,15 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R
if succ {
err = handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
if last {
if err := handler.config.cluster.RemoveScheduler(EvictLeaderName); err != nil {
if err == ErrSchedulerNotFound {
handler.rd.JSON(w, http.StatusNotFound, err)
handler.rd.JSON(w, http.StatusNotFound, err.Error())
} else {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
}
return
}
Expand All @@ -358,7 +358,7 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R
return
}

handler.rd.JSON(w, http.StatusNotFound, ErrScheduleConfigNotExist)
handler.rd.JSON(w, http.StatusNotFound, ErrScheduleConfigNotExist.Error())
}

func newEvictLeaderHandler(config *evictLeaderSchedulerConfig) http.Handler {
Expand Down
12 changes: 6 additions & 6 deletions server/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (handler *grantLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
id = (uint64)(idFloat)
if _, exists = handler.config.StoreIDWithRanges[id]; !exists {
if err := handler.config.cluster.BlockStore(id); err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
}
Expand All @@ -266,7 +266,7 @@ func (handler *grantLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
handler.config.BuildWithArgs(args)
err := handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
handler.rd.JSON(w, http.StatusOK, nil)
Expand All @@ -290,15 +290,15 @@ func (handler *grantLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R
if succ {
err = handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
if last {
if err := handler.config.cluster.RemoveScheduler(GrantLeaderName); err != nil {
if err == ErrSchedulerNotFound {
handler.rd.JSON(w, http.StatusNotFound, err)
handler.rd.JSON(w, http.StatusNotFound, err.Error())
} else {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
}
return
}
Expand All @@ -308,7 +308,7 @@ func (handler *grantLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R
return
}

handler.rd.JSON(w, http.StatusNotFound, ErrScheduleConfigNotExist)
handler.rd.JSON(w, http.StatusNotFound, ErrScheduleConfigNotExist.Error())
}

func newGrantLeaderHandler(config *grantLeaderSchedulerConfig) http.Handler {
Expand Down
4 changes: 2 additions & 2 deletions server/schedulers/scatter_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http.
name, ok := input["range-name"].(string)
if ok {
if name != handler.config.GetRangeName() {
handler.rd.JSON(w, http.StatusInternalServerError, errors.New("Cannot change the range name, please delete this schedule"))
handler.rd.JSON(w, http.StatusInternalServerError, errors.New("Cannot change the range name, please delete this schedule").Error())
return
}
args = append(args, name)
Expand All @@ -261,7 +261,7 @@ func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http.
handler.config.BuildWithArgs(args)
err := handler.config.Persist()
if err != nil {
handler.rd.JSON(w, http.StatusInternalServerError, err)
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
}
handler.rd.JSON(w, http.StatusOK, nil)
}
Expand Down

0 comments on commit 00920b6

Please sign in to comment.