mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-10 00:00:26 +08:00
实现远程升级节点
This commit is contained in:
@@ -45,6 +45,7 @@ func (this *CreateBatchAction) RunPost(params struct {
|
||||
IpList string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择正确的集群")
|
||||
|
||||
@@ -17,6 +17,8 @@ func init() {
|
||||
GetPost("/installNodes", new(InstallNodesAction)).
|
||||
GetPost("/installRemote", new(InstallRemoteAction)).
|
||||
Post("/installStatus", new(InstallStatusAction)).
|
||||
GetPost("/upgradeRemote", new(UpgradeRemoteAction)).
|
||||
Post("/upgradeStatus", new(UpgradeStatusAction)).
|
||||
GetPost("/delete", new(DeleteAction)).
|
||||
GetPost("/createNode", new(CreateNodeAction)).
|
||||
GetPost("/createBatch", new(CreateBatchAction)).
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -20,18 +19,7 @@ func (this *InstallNodesAction) Init() {
|
||||
func (this *InstallNodesAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
this.Data["leftMenuItems"] = []maps.Map{
|
||||
{
|
||||
"name": "自动注册",
|
||||
"url": "/clusters/cluster/installNodes?clusterId=" + numberutils.FormatInt64(params.ClusterId),
|
||||
"isActive": true,
|
||||
},
|
||||
{
|
||||
"name": "远程安装",
|
||||
"url": "/clusters/cluster/installRemote?clusterId=" + numberutils.FormatInt64(params.ClusterId),
|
||||
"isActive": false,
|
||||
},
|
||||
}
|
||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "register")
|
||||
|
||||
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package cluster
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
@@ -21,18 +20,7 @@ func (this *InstallRemoteAction) Init() {
|
||||
func (this *InstallRemoteAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
this.Data["leftMenuItems"] = []maps.Map{
|
||||
{
|
||||
"name": "自动注册",
|
||||
"url": "/clusters/cluster/installNodes?clusterId=" + numberutils.FormatInt64(params.ClusterId),
|
||||
"isActive": false,
|
||||
},
|
||||
{
|
||||
"name": "远程安装",
|
||||
"url": "/clusters/cluster/installRemote?clusterId=" + numberutils.FormatInt64(params.ClusterId),
|
||||
"isActive": true,
|
||||
},
|
||||
}
|
||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "install")
|
||||
|
||||
nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{ClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpgradeRemoteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "upgrade")
|
||||
|
||||
nodes := []maps.Map{}
|
||||
resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithClusterIdRequest{ClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, node := range resp.Nodes {
|
||||
loginParams := maps.Map{}
|
||||
if node.Node.Login != nil && len(node.Node.Login.Params) > 0 {
|
||||
err := json.Unmarshal(node.Node.Login.Params, &loginParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
nodes = append(nodes, maps.Map{
|
||||
"id": node.Node.Id,
|
||||
"name": node.Node.Name,
|
||||
"os": node.Os,
|
||||
"arch": node.Arch,
|
||||
"oldVersion": node.OldVersion,
|
||||
"newVersion": node.NewVersion,
|
||||
"login": node.Node.Login,
|
||||
"loginParams": loginParams,
|
||||
"addresses": node.Node.IpAddresses,
|
||||
"installStatus": node.Node.InstallStatus,
|
||||
})
|
||||
}
|
||||
this.Data["nodes"] = nodes
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
_, err := this.RPC().NodeRPC().UpgradeNode(this.AdminContext(), &pb.UpgradeNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpgradeStatusAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpgradeStatusAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeRPC().FindNodeInstallStatus(this.AdminContext(), &pb.FindNodeInstallStatusRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.InstallStatus == nil {
|
||||
this.Data["status"] = nil
|
||||
this.Success()
|
||||
}
|
||||
|
||||
this.Data["status"] = maps.Map{
|
||||
"isRunning": resp.InstallStatus.IsRunning,
|
||||
"isFinished": resp.InstallStatus.IsFinished,
|
||||
"isOk": resp.InstallStatus.IsOk,
|
||||
"error": resp.InstallStatus.Error,
|
||||
"errorCode": resp.InstallStatus.ErrorCode,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
27
internal/web/actions/default/clusters/cluster/utils.go
Normal file
27
internal/web/actions/default/clusters/cluster/utils.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// 安装升级相关的左侧菜单
|
||||
func LeftMenuItemsForInstall(clusterId int64, selectedItem string) []maps.Map {
|
||||
return []maps.Map{
|
||||
{
|
||||
"name": "自动注册",
|
||||
"url": "/clusters/cluster/installNodes?clusterId=" + numberutils.FormatInt64(clusterId),
|
||||
"isActive": selectedItem == "register",
|
||||
},
|
||||
{
|
||||
"name": "远程安装",
|
||||
"url": "/clusters/cluster/installRemote?clusterId=" + numberutils.FormatInt64(clusterId),
|
||||
"isActive": selectedItem == "install",
|
||||
},
|
||||
{
|
||||
"name": "远程升级",
|
||||
"url": "/clusters/cluster/upgradeRemote?clusterId=" + numberutils.FormatInt64(clusterId),
|
||||
"isActive": selectedItem == "upgrade",
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user