feat: sync httpdns sdk/platform updates without large binaries
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/setup"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
@@ -484,6 +485,12 @@ func (this *NSNodeService) DownloadNSNodeInstallationFile(ctx context.Context, r
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 检查自动升级开关
|
||||
upgradeConfig, _ := setup.LoadUpgradeConfig()
|
||||
if upgradeConfig != nil && !upgradeConfig.AutoUpgrade {
|
||||
return &pb.DownloadNSNodeInstallationFileResponse{}, nil
|
||||
}
|
||||
|
||||
var file = installers.SharedDeployManager.FindNSNodeFile(req.Os, req.Arch)
|
||||
if file == nil {
|
||||
return &pb.DownloadNSNodeInstallationFileResponse{}, nil
|
||||
@@ -738,3 +745,109 @@ func (this *NSNodeService) UpdateNSNodeAPIConfig(ctx context.Context, req *pb.Up
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindAllUpgradeNSNodesWithNSClusterId 列出所有需要升级的NS节点
|
||||
func (this *NSNodeService) FindAllUpgradeNSNodesWithNSClusterId(ctx context.Context, req *pb.FindAllUpgradeNSNodesWithNSClusterIdRequest) (*pb.FindAllUpgradeNSNodesWithNSClusterIdResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
deployFiles := installers.SharedDeployManager.LoadNSNodeFiles()
|
||||
var result []*pb.FindAllUpgradeNSNodesWithNSClusterIdResponse_NSNodeUpgrade
|
||||
for _, deployFile := range deployFiles {
|
||||
nodes, err := models.SharedNSNodeDAO.FindAllLowerVersionNodesWithClusterId(tx, req.NsClusterId, deployFile.OS, deployFile.Arch, deployFile.Version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, node := range nodes {
|
||||
// 解析状态获取当前版本
|
||||
var oldVersion string
|
||||
if len(node.Status) > 0 {
|
||||
var statusMap map[string]interface{}
|
||||
if json.Unmarshal(node.Status, &statusMap) == nil {
|
||||
if v, ok := statusMap["buildVersion"]; ok {
|
||||
oldVersion, _ = v.(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 安装信息
|
||||
installStatus, installErr := node.DecodeInstallStatus()
|
||||
if installErr != nil {
|
||||
return nil, installErr
|
||||
}
|
||||
pbInstallStatus := &pb.NodeInstallStatus{}
|
||||
if installStatus != nil {
|
||||
pbInstallStatus = &pb.NodeInstallStatus{
|
||||
IsRunning: installStatus.IsRunning,
|
||||
IsFinished: installStatus.IsFinished,
|
||||
IsOk: installStatus.IsOk,
|
||||
Error: installStatus.Error,
|
||||
ErrorCode: installStatus.ErrorCode,
|
||||
UpdatedAt: installStatus.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// 认证信息
|
||||
login, loginErr := models.SharedNodeLoginDAO.FindEnabledNodeLoginWithNodeId(tx, nodeconfigs.NodeRoleDNS, int64(node.Id))
|
||||
if loginErr != nil {
|
||||
return nil, loginErr
|
||||
}
|
||||
var pbLogin *pb.NodeLogin
|
||||
if login != nil {
|
||||
pbLogin = &pb.NodeLogin{
|
||||
Id: int64(login.Id),
|
||||
Name: login.Name,
|
||||
Type: login.Type,
|
||||
Params: login.Params,
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, &pb.FindAllUpgradeNSNodesWithNSClusterIdResponse_NSNodeUpgrade{
|
||||
NsNode: &pb.NSNode{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
IsOn: node.IsOn,
|
||||
UniqueId: node.UniqueId,
|
||||
IsInstalled: node.IsInstalled,
|
||||
IsUp: node.IsUp,
|
||||
IsActive: node.IsActive,
|
||||
StatusJSON: node.Status,
|
||||
InstallStatus: pbInstallStatus,
|
||||
NodeLogin: pbLogin,
|
||||
},
|
||||
Os: deployFile.OS,
|
||||
Arch: deployFile.Arch,
|
||||
OldVersion: oldVersion,
|
||||
NewVersion: deployFile.Version,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &pb.FindAllUpgradeNSNodesWithNSClusterIdResponse{Nodes: result}, nil
|
||||
}
|
||||
|
||||
// UpgradeNSNode 升级单个NS节点
|
||||
func (this *NSNodeService) UpgradeNSNode(ctx context.Context, req *pb.UpgradeNSNodeRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
err = models.SharedNSNodeDAO.UpdateNodeIsInstalled(tx, req.NsNodeId, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
goman.New(func() {
|
||||
installErr := installers.SharedNSNodeQueue().InstallNodeProcess(req.NsNodeId, true)
|
||||
if installErr != nil {
|
||||
logs.Println("[RPC]upgrade dns node:" + installErr.Error())
|
||||
}
|
||||
})
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user