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.

io.go 2.0 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package mq
  2. import (
  3. "time"
  4. "gitlink.org.cn/cloudream/common/consts/errorcode"
  5. "gitlink.org.cn/cloudream/common/pkgs/logger"
  6. "gitlink.org.cn/cloudream/common/pkgs/mq"
  7. mytask "gitlink.org.cn/cloudream/storage/agent/internal/task"
  8. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  9. agtmq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/agent"
  10. )
  11. func (svc *Service) SetupIOPlan(msg *agtmq.SetupIOPlan) (*agtmq.SetupIOPlanResp, *mq.CodeMessage) {
  12. err := svc.sw.SetupPlan(msg.Plan)
  13. if err != nil {
  14. logger.WithField("PlanID", msg.Plan.ID).Warnf("adding plan: %s", err.Error())
  15. return nil, mq.Failed(errorcode.OperationFailed, "adding plan failed")
  16. }
  17. return mq.ReplyOK(agtmq.NewSetupIOPlanResp())
  18. }
  19. func (svc *Service) StartIOPlan(msg *agtmq.StartIOPlan) (*agtmq.StartIOPlanResp, *mq.CodeMessage) {
  20. tsk := svc.taskManager.StartNew(mytask.NewExecuteIOPlan(msg.PlanID))
  21. return mq.ReplyOK(agtmq.NewStartIOPlanResp(tsk.ID()))
  22. }
  23. func (svc *Service) WaitIOPlan(msg *agtmq.WaitIOPlan) (*agtmq.WaitIOPlanResp, *mq.CodeMessage) {
  24. tsk := svc.taskManager.FindByID(msg.TaskID)
  25. if tsk == nil {
  26. return nil, mq.Failed(errorcode.TaskNotFound, "task not found")
  27. }
  28. if msg.WaitTimeoutMs == 0 {
  29. tsk.Wait()
  30. errMsg := ""
  31. if tsk.Error() != nil {
  32. errMsg = tsk.Error().Error()
  33. }
  34. planTsk := tsk.Body().(*mytask.ExecuteIOPlan)
  35. return mq.ReplyOK(agtmq.NewWaitIOPlanResp(true, errMsg, planTsk.Result))
  36. } else {
  37. if tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs) * time.Millisecond) {
  38. errMsg := ""
  39. if tsk.Error() != nil {
  40. errMsg = tsk.Error().Error()
  41. }
  42. planTsk := tsk.Body().(*mytask.ExecuteIOPlan)
  43. return mq.ReplyOK(agtmq.NewWaitIOPlanResp(true, errMsg, planTsk.Result))
  44. }
  45. return mq.ReplyOK(agtmq.NewWaitIOPlanResp(false, "", ioswitch.PlanResult{}))
  46. }
  47. }
  48. func (svc *Service) CancelIOPlan(msg *agtmq.CancelIOPlan) (*agtmq.CancelIOPlanResp, *mq.CodeMessage) {
  49. svc.sw.CancelPlan(msg.PlanID)
  50. return mq.ReplyOK(agtmq.NewCancelIOPlanResp())
  51. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。