From 7df93b2ad172ebce10d5317c01748c2a3ebf7769 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 30 Jul 2024 13:54:43 +0800 Subject: [PATCH] server/service: fix index out of range error when calling batchuuidlist() --- server/db/redismanager/redis.go | 6 +++--- server/handler/basicHandler.go | 2 +- server/handler/customTopoHandler.go | 13 ++++++++++--- server/service/custom/customService.go | 5 +---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/db/redismanager/redis.go b/server/db/redismanager/redis.go index c108533..2b6e9de 100644 --- a/server/db/redismanager/redis.go +++ b/server/db/redismanager/redis.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/json" "fmt" + "strings" "sync" "sync/atomic" "time" @@ -219,11 +220,11 @@ func (r *RedisClient) UpdateTopoRunningAgentList(uuids []string, updateonce bool }) if len(abort_reason) != 0 { - logger.Debug(">>>>>>>>>>>>获取agent状态信息") + logger.Debug("%sagent status%s", strings.Repeat("=", 9), strings.Repeat("=", 9)) for _, r := range abort_reason { logger.Debug(r) } - logger.Debug(">>>>>>>>>>>>") + logger.Debug(strings.Repeat("=", 30)) } if updateonce { @@ -234,7 +235,6 @@ func (r *RedisClient) UpdateTopoRunningAgentList(uuids []string, updateonce bool } logger.Info("running agent number: %d", running_agent_num) - return int(running_agent_num) } diff --git a/server/handler/basicHandler.go b/server/handler/basicHandler.go index c937059..69d7205 100644 --- a/server/handler/basicHandler.go +++ b/server/handler/basicHandler.go @@ -138,7 +138,7 @@ func BatchListHandle(ctx *gin.Context) { batchlist, err := pluginclient.Global_Client.BatchList() if err != nil { - err = errors.Errorf("%s **errstack**0", err.Error()) + err = errors.Errorf("%s **warn**0", err.Error()) errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) response.Fail(ctx, nil, err.Error()) return diff --git a/server/handler/customTopoHandler.go b/server/handler/customTopoHandler.go index 33414fd..5d10a78 100755 --- a/server/handler/customTopoHandler.go +++ b/server/handler/customTopoHandler.go @@ -157,15 +157,22 @@ func RunCustomTopoHandle(ctx *gin.Context) { custom_topodata.Nodes, custom_topodata.Edges, custom_topodata.Combos, err = custom.RunCustomTopoService(uint(tcid_int)) if err != nil { + if len(strings.Split(errors.Cause(err).Error(), "**")) == 0 { + err = errors.Errorf("wrong err format: %s **warn**0", errors.Cause(err).Error()) + errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) + doneChan <- custom_topodata + response.Fail(ctx, nil, errors.Cause(err).Error()) + return + } switch strings.Split(errors.Cause(err).Error(), "**")[1] { case "errstack": - err = errors.Wrap(err, " **errstack**2") // err top + err = errors.Wrap(err, " **errstack**2") errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) doneChan <- custom_topodata response.Fail(ctx, nil, errors.Cause(err).Error()) return case "errstackfatal": - err = errors.Wrap(err, " **errstackfatal**2") // err top + err = errors.Wrap(err, " **errstackfatal**2") doneChan <- custom_topodata response.Fail(ctx, nil, errors.Cause(err).Error()) errormanager.ErrorTransmit(pluginclient.Global_Context, err, true) @@ -173,7 +180,7 @@ func RunCustomTopoHandle(ctx *gin.Context) { } } if len(custom_topodata.Nodes.Nodes) == 0 || len(custom_topodata.Edges.Edges) == 0 { - err := errors.New("nodes list is null or edges list is null **errstack**0") // err top + err := errors.New("nodes list is null or edges list is null **errstack**0") errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) doneChan <- custom_topodata response.Fail(ctx, nil, errors.Cause(err).Error()) diff --git a/server/service/custom/customService.go b/server/service/custom/customService.go index c1fdb27..12c0287 100755 --- a/server/service/custom/customService.go +++ b/server/service/custom/customService.go @@ -24,17 +24,14 @@ func RunCustomTopoService(tcid uint) (*graph.Nodes, *graph.Edges, []map[string]s err := errors.New("Global_Client is nil **errstackfatal**2") return nil, nil, nil, err } - if agentmanager.Global_AgentManager == nil { err := errors.New("Global_AgentManager is nil **errstackfatal**0") return nil, nil, nil, err } - if redismanager.Global_Redis == nil { err := errors.New("global_redis is nil **errstackfatal**1") return nil, nil, nil, err } - if mysqlmanager.Global_Mysql == nil { err := errors.New("global_mysql is nil **errstackfatal**1") return nil, nil, nil, err @@ -52,7 +49,7 @@ func RunCustomTopoService(tcid uint) (*graph.Nodes, *graph.Edges, []map[string]s machine_uuids, err := pluginclient.Global_Client.BatchUUIDList(strconv.Itoa(int(tc.BatchId))) if err != nil { - return nil, nil, nil, errors.Wrap(err, "**2") + return nil, nil, nil, errors.Errorf("%s **errstack**0", err.Error()) } // ctxv := context.WithValue(agentmanager.Topo.Tctx, "custom_name", "pilotgo-topo") -- Gitee