From 57194649cff02c820cc76e1f5515c7184ec365b4 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Mon, 4 Jan 2021 17:14:41 +0800 Subject: [PATCH] taskInfo --- models/cloudbrain.go | 7 +++++++ modules/cloudbrain/cloudbrain.go | 1 + routers/repo/cloudbrain.go | 31 ++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 8cf2132f9..1124e3470 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -130,6 +130,13 @@ type TaskPod struct { } `json:"taskStatuses"` } + +type TaskInfo struct { + Username string `json:"username"` + TaskName string `json:"task_name"` + CodeName string `json:"code_name"` +} + func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) { data, _ := json.Marshal(input) var taskPod TaskPod diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 394b29432..264efd6b4 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -15,6 +15,7 @@ const ( DataSetMountPath = "/dataset" ModelMountPath = "/model" BenchMarkMountPath = "/benchmark" + TaskInfoName = "/taskInfo" SubTaskName = "task1" diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 1c8ce8035..14160ec94 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -2,6 +2,7 @@ package repo import ( "code.gitea.io/gitea/modules/git" + "encoding/json" "errors" "os" "os/exec" @@ -132,7 +133,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { } benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath - downloadBenchmarkCode(benchmarkPath) + downloadBenchmarkCode(repo, jobName, benchmarkPath) err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath) if err != nil { @@ -261,7 +262,7 @@ func downloadCode(repo *models.Repository, codePath string) error { return nil } -func downloadBenchmarkCode(benchmarkPath string) error { +func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPath string) error { err := os.MkdirAll(benchmarkPath, os.ModePerm) if err != nil { log.Error("mkdir benchmarkPath failed", err.Error()) @@ -277,6 +278,30 @@ func downloadBenchmarkCode(benchmarkPath string) error { return err } - //todo: write sth into a config file + fileName := benchmarkPath + cloudbrain.TaskInfoName + f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) + if err != nil { + log.Error("OpenFile failed", err.Error()) + return err + } + + defer f.Close() + + data, err := json.Marshal(models.TaskInfo{ + Username: repo.Owner.Name, + TaskName: taskName, + CodeName: repo.Name, + }) + if err != nil { + log.Error("json.Marshal failed", err.Error()) + return err + } + + _, err = f.Write(data) + if err != nil { + log.Error("WriteString failed", err.Error()) + return err + } + return nil }