diff --git a/Makefile b/Makefile index 61df2ef76..b621ff5e5 100644 --- a/Makefile +++ b/Makefile @@ -616,20 +616,20 @@ update-translations: generate-images: $(eval TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')) mkdir -p $(TMPDIR)/images - inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png - inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png - inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png - inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png - inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png + inkscape $(PWD)/assets/logo.svg -w 880 -h 880 --export-filename=$(PWD)/public/img/gitea-lg.png + inkscape $(PWD)/assets/logo.svg -w 512 -h 512 --export-filename=$(PWD)/public/img/gitea-512.png + inkscape $(PWD)/assets/logo.svg -w 192 -h 192 --export-filename=$(PWD)/public/img/gitea-192.png + inkscape $(PWD)/assets/logo.svg -w 120 -h 120 --export-filename=$(TMPDIR)/images/sm-1.png + inkscape $(PWD)/assets/logo.svg -w 120 -h 120 --export-filename=$(TMPDIR)/images/sm-2.png composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png - inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png - inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png - inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png - inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png - inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png - inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png + inkscape $(PWD)/assets/logo.svg -w 200 -h 200 --export-filename=$(PWD)/public/img/avatar_default.png + inkscape $(PWD)/assets/logo.svg -w 180 -h 180 --export-filename=$(PWD)/public/img/favicon.png + inkscape $(PWD)/assets/logo.svg -w 128 -h 128 --export-filename=$(TMPDIR)/images/128-raw.png + inkscape $(PWD)/assets/logo.svg -w 64 -h 64 --export-filename=$(TMPDIR)/images/64-raw.png + inkscape $(PWD)/assets/logo.svg -w 32 -h 32 --export-filename=$(TMPDIR)/images/32-1.png + inkscape $(PWD)/assets/logo.svg -w 32 -h 32 --export-filename=$(TMPDIR)/images/32-2.png composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png - inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png + inkscape $(PWD)/assets/logo.svg -w 16 -h 16 --export-filename=$(TMPDIR)/images/16-raw.png zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png diff --git a/assets/logo.svg b/assets/logo.svg index ac1594adb..65e0e4d62 100644 --- a/assets/logo.svg +++ b/assets/logo.svg @@ -1,160 +1,13 @@ - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/models/attachment.go b/models/attachment.go index 2e39800f6..e456a09ca 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -43,6 +43,8 @@ type Attachment struct { DecompressState int32 `xorm:"DEFAULT 0"` Type int `xorm:"DEFAULT 0"` CreatedUnix timeutil.TimeStamp `xorm:"created"` + + FileChunk *FileChunk `xorm:"-"` } type AttachmentUsername struct { diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 17ce565d0..f01d1e1a5 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -171,6 +171,7 @@ type TaskInfo struct { CodeName string `json:"code_name"` BenchmarkCategory []string `json:"selected_category"` CodeLink string `json:"code_link"` + GpuType string `json:"gpu_type"` } func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) { @@ -280,6 +281,16 @@ type Category struct { Value string `json:"value"` } +type GpuInfos struct { + GpuInfo []*GpuInfo `json:"gpu_type"` +} + +type GpuInfo struct { + Id int `json:"id"` + Value string `json:"value"` + Queue string `json:"queue"` +} + type CommitImageParams struct { Ip string `json:"ip"` TaskContainerId string `json:"taskContainerId"` diff --git a/models/dataset.go b/models/dataset.go index b307a1352..f4713d77b 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -235,6 +235,14 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err for sortedRels.ID[currentIndex] < attachment.DatasetID { currentIndex++ } + fileChunks := make([]*FileChunk, 0, 10) + err = e. + Where("uuid = ?", attachment.UUID). + Find(&fileChunks) + if err != nil { + return err + } + attachment.FileChunk = fileChunks[0] sortedRels.Rel[currentIndex].Attachments = append(sortedRels.Rel[currentIndex].Attachments, attachment) } diff --git a/models/repo.go b/models/repo.go index e431e0248..be84a462e 100755 --- a/models/repo.go +++ b/models/repo.go @@ -6,14 +6,12 @@ package models import ( + "code.gitea.io/gitea/modules/blockchain" "context" "crypto/md5" "errors" "fmt" "html/template" - "sync" - - "code.gitea.io/gitea/modules/blockchain" // Needed for jpeg support _ "image/jpeg" @@ -2409,15 +2407,6 @@ func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) { return nil, nil } -var lck sync.Mutex - -func (repo *Repository) IncreaseCloneCnt() { - lck.Lock() - defer lck.Unlock() - repo.CloneCnt++ - _ = UpdateRepositoryCols(repo, "clone_cnt") -} - func updateRepositoryCols(e Engine, repo *Repository, cols ...string) error { _, err := e.ID(repo.ID).Cols(cols...).Update(repo) return err @@ -2434,3 +2423,21 @@ func GetBlockChainUnSuccessRepos() ([]*Repository, error) { Where("block_chain_status != ?", RepoBlockChainSuccess). Find(&repos) } + +func (repo *Repository) IncreaseCloneCnt() { + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return + } + if _, err := sess.Exec("UPDATE `repository` SET clone_cnt = clone_cnt + 1 WHERE id = ?", repo.ID); err != nil { + return + } + + if err := sess.Commit(); err != nil { + return + } + + return +} diff --git a/modules/auth/cloudbrain.go b/modules/auth/cloudbrain.go index b4f0c8f7c..8325dc063 100755 --- a/modules/auth/cloudbrain.go +++ b/modules/auth/cloudbrain.go @@ -12,6 +12,7 @@ type CreateCloudBrainForm struct { Attachment string `form:"attachment" binding:"Required"` JobType string `form:"job_type" binding:"Required"` BenchmarkCategory string `form:"get_benchmark_category"` + GpuType string `form:"gpu_type"` } type CommitImageCloudBrainForm struct { diff --git a/modules/auth/dataset.go b/modules/auth/dataset.go old mode 100644 new mode 100755 index f9658a0d6..577637273 --- a/modules/auth/dataset.go +++ b/modules/auth/dataset.go @@ -31,4 +31,5 @@ type EditDatasetForm struct { Private bool ReleaseID int64 `xorm:"INDEX"` Files []string + Type string `binding:"Required"` } diff --git a/modules/base/tool.go b/modules/base/tool.go index 157bd9bc3..8145522e2 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -21,6 +21,7 @@ import ( "strings" "time" "unicode" + "unicode/utf8" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -287,19 +288,19 @@ func EllipsisString(str string, length int) string { if length <= 3 { return "..." } - if len(str) <= length { + if utf8.RuneCountInString(str) <= length { return str } - return str[:length-3] + "..." + return string([]rune(str)[:length-3]) + "..." } // TruncateString returns a truncated string with given limit, // it returns input string if length is not reached limit. func TruncateString(str string, limit int) string { - if len(str) < limit { + if utf8.RuneCountInString(str) < limit { return str } - return str[:limit] + return string([]rune(str)[:limit]) } // StringsToInt64s converts a slice of string to a slice of int64. diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 9371be77b..a0070658e 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -23,7 +23,7 @@ const ( Success = "S000" ) -func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType string) error { +func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue string) error { dataActualPath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath + @@ -32,7 +32,7 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, jobResult, err := CreateJob(jobName, models.CreateJobParams{ JobName: jobName, RetryCount: 1, - GpuType: setting.JobType, + GpuType: gpuQueue, Image: image, TaskRoles: []models.TaskRole{ { diff --git a/modules/cloudbrain/resty.go b/modules/cloudbrain/resty.go index 3fb3abc52..ed6157776 100755 --- a/modules/cloudbrain/resty.go +++ b/modules/cloudbrain/resty.go @@ -1,6 +1,7 @@ package cloudbrain import ( + "code.gitea.io/gitea/modules/log" "fmt" "code.gitea.io/gitea/models" @@ -14,6 +15,10 @@ var ( TOKEN string ) +const ( + JobHasBeenStopped = "S410" +) + func getRestyClient() *resty.Client { if restyClient == nil { restyClient = resty.New() @@ -240,7 +245,11 @@ sendjob: } if result.Code != Success { - return fmt.Errorf("StopJob err: %s", res.String()) + if result.Code == JobHasBeenStopped { + log.Info("StopJob(%s) failed:%s", jobID, result.Msg) + } else { + return fmt.Errorf("StopJob err: %s", res.String()) + } } return nil diff --git a/modules/log/logger.go b/modules/log/logger.go old mode 100644 new mode 100755 index 9704ffd3d..c9ed8fb2a --- a/modules/log/logger.go +++ b/modules/log/logger.go @@ -67,19 +67,43 @@ func (l *Logger) Log(skip int, level Level, format string, v ...interface{}) err caller = fn.Name() + "()" } } - msg := format - if len(v) > 0 { - msg = ColorSprintf(format, v...) - } + stack := "" if l.GetStacktraceLevel() <= level { stack = Stack(skip + 1) } - return l.SendLog(level, caller, strings.TrimPrefix(filename, prefix), line, msg, stack) + + msg := format + if len(v) > 0 { + switch v[len(v)-1].(type) { + case string: + if !strings.Contains(v[len(v)-1].(string), "-") { + //has no msgID + msg = ColorSprintf(format, v...) + return l.SendLog(level, caller, strings.TrimPrefix(filename, prefix), line, msg, "", stack) + } else { + if len(v) > 1 { + args := make([]interface{}, len(v)-1) + for i := 0; i < len(v)-1; i++ { + args[i] = v[i] + } + msg = ColorSprintf(format, args...) + } + return l.SendLog(level, caller, strings.TrimPrefix(filename, prefix), line, msg, v[len(v)-1].(string), stack) + } + default: + //has no msgID + msg = ColorSprintf(format, v...) + return l.SendLog(level, caller, strings.TrimPrefix(filename, prefix), line, msg, "", stack) + } + } else { + //has no msgID + return l.SendLog(level, caller, strings.TrimPrefix(filename, prefix), line, msg, "", stack) + } } // SendLog sends a log event at the provided level with the information given -func (l *Logger) SendLog(level Level, caller, filename string, line int, msg string, stack string) error { +func (l *Logger) SendLog(level Level, caller, filename string, line int, msg, msgID, stack string) error { if l.GetLevel() > level { return nil } @@ -88,7 +112,7 @@ func (l *Logger) SendLog(level Level, caller, filename string, line int, msg str caller: caller, filename: filename, line: line, - msg: msg, + msg: msg + "[" + msgID + "]", time: time.Now(), stacktrace: stack, } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 1f2d4dfba..b5a0ca005 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -437,6 +437,7 @@ var ( RestServerHost string JobPath string JobType string + GpuTypes string DebugServerHost string //benchmark config @@ -1146,7 +1147,8 @@ func NewContext() { RestServerHost = sec.Key("REST_SERVER_HOST").MustString("http://192.168.202.73") JobPath = sec.Key("JOB_PATH").MustString("/datasets/minio/data/opendata/jobs/") DebugServerHost = sec.Key("DEBUG_SERVER_HOST").MustString("http://192.168.202.73") - JobType = sec.Key("JOB_TYPE").MustString("debug_openi") + JobType = sec.Key("GPU_TYPE_DEFAULT").MustString("openidebug") + GpuTypes = sec.Key("GPU_TYPES").MustString("openidebug,openidgx") sec = Cfg.Section("benchmark") IsBenchmarkEnabled = sec.Key("ENABLED").MustBool(false) diff --git a/modules/storage/minio.go b/modules/storage/minio.go old mode 100644 new mode 100755 index 83a60f376..b14442d56 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -83,7 +83,7 @@ func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string, er reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"") var preURL *url.URL - preURL, err := m.client.PresignedGetObject(m.bucket, m.buildMinioPath(path), PresignedGetUrlExpireTime, reqParams) + preURL, err := m.client.PresignedGetObject(m.bucket, path, PresignedGetUrlExpireTime, reqParams) if err != nil { return "", err } diff --git a/modules/structs/repo.go b/modules/structs/repo.go old mode 100644 new mode 100755 diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6c530002c..c4956c65f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -391,7 +391,8 @@ follow = Follow unfollow = Unfollow heatmap.loading = Loading Heatmap… user_bio = Biography - +own = Own +all = All form.name_reserved = The username '%s' is reserved. form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username. form.name_chars_not_allowed = User name '%s' contains invalid characters. @@ -753,6 +754,7 @@ cloudbrain.new=New cloudbrain cloudbrain.desc=cloudbrain cloudbrain.cancel=Cancel cloudbrain.commit_image = submit +clone_cnt=download balance = balance balance.total_view = total balance balance.available = available balance: diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 81522e06f..607af0cd4 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1,4 +1,5 @@ home=个人中心 +index=首页 dashboard=个人中心 explore=探索 datasets=数据集 @@ -391,7 +392,8 @@ follow=关注 unfollow=取消关注 heatmap.loading=正在加载热图... user_bio=简历 - +own = 个人 +all = 所有 form.name_reserved='%s' 用户名被保留。 form.name_pattern_not_allowed=用户名中不允许使用 "%s"。 form.name_chars_not_allowed=用户名 '%s' 包含无效字符。 @@ -642,6 +644,7 @@ public=公有 dir=目录 back=返回 copy_url=复制下载链接 +copy_md5=复制文件MD5 directory=查看数据集目录结构 visibility=可见性 visibility_description=只有组织所有人或拥有权利的组织成员才能看到。 @@ -753,6 +756,7 @@ cloudbrain.new=新建任务 cloudbrain.desc=云脑功能 cloudbrain.cancel=取消 cloudbrain.commit_image=提交 +clone_cnt=次下载 balance=余额 balance.total_view=余额总览 balance.available=可用余额: diff --git a/public/img/404.png b/public/img/404.png index a57f44d6e..61cd093d6 100644 Binary files a/public/img/404.png and b/public/img/404.png differ diff --git a/public/img/500.png b/public/img/500.png index 099a5be1c..1f0afe204 100644 Binary files a/public/img/500.png and b/public/img/500.png differ diff --git a/public/img/apple-touch-icon.png b/public/img/apple-touch-icon.png index d2def0bdc..ec276009b 100644 Binary files a/public/img/apple-touch-icon.png and b/public/img/apple-touch-icon.png differ diff --git a/public/img/avatar_default.png b/public/img/avatar_default.png index 455155db1..94a3900d4 100644 Binary files a/public/img/avatar_default.png and b/public/img/avatar_default.png differ diff --git a/public/img/emoji/gitea.png b/public/img/emoji/gitea.png index 69e0ce986..8a079410e 100644 Binary files a/public/img/emoji/gitea.png and b/public/img/emoji/gitea.png differ diff --git a/public/img/favicon.ico b/public/img/favicon.ico index 681d76d33..3e1700266 100644 Binary files a/public/img/favicon.ico and b/public/img/favicon.ico differ diff --git a/public/img/favicon.png b/public/img/favicon.png index e4dbb4a9a..179324343 100644 Binary files a/public/img/favicon.png and b/public/img/favicon.png differ diff --git a/public/img/feishu.png b/public/img/feishu.png index 2c3ab7441..aa81d2ca8 100644 Binary files a/public/img/feishu.png and b/public/img/feishu.png differ diff --git a/public/img/gitea-192.png b/public/img/gitea-192.png index 12caba8d5..136d7f954 100644 Binary files a/public/img/gitea-192.png and b/public/img/gitea-192.png differ diff --git a/public/img/gitea-512.png b/public/img/gitea-512.png index 456abfa0c..ee151a280 100644 Binary files a/public/img/gitea-512.png and b/public/img/gitea-512.png differ diff --git a/public/img/gitea-lg.png b/public/img/gitea-lg.png index 682ceaf7b..f046587a8 100644 Binary files a/public/img/gitea-lg.png and b/public/img/gitea-lg.png differ diff --git a/public/img/gitea-sm.png b/public/img/gitea-sm.png index 405f40f17..a303865af 100644 Binary files a/public/img/gitea-sm.png and b/public/img/gitea-sm.png differ diff --git a/public/img/org_bg.png b/public/img/org_bg.png index baa8b7d98..26405fd3a 100644 Binary files a/public/img/org_bg.png and b/public/img/org_bg.png differ diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go old mode 100644 new mode 100755 diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 7c0ad1027..f63c09b05 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -205,7 +205,7 @@ func GetAttachment(ctx *context.Context) { if setting.Attachment.StoreType == storage.MinioStorageType { url := "" if typeCloudBrain == models.TypeCloudBrainOne { - url, err = storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name) + url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath + attach.RelativePath(), attach.Name) if err != nil { ctx.ServerError("PresignedGetURL", err) return diff --git a/routers/repo/blockchain.go b/routers/repo/blockchain.go index d650e71ca..dc3fcd848 100755 --- a/routers/repo/blockchain.go +++ b/routers/repo/blockchain.go @@ -28,14 +28,14 @@ const ( func BlockChainIndex(ctx *context.Context) { repo := ctx.Repo.Repository if repo.ContractAddress == "" || ctx.User.PublicKey == "" { - log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) + log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID, ctx.Data["msgID"]) ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) return } res, err := blockchain.GetBalance(repo.ContractAddress, ctx.User.PublicKey) if err != nil { - log.Error("GetBalance(%s) failed:%v", ctx.User.PublicKey, err) + log.Error("GetBalance(%s) failed:%s", ctx.User.PublicKey, err, ctx.Data["msgID"]) ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) return } @@ -52,7 +52,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { repo, err := models.GetRepositoryByID(req.RepoId) if err != nil { - log.Error("GetRepositoryByID failed:", err.Error()) + log.Error("GetRepositoryByID failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -61,7 +61,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { } if repo.BlockChainStatus == models.RepoBlockChainSuccess && len(repo.ContractAddress) != 0 { - log.Error("the repo has been RepoBlockChainSuccess:", req.RepoId) + log.Error("the repo has been RepoBlockChainSuccess:%d", req.RepoId, ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "the repo has been RepoBlockChainSuccess", @@ -73,7 +73,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { repo.ContractAddress = req.ContractAddress if err = models.UpdateRepositoryCols(repo, "block_chain_status", "contract_address"); err != nil { - log.Error("UpdateRepositoryCols failed:", err.Error()) + log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -91,7 +91,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { var req BlockChainCommitNotify data, _ := ctx.Req.Body().Bytes() if err := json.Unmarshal(data, &req); err != nil { - log.Error("json.Unmarshal failed:", err.Error()) + log.Error("json.Unmarshal failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "response data error", @@ -101,7 +101,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { blockChain, err := models.GetBlockChainByCommitID(req.CommitID) if err != nil { - log.Error("GetRepositoryByID failed:", err.Error()) + log.Error("GetRepositoryByID failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -110,7 +110,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { } if blockChain.Status == models.BlockChainCommitSuccess { - log.Error("the commit has been BlockChainCommitReady:", blockChain.RepoID) + log.Error("the commit has been BlockChainCommitReady:%s", blockChain.RepoID, ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "the commit has been BlockChainCommitReady", @@ -122,7 +122,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { blockChain.TransactionHash = req.TransactionHash if err = models.UpdateBlockChainCols(blockChain, "status", "transaction_hash"); err != nil { - log.Error("UpdateBlockChainCols failed:", err.Error()) + log.Error("UpdateBlockChainCols failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 5ef8f2979..27642d7bb 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -2,8 +2,10 @@ package repo import ( "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/storage" "encoding/json" "errors" + "net/http" "os" "os/exec" "strconv" @@ -23,6 +25,12 @@ const ( tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" tplCloudBrainNew base.TplName = "repo/cloudbrain/new" tplCloudBrainShow base.TplName = "repo/cloudbrain/show" + tplCloudBrainShowModels base.TplName = "repo/cloudbrain/models/index" +) + +var ( + gpuInfos *models.GpuInfos + categories *models.Categories ) // MustEnableDataset check if repository enable internal cb @@ -88,7 +96,7 @@ func CloudBrainNew(ctx *context.Context) { result, err := cloudbrain.GetImages() if err != nil { ctx.Data["error"] = err.Error() - log.Error("cloudbrain.GetImages failed:", err.Error()) + log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["msgID"]) } for i, payload := range result.Payload.ImageInfo { @@ -104,7 +112,7 @@ func CloudBrainNew(ctx *context.Context) { resultPublic, err := cloudbrain.GetPublicImages() if err != nil { ctx.Data["error"] = err.Error() - log.Error("cloudbrain.GetPublicImages failed:", err.Error()) + log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["msgID"]) } for i, payload := range resultPublic.Payload.ImageInfo { @@ -131,9 +139,15 @@ func CloudBrainNew(ctx *context.Context) { ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled - var categories *models.Categories - json.Unmarshal([]byte(setting.BenchmarkCategory), &categories) + if categories == nil { + json.Unmarshal([]byte(setting.BenchmarkCategory), &categories) + } ctx.Data["benchmark_categories"] = categories.Category + + if gpuInfos == nil { + json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) + } + ctx.Data["gpu_types"] = gpuInfos.GpuInfo ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled ctx.HTML(200, tplCloudBrainNew) @@ -146,10 +160,11 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { command := form.Command uuid := form.Attachment jobType := form.JobType + gpuQueue := setting.JobType codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet) { - log.Error("jobtype error:", jobType) + log.Error("jobtype error:", jobType, ctx.Data["msgID"]) ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) return } @@ -165,15 +180,22 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { - downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath, form.BenchmarkCategory) + gpuQueue = form.GpuType + var gpuType string + for _, gpuInfo := range gpuInfos.GpuInfo { + if gpuInfo.Queue == gpuQueue { + gpuType = gpuInfo.Value + } + } + downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath, form.BenchmarkCategory, gpuType) } snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath 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, gpuQueue) if err != nil { ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) return @@ -245,7 +267,7 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain ImageTag: form.Tag, }) if err != nil { - log.Error("CommitImage(%s) failed:", task.JobName, err.Error()) + log.Error("CommitImage(%s) failed:%v", task.JobName, err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "result_code": "-1", "error_msg": "CommitImage failed", @@ -268,14 +290,14 @@ func CloudBrainStop(ctx *context.Context) { } if task.Status == string(models.JobStopped) { - log.Error("the job(%s) has been stopped", task.JobName) + log.Error("the job(%s) has been stopped", task.JobName, ctx.Data["msgID"]) ctx.ServerError("the job has been stopped", errors.New("the job has been stopped")) return } err = cloudbrain.StopJob(jobID) if err != nil { - log.Error("StopJob(%s) failed:%v", task.JobName, err.Error()) + log.Error("StopJob(%s) failed:%v", task.JobName, err.Error(), ctx.Data["msgID"]) ctx.ServerError("StopJob failed", err) return } @@ -299,7 +321,7 @@ func CloudBrainDel(ctx *context.Context) { } if task.Status != string(models.JobStopped) { - log.Error("the job(%s) has not been stopped", task.JobName) + log.Error("the job(%s) has not been stopped", task.JobName, ctx.Data["msgID"]) ctx.ServerError("the job has not been stopped", errors.New("the job has not been stopped")) return } @@ -313,6 +335,69 @@ func CloudBrainDel(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } +func CloudBrainShowModels(ctx *context.Context) { + ctx.Data["PageIsCloudBrain"] = true + + jobID := ctx.Params(":jobid") + parentDir := ctx.Query("parentDir") + dirArray := strings.Split(parentDir, "/") + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + log.Error("no such job!", ctx.Data["msgID"]) + ctx.ServerError("no such job:", err) + return + } + + //get dirs + dirs, err := getModelDirs(task.JobName, parentDir) + if err != nil { + log.Error("getModelDirs failed:%v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("getModelDirs failed:", err) + return + } + + var fileInfos []FileInfo + err = json.Unmarshal([]byte(dirs), &fileInfos) + if err != nil { + log.Error("json.Unmarshal failed:%v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("json.Unmarshal failed:", err) + return + } + + ctx.Data["Path"] = dirArray + ctx.Data["Dirs"] = fileInfos + ctx.Data["task"] = task + ctx.Data["JobID"] = jobID + ctx.HTML(200, tplCloudBrainShowModels) +} + +func getModelDirs(jobName string, parentDir string) (string, error) { + var req string + modelActualPath := setting.JobPath + jobName + "/model/" + if parentDir == "" { + req = "baseDir=" + modelActualPath + } else { + req = "baseDir=" + modelActualPath + "&parentDir=" + parentDir + } + + return getDirs(req) +} + +func CloudBrainDownloadModel(ctx *context.Context) { + parentDir := ctx.Query("parentDir") + fileName := ctx.Query("fileName") + jobName := ctx.Query("jobName") + filePath := "jobs/" +jobName + "/model/" + parentDir + url, err := storage.Attachments.PresignedGetURL(filePath, fileName) + if err != nil { + log.Error("PresignedGetURL failed: %v", err.Error(), ctx.Data["msgID"]) + ctx.ServerError("PresignedGetURL", err) + return + } + + http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) +} + func GetRate(ctx *context.Context) { var jobID = ctx.Params(":jobid") job, err := models.GetCloudbrainByJobID(jobID) @@ -322,11 +407,11 @@ func GetRate(ctx *context.Context) { } if job.JobType == string(models.JobTypeBenchmark) { - ctx.Redirect(setting.BenchmarkServerHost) + ctx.Redirect(setting.BenchmarkServerHost + "?username=" + ctx.User.Name) } else if job.JobType == string(models.JobTypeSnn4imagenet) { ctx.Redirect(setting.Snn4imagenetServerHost) } else { - log.Error("JobType error:", job.JobType) + log.Error("JobType error:%s", job.JobType, ctx.Data["msgID"]) } } @@ -339,7 +424,7 @@ func downloadCode(repo *models.Repository, codePath string) error { return nil } -func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benchmarkCategory string) error { +func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benchmarkCategory, gpuType string) error { err := os.MkdirAll(codePath, os.ModePerm) if err != nil { log.Error("mkdir codePath failed", err.Error()) @@ -370,6 +455,7 @@ func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benc CodeName: repo.Name, BenchmarkCategory: strings.Split(benchmarkCategory, ","), CodeLink: strings.TrimSuffix(repo.CloneLink().HTTPS, ".git"), + GpuType: gpuType, }) if err != nil { log.Error("json.Marshal failed", err.Error()) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 9c8557afa..3be36fbe4 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -49,6 +49,12 @@ func DatasetIndex(ctx *context.Context) { ctx.NotFound("GetDatasetByRepo", err) return } + + if ctx.Query("type") == "" { + log.Error("not found param type") + ctx.NotFound("type error", nil) + return + } err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) if err != nil { ctx.ServerError("GetDatasetAttachments", err) @@ -116,5 +122,5 @@ func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { ctx.HTML(200, tplIndex) log.Error("%v", err) } - ctx.Redirect(ctx.Repo.RepoLink + "/datasets") + ctx.Redirect(ctx.Repo.RepoLink + "/datasets?type=" + form.Type) } diff --git a/routers/repo/dir.go b/routers/repo/dir.go index 388af34ec..d1dfbcd11 100755 --- a/routers/repo/dir.go +++ b/routers/repo/dir.go @@ -58,10 +58,10 @@ func DirIndex(ctx *context.Context) { dirArray = []string{attachment.Name} } - dirs, err := getDirs(uuid, parentDir) + dirs, err := getDatasetDirs(uuid, parentDir) if err != nil { - log.Error("getDirs failed:", err.Error()) - ctx.ServerError("getDirs failed:", err) + log.Error("getDatasetDirs failed:", err.Error()) + ctx.ServerError("getDatasetDirs failed:", err) return } @@ -75,20 +75,31 @@ func DirIndex(ctx *context.Context) { ctx.Data["Path"] = dirArray ctx.Data["Dirs"] = fileInfos + ctx.Data["Uuid"] = uuid ctx.Data["PageIsDataset"] = true ctx.HTML(200, tplDirIndex) } -func getDirs(uuid string, parentDir string) (string, error) { - var dirs string +func getDatasetDirs(uuid string, parentDir string) (string, error) { var req string + dataActualPath := setting.Attachment.Minio.RealPath + + setting.Attachment.Minio.Bucket + "/" + + setting.Attachment.Minio.BasePath + + models.AttachmentRelativePath(uuid) + + uuid + "/" if parentDir == "" { - req = "uuid=" + uuid + req = "baseDir=" + dataActualPath } else { - req = "uuid=" + uuid + "&parentDir=" + parentDir + req = "baseDir=" + dataActualPath + "&parentDir=" + parentDir } + return getDirs(req) +} + +func getDirs(req string) (string, error) { + var dirs string + url := setting.DecompressAddress + "/dirs?" + req reqHttp, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { @@ -127,6 +138,5 @@ func getDirs(uuid string, parentDir string) (string, error) { } dirs = resp.FileInfos - return dirs, nil } diff --git a/routers/repo/download.go b/routers/repo/download.go old mode 100644 new mode 100755 index 7ef0574b1..5b8982102 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -8,6 +8,7 @@ package repo import ( "fmt" "io" + "net/url" "path" "strings" @@ -32,6 +33,7 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { // Google Chrome dislike commas in filenames, so let's change it to a space name = strings.Replace(name, ",", " ", -1) + name = url.QueryEscape(name) if base.IsTextFile(buf) || ctx.QueryBool("render") { cs, err := charset.DetectEncoding(buf) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 2bb8ed350..aa3d5fc82 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -49,6 +49,7 @@ import ( "gitea.com/macaron/session" "gitea.com/macaron/toolbox" "github.com/prometheus/client_golang/prometheus" + gouuid "github.com/satori/go.uuid" "github.com/tstranex/u2f" ) @@ -85,7 +86,7 @@ func setupAccessLogger(m *macaron.Macaron) { log.Error("Could not set up macaron access logger: %v", err.Error()) } - err = logger.SendLog(log.INFO, "", "", 0, buf.String(), "") + err = logger.SendLog(log.INFO, "", "", 0, buf.String(), ctx.Data["msgID"].(string), "") if err != nil { log.Error("Could not set up macaron access logger: %v", err.Error()) } @@ -107,6 +108,24 @@ func RouterHandler(level log.Level) func(ctx *macaron.Context) { } } +// SetLogMsgID set msgID in Context +func SetLogMsgID() func(ctx *macaron.Context) { + return func(ctx *macaron.Context) { + start := time.Now() + + uuid := gouuid.NewV4().String() + ctx.Data["MsgID"] = uuid + + log.Info("Started %s %s for %s", log.ColoredMethod(ctx.Req.Method), ctx.Req.URL.RequestURI(), ctx.RemoteAddr(), ctx.Data["MsgID"]) + + rw := ctx.Resp.(macaron.ResponseWriter) + ctx.Next() + + status := rw.Status() + log.Info("Completed %s %s %v %s in %v", log.ColoredMethod(ctx.Req.Method), ctx.Req.URL.RequestURI(), log.ColoredStatus(status), log.ColoredStatus(status, http.StatusText(rw.Status())), log.ColoredTime(time.Since(start)), ctx.Data["MsgID"]) + } +} + // NewMacaron initializes Macaron instance. func NewMacaron() *macaron.Macaron { gob.Register(&u2f.Challenge{}) @@ -125,6 +144,7 @@ func NewMacaron() *macaron.Macaron { m.Use(macaron.Logger()) } } + m.Use(SetLogMsgID()) // Access Logger is similar to Router Log but more configurable and by default is more like the NCSA Common Log format if setting.EnableAccessLog { setupAccessLogger(m) @@ -285,7 +305,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Head("/", func() string { return "" }) - m.Get("/", routers.Home) + m.Get("/", routers.ExploreRepos) m.Get("/dashboard", routers.Dashboard) m.Group("/explore", func() { m.Get("", func(ctx *context.Context) { @@ -910,9 +930,11 @@ 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("/rate", reqRepoCloudBrainWriter, repo.GetRate) + m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate) + m.Get("/models", reqRepoCloudBrainReader, repo.CloudBrainShowModels) + m.Get("/download_model", reqRepoCloudBrainReader, repo.CloudBrainDownloadModel) }) - m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) + m.Get("/create", reqRepoCloudBrainReader, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) }, context.RepoRef()) diff --git a/routers/user/home.go b/routers/user/home.go old mode 100644 new mode 100755 diff --git a/routers/user/profile.go b/routers/user/profile.go old mode 100644 new mode 100755 diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index ce5d9892d..4392e5536 100755 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -176,6 +176,15 @@ {{end}} {{template "custom/header" .}} + {{template "custom/body_outer_pre" .}} diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 1eada0a01..11dab3717 100755 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -9,7 +9,7 @@ {{if .IsSigned}} - {{.i18n.Tr "dashboard"}} + {{.i18n.Tr "index"}} {{.i18n.Tr "custom.head.openi"}} {{if not .UnitIssuesGlobalDisabled}} {{.i18n.Tr "issues"}} @@ -109,10 +109,6 @@
- - {{svg "octicon-info" 16}} - {{.i18n.Tr "your_dashboard"}} - {{svg "octicon-person" 16}} {{.i18n.Tr "your_profile"}} diff --git a/templates/explore/dataset_list.tmpl b/templates/explore/dataset_list.tmpl index 9200274a9..48ae78127 100755 --- a/templates/explore/dataset_list.tmpl +++ b/templates/explore/dataset_list.tmpl @@ -25,7 +25,7 @@ {{range .Datasets}}
- + {{.Repo.OwnerName}} / {{.Title}}
diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl old mode 100644 new mode 100755 diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 9a58a05a6..60ce3c202 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -248,7 +248,7 @@
-
+
{{.Status}}
@@ -257,15 +257,6 @@ {{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}
- -
- - - 查看 - - -
-
@@ -304,6 +295,15 @@
+ + + 提交镜像 diff --git a/templates/repo/cloudbrain/new.tmpl b/templates/repo/cloudbrain/new.tmpl index a2b307efb..c1afb9389 100755 --- a/templates/repo/cloudbrain/new.tmpl +++ b/templates/repo/cloudbrain/new.tmpl @@ -88,6 +88,17 @@ .inline.required.field.cloudbrain_snn4imagenet { display: none; } + + .select2-container .select2-selection--single{ + height:38px !important; + } + + .select2-container--default .select2-selection--single { + border : 1px solid rgba(34,36,38,.15) !important; + } + .select2-container--default .select2-selection--single .select2-selection__rendered{ + line-height: 38px !important; + }
@@ -139,9 +150,18 @@
+
+ + +
+
- {{range .images}} {{end}} @@ -198,7 +218,8 @@
{{template "base/footer" .}} - + +