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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. utils.Convert(hpcInfo.Environment, &resp.HpcInfoList[i].Environment)
  48. resp.HpcInfoList[i].ClusterType = clusterType
  49. }
  50. }
  51. case 0:
  52. var resourceType int32
  53. l.svcCtx.DbEngin.Raw("select resource_type as resourceType from `t_adapter` where id = ?", req.AdapterId).Scan(&resourceType)
  54. switch resourceType {
  55. case 01:
  56. var cloudModelList []cloud.TaskCloudModel
  57. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &cloudModelList)
  58. if err != nil {
  59. return nil, err
  60. }
  61. utils.Convert(cloudModelList, &resp.CloudInfoList)
  62. case 02:
  63. var vmModelList []models.TaskVm
  64. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &vmModelList)
  65. if err != nil {
  66. return nil, err
  67. }
  68. utils.Convert(vmModelList, &resp.VmInfoList)
  69. }
  70. case 1:
  71. var aiModelList []models.TaskAiAsynchronous
  72. err := findModelList(req.AdapterId, l.svcCtx.DbEngin, &aiModelList)
  73. if err != nil {
  74. return nil, err
  75. }
  76. utils.Convert(aiModelList, &resp.AiInfoList)
  77. }
  78. return &resp, nil
  79. }
  80. func findModelList(adapterId int64, dbEngin *gorm.DB, data interface{}) error {
  81. tx := dbEngin.Where("cluster_id in (select id from t_cluster where adapter_id = ?) AND status not in "+
  82. "('Deleted', 'Succeeded', 'COMPLETED', 'Completed', 'Failed','FAIL','statC','statE')", adapterId).Find(data)
  83. if tx.Error != nil {
  84. return tx.Error
  85. }
  86. return nil
  87. }

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.