From 2b2b516788408860bc0ff66da09dbd2e22d987aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 23 May 2021 22:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9B=86=E7=BE=A4=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=93=8D=E4=BD=9C=E7=BB=93=E6=9E=9C=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/default/nodes/nodeutils/utils.go | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/web/actions/default/nodes/nodeutils/utils.go b/internal/web/actions/default/nodes/nodeutils/utils.go index 606bf525..0fe5b86e 100644 --- a/internal/web/actions/default/nodes/nodeutils/utils.go +++ b/internal/web/actions/default/nodes/nodeutils/utils.go @@ -6,10 +6,12 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/configs" "github.com/TeaOSLab/EdgeAdmin/internal/rpc" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "sort" "strconv" "sync" ) +// MessageResult 和节点消息通讯结果定义 type MessageResult struct { NodeId int64 `json:"nodeId"` NodeName string `json:"nodeName"` @@ -17,7 +19,7 @@ type MessageResult struct { Message string `json:"message"` } -// 向集群发送命令消息 +// SendMessageToCluster 向集群发送命令消息 func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg interface{}, timeoutSeconds int32) (results []*MessageResult, err error) { results = []*MessageResult{} @@ -153,10 +155,17 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg } wg.Wait() + // 对结果进行排序 + if len(results) > 0 { + sort.Slice(results, func(i, j int) bool { + return results[i].NodeId < results[j].NodeId + }) + } + return } -// 向一组节点发送命令消息 +// SendMessageToNodeIds 向一组节点发送命令消息 func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg interface{}, timeoutSeconds int32) (results []*MessageResult, err error) { results = []*MessageResult{} if len(nodeIds) == 0 { @@ -321,5 +330,12 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg } wg.Wait() + // 对结果进行排序 + if len(results) > 0 { + sort.Slice(results, func(i, j int) bool { + return results[i].NodeId < results[j].NodeId + }) + } + return }