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.

reportavailablelogic.go 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package participantservicelogic
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/pkg/errors"
  6. "gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
  7. "gitlink.org.cn/jcce-pcm/utils/tool"
  8. "gorm.io/gorm"
  9. "time"
  10. "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
  11. "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type ReportAvailableLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewReportAvailableLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReportAvailableLogic {
  20. return &ReportAvailableLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. // ReportAvailable 监控数据上报
  27. func (l *ReportAvailableLogic) ReportAvailable(in *pcmCore.ParticipantAvailReq) (*pcmCore.ParticipantResp, error) {
  28. db := l.svcCtx.DbEngin.Begin()
  29. // 执行回滚或者提交操作
  30. defer func() {
  31. if p := recover(); p != nil {
  32. db.Rollback()
  33. logx.Error(p)
  34. } else if db.Error != nil {
  35. logx.Info("rollback")
  36. db.Rollback()
  37. } else {
  38. db = db.Commit()
  39. logx.Info("commit success")
  40. }
  41. }()
  42. //判断Participant静态信息是否存在
  43. participantPhyInfo := &model.ScParticipantPhyInfo{}
  44. participantPhyInfo.Id = in.ParticipantId
  45. if in.ParticipantId == 0 {
  46. return &pcmCore.ParticipantResp{
  47. Code: 500,
  48. Msg: fmt.Sprintf("ParticipantInfo Does not exist, please check participantPhyId: %d", in.ParticipantId),
  49. }, nil
  50. }
  51. if errors.Is(db.Take(&participantPhyInfo).Error, gorm.ErrRecordNotFound) {
  52. return &pcmCore.ParticipantResp{
  53. Code: 500,
  54. Msg: fmt.Sprintf("ParticipantInfo Does not exist, please check participantPhyId: %d", in.ParticipantId),
  55. }, nil
  56. }
  57. participantAvailInfo := &model.ScParticipantAvailInfo{}
  58. tool.Convert(in, participantAvailInfo)
  59. if in.Id == 0 {
  60. participantAvailInfo.Id = tool.GenSnowflakeID()
  61. }
  62. participantAvailInfo.CreatedTime = time.Now()
  63. //保存participant动态信息
  64. result := db.Save(&participantAvailInfo)
  65. //保存节点信息
  66. nodeList := make([]*model.ScNodeAvailInfo, 0)
  67. for _, info := range in.NodeAvailInfo {
  68. nodeInfo := &model.ScNodeAvailInfo{}
  69. tool.Convert(info, nodeInfo)
  70. nodeInfo.CreatedTime = time.Now()
  71. nodeInfo.ParticipantAvailId = participantAvailInfo.Id
  72. if nodeInfo.Id == 0 {
  73. nodeInfo.Id = tool.GenSnowflakeID()
  74. }
  75. nodeList = append(nodeList, nodeInfo)
  76. }
  77. result = db.Save(&nodeList)
  78. if result.Error != nil {
  79. logx.Errorf("orm err:", result.Error)
  80. return &pcmCore.ParticipantResp{
  81. Code: 500,
  82. Msg: fmt.Sprintf("Save participantAvailInfo error %s", result.Error),
  83. }, nil
  84. }
  85. return &pcmCore.ParticipantResp{
  86. Code: 200,
  87. Msg: "ok",
  88. }, nil
  89. }

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.