diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index f1fecebd050..7b4199b643c 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -42,10 +42,10 @@ import ( "github.com/tikv/pd/server/join" "go.uber.org/zap" - // register microservice HTTP API - _ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/apis/v1" - _ "github.com/tikv/pd/pkg/mcs/scheduling/server/apis/v1" - _ "github.com/tikv/pd/pkg/mcs/tso/server/apis/v1" + // register microservice API + _ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/install" + _ "github.com/tikv/pd/pkg/mcs/scheduling/server/install" + _ "github.com/tikv/pd/pkg/mcs/tso/server/install" ) func main() { diff --git a/pkg/mcs/resourcemanager/server/grpc_service.go b/pkg/mcs/resourcemanager/server/grpc_service.go index cf198304dfc..5c1b5f0e458 100644 --- a/pkg/mcs/resourcemanager/server/grpc_service.go +++ b/pkg/mcs/resourcemanager/server/grpc_service.go @@ -60,7 +60,7 @@ type Service struct { } // NewService creates a new resource manager service. -func NewService[T ResourceManagerConfigProvider](svr bs.Server) registry.RegistrableService { +func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService { manager := NewManager[T](svr) return &Service{ diff --git a/pkg/mcs/resourcemanager/server/install/install.go b/pkg/mcs/resourcemanager/server/install/install.go index 89a4ac1914f..8573d5e52eb 100644 --- a/pkg/mcs/resourcemanager/server/install/install.go +++ b/pkg/mcs/resourcemanager/server/install/install.go @@ -16,7 +16,7 @@ package install import ( "github.com/tikv/pd/pkg/mcs/registry" - rm_server "github.com/tikv/pd/pkg/mcs/resourcemanager/server" + "github.com/tikv/pd/pkg/mcs/resourcemanager/server" // init API group _ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/apis/v1" @@ -28,5 +28,5 @@ func init() { // Install registers the API group and grpc service. func Install(register *registry.ServiceRegistry) { - register.RegisterService("ResourceManager", rm_server.NewService[*rm_server.Server]) + register.RegisterService("ResourceManager", server.NewService[*server.Server]) } diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 18d8c1f4d3c..1118e347f59 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -62,15 +62,15 @@ type Manager struct { consumptionRecord map[string]time.Time } -// ResourceManagerConfigProvider is used to get resource manager config from the given +// ConfigProvider is used to get resource manager config from the given // `bs.server` without modifying its interface. -type ResourceManagerConfigProvider interface { +type ConfigProvider interface { GetControllerConfig() *ControllerConfig } // NewManager returns a new manager base on the given server, -// which should implement the `ResourceManagerConfigProvider` interface. -func NewManager[T ResourceManagerConfigProvider](srv bs.Server) *Manager { +// which should implement the `ConfigProvider` interface. +func NewManager[T ConfigProvider](srv bs.Server) *Manager { m := &Manager{ controllerConfig: srv.(T).GetControllerConfig(), groups: make(map[string]*ResourceGroup), diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index 3b0e51f1f66..e75c78eb415 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -44,13 +44,17 @@ func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Write([]byte("not implemented")) } +// ConfigProvider is used to get scheduling config from the given +// `bs.server` without modifying its interface. +type ConfigProvider interface{} + // Service is the scheduling grpc service. type Service struct { *Server } // NewService creates a new TSO service. -func NewService(svr bs.Server) registry.RegistrableService { +func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService { server, ok := svr.(*Server) if !ok { log.Fatal("create scheduling server failed") diff --git a/pkg/mcs/scheduling/server/install/install.go b/pkg/mcs/scheduling/server/install/install.go new file mode 100644 index 00000000000..4ce94067efb --- /dev/null +++ b/pkg/mcs/scheduling/server/install/install.go @@ -0,0 +1,32 @@ +// Copyright 2023 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package install + +import ( + "github.com/tikv/pd/pkg/mcs/registry" + "github.com/tikv/pd/pkg/mcs/scheduling/server" + + // init API group + _ "github.com/tikv/pd/pkg/mcs/scheduling/server/apis/v1" +) + +func init() { + Install(registry.ServerServiceRegistry) +} + +// Install registers the API group and grpc service. +func Install(register *registry.ServiceRegistry) { + register.RegisterService("Scheduling", server.NewService[*server.Server]) +} diff --git a/pkg/mcs/tso/server/grpc_service.go b/pkg/mcs/tso/server/grpc_service.go index dd0a96b1cba..e9fdddf79ab 100644 --- a/pkg/mcs/tso/server/grpc_service.go +++ b/pkg/mcs/tso/server/grpc_service.go @@ -54,13 +54,17 @@ func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Write([]byte("not implemented")) } +// ConfigProvider is used to get tso config from the given +// `bs.server` without modifying its interface. +type ConfigProvider interface{} + // Service is the TSO grpc service. type Service struct { *Server } // NewService creates a new TSO service. -func NewService(svr bs.Server) registry.RegistrableService { +func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService { server, ok := svr.(*Server) if !ok { log.Fatal("create tso server failed") diff --git a/pkg/mcs/tso/server/install/install.go b/pkg/mcs/tso/server/install/install.go new file mode 100644 index 00000000000..27db0c51d75 --- /dev/null +++ b/pkg/mcs/tso/server/install/install.go @@ -0,0 +1,32 @@ +// Copyright 2023 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package install + +import ( + "github.com/tikv/pd/pkg/mcs/registry" + "github.com/tikv/pd/pkg/mcs/tso/server" + + // init API group + _ "github.com/tikv/pd/pkg/mcs/tso/server/apis/v1" +) + +func init() { + Install(registry.ServerServiceRegistry) +} + +// Install registers the API group and grpc service. +func Install(register *registry.ServiceRegistry) { + register.RegisterService("Scheduling", server.NewService[*server.Server]) +}