From e650529efb84e98231d975b0d956645fd288f458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 12 Aug 2021 11:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=BF=9C=E7=A8=8B=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=92=8C=E5=90=AF=E5=8A=A8DNS=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/ns/clusters/cluster/init.go | 2 ++ .../default/ns/clusters/cluster/node/index.go | 2 +- .../default/ns/clusters/cluster/node/start.go | 30 +++++++++++++++++++ .../default/ns/clusters/cluster/node/stop.go | 30 +++++++++++++++++++ .../ns/clusters/cluster/node/index.html | 4 +-- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 internal/web/actions/default/ns/clusters/cluster/node/start.go create mode 100644 internal/web/actions/default/ns/clusters/cluster/node/stop.go diff --git a/internal/web/actions/default/ns/clusters/cluster/init.go b/internal/web/actions/default/ns/clusters/cluster/init.go index c8981763..223598c6 100644 --- a/internal/web/actions/default/ns/clusters/cluster/init.go +++ b/internal/web/actions/default/ns/clusters/cluster/init.go @@ -31,6 +31,8 @@ func init() { GetPost("/install", new(node.InstallAction)). Post("/status", new(node.StatusAction)). Post("/updateInstallStatus", new(node.UpdateInstallStatusAction)). + Post("/start", new(node.StartAction)). + Post("/stop", new(node.StopAction)). EndAll() }) } diff --git a/internal/web/actions/default/ns/clusters/cluster/node/index.go b/internal/web/actions/default/ns/clusters/cluster/node/index.go index ac6b93ef..fce62036 100644 --- a/internal/web/actions/default/ns/clusters/cluster/node/index.go +++ b/internal/web/actions/default/ns/clusters/cluster/node/index.go @@ -114,7 +114,7 @@ func (this *IndexAction) RunGet(params struct { "isOn": node.IsOn, "status": maps.Map{ - "isActive": status.IsActive, + "isActive": node.IsActive && status.IsActive, "updatedAt": status.UpdatedAt, "hostname": status.Hostname, "cpuUsage": status.CPUUsage, diff --git a/internal/web/actions/default/ns/clusters/cluster/node/start.go b/internal/web/actions/default/ns/clusters/cluster/node/start.go new file mode 100644 index 00000000..658232b6 --- /dev/null +++ b/internal/web/actions/default/ns/clusters/cluster/node/start.go @@ -0,0 +1,30 @@ +package node + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type StartAction struct { + actionutils.ParentAction +} + +func (this *StartAction) RunPost(params struct { + NodeId int64 +}) { + resp, err := this.RPC().NSNodeRPC().StartNSNode(this.AdminContext(), &pb.StartNSNodeRequest{NsNodeId: params.NodeId}) + if err != nil { + this.ErrorPage(err) + return + } + + // 创建日志 + defer this.CreateLog(oplogs.LevelInfo, "远程启动节点 %d", params.NodeId) + + if resp.IsOk { + this.Success() + } + + this.Fail("启动失败:" + resp.Error) +} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/stop.go b/internal/web/actions/default/ns/clusters/cluster/node/stop.go new file mode 100644 index 00000000..30bfcf6c --- /dev/null +++ b/internal/web/actions/default/ns/clusters/cluster/node/stop.go @@ -0,0 +1,30 @@ +package node + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type StopAction struct { + actionutils.ParentAction +} + +func (this *StopAction) RunPost(params struct { + NodeId int64 +}) { + resp, err := this.RPC().NSNodeRPC().StopNSNode(this.AdminContext(), &pb.StopNSNodeRequest{NsNodeId: params.NodeId}) + if err != nil { + this.ErrorPage(err) + return + } + + // 创建日志 + defer this.CreateLog(oplogs.LevelInfo, "远程停止节点 %d", params.NodeId) + + if resp.IsOk { + this.Success() + } + + this.Fail("执行失败:" + resp.Error) +} diff --git a/web/views/@default/ns/clusters/cluster/node/index.html b/web/views/@default/ns/clusters/cluster/node/index.html index 7237951d..9f9118af 100644 --- a/web/views/@default/ns/clusters/cluster/node/index.html +++ b/web/views/@default/ns/clusters/cluster/node/index.html @@ -39,12 +39,12 @@
运行中   - + [通过SSH停止] [停止中...]
已断开   - + [通过SSH启动] [启动中...] 去安装>