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

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

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.