配置更新时立即向集群节点发消息

This commit is contained in:
刘祥超
2020-10-09 12:03:32 +08:00
parent 37130d2e23
commit 6a3374e5ff
13 changed files with 36 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
package common package clusters
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
@@ -8,15 +8,15 @@ import (
) )
// 检查变更的集群列表 // 检查变更的集群列表
type ChangedClustersAction struct { type CheckChangeAction struct {
actionutils.ParentAction actionutils.ParentAction
} }
func (this *ChangedClustersAction) Init() { func (this *CheckChangeAction) Init() {
this.Nav("", "", "") this.Nav("", "", "")
} }
func (this *ChangedClustersAction) RunGet(params struct { func (this *CheckChangeAction) RunPost(params struct {
IsNotifying bool IsNotifying bool
}) { }) {
timeout := time.NewTimer(55 * time.Second) // 比客户端提前结束,避免在客户端产生一个请求错误 timeout := time.NewTimer(55 * time.Second) // 比客户端提前结束,避免在客户端产生一个请求错误

View File

@@ -13,6 +13,8 @@ func init() {
Prefix("/clusters"). Prefix("/clusters").
Get("", new(IndexAction)). Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)). GetPost("/create", new(CreateAction)).
Post("/sync", new(SyncAction)).
Post("/checkChange", new(CheckChangeAction)).
EndAll() EndAll()
}) })
} }

View File

@@ -1,16 +1,18 @@
package common package clusters
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
) )
// 同步集群 // 同步集群
type SyncClustersAction struct { type SyncAction struct {
actionutils.ParentAction actionutils.ParentAction
} }
func (this *SyncClustersAction) RunPost(params struct{}) { func (this *SyncAction) RunPost(params struct{}) {
// TODO 将来可以单独选择某一个集群进行单独的同步 // TODO 将来可以单独选择某一个集群进行单独的同步
// 所有有变化的集群 // 所有有变化的集群
@@ -29,6 +31,13 @@ func (this *SyncClustersAction) RunPost(params struct{}) {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
// 发送通知
_, err = nodeutils.SendMessageToCluster(this.AdminContext(), cluster.Id, messageconfigs.MessageCodeConfigChanged, &messageconfigs.ConfigChangedMessage{}, 10)
if err != nil {
this.ErrorPage(err)
return
}
} }
this.Success() this.Success()

View File

@@ -1,17 +0,0 @@
package common
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(new(helpers.UserMustAuth)).
Prefix("/common").
Get("/changedClusters", new(ChangedClustersAction)).
Post("/syncClusters", new(SyncClustersAction)).
EndAll()
})
}

View File

@@ -97,6 +97,7 @@ func (this *IndexAction) RunGet(params struct{}) {
serverMaps = append(serverMaps, maps.Map{ serverMaps = append(serverMaps, maps.Map{
"id": server.Id, "id": server.Id,
"isOn": server.IsOn,
"name": server.Name, "name": server.Name,
"cluster": maps.Map{ "cluster": maps.Map{
"id": server.Cluster.Id, "id": server.Cluster.Id,

View File

@@ -6,7 +6,6 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/common"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dashboard" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dashboard"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns"

View File

@@ -37,7 +37,7 @@ Tea.context(function () {
* 检查集群变更 * 检查集群变更
*/ */
this.checkClusterChanges = function () { this.checkClusterChanges = function () {
this.$get("/common/changedClusters") this.$post("/clusters/checkChange")
.params({ .params({
isNotifying: (this.globalChangedClusters.length > 0) ? 1 : 0 isNotifying: (this.globalChangedClusters.length > 0) ? 1 : 0
}) })
@@ -64,7 +64,7 @@ Tea.context(function () {
*/ */
this.syncClustersConfigs = function () { this.syncClustersConfigs = function () {
teaweb.confirm("确定要同步集群服务配置吗?", function () { teaweb.confirm("确定要同步集群服务配置吗?", function () {
this.$post("/common/syncClusters") this.$post("/clusters/sync")
.success(function () { .success(function () {
this.globalChangedClusters = []; this.globalChangedClusters = [];
}) })

View File

@@ -1,6 +1,6 @@
<second-menu> <second-menu>
<menu-item :href="'/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + nodeId" code="node">节点详情</menu-item> <menu-item :href="'/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + nodeId" code="node">节点详情</menu-item>
<menu-item :href="'/clusters/cluster/node/logs?clusterId=' + clusterId + '&nodeId=' + nodeId" code="log">节点日志</menu-item> <menu-item :href="'/clusters/cluster/node/logs?clusterId=' + clusterId + '&nodeId=' + nodeId" code="log">运行日志</menu-item>
<menu-item :href="'/clusters/cluster/node/update?clusterId=' + clusterId + '&nodeId=' + nodeId" code="update">修改节点</menu-item> <menu-item :href="'/clusters/cluster/node/update?clusterId=' + clusterId + '&nodeId=' + nodeId" code="update">修改设置</menu-item>
<menu-item :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + nodeId" code="install">安装节点</menu-item> <menu-item :href="'/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + nodeId" code="install">安装节点</menu-item>
</second-menu> </second-menu>

View File

@@ -0,0 +1,5 @@
pre.log-box {
margin: 0;
padding: 0;
}
/*# sourceMappingURL=logs.css.map */

View File

@@ -0,0 +1 @@
{"version":3,"sources":["logs.less"],"names":[],"mappings":"AAAA,GAAG;EACF,SAAA;EACA,UAAA","file":"logs.css"}

View File

@@ -14,10 +14,7 @@
</thead> </thead>
<tr v-for="log in logs"> <tr v-for="log in logs">
<td> <td>
<span :class="{red:log.level == 'error', yellow:log.level == 'warning'}"> <pre class="log-box"><span :class="{red:log.level == 'error', yellow:log.level == 'warning'}"><span v-if="!log.isToday">[{{log.createdTime}}]</span><strong v-if="log.isToday">[{{log.createdTime}}]</strong>[{{log.tag}}]{{log.description}}</span></pre>
<span v-if="!log.isToday">[{{log.createdTime}}]</span>
<strong v-if="log.isToday">[{{log.createdTime}}]</strong>
[{{log.tag}}]{{log.description}}</span>
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -0,0 +1,4 @@
pre.log-box {
margin: 0;
padding: 0;
}

View File

@@ -9,10 +9,8 @@
<th>服务名称</th> <th>服务名称</th>
<th>服务类型</th> <th>服务类型</th>
<th>部署集群</th> <th>部署集群</th>
<th>运行中节点数</th>
<th>未运行节点数</th>
<th>端口</th> <th>端口</th>
<th>状态</th> <th class="two wide">状态</th>
<th class="two op">操作</th> <th class="two op">操作</th>
</tr> </tr>
</thead> </thead>
@@ -20,8 +18,6 @@
<td>{{server.name}}</td> <td>{{server.name}}</td>
<td>{{server.serverTypeName}}</td> <td>{{server.serverTypeName}}</td>
<td>{{server.cluster.name}}</td> <td>{{server.cluster.name}}</td>
<td><span class="disabled">[暂无]</span></td>
<td><span class="disabled">[暂无]</span></td>
<td> <td>
<span v-if="server.ports.length == 0">-</span> <span v-if="server.ports.length == 0">-</span>
<div v-for="port in server.ports"> <div v-for="port in server.ports">
@@ -29,7 +25,7 @@
</div> </div>
</td> </td>
<td> <td>
<span class="disabled">[暂无]</span> <label-on :v-is-on="server.isOn"></label-on>
</td> </td>
<td> <td>
<a :href="'/servers/server?serverId=' + server.id">详情</a> <a :href="'/servers/server?serverId=' + server.id">详情</a>