2020-10-25 21:27:28 +08:00
|
|
|
package clusterutils
|
2020-09-06 16:19:34 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
2020-12-17 17:35:38 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
2020-09-06 16:19:34 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-12-23 09:52:31 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
2020-10-02 17:22:24 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
2020-09-06 16:19:34 +08:00
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"github.com/iwind/TeaGo/logs"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
2020-11-15 16:28:25 +08:00
|
|
|
// 单个集群的帮助
|
2020-09-06 16:19:34 +08:00
|
|
|
type ClusterHelper struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewClusterHelper() *ClusterHelper {
|
|
|
|
|
return &ClusterHelper{}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 17:35:38 +08:00
|
|
|
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
|
|
|
|
action := actionPtr.Object()
|
2020-09-06 16:19:34 +08:00
|
|
|
if action.Request.Method != http.MethodGet {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action.Data["teaMenu"] = "clusters"
|
|
|
|
|
|
|
|
|
|
selectedTabbar := action.Data.GetString("mainTab")
|
|
|
|
|
clusterId := action.ParamInt64("clusterId")
|
|
|
|
|
clusterIdString := strconv.FormatInt(clusterId, 10)
|
|
|
|
|
action.Data["clusterId"] = clusterId
|
|
|
|
|
|
2020-10-26 21:14:26 +08:00
|
|
|
if clusterId > 0 {
|
2020-12-23 09:52:31 +08:00
|
|
|
cluster, err := dao.SharedNodeClusterDAO.FindEnabledNodeCluster(actionPtr.(rpc.ContextInterface).AdminContext(), clusterId)
|
2020-10-26 21:14:26 +08:00
|
|
|
if err != nil {
|
|
|
|
|
logs.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if cluster == nil {
|
|
|
|
|
action.WriteString("can not find cluster")
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-09-06 16:19:34 +08:00
|
|
|
|
2020-10-26 21:14:26 +08:00
|
|
|
tabbar := actionutils.NewTabbar()
|
|
|
|
|
tabbar.Add("集群列表", "", "/clusters", "", false)
|
2020-11-15 21:17:52 +08:00
|
|
|
tabbar.Add("集群节点", "", "/clusters/cluster?clusterId="+clusterIdString, "server", selectedTabbar == "node")
|
|
|
|
|
tabbar.Add("集群设置", "", "/clusters/cluster/settings?clusterId="+clusterIdString, "setting", selectedTabbar == "setting")
|
|
|
|
|
tabbar.Add("删除集群", "", "/clusters/cluster/delete?clusterId="+clusterIdString, "trash", selectedTabbar == "delete")
|
2020-10-25 19:45:42 +08:00
|
|
|
|
2020-10-26 21:14:26 +08:00
|
|
|
{
|
|
|
|
|
m := tabbar.Add("当前集群:"+cluster.Name, "", "/clusters/cluster?clusterId="+clusterIdString, "", false)
|
|
|
|
|
m["right"] = true
|
|
|
|
|
}
|
|
|
|
|
actionutils.SetTabbar(action, tabbar)
|
2020-09-06 16:19:34 +08:00
|
|
|
|
2020-10-26 21:14:26 +08:00
|
|
|
// 左侧菜单
|
|
|
|
|
secondMenuItem := action.Data.GetString("secondMenuItem")
|
|
|
|
|
switch selectedTabbar {
|
|
|
|
|
case "setting":
|
2020-12-17 17:35:38 +08:00
|
|
|
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
2020-10-26 21:14:26 +08:00
|
|
|
}
|
2020-09-06 16:19:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置菜单
|
2020-12-17 17:35:38 +08:00
|
|
|
func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedItem string) (items []maps.Map) {
|
|
|
|
|
clusterId := numberutils.FormatInt64(cluster.Id)
|
2020-09-06 16:19:34 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "基础设置",
|
|
|
|
|
"url": "/clusters/cluster/settings?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "basic",
|
|
|
|
|
})
|
2020-12-17 15:50:44 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "缓存设置",
|
|
|
|
|
"url": "/clusters/cluster/settings/cache?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "cache",
|
2020-12-17 17:35:38 +08:00
|
|
|
"isOn": cluster.HttpCachePolicyId > 0,
|
2020-12-17 15:50:44 +08:00
|
|
|
})
|
|
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "WAF设置",
|
|
|
|
|
"url": "/clusters/cluster/settings/waf?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "waf",
|
2020-12-17 17:35:38 +08:00
|
|
|
"isOn": cluster.HttpFirewallPolicyId > 0,
|
2020-12-17 15:50:44 +08:00
|
|
|
})
|
2020-10-17 21:15:22 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "健康检查",
|
|
|
|
|
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "health",
|
|
|
|
|
})
|
2020-11-15 16:28:25 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "DNS设置",
|
|
|
|
|
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "dns",
|
|
|
|
|
})
|
2021-01-11 18:15:53 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "系统服务",
|
|
|
|
|
"url": "/clusters/cluster/settings/services?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "service",
|
|
|
|
|
})
|
2020-12-02 14:25:14 +08:00
|
|
|
items = append(items, maps.Map{
|
|
|
|
|
"name": "TOA设置",
|
|
|
|
|
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterId,
|
|
|
|
|
"isActive": selectedItem == "toa",
|
|
|
|
|
})
|
2020-09-06 16:19:34 +08:00
|
|
|
return
|
|
|
|
|
}
|