mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	节点增加DNS解析库类型设置
This commit is contained in:
		@@ -26,5 +26,5 @@ const (
 | 
				
			|||||||
	ReportNodeVersion    = "0.1.0"
 | 
						ReportNodeVersion    = "0.1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// SQLVersion SQL版本号
 | 
						// SQLVersion SQL版本号
 | 
				
			||||||
	SQLVersion = "8"
 | 
						SQLVersion = "9"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1070,6 +1070,16 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
 | 
				
			|||||||
		config.SystemServices = services
 | 
							config.SystemServices = services
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// DNS Resolver
 | 
				
			||||||
 | 
						if IsNotNull(node.DnsResolver) {
 | 
				
			||||||
 | 
							var dnsResolverConfig = nodeconfigs.DefaultDNSResolverConfig()
 | 
				
			||||||
 | 
							err = json.Unmarshal(node.DnsResolver, dnsResolverConfig)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							config.DNSResolver = dnsResolverConfig
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 防火墙动作
 | 
						// 防火墙动作
 | 
				
			||||||
	actions, err := SharedNodeClusterFirewallActionDAO.FindAllEnabledFirewallActions(tx, primaryClusterId, cacheMap)
 | 
						actions, err := SharedNodeClusterFirewallActionDAO.FindAllEnabledFirewallActions(tx, primaryClusterId, cacheMap)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -1400,6 +1410,49 @@ func (this *NodeDAO) UpdateNodeDNS(tx *dbs.Tx, nodeId int64, routes map[int64][]
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FindNodeDNSResolver 查找域名DNS Resolver
 | 
				
			||||||
 | 
					func (this *NodeDAO) FindNodeDNSResolver(tx *dbs.Tx, nodeId int64) (*nodeconfigs.DNSResolverConfig, error) {
 | 
				
			||||||
 | 
						configJSON, err := this.Query(tx).
 | 
				
			||||||
 | 
							Pk(nodeId).
 | 
				
			||||||
 | 
							Result("dnsResolver").
 | 
				
			||||||
 | 
							FindJSONCol()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if IsNull(configJSON) {
 | 
				
			||||||
 | 
							return nodeconfigs.DefaultDNSResolverConfig(), nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var config = nodeconfigs.DefaultDNSResolverConfig()
 | 
				
			||||||
 | 
						err = json.Unmarshal(configJSON, config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return config, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateNodeDNSResolver 修改域名DNS Resolver
 | 
				
			||||||
 | 
					func (this *NodeDAO) UpdateNodeDNSResolver(tx *dbs.Tx, nodeId int64, dnsResolverConfig *nodeconfigs.DNSResolverConfig) error {
 | 
				
			||||||
 | 
						if nodeId <= 0 {
 | 
				
			||||||
 | 
							return ErrNotFound
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						configJSON, err := json.Marshal(dnsResolverConfig)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var op = NewNodeOperator()
 | 
				
			||||||
 | 
						op.Id = nodeId
 | 
				
			||||||
 | 
						op.DnsResolver = configJSON
 | 
				
			||||||
 | 
						err = this.Save(tx, op)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return this.NotifyUpdate(tx, nodeId)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateNodeSystem 设置系统信息
 | 
					// UpdateNodeSystem 设置系统信息
 | 
				
			||||||
func (this *NodeDAO) UpdateNodeSystem(tx *dbs.Tx, nodeId int64, maxCPU int32) error {
 | 
					func (this *NodeDAO) UpdateNodeSystem(tx *dbs.Tx, nodeId int64, maxCPU int32) error {
 | 
				
			||||||
	if nodeId <= 0 {
 | 
						if nodeId <= 0 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,7 @@ type Node struct {
 | 
				
			|||||||
	MaxCacheDiskCapacity   dbs.JSON `field:"maxCacheDiskCapacity"`   // 硬盘缓存容量
 | 
						MaxCacheDiskCapacity   dbs.JSON `field:"maxCacheDiskCapacity"`   // 硬盘缓存容量
 | 
				
			||||||
	MaxCacheMemoryCapacity dbs.JSON `field:"maxCacheMemoryCapacity"` // 内存缓存容量
 | 
						MaxCacheMemoryCapacity dbs.JSON `field:"maxCacheMemoryCapacity"` // 内存缓存容量
 | 
				
			||||||
	CacheDiskDir           string   `field:"cacheDiskDir"`           // 缓存目录
 | 
						CacheDiskDir           string   `field:"cacheDiskDir"`           // 缓存目录
 | 
				
			||||||
 | 
						DnsResolver            dbs.JSON `field:"dnsResolver"`            // DNS解析器
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NodeOperator struct {
 | 
					type NodeOperator struct {
 | 
				
			||||||
@@ -69,6 +70,7 @@ type NodeOperator struct {
 | 
				
			|||||||
	MaxCacheDiskCapacity   interface{} // 硬盘缓存容量
 | 
						MaxCacheDiskCapacity   interface{} // 硬盘缓存容量
 | 
				
			||||||
	MaxCacheMemoryCapacity interface{} // 内存缓存容量
 | 
						MaxCacheMemoryCapacity interface{} // 内存缓存容量
 | 
				
			||||||
	CacheDiskDir           interface{} // 缓存目录
 | 
						CacheDiskDir           interface{} // 缓存目录
 | 
				
			||||||
 | 
						DnsResolver            interface{} // DNS解析器
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewNodeOperator() *NodeOperator {
 | 
					func NewNodeOperator() *NodeOperator {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1746,3 +1746,46 @@ func (this *NodeService) FindNodeLevelInfo(ctx context.Context, req *pb.FindNode
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FindNodeDNSResolver 读取节点DNS Resolver
 | 
				
			||||||
 | 
					func (this *NodeService) FindNodeDNSResolver(ctx context.Context, req *pb.FindNodeDNSResolverRequest) (*pb.FindNodeDNSResolverResponse, error) {
 | 
				
			||||||
 | 
						_, err := this.ValidateAdmin(ctx, 0)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
						config, err := models.SharedNodeDAO.FindNodeDNSResolver(tx, req.NodeId)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						configJSON, err := json.Marshal(config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &pb.FindNodeDNSResolverResponse{
 | 
				
			||||||
 | 
							DnsResolverJSON: configJSON,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateNodeDNSResolver 修改DNS Resolver
 | 
				
			||||||
 | 
					func (this *NodeService) UpdateNodeDNSResolver(ctx context.Context, req *pb.UpdateNodeDNSResolverRequest) (*pb.RPCSuccess, error) {
 | 
				
			||||||
 | 
						_, err := this.ValidateAdmin(ctx, 0)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
						var config = nodeconfigs.DefaultDNSResolverConfig()
 | 
				
			||||||
 | 
						err = json.Unmarshal(req.DnsResolverJSON, config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = models.SharedNodeDAO.UpdateNodeDNSResolver(tx, req.NodeId, config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return this.Success()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user