mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-15 13:00:25 +08:00
[边缘节点]可以同时通过关键词搜索集群和节点
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
package clusters
|
package clusters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -16,12 +20,30 @@ func (this *IndexAction) Init() {
|
|||||||
this.Nav("", "cluster", "index")
|
this.Nav("", "cluster", "index")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{})
|
Keyword string
|
||||||
|
SearchType string
|
||||||
|
}) {
|
||||||
|
this.Data["keyword"] = params.Keyword
|
||||||
|
this.Data["searchType"] = params.SearchType
|
||||||
|
this.Data["isSearching"] = len(params.Keyword) > 0
|
||||||
|
|
||||||
|
// 搜索节点
|
||||||
|
if params.SearchType == "node" && len(params.Keyword) > 0 {
|
||||||
|
this.searchNodes(params.Keyword)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索集群
|
||||||
|
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.Data["countClusters"] = countResp.Count
|
||||||
|
|
||||||
count := countResp.Count
|
count := countResp.Count
|
||||||
page := this.NewPage(count)
|
page := this.NewPage(count)
|
||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
@@ -29,6 +51,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
clusterMaps := []maps.Map{}
|
clusterMaps := []maps.Map{}
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
|
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
|
||||||
|
Keyword: params.Keyword,
|
||||||
Offset: page.Offset,
|
Offset: page.Offset,
|
||||||
Size: page.Size,
|
Size: page.Size,
|
||||||
})
|
})
|
||||||
@@ -88,6 +111,149 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Data["clusters"] = clusterMaps
|
this.Data["clusters"] = clusterMaps
|
||||||
|
this.Data["nodes"] = []maps.Map{}
|
||||||
|
|
||||||
|
if len(params.Keyword) > 0 {
|
||||||
|
// 搜索节点
|
||||||
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["countNodes"] = countResp.Count
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) searchNodes(keyword string) {
|
||||||
|
// 搜索节点
|
||||||
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
|
||||||
|
Keyword: keyword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count := countResp.Count
|
||||||
|
page := this.NewPage(count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
this.Data["countNodes"] = count
|
||||||
|
|
||||||
|
nodesResp, err := this.RPC().NodeRPC().ListEnabledNodesMatch(this.AdminContext(), &pb.ListEnabledNodesMatchRequest{
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
Keyword: keyword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeMaps := []maps.Map{}
|
||||||
|
for _, node := range nodesResp.Nodes {
|
||||||
|
// 状态
|
||||||
|
isSynced := false
|
||||||
|
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秒之内认为活跃
|
||||||
|
isSynced = status.ConfigVersion == node.Version
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP
|
||||||
|
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{NodeId: node.Id})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ipAddresses := []maps.Map{}
|
||||||
|
for _, addr := range ipAddressesResp.Addresses {
|
||||||
|
ipAddresses = append(ipAddresses, maps.Map{
|
||||||
|
"id": addr.Id,
|
||||||
|
"name": addr.Name,
|
||||||
|
"ip": addr.Ip,
|
||||||
|
"canAccess": addr.CanAccess,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分组
|
||||||
|
var groupMap maps.Map = nil
|
||||||
|
if node.Group != nil {
|
||||||
|
groupMap = maps.Map{
|
||||||
|
"id": node.Group.Id,
|
||||||
|
"name": node.Group.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 区域
|
||||||
|
var regionMap maps.Map = nil
|
||||||
|
if node.Region != nil {
|
||||||
|
regionMap = maps.Map{
|
||||||
|
"id": node.Region.Id,
|
||||||
|
"name": node.Region.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DNS
|
||||||
|
dnsRouteNames := []string{}
|
||||||
|
for _, route := range node.DnsRoutes {
|
||||||
|
dnsRouteNames = append(dnsRouteNames, route.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeMaps = append(nodeMaps, maps.Map{
|
||||||
|
"id": node.Id,
|
||||||
|
"name": node.Name,
|
||||||
|
"isInstalled": node.IsInstalled,
|
||||||
|
"isOn": node.IsOn,
|
||||||
|
"isUp": node.IsUp,
|
||||||
|
"installStatus": maps.Map{
|
||||||
|
"isRunning": node.InstallStatus.IsRunning,
|
||||||
|
"isFinished": node.InstallStatus.IsFinished,
|
||||||
|
"isOk": node.InstallStatus.IsOk,
|
||||||
|
"error": node.InstallStatus.Error,
|
||||||
|
},
|
||||||
|
"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),
|
||||||
|
},
|
||||||
|
"cluster": maps.Map{
|
||||||
|
"id": node.NodeCluster.Id,
|
||||||
|
"name": node.NodeCluster.Name,
|
||||||
|
},
|
||||||
|
"isSynced": isSynced,
|
||||||
|
"ipAddresses": ipAddresses,
|
||||||
|
"group": groupMap,
|
||||||
|
"region": regionMap,
|
||||||
|
"dnsRouteNames": dnsRouteNames,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["nodes"] = nodeMaps
|
||||||
|
|
||||||
|
this.Data["clusters"] = []maps.Map{}
|
||||||
|
|
||||||
|
// 搜索集群
|
||||||
|
{
|
||||||
|
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{
|
||||||
|
Keyword: keyword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["countClusters"] = countResp.Count
|
||||||
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
{$layout}
|
{$layout}
|
||||||
{$template "menu"}
|
{$template "menu"}
|
||||||
|
|
||||||
<p class="comment" v-if="clusters.length == 0">暂时还没有集群。</p>
|
<div class="margin"></div>
|
||||||
|
<form method="get" action="/clusters" class="ui form">
|
||||||
|
<input type="hidden" name="searchType" :value="searchType"/>
|
||||||
|
<div class="ui fields inline">
|
||||||
|
<div class="ui field">
|
||||||
|
<input type="text" name="keyword" v-model="keyword" placeholder="集群、节点关键词"/>
|
||||||
|
</div>
|
||||||
|
<div class="ui field">
|
||||||
|
<button class="ui button" type="submit">搜索</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="ui tabular menu" v-if="isSearching">
|
||||||
|
<a :href="'/clusters?searchType=cluster&keyword=' + keyword" class="item" :class="{active: searchType == '' || searchType == 'cluster'}">集群({{countClusters}})</a>
|
||||||
|
<a :href="'/clusters?searchType=node&keyword=' + keyword" class="item" :class="{active: searchType == 'node'}">节点({{countNodes}})</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 集群 -->
|
||||||
|
<div v-show="searchType == '' || searchType == 'cluster'">
|
||||||
|
<div class="margin"></div>
|
||||||
|
<p class="comment" v-if="clusters.length == 0">暂时还没有集群。</p>
|
||||||
<table class="ui table selectable celled" v-if="clusters.length > 0">
|
<table class="ui table selectable celled" v-if="clusters.length > 0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -39,5 +59,93 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-show="searchType == 'node'">
|
||||||
|
<p class="comment" v-if="nodes.length == 0">暂时还没有节点。</p>
|
||||||
|
<table class="ui table selectable celled" v-if="nodes.length > 0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>节点名称</th>
|
||||||
|
<th>所属区域</th>
|
||||||
|
<th>所属分组</th>
|
||||||
|
<th>IP</th>
|
||||||
|
<th class="width10">DNS线路</th>
|
||||||
|
<th class="width5 center">CPU</th>
|
||||||
|
<th class="width5 center">内存</th>
|
||||||
|
<!--<th>流量</th>
|
||||||
|
<th>连接数</th>-->
|
||||||
|
<th class="two wide center">状态</th>
|
||||||
|
<th class="two op">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tr v-for="node in nodes">
|
||||||
|
<td>{{node.name}}
|
||||||
|
<div style="margin-top: 0.5em">
|
||||||
|
<span class="ui label tiny">集群:{{node.cluster.name}}</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="node.region != null">{{node.region.name}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="node.group != null">{{node.group.name}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="node.ipAddresses.length == 0" class="disabled">-</span>
|
||||||
|
<div v-else class="address-box">
|
||||||
|
<div v-for="addr in node.ipAddresses" style="margin-bottom:0.3em">
|
||||||
|
<div class="ui label tiny basic">{{addr.ip}}
|
||||||
|
<span class="small" v-if="addr.name.length > 0">({{addr.name}}<span v-if="!addr.canAccess">,不可访问</span>)</span>
|
||||||
|
<span class="small" v-if="addr.name.length == 0 && !addr.canAccess">(不可访问)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div v-if="node.dnsRouteNames.length > 0">
|
||||||
|
<div v-for="routeName in node.dnsRouteNames">
|
||||||
|
<tiny-basic-label>{{routeName}}</tiny-basic-label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<span v-if="node.status.isActive" :class="{red:node.status.cpuUsage > 0.80}">{{node.status.cpuUsageText}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<span v-if="node.status.isActive" :class="{red:node.status.memUsage > 0.80}">{{node.status.memUsageText}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<div v-if="!node.isUp">
|
||||||
|
<span class="red">健康问题</span>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="!node.isOn">
|
||||||
|
<label-on :v-is-on="node.isOn"></label-on>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="node.isInstalled">
|
||||||
|
<div v-if="node.status.isActive">
|
||||||
|
<span v-if="!node.isSynced" class="red">同步中</span>
|
||||||
|
<span v-else class="green">运行中</span>
|
||||||
|
</div>
|
||||||
|
<span v-else-if="node.status.updatedAt > 0" class="red">已断开</span>
|
||||||
|
<span v-else-if="node.status.updatedAt == 0" class="red">未连接</span>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<span v-if="node.installStatus.isRunning" class="red">安装中</span>
|
||||||
|
<a v-if="node.installStatus.isFinished && !node.installStatus.isOk" :href="'/clusters/cluster/node/install?clusterId=' + node.cluster.id + '&nodeId=' + node.id" title="点击看安装错误"><span class="red">安装出错</span></a>
|
||||||
|
<a v-else class="red" :href="'/clusters/cluster/node/install?clusterId=' + node.cluster.id + '&nodeId=' + node.id" title="点击进安装界面"><span class="red">未安装</span></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a :href="'/clusters/cluster/node?clusterId=' + node.cluster.id + '&nodeId=' + node.id">详情</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<page-box></page-box>
|
<page-box></page-box>
|
||||||
Reference in New Issue
Block a user