mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-03 12:20:27 +08:00
5秒盾策略变化时只更新策略配置
This commit is contained in:
@@ -3568,7 +3568,8 @@
|
||||
"code": "rpc deleteIPItems(DeleteIPItemsRequest) returns (RPCSuccess);",
|
||||
"doc": "批量删除IP",
|
||||
"roles": [
|
||||
"admin"
|
||||
"admin",
|
||||
"user"
|
||||
],
|
||||
"isDeprecated": false
|
||||
},
|
||||
@@ -3649,7 +3650,8 @@
|
||||
"code": "rpc countAllEnabledIPItems(CountAllEnabledIPItemsRequest) returns (RPCCountResponse);",
|
||||
"doc": "计算所有IP数量",
|
||||
"roles": [
|
||||
"admin"
|
||||
"admin",
|
||||
"user"
|
||||
],
|
||||
"isDeprecated": false
|
||||
},
|
||||
@@ -3660,7 +3662,8 @@
|
||||
"code": "rpc listAllEnabledIPItems(ListAllEnabledIPItemsRequest) returns (ListAllEnabledIPItemsResponse);",
|
||||
"doc": "列出所有名单中的IP",
|
||||
"roles": [
|
||||
"admin"
|
||||
"admin",
|
||||
"user"
|
||||
],
|
||||
"isDeprecated": false
|
||||
},
|
||||
@@ -3671,7 +3674,8 @@
|
||||
"code": "rpc updateIPItemsRead(UpdateIPItemsReadRequest) returns (RPCSuccess);",
|
||||
"doc": "设置所有为已读",
|
||||
"roles": [
|
||||
"admin"
|
||||
"admin",
|
||||
"user"
|
||||
],
|
||||
"isDeprecated": false
|
||||
}
|
||||
@@ -5550,6 +5554,15 @@
|
||||
"admin"
|
||||
],
|
||||
"isDeprecated": false
|
||||
},
|
||||
{
|
||||
"name": "findNodeUAMPolicies",
|
||||
"requestMessageName": "FindNodeUAMPoliciesRequest",
|
||||
"responseMessageName": "FindNodeUAMPoliciesResponse",
|
||||
"code": "rpc findNodeUAMPolicies(FindNodeUAMPoliciesRequest) returns (FindNodeUAMPoliciesResponse);",
|
||||
"doc": "查找节点的UAM策略",
|
||||
"roles": [],
|
||||
"isDeprecated": false
|
||||
}
|
||||
],
|
||||
"filename": "service_node.proto",
|
||||
@@ -18687,6 +18700,16 @@
|
||||
"code": "message FindNodeTasksResponse {\n\trepeated NodeTask nodeTasks = 1;\n}",
|
||||
"doc": ""
|
||||
},
|
||||
{
|
||||
"name": "FindNodeUAMPoliciesRequest",
|
||||
"code": "message FindNodeUAMPoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
|
||||
"doc": "查找节点的UAM策略"
|
||||
},
|
||||
{
|
||||
"name": "FindNodeUAMPoliciesResponse",
|
||||
"code": "message FindNodeUAMPoliciesResponse {\n\trepeated UAMPolicy uamPolicies = 1; // UAM策略列表\n\n\n\tmessage UAMPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes uamPolicyJSON = 2; // UAM策略配置\n\t}\n}",
|
||||
"doc": ""
|
||||
},
|
||||
{
|
||||
"name": "FindNotifyingNodeTasksRequest",
|
||||
"code": "message FindNotifyingNodeTasksRequest {\n\tint64 size = 1;\n}",
|
||||
|
||||
@@ -19,9 +19,11 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var sharedNodeConfig *NodeConfig = nil
|
||||
var uamPolicyLocker = &sync.RWMutex{}
|
||||
|
||||
type ServerError struct {
|
||||
Id int64
|
||||
@@ -190,6 +192,9 @@ func CloneNodeConfig(nodeConfig *NodeConfig) (*NodeConfig, error) {
|
||||
return nil, errors.New("node config should not be nil")
|
||||
}
|
||||
|
||||
uamPolicyLocker.RLock()
|
||||
defer uamPolicyLocker.RUnlock()
|
||||
|
||||
var newConfigValue = reflect.Indirect(reflect.ValueOf(&NodeConfig{}))
|
||||
var oldValue = reflect.Indirect(reflect.ValueOf(nodeConfig))
|
||||
var valueType = oldValue.Type()
|
||||
@@ -374,14 +379,17 @@ func (this *NodeConfig) Init(ctx context.Context) (err error, serverErrors []*Se
|
||||
}
|
||||
|
||||
// uam policy
|
||||
uamPolicyLocker.RLock()
|
||||
if this.UAMPolicies != nil {
|
||||
for _, policy := range this.UAMPolicies {
|
||||
err = policy.Init()
|
||||
if err != nil {
|
||||
uamPolicyLocker.RUnlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
uamPolicyLocker.RUnlock()
|
||||
|
||||
// dns resolver
|
||||
if this.DNSResolver != nil {
|
||||
@@ -608,12 +616,21 @@ func (this *NodeConfig) FindWebPImagePolicyWithClusterId(clusterId int64) *WebPI
|
||||
|
||||
// FindUAMPolicyWithClusterId 使用集群ID查找UAM策略
|
||||
func (this *NodeConfig) FindUAMPolicyWithClusterId(clusterId int64) *UAMPolicy {
|
||||
uamPolicyLocker.RLock()
|
||||
defer uamPolicyLocker.RUnlock()
|
||||
if this.UAMPolicies == nil {
|
||||
return nil
|
||||
}
|
||||
return this.UAMPolicies[clusterId]
|
||||
}
|
||||
|
||||
// UpdateUAMPolicies 修改集群UAM策略
|
||||
func (this *NodeConfig) UpdateUAMPolicies(policies map[int64]*UAMPolicy) {
|
||||
uamPolicyLocker.Lock()
|
||||
defer uamPolicyLocker.Unlock()
|
||||
this.UAMPolicies = policies
|
||||
}
|
||||
|
||||
// SecretHash 对Id和Secret的Hash计算
|
||||
func (this *NodeConfig) SecretHash() string {
|
||||
return this.secretHash
|
||||
|
||||
@@ -97,5 +97,24 @@ func TestNodeConfig_AddServer(t *testing.T) {
|
||||
for _, s := range config.Servers {
|
||||
t.Log(s.Id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCloneNodeConfig_UAMPolicies(t *testing.T) {
|
||||
var config = &NodeConfig{}
|
||||
config.UAMPolicies = map[int64]*UAMPolicy{}
|
||||
t.Logf("%p", config.UAMPolicies)
|
||||
|
||||
clonedConfig, err := CloneNodeConfig(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("%p", clonedConfig.UAMPolicies)
|
||||
}
|
||||
|
||||
func BenchmarkNodeConfig(b *testing.B) {
|
||||
var config = &NodeConfig{}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _ = CloneNodeConfig(config)
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -169,6 +169,9 @@ service NodeService {
|
||||
|
||||
// 修改某个节点的API相关配置
|
||||
rpc updateNodeAPIConfig(UpdateNodeAPIConfigRequest) returns (RPCSuccess);
|
||||
|
||||
// 查找节点的UAM策略
|
||||
rpc findNodeUAMPolicies(FindNodeUAMPoliciesRequest) returns (FindNodeUAMPoliciesResponse);
|
||||
}
|
||||
|
||||
// 创建节点
|
||||
@@ -657,4 +660,18 @@ message FindNodeAPIConfigResponse {
|
||||
message UpdateNodeAPIConfigRequest {
|
||||
int64 nodeId = 1;
|
||||
bytes apiNodeAddrsJSON = 2;
|
||||
}
|
||||
|
||||
// 查找节点的UAM策略
|
||||
message FindNodeUAMPoliciesRequest {
|
||||
int64 nodeId = 1; // 节点ID
|
||||
}
|
||||
|
||||
message FindNodeUAMPoliciesResponse {
|
||||
repeated UAMPolicy uamPolicies = 1; // UAM策略列表
|
||||
|
||||
message UAMPolicy {
|
||||
int64 nodeClusterId = 1; // 集群ID
|
||||
bytes uamPolicyJSON = 2; // UAM策略配置
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user