mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-05 01:20:25 +08:00
修复域名服务集群检测新版本节点的Bug
This commit is contained in:
@@ -26,11 +26,11 @@ func NewDeployManager() *DeployManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载所有文件
|
// LoadNodeFiles 加载所有边缘节点文件
|
||||||
func (this *DeployManager) LoadFiles() []*DeployFile {
|
func (this *DeployManager) LoadNodeFiles() []*DeployFile {
|
||||||
keyMap := map[string]*DeployFile{} // key => File
|
keyMap := map[string]*DeployFile{} // key => File
|
||||||
|
|
||||||
reg := regexp.MustCompile(`(\w+)-(\w+)-v([0-9.]+)\.zip`)
|
reg := regexp.MustCompile(`^edge-node-(\w+)-(\w+)-v([0-9.]+)\.zip$`)
|
||||||
for _, file := range files.NewFile(this.dir).List() {
|
for _, file := range files.NewFile(this.dir).List() {
|
||||||
name := file.Name()
|
name := file.Name()
|
||||||
if !reg.MatchString(name) {
|
if !reg.MatchString(name) {
|
||||||
@@ -60,3 +60,40 @@ func (this *DeployManager) LoadFiles() []*DeployFile {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// LoadNSNodeFiles 加载所有文件
|
||||||
|
func (this *DeployManager) LoadNSNodeFiles() []*DeployFile {
|
||||||
|
keyMap := map[string]*DeployFile{} // key => File
|
||||||
|
|
||||||
|
reg := regexp.MustCompile(`^edge-dns-(\w+)-(\w+)-v([0-9.]+)\.zip$`)
|
||||||
|
for _, file := range files.NewFile(this.dir).List() {
|
||||||
|
name := file.Name()
|
||||||
|
if !reg.MatchString(name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
matches := reg.FindStringSubmatch(name)
|
||||||
|
osName := matches[1]
|
||||||
|
arch := matches[2]
|
||||||
|
version := matches[3]
|
||||||
|
|
||||||
|
key := osName + "_" + arch
|
||||||
|
oldFile, ok := keyMap[key]
|
||||||
|
if ok && stringutil.VersionCompare(oldFile.Version, version) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
keyMap[key] = &DeployFile{
|
||||||
|
OS: osName,
|
||||||
|
Arch: arch,
|
||||||
|
Version: version,
|
||||||
|
Path: file.Path(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result := []*DeployFile{}
|
||||||
|
for _, v := range keyMap {
|
||||||
|
result = append(result, v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -2,8 +2,16 @@ package installers
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestDeployManager_LoadFiles(t *testing.T) {
|
func TestDeployManager_LoadNodeFiles(t *testing.T) {
|
||||||
files := NewDeployManager().LoadFiles()
|
files := NewDeployManager().LoadNodeFiles()
|
||||||
|
for _, file := range files {
|
||||||
|
t.Logf("%#v", file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestDeployManager_LoadNSNodeFiles(t *testing.T) {
|
||||||
|
files := NewDeployManager().LoadNSNodeFiles()
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
t.Logf("%#v", file)
|
t.Logf("%#v", file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func TestQueue_InstallNode(t *testing.T) {
|
func TestQueue_InstallNode(t *testing.T) {
|
||||||
queue := NewQueue()
|
queue := NewQueue()
|
||||||
err := queue.InstallNodeProcess(16)
|
err := queue.InstallNodeProcess(16, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NSNodeService 域名服务器节点服务
|
// NSNodeService 域名服务器节点服务
|
||||||
@@ -135,7 +136,7 @@ func (this *NSNodeService) CountAllUpgradeNSNodesWithNSClusterId(ctx context.Con
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
deployFiles := installers.SharedDeployManager.LoadFiles()
|
deployFiles := installers.SharedDeployManager.LoadNSNodeFiles()
|
||||||
total := int64(0)
|
total := int64(0)
|
||||||
for _, deployFile := range deployFiles {
|
for _, deployFile := range deployFiles {
|
||||||
count, err := nameservers.SharedNSNodeDAO.CountAllLowerVersionNodesWithClusterId(tx, req.NsClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
count, err := nameservers.SharedNSNodeDAO.CountAllLowerVersionNodesWithClusterId(tx, req.NsClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
||||||
@@ -365,3 +366,22 @@ func (this *NSNodeService) FindCurrentNSNodeConfig(ctx context.Context, req *pb.
|
|||||||
}
|
}
|
||||||
return &pb.FindCurrentNSNodeConfigResponse{NsNodeJSON: configJSON}, nil
|
return &pb.FindCurrentNSNodeConfigResponse{NsNodeJSON: configJSON}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckNSNodeLatestVersion 检查新版本
|
||||||
|
func (this *NSNodeService) CheckNSNodeLatestVersion(ctx context.Context, req *pb.CheckNSNodeLatestVersionRequest) (*pb.CheckNSNodeLatestVersionResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
deployFiles := installers.SharedDeployManager.LoadNSNodeFiles()
|
||||||
|
for _, file := range deployFiles {
|
||||||
|
if file.OS == req.Os && file.Arch == req.Arch && stringutil.VersionCompare(file.Version, req.CurrentVersion) > 0 {
|
||||||
|
return &pb.CheckNSNodeLatestVersionResponse{
|
||||||
|
HasNewVersion: true,
|
||||||
|
NewVersion: file.Version,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &pb.CheckNSNodeLatestVersionResponse{HasNewVersion: false}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -885,7 +885,7 @@ func (this *NodeService) CountAllUpgradeNodesWithNodeClusterId(ctx context.Conte
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
deployFiles := installers.SharedDeployManager.LoadFiles()
|
deployFiles := installers.SharedDeployManager.LoadNodeFiles()
|
||||||
total := int64(0)
|
total := int64(0)
|
||||||
for _, deployFile := range deployFiles {
|
for _, deployFile := range deployFiles {
|
||||||
count, err := models.SharedNodeDAO.CountAllLowerVersionNodesWithClusterId(tx, req.NodeClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
count, err := models.SharedNodeDAO.CountAllLowerVersionNodesWithClusterId(tx, req.NodeClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
||||||
@@ -909,7 +909,7 @@ func (this *NodeService) FindAllUpgradeNodesWithNodeClusterId(ctx context.Contex
|
|||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
// 获取当前能升级到的最新版本
|
// 获取当前能升级到的最新版本
|
||||||
deployFiles := installers.SharedDeployManager.LoadFiles()
|
deployFiles := installers.SharedDeployManager.LoadNodeFiles()
|
||||||
result := []*pb.FindAllUpgradeNodesWithNodeClusterIdResponse_NodeUpgrade{}
|
result := []*pb.FindAllUpgradeNodesWithNodeClusterIdResponse_NodeUpgrade{}
|
||||||
for _, deployFile := range deployFiles {
|
for _, deployFile := range deployFiles {
|
||||||
nodes, err := models.SharedNodeDAO.FindAllLowerVersionNodesWithClusterId(tx, req.NodeClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
nodes, err := models.SharedNodeDAO.FindAllLowerVersionNodesWithClusterId(tx, req.NodeClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
||||||
@@ -1322,7 +1322,7 @@ func (this *NodeService) CheckNodeLatestVersion(ctx context.Context, req *pb.Che
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deployFiles := installers.SharedDeployManager.LoadFiles()
|
deployFiles := installers.SharedDeployManager.LoadNodeFiles()
|
||||||
for _, file := range deployFiles {
|
for _, file := range deployFiles {
|
||||||
if file.OS == req.Os && file.Arch == req.Arch && stringutil.VersionCompare(file.Version, req.CurrentVersion) > 0 {
|
if file.OS == req.Os && file.Arch == req.Arch && stringutil.VersionCompare(file.Version, req.CurrentVersion) > 0 {
|
||||||
return &pb.CheckNodeLatestVersionResponse{
|
return &pb.CheckNodeLatestVersionResponse{
|
||||||
|
|||||||
Reference in New Issue
Block a user