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 1.6 kB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package database
  2. import (
  3. "github.com/zeromicro/go-zero/core/logx"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/entity"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  6. "gorm.io/gorm"
  7. )
  8. type CloudStorage struct {
  9. DbEngin *gorm.DB
  10. }
  11. func NewCloudStorage(dbEngin *gorm.DB) *CloudStorage {
  12. return &CloudStorage{DbEngin: dbEngin}
  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. }

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.