|
|
@@ -9,6 +9,7 @@ import ( |
|
|
|
"bufio" |
|
|
|
"encoding/json" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"path" |
|
|
@@ -647,6 +648,19 @@ func CloudbrainDownloadLogFile(ctx *context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
existStr := "" |
|
|
|
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 |
|
|
@@ -664,17 +678,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.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -760,8 +787,28 @@ 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 { |
|
|
|
if baseLine == "" && order == "desc" && result["Lines"].(int) == 0 { |
|
|
|
result["Lines"] = 1 |
|
|
|
result["EndLine"] = 1 |
|
|
|
content = content + ctx.Data["existStr"].(string) |
|
|
|
} |
|
|
|
|
|
|
|
if result["Lines"].(int) == 0 && result["StartLine"] == result["EndLine"] && result["StartLine"].(int) != 0 { |
|
|
|
content = content + ctx.Data["existStr"].(string) |
|
|
|
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 { |
|
|
|
if ctx.Data["existStr"] != nil && result["Lines"].(int) < 50 { |
|
|
|
content = content + ctx.Data["existStr"].(string) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
logFileName := result["FileName"] |
|
|
|