mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-10 12:10:26 +08:00
实现基础的智能调度
This commit is contained in:
@@ -472,13 +472,14 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
||||
var nodeKeys = []string{}
|
||||
var addingNodeRecordKeysMap = map[string]bool{} // clusterDnsName_type_ip_route
|
||||
for _, node := range nodes {
|
||||
ipAddresses, err := models.SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||
shouldSkip, shouldOverwrite, ipAddressesStrings, err := models.SharedNodeDAO.CheckNodeIPAddresses(tx, node)
|
||||
if err != nil {
|
||||
return nil, nil, nil, 0, 0, false, false, err
|
||||
}
|
||||
if len(ipAddresses) == 0 {
|
||||
if shouldSkip {
|
||||
continue
|
||||
}
|
||||
|
||||
routeCodes, err := node.DNSRouteCodesForDomainId(int64(cluster.DnsDomainId))
|
||||
if err != nil {
|
||||
return nil, nil, nil, 0, 0, false, false, err
|
||||
@@ -491,7 +492,16 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
||||
continue
|
||||
}
|
||||
}
|
||||
for _, route := range routeCodes {
|
||||
|
||||
if !shouldOverwrite {
|
||||
ipAddresses, err := models.SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||
if err != nil {
|
||||
return nil, nil, nil, 0, 0, false, false, err
|
||||
}
|
||||
if len(ipAddresses) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, ipAddress := range ipAddresses {
|
||||
// 检查专属节点
|
||||
if !ipAddress.IsValidInCluster(clusterId) {
|
||||
@@ -505,6 +515,16 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
||||
if net.ParseIP(ip) == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ipAddressesStrings = append(ipAddressesStrings, ip)
|
||||
}
|
||||
}
|
||||
if len(ipAddressesStrings) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, route := range routeCodes {
|
||||
for _, ip := range ipAddressesStrings {
|
||||
var key = ip + "_" + route
|
||||
nodeKeys = append(nodeKeys, key)
|
||||
record, ok := nodeRecordMapping[key]
|
||||
|
||||
@@ -62,7 +62,7 @@ func (this *DNSTaskService) FindAllDoingDNSTasks(ctx context.Context, req *pb.Fi
|
||||
}
|
||||
|
||||
switch task.Type {
|
||||
case dns.DNSTaskTypeClusterChange, dns.DNSTaskTypeClusterRemoveDomain:
|
||||
case dns.DNSTaskTypeClusterChange, dns.DNSTaskTypeClusterNodesChange, dns.DNSTaskTypeClusterRemoveDomain:
|
||||
clusterName, err := models.SharedNodeClusterDAO.FindNodeClusterName(tx, int64(task.ClusterId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -384,6 +384,9 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
NodeRegion: pbRegion,
|
||||
DnsRoutes: pbRoutes,
|
||||
Level: int32(node.Level),
|
||||
OfflineDay: node.OfflineDay,
|
||||
IsBackupForCluster: node.IsBackupForCluster,
|
||||
IsBackupForGroup: node.IsBackupForGroup,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -683,6 +686,9 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
||||
DnsRoutes: pbRoutes,
|
||||
EnableIPLists: node.EnableIPLists,
|
||||
ApiNodeAddrsJSON: node.ApiNodeAddrs,
|
||||
OfflineDay: node.OfflineDay,
|
||||
IsBackupForCluster: node.IsBackupForCluster,
|
||||
IsBackupForGroup: node.IsBackupForGroup,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
@@ -1397,12 +1403,15 @@ func (this *NodeService) FindAllEnabledNodesDNSWithNodeClusterId(ctx context.Con
|
||||
continue
|
||||
}
|
||||
result = append(result, &pb.NodeDNSInfo{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
IpAddr: ip,
|
||||
NodeIPAddressId: int64(ipAddress.Id),
|
||||
Routes: pbRoutes,
|
||||
NodeClusterId: req.NodeClusterId,
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
IpAddr: ip,
|
||||
NodeIPAddressId: int64(ipAddress.Id),
|
||||
Routes: pbRoutes,
|
||||
NodeClusterId: req.NodeClusterId,
|
||||
IsBackupForCluster: node.IsBackupForCluster,
|
||||
IsBackupForGroup: node.IsBackupForGroup,
|
||||
IsOffline: node.CheckIsOffline(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1497,6 +1506,9 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
||||
NodeClusterDNSName: clusterDNS.DnsName,
|
||||
DnsDomainId: dnsDomainId,
|
||||
DnsDomainName: dnsDomainName,
|
||||
IsBackupForCluster: node.IsBackupForCluster,
|
||||
IsBackupForGroup: node.IsBackupForGroup,
|
||||
IsOffline: node.CheckIsOffline(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -2097,6 +2109,9 @@ func (this *NodeService) FindEnabledNodeConfigInfo(ctx context.Context, req *pb.
|
||||
// ddos protection
|
||||
result.HasDDoSProtection = node.HasDDoSProtection()
|
||||
|
||||
// schedule
|
||||
result.HasScheduleSettings = node.HasScheduleSettings()
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
21
internal/rpc/services/service_node_ext.go
Normal file
21
internal/rpc/services/service_node_ext.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build !plus
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
func (this *NodeService) FindNodeScheduleInfo(ctx context.Context, req *pb.FindNodeScheduleInfoRequest) (*pb.FindNodeScheduleInfoResponse, error) {
|
||||
return nil, this.NotImplementedYet()
|
||||
}
|
||||
|
||||
func (this *NodeService) UpdateNodeScheduleInfo(ctx context.Context, req *pb.UpdateNodeScheduleInfoRequest) (*pb.RPCSuccess, error) {
|
||||
return nil, this.NotImplementedYet()
|
||||
}
|
||||
|
||||
func (this *NodeService) ResetNodeActionStatus(ctx context.Context, req *pb.ResetNodeActionStatusRequest) (*pb.RPCSuccess, error) {
|
||||
return nil, this.NotImplementedYet()
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (this *ServerDailyStatService) UploadServerDailyStats(ctx context.Context,
|
||||
|
||||
// 节点流量
|
||||
if nodeId > 0 {
|
||||
err = stats.SharedNodeTrafficDailyStatDAO.IncreaseDailyStat(tx, clusterId, role, nodeId, timeutil.FormatTime("Ymd", stat.CreatedAt), stat.Bytes, stat.CachedBytes, stat.CountRequests, stat.CountCachedRequests, stat.CountAttackRequests, stat.AttackBytes)
|
||||
err = models.SharedNodeTrafficDailyStatDAO.IncreaseDailyStat(tx, clusterId, role, nodeId, timeutil.FormatTime("Ymd", stat.CreatedAt), stat.Bytes, stat.CachedBytes, stat.CountRequests, stat.CountCachedRequests, stat.CountAttackRequests, stat.AttackBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
||||
}
|
||||
|
||||
// 当月总流量
|
||||
monthlyTrafficStat, err := stats.SharedNodeTrafficDailyStatDAO.SumDailyStat(tx, nodeconfigs.NodeRoleNode, req.NodeId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
||||
monthlyTrafficStat, err := models.SharedNodeTrafficDailyStatDAO.SumDailyStat(tx, nodeconfigs.NodeRoleNode, req.NodeId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -335,7 +335,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
||||
|
||||
// 按日流量统计
|
||||
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
||||
dailyTrafficStats, err := stats.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
||||
dailyTrafficStats, err := models.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user