优化代码

This commit is contained in:
GoEdgeLab
2020-12-17 17:35:38 +08:00
parent 41ac159e23
commit a208cbaa41
33 changed files with 92 additions and 76 deletions

View File

@@ -0,0 +1,7 @@
package rpc
import "context"
type ContextInterface interface {
AdminContext() context.Context
}

View File

@@ -53,7 +53,7 @@ func (this *SyncClusterTask) loop() error {
return err return err
} }
for _, cluster := range resp.Clusters { for _, cluster := range resp.NodeClusters {
_, err := rpcClient.NodeRPC().SyncNodesVersionWithCluster(ctx, &pb.SyncNodesVersionWithClusterRequest{ _, err := rpcClient.NodeRPC().SyncNodesVersionWithCluster(ctx, &pb.SyncNodesVersionWithClusterRequest{
NodeClusterId: cluster.Id, NodeClusterId: cluster.Id,
}) })

View File

@@ -25,7 +25,7 @@ func (this *CheckChangeAction) RunPost(params struct {
} }
result := []maps.Map{} result := []maps.Map{}
for _, cluster := range resp.Clusters { for _, cluster := range resp.NodeClusters {
result = append(result, maps.Map{ result = append(result, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -139,8 +139,8 @@ func (this *IndexAction) RunGet(params struct {
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100), "memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
}, },
"cluster": maps.Map{ "cluster": maps.Map{
"id": node.Cluster.Id, "id": node.NodeCluster.Id,
"name": node.Cluster.Name, "name": node.NodeCluster.Name,
}, },
"isSynced": isSynced, "isSynced": isSynced,
"ipAddresses": ipAddresses, "ipAddresses": ipAddresses,

View File

@@ -26,12 +26,12 @@ func (this *InstallNodesAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
if clusterResp.Cluster == nil { if clusterResp.NodeCluster == nil {
this.NotFound("nodeCluster", params.ClusterId) this.NotFound("nodeCluster", params.ClusterId)
return return
} }
cluster := clusterResp.Cluster cluster := clusterResp.NodeCluster
clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{NodeClusterId: params.ClusterId}) clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{NodeClusterId: params.ClusterId})
if err != nil { if err != nil {

View File

@@ -51,14 +51,14 @@ func (this *InstallAction) RunGet(params struct {
// 集群 // 集群
var clusterMap maps.Map = nil var clusterMap maps.Map = nil
if node.Cluster != nil { if node.NodeCluster != nil {
clusterId := node.Cluster.Id clusterId := node.NodeCluster.Id
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
cluster := clusterResp.Cluster cluster := clusterResp.NodeCluster
if cluster != nil { if cluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": cluster.Id, "id": cluster.Id,

View File

@@ -37,14 +37,14 @@ func (this *NodeAction) RunGet(params struct {
} }
var clusterMap maps.Map = nil var clusterMap maps.Map = nil
if node.Cluster != nil { if node.NodeCluster != nil {
clusterId := node.Cluster.Id clusterId := node.NodeCluster.Id
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
cluster := clusterResp.Cluster cluster := clusterResp.NodeCluster
if cluster != nil { if cluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": cluster.Id, "id": cluster.Id,

View File

@@ -37,10 +37,10 @@ func (this *UpdateAction) RunGet(params struct {
} }
var clusterMap maps.Map = nil var clusterMap maps.Map = nil
if node.Cluster != nil { if node.NodeCluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": node.Cluster.Id, "id": node.NodeCluster.Id,
"name": node.Cluster.Name, "name": node.NodeCluster.Name,
} }
} }
@@ -178,7 +178,7 @@ func (this *UpdateAction) RunGet(params struct {
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range resp.Clusters { for _, cluster := range resp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -26,7 +26,7 @@ func (this *IndexAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
cluster := clusterResp.Cluster cluster := clusterResp.NodeCluster
if cluster == nil { if cluster == nil {
this.WriteString("not found cluster") this.WriteString("not found cluster")
return return

View File

@@ -2,7 +2,9 @@ package clusterutils
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc" "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/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/logs"
@@ -19,7 +21,8 @@ func NewClusterHelper() *ClusterHelper {
return &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 { if action.Request.Method != http.MethodGet {
return return
} }
@@ -31,19 +34,12 @@ func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
clusterIdString := strconv.FormatInt(clusterId, 10) clusterIdString := strconv.FormatInt(clusterId, 10)
action.Data["clusterId"] = clusterId action.Data["clusterId"] = clusterId
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Error(err)
return
}
if clusterId > 0 { 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 { if err != nil {
logs.Error(err) logs.Error(err)
return return
} }
cluster := clusterResp.Cluster
if cluster == nil { if cluster == nil {
action.WriteString("can not find cluster") action.WriteString("can not find cluster")
return return
@@ -65,13 +61,14 @@ func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
secondMenuItem := action.Data.GetString("secondMenuItem") secondMenuItem := action.Data.GetString("secondMenuItem")
switch selectedTabbar { switch selectedTabbar {
case "setting": 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{ items = append(items, maps.Map{
"name": "基础设置", "name": "基础设置",
"url": "/clusters/cluster/settings?clusterId=" + clusterId, "url": "/clusters/cluster/settings?clusterId=" + clusterId,
@@ -81,11 +78,13 @@ func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem stri
"name": "缓存设置", "name": "缓存设置",
"url": "/clusters/cluster/settings/cache?clusterId=" + clusterId, "url": "/clusters/cluster/settings/cache?clusterId=" + clusterId,
"isActive": selectedItem == "cache", "isActive": selectedItem == "cache",
"isOn": cluster.HttpCachePolicyId > 0,
}) })
items = append(items, maps.Map{ items = append(items, maps.Map{
"name": "WAF设置", "name": "WAF设置",
"url": "/clusters/cluster/settings/waf?clusterId=" + clusterId, "url": "/clusters/cluster/settings/waf?clusterId=" + clusterId,
"isActive": selectedItem == "waf", "isActive": selectedItem == "waf",
"isOn": cluster.HttpFirewallPolicyId > 0,
}) })
items = append(items, maps.Map{ items = append(items, maps.Map{
"name": "健康检查", "name": "健康检查",

View File

@@ -50,7 +50,7 @@ func (this *GrantAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,
@@ -66,13 +66,13 @@ func (this *GrantAction) RunGet(params struct {
return return
} }
for _, node := range nodesResp.Nodes { for _, node := range nodesResp.Nodes {
if node.Cluster == nil { if node.NodeCluster == nil {
continue continue
} }
clusterMap := maps.Map{ clusterMap := maps.Map{
"id": node.Cluster.Id, "id": node.NodeCluster.Id,
"name": node.Cluster.Name, "name": node.NodeCluster.Name,
} }
nodeMaps = append(nodeMaps, maps.Map{ nodeMaps = append(nodeMaps, maps.Map{

View File

@@ -36,7 +36,7 @@ func (this *IndexAction) RunGet(params struct{}) {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
// 全部节点数量 // 全部节点数量
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{NodeClusterId: cluster.Id}) countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{NodeClusterId: cluster.Id})
if err != nil { if err != nil {

View File

@@ -18,7 +18,7 @@ func (this *OptionsAction) RunPost(params struct{}) {
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -21,7 +21,7 @@ func (this *SyncAction) RunPost(params struct{}) {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusters := clustersResp.Clusters clusters := clustersResp.NodeClusters
for _, cluster := range clusters { for _, cluster := range clusters {
_, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{ _, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{

View File

@@ -23,7 +23,7 @@ func (this *ClusterAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
cluster := clusterResp.Cluster cluster := clusterResp.NodeCluster
if cluster == nil { if cluster == nil {
this.NotFound("nodeCluster", params.ClusterId) this.NotFound("nodeCluster", params.ClusterId)
return return

View File

@@ -32,7 +32,7 @@ func (this *IndexAction) RunGet(params struct{}) {
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
domainId := cluster.DnsDomainId domainId := cluster.DnsDomainId
domainName := "" domainName := ""
providerId := int64(0) providerId := int64(0)

View File

@@ -38,10 +38,10 @@ func (this *IndexAction) RunGet(params struct{}) {
messages := []maps.Map{} messages := []maps.Map{}
for _, message := range listResp.Messages { for _, message := range listResp.Messages {
clusterMap := maps.Map{} clusterMap := maps.Map{}
if message.Cluster != nil { if message.NodeCluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": message.Cluster.Id, "id": message.NodeCluster.Id,
"name": message.Cluster.Name, "name": message.NodeCluster.Name,
} }
} }

View File

@@ -21,7 +21,9 @@ func (this *CleanAction) Init() {
this.Nav("", "", "clean") this.Nav("", "", "clean")
} }
func (this *CleanAction) RunGet(params struct{}) { func (this *CleanAction) RunGet(params struct {
CachePolicyId int64
}) {
// 默认的集群ID // 默认的集群ID
cookie, err := this.Request.Cookie("cache_cluster_id") cookie, err := this.Request.Cookie("cache_cluster_id")
if cookie != nil && err == nil { if cookie != nil && err == nil {
@@ -29,13 +31,13 @@ func (this *CleanAction) RunGet(params struct{}) {
} }
// 集群列表 // 集群列表
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -23,7 +23,9 @@ func (this *PreheatAction) Init() {
this.Nav("", "", "preheat") this.Nav("", "", "preheat")
} }
func (this *PreheatAction) RunGet(params struct{}) { func (this *PreheatAction) RunGet(params struct {
CachePolicyId int64
}) {
// 默认的集群ID // 默认的集群ID
cookie, err := this.Request.Cookie("cache_cluster_id") cookie, err := this.Request.Cookie("cache_cluster_id")
if cookie != nil && err == nil { if cookie != nil && err == nil {
@@ -31,13 +33,13 @@ func (this *PreheatAction) RunGet(params struct{}) {
} }
// 集群列表 // 集群列表
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -23,7 +23,9 @@ func (this *PurgeAction) Init() {
this.Nav("", "", "purge") this.Nav("", "", "purge")
} }
func (this *PurgeAction) RunGet(params struct{}) { func (this *PurgeAction) RunGet(params struct {
CachePolicyId int64
}) {
// 默认的集群ID // 默认的集群ID
cookie, err := this.Request.Cookie("cache_cluster_id") cookie, err := this.Request.Cookie("cache_cluster_id")
if cookie != nil && err == nil { if cookie != nil && err == nil {
@@ -31,13 +33,13 @@ func (this *PurgeAction) RunGet(params struct{}) {
} }
// 集群列表 // 集群列表
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -21,7 +21,9 @@ func (this *StatAction) Init() {
this.Nav("", "", "stat") this.Nav("", "", "stat")
} }
func (this *StatAction) RunGet(params struct{}) { func (this *StatAction) RunGet(params struct {
CachePolicyId int64
}) {
// 默认的集群ID // 默认的集群ID
cookie, err := this.Request.Cookie("cache_cluster_id") cookie, err := this.Request.Cookie("cache_cluster_id")
if cookie != nil && err == nil { if cookie != nil && err == nil {
@@ -29,13 +31,13 @@ func (this *StatAction) RunGet(params struct{}) {
} }
// 集群列表 // 集群列表
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -15,7 +15,9 @@ func (this *TestAction) Init() {
this.Nav("", "", "test") this.Nav("", "", "test")
} }
func (this *TestAction) RunGet(params struct{}) { func (this *TestAction) RunGet(params struct {
CachePolicyId int64
}) {
// 默认的集群ID // 默认的集群ID
cookie, err := this.Request.Cookie("cache_cluster_id") cookie, err := this.Request.Cookie("cache_cluster_id")
if cookie != nil && err == nil { if cookie != nil && err == nil {
@@ -23,13 +25,13 @@ func (this *TestAction) RunGet(params struct{}) {
} }
// 集群列表 // 集群列表
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters { for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -30,7 +30,7 @@ func (this *CreateAction) RunGet(params struct{}) {
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range resp.Clusters { for _, cluster := range resp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,

View File

@@ -151,8 +151,8 @@ func (this *IndexAction) RunGet(params struct {
"isOn": server.IsOn, "isOn": server.IsOn,
"name": server.Name, "name": server.Name,
"cluster": maps.Map{ "cluster": maps.Map{
"id": server.Cluster.Id, "id": server.NodeCluster.Id,
"name": server.Cluster.Name, "name": server.NodeCluster.Name,
}, },
"ports": portMaps, "ports": portMaps,
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"), "serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),

View File

@@ -33,7 +33,7 @@ func (this *IndexAction) RunGet(params struct {
return return
} }
clusterMaps := []maps.Map{} clusterMaps := []maps.Map{}
for _, cluster := range resp.Clusters { for _, cluster := range resp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{ clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id, "id": cluster.Id,
"name": cluster.Name, "name": cluster.Name,
@@ -54,8 +54,8 @@ func (this *IndexAction) RunGet(params struct {
} }
clusterId := int64(0) clusterId := int64(0)
if server.Cluster != nil { if server.NodeCluster != nil {
clusterId = server.Cluster.Id clusterId = server.NodeCluster.Id
} }
// 分组 // 分组

View File

@@ -35,10 +35,10 @@ func (this *IndexAction) RunGet(params struct {
userMaps := []maps.Map{} userMaps := []maps.Map{}
for _, user := range usersResp.Users { for _, user := range usersResp.Users {
var clusterMap maps.Map = nil var clusterMap maps.Map = nil
if user.Cluster != nil { if user.NodeCluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": user.Cluster.Id, "id": user.NodeCluster.Id,
"name": user.Cluster.Name, "name": user.NodeCluster.Name,
} }
} }
userMaps = append(userMaps, maps.Map{ userMaps = append(userMaps, maps.Map{

View File

@@ -48,8 +48,8 @@ func (this *UpdateAction) RunGet(params struct {
} }
this.Data["clusterId"] = 0 this.Data["clusterId"] = 0
if user.Cluster != nil { if user.NodeCluster != nil {
this.Data["clusterId"] = user.Cluster.Id this.Data["clusterId"] = user.NodeCluster.Id
} }
this.Show() this.Show()

View File

@@ -36,10 +36,10 @@ func (this *UserAction) RunGet(params struct {
} }
var clusterMap maps.Map = nil var clusterMap maps.Map = nil
if user.Cluster != nil { if user.NodeCluster != nil {
clusterMap = maps.Map{ clusterMap = maps.Map{
"id": user.Cluster.Id, "id": user.NodeCluster.Id,
"name": user.Cluster.Name, "name": user.NodeCluster.Name,
} }
} }

View File

@@ -51,10 +51,10 @@ func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicyWithServerId(ctx conte
if server == nil { if server == nil {
return nil, nil return nil, nil
} }
if server.Cluster == nil { if server.NodeCluster == nil {
return nil, nil return nil, nil
} }
clusterId := server.Cluster.Id clusterId := server.NodeCluster.Id
cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId) cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -172,10 +172,10 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicyWithServerId(ctx
if server == nil { if server == nil {
return nil, nil return nil, nil
} }
if server.Cluster == nil { if server.NodeCluster == nil {
return nil, nil return nil, nil
} }
clusterId := server.Cluster.Id clusterId := server.NodeCluster.Id
cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId) cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -17,5 +17,5 @@ func (this *NodeClusterDAO) FindEnabledNodeCluster(ctx context.Context, clusterI
if err != nil { if err != nil {
return nil, err return nil, err
} }
return clusterResp.Cluster, nil return clusterResp.NodeCluster, nil
} }

View File

@@ -40,7 +40,7 @@ Vue.component("http-cache-policy-selector", {
template: `<div> template: `<div>
<div v-if="cachePolicy != null" class="ui label basic"> <div v-if="cachePolicy != null" class="ui label basic">
<input type="hidden" name="cachePolicyId" :value="cachePolicy.id"/> <input type="hidden" name="cachePolicyId" :value="cachePolicy.id"/>
{{cachePolicy.name}} &nbsp; <a :href="'/servers/components/cache/policy?cachePolicyId=' + cachePolicy.id" target="_blank"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()"><i class="icon remove small"></i></a> {{cachePolicy.name}} &nbsp; <a :href="'/servers/components/cache/policy?cachePolicyId=' + cachePolicy.id" target="_blank" title="修改"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()" title="删除"><i class="icon remove small"></i></a>
</div> </div>
<div v-if="cachePolicy == null"> <div v-if="cachePolicy == null">
<span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a> <span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a>

View File

@@ -40,7 +40,7 @@ Vue.component("http-firewall-policy-selector", {
template: `<div> template: `<div>
<div v-if="firewallPolicy != null" class="ui label basic"> <div v-if="firewallPolicy != null" class="ui label basic">
<input type="hidden" name="httpFirewallPolicyId" :value="firewallPolicy.id"/> <input type="hidden" name="httpFirewallPolicyId" :value="firewallPolicy.id"/>
{{firewallPolicy.name}} &nbsp; <a :href="'/servers/components/waf/policy?firewallPolicyId=' + firewallPolicy.id" target="_blank"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()"><i class="icon remove small"></i></a> {{firewallPolicy.name}} &nbsp; <a :href="'/servers/components/waf/policy?firewallPolicyId=' + firewallPolicy.id" target="_blank" title="修改"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()" title="删除"><i class="icon remove small"></i></a>
</div> </div>
<div v-if="firewallPolicy == null"> <div v-if="firewallPolicy == null">
<span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a> <span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a>