@@ -1114,6 +1114,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error | |||||
Type: tp, | Type: tp, | ||||
Config: &BlockChainConfig{EnableBlockChain: true}, | Config: &BlockChainConfig{EnableBlockChain: true}, | ||||
}) | }) | ||||
} else if tp == UnitTypeModelManage { | |||||
units = append(units, RepoUnit{ | |||||
RepoID: repo.ID, | |||||
Type: tp, | |||||
Config: &ModelManageConfig{EnableModelManage: true}, | |||||
}) | |||||
} else { | } else { | ||||
units = append(units, RepoUnit{ | units = append(units, RepoUnit{ | ||||
RepoID: repo.ID, | RepoID: repo.ID, | ||||
@@ -131,6 +131,20 @@ type CloudBrainConfig struct { | |||||
EnableCloudBrain bool | EnableCloudBrain bool | ||||
} | } | ||||
type ModelManageConfig struct { | |||||
EnableModelManage bool | |||||
} | |||||
// FromDB fills up a CloudBrainConfig from serialized format. | |||||
func (cfg *ModelManageConfig) FromDB(bs []byte) error { | |||||
return json.Unmarshal(bs, &cfg) | |||||
} | |||||
// ToDB exports a CloudBrainConfig to a serialized format. | |||||
func (cfg *ModelManageConfig) ToDB() ([]byte, error) { | |||||
return json.Marshal(cfg) | |||||
} | |||||
// FromDB fills up a CloudBrainConfig from serialized format. | // FromDB fills up a CloudBrainConfig from serialized format. | ||||
func (cfg *CloudBrainConfig) FromDB(bs []byte) error { | func (cfg *CloudBrainConfig) FromDB(bs []byte) error { | ||||
return json.Unmarshal(bs, &cfg) | return json.Unmarshal(bs, &cfg) | ||||
@@ -176,6 +190,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { | |||||
r.Config = new(CloudBrainConfig) | r.Config = new(CloudBrainConfig) | ||||
case UnitTypeBlockChain: | case UnitTypeBlockChain: | ||||
r.Config = new(BlockChainConfig) | r.Config = new(BlockChainConfig) | ||||
case UnitTypeModelManage: | |||||
r.Config = new(ModelManageConfig) | |||||
default: | default: | ||||
panic("unrecognized repo unit type: " + com.ToStr(*val)) | panic("unrecognized repo unit type: " + com.ToStr(*val)) | ||||
} | } | ||||
@@ -27,6 +27,7 @@ const ( | |||||
UnitTypeDatasets UnitType = 10 // 10 Dataset | UnitTypeDatasets UnitType = 10 // 10 Dataset | ||||
UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain | UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain | ||||
UnitTypeBlockChain UnitType = 12 // 12 BlockChain | UnitTypeBlockChain UnitType = 12 // 12 BlockChain | ||||
UnitTypeModelManage UnitType = 13 // 13 ModelManage | |||||
) | ) | ||||
// Value returns integer value for unit type | // Value returns integer value for unit type | ||||
@@ -56,6 +57,8 @@ func (u UnitType) String() string { | |||||
return "UnitTypeCloudBrain" | return "UnitTypeCloudBrain" | ||||
case UnitTypeBlockChain: | case UnitTypeBlockChain: | ||||
return "UnitTypeBlockChain" | return "UnitTypeBlockChain" | ||||
case UnitTypeModelManage: | |||||
return "UnitTypeModelManage" | |||||
} | } | ||||
return fmt.Sprintf("Unknown UnitType %d", u) | return fmt.Sprintf("Unknown UnitType %d", u) | ||||
} | } | ||||
@@ -80,6 +83,7 @@ var ( | |||||
UnitTypeDatasets, | UnitTypeDatasets, | ||||
UnitTypeCloudBrain, | UnitTypeCloudBrain, | ||||
UnitTypeBlockChain, | UnitTypeBlockChain, | ||||
UnitTypeModelManage, | |||||
} | } | ||||
// DefaultRepoUnits contains the default unit types | // DefaultRepoUnits contains the default unit types | ||||
@@ -92,6 +96,7 @@ var ( | |||||
UnitTypeDatasets, | UnitTypeDatasets, | ||||
UnitTypeCloudBrain, | UnitTypeCloudBrain, | ||||
UnitTypeBlockChain, | UnitTypeBlockChain, | ||||
UnitTypeModelManage, | |||||
} | } | ||||
// NotAllowedDefaultRepoUnits contains units that can't be default | // NotAllowedDefaultRepoUnits contains units that can't be default | ||||
@@ -281,6 +286,14 @@ var ( | |||||
7, | 7, | ||||
} | } | ||||
UnitModelManage = Unit{ | |||||
UnitTypeModelManage, | |||||
"repo.modelmanage", | |||||
"/modelmanage", | |||||
"repo.modelmanage.desc", | |||||
8, | |||||
} | |||||
// Units contains all the units | // Units contains all the units | ||||
Units = map[UnitType]Unit{ | Units = map[UnitType]Unit{ | ||||
UnitTypeCode: UnitCode, | UnitTypeCode: UnitCode, | ||||
@@ -293,6 +306,7 @@ var ( | |||||
UnitTypeDatasets: UnitDataset, | UnitTypeDatasets: UnitDataset, | ||||
UnitTypeCloudBrain: UnitCloudBrain, | UnitTypeCloudBrain: UnitCloudBrain, | ||||
UnitTypeBlockChain: UnitBlockChain, | UnitTypeBlockChain: UnitBlockChain, | ||||
UnitTypeModelManage: UnitModelManage, | |||||
} | } | ||||
) | ) | ||||
@@ -122,6 +122,7 @@ type RepoSettingForm struct { | |||||
// Advanced settings | // Advanced settings | ||||
EnableDataset bool | EnableDataset bool | ||||
EnableCloudBrain bool | EnableCloudBrain bool | ||||
EnableModelManager bool | |||||
EnableWiki bool | EnableWiki bool | ||||
EnableExternalWiki bool | EnableExternalWiki bool | ||||
ExternalWikiURL string | ExternalWikiURL string | ||||
@@ -821,5 +821,6 @@ func UnitTypes() macaron.Handler { | |||||
ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki | ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki | ||||
ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker | ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker | ||||
ctx.Data["UnitTypeBlockChain"] = models.UnitTypeBlockChain | ctx.Data["UnitTypeBlockChain"] = models.UnitTypeBlockChain | ||||
ctx.Data["UnitTypeModelManage"] = models.UnitTypeModelManage | |||||
} | } | ||||
} | } |
@@ -118,7 +118,7 @@ func SaveModel(ctx *context.Context) { | |||||
label := ctx.Query("Label") | label := ctx.Query("Label") | ||||
description := ctx.Query("Description") | description := ctx.Query("Description") | ||||
if !ctx.Repo.CanWrite(models.UnitTypeCloudBrain) { | |||||
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { | |||||
ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) | ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) | ||||
return | return | ||||
} | } | ||||
@@ -418,7 +418,7 @@ func ShowModelTemplate(ctx *context.Context) { | |||||
func isQueryRight(ctx *context.Context) bool { | func isQueryRight(ctx *context.Context) bool { | ||||
if ctx.Repo.Repository.IsPrivate { | if ctx.Repo.Repository.IsPrivate { | ||||
if ctx.Repo.CanRead(models.UnitTypeCloudBrain) || ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { | |||||
if ctx.Repo.CanRead(models.UnitTypeModelManage) || ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { | |||||
return true | return true | ||||
} | } | ||||
return false | return false | ||||
@@ -239,6 +239,18 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { | |||||
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeCloudBrain) | deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeCloudBrain) | ||||
} | } | ||||
if form.EnableModelManager && !models.UnitTypeModelManage.UnitGlobalDisabled() { | |||||
units = append(units, models.RepoUnit{ | |||||
RepoID: repo.ID, | |||||
Type: models.UnitTypeModelManage, | |||||
Config: &models.ModelManageConfig{ | |||||
EnableModelManage: form.EnableModelManager, | |||||
}, | |||||
}) | |||||
} else if !models.UnitTypeModelManage.UnitGlobalDisabled() { | |||||
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeModelManage) | |||||
} | |||||
if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { | if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { | ||||
if !validation.IsValidExternalURL(form.ExternalWikiURL) { | if !validation.IsValidExternalURL(form.ExternalWikiURL) { | ||||
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) | ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) | ||||
@@ -616,6 +616,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) | reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) | ||||
reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain) | reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain) | ||||
reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain) | reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain) | ||||
reqRepoModelManageReader := context.RequireRepoReader(models.UnitTypeModelManage) | |||||
reqRepoModelManageWriter := context.RequireRepoWriter(models.UnitTypeModelManage) | |||||
//reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain) | //reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain) | ||||
//reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain) | //reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain) | ||||
@@ -973,21 +975,21 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | ||||
}, context.RepoRef()) | }, context.RepoRef()) | ||||
m.Group("/modelmanage", func() { | m.Group("/modelmanage", func() { | ||||
m.Post("/create_model", repo.SaveModel) | |||||
m.Post("/create_model", reqRepoModelManageWriter, repo.SaveModel) | |||||
m.Delete("/delete_model", repo.DeleteModel) | m.Delete("/delete_model", repo.DeleteModel) | ||||
m.Put("/modify_model", repo.ModifyModelInfo) | m.Put("/modify_model", repo.ModifyModelInfo) | ||||
m.Get("/show_model", reqRepoCloudBrainReader, repo.ShowModelTemplate) | |||||
m.Get("/show_model_info", reqRepoCloudBrainReader, repo.ShowModelInfo) | |||||
m.Get("/show_model_info_api", reqRepoCloudBrainReader, repo.ShowSingleModel) | |||||
m.Get("/show_model_api", reqRepoCloudBrainReader, repo.ShowModelPageInfo) | |||||
m.Get("/show_model_child_api", reqRepoCloudBrainReader, repo.ShowOneVersionOtherModel) | |||||
m.Get("/show_model", reqRepoModelManageReader, repo.ShowModelTemplate) | |||||
m.Get("/show_model_info", repo.ShowModelInfo) | |||||
m.Get("/show_model_info_api", repo.ShowSingleModel) | |||||
m.Get("/show_model_api", repo.ShowModelPageInfo) | |||||
m.Get("/show_model_child_api", repo.ShowOneVersionOtherModel) | |||||
m.Get("/query_train_job", reqRepoCloudBrainReader, repo.QueryTrainJobList) | m.Get("/query_train_job", reqRepoCloudBrainReader, repo.QueryTrainJobList) | ||||
m.Get("/query_train_job_version", reqRepoCloudBrainReader, repo.QueryTrainJobVersionList) | m.Get("/query_train_job_version", reqRepoCloudBrainReader, repo.QueryTrainJobVersionList) | ||||
m.Group("/:ID", func() { | m.Group("/:ID", func() { | ||||
m.Get("", reqRepoCloudBrainReader, repo.ShowSingleModel) | |||||
m.Get("/downloadsingle", reqRepoCloudBrainReader, repo.DownloadSingleModelFile) | |||||
m.Get("", repo.ShowSingleModel) | |||||
m.Get("/downloadsingle", repo.DownloadSingleModelFile) | |||||
}) | }) | ||||
m.Get("/downloadall", reqRepoCloudBrainReader, repo.DownloadMultiModelFile) | |||||
m.Get("/downloadall", repo.DownloadMultiModelFile) | |||||
}, context.RepoRef()) | }, context.RepoRef()) | ||||
m.Group("/modelarts", func() { | m.Group("/modelarts", func() { | ||||