实现API节点远程升级

This commit is contained in:
GoEdgeLab
2023-03-05 12:05:18 +08:00
parent b5cba51456
commit 2ac7f6d14a
12 changed files with 426 additions and 69 deletions
+6 -1
View File
@@ -23,7 +23,12 @@
</thead>
<tr v-for="node in nodes">
<td><a :href="'/api/node?nodeId=' + node.id">{{node.name}}</a>
<grey-label v-if="node.isPrimary">主节点</grey-label>
<div v-if="node.isPrimary">
<grey-label v-if="node.isPrimary">主节点</grey-label>
</div>
<div v-if="node.status != null && node.status.shouldUpgrade">
<span class="red small">v{{node.status.buildVersion}} -&gt; v{{node.status.latestVersion}}<br/><a href="" v-if="node.status.canUpgrade" @click.prevent="upgradeNode(node.id)">[远程升级]</a> </span>
</div>
</td>
<td>
<div v-if="node.accessAddrs != null && node.accessAddrs.length > 0">
+11 -2
View File
@@ -1,7 +1,7 @@
Tea.context(function () {
// 创建节点
this.createNode = function () {
teaweb.popup("/api/node/createPopup", {
teaweb.popup(".node.createPopup", {
width: "50em",
height: "30em",
callback: function () {
@@ -16,11 +16,20 @@ Tea.context(function () {
this.deleteNode = function (nodeId) {
let that = this
teaweb.confirm("确定要删除此节点吗?", function () {
that.$post("/api/delete")
that.$post(".delete")
.params({
nodeId: nodeId
})
.refresh()
})
}
// 升级节点
this.upgradeNode = function (nodeId) {
teaweb.popup(".node.upgradePopup?nodeId=" + nodeId, {
onClose: function () {
teaweb.reload()
}
})
}
})
@@ -0,0 +1,35 @@
{$layout "layout_popup"}
<h3>远程升级</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success" data-tea-timeout="3600" data-tea-before="before" data-tea-done="done">
<csrf-token></csrf-token>
<input type="hidden" name="nodeId" :value="nodeId"/>
<table class="ui table definition selectable">
<tr v-show="nodeName.length > 0">
<td class="title">API节点</td>
<td>{{nodeName}}</td>
</tr>
<tr v-show="currentVersion.length > 0">
<td>当前版本</td>
<td>v{{currentVersion}}</td>
</tr>
<tr v-show="latestVersion.length > 0">
<td>目标版本</td>
<td>v{{latestVersion}}</td>
</tr>
<tr>
<td class="title">升级结果</td>
<td>
<span v-if="currentVersion == latestVersion" class="green">已经升级到最新版本</span>
<span :class="{red: !resultIsOk}" v-if="currentVersion != latestVersion">
<span v-if="!isRequesting">{{result}}</span>
<span v-if="isRequesting">升级中...</span>
</span>
</td>
</tr>
</table>
<submit-btn v-show="canUpgrade && !isRequesting && !isUpgrading">开始升级</submit-btn>
</form>
@@ -0,0 +1,39 @@
Tea.context(function () {
this.$delay(function () {
this.checkLoop()
})
this.success = function () {
}
this.isRequesting = false
this.before = function () {
this.isRequesting = true
}
this.done = function () {
this.isRequesting = false
}
this.checkLoop = function () {
if (this.currentVersion == this.latestVersion) {
return
}
this.$post(".upgradeCheck")
.params({
nodeId: this.nodeId
})
.success(function (resp) {
if (resp.data.isOk) {
teaweb.reload()
}
})
.done(function () {
this.$delay(function () {
this.checkLoop()
}, 3000)
})
}
})