From 13f00104dd2877a8106de6eee2bf9f80eed68b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 17 Sep 2022 11:38:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9F=9F=E5=90=8D=E6=97=B6=E6=A3=80=E6=9F=A5=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cluster/settings/health/checkDomain.go | 52 +++++++++++++++++++ .../default/clusters/cluster/settings/init.go | 1 + .../common/health-check-config-box.js | 29 +++++++++-- .../cluster/settings/health/index.html | 2 +- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go diff --git a/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go b/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go new file mode 100644 index 00000000..1948c5a7 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go @@ -0,0 +1,52 @@ +// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package health + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "net" + "strings" +) + +type CheckDomainAction struct { + actionutils.ParentAction +} + +func (this *CheckDomainAction) RunPost(params struct { + Host string + ClusterId int64 +}) { + this.Data["isOk"] = true // 默认为TRUE + + var host = params.Host + if len(host) > 0 && + !strings.Contains(host, "{") /** 包含变量 **/ { + h, _, err := net.SplitHostPort(host) + if err == nil && len(h) > 0 { + host = h + } + + // 是否为IP + if net.ParseIP(host) != nil { + this.Success() + return + } + + host = strings.ToLower(host) + resp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{ + NodeClusterId: params.ClusterId, + ServerNames: []string{host}, + SupportWildcard: true, + }) + if err != nil { + this.ErrorPage(err) + return + } + if len(resp.DuplicatedServerNames) == 0 { + this.Data["isOk"] = false + } + } + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index 5d7ee790..cf1ce903 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -29,6 +29,7 @@ func init() { // 健康检查 GetPost("/health", new(health.IndexAction)). GetPost("/health/runPopup", new(health.RunPopupAction)). + Post("/health/checkDomain", new(health.CheckDomainAction)). // 缓存 GetPost("/cache", new(cache.IndexAction)). diff --git a/web/public/js/components/common/health-check-config-box.js b/web/public/js/components/common/health-check-config-box.js index 0d840707..081a75cb 100644 --- a/web/public/js/components/common/health-check-config-box.js +++ b/web/public/js/components/common/health-check-config-box.js @@ -1,5 +1,5 @@ Vue.component("health-check-config-box", { - props: ["v-health-check-config"], + props: ["v-health-check-config", "v-check-domain-url"], data: function () { let healthCheckConfig = this.vHealthCheckConfig let urlProtocol = "http" @@ -76,7 +76,9 @@ Vue.component("health-check-config-box", { urlHost: urlHost, urlPort: urlPort, urlRequestURI: urlRequestURI, - urlIsEditing: healthCheckConfig.url.length == 0 + urlIsEditing: healthCheckConfig.url.length == 0, + + hostErr: "" } }, watch: { @@ -100,6 +102,7 @@ Vue.component("health-check-config-box", { }, urlHost: function () { this.changeURL() + this.hostErr = "" }, "healthCheck.countTries": function (v) { let count = parseInt(v) @@ -147,6 +150,24 @@ Vue.component("health-check-config-box", { } }) }, + onChangeURLHost: function () { + let checkDomainURL = this.vCheckDomainUrl + if (checkDomainURL == null || checkDomainURL.length == 0) { + return + } + + let that = this + Tea.action(checkDomainURL) + .params({host: this.urlHost}) + .success(function (resp) { + if (!resp.data.isOk) { + that.hostErr = "在当前集群中找不到此域名,可能会影响健康检查结果。" + } else { + that.hostErr = "" + } + }) + .post() + }, editURL: function () { this.urlIsEditing = !this.urlIsEditing } @@ -185,8 +206,8 @@ Vue.component("health-check-config-box", { 域名 - -

已经部署到当前集群的一个域名;如果为空则使用节点IP作为域名。如果协议是https,这里必须填写一个已经设置了SSL证书的域名。

+ +

{{hostErr}}已经部署到当前集群的一个域名;如果为空则使用节点IP作为域名。如果协议是https,这里必须填写一个已经设置了SSL证书的域名。

diff --git a/web/views/@default/clusters/cluster/settings/health/index.html b/web/views/@default/clusters/cluster/settings/health/index.html index feee29ad..a64c3508 100644 --- a/web/views/@default/clusters/cluster/settings/health/index.html +++ b/web/views/@default/clusters/cluster/settings/health/index.html @@ -5,7 +5,7 @@
- +   立即检查
\ No newline at end of file