deploy.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package forms
  2. import (
  3. "errors"
  4. "fmt"
  5. "gadmin/internal/gorm/model"
  6. )
  7. type DeployNotifyReq struct {
  8. Code int `json:"code" form:"code"`
  9. Msg string `json:"msg" form:"msg"`
  10. TraceID string `json:"traceID" form:"traceID"`
  11. LogFile string `json:"logFile" form:"logFile"`
  12. }
  13. func (req *DeployNotifyReq) Check() error {
  14. if req.TraceID == "" {
  15. return errors.New("TraceID不能为空")
  16. }
  17. return nil
  18. }
  19. type DeployLogViewReq struct {
  20. Id int64 `json:"id" form:"id"`
  21. LogFile string `json:"log_file"` // 日志路径
  22. }
  23. func (req *DeployLogViewReq) Check() error {
  24. if req.Id <= 0 {
  25. return errors.New("操作记录ID不能为空")
  26. }
  27. return nil
  28. }
  29. type DeployLogViewModel struct {
  30. model.ServerDeployLog
  31. LogContent string `json:"stdout"`
  32. }
  33. type DeployLogListReq struct {
  34. ListReq
  35. DeployId int64 `json:"deployId" form:"deployId"`
  36. }
  37. func (req *DeployLogListReq) Check() error {
  38. if req.DeployId <= 0 {
  39. return errors.New("部署ID不能为空")
  40. }
  41. return nil
  42. }
  43. type DeployLogListModel struct {
  44. model.ServerDeployLog
  45. AdminName string `json:"adminName"`
  46. }
  47. type DeployListReq struct {
  48. ListReq
  49. GroupId int64 `json:"groupId" form:"groupId"`
  50. ContainerName string `json:"container_name" form:"container_name"`
  51. Name string `json:"name" form:"name"`
  52. ServerType []string `json:"server_type[]" form:"server_type[]"`
  53. RunStatus []string `json:"run_status[]" form:"run_status[]"`
  54. DeployStatus []string `json:"deploy_status[]" form:"deploy_status[]"`
  55. }
  56. func (req *DeployListReq) Check() error {
  57. return nil
  58. }
  59. type DeployListData struct {
  60. model.ServerDeploy
  61. AdminName string `json:"adminName"`
  62. }
  63. type DeployTaskReq struct {
  64. ID int64 `json:"id" form:"id"`
  65. Version string `json:"version" form:"version"` // 部署版本号
  66. Type int64 `json:"type" form:"type"` // 部署类型
  67. Ids []int64 `json:"ids" form:"ids"` // 批量部署ID
  68. DeployServ []string `json:"deployServ" form:"deployServ"` // 部署服务选项
  69. }
  70. func (req *DeployTaskReq) Check() error {
  71. switch req.Type {
  72. case 1:
  73. if req.ID <= 0 {
  74. return errors.New("部署ID不能为空")
  75. }
  76. req.Ids = []int64{req.ID}
  77. case 2:
  78. // 去重
  79. var ids []int64
  80. for _, id := range req.Ids {
  81. if id > 0 {
  82. ids = append(ids, id)
  83. }
  84. }
  85. req.Ids = ids
  86. if len(req.Ids) == 0 {
  87. return errors.New("请选择需要部署的服务器")
  88. }
  89. default:
  90. return errors.New(fmt.Sprintf("部署类型是无效的:%v", req.Type))
  91. }
  92. if req.Version == "" {
  93. return errors.New("版本号不能为空")
  94. }
  95. if len(req.DeployServ) == 0 {
  96. return errors.New("请选择部署服务")
  97. }
  98. return nil
  99. }
  100. type DeployStopReq struct {
  101. ID int64 `json:"id" form:"id"`
  102. Type int64 `json:"type" form:"type"` // 部署类型
  103. Ids []int64 `json:"ids" form:"ids"`
  104. StopType int64 `json:"stop_type" form:"stop_type"` // 停服方式
  105. }
  106. func (req *DeployStopReq) Check() error {
  107. switch req.Type {
  108. case 1:
  109. if req.ID <= 0 {
  110. return errors.New("部署ID不能为空")
  111. }
  112. req.Ids = []int64{req.ID}
  113. case 2:
  114. // 去重
  115. var ids []int64
  116. for _, id := range req.Ids {
  117. if id > 0 {
  118. ids = append(ids, id)
  119. }
  120. }
  121. req.Ids = ids
  122. if len(req.Ids) == 0 {
  123. return errors.New("请选择需要部署的服务器")
  124. }
  125. default:
  126. return errors.New(fmt.Sprintf("部署类型是无效的:%v", req.Type))
  127. }
  128. if req.StopType != 2 && req.StopType != 9 {
  129. return errors.New("停服方式是无效的")
  130. }
  131. return nil
  132. }
  133. type DeployEditReq struct {
  134. ID int64 `json:"id" form:"id"`
  135. GroupID int32 `json:"group_id" form:"group_id"` // 模板ID
  136. ContainerName string `json:"container_name" form:"container_name"` // 加装类型
  137. Name string `json:"name" form:"name"` // 模板名称
  138. ServerType string `json:"server_type" form:"server_type"`
  139. DockerAddr string `json:"docker_addr" form:"docker_addr"` // 关联ID
  140. CaPem string `json:"ca_pem" form:"ca_pem"` // 关联ID
  141. CertPem string `json:"cert_pem" form:"cert_pem"` // 关联ID
  142. KeyPem string `json:"key_pem" form:"key_pem"` // 关联ID
  143. Remark string `json:"remark" form:"remark"` // 关联ID
  144. IsMproom int32 `json:"is_mproom" form:"is_mproom"` // 是否启用IsMproom
  145. }
  146. type DeployDeleteReq struct {
  147. ID int64 `json:"id" form:"id"`
  148. }