Browse Source

增加打印。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.2^2
zouap 3 years ago
parent
commit
a81b44416e
2 changed files with 94 additions and 1 deletions
  1. +1
    -1
      modules/storage/minio.go
  2. +93
    -0
      routers/repo/ai_model_manage.go

+ 1
- 1
modules/storage/minio.go View File

@@ -144,7 +144,7 @@ func (m *MinioStorage) HasObject(path string) (bool, error) {

// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
log.Info("minio object key=" + m.buildMinioPath(path))
objectCh := m.client.ListObjects(m.bucket, m.buildMinioPath(path), false, doneCh)
for object := range objectCh {
if object.Err != nil {


+ 93
- 0
routers/repo/ai_model_manage.go View File

@@ -190,7 +190,100 @@ func SaveNewNameModel(ctx *context.Context) {
}

func SaveLocalModel(ctx *context.Context) {
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) {
ctx.Error(403, ctx.Tr("repo.model_noright"))
return
}
re := map[string]string{
"code": "-1",
}
log.Info("save SaveLocalModel start.")
uuid := uuid.NewV4()
id := uuid.String()
name := ctx.Query("name")
version := ctx.Query("version")
if version == "" {
version = "0.0.1"
}
label := ctx.Query("label")
description := ctx.Query("description")
engine := ctx.QueryInt("engine")
taskType := ctx.QueryInt("type")
modelActualPath := ""
if taskType == models.TypeCloudBrainOne {
destKeyNamePrefix := Model_prefix + models.AttachmentRelativePath(id) + "/"
modelActualPath = setting.Bucket + "/" + destKeyNamePrefix
} else if taskType == models.TypeCloudBrainTwo {
destKeyNamePrefix := Model_prefix + models.AttachmentRelativePath(id) + "/"
modelActualPath = setting.Attachment.Minio.Bucket + "/" + destKeyNamePrefix
} else {
re["msg"] = "type is error."
ctx.JSON(200, re)
return
}
var lastNewModelId string
repoId := ctx.Repo.Repository.RepoID
aimodels := models.QueryModelByName(name, repoId)
if len(aimodels) > 0 {
for _, model := range aimodels {
if model.Version == version {
re["msg"] = ctx.Tr("repo.model.manage.create_error")
ctx.JSON(200, re)
return
}
if model.New == MODEL_LATEST {
lastNewModelId = model.ID
}
}
}
model := &models.AiModelManage{
ID: id,
Version: version,
VersionCount: len(aimodels) + 1,
Label: label,
Name: name,
Description: description,
New: MODEL_LATEST,
Type: taskType,
Path: modelActualPath,
Size: 0,
AttachmentId: "",
RepoId: repoId,
UserId: ctx.User.ID,
Engine: int64(engine),
TrainTaskInfo: "",
Accuracy: "",
Status: STATUS_FINISHED,
}

err := models.SaveModelToDb(model)
if err != nil {
re["msg"] = err.Error()
ctx.JSON(200, re)
return
}
if len(lastNewModelId) > 0 {
//udpate status and version count
models.ModifyModelNewProperty(lastNewModelId, MODEL_NOT_LATEST, 0)
}
var units []models.RepoUnit
var deleteUnitTypes []models.UnitType
units = append(units, models.RepoUnit{
RepoID: ctx.Repo.Repository.ID,
Type: models.UnitTypeModelManage,
Config: &models.ModelManageConfig{
EnableModelManage: true,
},
})
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeModelManage)

models.UpdateRepositoryUnits(ctx.Repo.Repository, units, deleteUnitTypes)

log.Info("save model end.")
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask)
re["code"] = "0"
re["id"] = id
ctx.JSON(200, re)
}

func UploadLocalModel(ctx *context.Context) {


Loading…
Cancel
Save