mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-11 01:50:27 +08:00
增加节点停止、启动、安装测试等功能
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package nodes
|
||||
|
||||
// 节点状态
|
||||
type NodeStatus struct {
|
||||
BuildVersion string `json:"buildVersion"` // 编译版本
|
||||
ConfigVersion int64 `json:"configVersion"` // 节点配置版本
|
||||
|
||||
Hostname string `json:"hostname"`
|
||||
HostIP string `json:"hostIP"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
CPULogicalCount int `json:"cpuLogicalCount"`
|
||||
CPUPhysicalCount int `json:"cpuPhysicalCount"`
|
||||
MemoryUsage float64 `json:"memoryUsage"`
|
||||
MemoryTotal uint64 `json:"memoryTotal"`
|
||||
DiskUsage float64 `json:"diskUsage"`
|
||||
DiskMaxUsage float64 `json:"diskMaxUsage"`
|
||||
DiskMaxUsagePartition string `json:"diskMaxUsagePartition"`
|
||||
DiskTotal uint64 `json:"diskTotal"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
Load1m float64 `json:"load1m"`
|
||||
Load5m float64 `json:"load5m"`
|
||||
Load15m float64 `json:"load15m"`
|
||||
|
||||
IsActive bool `json:"isActive"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package cluster
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs/nodes"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -53,14 +53,14 @@ func (this *IndexAction) RunGet(params struct {
|
||||
for _, node := range nodesResp.Nodes {
|
||||
// 状态
|
||||
isSynced := false
|
||||
status := &nodes.NodeStatus{}
|
||||
if len(node.Status) > 0 && node.Status != "null" {
|
||||
err = json.Unmarshal([]byte(node.Status), &status)
|
||||
status := &nodeconfigs.NodeStatus{}
|
||||
if len(node.StatusJSON) > 0 {
|
||||
err = json.Unmarshal(node.StatusJSON, &status)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
continue
|
||||
}
|
||||
status.IsActive = time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
||||
isSynced = status.ConfigVersion == node.Version
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ func init() {
|
||||
Post("/node/updateInstallStatus", new(node.UpdateInstallStatusAction)).
|
||||
Post("/node/status", new(node.StatusAction)).
|
||||
Get("/node/logs", new(node.LogsAction)).
|
||||
Post("/node/start", new(node.StartAction)).
|
||||
Post("/node/stop", new(node.StopAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package node
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NodeAction struct {
|
||||
@@ -106,6 +109,17 @@ func (this *NodeAction) RunGet(params struct {
|
||||
}
|
||||
}
|
||||
|
||||
// 运行状态
|
||||
status := &nodeconfigs.NodeStatus{}
|
||||
if len(node.StatusJSON) > 0 {
|
||||
err = json.Unmarshal(node.StatusJSON, &status)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": node.Id,
|
||||
"name": node.Name,
|
||||
@@ -118,6 +132,16 @@ func (this *NodeAction) RunGet(params struct {
|
||||
"secret": node.Secret,
|
||||
"maxCPU": node.MaxCPU,
|
||||
"isOn": node.IsOn,
|
||||
|
||||
"status": maps.Map{
|
||||
"isActive": status.IsActive,
|
||||
"updatedAt": status.UpdatedAt,
|
||||
"hostname": status.Hostname,
|
||||
"cpuUsage": status.CPUUsage,
|
||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
||||
"memUsage": status.MemoryUsage,
|
||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
||||
},
|
||||
}
|
||||
|
||||
this.Show()
|
||||
|
||||
25
internal/web/actions/default/clusters/cluster/node/start.go
Normal file
25
internal/web/actions/default/clusters/cluster/node/start.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"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().NodeRPC().StartNode(this.AdminContext(), &pb.StartNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IsOk {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
this.Fail("启动失败:" + resp.Error)
|
||||
}
|
||||
25
internal/web/actions/default/clusters/cluster/node/stop.go
Normal file
25
internal/web/actions/default/clusters/cluster/node/stop.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"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().NodeRPC().StopNode(this.AdminContext(), &pb.StopNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IsOk {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
this.Fail("执行失败:" + resp.Error)
|
||||
}
|
||||
@@ -16,5 +16,5 @@ Vue.component("more-options-indicator", {
|
||||
this.$emit("change", this.visible)
|
||||
}
|
||||
},
|
||||
template: '<a href="" style="font-weight: normal" @click.prevent="changeVisible()"><span v-if="!visible">更多选项</span><span v-if="visible">收起选项</span> <i class="icon angle" :class="{down:!visible, up:visible}"></i> </a>'
|
||||
template: '<a href="" style="font-weight: normal" @click.prevent="changeVisible()"><slot><span v-if="!visible">更多选项</span><span v-if="visible">收起选项</span></slot> <i class="icon angle" :class="{down:!visible, up:visible}"></i> </a>'
|
||||
});
|
||||
@@ -104,6 +104,9 @@ span.red,
|
||||
pre.red {
|
||||
color: #db2828;
|
||||
}
|
||||
span.blue {
|
||||
color: #4183c4;
|
||||
}
|
||||
pre:not(.CodeMirror-line) {
|
||||
font-family: Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif !important;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -33,6 +33,10 @@ span.red, pre.red {
|
||||
color: #db2828;
|
||||
}
|
||||
|
||||
span.blue {
|
||||
color: #4183c4;
|
||||
}
|
||||
|
||||
pre:not(.CodeMirror-line) {
|
||||
font-family: Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif !important;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{$layout}
|
||||
|
||||
{$template "menu"}
|
||||
{$template "menu"}
|
||||
|
||||
<form class="ui form segment" action="/clusters/cluster">
|
||||
<form class="ui form segment" action="/clusters/cluster">
|
||||
<input type="hidden" name="clusterId" :value="clusterId"/>
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
@@ -29,22 +29,22 @@
|
||||
<button class="ui button" type="submit">搜索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<p class="comment" v-if="nodes.length == 0">暂时还没有节点。</p>
|
||||
<p class="comment" v-if="nodes.length == 0">暂时还没有节点。</p>
|
||||
|
||||
<table class="ui table selectable" v-if="nodes.length > 0">
|
||||
<table class="ui table selectable" v-if="nodes.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th class="one wide">ID</th>
|
||||
<th>节点名称</th>
|
||||
<th>主机名</th>
|
||||
<th>IP</th>
|
||||
<th>CPU</th>
|
||||
<th>内存</th>
|
||||
<th class="two wide">CPU</th>
|
||||
<th class="two wide">内存</th>
|
||||
<!--<th>流量</th>
|
||||
<th>连接数</th>-->
|
||||
<th>状态</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -96,7 +96,7 @@
|
||||
<a :href="'/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + node.id">详情</a> <a href="" @click.prevent="deleteNode(node.id)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
|
||||
|
||||
<div class="page" v-html="page"></div>
|
||||
<div class="page" v-html="page"></div>
|
||||
@@ -56,6 +56,20 @@ Tea.context(function () {
|
||||
})
|
||||
})
|
||||
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 + ",<br/>现在修改API信息?", function () {
|
||||
window.location = "/api"
|
||||
})
|
||||
return
|
||||
default:
|
||||
teaweb.warn("安装失败:" + errMsg)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator>SSH等更多选项</more-options-indicator></td>
|
||||
</tr>
|
||||
<tbody v-show="moreOptionsVisible">
|
||||
<tr>
|
||||
<td>SSH主机地址</td>
|
||||
<td>
|
||||
@@ -71,8 +75,39 @@
|
||||
<span v-else class="disabled">没有限制。</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<h3>运行状态</h3>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">是否在运行</td>
|
||||
<td>
|
||||
<div v-if="node.status.isActive">
|
||||
<span class="green">运行中</span>
|
||||
<a href="" @click.prevent="stopNode()" v-if="!isStopping"><span>[通过SSH停止]</span></a>
|
||||
<span v-if="isStopping">[停止中...]</span>
|
||||
</div>
|
||||
<div v-else>
|
||||
<span class="red">已断开</span>
|
||||
<a href="" @click.prevent="startNode()" v-if="node.isInstalled && !isStarting"><span>[通过SSH启动]</span></a>
|
||||
<span v-if="node.isInstalled && isStarting">[启动中...]</span>
|
||||
<a v-if="!node.isInstalled" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" ><span>去安装></span></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-show="node.status.isActive">
|
||||
<td>CPU</td>
|
||||
<td>{{node.status.cpuUsageText}}</td>
|
||||
</tr>
|
||||
<tr v-show="node.status.isActive">
|
||||
<td>内存</td>
|
||||
<td>{{node.status.memUsageText}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
<h3>安装信息</h3>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
|
||||
35
web/views/@default/clusters/cluster/node/node.js
Normal file
35
web/views/@default/clusters/cluster/node/node.js
Normal file
@@ -0,0 +1,35 @@
|
||||
Tea.context(function () {
|
||||
this.isStarting = false
|
||||
this.startNode = function () {
|
||||
this.isStarting = true
|
||||
this.$post("/clusters/cluster/node/start")
|
||||
.params({
|
||||
nodeId: this.node.id
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("启动成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
})
|
||||
.done(function () {
|
||||
this.isStarting = false
|
||||
})
|
||||
}
|
||||
|
||||
this.isStopping = false
|
||||
this.stopNode = function () {
|
||||
this.isStopping = true
|
||||
this.$post("/clusters/cluster/node/stop")
|
||||
.params({
|
||||
nodeId: this.node.id
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.success("执行成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
})
|
||||
.done(function () {
|
||||
this.isStopping = false
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user