Browse Source

fix-1913 提交镜像

tags/v1.22.4.2^2
ychao_1983 3 years ago
parent
commit
212b3c217c
7 changed files with 112 additions and 3 deletions
  1. +2
    -0
      models/cloudbrain.go
  2. +2
    -2
      models/cloudbrain_image.go
  3. +10
    -0
      modules/auth/cloudbrain.go
  4. +40
    -1
      modules/cloudbrain/resty.go
  5. +7
    -0
      routers/admin/cloudbrains.go
  6. +49
    -0
      routers/repo/cloudbrain.go
  7. +2
    -0
      routers/routes/routes.go

+ 2
- 0
models/cloudbrain.go View File

@@ -580,6 +580,8 @@ type CommitImageParams struct {
Topics []string
CloudBrainType int
UID int64
Place string
Type int
}

type CommitImageResult struct {


+ 2
- 2
models/cloudbrain_image.go View File

@@ -567,12 +567,12 @@ func isImageStaring(e Engine, userID, imageID int64) bool {
}
func RecommendImage(imageId int64, recommond bool) error {

image := Image{Type: getRecommondType(recommond)}
image := Image{Type: GetRecommondType(recommond)}
_, err := x.ID(imageId).Cols("type").Update(image)
return err
}

func getRecommondType(recommond bool) int {
func GetRecommondType(recommond bool) int {
if recommond {

return RECOMMOND_TYPE


+ 10
- 0
modules/auth/cloudbrain.go View File

@@ -33,6 +33,16 @@ type CommitImageCloudBrainForm struct {
Topics string `form:"topics"`
}

type CommitAdminImageCloudBrainForm struct {
Description string `form:"description" binding:"Required"`
Type int `form:"type" binding:"Required"`
Tag string `form:"tag" binding:"Required;MaxSize(100)" `
IsPrivate bool `form:"isPrivate" binding:"Required"`
Topics string `form:"topics"`
Place string `form:"place" binding:"Required"`
IsRecommend bool `form:"isRecommend" binding:"Required"`
}

type EditImageCloudBrainForm struct {
ID int64 `form:"id" binding:"Required"`
Description string `form:"description" binding:"Required"`


+ 40
- 1
modules/cloudbrain/resty.go View File

@@ -312,12 +312,51 @@ sendjob:
return nil
})
if err == nil {

go updateImageStatus(image, isSetCreatedUnix, createTime)
}
return err
}

func CommitAdminImage(jobID string, params models.CommitImageParams) error {

exist, err := models.IsImageExist(params.ImageTag)

if err != nil {
return fmt.Errorf("resty CommitImage: %v", err)
}
if exist {
return models.ErrorImageTagExist{
Tag: params.ImageTag,
}
}

image := models.Image{
CloudbrainType: params.CloudBrainType,
UID: params.UID,
IsPrivate: params.IsPrivate,
Tag: params.ImageTag,
Description: params.ImageDescription,
Place: params.Place,
Status: models.IMAGE_STATUS_SUCCESS,
Type: params.Type,
}

err = models.WithTx(func(ctx models.DBContext) error {

if err := models.CreateLocalImage(&image); err != nil {
log.Error("Failed to insert image record.", err)
return fmt.Errorf("resty CommitImage: %v", err)
}

if err := models.SaveImageTopics(image.ID, params.Topics...); err != nil {
log.Error("Failed to insert image record.", err)
return fmt.Errorf("resty CommitImage: %v", err)
}
return nil
})
return err
}

func updateImageStatus(image models.Image, isSetCreatedUnix bool, createTime time.Time) {
attemps := 5
commitSuccess := false


+ 7
- 0
routers/admin/cloudbrains.go View File

@@ -21,6 +21,7 @@ import (
const (
tplCloudBrains base.TplName = "admin/cloudbrain/list"
tplImages base.TplName = "admin/cloudbrain/images"
tplCommitImages base.TplName = "admin/cloudbrain/imagecommit"
EXCEL_DATE_FORMAT = "20060102150405"
CREATE_TIME_FORMAT = "2006/01/02 15:04:05"
)
@@ -114,6 +115,12 @@ func Images(ctx *context.Context) {

}

func CloudBrainCommitImageShow(ctx *context.Context) {
ctx.Data["PageIsAdminImages"] = true
ctx.HTML(200, tplImages)

}

func DownloadCloudBrains(ctx *context.Context) {

page := 1


+ 49
- 0
routers/repo/cloudbrain.go View File

@@ -702,6 +702,55 @@ func CloudBrainCommitImageCheck(ctx *context.Context, form auth.CommitImageCloud

}

func CloudBrainAdminCommitImage(ctx *context.Context, form auth.CommitAdminImageCloudBrainForm) {

if !NamePattern.MatchString(form.Tag) {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err")))
return
}

if utf8.RuneCountInString(form.Description) > 255 {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err", 255)))
return
}

validTopics, errMessage := checkTopics(form.Topics)
if errMessage != "" {
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr(errMessage)))
return
}

err := cloudbrain.CommitAdminImage(ctx.Cloudbrain.JobID, models.CommitImageParams{
CommitImageCloudBrainParams: models.CommitImageCloudBrainParams{
Ip: ctx.Cloudbrain.ContainerIp,
TaskContainerId: ctx.Cloudbrain.ContainerID,
ImageDescription: form.Description,
ImageTag: form.Tag,
},
IsPrivate: form.IsPrivate,
CloudBrainType: form.Type,
Topics: validTopics,
UID: ctx.User.ID,
Type: models.GetRecommondType(form.IsRecommend),
Place: form.Place,
})
if err != nil {
log.Error("CommitImage(%s) failed:%v", ctx.Cloudbrain.JobName, err.Error(), ctx.Data["msgID"])
if models.IsErrImageTagExist(err) {
ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_exist")))

} else if models.IsErrorImageCommitting(err) {
ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_committing")))
} else {
ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_commit_fail")))
}

return
}

ctx.JSON(200, models.BaseOKMessage)
}

func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) {

if !NamePattern.MatchString(form.Tag) {


+ 2
- 0
routers/routes/routes.go View File

@@ -534,6 +534,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/images", func() {
m.Get("", admin.Images)
m.Get("/data", repo.GetAllImages)
m.Get("/commit_image", admin.CloudBrainCommitImageShow)
m.Post("/commit_image", bindIgnErr(auth.CommitAdminImageCloudBrainForm{}), repo.CloudBrainAdminCommitImage)
})
m.Put("/image/:id/action/:action", image.Action)



Loading…
Cancel
Save