You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

hpc_storage.go 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package database
  2. import (
  3. "github.com/zeromicro/go-zero/core/logx"
  4. clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  8. "gorm.io/gorm"
  9. "strconv"
  10. "time"
  11. )
  12. type HpcStorage struct {
  13. DbEngin *gorm.DB
  14. }
  15. func (s *HpcStorage) GetParticipants() (*types.ClusterListResp, error) {
  16. var resp types.ClusterListResp
  17. tx := s.DbEngin.Raw("select * from t_cluster where `deleted_at` IS NULL ORDER BY create_time Desc").Scan(&resp.List)
  18. if tx.Error != nil {
  19. logx.Errorf(tx.Error.Error())
  20. return nil, tx.Error
  21. }
  22. return &resp, nil
  23. }
  24. func (s *HpcStorage) GetClustersByAdapterId(id string) (*types.ClusterListResp, error) {
  25. var resp types.ClusterListResp
  26. tx := s.DbEngin.Raw("select * from t_cluster where `deleted_at` IS NULL and `adapter_id` = ? ORDER BY create_time Desc", id).Scan(&resp.List)
  27. if tx.Error != nil {
  28. logx.Errorf(tx.Error.Error())
  29. return nil, tx.Error
  30. }
  31. return &resp, nil
  32. }
  33. func (s *HpcStorage) GetClusterNameById(id string) (string, error) {
  34. var name string
  35. tx := s.DbEngin.Raw("select `description` from t_cluster where `id` = ?", id).Scan(&name)
  36. if tx.Error != nil {
  37. logx.Errorf(tx.Error.Error())
  38. return "", tx.Error
  39. }
  40. return name, nil
  41. }
  42. func (s *HpcStorage) GetAdapterNameById(id string) (string, error) {
  43. var name string
  44. tx := s.DbEngin.Raw("select `name` from t_adapter where `id` = ?", id).Scan(&name)
  45. if tx.Error != nil {
  46. logx.Errorf(tx.Error.Error())
  47. return "", tx.Error
  48. }
  49. return name, nil
  50. }
  51. func (s *HpcStorage) GetAdapterIdsByType(adapterType string) ([]string, error) {
  52. var list []types.AdapterInfo
  53. var ids []string
  54. db := s.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
  55. db = db.Where("type = ?", adapterType)
  56. err := db.Order("create_time desc").Find(&list).Error
  57. if err != nil {
  58. return nil, err
  59. }
  60. for _, info := range list {
  61. ids = append(ids, info.Id)
  62. }
  63. return ids, nil
  64. }
  65. func (s *HpcStorage) GetAdaptersByType(adapterType string) ([]*types.AdapterInfo, error) {
  66. var list []*types.AdapterInfo
  67. db := s.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
  68. db = db.Where("type = ?", adapterType)
  69. err := db.Order("create_time desc").Find(&list).Error
  70. if err != nil {
  71. return nil, err
  72. }
  73. return list, nil
  74. }
  75. func (s *HpcStorage) GetHpcTasksByAdapterId(adapterId string) ([]*models.TaskHpc, error) {
  76. var resp []*models.TaskHpc
  77. db := s.DbEngin.Model(&models.TaskHpc{}).Table("task_hpc")
  78. db = db.Where("adapter_id = ?", adapterId)
  79. err := db.Order("start_time desc").Find(&resp).Error
  80. if err != nil {
  81. return nil, err
  82. }
  83. return resp, nil
  84. }
  85. func (s *HpcStorage) GetHpcTaskListById(id int64) ([]*models.TaskHpc, error) {
  86. var taskList []*models.TaskHpc
  87. tx := s.DbEngin.Raw("select * from task_hpc where `task_id` = ? ", id).Scan(&taskList)
  88. if tx.Error != nil {
  89. return nil, tx.Error
  90. }
  91. return taskList, nil
  92. }
  93. func (s *HpcStorage) UpdateTask(task *types.TaskModel) error {
  94. task.UpdatedTime = time.Now().Format(constants.Layout)
  95. tx := s.DbEngin.Table("task").Model(task).Updates(task)
  96. if tx.Error != nil {
  97. logx.Errorf(tx.Error.Error())
  98. return tx.Error
  99. }
  100. return nil
  101. }
  102. func (s *HpcStorage) UpdateHpcTask(task *models.TaskHpc) error {
  103. tx := s.DbEngin.Updates(task)
  104. if tx.Error != nil {
  105. return tx.Error
  106. }
  107. return nil
  108. }
  109. func (s *HpcStorage) AddNoticeInfo(adapterId string, adapterName string, clusterId string, clusterName string, taskName string, noticeType string, incident string) {
  110. aId, err := strconv.ParseInt(adapterId, 10, 64)
  111. if err != nil {
  112. logx.Errorf("adapterId convert failure, err: %v", err)
  113. }
  114. var cId int64
  115. if clusterId != "" {
  116. cId, err = strconv.ParseInt(clusterId, 10, 64)
  117. if err != nil {
  118. logx.Errorf("clusterId convert failure, err: %v", err)
  119. }
  120. }
  121. noticeInfo := clientCore.NoticeInfo{
  122. AdapterId: aId,
  123. AdapterName: adapterName,
  124. ClusterId: cId,
  125. ClusterName: clusterName,
  126. NoticeType: noticeType,
  127. TaskName: taskName,
  128. Incident: incident,
  129. CreatedTime: time.Now(),
  130. }
  131. result := s.DbEngin.Table("t_notice").Create(&noticeInfo)
  132. if result.Error != nil {
  133. logx.Errorf("Task creation failure, err: %v", result.Error)
  134. }
  135. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.