@@ -20,21 +20,32 @@ package admin
2020import (
2121 "context"
2222 "errors"
23+ "fmt"
2324
2425 "github.com/polarismesh/polaris/admin/job"
25- "github.com/polarismesh/polaris/auth"
2626 "github.com/polarismesh/polaris/cache"
2727 "github.com/polarismesh/polaris/service"
2828 "github.com/polarismesh/polaris/service/healthcheck"
2929 "github.com/polarismesh/polaris/store"
3030)
3131
3232var (
33- server AdminOperateServer
34- maintainServer = & Server {}
35- finishInit bool
33+ server AdminOperateServer
34+ maintainServer = & Server {}
35+ finishInit bool
36+ serverProxyFactories = map [string ]ServerProxyFactory {}
3637)
3738
39+ type ServerProxyFactory func (ctx context.Context , pre AdminOperateServer ) (AdminOperateServer , error )
40+
41+ func RegisterServerProxy (name string , factor ServerProxyFactory ) error {
42+ if _ , ok := serverProxyFactories [name ]; ok {
43+ return fmt .Errorf ("duplicate ServerProxyFactory, name(%s)" , name )
44+ }
45+ serverProxyFactories [name ] = factor
46+ return nil
47+ }
48+
3849// Initialize 初始化
3950func Initialize (ctx context.Context , cfg * Config , namingService service.DiscoverServer ,
4051 healthCheckServer * healthcheck.Server , cacheMgn * cache.CacheManager , storage store.Store ) error {
@@ -43,40 +54,49 @@ func Initialize(ctx context.Context, cfg *Config, namingService service.Discover
4354 return nil
4455 }
4556
46- err := initialize (ctx , cfg , namingService , healthCheckServer , cacheMgn , storage )
57+ proxySvr , actualSvr , err := InitServer (ctx , cfg , namingService , healthCheckServer , cacheMgn , storage )
4758 if err != nil {
4859 return err
4960 }
5061
62+ server = proxySvr
63+ maintainServer = actualSvr
5164 finishInit = true
5265 return nil
5366}
5467
55- func initialize ( _ context.Context , cfg * Config , namingService service.DiscoverServer ,
56- healthCheckServer * healthcheck.Server , cacheMgn * cache.CacheManager , storage store.Store ) error {
68+ func InitServer ( ctx context.Context , cfg * Config , namingService service.DiscoverServer ,
69+ healthCheckServer * healthcheck.Server , cacheMgn * cache.CacheManager , storage store.Store ) ( AdminOperateServer , * Server , error ) {
5770
58- userMgn , err := auth .GetUserServer ()
59- if err != nil {
60- return err
61- }
71+ actualSvr := new (Server )
6272
63- strategyMgn , err := auth .GetStrategyServer ()
64- if err != nil {
65- return err
66- }
67-
68- maintainServer .namingServer = namingService
69- maintainServer .healthCheckServer = healthCheckServer
70- maintainServer .cacheMgn = cacheMgn
71- maintainServer .storage = storage
73+ actualSvr .namingServer = namingService
74+ actualSvr .healthCheckServer = healthCheckServer
75+ actualSvr .cacheMgn = cacheMgn
76+ actualSvr .storage = storage
7277
7378 maintainJobs := job .NewMaintainJobs (namingService , cacheMgn , storage )
7479 if err := maintainJobs .StartMaintianJobs (cfg .Jobs ); err != nil {
75- return err
80+ return nil , nil , err
7681 }
7782
78- server = newServerAuthAbility (maintainServer , userMgn , strategyMgn )
79- return nil
83+ var proxySvr AdminOperateServer
84+ proxySvr = actualSvr
85+ order := GetChainOrder ()
86+ for i := range order {
87+ factory , exist := serverProxyFactories [order [i ]]
88+ if ! exist {
89+ return nil , nil , fmt .Errorf ("name(%s) not exist in serverProxyFactories" , order [i ])
90+ }
91+
92+ afterSvr , err := factory (ctx , proxySvr )
93+ if err != nil {
94+ return nil , nil , err
95+ }
96+ proxySvr = afterSvr
97+ }
98+
99+ return proxySvr , actualSvr , nil
80100}
81101
82102// GetServer 获取已经初始化好的Server
0 commit comments