增加节点停止、启动、安装测试等功能

This commit is contained in:
GoEdgeLab
2020-10-27 12:33:27 +08:00
parent 16ab3a5497
commit 0bf5859112
14 changed files with 299 additions and 158 deletions

View File

@@ -1,102 +1,102 @@
{$layout}
{$template "menu"}
{$template "menu"}
<form class="ui form segment" action="/clusters/cluster">
<input type="hidden" name="clusterId" :value="clusterId"/>
<div class="ui fields inline">
<div class="ui field">
安装状态:
</div>
<div class="ui field">
<select class="ui dropdown" name="installedState" v-model="installState">
<option value="0">[全部]</option>
<option value="1">已安装</option>
<option value="2">未安装</option>
</select>
</div>
<div class="ui field">
在线状态:
</div>
<div class="ui field">
<select class="ui dropdown" name="activeState" v-model="activeState">
<option value="0">[全部]</option>
<option value="1">在线</option>
<option value="2">不在线</option>
</select>
</div>
<div class="ui field">
<button class="ui button" type="submit">搜索</button>
</div>
<form class="ui form segment" action="/clusters/cluster">
<input type="hidden" name="clusterId" :value="clusterId"/>
<div class="ui fields inline">
<div class="ui field">
安装状态:
</div>
</form>
<div class="ui field">
<select class="ui dropdown" name="installedState" v-model="installState">
<option value="0">[全部]</option>
<option value="1">已安装</option>
<option value="2">未安装</option>
</select>
</div>
<div class="ui field">
在线状态:
</div>
<div class="ui field">
<select class="ui dropdown" name="activeState" v-model="activeState">
<option value="0">[全部]</option>
<option value="1">在线</option>
<option value="2">不在线</option>
</select>
</div>
<div class="ui field">
<button class="ui button" type="submit">搜索</button>
</div>
</div>
</form>
<p class="comment" v-if="nodes.length == 0">暂时还没有节点。</p>
<p class="comment" v-if="nodes.length == 0">暂时还没有节点。</p>
<table class="ui table selectable" v-if="nodes.length > 0">
<thead>
<tr>
<th>ID</th>
<th>节点名称</th>
<th>主机名</th>
<th>IP</th>
<th>CPU</th>
<th>内存</th>
<!--<th>流量</th>
<th>连接数</th>-->
<th>状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="node in nodes">
<td>{{node.id}}</td>
<td>{{node.name}}</td>
<td>
<span v-if="node.status.hostname != null && node.status.hostname.length > 0">{{node.status.hostname}}</span>
<span v-else>-</span>
</td>
<td>
<span v-if="node.ipAddresses.length == 0">-</span>
<div v-else class="address-box">
<div v-for="addr in node.ipAddresses" style="margin-bottom:0.3em">
<div class="ui label tiny">{{addr.ip}}
<span class="small" v-if="addr.name.length > 0">{{addr.name}}<span v-if="!addr.canAccess">,不可访问</span></span>
<span class="small" v-if="addr.name.length == 0 && !addr.canAccess">(不可访问)</span>
</div>
<table class="ui table selectable" v-if="nodes.length > 0">
<thead>
<tr>
<th class="one wide">ID</th>
<th>节点名称</th>
<th>主机名</th>
<th>IP</th>
<th class="two wide">CPU</th>
<th class="two wide">内存</th>
<!--<th>流量</th>
<th>连接数</th>-->
<th class="two wide">状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="node in nodes">
<td>{{node.id}}</td>
<td>{{node.name}}</td>
<td>
<span v-if="node.status.hostname != null && node.status.hostname.length > 0">{{node.status.hostname}}</span>
<span v-else>-</span>
</td>
<td>
<span v-if="node.ipAddresses.length == 0">-</span>
<div v-else class="address-box">
<div v-for="addr in node.ipAddresses" style="margin-bottom:0.3em">
<div class="ui label tiny">{{addr.ip}}
<span class="small" v-if="addr.name.length > 0">{{addr.name}}<span v-if="!addr.canAccess">,不可访问</span></span>
<span class="small" v-if="addr.name.length == 0 && !addr.canAccess">(不可访问)</span>
</div>
</div>
</td>
<td>
<span v-if="node.status.isActive" :class="{red:node.status.cpuUsage > 0.80}">{{node.status.cpuUsageText}}</span>
<span v-else>-</span>
</td>
<td>
<span v-if="node.status.isActive" :class="{red:node.status.memUsage > 0.80}">{{node.status.memUsageText}}</span>
<span v-else>-</span>
</td>
<td>
<div v-if="!node.isOn">
<label-on :v-is-on="node.isOn"></label-on>
</div>
</td>
<td>
<span v-if="node.status.isActive" :class="{red:node.status.cpuUsage > 0.80}">{{node.status.cpuUsageText}}</span>
<span v-else>-</span>
</td>
<td>
<span v-if="node.status.isActive" :class="{red:node.status.memUsage > 0.80}">{{node.status.memUsageText}}</span>
<span v-else>-</span>
</td>
<td>
<div v-if="!node.isOn">
<label-on :v-is-on="node.isOn"></label-on>
</div>
<div v-else-if="node.isInstalled">
<div v-if="node.status.isActive">
<span v-if="!node.isSynced" class="red">同步中</span>
<span v-else class="green">运行中</span>
</div>
<div v-else-if="node.isInstalled">
<div v-if="node.status.isActive">
<span v-if="!node.isSynced" class="red">同步中</span>
<span v-else class="green">运行中</span>
</div>
<span v-else-if="node.status.updatedAt > 0" class="red">已断开</span>
<span v-else-if="node.status.updatedAt == 0" class="red">连接</span>
</div>
<div v-else>
<span v-if="node.installStatus.isRunning" class="red">安装中</span>
<a v-if="node.installStatus.isFinished && !node.installStatus.isOk" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击看安装错误"><span class="red">安装出错</span></a>
<a v-else class="red" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击进安装界面"><span class="red">未安装</span></a>
</div>
</td>
<td>
<a :href="'/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + node.id">详情</a> &nbsp; <a href="" @click.prevent="deleteNode(node.id)">删除</a>
</td>
</tr>
</table>
<span v-else-if="node.status.updatedAt > 0" class="red">已断开</span>
<span v-else-if="node.status.updatedAt == 0" class="red">未连接</span>
</div>
<div v-else>
<span v-if="node.installStatus.isRunning" class="red">安装中</span>
<a v-if="node.installStatus.isFinished && !node.installStatus.isOk" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击看安装错误"><span class="red">安装出错</span></a>
<a v-else class="red" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击进安装界面"><span class="red">安装</span></a>
</div>
</td>
<td>
<a :href="'/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + node.id">详情</a> &nbsp; <a href="" @click.prevent="deleteNode(node.id)">删除</a>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>
<div class="page" v-html="page"></div>

View File

@@ -56,6 +56,20 @@ Tea.context(function () {
})
})
return
case "CREATE_ROOT_DIRECTORY_FAILED":
teaweb.warn("创建根目录失败,请检查目录权限或者手工创建:" + errMsg)
return
case "INSTALL_HELPER_FAILED":
teaweb.warn("安装助手失败:" + errMsg)
return
case "TEST_FAILED":
teaweb.warn("环境测试失败:" + errMsg)
return
case "RPC_TEST_FAILED":
teaweb.confirm("html:要安装的节点到API服务之间的RPC通讯测试失败具体错误" + errMsg + "<br/>现在修改API信息", function () {
window.location = "/api"
})
return
default:
teaweb.warn("安装失败:" + errMsg)
}

View File

@@ -30,49 +30,84 @@
</td>
</tr>
<tr>
<td>SSH主机地址</td>
<td colspan="2"><more-options-indicator>SSH等更多选项</more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>SSH主机地址</td>
<td>
<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
<span v-if="node.login.params.host.length > 0">{{node.login.params.host}}</span>
<span v-else class="disabled">尚未设置</span>
</div>
<div v-else class="disabled">
尚未设置
</div>
</td>
</tr>
<tr>
<td>SSH主机端口</td>
<td>
<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
<span v-if="node.login.params.port > 0">{{node.login.params.port}}</span>
<span v-else class="disabled">尚未设置</span>
</div>
<span v-else class="disabled">
尚未设置
</span>
</td>
</tr>
<tr>
<td>SSH登录认证</td>
<td>
<div v-if="node.login != null && node.login.grant != null && node.login.grant.id > 0">
<a :href="'/clusters/grants/grant?grantId=' + node.login.grant.id">{{node.login.grant.name}}<span class="small">{{node.login.grant.methodName}}</span></a>
</div>
<span v-else class="disabled">
尚未设置
</span>
</td>
</tr>
<tr>
<td>CPU线程数</td>
<td>
<span v-if="node.maxCPU > 0">{{node.maxCPU}}线程</span>
<span v-else class="disabled">没有限制。</span>
</td>
</tr>
</tbody>
</table>
<div class="ui divider"></div>
<h3>运行状态</h3>
<table class="ui table definition selectable">
<tr>
<td class="title">是否在运行</td>
<td>
<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
<span v-if="node.login.params.host.length > 0">{{node.login.params.host}}</span>
<span v-else class="disabled">尚未设置</span>
<div v-if="node.status.isActive">
<span class="green">运行中</span> &nbsp;
<a href="" @click.prevent="stopNode()" v-if="!isStopping"><span>[通过SSH停止]</span></a>
<span v-if="isStopping">[停止中...]</span>
</div>
<div v-else class="disabled">
尚未设置
<div v-else>
<span class="red">已断开</span> &nbsp;
<a href="" @click.prevent="startNode()" v-if="node.isInstalled && !isStarting"><span>[通过SSH启动]</span></a>
<span v-if="node.isInstalled && isStarting">[启动中...]</span>
<a v-if="!node.isInstalled" :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" ><span>去安装&gt;</span></a>
</div>
</td>
</tr>
<tr>
<td>SSH主机端口</td>
<td>
<div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
<span v-if="node.login.params.port > 0">{{node.login.params.port}}</span>
<span v-else class="disabled">尚未设置</span>
</div>
<span v-else class="disabled">
尚未设置
</span>
</td>
<tr v-show="node.status.isActive">
<td>CPU</td>
<td>{{node.status.cpuUsageText}}</td>
</tr>
<tr>
<td>SSH登录认证</td>
<td>
<div v-if="node.login != null && node.login.grant != null && node.login.grant.id > 0">
<a :href="'/clusters/grants/grant?grantId=' + node.login.grant.id">{{node.login.grant.name}}<span class="small">{{node.login.grant.methodName}}</span></a>
</div>
<span v-else class="disabled">
尚未设置
</span>
</td>
</tr>
<tr>
<td>CPU线程数</td>
<td>
<span v-if="node.maxCPU > 0">{{node.maxCPU}}线程</span>
<span v-else class="disabled">没有限制。</span>
</td>
<tr v-show="node.status.isActive">
<td>内存</td>
<td>{{node.status.memUsageText}}</td>
</tr>
</table>
<div class="ui divider"></div>
<h3>安装信息</h3>
<table class="ui table definition selectable">
<tr>

View File

@@ -0,0 +1,35 @@
Tea.context(function () {
this.isStarting = false
this.startNode = function () {
this.isStarting = true
this.$post("/clusters/cluster/node/start")
.params({
nodeId: this.node.id
})
.success(function () {
teaweb.success("启动成功", function () {
teaweb.reload()
})
})
.done(function () {
this.isStarting = false
})
}
this.isStopping = false
this.stopNode = function () {
this.isStopping = true
this.$post("/clusters/cluster/node/stop")
.params({
nodeId: this.node.id
})
.success(function () {
teaweb.success("执行成功", function () {
teaweb.reload()
})
})
.done(function () {
this.isStopping = false
})
}
})