mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 01:50:25 +08:00
Ln节点可以指定访问IP
This commit is contained in:
@@ -199,7 +199,7 @@ func (this *NodeDAO) CreateNode(tx *dbs.Tx, adminId int64, name string, clusterI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateNode 修改节点
|
// UpdateNode 修改节点
|
||||||
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, secondaryClusterIds []int64, groupId int64, regionId int64, isOn bool, level int) error {
|
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, secondaryClusterIds []int64, groupId int64, regionId int64, isOn bool, level int, lnAddrs []string) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
}
|
}
|
||||||
@@ -248,6 +248,15 @@ func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId
|
|||||||
|
|
||||||
if teaconst.IsPlus {
|
if teaconst.IsPlus {
|
||||||
op.Level = level
|
op.Level = level
|
||||||
|
|
||||||
|
if lnAddrs == nil {
|
||||||
|
lnAddrs = []string{}
|
||||||
|
}
|
||||||
|
lnAddrsJSON, err := json.Marshal(lnAddrs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
op.LnAddrs = lnAddrsJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
err = this.Save(tx, op)
|
err = this.Save(tx, op)
|
||||||
@@ -605,7 +614,7 @@ func (this *NodeDAO) FindEnabledNodesWithGroupIdAndLevel(tx *dbs.Tx, groupId int
|
|||||||
}
|
}
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
Result("id", "clusterId", "secondaryClusterIds", "uniqueId", "secret").
|
Result("id", "clusterId", "secondaryClusterIds", "uniqueId", "secret", "lnAddrs").
|
||||||
Attr("isOn", true).
|
Attr("isOn", true).
|
||||||
Attr("groupId", groupId).
|
Attr("groupId", groupId).
|
||||||
Attr("level", level).
|
Attr("level", level).
|
||||||
@@ -1881,16 +1890,20 @@ func (this *NodeDAO) FindParentNodeConfigs(tx *dbs.Tx, nodeId int64, groupId int
|
|||||||
|
|
||||||
if len(parentNodes) > 0 {
|
if len(parentNodes) > 0 {
|
||||||
for _, node := range parentNodes {
|
for _, node := range parentNodes {
|
||||||
|
// 是否有Ln地址
|
||||||
|
var addrStrings = node.DecodeLnAddrs()
|
||||||
|
if len(addrStrings) == 0 {
|
||||||
|
// 如果没有就取节点的可访问地址
|
||||||
addrs, err := SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
addrs, err := SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var addrStrings = []string{}
|
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if addr.IsOn {
|
if addr.IsOn {
|
||||||
addrStrings = append(addrStrings, addr.DNSIP())
|
addrStrings = append(addrStrings, addr.DNSIP())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 没有地址就跳过
|
// 没有地址就跳过
|
||||||
if len(addrStrings) == 0 {
|
if len(addrStrings) == 0 {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ type Node struct {
|
|||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
Level uint8 `field:"level"` // 级别
|
Level uint8 `field:"level"` // 级别
|
||||||
|
LnAddrs dbs.JSON `field:"lnAddrs"` // Ln级别访问地址
|
||||||
IsOn bool `field:"isOn"` // 是否启用
|
IsOn bool `field:"isOn"` // 是否启用
|
||||||
IsUp bool `field:"isUp"` // 是否在线
|
IsUp bool `field:"isUp"` // 是否在线
|
||||||
CountUp uint32 `field:"countUp"` // 连续在线次数
|
CountUp uint32 `field:"countUp"` // 连续在线次数
|
||||||
@@ -42,41 +43,42 @@ type Node struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NodeOperator struct {
|
type NodeOperator struct {
|
||||||
Id interface{} // ID
|
Id any // ID
|
||||||
AdminId interface{} // 管理员ID
|
AdminId any // 管理员ID
|
||||||
UserId interface{} // 用户ID
|
UserId any // 用户ID
|
||||||
Level interface{} // 级别
|
Level any // 级别
|
||||||
IsOn interface{} // 是否启用
|
LnAddrs any // Ln级别访问地址
|
||||||
IsUp interface{} // 是否在线
|
IsOn any // 是否启用
|
||||||
CountUp interface{} // 连续在线次数
|
IsUp any // 是否在线
|
||||||
CountDown interface{} // 连续下线次数
|
CountUp any // 连续在线次数
|
||||||
IsActive interface{} // 是否活跃
|
CountDown any // 连续下线次数
|
||||||
InactiveNotifiedAt interface{} // 离线通知时间
|
IsActive any // 是否活跃
|
||||||
UniqueId interface{} // 节点ID
|
InactiveNotifiedAt any // 离线通知时间
|
||||||
Secret interface{} // 密钥
|
UniqueId any // 节点ID
|
||||||
Name interface{} // 节点名
|
Secret any // 密钥
|
||||||
Code interface{} // 代号
|
Name any // 节点名
|
||||||
ClusterId interface{} // 主集群ID
|
Code any // 代号
|
||||||
SecondaryClusterIds interface{} // 从集群ID
|
ClusterId any // 主集群ID
|
||||||
RegionId interface{} // 区域ID
|
SecondaryClusterIds any // 从集群ID
|
||||||
GroupId interface{} // 分组ID
|
RegionId any // 区域ID
|
||||||
CreatedAt interface{} // 创建时间
|
GroupId any // 分组ID
|
||||||
Status interface{} // 最新的状态
|
CreatedAt any // 创建时间
|
||||||
Version interface{} // 当前版本号
|
Status any // 最新的状态
|
||||||
LatestVersion interface{} // 最后版本号
|
Version any // 当前版本号
|
||||||
InstallDir interface{} // 安装目录
|
LatestVersion any // 最后版本号
|
||||||
IsInstalled interface{} // 是否已安装
|
InstallDir any // 安装目录
|
||||||
InstallStatus interface{} // 安装状态
|
IsInstalled any // 是否已安装
|
||||||
State interface{} // 状态
|
InstallStatus any // 安装状态
|
||||||
ConnectedAPINodes interface{} // 当前连接的API节点
|
State any // 状态
|
||||||
MaxCPU interface{} // 可以使用的最多CPU
|
ConnectedAPINodes any // 当前连接的API节点
|
||||||
MaxThreads interface{} // 最大线程数
|
MaxCPU any // 可以使用的最多CPU
|
||||||
DdosProtection interface{} // DDOS配置
|
MaxThreads any // 最大线程数
|
||||||
DnsRoutes interface{} // DNS线路设置
|
DdosProtection any // DDOS配置
|
||||||
MaxCacheDiskCapacity interface{} // 硬盘缓存容量
|
DnsRoutes any // DNS线路设置
|
||||||
MaxCacheMemoryCapacity interface{} // 内存缓存容量
|
MaxCacheDiskCapacity any // 硬盘缓存容量
|
||||||
CacheDiskDir interface{} // 缓存目录
|
MaxCacheMemoryCapacity any // 内存缓存容量
|
||||||
DnsResolver interface{} // DNS解析器
|
CacheDiskDir any // 缓存目录
|
||||||
|
DnsResolver any // DNS解析器
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeOperator() *NodeOperator {
|
func NewNodeOperator() *NodeOperator {
|
||||||
|
|||||||
@@ -168,3 +168,16 @@ func (this *Node) DecodeDNSResolver() *nodeconfigs.DNSResolverConfig {
|
|||||||
}
|
}
|
||||||
return resolverConfig
|
return resolverConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Node) DecodeLnAddrs() []string {
|
||||||
|
if IsNull(this.LnAddrs) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = []string{}
|
||||||
|
err := json.Unmarshal(this.LnAddrs, &result)
|
||||||
|
if err != nil {
|
||||||
|
// ignore error
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeReque
|
|||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
|
|
||||||
err = models.SharedNodeDAO.UpdateNode(tx, req.NodeId, req.Name, req.NodeClusterId, req.SecondaryNodeClusterIds, req.NodeGroupId, req.NodeRegionId, req.IsOn, int(req.Level))
|
err = models.SharedNodeDAO.UpdateNode(tx, req.NodeId, req.Name, req.NodeClusterId, req.SecondaryNodeClusterIds, req.NodeGroupId, req.NodeRegionId, req.IsOn, int(req.Level), req.LnAddrs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -673,6 +673,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
|||||||
MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity,
|
MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity,
|
||||||
CacheDiskDir: node.CacheDiskDir,
|
CacheDiskDir: node.CacheDiskDir,
|
||||||
Level: int32(node.Level),
|
Level: int32(node.Level),
|
||||||
|
LnAddrs: node.DecodeLnAddrs(),
|
||||||
DnsRoutes: pbRoutes,
|
DnsRoutes: pbRoutes,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user