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.

applistlogic.go 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package apps
  2. import (
  3. "context"
  4. "gorm.io/datatypes"
  5. "gorm.io/gorm"
  6. "time"
  7. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  8. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type AppListLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppListLogic {
  17. return &AppListLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. type Task struct {
  24. Id int64 `db:"id"` // id
  25. Name string `db:"name"` // 作业名称
  26. Description string `db:"description"` // 作业描述
  27. Status string `db:"status"` // 作业状态
  28. Strategy int64 `db:"strategy"` // 策略
  29. SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
  30. CommitTime time.Time `db:"commit_time"` // 提交时间
  31. StartTime string `db:"start_time"` // 开始时间
  32. EndTime string `db:"end_time"` // 结束运行时间
  33. RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
  34. YamlString datatypes.JSON `db:"yaml_string"`
  35. Result string `db:"result"` // 作业结果
  36. DeletedAt gorm.DeletedAt `gorm:"index"`
  37. NsID string `db:"ns_id"`
  38. PName string `db:"p_name"` // p端名称
  39. PId int64 `db:"p_id"` // p端id
  40. }
  41. func (l *AppListLogic) AppList(req *types.AppListReq) (resp *types.AppListResp, err error) {
  42. var tasks []Task
  43. resp = &types.AppListResp{}
  44. l.svcCtx.DbEngin.Raw("SELECT t.*,phy.name as p_name,phy.id as p_id FROM task t LEFT JOIN cloud c ON c.task_id = t.id join sc_participant_phy_info phy on c.participant_id = phy.id WHERE c.kind in ('Deployment', 'StatefulSet') AND t.`ns_id` = ? AND t.`deleted_at` IS NULL ORDER BY t.created_time Desc", req.NsID).Scan(&tasks)
  45. for _, task := range tasks {
  46. var replicas []types.Replica
  47. l.svcCtx.DbEngin.Raw("SELECT sc_participant_phy_info.name,replica FROM cloud left join sc_participant_phy_info on cloud.participant_id = sc_participant_phy_info.id WHERE task_id =?", task.Id).Scan(&replicas)
  48. resp.Apps = append(resp.Apps, types.App{
  49. Id: task.Id,
  50. Name: task.Name,
  51. Status: task.Status,
  52. StartTime: task.StartTime,
  53. EndTime: task.EndTime,
  54. CreateTime: task.CommitTime.Format("2006-01-02 15:04:05"),
  55. ParticipantId: task.PId,
  56. ParticipantName: task.PName,
  57. Replicas: replicas,
  58. })
  59. }
  60. return
  61. }

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.