From 46904fa4da33fd4ff54bce1efed4ab1ee79db9bf Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 8 Dec 2022 15:16:53 +0800 Subject: [PATCH 01/15] fix-3221 --- routers/api/v1/repo/cloudbrain.go | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index cd8340c41..d724149df 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -9,6 +9,7 @@ import ( "bufio" "encoding/json" "io" + "io/ioutil" "net/http" "os" "path" @@ -621,6 +622,19 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { } } + existStr := "testduibudui+" + "" + if job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference) { + if job.Type == models.TypeCloudBrainOne { + result, err := cloudbrain.GetJob(job.JobID) + if err == nil && result != nil { + jobRes, _ := models.ConvertToJobResultPayload(result.Payload) + taskRoles := jobRes.TaskRoles + taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) + existStr = taskRes.TaskStatuses[0].ExitDiagnostics + } + } + } + logDir := "/model" if job.JobType == string(models.JobTypeInference) || job.JobType == string(models.JobTypeModelSafety) { logDir = cloudbrain.ResultPath @@ -638,17 +652,30 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { } } if fileName != "" { - prefix := "/" + setting.CBCodePathPrefix + job.JobName + logDir - url, err := storage.Attachments.PresignedGetURL(prefix+"/"+fileName, fileName) + prefix := "/" + setting.CBCodePathPrefix + job.JobName + "/model" + filePath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + prefix + "/" + fileName + // Read the file contents into a byte slice + data, err := ioutil.ReadFile(filePath) if err != nil { - log.Error("Get minio get SignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("ReadFile", err) + return + } + + // Set the appropriate response headers + ctx.Resp.Header().Set("Content-Type", "application/octet-stream") + ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName) + + // Write the file contents to the response + if _, err := ctx.Resp.Write(data); err != nil { + ctx.ServerError("Write", err) + return + } + if _, err := ctx.Resp.Write([]byte(existStr)); err != nil { + log.Error("Write failed: %v", err.Error(), ctx.Data["msgID"]) return } - log.Info("fileName=" + fileName) - http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusTemporaryRedirect) } else { log.Info("fileName is null.") - } } From e1716a0b6d2b137cb2dbfdb97ff3afcd7da3fcbe Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 8 Dec 2022 17:39:36 +0800 Subject: [PATCH 02/15] fix-3221 --- routers/api/v1/repo/cloudbrain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index d724149df..b55529b51 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -622,7 +622,7 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { } } - existStr := "testduibudui+" + "" + existStr := "" if job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference) { if job.Type == models.TypeCloudBrainOne { result, err := cloudbrain.GetJob(job.JobID) From f8b6b19a8730a43e7f6dd192c056fbfa24a1a5a7 Mon Sep 17 00:00:00 2001 From: liuzx Date: Fri, 9 Dec 2022 11:29:25 +0800 Subject: [PATCH 03/15] fix-3241 --- routers/api/v1/repo/cloudbrain.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index b55529b51..a0dea0b86 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -765,6 +765,16 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) } + if (job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference)) && job.Type == models.TypeCloudBrainOne && job.Status == string(models.JobFailed) { + if ctx.Data["existStr"] != nil { + content = content + ctx.Data["existStr"].(string) + } + } else { + if ctx.Data["existStr"] != nil && result["Lines"].(int) < 50 { + content = content + ctx.Data["existStr"].(string) + } + } + logFileName := result["FileName"] //Logs can only be downloaded if the file exists From fc77e2417326dd840ce8079b2b44b510ddebb774 Mon Sep 17 00:00:00 2001 From: liuzx Date: Fri, 9 Dec 2022 11:44:32 +0800 Subject: [PATCH 04/15] fix-3241 --- routers/api/v1/repo/cloudbrain.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index a0dea0b86..89ebcc51a 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -761,10 +761,6 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = result["Content"].(string) } - if ctx.Data["existStr"] != nil && result["Lines"].(int) < 50 { - content = content + ctx.Data["existStr"].(string) - } - if (job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference)) && job.Type == models.TypeCloudBrainOne && job.Status == string(models.JobFailed) { if ctx.Data["existStr"] != nil { content = content + ctx.Data["existStr"].(string) From 17af23793324aa0bd2c391cc3c96f76caecaf966 Mon Sep 17 00:00:00 2001 From: liuzx Date: Mon, 12 Dec 2022 16:14:31 +0800 Subject: [PATCH 05/15] fix-3220 --- routers/api/v1/repo/cloudbrain.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 89ebcc51a..cd15dae98 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -764,6 +764,10 @@ func CloudbrainGetLog(ctx *context.APIContext) { if (job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference)) && job.Type == models.TypeCloudBrainOne && job.Status == string(models.JobFailed) { if ctx.Data["existStr"] != nil { content = content + ctx.Data["existStr"].(string) + if baseLine == "" && order == "desc" { + result["Lines"] = 1 + result["EndLine"] = 1 + } } } else { if ctx.Data["existStr"] != nil && result["Lines"].(int) < 50 { From a3a14e889b29009f66bcd1f63f215ed1f7d85eeb Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 14 Dec 2022 09:48:42 +0800 Subject: [PATCH 06/15] fix-3220 --- routers/api/v1/repo/cloudbrain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index cd15dae98..c2c06dcff 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -764,7 +764,7 @@ func CloudbrainGetLog(ctx *context.APIContext) { if (job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference)) && job.Type == models.TypeCloudBrainOne && job.Status == string(models.JobFailed) { if ctx.Data["existStr"] != nil { content = content + ctx.Data["existStr"].(string) - if baseLine == "" && order == "desc" { + if baseLine == "" && order == "desc" && result["Lines"].(int) == 0 { result["Lines"] = 1 result["EndLine"] = 1 } From c3bf329a3adbc26dd87d91845a158e2a0dbc84c4 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 10:52:14 +0800 Subject: [PATCH 07/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index c2c06dcff..2ab733e21 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -763,11 +763,13 @@ func CloudbrainGetLog(ctx *context.APIContext) { if (job.JobType == string(models.JobTypeTrain) || job.JobType == string(models.JobTypeInference)) && job.Type == models.TypeCloudBrainOne && job.Status == string(models.JobFailed) { if ctx.Data["existStr"] != nil { - content = content + ctx.Data["existStr"].(string) if baseLine == "" && order == "desc" && result["Lines"].(int) == 0 { result["Lines"] = 1 result["EndLine"] = 1 } + if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { + content = content + ctx.Data["existStr"].(string) + } } } else { if ctx.Data["existStr"] != nil && result["Lines"].(int) < 50 { From 51a816eb54a24ebb72dfe0c3d76f4a63b471d8b9 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:12:12 +0800 Subject: [PATCH 08/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 2ab733e21..bc194e2f3 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -767,7 +767,7 @@ func CloudbrainGetLog(ctx *context.APIContext) { result["Lines"] = 1 result["EndLine"] = 1 } - if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { + if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 || ctx.Data["existStr"] != nil && result["Lines"] == 0 { content = content + ctx.Data["existStr"].(string) } } From b65a2f8b7e9b9f9aa6dd3b5a6e7394e60aec5c1c Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:14:25 +0800 Subject: [PATCH 09/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index bc194e2f3..b1602958e 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -767,8 +767,11 @@ func CloudbrainGetLog(ctx *context.APIContext) { result["Lines"] = 1 result["EndLine"] = 1 } - if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 || ctx.Data["existStr"] != nil && result["Lines"] == 0 { + if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { content = content + ctx.Data["existStr"].(string) + if result["Lines"].(int) == 0 { + result["Lines"] = 1 + } } } } else { From 7a3fd488d47685dd9c89aeb077ec86ea4243daec Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:19:25 +0800 Subject: [PATCH 10/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index b1602958e..a5ac1873f 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -771,6 +771,8 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) if result["Lines"].(int) == 0 { result["Lines"] = 1 + startLine := ctx.QueryInt("base_line") + result["EndLine"] = startLine + 1 } } } From 81e4dbd2402873e945138d88d77e0e5805e36036 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:23:38 +0800 Subject: [PATCH 11/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index a5ac1873f..44685a921 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -771,8 +771,8 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) if result["Lines"].(int) == 0 { result["Lines"] = 1 - startLine := ctx.QueryInt("base_line") - result["EndLine"] = startLine + 1 + // startLine := ctx.QueryInt("base_line") + // result["EndLine"] = startLine + 1 } } } From 9142f19cc236f9a1491f6151ce2df09776ea40d1 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:28:22 +0800 Subject: [PATCH 12/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 44685a921..2ab733e21 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -769,11 +769,6 @@ func CloudbrainGetLog(ctx *context.APIContext) { } if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { content = content + ctx.Data["existStr"].(string) - if result["Lines"].(int) == 0 { - result["Lines"] = 1 - // startLine := ctx.QueryInt("base_line") - // result["EndLine"] = startLine + 1 - } } } } else { From 77a8f22e0224cab9cee2f32c1310de14a6723287 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:34:39 +0800 Subject: [PATCH 13/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 2ab733e21..b1602958e 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -769,6 +769,9 @@ func CloudbrainGetLog(ctx *context.APIContext) { } if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { content = content + ctx.Data["existStr"].(string) + if result["Lines"].(int) == 0 { + result["Lines"] = 1 + } } } } else { From 0cd2bdae14de63888e4569fdf27cfeb69a08e468 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 11:37:58 +0800 Subject: [PATCH 14/15] fix-3393 --- routers/api/v1/repo/cloudbrain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index b1602958e..e5cfbc86c 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -771,6 +771,7 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) if result["Lines"].(int) == 0 { result["Lines"] = 1 + result["EndLine"] = result["StartLine"] } } } From c45ffda6eb5f4df3caa0d1c02a4107b16cbf8ad6 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 15 Dec 2022 15:30:25 +0800 Subject: [PATCH 15/15] fix-3392 --- routers/api/v1/repo/cloudbrain.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index e5cfbc86c..ca4a8c747 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -766,13 +766,17 @@ func CloudbrainGetLog(ctx *context.APIContext) { if baseLine == "" && order == "desc" && result["Lines"].(int) == 0 { result["Lines"] = 1 result["EndLine"] = 1 + content = content + ctx.Data["existStr"].(string) } - if ctx.Data["existStr"] != nil && result["Lines"].(int) < 60 { + + if result["Lines"].(int) == 0 && result["StartLine"] == result["EndLine"] && result["StartLine"].(int) != 0 { content = content + ctx.Data["existStr"].(string) - if result["Lines"].(int) == 0 { - result["Lines"] = 1 - result["EndLine"] = result["StartLine"] - } + result["Lines"] = 1 + result["StartLine"] = result["StartLine"].(int) - 1 + } + if result["Lines"].(int) == 1 && result["StartLine"] == result["EndLine"] { + result["Lines"] = 0 + result["StartLine"] = result["StartLine"].(int) + 1 } } } else {