mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	优化代码
This commit is contained in:
		@@ -2257,119 +2257,3 @@ func (this *NodeService) UpdateNodeAPIConfig(ctx context.Context, req *pb.Update
 | 
			
		||||
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindNodeUAMPolicies 查找节点的UAM策略
 | 
			
		||||
func (this *NodeService) FindNodeUAMPolicies(ctx context.Context, req *pb.FindNodeUAMPoliciesRequest) (*pb.FindNodeUAMPoliciesResponse, error) {
 | 
			
		||||
	nodeId, err := this.ValidateNode(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	clusterIds, err := models.SharedNodeDAO.FindEnabledAndOnNodeClusterIds(tx, nodeId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var pbPolicies = []*pb.FindNodeUAMPoliciesResponse_UAMPolicy{}
 | 
			
		||||
	for _, clusterId := range clusterIds {
 | 
			
		||||
		policy, err := models.SharedNodeClusterDAO.FindClusterUAMPolicy(tx, clusterId, nil)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		if policy == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		policyJSON, err := json.Marshal(policy)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		pbPolicies = append(pbPolicies, &pb.FindNodeUAMPoliciesResponse_UAMPolicy{
 | 
			
		||||
			NodeClusterId: clusterId,
 | 
			
		||||
			UamPolicyJSON: policyJSON,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.FindNodeUAMPoliciesResponse{
 | 
			
		||||
		UamPolicies: pbPolicies,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindNodeHTTPCCPolicies 查找节点的HTTP CC策略
 | 
			
		||||
func (this *NodeService) FindNodeHTTPCCPolicies(ctx context.Context, req *pb.FindNodeHTTPCCPoliciesRequest) (*pb.FindNodeHTTPCCPoliciesResponse, error) {
 | 
			
		||||
	nodeId, err := this.ValidateNode(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	clusterIds, err := models.SharedNodeDAO.FindEnabledAndOnNodeClusterIds(tx, nodeId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var pbPolicies = []*pb.FindNodeHTTPCCPoliciesResponse_HTTPCCPolicy{}
 | 
			
		||||
	for _, clusterId := range clusterIds {
 | 
			
		||||
		policy, err := models.SharedNodeClusterDAO.FindClusterHTTPCCPolicy(tx, clusterId, nil)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		if policy == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 集成默认设置
 | 
			
		||||
		for i := 0; i < len(serverconfigs.DefaultHTTPCCThresholds); i ++ {
 | 
			
		||||
			if i < len(policy.Thresholds) {
 | 
			
		||||
				policy.Thresholds[i].MergeIfEmpty(serverconfigs.DefaultHTTPCCThresholds[i])
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		policyJSON, err := json.Marshal(policy)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		pbPolicies = append(pbPolicies, &pb.FindNodeHTTPCCPoliciesResponse_HTTPCCPolicy{
 | 
			
		||||
			NodeClusterId:    clusterId,
 | 
			
		||||
			HttpCCPolicyJSON: policyJSON,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.FindNodeHTTPCCPoliciesResponse{
 | 
			
		||||
		HttpCCPolicies: pbPolicies,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindNodeHTTPPagesPolicies 查找节点的自定义页面策略
 | 
			
		||||
func (this *NodeService) FindNodeHTTPPagesPolicies(ctx context.Context, req *pb.FindNodeHTTPPagesPoliciesRequest) (*pb.FindNodeHTTPPagesPoliciesResponse, error) {
 | 
			
		||||
	nodeId, err := this.ValidateNode(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	clusterIds, err := models.SharedNodeDAO.FindEnabledAndOnNodeClusterIds(tx, nodeId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var pbPolicies = []*pb.FindNodeHTTPPagesPoliciesResponse_HTTPPagesPolicy{}
 | 
			
		||||
	for _, clusterId := range clusterIds {
 | 
			
		||||
		policy, err := models.SharedNodeClusterDAO.FindClusterHTTPPagesPolicy(tx, clusterId, nil)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		if policy == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		policyJSON, err := json.Marshal(policy)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		pbPolicies = append(pbPolicies, &pb.FindNodeHTTPPagesPoliciesResponse_HTTPPagesPolicy{
 | 
			
		||||
			NodeClusterId:       clusterId,
 | 
			
		||||
			HttpPagesPolicyJSON: policyJSON,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.FindNodeHTTPPagesPoliciesResponse{
 | 
			
		||||
		HttpPagesPolicies: pbPolicies,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,18 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (this *NodeService) FindNodeUAMPolicies(ctx context.Context, req *pb.FindNodeUAMPoliciesRequest) (*pb.FindNodeUAMPoliciesResponse, error) {
 | 
			
		||||
	return nil, this.NotImplementedYet()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *NodeService) FindNodeHTTPCCPolicies(ctx context.Context, req *pb.FindNodeHTTPCCPoliciesRequest) (*pb.FindNodeHTTPCCPoliciesResponse, error) {
 | 
			
		||||
	return nil, this.NotImplementedYet()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *NodeService) FindNodeHTTPPagesPolicies(ctx context.Context, req *pb.FindNodeHTTPPagesPoliciesRequest) (*pb.FindNodeHTTPPagesPoliciesResponse, error) {
 | 
			
		||||
	return nil, this.NotImplementedYet()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *NodeService) FindNodeScheduleInfo(ctx context.Context, req *pb.FindNodeScheduleInfoRequest) (*pb.FindNodeScheduleInfoResponse, error) {
 | 
			
		||||
	return nil, this.NotImplementedYet()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user