dto.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. package model
  2. import (
  3. "time"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Machine Machine.
  7. type Machine struct {
  8. ID int64 `json:"id" gorm:"column:id"`
  9. Name string `json:"name" gorm:"column:name"`
  10. PodName string `json:"pod_name,omitempty" gorm:"column:pod_name"`
  11. Status int `json:"status" gorm:"column:status"`
  12. Username string `json:"username" gorm:"column:username"`
  13. BusinessUnit string `json:"business_unit,omitempty" gorm:"column:business_unit"`
  14. Project string `json:"project,omitempty" gorm:"column:project"`
  15. App string `json:"app,omitempty" gorm:"column:app"`
  16. ClusterID int64 `json:"cluster_id,omitempty" gorm:"column:cluster_id"`
  17. NetworkID int64 `json:"network_id,omitempty" gorm:"column:network_id"`
  18. Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  19. Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  20. UpdateBy string `json:"update_by" gorm:"column:update_by"`
  21. EndTime time.Time `json:"end_time" gorm:"column:end_time"`
  22. Comment string `json:"comment" gorm:"column:comment"`
  23. DelayStatus int `json:"delay_status" gorm:"column:delay_status"`
  24. }
  25. // AfterCreate After Create.
  26. func (m *Machine) AfterCreate(db *gorm.DB) (err error) {
  27. if err = db.Model(m).Where("name = ?", m.Name).Find(&m).Error; err != nil {
  28. return
  29. }
  30. m.EndTime = m.Ctime.AddDate(0, 3, 0)
  31. if err = db.Model(&Machine{}).Where("id = ?", m.ID).Update("end_time", m.EndTime).Error; err != nil {
  32. return
  33. }
  34. return
  35. }
  36. // AfterCreate After Create.
  37. func (h *HubImageLog) AfterCreate(db *gorm.DB) (err error) {
  38. err = db.Model(h).Where("imagetag = ?", h.ImageTag).Find(&h).Error
  39. return
  40. }
  41. // IsFailed Is Failed.
  42. func (m *Machine) IsFailed() bool {
  43. return m.Status >= ImmediatelyFailedMachineInMerlin && m.Status < RemovedMachineInMerlin
  44. }
  45. // IsDeleted Is Deleted.
  46. func (m *Machine) IsDeleted() bool {
  47. return m.Status >= RemovedMachineInMerlin && m.Status < CreatingMachineInMerlin
  48. }
  49. // IsCreating Is Creating.
  50. func (m *Machine) IsCreating() bool {
  51. return m.Status >= CreatingMachineInMerlin && m.Status < BootMachineInMerlin
  52. }
  53. // IsBoot Is Boot.
  54. func (m *Machine) IsBoot() bool {
  55. return m.Status >= BootMachineInMerlin && m.Status < ShutdownMachineInMerlin
  56. }
  57. // IsShutdown Is Shutdown.
  58. func (m *Machine) IsShutdown() bool {
  59. return m.Status >= ShutdownMachineInMerlin && m.Status < 300
  60. }
  61. // ToTreeNode return Tree node.
  62. func (m *Machine) ToTreeNode() *TreeNode {
  63. return &TreeNode{
  64. BusinessUnit: m.BusinessUnit,
  65. Project: m.Project,
  66. App: m.App,
  67. }
  68. }
  69. // ToMachineLog generate a machine log struct.
  70. func (m *Machine) ToMachineLog() (ml *MachineLog) {
  71. ml = &MachineLog{
  72. OperateType: GenForMachineLog,
  73. Username: m.Username,
  74. MachineID: m.ID,
  75. }
  76. if m.Status == CreatingMachineInMerlin {
  77. ml.OperateResult = OperationSuccessForMachineLog
  78. } else if m.Status == ImmediatelyFailedMachineInMerlin {
  79. ml.OperateResult = OperationFailedForMachineLog
  80. }
  81. return
  82. }
  83. // MachineLog Machine Log.
  84. type MachineLog struct {
  85. ID int64 `json:"-" gorm:"column:id"`
  86. Username string `json:"username" gorm:"column:username"`
  87. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  88. OperateType string `json:"operate_type" gorm:"column:operation_type"`
  89. OperateResult string `json:"operate_result" gorm:"column:operation_result"`
  90. OperateTime time.Time `json:"operate_time" gorm:"column:ctime;default:current_timestamp"`
  91. UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  92. }
  93. // MobileMachineLog Mobile Machine Log.
  94. type MobileMachineLog struct {
  95. ID int64 `json:"-" gorm:"column:id"`
  96. Username string `json:"username" gorm:"column:username"`
  97. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  98. OperateType string `json:"operate_type" gorm:"column:operation_type"`
  99. OperateResult string `json:"operate_result" gorm:"column:operation_result"`
  100. OperateTime time.Time `json:"operate_time" gorm:"column:ctime;default:current_timestamp"`
  101. UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  102. }
  103. // MobileMachineErrorLog Mobile Machine Error Log.
  104. type MobileMachineErrorLog struct {
  105. ID int64 `json:"id" gorm:"column:id"`
  106. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  107. SerialName string `json:"serial" gorm:"column:serial"`
  108. ErrorMessage string `json:"error_message" gorm:"column:error_message"`
  109. ErrorCode int `json:"error_code" gorm:"column:error_code"`
  110. CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
  111. UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  112. }
  113. // Snapshot Snapshot.
  114. type Snapshot struct {
  115. ID int64 `gorm:"column:id"`
  116. Name string `gorm:"column:name"`
  117. MachineID int64 `gorm:"column:machine_id"`
  118. UserID int64 `gorm:"column:user_id"`
  119. Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  120. Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  121. UpdateBy int `gorm:"column:update_by"`
  122. Comment string `gorm:"column:comment"`
  123. }
  124. // SnapshotLog Snapshot Log.
  125. type SnapshotLog struct {
  126. ID int64 `gorm:"column:id"`
  127. UserID int64 `gorm:"column:user_id"`
  128. SnapshotID int64 `gorm:"column:snapshot_id"`
  129. OperateType string `gorm:"column:operation_type"`
  130. OperateResult int `gorm:"column:operation_result"`
  131. OperateTime time.Time `gorm:"column:operation_time;default:current_timestamp"`
  132. }
  133. // Task Task.
  134. type Task struct {
  135. ID int64 `gorm:"column:id"`
  136. TYPE string `gorm:"column:type"`
  137. ExecuteTime time.Time `gorm:"column:execute_time"`
  138. MachineID int64 `gorm:"column:machine_id"`
  139. Status int `gorm:"column:status"`
  140. Ctime time.Time `gorm:"column:ctime;default:current_timestamp"`
  141. UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  142. }
  143. // User User.
  144. type User struct {
  145. ID int64 `json:"id" gorm:"auto_increment;primary_key;column:id"`
  146. Name string `json:"username" gorm:"column:name"`
  147. EMail string `json:"email" gorm:"column:email"`
  148. CTime time.Time `gorm:"column:ctime;default:current_timestamp"`
  149. UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  150. }
  151. // Image Image.
  152. type Image struct {
  153. ID int64 `json:"id" gorm:"auto_increment;primary_key;column:id"`
  154. Name string `json:"name" gorm:"varchar(100);column:name"`
  155. Status int `json:"status" gorm:"not null;column:status"`
  156. OS string `json:"os" gorm:"not null;column:os"`
  157. Version string `json:"version" gorm:"not null;column:version"`
  158. Description string `json:"description" gorm:"column:description"`
  159. CreatedBy string `json:"created_by" gorm:"column:created_by"`
  160. UpdatedBy string `json:"updated_by" gorm:"column:updated_by"`
  161. Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  162. Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  163. }
  164. // MachinePackage MachinePackage.
  165. type MachinePackage struct {
  166. ID int64 `json:"id" gorm:"column:id"`
  167. Name string `json:"name" gorm:"column:name"`
  168. CPUCore int `json:"cpu_request" gorm:"column:cpu_core"`
  169. Memory int `json:"memory_request" gorm:"column:memory"`
  170. StorageCapacity int `json:"disk_request" gorm:"column:storage_capacity"`
  171. CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  172. UTime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  173. }
  174. // MailLog MailLog.
  175. type MailLog struct {
  176. ID int64 `gorm:"column:id"`
  177. ReceiverName string `gorm:"column:receiver_name"`
  178. MailType int `gorm:"column:mail_type"`
  179. SendHead string `gorm:"column:send_head"`
  180. SendContext string `gorm:"column:send_context"`
  181. SendTime time.Time `gorm:"column:ctime;default:current_timestamp"`
  182. UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  183. }
  184. // ToPaasQueryAndDelMachineRequest To Paas Query And Del Machine Request.
  185. func (m *Machine) ToPaasQueryAndDelMachineRequest() (pqadmr *PaasQueryAndDelMachineRequest) {
  186. pqadmr = &PaasQueryAndDelMachineRequest{}
  187. pqadmr.Name = m.Name
  188. pqadmr.BusinessUnit = m.BusinessUnit
  189. pqadmr.Project = m.Project
  190. pqadmr.App = m.App
  191. pqadmr.ClusterID = m.ClusterID
  192. return
  193. }
  194. // ApplicationRecord ApplicationRecord.
  195. type ApplicationRecord struct {
  196. ID int64 `json:"id" gorm:"column:id"`
  197. Applicant string `json:"applicant" gorm:"column:applicant"`
  198. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  199. ApplyEndTime time.Time `json:"apply_end_time" gorm:"column:apply_end_time"`
  200. Status string `json:"status" gorm:"column:status"`
  201. Auditor string `json:"auditor" gorm:"column:auditor"`
  202. CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  203. UTime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  204. }
  205. // MachineNode the node is associated with machine.
  206. type MachineNode struct {
  207. ID int64 `json:"id" gorm:"column:id"`
  208. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  209. BusinessUnit string `json:"business_unit" gorm:"column:business_unit"`
  210. Project string `json:"project" gorm:"column:project"`
  211. App string `json:"app" gorm:"column:app"`
  212. TreeID int64 `json:"tree_id,omitempty" gorm:"column:tree_id"`
  213. CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
  214. }
  215. // HubImageLog Hub Image Log
  216. type HubImageLog struct {
  217. ID int64 `json:"id" gorm:"column:id"`
  218. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  219. UserName string `json:"username" gorm:"column:username"`
  220. ImageSrc string `json:"image_src" gorm:"column:imagesrc"`
  221. ImageTag string `json:"image_tag" gorm:"column:imagetag"`
  222. Status int `json:"status" gorm:"column:status"`
  223. OperateType int `json:"operate_type" gorm:"column:operate_type"`
  224. CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
  225. UTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  226. }
  227. // MobileMachine the node is associated with MobileMachine.
  228. type MobileMachine struct {
  229. ID int64 `json:"id" gorm:"column:id"`
  230. Serial string `json:"serial" gorm:"column:serial"`
  231. Name string `json:"name" gorm:"column:name"`
  232. CPU string `json:"cpu" gorm:"column:cpu"`
  233. Version string `json:"version" gorm:"column:version"`
  234. Mode string `json:"mode" gorm:"column:mode"`
  235. State string `json:"state" gorm:"column:state"`
  236. Host string `json:"host" gorm:"column:host"`
  237. CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
  238. MTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp"`
  239. LastBindTime time.Time `json:"last_bind_time" gorm:"column:last_bind_time;default:current_timestamp"`
  240. OwnerName string `json:"owner_name" gorm:"column:owner_name"`
  241. Username string `json:"username" gorm:"column:username"`
  242. Type int `json:"type" gorm:"column:type"`
  243. EndTime time.Time `json:"end_time" gorm:"column:end_time"`
  244. Alias string `json:"alias" gorm:"column:alias"`
  245. Comment string `json:"comment" gorm:"column:comment"`
  246. WsURL string `json:"wsurl" gorm:"column:wsurl"`
  247. UploadURL string `json:"upload_url" gorm:"column:upload_url"`
  248. Action int `json:"action" gorm:"column:action"`
  249. IsLendOut int `json:"is_lendout" gorm:"column:is_lendout"`
  250. UUID string `json:"uuid" gorm:"column:uuid"`
  251. }
  252. // MobileImage Mobile Image.
  253. type MobileImage struct {
  254. ID int64 `json:"id" gorm:"column:id"`
  255. Mode string `json:"mode" gorm:"column:mode"`
  256. CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  257. MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp"`
  258. ImageSrc string `json:"image_src" gorm:"column:image_src"`
  259. }
  260. // MobileSyncLog MobileSyncLog.
  261. type MobileSyncLog struct {
  262. ID int64 `json:"id" gorm:"column:id"`
  263. UUID string `json:"uuid" gorm:"column:uuid"`
  264. AddCnt int `json:"add_count" gorm:"column:add_count"`
  265. UpdateCnt int `json:"update_count" gorm:"column:update_count"`
  266. DeleteCnt int `json:"delete_count" gorm:"column:delete_count"`
  267. TotalCnt int `json:"total_count" gorm:"column:total_count"`
  268. Status int `json:"status" gorm:"column:status"`
  269. CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  270. MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp"`
  271. }
  272. // MobileCategory MobileCategory.
  273. type MobileCategory struct {
  274. CPUs []string `json:"cpus"`
  275. Versions []string `json:"versions"`
  276. Modes []string `json:"modes"`
  277. States []string `json:"states"`
  278. Types []int `json:"types"`
  279. Usages []int `json:"usages"`
  280. }
  281. // SnapshotRecord Snapshot Record
  282. type SnapshotRecord struct {
  283. ID int64 `json:"id" gorm:"column:id"`
  284. MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
  285. Username string `json:"username" gorm:"column:username"`
  286. ImageName string `json:"image_name" gorm:"column:image_name"`
  287. Status string `json:"status" gorm:"column:status"`
  288. Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
  289. MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  290. }
  291. // HubImageConf Hub Image Conf
  292. type HubImageConf struct {
  293. ID int64 `json:"id" gorm:"column:id"`
  294. ImageName string `json:"image_name" gorm:"column:image_name"`
  295. UpdateBy string `json:"update_by" gorm:"column:update_by"`
  296. Command string `json:"command" gorm:"column:command"`
  297. Envs string `json:"environments" gorm:"column:environments"`
  298. Hosts string `json:"hosts" gorm:"column:hosts"`
  299. CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
  300. UTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
  301. }