WebP策略变化时只更新相关配置

This commit is contained in:
GoEdgeLab
2023-12-11 11:08:48 +08:00
parent c64f1af77c
commit bd0b7e31bf
8 changed files with 862 additions and 563 deletions

View File

@@ -5649,6 +5649,15 @@
"node"
],
"isDeprecated": false
},
{
"name": "findNodeWebPPolicies",
"requestMessageName": "FindNodeWebPPoliciesRequest",
"responseMessageName": "FindNodeWebPPoliciesResponse",
"code": "rpc findNodeWebPPolicies(FindNodeWebPPoliciesRequest) returns (FindNodeWebPPoliciesResponse);",
"doc": "查找节点的WebP策略",
"roles": [],
"isDeprecated": false
}
],
"filename": "service_node.proto",
@@ -18084,7 +18093,7 @@
},
{
"name": "FindEnabledNodeClusterConfigInfoResponse",
"code": "message FindEnabledNodeClusterConfigInfoResponse {\n\tbool healthCheckIsOn = 1; // 启用了健康检查\n\tbool hasFirewallActions = 2; // 有防火墙动作设置\n\tbool hasThresholds = 3; // 有节点阈值设置\n\tbool hasMessageReceivers = 4; // 已设置消息通知接收人\n\tbool isTOAEnabled = 5; // 启用了TOA\n\tbool hasMetricItems = 6; // 有指标统计设置\n\tbool webpIsOn = 7; // 是否定义了WebP策略\n\tbool uamIsOn = 10; // 是否定义了UAM策略\n\tbool httpCCIsOn = 12; // 是否定义了CC策略\n\tbool hasSystemServices = 8; // 启用了系统服务\n\tbool hasDDoSProtection = 9; // 启用了DDoS防护\n\tbool hasHTTPPagesPolicy = 11; // 是否设置了自定义页面策略\n\tbool http3IsOn = 13; // 是否启用HTTP3\n\tbool hasNetworkSecurityPolicy = 14; // 设置了网络安全策略\n}",
"code": "message FindEnabledNodeClusterConfigInfoResponse {\n\tbool healthCheckIsOn = 1; // 启用了健康检查\n\tbool hasFirewallActions = 2; // 有防火墙动作设置\n\tbool hasThresholds = 3; // 有节点阈值设置\n\tbool hasMessageReceivers = 4; // 已设置消息通知接收人\n\tbool isTOAEnabled = 5; // 启用了TOA\n\tbool hasMetricItems = 6; // 有指标统计设置\n\tbool webPIsOn = 7; // 是否定义了WebP策略\n\tbool uamIsOn = 10; // 是否定义了UAM策略\n\tbool httpCCIsOn = 12; // 是否定义了CC策略\n\tbool hasSystemServices = 8; // 启用了系统服务\n\tbool hasDDoSProtection = 9; // 启用了DDoS防护\n\tbool hasHTTPPagesPolicy = 11; // 是否设置了自定义页面策略\n\tbool http3IsOn = 13; // 是否启用HTTP3\n\tbool hasNetworkSecurityPolicy = 14; // 设置了网络安全策略\n}",
"doc": ""
},
{
@@ -19432,6 +19441,16 @@
"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": "FindNodeWebPPoliciesRequest",
"code": "message FindNodeWebPPoliciesRequest {\n\n}",
"doc": "查找节点的WebP策略"
},
{
"name": "FindNodeWebPPoliciesResponse",
"code": "message FindNodeWebPPoliciesResponse {\n\trepeated WebPPolicy webPPolicies = 1; // WebP策略列表\n\n\n\tmessage WebPPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes webPPolicyJSON = 2; // WebP策略配置\n\t}\n}",
"doc": ""
},
{
"name": "FindNotifyingNodeTasksRequest",
"code": "message FindNotifyingNodeTasksRequest {\n\tint64 size = 1;\n}",
@@ -22339,7 +22358,7 @@
},
{
"name": "UpdateNodeClusterWebPPolicyRequest",
"code": "message UpdateNodeClusterWebPPolicyRequest {\n\tint64 nodeClusterId = 1;\n\tbytes webpPolicyJSON = 2;\n}",
"code": "message UpdateNodeClusterWebPPolicyRequest {\n\tint64 nodeClusterId = 1;\n\tbytes webPPolicyJSON = 2;\n}",
"doc": "设置集群WebP策略"
},
{

View File

@@ -8,11 +8,15 @@ func init() {
_ = DefaultWebPImagePolicy.Init()
}
var DefaultWebPImagePolicy = &WebPImagePolicy{
IsOn: true,
RequireCache: true,
MinLength: shared.NewSizeCapacity(0, shared.SizeCapacityUnitKB),
MaxLength: shared.NewSizeCapacity(128, shared.SizeCapacityUnitMB),
var DefaultWebPImagePolicy = NewWebPImagePolicy()
func NewWebPImagePolicy() *WebPImagePolicy {
return &WebPImagePolicy{
IsOn: true,
RequireCache: true,
MinLength: shared.NewSizeCapacity(0, shared.SizeCapacityUnitKB),
MaxLength: shared.NewSizeCapacity(128, shared.SizeCapacityUnitMB),
}
}
// WebPImagePolicy WebP策略

View File

@@ -28,6 +28,7 @@ var uamPolicyLocker = &sync.RWMutex{}
var httpCCPolicyLocker = &sync.RWMutex{}
var http3PolicyLocker = &sync.RWMutex{}
var httpPagesPolicyLocker = &sync.RWMutex{}
var webPPolicyLocker = &sync.RWMutex{}
type ServerError struct {
Id int64
@@ -210,6 +211,9 @@ func CloneNodeConfig(nodeConfig *NodeConfig) (*NodeConfig, error) {
httpPagesPolicyLocker.RLock()
defer httpPagesPolicyLocker.RUnlock()
webPPolicyLocker.RLock()
defer webPPolicyLocker.RUnlock()
var newConfigValue = reflect.Indirect(reflect.ValueOf(&NodeConfig{}))
var oldValue = reflect.Indirect(reflect.ValueOf(nodeConfig))
var valueType = oldValue.Type()
@@ -376,14 +380,17 @@ func (this *NodeConfig) Init(ctx context.Context) (err error, serverErrors []*Se
}
// webp image policy
webPPolicyLocker.RLock()
if this.WebPImagePolicies != nil {
for _, policy := range this.WebPImagePolicies {
err = policy.Init()
if err != nil {
webPPolicyLocker.RUnlock()
return
}
}
}
webPPolicyLocker.RUnlock()
// uam policy
uamPolicyLocker.RLock()
@@ -675,12 +682,22 @@ func (this *NodeConfig) UpdateCertOCSP(certId int64, ocsp []byte, expiresAt int6
// FindWebPImagePolicyWithClusterId 使用集群ID查找WebP策略
func (this *NodeConfig) FindWebPImagePolicyWithClusterId(clusterId int64) *WebPImagePolicy {
webPPolicyLocker.RLock()
defer webPPolicyLocker.RUnlock()
if this.WebPImagePolicies == nil {
return nil
}
return this.WebPImagePolicies[clusterId]
}
// UpdateWebPImagePolicies 修改集群WebP策略
func (this *NodeConfig) UpdateWebPImagePolicies(policies map[int64]*WebPImagePolicy) {
webPPolicyLocker.Lock()
defer webPPolicyLocker.Unlock()
this.WebPImagePolicies = policies
}
// FindUAMPolicyWithClusterId 使用集群ID查找UAM策略
func (this *NodeConfig) FindUAMPolicyWithClusterId(clusterId int64) *UAMPolicy {
uamPolicyLocker.RLock()

File diff suppressed because it is too large Load Diff

View File

@@ -2987,7 +2987,7 @@ type FindEnabledNodeClusterConfigInfoResponse struct {
HasMessageReceivers bool `protobuf:"varint,4,opt,name=hasMessageReceivers,proto3" json:"hasMessageReceivers,omitempty"` // 已设置消息通知接收人
IsTOAEnabled bool `protobuf:"varint,5,opt,name=isTOAEnabled,proto3" json:"isTOAEnabled,omitempty"` // 启用了TOA
HasMetricItems bool `protobuf:"varint,6,opt,name=hasMetricItems,proto3" json:"hasMetricItems,omitempty"` // 有指标统计设置
WebpIsOn bool `protobuf:"varint,7,opt,name=webpIsOn,proto3" json:"webpIsOn,omitempty"` // 是否定义了WebP策略
WebPIsOn bool `protobuf:"varint,7,opt,name=webPIsOn,proto3" json:"webPIsOn,omitempty"` // 是否定义了WebP策略
UamIsOn bool `protobuf:"varint,10,opt,name=uamIsOn,proto3" json:"uamIsOn,omitempty"` // 是否定义了UAM策略
HttpCCIsOn bool `protobuf:"varint,12,opt,name=httpCCIsOn,proto3" json:"httpCCIsOn,omitempty"` // 是否定义了CC策略
HasSystemServices bool `protobuf:"varint,8,opt,name=hasSystemServices,proto3" json:"hasSystemServices,omitempty"` // 启用了系统服务
@@ -3071,9 +3071,9 @@ func (x *FindEnabledNodeClusterConfigInfoResponse) GetHasMetricItems() bool {
return false
}
func (x *FindEnabledNodeClusterConfigInfoResponse) GetWebpIsOn() bool {
func (x *FindEnabledNodeClusterConfigInfoResponse) GetWebPIsOn() bool {
if x != nil {
return x.WebpIsOn
return x.WebPIsOn
}
return false
}
@@ -3285,7 +3285,7 @@ type UpdateNodeClusterWebPPolicyRequest struct {
unknownFields protoimpl.UnknownFields
NodeClusterId int64 `protobuf:"varint,1,opt,name=nodeClusterId,proto3" json:"nodeClusterId,omitempty"`
WebpPolicyJSON []byte `protobuf:"bytes,2,opt,name=webpPolicyJSON,proto3" json:"webpPolicyJSON,omitempty"`
WebPPolicyJSON []byte `protobuf:"bytes,2,opt,name=webPPolicyJSON,proto3" json:"webPPolicyJSON,omitempty"`
}
func (x *UpdateNodeClusterWebPPolicyRequest) Reset() {
@@ -3327,9 +3327,9 @@ func (x *UpdateNodeClusterWebPPolicyRequest) GetNodeClusterId() int64 {
return 0
}
func (x *UpdateNodeClusterWebPPolicyRequest) GetWebpPolicyJSON() []byte {
func (x *UpdateNodeClusterWebPPolicyRequest) GetWebPPolicyJSON() []byte {
if x != nil {
return x.WebpPolicyJSON
return x.WebPPolicyJSON
}
return nil
}
@@ -4902,8 +4902,8 @@ var file_service_node_cluster_proto_rawDesc = []byte{
0x41, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x12, 0x26, 0x0a, 0x0e, 0x68, 0x61, 0x73, 0x4d,
0x65, 0x74, 0x72, 0x69, 0x63, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08,
0x52, 0x0e, 0x68, 0x61, 0x73, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x49, 0x74, 0x65, 0x6d, 0x73,
0x12, 0x1a, 0x0a, 0x08, 0x77, 0x65, 0x62, 0x70, 0x49, 0x73, 0x4f, 0x6e, 0x18, 0x07, 0x20, 0x01,
0x28, 0x08, 0x52, 0x08, 0x77, 0x65, 0x62, 0x70, 0x49, 0x73, 0x4f, 0x6e, 0x12, 0x18, 0x0a, 0x07,
0x12, 0x1a, 0x0a, 0x08, 0x77, 0x65, 0x62, 0x50, 0x49, 0x73, 0x4f, 0x6e, 0x18, 0x07, 0x20, 0x01,
0x28, 0x08, 0x52, 0x08, 0x77, 0x65, 0x62, 0x50, 0x49, 0x73, 0x4f, 0x6e, 0x12, 0x18, 0x0a, 0x07,
0x75, 0x61, 0x6d, 0x49, 0x73, 0x4f, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x75,
0x61, 0x6d, 0x49, 0x73, 0x4f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x43, 0x43,
0x49, 0x73, 0x4f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70,
@@ -4943,8 +4943,8 @@ var file_service_node_cluster_proto_rawDesc = []byte{
0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x6e,
0x6f, 0x64, 0x65, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x03, 0x52, 0x0d, 0x6e, 0x6f, 0x64, 0x65, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49,
0x64, 0x12, 0x26, 0x0a, 0x0e, 0x77, 0x65, 0x62, 0x70, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x4a,
0x53, 0x4f, 0x4e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x77, 0x65, 0x62, 0x70, 0x50,
0x64, 0x12, 0x26, 0x0a, 0x0e, 0x77, 0x65, 0x62, 0x50, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x4a,
0x53, 0x4f, 0x4e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x77, 0x65, 0x62, 0x50, 0x50,
0x6f, 0x6c, 0x69, 0x63, 0x79, 0x4a, 0x53, 0x4f, 0x4e, 0x22, 0x4e, 0x0a, 0x26, 0x46, 0x69, 0x6e,
0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6c, 0x75, 0x73,
0x74, 0x65, 0x72, 0x55, 0x41, 0x4d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75,

View File

@@ -83,6 +83,7 @@ const (
NodeService_CopyNodeActionsToNodeCluster_FullMethodName = "/pb.NodeService/copyNodeActionsToNodeCluster"
NodeService_FindNodeTOAConfig_FullMethodName = "/pb.NodeService/findNodeTOAConfig"
NodeService_FindNodeNetworkSecurityPolicy_FullMethodName = "/pb.NodeService/findNodeNetworkSecurityPolicy"
NodeService_FindNodeWebPPolicies_FullMethodName = "/pb.NodeService/findNodeWebPPolicies"
)
// NodeServiceClient is the client API for NodeService service.
@@ -217,6 +218,8 @@ type NodeServiceClient interface {
FindNodeTOAConfig(ctx context.Context, in *FindNodeTOAConfigRequest, opts ...grpc.CallOption) (*FindNodeTOAConfigResponse, error)
// 查找节点的网络安全策略
FindNodeNetworkSecurityPolicy(ctx context.Context, in *FindNodeNetworkSecurityPolicyRequest, opts ...grpc.CallOption) (*FindNodeNetworkSecurityPolicyResponse, error)
// 查找节点的WebP策略
FindNodeWebPPolicies(ctx context.Context, in *FindNodeWebPPoliciesRequest, opts ...grpc.CallOption) (*FindNodeWebPPoliciesResponse, error)
}
type nodeServiceClient struct {
@@ -825,6 +828,15 @@ func (c *nodeServiceClient) FindNodeNetworkSecurityPolicy(ctx context.Context, i
return out, nil
}
func (c *nodeServiceClient) FindNodeWebPPolicies(ctx context.Context, in *FindNodeWebPPoliciesRequest, opts ...grpc.CallOption) (*FindNodeWebPPoliciesResponse, error) {
out := new(FindNodeWebPPoliciesResponse)
err := c.cc.Invoke(ctx, NodeService_FindNodeWebPPolicies_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// NodeServiceServer is the server API for NodeService service.
// All implementations should embed UnimplementedNodeServiceServer
// for forward compatibility
@@ -957,6 +969,8 @@ type NodeServiceServer interface {
FindNodeTOAConfig(context.Context, *FindNodeTOAConfigRequest) (*FindNodeTOAConfigResponse, error)
// 查找节点的网络安全策略
FindNodeNetworkSecurityPolicy(context.Context, *FindNodeNetworkSecurityPolicyRequest) (*FindNodeNetworkSecurityPolicyResponse, error)
// 查找节点的WebP策略
FindNodeWebPPolicies(context.Context, *FindNodeWebPPoliciesRequest) (*FindNodeWebPPoliciesResponse, error)
}
// UnimplementedNodeServiceServer should be embedded to have forward compatible implementations.
@@ -1155,6 +1169,9 @@ func (UnimplementedNodeServiceServer) FindNodeTOAConfig(context.Context, *FindNo
func (UnimplementedNodeServiceServer) FindNodeNetworkSecurityPolicy(context.Context, *FindNodeNetworkSecurityPolicyRequest) (*FindNodeNetworkSecurityPolicyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method FindNodeNetworkSecurityPolicy not implemented")
}
func (UnimplementedNodeServiceServer) FindNodeWebPPolicies(context.Context, *FindNodeWebPPoliciesRequest) (*FindNodeWebPPoliciesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method FindNodeWebPPolicies not implemented")
}
// UnsafeNodeServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to NodeServiceServer will
@@ -2327,6 +2344,24 @@ func _NodeService_FindNodeNetworkSecurityPolicy_Handler(srv interface{}, ctx con
return interceptor(ctx, in, info, handler)
}
func _NodeService_FindNodeWebPPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FindNodeWebPPoliciesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(NodeServiceServer).FindNodeWebPPolicies(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: NodeService_FindNodeWebPPolicies_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(NodeServiceServer).FindNodeWebPPolicies(ctx, req.(*FindNodeWebPPoliciesRequest))
}
return interceptor(ctx, in, info, handler)
}
// NodeService_ServiceDesc is the grpc.ServiceDesc for NodeService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -2586,6 +2621,10 @@ var NodeService_ServiceDesc = grpc.ServiceDesc{
MethodName: "findNodeNetworkSecurityPolicy",
Handler: _NodeService_FindNodeNetworkSecurityPolicy_Handler,
},
{
MethodName: "findNodeWebPPolicies",
Handler: _NodeService_FindNodeWebPPolicies_Handler,
},
},
Streams: []grpc.StreamDesc{
{

View File

@@ -205,6 +205,9 @@ service NodeService {
// 查找节点的网络安全策略
rpc findNodeNetworkSecurityPolicy(FindNodeNetworkSecurityPolicyRequest) returns (FindNodeNetworkSecurityPolicyResponse);
// 查找节点的WebP策略
rpc findNodeWebPPolicies(FindNodeWebPPoliciesRequest) returns (FindNodeWebPPoliciesResponse);
}
// 创建节点
@@ -827,4 +830,18 @@ message FindNodeNetworkSecurityPolicyRequest {
message FindNodeNetworkSecurityPolicyResponse {
bytes networkSecurityPolicyJSON = 1; // 网络安全策略
}
// 查找节点的WebP策略
message FindNodeWebPPoliciesRequest {
}
message FindNodeWebPPoliciesResponse {
repeated WebPPolicy webPPolicies = 1; // WebP策略列表
message WebPPolicy {
int64 nodeClusterId = 1; // 集群ID
bytes webPPolicyJSON = 2; // WebP策略配置
}
}

View File

@@ -482,7 +482,7 @@ message FindEnabledNodeClusterConfigInfoResponse {
bool hasMessageReceivers = 4; // 已设置消息通知接收人
bool isTOAEnabled = 5; // 启用了TOA
bool hasMetricItems = 6; // 有指标统计设置
bool webpIsOn = 7; // 是否定义了WebP策略
bool webPIsOn = 7; // 是否定义了WebP策略
bool uamIsOn = 10; // 是否定义了UAM策略
bool httpCCIsOn = 12; // 是否定义了CC策略
bool hasSystemServices = 8; // 启用了系统服务
@@ -510,7 +510,7 @@ message FindEnabledNodeClusterWebPPolicyResponse {
// 设置集群WebP策略
message UpdateNodeClusterWebPPolicyRequest {
int64 nodeClusterId = 1;
bytes webpPolicyJSON = 2;
bytes webPPolicyJSON = 2;
}
// 读取集群的UAM策略