mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-29 06:16:34 +08:00
节点IP地址可以设置专属集群
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -20,8 +21,18 @@ func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
SupportThresholds bool
|
||||
}) {
|
||||
// 专属集群
|
||||
clusterMaps, err := ipaddressutils.FindNodeClusterMapsWithNodeId(this.Parent(), params.NodeId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
// 阈值
|
||||
this.Data["supportThresholds"] = params.SupportThresholds
|
||||
|
||||
this.Show()
|
||||
@@ -33,6 +44,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
IsUp bool
|
||||
ThresholdsJSON []byte
|
||||
ClusterIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
@@ -57,6 +69,14 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
_ = json.Unmarshal(params.ThresholdsJSON, &thresholds)
|
||||
}
|
||||
|
||||
// 专属集群
|
||||
// 目前只考虑CDN边缘集群
|
||||
clusterMaps, err := ipaddressutils.FindNodeClusterMaps(this.Parent(), params.ClusterIds)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["ipAddress"] = maps.Map{
|
||||
"name": params.Name,
|
||||
"canAccess": params.CanAccess,
|
||||
@@ -65,6 +85,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
"isOn": true,
|
||||
"isUp": params.IsUp,
|
||||
"thresholds": thresholds,
|
||||
"clusters": clusterMaps,
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -11,14 +11,28 @@ import (
|
||||
|
||||
// UpdateNodeIPAddresses 保存一组IP地址
|
||||
func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, role nodeconfigs.NodeRole, ipAddressesJSON []byte) error {
|
||||
addresses := []maps.Map{}
|
||||
var addresses = []maps.Map{}
|
||||
err := json.Unmarshal(ipAddressesJSON, &addresses)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addresses {
|
||||
var resultAddrIds = []int64{}
|
||||
addrId := addr.GetInt64("id")
|
||||
var addrId = addr.GetInt64("id")
|
||||
|
||||
// 专属集群
|
||||
var addrClusterIds = []int64{}
|
||||
var addrClusters = addr.GetSlice("clusters")
|
||||
if len(addrClusters) > 0 {
|
||||
for _, addrCluster := range addrClusters {
|
||||
var m = maps.NewMap(addrCluster)
|
||||
var clusterId = m.GetInt64("id")
|
||||
if clusterId > 0 {
|
||||
addrClusterIds = append(addrClusterIds, clusterId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if addrId > 0 {
|
||||
resultAddrIds = append(resultAddrIds, addrId)
|
||||
|
||||
@@ -36,6 +50,7 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
IsOn: isOn,
|
||||
IsUp: addr.GetBool("isUp"),
|
||||
ClusterIds: addrClusterIds,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -47,12 +62,13 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
||||
if len(result) == 1 {
|
||||
// 单个创建
|
||||
createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||
NodeId: nodeId,
|
||||
Role: role,
|
||||
Name: addr.GetString("name"),
|
||||
Ip: result[0],
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
IsUp: addr.GetBool("isUp"),
|
||||
NodeId: nodeId,
|
||||
Role: role,
|
||||
Name: addr.GetString("name"),
|
||||
Ip: result[0],
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
IsUp: addr.GetBool("isUp"),
|
||||
NodeClusterIds: addrClusterIds,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -62,13 +78,14 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
||||
} else if len(result) > 1 {
|
||||
// 批量创建
|
||||
createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(parentAction.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
||||
NodeId: nodeId,
|
||||
Role: role,
|
||||
Name: addr.GetString("name"),
|
||||
IpList: result,
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
IsUp: addr.GetBool("isUp"),
|
||||
GroupValue: ipStrings,
|
||||
NodeId: nodeId,
|
||||
Role: role,
|
||||
Name: addr.GetString("name"),
|
||||
IpList: result,
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
IsUp: addr.GetBool("isUp"),
|
||||
GroupValue: ipStrings,
|
||||
NodeClusterIds: addrClusterIds,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -140,3 +157,53 @@ func InitNodeIPAddressThresholds(parentAction *actionutils.ParentAction, addrId
|
||||
}
|
||||
return thresholds, nil
|
||||
}
|
||||
|
||||
// FindNodeClusterMapsWithNodeId 根据节点读取集群信息
|
||||
func FindNodeClusterMapsWithNodeId(parentAction *actionutils.ParentAction, nodeId int64) ([]maps.Map, error) {
|
||||
var clusterMaps = []maps.Map{}
|
||||
if nodeId > 0 { // CDN边缘节点
|
||||
nodeResp, err := parentAction.RPC().NodeRPC().FindEnabledNode(parentAction.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: nodeId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var node = nodeResp.Node
|
||||
if node != nil {
|
||||
var clusters = []*pb.NodeCluster{}
|
||||
if node.NodeCluster != nil {
|
||||
clusters = append(clusters, nodeResp.Node.NodeCluster)
|
||||
}
|
||||
if len(node.SecondaryNodeClusters) > 0 {
|
||||
clusters = append(clusters, node.SecondaryNodeClusters...)
|
||||
}
|
||||
for _, cluster := range clusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
"isChecked": false,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return clusterMaps, nil
|
||||
}
|
||||
|
||||
// FindNodeClusterMaps 根据一组集群ID读取集群信息
|
||||
func FindNodeClusterMaps(parentAction *actionutils.ParentAction, clusterIds []int64) ([]maps.Map, error) {
|
||||
var clusterMaps = []maps.Map{}
|
||||
if len(clusterIds) > 0 {
|
||||
for _, clusterId := range clusterIds {
|
||||
clusterResp, err := parentAction.RPC().NodeClusterRPC().FindEnabledNodeCluster(parentAction.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cluster = clusterResp.NodeCluster
|
||||
if cluster != nil {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return clusterMaps, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
@@ -21,9 +22,18 @@ func (this *UpdatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
AddressId int64
|
||||
SupportThresholds bool
|
||||
}) {
|
||||
// 专属集群
|
||||
clusterMaps, err := ipaddressutils.FindNodeClusterMapsWithNodeId(this.Parent(), params.NodeId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
this.Data["supportThresholds"] = params.SupportThresholds
|
||||
|
||||
this.Show()
|
||||
@@ -37,6 +47,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
IsOn bool
|
||||
IsUp bool
|
||||
ThresholdsJSON []byte
|
||||
ClusterIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
@@ -81,6 +92,14 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
_ = json.Unmarshal(params.ThresholdsJSON, &thresholds)
|
||||
}
|
||||
|
||||
// 专属集群
|
||||
// 目前只考虑CDN边缘集群
|
||||
clusterMaps, err := ipaddressutils.FindNodeClusterMaps(this.Parent(), params.ClusterIds)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["ipAddress"] = maps.Map{
|
||||
"name": params.Name,
|
||||
"ip": params.IP,
|
||||
@@ -89,6 +108,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
"isOn": params.IsOn,
|
||||
"isUp": isUp,
|
||||
"thresholds": thresholds,
|
||||
"clusters": clusterMaps,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
|
||||
Reference in New Issue
Block a user