diff --git a/internal/web/actions/default/clusters/cluster/createBatch.go b/internal/web/actions/default/clusters/cluster/createBatch.go index 28b69b8b..4ba6ef0c 100644 --- a/internal/web/actions/default/clusters/cluster/createBatch.go +++ b/internal/web/actions/default/clusters/cluster/createBatch.go @@ -42,6 +42,7 @@ func (this *CreateBatchAction) RunGet(params struct { func (this *CreateBatchAction) RunPost(params struct { ClusterId int64 + GroupId int64 IpList string Must *actions.Must @@ -76,6 +77,7 @@ func (this *CreateBatchAction) RunPost(params struct { resp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{ Name: ip, ClusterId: params.ClusterId, + GroupId: params.GroupId, 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 d83868db..8b1e6b4e 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -43,6 +43,7 @@ func (this *CreateNodeAction) RunPost(params struct { Name string IpAddressesJSON []byte ClusterId int64 + GroupId int64 GrantId int64 SshHost string SshPort int @@ -78,6 +79,7 @@ func (this *CreateNodeAction) RunPost(params struct { createResp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{ Name: params.Name, ClusterId: params.ClusterId, + GroupId: params.GroupId, Login: loginInfo, }) if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/groups/createPopup.go b/internal/web/actions/default/clusters/cluster/groups/createPopup.go index bb5bf73e..a8b60989 100644 --- a/internal/web/actions/default/clusters/cluster/groups/createPopup.go +++ b/internal/web/actions/default/clusters/cluster/groups/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 { @@ -31,7 +32,7 @@ func (this *CreatePopupAction) RunPost(params struct { params.Must. Field("name", params.Name). Require("请输入分组名称") - _, err := this.RPC().NodeGroupRPC().CreateNodeGroup(this.AdminContext(), &pb.CreateNodeGroupRequest{ + createResp, err := this.RPC().NodeGroupRPC().CreateNodeGroup(this.AdminContext(), &pb.CreateNodeGroupRequest{ ClusterId: params.ClusterId, Name: params.Name, }) @@ -40,5 +41,10 @@ func (this *CreatePopupAction) RunPost(params struct { return } + this.Data["group"] = maps.Map{ + "id": createResp.GroupId, + "name": params.Name, + } + this.Success() } diff --git a/internal/web/actions/default/clusters/cluster/groups/options.go b/internal/web/actions/default/clusters/cluster/groups/options.go new file mode 100644 index 00000000..c8eb2b01 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/groups/options.go @@ -0,0 +1,31 @@ +package groups + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" +) + +type OptionsAction struct { + actionutils.ParentAction +} + +func (this *OptionsAction) RunPost(params struct { + ClusterId int64 +}) { + groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ClusterId: params.ClusterId}) + if err != nil { + this.ErrorPage(err) + } + + groupMaps := []maps.Map{} + for _, group := range groupsResp.Groups { + groupMaps = append(groupMaps, maps.Map{ + "id": group.Id, + "name": group.Name, + }) + } + this.Data["groups"] = groupMaps + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/groups/selectPopup.go b/internal/web/actions/default/clusters/cluster/groups/selectPopup.go new file mode 100644 index 00000000..967ef772 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/groups/selectPopup.go @@ -0,0 +1,64 @@ +package groups + +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 { + ClusterId int64 +}) { + groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ClusterId: params.ClusterId}) + if err != nil { + this.ErrorPage(err) + } + + groupMaps := []maps.Map{} + for _, group := range groupsResp.Groups { + groupMaps = append(groupMaps, maps.Map{ + "id": group.Id, + "name": group.Name, + }) + } + this.Data["groups"] = groupMaps + + this.Show() +} + +func (this *SelectPopupAction) RunPost(params struct { + GroupId int64 + + Must *actions.Must +}) { + if params.GroupId <= 0 { + this.Fail("请选择要使用的分组") + } + + groupResp, err := this.RPC().NodeGroupRPC().FindEnabledNodeGroup(this.AdminContext(), &pb.FindEnabledNodeGroupRequest{GroupId: params.GroupId}) + if err != nil { + this.ErrorPage(err) + return + } + group := groupResp.Group + if group == nil { + this.NotFound("nodeGroup", params.GroupId) + return + } + + this.Data["group"] = maps.Map{ + "id": group.Id, + "name": group.Name, + } + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index 9a0b2f3b..43265536 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -23,16 +23,19 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ClusterId int64 + GroupId int64 InstalledState int ActiveState int Keyword string }) { + this.Data["groupId"] = params.GroupId this.Data["installState"] = params.InstalledState this.Data["activeState"] = params.ActiveState this.Data["keyword"] = params.Keyword countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ ClusterId: params.ClusterId, + GroupId: params.GroupId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -49,6 +52,7 @@ func (this *IndexAction) RunGet(params struct { Offset: page.Offset, Size: page.Size, ClusterId: params.ClusterId, + GroupId: params.GroupId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -84,6 +88,14 @@ func (this *IndexAction) RunGet(params struct { }) } + var groupMap maps.Map = nil + if node.Group != nil { + groupMap = maps.Map{ + "id": node.Group.Id, + "name": node.Group.Name, + } + } + nodeMaps = append(nodeMaps, maps.Map{ "id": node.Id, "name": node.Name, @@ -110,9 +122,35 @@ func (this *IndexAction) RunGet(params struct { }, "isSynced": isSynced, "ipAddresses": ipAddresses, + "group": groupMap, }) } this.Data["nodes"] = nodeMaps + // 所有分组 + groupMaps := []maps.Map{} + groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ + ClusterId: params.ClusterId, + }) + if err != nil { + this.ErrorPage(err) + return + } + for _, group := range groupsResp.Groups { + countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithGroupId(this.AdminContext(), &pb.CountAllEnabledNodesWithGroupIdRequest{GroupId: group.Id}) + if err != nil { + this.ErrorPage(err) + return + } + countNodes := countResp.Count + + groupMaps = append(groupMaps, maps.Map{ + "id": group.Id, + "name": group.Name, + "countNodes": countNodes, + }) + } + this.Data["groups"] = groupMaps + this.Show() } diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 7465317e..ce1af33e 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -42,6 +42,8 @@ func init() { GetPost("/groups/updatePopup", new(groups.UpdatePopupAction)). Post("/groups/delete", new(groups.DeleteAction)). Post("/groups/sort", new(groups.SortAction)). + Post("/groups/options", new(groups.OptionsAction)). + GetPost("/groups/selectPopup", new(groups.SelectPopupAction)). EndAll() }) diff --git a/internal/web/actions/default/clusters/cluster/node/node.go b/internal/web/actions/default/clusters/cluster/node/node.go index 89b619f7..fb476e84 100644 --- a/internal/web/actions/default/clusters/cluster/node/node.go +++ b/internal/web/actions/default/clusters/cluster/node/node.go @@ -120,6 +120,14 @@ 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{ + "id": node.Group.Id, + "name": node.Group.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -142,6 +150,8 @@ func (this *NodeAction) RunGet(params struct { "memUsage": status.MemoryUsage, "memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100), }, + + "group": groupMap, } 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 7c47210f..3cce88c7 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -98,6 +98,14 @@ func (this *UpdateAction) RunGet(params struct { } } + var groupMap maps.Map = nil + if node.Group != nil { + groupMap = maps.Map{ + "id": node.Group.Id, + "name": node.Group.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -106,6 +114,7 @@ func (this *UpdateAction) RunGet(params struct { "login": loginMap, "maxCPU": node.MaxCPU, "isOn": node.IsOn, + "group": groupMap, } // 所有集群 @@ -132,6 +141,7 @@ func (this *UpdateAction) RunGet(params struct { func (this *UpdateAction) RunPost(params struct { LoginId int64 NodeId int64 + GroupId int64 Name string IPAddressesJSON []byte `alias:"ipAddressesJSON"` ClusterId int64 @@ -171,6 +181,7 @@ func (this *UpdateAction) RunPost(params struct { // 保存 _, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{ NodeId: params.NodeId, + GroupId: params.GroupId, Name: params.Name, ClusterId: params.ClusterId, Login: loginInfo, diff --git a/web/public/js/components/node/node-group-selector.js b/web/public/js/components/node/node-group-selector.js new file mode 100644 index 00000000..9e36caf4 --- /dev/null +++ b/web/public/js/components/node/node-group-selector.js @@ -0,0 +1,50 @@ +Vue.component("node-group-selector", { + props: ["v-cluster-id", "v-group"], + mounted: function () { + let that = this + Tea.action("/clusters/cluster/groups/options") + .post() + .params({ + clusterId: this.vClusterId + }) + .success(function (resp) { + + }) + }, + data: function () { + return { + groups: [], + selectedGroup: this.vGroup, + } + }, + methods: { + selectGroup: function () { + let that = this + teaweb.popup("/clusters/cluster/groups/selectPopup?clusterId=" + this.vClusterId, { + callback: function (resp) { + that.selectedGroup = resp.data.group + } + }) + }, + addGroup: function () { + let that = this + teaweb.popup("/clusters/cluster/groups/createPopup?clusterId=" + this.vClusterId, { + callback: function (resp) { + that.selectedGroup = resp.data.group + } + }) + }, + removeGroup: function () { + this.selectedGroup = null + } + }, + template: `
+
+ + {{selectedGroup.name}}   +
+
+ [选择分组]   [添加分组] +
+
` +}) \ No newline at end of file diff --git a/web/views/@default/@layout.css b/web/views/@default/@layout.css index 5cea6994..fb4a0e6a 100644 --- a/web/views/@default/@layout.css +++ b/web/views/@default/@layout.css @@ -61,7 +61,7 @@ right: 0; left: 18em; padding-right: 2em; - padding-bottom: 1em; + padding-bottom: 2em; overflow-y: auto; } .right-box.tiny { diff --git a/web/views/@default/@left_menu.less b/web/views/@default/@left_menu.less index 173706b6..4374feb9 100644 --- a/web/views/@default/@left_menu.less +++ b/web/views/@default/@left_menu.less @@ -83,7 +83,7 @@ right: 0; left: 18em; padding-right: 2em; - padding-bottom: 1em; + padding-bottom: 2em; overflow-y: auto; } diff --git a/web/views/@default/clusters/cluster/createBatch.html b/web/views/@default/clusters/cluster/createBatch.html index 90f7339b..35afb969 100644 --- a/web/views/@default/clusters/cluster/createBatch.html +++ b/web/views/@default/clusters/cluster/createBatch.html @@ -14,6 +14,12 @@

每行一个节点IP。

+ + 所属分组 + + + + diff --git a/web/views/@default/clusters/cluster/createNode.html b/web/views/@default/clusters/cluster/createNode.html index 821826d4..31eb95d6 100644 --- a/web/views/@default/clusters/cluster/createNode.html +++ b/web/views/@default/clusters/cluster/createNode.html @@ -18,6 +18,12 @@ + + 所属分组 + + + + diff --git a/web/views/@default/clusters/cluster/groups/createPopup.html b/web/views/@default/clusters/cluster/groups/createPopup.html index 64a2c5c7..82bec521 100644 --- a/web/views/@default/clusters/cluster/groups/createPopup.html +++ b/web/views/@default/clusters/cluster/groups/createPopup.html @@ -5,7 +5,7 @@ - + diff --git a/web/views/@default/clusters/cluster/groups/selectPopup.html b/web/views/@default/clusters/cluster/groups/selectPopup.html new file mode 100644 index 00000000..6c3b5856 --- /dev/null +++ b/web/views/@default/clusters/cluster/groups/selectPopup.html @@ -0,0 +1,22 @@ +{$layout "layout_popup"} + +

选择分组

+ + + +
分组名称 *分组名称 *
+ + + + +
选择分组 +
+ {{group.name}} +

点击可已选中要使用的分组。

+
+
+

暂时还没有可以使用的分组。

+
+
+ 确定 + \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/groups/selectPopup.js b/web/views/@default/clusters/cluster/groups/selectPopup.js new file mode 100644 index 00000000..9da529b0 --- /dev/null +++ b/web/views/@default/clusters/cluster/groups/selectPopup.js @@ -0,0 +1,8 @@ +Tea.context(function () { + this.success = NotifyPopup + this.groupId = 0 + + this.selectGroup = function (group) { + this.groupId = group.id + } +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/groups/updatePopup.html b/web/views/@default/clusters/cluster/groups/updatePopup.html index 8286cbb4..2169f3d8 100644 --- a/web/views/@default/clusters/cluster/groups/updatePopup.html +++ b/web/views/@default/clusters/cluster/groups/updatePopup.html @@ -5,7 +5,7 @@ - + diff --git a/web/views/@default/clusters/cluster/index.html b/web/views/@default/clusters/cluster/index.html index d21bdb82..a7905434 100644 --- a/web/views/@default/clusters/cluster/index.html +++ b/web/views/@default/clusters/cluster/index.html @@ -5,6 +5,15 @@
+
+ 所属分组: +
+
+ +
安装状态:
@@ -41,8 +50,8 @@
- - + +
分组名称 *分组名称 *
ID 节点名称主机名IP所属分组IP CPU 内存