Skip to content

Commit fd23d40

Browse files
authored
codecov:1.18.0 (polarismesh#1315)
1 parent 6ca3a58 commit fd23d40

File tree

7 files changed

+87
-35
lines changed

7 files changed

+87
-35
lines changed

bootstrap/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func StartConfigCenterComponents(ctx context.Context, cfg *boot_config.Config, s
305305
return err
306306
}
307307
cfg.Config.Interceptors = config_center.GetChainOrder()
308-
return config_center.Initialize(ctx, cfg.Config, s, cacheMgn, namespaceOperator, userMgn, strategyMgn)
308+
return config_center.Initialize(ctx, cfg.Config, s, cacheMgn, namespaceOperator)
309309
}
310310

311311
// StartServers 启动server

cache/api/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type CacheManager interface {
119119
GetCacher(cacheIndex CacheIndex) Cache
120120
// RegisterCacher
121121
RegisterCacher(cacheIndex CacheIndex, item Cache)
122-
//
122+
// OpenResourceCache
123123
OpenResourceCache(entries ...ConfigEntry) error
124124
// Service 获取Service缓存信息
125125
Service() ServiceCache

config/client.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,37 @@ type (
4040

4141
// GetConfigFileWithCache 从缓存中获取配置文件,如果客户端的版本号大于服务端,则服务端重新加载缓存
4242
func (s *Server) GetConfigFileWithCache(ctx context.Context,
43-
client *apiconfig.ClientConfigFileInfo) *apiconfig.ConfigClientResponse {
44-
namespace := client.GetNamespace().GetValue()
45-
group := client.GetGroup().GetValue()
46-
fileName := client.GetFileName().GetValue()
43+
req *apiconfig.ClientConfigFileInfo) *apiconfig.ConfigClientResponse {
44+
namespace := req.GetNamespace().GetValue()
45+
group := req.GetGroup().GetValue()
46+
fileName := req.GetFileName().GetValue()
4747

4848
if namespace == "" || group == "" || fileName == "" {
4949
return api.NewConfigClientResponseWithInfo(
5050
apimodel.Code_BadRequest, "namespace & group & fileName can not be empty")
5151
}
52-
client = formatClientRequest(ctx, client)
52+
req = formatClientRequest(ctx, req)
5353
// 从缓存中获取灰度文件
5454
var release *model.ConfigFileRelease
5555
var match = false
56-
if len(client.GetTags()) > 0 {
56+
if len(req.GetTags()) > 0 {
5757
if release = s.fileCache.GetActiveGrayRelease(namespace, group, fileName); release != nil {
5858
key := model.GetGrayConfigRealseKey(release.SimpleConfigFileRelease)
59-
match = s.grayCache.HitGrayRule(key, model.ToTagMap(client.GetTags()))
59+
match = s.grayCache.HitGrayRule(key, model.ToTagMap(req.GetTags()))
6060
}
6161
}
6262
if !match {
6363
if release = s.fileCache.GetActiveRelease(namespace, group, fileName); release == nil {
64-
return api.NewConfigClientResponse(apimodel.Code_NotFoundResource, nil)
64+
return api.NewConfigClientResponse(apimodel.Code_NotFoundResource, req)
6565
}
6666
}
6767
// 客户端版本号大于等于服务端版本号,服务端不返回变更
68-
if client.GetVersion().GetValue() >= release.Version {
69-
return api.NewConfigClientResponse(apimodel.Code_DataNoChange, nil)
68+
if req.GetVersion().GetValue() >= release.Version {
69+
return api.NewConfigClientResponse(apimodel.Code_DataNoChange, req)
7070
}
71-
configFile, err := toClientInfo(client, release)
71+
configFile, err := toClientInfo(req, release)
7272
if err != nil {
73-
log.Error("[Config][Service] get config file to client info", utils.RequestID(ctx), zap.Error(err))
73+
log.Error("[Config][Service] get config file to client", utils.RequestID(ctx), zap.Error(err))
7474
return api.NewConfigClientResponseWithInfo(apimodel.Code_ExecuteException, err.Error())
7575
}
7676
return api.NewConfigClientResponse(apimodel.Code_ExecuteSuccess, configFile)

config/server.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424

2525
apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
2626

27-
"github.com/polarismesh/polaris/auth"
28-
"github.com/polarismesh/polaris/cache"
2927
cachetypes "github.com/polarismesh/polaris/cache/api"
3028
"github.com/polarismesh/polaris/common/model"
3129
"github.com/polarismesh/polaris/common/utils"
@@ -73,7 +71,7 @@ type Server struct {
7371
fileCache cachetypes.ConfigFileCache
7472
groupCache cachetypes.ConfigGroupCache
7573
grayCache cachetypes.GrayCache
76-
caches *cache.CacheManager
74+
caches cachetypes.CacheManager
7775
watchCenter *watchCenter
7876
namespaceOperator namespace.NamespaceOperateServer
7977
initialized bool
@@ -89,8 +87,8 @@ type Server struct {
8987
}
9088

9189
// Initialize 初始化配置中心模块
92-
func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cache.CacheManager,
93-
namespaceOperator namespace.NamespaceOperateServer, userMgn auth.UserServer, strategyMgn auth.StrategyServer) error {
90+
func Initialize(ctx context.Context, config Config, s store.Store, cacheMgr cachetypes.CacheManager,
91+
namespaceOperator namespace.NamespaceOperateServer) error {
9492
if !config.Open {
9593
originServer.initialized = true
9694
return nil
@@ -100,10 +98,10 @@ func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cac
10098
return nil
10199
}
102100

103-
if err := cacheMgn.OpenResourceCache(configCacheEntries...); err != nil {
101+
if err := cacheMgr.OpenResourceCache(configCacheEntries...); err != nil {
104102
return err
105103
}
106-
err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgn)
104+
err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgr)
107105
if err != nil {
108106
return err
109107
}
@@ -128,19 +126,19 @@ func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cac
128126
}
129127

130128
func (s *Server) initialize(ctx context.Context, config Config, ss store.Store,
131-
namespaceOperator namespace.NamespaceOperateServer, cacheMgn *cache.CacheManager) error {
129+
namespaceOperator namespace.NamespaceOperateServer, cacheMgr cachetypes.CacheManager) error {
132130
var err error
133131
s.cfg = &config
134132
if s.cfg.ContentMaxLength <= 0 {
135133
s.cfg.ContentMaxLength = fileContentMaxLength
136134
}
137135
s.storage = ss
138136
s.namespaceOperator = namespaceOperator
139-
s.fileCache = cacheMgn.ConfigFile()
140-
s.groupCache = cacheMgn.ConfigGroup()
141-
s.grayCache = cacheMgn.Gray()
137+
s.fileCache = cacheMgr.ConfigFile()
138+
s.groupCache = cacheMgr.ConfigGroup()
139+
s.grayCache = cacheMgr.Gray()
142140

143-
s.watchCenter, err = NewWatchCenter(cacheMgn)
141+
s.watchCenter, err = NewWatchCenter(cacheMgr)
144142
if err != nil {
145143
return err
146144
}
@@ -156,7 +154,7 @@ func (s *Server) initialize(ctx context.Context, config Config, ss store.Store,
156154
log.Warnf("Not Found Crypto Plugin")
157155
}
158156

159-
s.caches = cacheMgn
157+
s.caches = cacheMgr
160158
s.chains = newConfigChains(s, []ConfigFileChain{
161159
&CryptoConfigFileChain{},
162160
&ReleaseConfigFileChain{},

config/server_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package config
19+
20+
import (
21+
"context"
22+
"testing"
23+
24+
"github.com/golang/mock/gomock"
25+
mockcache "github.com/polarismesh/polaris/cache/mock"
26+
"github.com/polarismesh/polaris/common/eventhub"
27+
mockstore "github.com/polarismesh/polaris/store/mock"
28+
"github.com/stretchr/testify/assert"
29+
)
30+
31+
func Test_Initialize(t *testing.T) {
32+
t.SkipNow()
33+
eventhub.InitEventHub()
34+
ctrl := gomock.NewController(t)
35+
mockStore := mockstore.NewMockStore(ctrl)
36+
cacheMgr := mockcache.NewMockCacheManager(ctrl)
37+
38+
t.Cleanup(func() {
39+
ctrl.Finish()
40+
originServer.watchCenter.Close()
41+
originServer.initialized = false
42+
originServer = nil
43+
server = nil
44+
})
45+
46+
cacheMgr.EXPECT().OpenResourceCache(gomock.Any()).Return(nil).AnyTimes()
47+
cacheMgr.EXPECT().ConfigFile().Return(nil).AnyTimes()
48+
cacheMgr.EXPECT().Gray().Return(nil).AnyTimes()
49+
cacheMgr.EXPECT().ConfigGroup().Return(nil).AnyTimes()
50+
51+
err := Initialize(context.Background(), Config{
52+
Open: true,
53+
}, mockStore, cacheMgr, nil)
54+
assert.NoError(t, err)
55+
assert.NotNil(t, originServer)
56+
}

test/data/cluster-polaris-server.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,9 @@ store:
412412
txIsolationLevel: 2 #LevelReadCommitted
413413
# 插件配置
414414
plugin:
415-
# whitelist:
416-
# name: whitelist
417-
# option:
418-
# ip: [127.0.0.1]
415+
crypto:
416+
entries:
417+
- name: AES
419418
history:
420419
entries:
421420
- name: HistoryLogger

test/data/polaris-server.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,9 @@ store:
415415
txIsolationLevel: 2 #LevelReadCommitted
416416
# 插件配置
417417
plugin:
418-
# whitelist:
419-
# name: whitelist
420-
# option:
421-
# ip: [127.0.0.1]
418+
crypto:
419+
entries:
420+
- name: AES
422421
cmdb:
423422
name: memory
424423
option:

0 commit comments

Comments
 (0)