diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index a027624f4..350889a3f 100755 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -1061,6 +1061,11 @@ ENABLED = true BENCHMARKCODE = https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git HOST = http://192.168.202.90:3366/ +[snn4imagenet] +ENABLED = true +SNN4IMAGENETCODE = https://yult:eh2Ten4iLYjFkbj@git.openi.org.cn/ylt/snn4imagenet.git +HOST = http://192.168.202.90:3366/ + [decompress] HOST = http://192.168.207.34:39987 USER = cW4cMtH24eoWPE7X diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 036c25264..9784a58b5 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -25,6 +25,7 @@ const ( JobTypeDebug JobType = "DEBUG" JobTypeBenchmark JobType = "BENCHMARK" + JobTypeSnn4imagenet JobType = "SNN4IMAGENET" ModelArtsCreateQueue ModelArtsJobStatus = "CREATE_QUEUING" //免费资源创建排队中 ModelArtsCreating ModelArtsJobStatus = "CREATING" //创建中 diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 50de926ca..551353bd5 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -15,6 +15,7 @@ const ( DataSetMountPath = "/dataset" ModelMountPath = "/model" BenchMarkMountPath = "/benchmark" + Snn4imagenetMountPath = "/snn4imagenet" TaskInfoName = "/taskInfo" SubTaskName = "task1" @@ -22,7 +23,7 @@ const ( Success = "S000" ) -func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType string) error { +func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType string) error { dataActualPath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath + @@ -78,6 +79,13 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, ReadOnly: true, }, }, + { + HostPath: models.StHostPath{ + Path: snn4imagenetPath, + MountPath: Snn4imagenetMountPath, + ReadOnly: true, + }, + }, }, }) if err != nil { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 3e71804ab..65fddc7a0 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -444,6 +444,11 @@ var ( BenchmarkCode string BenchmarkServerHost string + //snn4imagenet config + IsSnn4imagenetEnabled bool + Snn4imagenetCode string + Snn4imagenetServerHost string + //blockchain config BlockChainHost string CommitValidDate string @@ -1146,6 +1151,11 @@ func NewContext() { BenchmarkCode = sec.Key("BENCHMARKCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git") BenchmarkServerHost = sec.Key("HOST").MustString("http://192.168.202.90:3366/") + sec = Cfg.Section("snn4imagenet") + IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false) + Snn4imagenetCode = sec.Key("SNN4IMAGENETCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git") + Snn4imagenetServerHost = sec.Key("HOST").MustString("http://192.168.202.90:3366/") + sec = Cfg.Section("blockchain") BlockChainHost = sec.Key("HOST").MustString("http://192.168.136.66:3302/") CommitValidDate = sec.Key("COMMIT_VALID_DATE").MustString("2021-01-15") diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index d0e662505..30542e26e 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -131,6 +131,8 @@ func CloudBrainNew(ctx *context.Context) { ctx.Data["model_path"] = cloudbrain.ModelMountPath ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled + ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath + ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled ctx.HTML(200, tplCloudBrainNew) } @@ -143,7 +145,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { jobType := form.JobType codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath - if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) { + if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet){ log.Error("jobtype error:", jobType) ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) return @@ -160,10 +162,15 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { - downloadBenchmarkCode(repo, jobName, benchmarkPath) + downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath) } - err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType) + snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath + if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) { + downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath) + } + + err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType) if err != nil { ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) return @@ -304,15 +311,21 @@ func CloudBrainDel(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } -func CloudBrainBenchmark(ctx *context.Context) { +func GetRate(ctx *context.Context) { var jobID = ctx.Params(":jobid") - _, err := models.GetCloudbrainByJobID(jobID) + job, err := models.GetCloudbrainByJobID(jobID) if err != nil { ctx.ServerError("GetCloudbrainByJobID failed", err) return } - ctx.Redirect(setting.BenchmarkServerHost) + if job.JobType == string(models.JobTypeBenchmark) { + ctx.Redirect(setting.BenchmarkServerHost) + } else if job.JobType == string(models.JobTypeSnn4imagenet) { + ctx.Redirect(setting.Snn4imagenetServerHost) + } else { + log.Error("JobType error:", job.JobType) + } } func downloadCode(repo *models.Repository, codePath string) error { @@ -324,14 +337,14 @@ func downloadCode(repo *models.Repository, codePath string) error { return nil } -func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPath string) error { - err := os.MkdirAll(benchmarkPath, os.ModePerm) +func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath string) error { + err := os.MkdirAll(codePath, os.ModePerm) if err != nil { - log.Error("mkdir benchmarkPath failed", err.Error()) + log.Error("mkdir codePath failed", err.Error()) return err } - command := "git clone " + setting.BenchmarkCode + " " + benchmarkPath + command := "git clone " + gitPath + " " + codePath cmd := exec.Command("/bin/bash", "-c", command) output, err := cmd.Output() log.Info(string(output)) @@ -340,7 +353,7 @@ func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPa return err } - fileName := benchmarkPath + cloudbrain.TaskInfoName + fileName := codePath + 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()) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 57f563cb8..7237fedff 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -532,7 +532,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/get_multipart_url", repo.GetMultipartUploadUrl) m.Post("/complete_multipart", repo.CompleteMultipart) m.Post("/update_chunk", repo.UpdateMultipart) - m.Get("/get_obs_key", repo.GetObsKey) }, reqSignIn) m.Group("/attachments", func() { @@ -911,7 +910,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/commit_image", reqRepoCloudBrainWriter, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", reqRepoCloudBrainWriter, repo.CloudBrainStop) m.Post("/del", reqRepoCloudBrainWriter, repo.CloudBrainDel) - m.Get("/benchmark", reqRepoCloudBrainWriter, repo.CloudBrainBenchmark) + m.Get("/rate", reqRepoCloudBrainWriter, repo.GetRate) }) m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index e2197e3b8..0dc0aa090 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -269,7 +269,7 @@