diff --git a/automation/server/internal/module/job_workflow/model/template.go b/automation/server/internal/module/job_workflow/model/template.go index 31d20c30c2ef3355bc7a13e931dd0347f7b3b99b..1fbb5b44f65446f785abae6ffe89355806232008 100644 --- a/automation/server/internal/module/job_workflow/model/template.go +++ b/automation/server/internal/module/job_workflow/model/template.go @@ -1,5 +1,7 @@ package model +import "encoding/json" + type TaskTemplate struct { ID int `json:"id" gorm:"primaryKey;autoIncrement;comment:作业编排Id"` Name string `json:"name" gorm:"type:varchar(255);comment:作业编排名称"` @@ -14,14 +16,14 @@ type TaskTemplate struct { } type TaskTemplateVariable struct { - ID int `json:"id" gorm:"primaryKey;autoIncrement"` - TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` - Name string `json:"name" gorm:"type:varchar(255);comment:变量名称"` - Type string `json:"type" gorm:"comment:变量类型(字符串、命名空间、数组等)"` - DefaultVaue string `json:"default_value" gorm:"comment:变量默认值"` - Description string `json:"description" gorm:"comment:变量描述"` - IsChangeable bool `json:"is_changeable" gorm:"comment:赋值可变"` - IsRequired string `json:"is_required" gorm:"comment:是否必需"` + ID int `json:"id" gorm:"primaryKey;autoIncrement"` + TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` + Name string `json:"name" gorm:"type:varchar(255);comment:变量名称"` + Type string `json:"type" gorm:"comment:变量类型(字符串、命名空间、数组等)"` + DefaultVaue json.RawMessage `json:"default_value" gorm:"comment:变量默认值"` + Description string `json:"description" gorm:"comment:变量描述"` + IsChangeable bool `json:"is_changeable" gorm:"comment:赋值可变"` + IsRequired bool `json:"is_required" gorm:"comment:是否必需"` } type TaskTemplateStep struct { @@ -35,16 +37,16 @@ type TaskTemplateStep struct { } type TaskTemplateStepScript struct { - ID int `json:"id" gorm:"primaryKey;autoIncrement"` - TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` - StepId int `json:"step_id" gorm:"comment:作业编排步骤Id"` - ScriptType string `json:"script_type" gorm:"comment:脚本类型"` - ScriptId string `json:"script_id" gorm:"comment:引用脚本Id"` - ScriptVersionId string `json:"script_version_id" gorm:"comment:引用脚本版本Id"` - ScriptContent string `json:"script_content" gorm:"comment:脚本内容"` - ScriptParam string `json:"script_param" gorm:"comment:脚本执行参数"` - ScriptTimeout string `json:"script_timeout" gorm:"comment:脚本超时"` - DestinationHostList string `json:"destination_host_list" gorm:"comment:远程执行主机列表"` + ID int `json:"id" gorm:"primaryKey;autoIncrement"` + TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` + StepId int `json:"step_id" gorm:"comment:作业编排步骤Id"` + ScriptType string `json:"script_type" gorm:"comment:脚本类型"` + ScriptId string `json:"script_id" gorm:"comment:引用脚本Id"` + ScriptVersionId string `json:"script_version_id" gorm:"comment:引用脚本版本Id"` + ScriptContent string `json:"script_content" gorm:"comment:脚本内容"` + ScriptParam string `json:"script_param" gorm:"comment:脚本执行参数"` + ScriptTimeout int `json:"script_timeout" gorm:"comment:脚本超时"` + DestinationHostList json.RawMessage `json:"destination_host_list" gorm:"comment:远程执行主机列表"` } type TaskTemplateDTO struct { diff --git a/automation/server/internal/module/script_library/controller/script.go b/automation/server/internal/module/script_library/controller/script.go index e76f53f02ed6238f359b90a42ce504fd7fe0d70d..b8f78e7ac5ef7e57ae9b696c230885dfbf8ce71f 100644 --- a/automation/server/internal/module/script_library/controller/script.go +++ b/automation/server/internal/module/script_library/controller/script.go @@ -8,7 +8,7 @@ import ( ) func AddScriptHandler(c *gin.Context) { - var script model.ScriptWithVersion + var script model.AddScriptDTO if err := c.ShouldBindJSON(&script); err != nil { response.Fail(c, nil, err.Error()) return diff --git a/automation/server/internal/module/script_library/model/script.go b/automation/server/internal/module/script_library/model/script.go index c9a9697731c61c83de982906d16d8a3a81a56b40..0e791d2e5615b38945ee8f385ced5d34c5dd67ef 100644 --- a/automation/server/internal/module/script_library/model/script.go +++ b/automation/server/internal/module/script_library/model/script.go @@ -44,3 +44,8 @@ type ScriptResponse struct { LastModifyUser string `json:"last_modify_user"` LastModifyUpdatedAt string `json:"last_modify_updated_at"` } + +type AddScriptDTO struct { + Script Script `json:"script"` + FirstVersion ScriptVersion `json:"first_version"` +} diff --git a/automation/server/internal/module/script_library/service/script.go b/automation/server/internal/module/script_library/service/script.go index f02f1737d673b6d085d1b980cb31622900b95cba..a3773e7dc35865aa8363467307c02521f8cfa6ca 100644 --- a/automation/server/internal/module/script_library/service/script.go +++ b/automation/server/internal/module/script_library/service/script.go @@ -13,7 +13,7 @@ func generateScriptId() string { return uuid.NewString() } -func AddScript(s *model.ScriptWithVersion) error { +func AddScript(s *model.AddScriptDTO) error { scriptId := generateScriptId() // decodedContent, err := utils.DecodeScriptContent(s.Content) @@ -23,28 +23,28 @@ func AddScript(s *model.ScriptWithVersion) error { script := &model.Script{ ID: scriptId, - Name: s.Name, - ScriptName: s.ScriptName, - ScriptType: s.ScriptType, - Description: s.Description, - Tags: s.Tags, - IsPublic: s.IsPublic, - Creator: s.Creator, + Name: s.Script.Name, + ScriptName: s.Script.ScriptName, + ScriptType: s.Script.ScriptType, + Description: s.Script.Description, + Tags: s.Script.Tags, + IsPublic: s.Script.IsPublic, + Creator: s.Script.Creator, CreatedAt: time.Now().Format("2006-01-02 15:04:05"), - LastModifyUser: s.Creator, + LastModifyUser: s.Script.Creator, LastModifyUpdatedAt: time.Now().Format("2006-01-02 15:04:05"), } scriptVersion := &model.ScriptVersion{ ScriptID: scriptId, // Content: decodedContent, - Content: s.Content, - Params: s.Params, - Version: s.Version, - VersionDesc: s.VersionDesc, - Creator: s.Creator, + Content: s.FirstVersion.Content, + Params: s.FirstVersion.Params, + Version: s.FirstVersion.Version, + VersionDesc: s.FirstVersion.VersionDesc, + Creator: s.Script.Creator, CreatedAt: time.Now().Format("2006-01-02 15:04:05"), - LastModifyUser: s.Creator, + LastModifyUser: s.Script.Creator, LastModifyUpdatedAt: time.Now().Format("2006-01-02 15:04:05"), } diff --git a/automation/server/internal/service/mysql.go b/automation/server/internal/service/mysql.go index f3a10aeba0b5c91d6ed84ad788acb340540b2113..7d2cac8c51343a1dfd57b9e6f7d5cabf64e112bd 100644 --- a/automation/server/internal/service/mysql.go +++ b/automation/server/internal/service/mysql.go @@ -8,6 +8,7 @@ import ( "gorm.io/gorm/schema" "openeuler.org/PilotGo/PilotGo-plugin-automation/cmd/config/options" dangerousRule "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/dangerous_rule/model" + jobworkflow "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/job_workflow/model" scriptLibrary "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/script_library/model" ) @@ -45,6 +46,10 @@ func (m *MySQLService) Init(ctx *AppContext) error { db.AutoMigrate(&scriptLibrary.Tag{}) db.AutoMigrate(&scriptLibrary.Script{}) db.AutoMigrate(&scriptLibrary.ScriptVersion{}) + db.AutoMigrate(&jobworkflow.TaskTemplate{}) + db.AutoMigrate(&jobworkflow.TaskTemplateVariable{}) + db.AutoMigrate(&jobworkflow.TaskTemplateStep{}) + db.AutoMigrate(&jobworkflow.TaskTemplateStepScript{}) ctx.MySQL = db return nil