diff --git a/internal/web/actions/default/clusters/cluster/createBatch.go b/internal/web/actions/default/clusters/cluster/createBatch.go index 9839bd56..6055d325 100644 --- a/internal/web/actions/default/clusters/cluster/createBatch.go +++ b/internal/web/actions/default/clusters/cluster/createBatch.go @@ -44,6 +44,7 @@ func (this *CreateBatchAction) RunGet(params struct { func (this *CreateBatchAction) RunPost(params struct { ClusterId int64 GroupId int64 + RegionId int64 IpList string Must *actions.Must @@ -79,6 +80,7 @@ func (this *CreateBatchAction) RunPost(params struct { Name: ip, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, Login: nil, }) if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index e5a479eb..36341283 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -72,6 +72,7 @@ func (this *CreateNodeAction) RunPost(params struct { IpAddressesJSON []byte ClusterId int64 GroupId int64 + RegionId int64 GrantId int64 SshHost string SshPort int @@ -120,6 +121,7 @@ func (this *CreateNodeAction) RunPost(params struct { Name: params.Name, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, Login: loginInfo, DnsDomainId: params.DnsDomainId, DnsRoutes: dnsRouteCodes, diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index 2d4d8cee..f73918d9 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -25,11 +25,13 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ClusterId int64 GroupId int64 + RegionId int64 InstalledState int ActiveState int Keyword string }) { this.Data["groupId"] = params.GroupId + this.Data["regionId"] = params.RegionId this.Data["installState"] = params.InstalledState this.Data["activeState"] = params.ActiveState this.Data["keyword"] = params.Keyword @@ -37,6 +39,7 @@ func (this *IndexAction) RunGet(params struct { countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -54,6 +57,7 @@ func (this *IndexAction) RunGet(params struct { Size: page.Size, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -89,6 +93,7 @@ func (this *IndexAction) RunGet(params struct { }) } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -97,6 +102,15 @@ func (this *IndexAction) RunGet(params struct { } } + // 区域 + 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 { @@ -131,6 +145,7 @@ func (this *IndexAction) RunGet(params struct { "isSynced": isSynced, "ipAddresses": ipAddresses, "group": groupMap, + "region": regionMap, "dnsRouteNames": dnsRouteNames, }) } @@ -164,5 +179,20 @@ func (this *IndexAction) RunGet(params struct { } this.Data["groups"] = groupMaps + // 所有区域 + regionsResp, err := this.RPC().NodeRegionRPC().FindAllEnabledAndOnNodeRegions(this.AdminContext(), &pb.FindAllEnabledAndOnNodeRegionsRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + regionMaps := []maps.Map{} + for _, region := range regionsResp.NodeRegions { + regionMaps = append(regionMaps, maps.Map{ + "id": region.Id, + "name": region.Name, + }) + } + this.Data["regions"] = regionMaps + this.Show() } diff --git a/internal/web/actions/default/clusters/cluster/node/node.go b/internal/web/actions/default/clusters/cluster/node/node.go index 47710446..4f58ef93 100644 --- a/internal/web/actions/default/clusters/cluster/node/node.go +++ b/internal/web/actions/default/clusters/cluster/node/node.go @@ -137,6 +137,7 @@ func (this *NodeAction) RunGet(params struct { status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃 } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -145,6 +146,15 @@ func (this *NodeAction) RunGet(params struct { } } + // 区域 + var regionMap maps.Map = nil + if node.Region != nil { + regionMap = maps.Map{ + "id": node.Region.Id, + "name": node.Region.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -169,7 +179,8 @@ func (this *NodeAction) RunGet(params struct { "connectionCount": status.ConnectionCount, }, - "group": groupMap, + "group": groupMap, + "region": regionMap, } this.Show() diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index 16131274..9a7975a8 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -138,6 +138,7 @@ func (this *UpdateAction) RunGet(params struct { } } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -146,6 +147,15 @@ func (this *UpdateAction) RunGet(params struct { } } + // 区域 + var regionMap maps.Map = nil + if node.Region != nil { + regionMap = maps.Map{ + "id": node.Region.Id, + "name": node.Region.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -155,6 +165,7 @@ func (this *UpdateAction) RunGet(params struct { "maxCPU": node.MaxCPU, "isOn": node.IsOn, "group": groupMap, + "region": regionMap, } // 所有集群 @@ -182,6 +193,7 @@ func (this *UpdateAction) RunPost(params struct { LoginId int64 NodeId int64 GroupId int64 + RegionId int64 Name string IPAddressesJSON []byte `alias:"ipAddressesJSON"` ClusterId int64 @@ -237,6 +249,7 @@ func (this *UpdateAction) RunPost(params struct { _, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{ NodeId: params.NodeId, GroupId: params.GroupId, + RegionId: params.RegionId, Name: params.Name, ClusterId: params.ClusterId, Login: loginInfo, diff --git a/internal/web/actions/default/clusters/regions/createPopup.go b/internal/web/actions/default/clusters/regions/createPopup.go index 17402900..616eef76 100644 --- a/internal/web/actions/default/clusters/regions/createPopup.go +++ b/internal/web/actions/default/clusters/regions/createPopup.go @@ -4,6 +4,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { @@ -34,6 +35,11 @@ func (this *CreatePopupAction) RunPost(params struct { return } + this.Data["region"] = maps.Map{ + "id": createResp.NodeRegionId, + "name": params.Name, + } + // 日志 defer this.CreateLogInfo("创建节点区域 %d", createResp.NodeRegionId) diff --git a/internal/web/actions/default/clusters/regions/init.go b/internal/web/actions/default/clusters/regions/init.go index c0d9ae19..3408aad4 100644 --- a/internal/web/actions/default/clusters/regions/init.go +++ b/internal/web/actions/default/clusters/regions/init.go @@ -18,6 +18,7 @@ func init() { GetPost("/updatePopup", new(UpdatePopupAction)). Post("/delete", new(DeleteAction)). Post("/sort", new(SortAction)). + GetPost("/selectPopup", new(SelectPopupAction)). EndAll() }) } diff --git a/internal/web/actions/default/clusters/regions/selectPopup.go b/internal/web/actions/default/clusters/regions/selectPopup.go new file mode 100644 index 00000000..6838d3e8 --- /dev/null +++ b/internal/web/actions/default/clusters/regions/selectPopup.go @@ -0,0 +1,60 @@ +package regions + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" +) + +type SelectPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectPopupAction) RunGet(params struct{}) { + regionsResp, err := this.RPC().NodeRegionRPC().FindAllEnabledAndOnNodeRegions(this.AdminContext(), &pb.FindAllEnabledAndOnNodeRegionsRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + + regionMaps := []maps.Map{} + for _, region := range regionsResp.NodeRegions { + regionMaps = append(regionMaps, maps.Map{ + "id": region.Id, + "name": region.Name, + }) + } + this.Data["regions"] = regionMaps + + this.Show() +} + +func (this *SelectPopupAction) RunPost(params struct { + RegionId int64 + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + regionResp, err := this.RPC().NodeRegionRPC().FindEnabledNodeRegion(this.AdminContext(), &pb.FindEnabledNodeRegionRequest{NodeRegionId: params.RegionId}) + if err != nil { + this.ErrorPage(err) + return + } + region := regionResp.NodeRegion + if region == nil { + this.NotFound("nodeRegion", params.RegionId) + return + } + + this.Data["region"] = maps.Map{ + "id": region.Id, + "name": region.Name, + } + + this.Success() +} diff --git a/web/public/js/components/node/node-group-selector.js b/web/public/js/components/node/node-group-selector.js index 82473834..7fe3d1a3 100644 --- a/web/public/js/components/node/node-group-selector.js +++ b/web/public/js/components/node/node-group-selector.js @@ -27,7 +27,7 @@ Vue.component("node-group-selector", { } }, template: `
每行一个节点IP。
+可用线路是根据集群设置的域名获取的,注意DNS服务商可能对这些线路有所限制。