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.

cloudStorage.go 2.8 kB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/scheduler/entity"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  7. "gorm.io/gorm"
  8. "strconv"
  9. "time"
  10. )
  11. type CloudStorage struct {
  12. DbEngin *gorm.DB
  13. }
  14. func (c *CloudStorage) GetProviderParams() ([]entity.ProviderParams, error) {
  15. var proParams []entity.ProviderParams
  16. sqlstr := "SELECT SUM(a.disk_avail) as disk_avail,SUM(a.mem_avail) as mem_avail,SUM(a.cpu_total * a.cpu_usable) as cpu_avail,participant_id from (SELECT * from sc_node_avail_info where created_time in (SELECT MAX(created_time) as time from sc_node_avail_info where deleted_flag = 0 GROUP BY participant_id,node_name)) a GROUP BY a.participant_id"
  17. c.DbEngin.Raw(sqlstr).Scan(&proParams)
  18. if len(proParams) == 0 {
  19. return nil, nil
  20. }
  21. return proParams, nil
  22. }
  23. func (c *CloudStorage) FindAvailableParticipants() ([]entity.Participant, error) {
  24. var parts []entity.Participant
  25. sqlstr := "select id as participant_id, name as name from sc_participant_phy_info"
  26. c.DbEngin.Raw(sqlstr).Scan(&parts)
  27. if len(parts) == 0 {
  28. return nil, nil
  29. }
  30. return parts, nil
  31. }
  32. func (c *CloudStorage) GetClustersByAdapterId(id string) (*types.ClusterListResp, error) {
  33. var resp types.ClusterListResp
  34. tx := c.DbEngin.Raw("select * from t_cluster where `deleted_at` IS NULL and `adapter_id` = ? ORDER BY create_time Desc", id).Scan(&resp.List)
  35. if tx.Error != nil {
  36. logx.Errorf(tx.Error.Error())
  37. return nil, tx.Error
  38. }
  39. return &resp, nil
  40. }
  41. func (s *CloudStorage) GetAdaptersByType(adapterType string) ([]*types.AdapterInfo, error) {
  42. var list []*types.AdapterInfo
  43. db := s.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
  44. db = db.Where("type = ?", adapterType)
  45. err := db.Order("create_time desc").Find(&list).Error
  46. if err != nil {
  47. return nil, err
  48. }
  49. return list, nil
  50. }
  51. func (c *CloudStorage) AddNoticeInfo(adapterId string, adapterName string, clusterId string, clusterName string, taskName string, noticeType string, incident string) {
  52. aId, err := strconv.ParseInt(adapterId, 10, 64)
  53. if err != nil {
  54. logx.Errorf("adapterId convert failure, err: %v", err)
  55. }
  56. var cId int64
  57. if clusterId != "" {
  58. cId, err = strconv.ParseInt(clusterId, 10, 64)
  59. if err != nil {
  60. logx.Errorf("clusterId convert failure, err: %v", err)
  61. }
  62. }
  63. noticeInfo := clientCore.NoticeInfo{
  64. AdapterId: aId,
  65. AdapterName: adapterName,
  66. ClusterId: cId,
  67. ClusterName: clusterName,
  68. NoticeType: noticeType,
  69. TaskName: taskName,
  70. Incident: incident,
  71. CreatedTime: time.Now(),
  72. }
  73. result := c.DbEngin.Table("t_notice").Create(&noticeInfo)
  74. if result.Error != nil {
  75. logx.Errorf("Task creation failure, err: %v", result.Error)
  76. }
  77. }

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.