健康检查连续下线次数默认值从1次改为3次

This commit is contained in:
刘祥超
2021-08-29 15:26:56 +08:00
parent f5f07c0e96
commit 502ce4e414

View File

@@ -1,150 +1,150 @@
Vue.component("health-check-config-box", { Vue.component("health-check-config-box", {
props: ["v-health-check-config"], props: ["v-health-check-config"],
data: function () { data: function () {
let healthCheckConfig = this.vHealthCheckConfig let healthCheckConfig = this.vHealthCheckConfig
let urlProtocol = "http" let urlProtocol = "http"
let urlPort = "" let urlPort = ""
let urlRequestURI = "/" let urlRequestURI = "/"
let urlHost = "" let urlHost = ""
if (healthCheckConfig == null) { if (healthCheckConfig == null) {
healthCheckConfig = { healthCheckConfig = {
isOn: false, isOn: false,
url: "", url: "",
interval: {count: 60, unit: "second"}, interval: {count: 60, unit: "second"},
statusCodes: [200], statusCodes: [200],
timeout: {count: 10, unit: "second"}, timeout: {count: 10, unit: "second"},
countTries: 3, countTries: 3,
tryDelay: {count: 100, unit: "ms"}, tryDelay: {count: 100, unit: "ms"},
autoDown: true, autoDown: true,
countUp: 1, countUp: 1,
countDown: 1 countDown: 3
} }
let that = this let that = this
setTimeout(function () { setTimeout(function () {
that.changeURL() that.changeURL()
}, 500) }, 500)
} else { } else {
try { try {
let url = new URL(healthCheckConfig.url) let url = new URL(healthCheckConfig.url)
urlProtocol = url.protocol.substring(0, url.protocol.length - 1) urlProtocol = url.protocol.substring(0, url.protocol.length - 1)
// 域名 // 域名
urlHost = url.host urlHost = url.host
if (urlHost == "%24%7Bhost%7D") { if (urlHost == "%24%7Bhost%7D") {
urlHost = "${host}" urlHost = "${host}"
} }
let colonIndex = urlHost.indexOf(":") let colonIndex = urlHost.indexOf(":")
if (colonIndex > 0) { if (colonIndex > 0) {
urlHost = urlHost.substring(0, colonIndex) urlHost = urlHost.substring(0, colonIndex)
} }
urlPort = url.port urlPort = url.port
urlRequestURI = url.pathname urlRequestURI = url.pathname
if (url.search.length > 0) { if (url.search.length > 0) {
urlRequestURI += url.search urlRequestURI += url.search
} }
} catch (e) { } catch (e) {
} }
if (healthCheckConfig.statusCodes == null) { if (healthCheckConfig.statusCodes == null) {
healthCheckConfig.statusCodes = [200] healthCheckConfig.statusCodes = [200]
} }
if (healthCheckConfig.interval == null) { if (healthCheckConfig.interval == null) {
healthCheckConfig.interval = {count: 60, unit: "second"} healthCheckConfig.interval = {count: 60, unit: "second"}
} }
if (healthCheckConfig.timeout == null) { if (healthCheckConfig.timeout == null) {
healthCheckConfig.timeout = {count: 10, unit: "second"} healthCheckConfig.timeout = {count: 10, unit: "second"}
} }
if (healthCheckConfig.tryDelay == null) { if (healthCheckConfig.tryDelay == null) {
healthCheckConfig.tryDelay = {count: 100, unit: "ms"} healthCheckConfig.tryDelay = {count: 100, unit: "ms"}
} }
if (healthCheckConfig.countUp == null || healthCheckConfig.countUp < 1) { if (healthCheckConfig.countUp == null || healthCheckConfig.countUp < 1) {
healthCheckConfig.countUp = 1 healthCheckConfig.countUp = 1
} }
if (healthCheckConfig.countDown == null || healthCheckConfig.countDown < 1) { if (healthCheckConfig.countDown == null || healthCheckConfig.countDown < 1) {
healthCheckConfig.countDown = 1 healthCheckConfig.countDown = 3
} }
} }
return { return {
healthCheck: healthCheckConfig, healthCheck: healthCheckConfig,
advancedVisible: false, advancedVisible: false,
urlProtocol: urlProtocol, urlProtocol: urlProtocol,
urlHost: urlHost, urlHost: urlHost,
urlPort: urlPort, urlPort: urlPort,
urlRequestURI: urlRequestURI urlRequestURI: urlRequestURI
} }
}, },
watch: { watch: {
urlRequestURI: function () { urlRequestURI: function () {
if (this.urlRequestURI.length > 0 && this.urlRequestURI[0] != "/") { if (this.urlRequestURI.length > 0 && this.urlRequestURI[0] != "/") {
this.urlRequestURI = "/" + this.urlRequestURI this.urlRequestURI = "/" + this.urlRequestURI
} }
this.changeURL() this.changeURL()
}, },
urlPort: function (v) { urlPort: function (v) {
let port = parseInt(v) let port = parseInt(v)
if (!isNaN(port)) { if (!isNaN(port)) {
this.urlPort = port.toString() this.urlPort = port.toString()
} else { } else {
this.urlPort = "" this.urlPort = ""
} }
this.changeURL() this.changeURL()
}, },
urlProtocol: function () { urlProtocol: function () {
this.changeURL() this.changeURL()
}, },
urlHost: function () { urlHost: function () {
this.changeURL() this.changeURL()
}, },
"healthCheck.countTries": function (v) { "healthCheck.countTries": function (v) {
let count = parseInt(v) let count = parseInt(v)
if (!isNaN(count)) { if (!isNaN(count)) {
this.healthCheck.countTries = count this.healthCheck.countTries = count
} else { } else {
this.healthCheck.countTries = 0 this.healthCheck.countTries = 0
} }
}, },
"healthCheck.countUp": function (v) { "healthCheck.countUp": function (v) {
let count = parseInt(v) let count = parseInt(v)
if (!isNaN(count)) { if (!isNaN(count)) {
this.healthCheck.countUp = count this.healthCheck.countUp = count
} else { } else {
this.healthCheck.countUp = 0 this.healthCheck.countUp = 0
} }
}, },
"healthCheck.countDown": function (v) { "healthCheck.countDown": function (v) {
let count = parseInt(v) let count = parseInt(v)
if (!isNaN(count)) { if (!isNaN(count)) {
this.healthCheck.countDown = count this.healthCheck.countDown = count
} else { } else {
this.healthCheck.countDown = 0 this.healthCheck.countDown = 0
} }
} }
}, },
methods: { methods: {
showAdvanced: function () { showAdvanced: function () {
this.advancedVisible = !this.advancedVisible this.advancedVisible = !this.advancedVisible
}, },
changeURL: function () { changeURL: function () {
let urlHost = this.urlHost let urlHost = this.urlHost
if (urlHost.length == 0) { if (urlHost.length == 0) {
urlHost = "${host}" urlHost = "${host}"
} }
this.healthCheck.url = this.urlProtocol + "://" + urlHost + ((this.urlPort.length > 0) ? ":" + this.urlPort : "") + this.urlRequestURI this.healthCheck.url = this.urlProtocol + "://" + urlHost + ((this.urlPort.length > 0) ? ":" + this.urlPort : "") + this.urlRequestURI
}, },
changeStatus: function (values) { changeStatus: function (values) {
this.healthCheck.statusCodes = values.$map(function (k, v) { this.healthCheck.statusCodes = values.$map(function (k, v) {
let status = parseInt(v) let status = parseInt(v)
if (isNaN(status)) { if (isNaN(status)) {
return 0 return 0
} else { } else {
return status return status
} }
}) })
} }
}, },
template: `<div> template: `<div>
<input type="hidden" name="healthCheckJSON" :value="JSON.stringify(healthCheck)"/> <input type="hidden" name="healthCheckJSON" :value="JSON.stringify(healthCheck)"/>
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tbody> <tbody>
@@ -227,7 +227,7 @@ Vue.component("health-check-config-box", {
<p class="comment">连续N次检查失败后自动下线。</p> <p class="comment">连续N次检查失败后自动下线。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tbody v-show="healthCheck.isOn"> <tbody v-show="healthCheck.isOn">
<tr> <tr>
<td colspan="2"><more-options-angle @change="showAdvanced"></more-options-angle></td> <td colspan="2"><more-options-angle @change="showAdvanced"></more-options-angle></td>