@@ -19,7 +19,6 @@ import (
1919 "fmt"
2020 "net/http"
2121 "reflect"
22- "strconv"
2322 "strings"
2423
2524 "github.com/gin-contrib/cors"
@@ -29,10 +28,8 @@ import (
2928
3029 rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
3130
32- "github.com/tikv/pd/pkg/errs"
3331 rmserver "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
3432 "github.com/tikv/pd/pkg/mcs/utils"
35- "github.com/tikv/pd/pkg/mcs/utils/constant"
3633 "github.com/tikv/pd/pkg/utils/apiutil"
3734 "github.com/tikv/pd/pkg/utils/apiutil/multiservicesapi"
3835 "github.com/tikv/pd/pkg/utils/reflectutil"
@@ -167,15 +164,17 @@ func (s *Service) putResourceGroup(c *gin.Context) {
167164// @Failure 404 {string} error
168165// @Param name path string true "groupName"
169166// @Param with_stats query bool false "whether to return statistics data."
170- // @Param keyspace_id query uint32 false "keyspace ID, if not set, it will be treated as null keyspace ID. "
167+ // @Param keyspace_name path string true "Keyspace name "
171168// @Router /config/group/{name} [get]
172169func (s * Service ) getResourceGroup (c * gin.Context ) {
173170 withStats := strings .EqualFold (c .Query ("with_stats" ), "true" )
174- keyspaceID , err := getKeyspaceIDFromQuery (c )
171+ keyspaceName := c .Query ("keyspace_name" )
172+ keyspaceIDValue , err := s .manager .GetKeyspaceIDByName (c , keyspaceName )
175173 if err != nil {
176174 c .String (http .StatusBadRequest , err .Error ())
177175 return
178176 }
177+ keyspaceID := keyspaceIDValue .GetValue ()
179178 group := s .manager .GetResourceGroup (keyspaceID , c .Param ("name" ), withStats )
180179 if group == nil {
181180 c .String (http .StatusNotFound , errors .New ("resource group not found" ).Error ())
@@ -190,15 +189,17 @@ func (s *Service) getResourceGroup(c *gin.Context) {
190189// @Success 200 {string} json format of []rmserver.ResourceGroup
191190// @Failure 404 {string} error
192191// @Param with_stats query bool false "whether to return statistics data."
193- // @Param keyspace_id query uint32 false "keyspace ID, if not set, it will be treated as null keyspace ID. "
192+ // @Param keyspace_name path string true "Keyspace name "
194193// @Router /config/groups [get]
195194func (s * Service ) getResourceGroupList (c * gin.Context ) {
196195 withStats := strings .EqualFold (c .Query ("with_stats" ), "true" )
197- keyspaceID , err := getKeyspaceIDFromQuery (c )
196+ keyspaceName := c .Query ("keyspace_name" )
197+ keyspaceIDValue , err := s .manager .GetKeyspaceIDByName (c , keyspaceName )
198198 if err != nil {
199199 c .String (http .StatusBadRequest , err .Error ())
200200 return
201201 }
202+ keyspaceID := keyspaceIDValue .GetValue ()
202203 groups := s .manager .GetResourceGroupList (keyspaceID , withStats )
203204 c .IndentedJSON (http .StatusOK , groups )
204205}
@@ -208,16 +209,18 @@ func (s *Service) getResourceGroupList(c *gin.Context) {
208209// @Tags ResourceManager
209210// @Summary delete resource group by name.
210211// @Param name path string true "Name of the resource group to be deleted"
211- // @Param keyspace_id query uint32 false "keyspace ID, if not set, it will be treated as null keyspace ID. "
212+ // @Param keyspace_name path string true "Keyspace name "
212213// @Success 200 {string} string "Success!"
213214// @Failure 404 {string} error
214215// @Router /config/group/{name} [delete]
215216func (s * Service ) deleteResourceGroup (c * gin.Context ) {
216- keyspaceID , err := getKeyspaceIDFromQuery (c )
217+ keyspaceName := c .Query ("keyspace_name" )
218+ keyspaceIDValue , err := s .manager .GetKeyspaceIDByName (c , keyspaceName )
217219 if err != nil {
218220 c .String (http .StatusBadRequest , err .Error ())
219221 return
220222 }
223+ keyspaceID := keyspaceIDValue .GetValue ()
221224 if err := s .manager .DeleteResourceGroup (keyspaceID , c .Param ("name" )); err != nil {
222225 c .String (http .StatusNotFound , err .Error ())
223226 }
@@ -322,15 +325,3 @@ func (s *Service) getKeyspaceServiceLimit(c *gin.Context) {
322325 }
323326 c .IndentedJSON (http .StatusOK , limiter )
324327}
325-
326- func getKeyspaceIDFromQuery (c * gin.Context ) (uint32 , error ) {
327- keyspaceIDStr := c .Query ("keyspace_id" )
328- if keyspaceIDStr == "" {
329- return constant .NullKeyspaceID , nil
330- }
331- keyspaceID , err := strconv .ParseUint (keyspaceIDStr , 10 , 32 )
332- if err != nil {
333- return 0 , errs .ErrStrconvParseUint .Wrap (err ).GenWithStackByArgs (keyspaceIDStr )
334- }
335- return uint32 (keyspaceID ), nil
336- }
0 commit comments