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.

pulltaskinfologic.go 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package core
  2. import (
  3. "context"
  4. "github.com/jinzhu/copier"
  5. clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  9. "gitlink.org.cn/jcce-pcm/utils/tool"
  10. "gorm.io/gorm"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  13. )
  14. type PullTaskInfoLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewPullTaskInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PullTaskInfoLogic {
  20. return &PullTaskInfoLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *PullTaskInfoLogic) PullTaskInfo(req *clientCore.PullTaskInfoReq) (*clientCore.PullTaskInfoResp, error) {
  27. resp := clientCore.PullTaskInfoResp{}
  28. // check the kind of adapter
  29. var kind int32
  30. l.svcCtx.DbEngin.Raw("select type as kind from `t_adapter` where id = ?", req.AdapterId).Scan(&kind)
  31. // pull task list from database
  32. switch kind {
  33. case 2:
  34. var hpcModelList []models.TaskHpc
  35. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &hpcModelList)
  36. if err != nil {
  37. return nil, err
  38. }
  39. utils.Convert(hpcModelList, &resp.HpcInfoList)
  40. if len(resp.HpcInfoList) > 0 {
  41. for i, hpcInfo := range hpcModelList {
  42. err := copier.CopyWithOption(resp.HpcInfoList[i], hpcInfo, copier.Option{Converters: utils.Converters})
  43. if err != nil {
  44. return nil, err
  45. }
  46. var clusterType string
  47. l.svcCtx.DbEngin.Raw("SELECT label FROM `t_cluster` where id = ? ", hpcInfo.ClusterId).Scan(&clusterType)
  48. tool.Convert(hpcInfo.Environment, &resp.HpcInfoList[i].Environment)
  49. resp.HpcInfoList[i].ClusterType = clusterType
  50. }
  51. }
  52. case 0:
  53. var resourceType int32
  54. l.svcCtx.DbEngin.Raw("select resource_type as resourceType from `t_adapter` where id = ?", req.AdapterId).Scan(&resourceType)
  55. switch resourceType {
  56. case 01:
  57. var cloudModelList []cloud.TaskCloudModel
  58. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &cloudModelList)
  59. if err != nil {
  60. return nil, err
  61. }
  62. utils.Convert(cloudModelList, &resp.CloudInfoList)
  63. case 02:
  64. var vmModelList []models.TaskVm
  65. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &vmModelList)
  66. if err != nil {
  67. return nil, err
  68. }
  69. utils.Convert(vmModelList, &resp.VmInfoList)
  70. }
  71. case 1:
  72. var aiModelList []models.Ai
  73. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &aiModelList)
  74. if err != nil {
  75. return nil, err
  76. }
  77. utils.Convert(aiModelList, &resp.AiInfoList)
  78. }
  79. return &resp, nil
  80. }
  81. func findModelList(adapterId int64, dbEngin *gorm.DB, data interface{}) error {
  82. tx := dbEngin.Where("cluster_id in (select id from t_cluster where adapter_id = ?) AND status not in "+
  83. "('Deleted', 'Succeeded', 'COMPLETED', 'Completed', 'Failed','FAIL','statC','statE')", adapterId).Find(data)
  84. if tx.Error != nil {
  85. return tx.Error
  86. }
  87. return nil
  88. }

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.