| @@ -139,6 +139,10 @@ const ( | |||||
| GCU = "GCU" | GCU = "GCU" | ||||
| ) | ) | ||||
| const ( | |||||
| AIModelPath = "aimodels/" | |||||
| ) | |||||
| type Cloudbrain struct { | type Cloudbrain struct { | ||||
| ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
| JobID string `xorm:"INDEX NOT NULL"` | JobID string `xorm:"INDEX NOT NULL"` | ||||
| @@ -2686,7 +2690,7 @@ func GetDatasetInfo(uuidStr string, grampusType ...string) (map[string]DatasetIn | |||||
| } | } | ||||
| if attach == nil { | if attach == nil { | ||||
| log.Error("GetAttachmentsByUUIDs failed: %v", err) | log.Error("GetAttachmentsByUUIDs failed: %v", err) | ||||
| continue | |||||
| return nil, datasetNames, err | |||||
| } | } | ||||
| fileName := strings.TrimSuffix(strings.TrimSuffix(strings.TrimSuffix(attach.Name, ".zip"), ".tar.gz"), ".tgz") | fileName := strings.TrimSuffix(strings.TrimSuffix(strings.TrimSuffix(attach.Name, ".zip"), ".tar.gz"), ".tgz") | ||||
| for _, datasetInfo := range datasetInfos { | for _, datasetInfo := range datasetInfos { | ||||
| @@ -391,3 +391,19 @@ func GetPartInfos(objectName string, uploadID string) (string, error) { | |||||
| return chunks, nil | return chunks, nil | ||||
| } | } | ||||
| func IsObjectExist4Minio(bucket, objectName string) (bool, error) { | |||||
| _, core, err := getClients() | |||||
| if err != nil { | |||||
| log.Error("getClients failed:", err.Error()) | |||||
| return false, err | |||||
| } | |||||
| _, err = core.StatObject(bucket, objectName, miniov6.StatObjectOptions{}) | |||||
| if err != nil { | |||||
| log.Error("GetObjectMetadata error.%v", err) | |||||
| return false, err | |||||
| } | |||||
| return true, nil | |||||
| } | |||||
| @@ -645,3 +645,16 @@ func GetObsLogFileName(prefix string) ([]FileInfo, error) { | |||||
| } | } | ||||
| return fileInfos, nil | return fileInfos, nil | ||||
| } | } | ||||
| func IsObjectExist4Obs(bucket, key string) (bool, error) { | |||||
| _, err := ObsCli.GetObjectMetadata(&obs.GetObjectMetadataInput{ | |||||
| Bucket: bucket, | |||||
| Key: key, | |||||
| }) | |||||
| if err != nil { | |||||
| log.Error("GetObjectMetadata error.%v", err) | |||||
| return false, err | |||||
| } | |||||
| return true, nil | |||||
| } | |||||
| @@ -211,6 +211,11 @@ func GrampusNotebookCreate(ctx *context.Context, form auth.CreateGrampusNotebook | |||||
| ctx.RenderWithErr(ctx.Tr("cloudbrain.error.dataset_select"), tpl, &form) | ctx.RenderWithErr(ctx.Tr("cloudbrain.error.dataset_select"), tpl, &form) | ||||
| return | return | ||||
| } | } | ||||
| uuidArray := strings.Split(uuid, ";") | |||||
| if datasetInfos == nil || len(datasetInfos) < len(uuidArray) { | |||||
| ctx.RenderWithErr(ctx.Tr("cloudbrain.error.partial_datasets_not_available"), tpl, &form) | |||||
| return | |||||
| } | |||||
| } | } | ||||
| //prepare code and out path | //prepare code and out path | ||||
| @@ -274,6 +279,12 @@ func GrampusNotebookCreate(ctx *context.Context, form auth.CreateGrampusNotebook | |||||
| ctx.RenderWithErr(ctx.Tr("repo.modelconvert.manage.model_not_exist"), tpl, &form) | ctx.RenderWithErr(ctx.Tr("repo.modelconvert.manage.model_not_exist"), tpl, &form) | ||||
| return | return | ||||
| } | } | ||||
| if !cloudbrainTask.IsModelFileExists(m, form.CkptName) { | |||||
| log.Error("model file not exist.name = %s", form.CkptName) | |||||
| grampusNotebookNewDataPrepare(ctx, processType) | |||||
| ctx.RenderWithErr(ctx.Tr("repo.modelconvert.manage.model_file_not_exist"), tpl, &form) | |||||
| return | |||||
| } | |||||
| req.ModelName = form.ModelName | req.ModelName = form.ModelName | ||||
| req.LabelName = form.LabelName | req.LabelName = form.LabelName | ||||
| req.CkptName = form.CkptName | req.CkptName = form.CkptName | ||||
| @@ -1324,7 +1335,7 @@ func GrampusTrainJobShow(ctx *context.Context) { | |||||
| taskList := make([]*models.Cloudbrain, 0) | taskList := make([]*models.Cloudbrain, 0) | ||||
| taskList = append(taskList, task) | taskList = append(taskList, task) | ||||
| prepareSpec4Show(ctx, task) | prepareSpec4Show(ctx, task) | ||||
| ctx.Data["version_list_task"] = taskList | ctx.Data["version_list_task"] = taskList | ||||
| ctx.Data["datasetDownload"] = GetCloudBrainDataSetInfo(task.Uuid, task.DatasetName, false) | ctx.Data["datasetDownload"] = GetCloudBrainDataSetInfo(task.Uuid, task.DatasetName, false) | ||||
| ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task) | ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task) | ||||
| @@ -0,0 +1,30 @@ | |||||
| package cloudbrainTask | |||||
| import ( | |||||
| "code.gitea.io/gitea/models" | |||||
| "code.gitea.io/gitea/modules/log" | |||||
| "code.gitea.io/gitea/modules/setting" | |||||
| "code.gitea.io/gitea/modules/storage" | |||||
| ) | |||||
| func IsModelFileExists(model *models.AiModelManage, fileName string) bool { | |||||
| if model.Type == models.TypeCloudBrainTwo { | |||||
| key := models.AIModelPath + models.AttachmentRelativePath(model.ID) + "/" + fileName | |||||
| log.Info("IsModelFileExists TypeCloudBrainTwo key=%s", key) | |||||
| isExist, err := storage.IsObjectExist4Obs(setting.Bucket, key) | |||||
| if err != nil { | |||||
| return false | |||||
| } | |||||
| return isExist | |||||
| } else if model.Type == models.TypeCloudBrainOne { | |||||
| prefix := models.AIModelPath + models.AttachmentRelativePath(model.ID) + "/" | |||||
| objectName := prefix + fileName | |||||
| log.Info("IsModelFileExists TypeCloudBrainOne objectName=%s", objectName) | |||||
| isExist, err := storage.IsObjectExist4Minio(setting.Attachment.Minio.Bucket, objectName) | |||||
| if err != nil { | |||||
| return false | |||||
| } | |||||
| return isExist | |||||
| } | |||||
| return false | |||||
| } | |||||