Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Nov 13, 2023
1 parent 02f3444 commit 4ce03e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
30 changes: 17 additions & 13 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func NewService(srv *scheserver.Service) *Service {
s.RegisterSchedulersRouter()
s.RegisterCheckersRouter()
s.RegisterHotspotRouter()
s.RegisterRegionsRouter()
return s
}

Expand Down Expand Up @@ -169,13 +168,6 @@ func (s *Service) RegisterOperatorsRouter() {
router.GET("/records", getOperatorRecords)
}

// RegisterRegionsRouter registers the router of the regions handler.
func (s *Service) RegisterRegionsRouter() {
router := s.root.Group("regions")
router.GET("/:id/label/:key", getRegionLabelByKey)
router.GET("/:id/labels", getRegionLabels)
}

// RegisterConfigRouter registers the router of the config handler.
func (s *Service) RegisterConfigRouter() {
router := s.root.Group("config")
Expand All @@ -202,9 +194,13 @@ func (s *Service) RegisterConfigRouter() {
placementRule.GET("/:group", getPlacementRuleByGroup)

regionLabel := router.Group("region-label")
regionLabel.GET("rules", getAllRegionLabelRules)
regionLabel.GET("rules/ids", getRegionLabelRulesByIDs)
regionLabel.GET("rule/:id", getRegionLabelRuleByID)
regionLabel.GET("/rules", getAllRegionLabelRules)
regionLabel.GET("/rules/ids", getRegionLabelRulesByIDs)
regionLabel.GET("/rule/:id", getRegionLabelRuleByID)

regions := router.Group("regions")
regions.GET("/:id/label/:key", getRegionLabelByKey)
regions.GET("/:id/labels", getRegionLabels)
}

// @Tags admin
Expand Down Expand Up @@ -991,7 +987,11 @@ func getRegionLabelByKey(c *gin.Context) {
return
}

region := handler.GetRegion(id)
region, err := handler.GetRegion(id)
if err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
if region == nil {
c.String(http.StatusNotFound, errs.ErrRegionNotFound.FastGenByArgs().Error())
return
Expand Down Expand Up @@ -1024,7 +1024,11 @@ func getRegionLabels(c *gin.Context) {
return
}

region := handler.GetRegion(id)
region, err := handler.GetRegion(id)
if err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
if region == nil {
c.String(http.StatusNotFound, errs.ErrRegionNotFound.FastGenByArgs().Error())
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/schedule/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,12 +1065,12 @@ func (h *Handler) GetHotBuckets(regionIDs ...uint64) (HotBucketsResponse, error)
}

// GetRegion returns the region labeler.
func (h *Handler) GetRegion(id uint64) *core.RegionInfo {
func (h *Handler) GetRegion(id uint64) (*core.RegionInfo, error) {
c := h.GetCluster()
if c == nil {
return nil
return nil, errs.ErrNotBootstrapped.GenWithStackByArgs()
}
return c.GetRegion(id)
return c.GetRegion(id), nil
}

// GetRegionLabeler returns the region labeler.
Expand Down
2 changes: 1 addition & 1 deletion server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewHandler(_ context.Context, svr *server.Server) (http.Handler, apiutil.AP
[]string{http.MethodPost, http.MethodGet}),
serverapi.MicroserviceRedirectRule(
prefix+"/region/id",
scheapi.APIPathPrefix+"/regions",
scheapi.APIPathPrefix+"/config/regions",
mcs.SchedulingServiceName,
[]string{http.MethodGet},
func(r *http.Request) bool {
Expand Down

0 comments on commit 4ce03e7

Please sign in to comment.