diff --git a/internal/web/actions/default/clusters/cluster/createBatch.go b/internal/web/actions/default/clusters/cluster/createBatch.go index aca4a1da..28b69b8b 100644 --- a/internal/web/actions/default/clusters/cluster/createBatch.go +++ b/internal/web/actions/default/clusters/cluster/createBatch.go @@ -45,6 +45,7 @@ func (this *CreateBatchAction) RunPost(params struct { IpList string Must *actions.Must + CSRF *actionutils.CSRF }) { if params.ClusterId <= 0 { this.Fail("请选择正确的集群") diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 6fa7fdf2..ca35f7ae 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -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)). diff --git a/internal/web/actions/default/clusters/cluster/installNodes.go b/internal/web/actions/default/clusters/cluster/installNodes.go index c27d45a5..71c60af8 100644 --- a/internal/web/actions/default/clusters/cluster/installNodes.go +++ b/internal/web/actions/default/clusters/cluster/installNodes.go @@ -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 { diff --git a/internal/web/actions/default/clusters/cluster/installRemote.go b/internal/web/actions/default/clusters/cluster/installRemote.go index 4d22c2c2..bf659ef8 100644 --- a/internal/web/actions/default/clusters/cluster/installRemote.go +++ b/internal/web/actions/default/clusters/cluster/installRemote.go @@ -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 { diff --git a/internal/web/actions/default/clusters/cluster/upgradeRemote.go b/internal/web/actions/default/clusters/cluster/upgradeRemote.go new file mode 100644 index 00000000..6a0574b3 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/upgradeRemote.go @@ -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() +} diff --git a/internal/web/actions/default/clusters/cluster/upgradeStatus.go b/internal/web/actions/default/clusters/cluster/upgradeStatus.go new file mode 100644 index 00000000..dc498787 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/upgradeStatus.go @@ -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() +} diff --git a/internal/web/actions/default/clusters/cluster/utils.go b/internal/web/actions/default/clusters/cluster/utils.go new file mode 100644 index 00000000..52647a9e --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/utils.go @@ -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", + }, + } +} diff --git a/web/views/@default/clusters/cluster/@menu.html b/web/views/@default/clusters/cluster/@menu.html index f5e7b19d..0dbf2132 100644 --- a/web/views/@default/clusters/cluster/@menu.html +++ b/web/views/@default/clusters/cluster/@menu.html @@ -1,5 +1,5 @@ 节点列表 创建节点 - 安装节点 + 安装升级 \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/createBatch.html b/web/views/@default/clusters/cluster/createBatch.html index f08684ee..90f7339b 100644 --- a/web/views/@default/clusters/cluster/createBatch.html +++ b/web/views/@default/clusters/cluster/createBatch.html @@ -4,6 +4,7 @@
+ diff --git a/web/views/@default/clusters/cluster/installRemote.html b/web/views/@default/clusters/cluster/installRemote.html index 9ef5282b..2837ebd7 100644 --- a/web/views/@default/clusters/cluster/installRemote.html +++ b/web/views/@default/clusters/cluster/installRemote.html @@ -18,7 +18,9 @@ - + @@ -36,6 +38,7 @@ 安装过程中发生错误:{{node.installStatus.error}} + 等待安装
{{node.name}} + {{node.name}} + {{addr.ip}} 安装 diff --git a/web/views/@default/clusters/cluster/node/node.html b/web/views/@default/clusters/cluster/node/node.html index d17fbaab..d4d4142d 100644 --- a/web/views/@default/clusters/cluster/node/node.html +++ b/web/views/@default/clusters/cluster/node/node.html @@ -85,7 +85,7 @@ 是否在运行
- 运行中   + 运行中   [通过SSH停止] [停止中...]
diff --git a/web/views/@default/clusters/cluster/upgradeRemote.css b/web/views/@default/clusters/cluster/upgradeRemote.css new file mode 100644 index 00000000..88ded090 --- /dev/null +++ b/web/views/@default/clusters/cluster/upgradeRemote.css @@ -0,0 +1,7 @@ +.left-box { + top: 10em; +} +.right-box { + top: 10em; +} +/*# sourceMappingURL=upgradeRemote.css.map */ \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/upgradeRemote.css.map b/web/views/@default/clusters/cluster/upgradeRemote.css.map new file mode 100644 index 00000000..014a1b9d --- /dev/null +++ b/web/views/@default/clusters/cluster/upgradeRemote.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["upgradeRemote.less"],"names":[],"mappings":"AAAA;EACC,SAAA;;AAGD;EACC,SAAA","file":"upgradeRemote.css"} \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/upgradeRemote.html b/web/views/@default/clusters/cluster/upgradeRemote.html new file mode 100644 index 00000000..9d4aa30f --- /dev/null +++ b/web/views/@default/clusters/cluster/upgradeRemote.html @@ -0,0 +1,53 @@ +{$layout} +{$template "menu"} +{$template "/left_menu"} + +
+

暂时没有需要升级的节点。

+ +
+

所有需要升级的节点

+ + + + + + + + + + + + + + + + + + + +
节点名访问IPSSH地址版本变化节点状态操作
+ {{node.name}} + + {{addr.ip}} + + + {{node.loginParams.host}}:{{node.loginParams.port}} + + 没有设置 + v{{node.oldVersion}} -> v{{node.newVersion}} +
+
升级中...
+
+ 已升级成功 + 升级过程中发生错误:{{node.installStatus.error}} +
+
+ 等待升级 +
+ 升级 + 升级中... + 升级 +
+
+
diff --git a/web/views/@default/clusters/cluster/upgradeRemote.js b/web/views/@default/clusters/cluster/upgradeRemote.js new file mode 100644 index 00000000..9b7c390b --- /dev/null +++ b/web/views/@default/clusters/cluster/upgradeRemote.js @@ -0,0 +1,87 @@ +Tea.context(function () { + this.isInstalling = false + let installingNode = null + + this.$delay(function () { + this.reload() + }) + + this.installNode = function (node) { + let that = this + teaweb.confirm("确定要开始升级此节点吗?", function () { + installingNode = node + that.isInstalling = true + node.isInstalling = true + + that.$post("$") + .params({ + nodeId: node.id + }) + }) + } + + this.reload = function () { + let that = this + if (installingNode != null) { + this.$post("/clusters/cluster/upgradeStatus") + .params({ + nodeId: installingNode.id + }) + .success(function (resp) { + if (resp.data.status != null) { + installingNode.installStatus = resp.data.status + if (installingNode.installStatus.isFinished) { + if (installingNode.installStatus.isOk) { + installingNode = null + teaweb.success("升级成功", function () { + window.location.reload() + }) + } else { + let nodeId = installingNode.id + let errMsg = installingNode.installStatus.error + that.isInstalling = false + installingNode.isInstalling = false + installingNode = null + + switch (resp.data.status.errorCode) { + case "EMPTY_LOGIN": + case "EMPTY_SSH_HOST": + case "EMPTY_SSH_PORT": + case "EMPTY_GRANT": + teaweb.warn("需要填写SSH登录信息", function () { + teaweb.popup("/clusters/cluster/updateNodeSSH?nodeId=" + nodeId, { + callback: function () { + teaweb.reload() + } + }) + }) + return + case "CREATE_ROOT_DIRECTORY_FAILED": + teaweb.warn("创建根目录失败,请检查目录权限或者手工创建:" + errMsg) + return + case "INSTALL_HELPER_FAILED": + teaweb.warn("安装助手失败:" + errMsg) + return + case "TEST_FAILED": + teaweb.warn("环境测试失败:" + errMsg) + return + case "RPC_TEST_FAILED": + teaweb.confirm("html:要升级的节点到API服务之间的RPC通讯测试失败,具体错误:" + errMsg + ",
现在修改API信息?", function () { + window.location = "/api" + }) + return + default: + teaweb.warn("升级失败:" + errMsg) + } + } + } + } + }) + .done(function () { + setTimeout(this.reload, 3000) + }) + } else { + setTimeout(this.reload, 3000) + } + } +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/upgradeRemote.less b/web/views/@default/clusters/cluster/upgradeRemote.less new file mode 100644 index 00000000..f54837f3 --- /dev/null +++ b/web/views/@default/clusters/cluster/upgradeRemote.less @@ -0,0 +1,7 @@ +.left-box { + top: 10em; +} + +.right-box { + top: 10em; +} \ No newline at end of file