Reviewed-by: 史梦园 <1729788216@qq.com>tags/v1.21.12.1
| @@ -165,6 +165,7 @@ type TaskInfo struct { | |||||
| Username string `json:"username"` | Username string `json:"username"` | ||||
| TaskName string `json:"task_name"` | TaskName string `json:"task_name"` | ||||
| CodeName string `json:"code_name"` | CodeName string `json:"code_name"` | ||||
| BenchmarkCategory string `json:"selected_category"` | |||||
| } | } | ||||
| func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) { | func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) { | ||||
| @@ -265,6 +266,15 @@ type ImageInfo struct { | |||||
| PlaceView string | PlaceView string | ||||
| } | } | ||||
| type Categories struct { | |||||
| Category []*Category `json:"category"` | |||||
| } | |||||
| type Category struct { | |||||
| Id int `json:"id"` | |||||
| Value string `json:"value"` | |||||
| } | |||||
| type CommitImageParams struct { | type CommitImageParams struct { | ||||
| Ip string `json:"ip"` | Ip string `json:"ip"` | ||||
| TaskContainerId string `json:"taskContainerId"` | TaskContainerId string `json:"taskContainerId"` | ||||
| @@ -11,6 +11,7 @@ type CreateCloudBrainForm struct { | |||||
| Command string `form:"command" binding:"Required"` | Command string `form:"command" binding:"Required"` | ||||
| Attachment string `form:"attachment" binding:"Required"` | Attachment string `form:"attachment" binding:"Required"` | ||||
| JobType string `form:"job_type" binding:"Required"` | JobType string `form:"job_type" binding:"Required"` | ||||
| BenchmarkCategory string `form:"get_benchmark_category"` | |||||
| } | } | ||||
| type CommitImageCloudBrainForm struct { | type CommitImageCloudBrainForm struct { | ||||
| @@ -443,6 +443,7 @@ var ( | |||||
| IsBenchmarkEnabled bool | IsBenchmarkEnabled bool | ||||
| BenchmarkCode string | BenchmarkCode string | ||||
| BenchmarkServerHost string | BenchmarkServerHost string | ||||
| BenchmarkCategory string | |||||
| //snn4imagenet config | //snn4imagenet config | ||||
| IsSnn4imagenetEnabled bool | IsSnn4imagenetEnabled bool | ||||
| @@ -1150,6 +1151,7 @@ func NewContext() { | |||||
| IsBenchmarkEnabled = sec.Key("ENABLED").MustBool(false) | IsBenchmarkEnabled = sec.Key("ENABLED").MustBool(false) | ||||
| BenchmarkCode = sec.Key("BENCHMARKCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git") | 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/") | BenchmarkServerHost = sec.Key("HOST").MustString("http://192.168.202.90:3366/") | ||||
| BenchmarkCategory = sec.Key("CATEGORY").MustString("") | |||||
| sec = Cfg.Section("snn4imagenet") | sec = Cfg.Section("snn4imagenet") | ||||
| IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false) | IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false) | ||||
| @@ -108,7 +108,6 @@ func CloudBrainNew(ctx *context.Context) { | |||||
| } | } | ||||
| for i, payload := range resultPublic.Payload.ImageInfo { | for i, payload := range resultPublic.Payload.ImageInfo { | ||||
| log.Info(resultPublic.Payload.ImageInfo[i].Place) | |||||
| if strings.HasPrefix(resultPublic.Payload.ImageInfo[i].Place, "192.168") { | if strings.HasPrefix(resultPublic.Payload.ImageInfo[i].Place, "192.168") { | ||||
| resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)] | resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)] | ||||
| } else { | } else { | ||||
| @@ -131,6 +130,10 @@ func CloudBrainNew(ctx *context.Context) { | |||||
| ctx.Data["model_path"] = cloudbrain.ModelMountPath | ctx.Data["model_path"] = cloudbrain.ModelMountPath | ||||
| ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath | ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath | ||||
| ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled | ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled | ||||
| var categories *models.Categories | |||||
| json.Unmarshal([]byte(setting.BenchmarkCategory), &categories) | |||||
| ctx.Data["benchmark_categories"] = categories.Category | |||||
| ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath | ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath | ||||
| ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled | ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled | ||||
| ctx.HTML(200, tplCloudBrainNew) | ctx.HTML(200, tplCloudBrainNew) | ||||
| @@ -162,12 +165,12 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||||
| benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath | benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath | ||||
| if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { | if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { | ||||
| downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath) | |||||
| downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath, form.BenchmarkCategory) | |||||
| } | } | ||||
| snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath | snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath | ||||
| if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) { | if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) { | ||||
| downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath) | |||||
| downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath, "") | |||||
| } | } | ||||
| err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType) | err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType) | ||||
| @@ -258,16 +261,15 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain | |||||
| func CloudBrainStop(ctx *context.Context) { | func CloudBrainStop(ctx *context.Context) { | ||||
| var jobID = ctx.Params(":jobid") | var jobID = ctx.Params(":jobid") | ||||
| log.Info(jobID) | |||||
| task, err := models.GetCloudbrainByJobID(jobID) | task, err := models.GetCloudbrainByJobID(jobID) | ||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("GetCloudbrainByJobID failed", err) | ctx.ServerError("GetCloudbrainByJobID failed", err) | ||||
| return | return | ||||
| } | } | ||||
| if task.Status != string(models.JobRunning) { | |||||
| log.Error("the job(%s) is not running", task.JobName) | |||||
| ctx.ServerError("the job is not running", errors.New("the job is not running")) | |||||
| if task.Status == string(models.JobStopped) { | |||||
| log.Error("the job(%s) has been stopped", task.JobName) | |||||
| ctx.ServerError("the job has been stopped", errors.New("the job has been stopped")) | |||||
| return | return | ||||
| } | } | ||||
| @@ -337,7 +339,7 @@ func downloadCode(repo *models.Repository, codePath string) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath string) error { | |||||
| func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benchmarkCategory string) error { | |||||
| err := os.MkdirAll(codePath, os.ModePerm) | err := os.MkdirAll(codePath, os.ModePerm) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("mkdir codePath failed", err.Error()) | log.Error("mkdir codePath failed", err.Error()) | ||||
| @@ -366,6 +368,7 @@ func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath strin | |||||
| Username: repo.Owner.Name, | Username: repo.Owner.Name, | ||||
| TaskName: taskName, | TaskName: taskName, | ||||
| CodeName: repo.Name, | CodeName: repo.Name, | ||||
| BenchmarkCategory: benchmarkCategory, | |||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("json.Marshal failed", err.Error()) | log.Error("json.Marshal failed", err.Error()) | ||||
| @@ -33,7 +33,7 @@ | |||||
| <div class="sixteen wide mobile eight wide tablet eight wide computer column" style=" margin:2.0rem 0"> | <div class="sixteen wide mobile eight wide tablet eight wide computer column" style=" margin:2.0rem 0"> | ||||
| {{.i18n.Tr "custom.foot.copyright"}} <a href="http://beian.miit.gov.cn/" target="_blank">京ICP备18004880号-2</a> | {{.i18n.Tr "custom.foot.copyright"}} <a href="http://beian.miit.gov.cn/" target="_blank">京ICP备18004880号-2</a> | ||||
| <br> | <br> | ||||
| {{.i18n.Tr "powered_by 鹏城实验室云脑、"}}<a href="https://www.trustie.net/" target="_blank">Trustie确实</a>、{{.i18n.Tr "、gitea"}} | |||||
| {{.i18n.Tr "powered_by 鹏城实验室云脑、"}}<a href="https://www.trustie.net/" target="_blank">Trustie确实</a>{{.i18n.Tr "、gitea"}} | |||||
| <br> | <br> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -297,9 +297,9 @@ | |||||
| <!-- 停止 --> | <!-- 停止 --> | ||||
| <div class="one wide column"> | <div class="one wide column"> | ||||
| <div class="ui text center clipboard"> | <div class="ui text center clipboard"> | ||||
| <form id="stopForm-{{.JobID}}" action="{{if ne .Status "RUNNING"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/stop{{end}}" method="post"> | |||||
| <form id="stopForm-{{.JobID}}" action="{{if eq .Status "STOPPED"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/stop{{end}}" method="post"> | |||||
| {{$.CsrfTokenHtml}} | {{$.CsrfTokenHtml}} | ||||
| <a class="fitted" onclick="document.getElementById('stopForm-{{.JobID}}').submit();" style="{{if ne .Status "RUNNING"}}color:#CCCCCC{{end}}; font-size:16px; font-weight:bold">停止</a> | |||||
| <a class="fitted" onclick="document.getElementById('stopForm-{{.JobID}}').submit();" style="{{if eq .Status "STOPPED"}}color:#CCCCCC{{end}}; font-size:16px; font-weight:bold">停止</a> | |||||
| </form> | </form> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -110,7 +110,6 @@ | |||||
| {{.i18n.Tr "repo.cloudbrain.new"}} | {{.i18n.Tr "repo.cloudbrain.new"}} | ||||
| </h3> | </h3> | ||||
| <div class="ui attached segment"> | <div class="ui attached segment"> | ||||
| <!-- <br> --> | |||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>任务名称</label> | <label>任务名称</label> | ||||
| <input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255"> | <input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255"> | ||||
| @@ -125,6 +124,17 @@ | |||||
| </select> | </select> | ||||
| </div> | </div> | ||||
| <div class="inline required field cloudbrain_benchmark"> | |||||
| <label style="vertical-align: top; margin-top:9px">数据集类别</label> | |||||
| <select class="ui search dropdown" multiple="multiple" id="cloudbrain_benchmark_category" style='width:385px'> | |||||
| {{range .benchmark_categories}} | |||||
| <option value="{{.Value}}">{{.Value}}</option> | |||||
| {{end}} | |||||
| </select> | |||||
| </div> | |||||
| <input id="store_category" type="hidden" name="get_benchmark_category"> | |||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>镜像</label> | <label>镜像</label> | ||||
| <select class="ui search dropdown" id="cloudbrain_image" placeholder="选择镜像" style='width:385px' name="image"> | <select class="ui search dropdown" id="cloudbrain_image" placeholder="选择镜像" style='width:385px' name="image"> | ||||
| @@ -170,6 +180,7 @@ | |||||
| <label>启动命令</label> | <label>启动命令</label> | ||||
| <textarea name="command" rows="10" readonly="readonly">{{.command}}</textarea> | <textarea name="command" rows="10" readonly="readonly">{{.command}}</textarea> | ||||
| </div> | </div> | ||||
| <div class="inline field"> | <div class="inline field"> | ||||
| <label></label> | <label></label> | ||||
| <button class="ui green button" onclick="showmask()"> | <button class="ui green button" onclick="showmask()"> | ||||
| @@ -196,7 +207,12 @@ | |||||
| document.getElementById("mask").style.display = "none" | document.getElementById("mask").style.display = "none" | ||||
| } | } | ||||
| } | } | ||||
| $('#cloudbrain_benchmark_category') | |||||
| .dropdown({ | |||||
| placeholder: "选择数据集类别", | |||||
| }) | |||||
| $('select.dropdown') | $('select.dropdown') | ||||
| .dropdown(); | .dropdown(); | ||||
| @@ -212,4 +228,10 @@ | |||||
| } | } | ||||
| }) | }) | ||||
| }) | }) | ||||
| $('.ui.green.button').click(function() { | |||||
| selected_value = $("#cloudbrain_benchmark_category").val() | |||||
| $('#store_category').attr("value", selected_value) | |||||
| }) | |||||
| </script> | </script> | ||||