From 282900d611e593a4ae964c7c3ee62048e59f99dd Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 17 Oct 2020 11:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=E5=9C=A8?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=90=AF=E5=8A=A8=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/default/clusters/cluster/init.go | 1 + .../default/clusters/cluster/installNodes.go | 72 +++++++++++++++++++ .../js/components/common/download-link.js | 2 +- .../@default/clusters/cluster/@menu.html | 2 +- .../@default/clusters/cluster/index.html | 4 +- .../clusters/cluster/installNodes.html | 20 ++++++ 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 internal/web/actions/default/clusters/cluster/installNodes.go create mode 100644 web/views/@default/clusters/cluster/installNodes.html diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 114ec276..bf3646d2 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -14,6 +14,7 @@ func init() { Helper(clusters.NewClusterHelper()). Prefix("/clusters/cluster"). Get("", new(IndexAction)). + GetPost("/installNodes", new(InstallNodesAction)). // 节点相关 Get("/node", new(node.NodeAction)). diff --git a/internal/web/actions/default/clusters/cluster/installNodes.go b/internal/web/actions/default/clusters/cluster/installNodes.go new file mode 100644 index 00000000..eb0f9642 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/installNodes.go @@ -0,0 +1,72 @@ +package cluster + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" + "strings" +) + +type InstallNodesAction struct { + actionutils.ParentAction +} + +func (this *InstallNodesAction) Init() { + this.Nav("", "node", "install") + this.SecondMenu("nodes") +} + +func (this *InstallNodesAction) RunGet(params struct { + ClusterId int64 +}) { + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId}) + if err != nil { + this.ErrorPage(err) + return + } + if clusterResp.Cluster == nil { + this.NotFound("nodeCluster", params.ClusterId) + return + } + + cluster := clusterResp.Cluster + + clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{ClusterId: params.ClusterId}) + if err != nil { + this.ErrorPage(err) + return + } + if err != nil { + this.ErrorPage(err) + return + } + apiNodeAddrs := []string{} + if clusterAPINodesResp.UseAllAPINodes { + apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + for _, apiNode := range apiNodesResp.Nodes { + if !apiNode.IsOn { + continue + } + apiNodeAddrs = append(apiNodeAddrs, apiNode.AccessAddrs...) + } + } else { + for _, apiNode := range clusterAPINodesResp.ApiNodes { + if !apiNode.IsOn { + continue + } + apiNodeAddrs = append(apiNodeAddrs, apiNode.AccessAddrs...) + } + } + + this.Data["cluster"] = maps.Map{ + "uniqueId": cluster.UniqueId, + "secret": cluster.Secret, + "endpoints": "\"" + strings.Join(apiNodeAddrs, "\", \"") + "\"", + } + + this.Show() +} diff --git a/web/public/js/components/common/download-link.js b/web/public/js/components/common/download-link.js index cc79df0e..03f15721 100644 --- a/web/public/js/components/common/download-link.js +++ b/web/public/js/components/common/download-link.js @@ -33,5 +33,5 @@ Vue.component("download-link", { }) } }, - template: ``, + template: ``, }) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/@menu.html b/web/views/@default/clusters/cluster/@menu.html index c4899af5..a9e8ed1f 100644 --- a/web/views/@default/clusters/cluster/@menu.html +++ b/web/views/@default/clusters/cluster/@menu.html @@ -2,5 +2,5 @@ 节点列表 添加节点 - + 安装节点 \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/index.html b/web/views/@default/clusters/cluster/index.html index 92350535..73eda244 100644 --- a/web/views/@default/clusters/cluster/index.html +++ b/web/views/@default/clusters/cluster/index.html @@ -60,7 +60,9 @@ -
-
{{addr.ip}} ({{addr.name}})
+
+
{{addr.ip}} ({{addr.name}})
+
diff --git a/web/views/@default/clusters/cluster/installNodes.html b/web/views/@default/clusters/cluster/installNodes.html new file mode 100644 index 00000000..ba06d008 --- /dev/null +++ b/web/views/@default/clusters/cluster/installNodes.html @@ -0,0 +1,20 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} +

可以通过节点安装包中的configs/cluster.yaml直接自动注册节点。

+ + + + + +
cluster.yaml
+ [下载] +
+
rpc:
+  endpoints: [ {{cluster.endpoints}} ]
+clusterId: "{{cluster.uniqueId}}"
+secret: "{{cluster.secret}}"
+
+
\ No newline at end of file