2020-10-17 11:14:07 +08:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
|
|
import (
|
2024-07-27 15:42:58 +08:00
|
|
|
"strings"
|
|
|
|
|
|
2020-10-17 11:14:07 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type InstallNodesAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *InstallNodesAction) Init() {
|
|
|
|
|
this.Nav("", "node", "install")
|
|
|
|
|
this.SecondMenu("nodes")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *InstallNodesAction) RunGet(params struct {
|
|
|
|
|
ClusterId int64
|
|
|
|
|
}) {
|
2023-06-28 16:18:52 +08:00
|
|
|
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "register", this.LangCode())
|
2020-10-26 21:14:26 +08:00
|
|
|
|
2020-12-17 15:50:44 +08:00
|
|
|
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId})
|
2020-10-17 11:14:07 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-17 17:35:38 +08:00
|
|
|
if clusterResp.NodeCluster == nil {
|
2020-10-17 11:14:07 +08:00
|
|
|
this.NotFound("nodeCluster", params.ClusterId)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 17:35:38 +08:00
|
|
|
cluster := clusterResp.NodeCluster
|
2020-10-17 11:14:07 +08:00
|
|
|
|
2020-12-17 15:50:44 +08:00
|
|
|
clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{NodeClusterId: params.ClusterId})
|
2020-10-17 11:14:07 +08:00
|
|
|
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
|
|
|
|
|
}
|
2021-11-05 15:34:48 +08:00
|
|
|
for _, apiNode := range apiNodesResp.ApiNodes {
|
2020-10-17 11:14:07 +08:00
|
|
|
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()
|
|
|
|
|
}
|