mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-02 00:56:38 +08:00
优化代码
This commit is contained in:
@@ -25,7 +25,7 @@ func (this *CheckChangeAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, cluster := range resp.Clusters {
|
||||
for _, cluster := range resp.NodeClusters {
|
||||
result = append(result, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
|
||||
@@ -139,8 +139,8 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
||||
},
|
||||
"cluster": maps.Map{
|
||||
"id": node.Cluster.Id,
|
||||
"name": node.Cluster.Name,
|
||||
"id": node.NodeCluster.Id,
|
||||
"name": node.NodeCluster.Name,
|
||||
},
|
||||
"isSynced": isSynced,
|
||||
"ipAddresses": ipAddresses,
|
||||
|
||||
@@ -26,12 +26,12 @@ func (this *InstallNodesAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if clusterResp.Cluster == nil {
|
||||
if clusterResp.NodeCluster == nil {
|
||||
this.NotFound("nodeCluster", params.ClusterId)
|
||||
return
|
||||
}
|
||||
|
||||
cluster := clusterResp.Cluster
|
||||
cluster := clusterResp.NodeCluster
|
||||
|
||||
clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{NodeClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
|
||||
@@ -51,14 +51,14 @@ func (this *InstallAction) RunGet(params struct {
|
||||
|
||||
// 集群
|
||||
var clusterMap maps.Map = nil
|
||||
if node.Cluster != nil {
|
||||
clusterId := node.Cluster.Id
|
||||
if node.NodeCluster != nil {
|
||||
clusterId := node.NodeCluster.Id
|
||||
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cluster := clusterResp.Cluster
|
||||
cluster := clusterResp.NodeCluster
|
||||
if cluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": cluster.Id,
|
||||
|
||||
@@ -37,14 +37,14 @@ func (this *NodeAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
var clusterMap maps.Map = nil
|
||||
if node.Cluster != nil {
|
||||
clusterId := node.Cluster.Id
|
||||
if node.NodeCluster != nil {
|
||||
clusterId := node.NodeCluster.Id
|
||||
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cluster := clusterResp.Cluster
|
||||
cluster := clusterResp.NodeCluster
|
||||
if cluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": cluster.Id,
|
||||
|
||||
@@ -37,10 +37,10 @@ func (this *UpdateAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
var clusterMap maps.Map = nil
|
||||
if node.Cluster != nil {
|
||||
if node.NodeCluster != nil {
|
||||
clusterMap = maps.Map{
|
||||
"id": node.Cluster.Id,
|
||||
"name": node.Cluster.Name,
|
||||
"id": node.NodeCluster.Id,
|
||||
"name": node.NodeCluster.Name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func (this *UpdateAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
clusterMaps := []maps.Map{}
|
||||
for _, cluster := range resp.Clusters {
|
||||
for _, cluster := range resp.NodeClusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
|
||||
@@ -26,7 +26,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cluster := clusterResp.Cluster
|
||||
cluster := clusterResp.NodeCluster
|
||||
if cluster == nil {
|
||||
this.WriteString("not found cluster")
|
||||
return
|
||||
|
||||
@@ -2,7 +2,9 @@ package clusterutils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -19,7 +21,8 @@ func NewClusterHelper() *ClusterHelper {
|
||||
return &ClusterHelper{}
|
||||
}
|
||||
|
||||
func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
|
||||
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||
action := actionPtr.Object()
|
||||
if action.Request.Method != http.MethodGet {
|
||||
return
|
||||
}
|
||||
@@ -31,19 +34,12 @@ func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
|
||||
clusterIdString := strconv.FormatInt(clusterId, 10)
|
||||
action.Data["clusterId"] = clusterId
|
||||
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if clusterId > 0 {
|
||||
clusterResp, err := rpcClient.NodeClusterRPC().FindEnabledNodeCluster(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
|
||||
cluster, err := models.SharedNodeClusterDAO.FindEnabledNodeCluster(actionPtr.(rpc.ContextInterface).AdminContext(), clusterId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
cluster := clusterResp.Cluster
|
||||
if cluster == nil {
|
||||
action.WriteString("can not find cluster")
|
||||
return
|
||||
@@ -65,13 +61,14 @@ func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
|
||||
secondMenuItem := action.Data.GetString("secondMenuItem")
|
||||
switch selectedTabbar {
|
||||
case "setting":
|
||||
action.Data["leftMenuItems"] = this.createSettingMenu(clusterIdString, secondMenuItem)
|
||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置菜单
|
||||
func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem string) (items []maps.Map) {
|
||||
func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedItem string) (items []maps.Map) {
|
||||
clusterId := numberutils.FormatInt64(cluster.Id)
|
||||
items = append(items, maps.Map{
|
||||
"name": "基础设置",
|
||||
"url": "/clusters/cluster/settings?clusterId=" + clusterId,
|
||||
@@ -81,11 +78,13 @@ func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem stri
|
||||
"name": "缓存设置",
|
||||
"url": "/clusters/cluster/settings/cache?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "cache",
|
||||
"isOn": cluster.HttpCachePolicyId > 0,
|
||||
})
|
||||
items = append(items, maps.Map{
|
||||
"name": "WAF设置",
|
||||
"url": "/clusters/cluster/settings/waf?clusterId=" + clusterId,
|
||||
"isActive": selectedItem == "waf",
|
||||
"isOn": cluster.HttpFirewallPolicyId > 0,
|
||||
})
|
||||
items = append(items, maps.Map{
|
||||
"name": "健康检查",
|
||||
|
||||
@@ -50,7 +50,7 @@ func (this *GrantAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
@@ -66,13 +66,13 @@ func (this *GrantAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
for _, node := range nodesResp.Nodes {
|
||||
if node.Cluster == nil {
|
||||
if node.NodeCluster == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
clusterMap := maps.Map{
|
||||
"id": node.Cluster.Id,
|
||||
"name": node.Cluster.Name,
|
||||
"id": node.NodeCluster.Id,
|
||||
"name": node.NodeCluster.Name,
|
||||
}
|
||||
|
||||
nodeMaps = append(nodeMaps, maps.Map{
|
||||
|
||||
@@ -36,7 +36,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
// 全部节点数量
|
||||
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{NodeClusterId: cluster.Id})
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,7 @@ func (this *OptionsAction) RunPost(params struct{}) {
|
||||
}
|
||||
|
||||
clusterMaps := []maps.Map{}
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
|
||||
@@ -21,7 +21,7 @@ func (this *SyncAction) RunPost(params struct{}) {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
clusters := clustersResp.Clusters
|
||||
clusters := clustersResp.NodeClusters
|
||||
|
||||
for _, cluster := range clusters {
|
||||
_, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{
|
||||
|
||||
Reference in New Issue
Block a user