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.

storage.go 2.8 kB

2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package mq
  2. import (
  3. "time"
  4. "gitlink.org.cn/cloudream/common/consts/errorcode"
  5. "gitlink.org.cn/cloudream/common/pkgs/mq"
  6. mytask "gitlink.org.cn/cloudream/storage/agent/internal/task"
  7. agtmq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/agent"
  8. )
  9. func (svc *Service) StartStorageCreatePackage(msg *agtmq.StartStorageCreatePackage) (*agtmq.StartStorageCreatePackageResp, *mq.CodeMessage) {
  10. return nil, mq.Failed(errorcode.OperationFailed, "not implemented")
  11. // coorCli, err := stgglb.CoordinatorMQPool.Acquire()
  12. // if err != nil {
  13. // logger.Warnf("new coordinator client: %s", err.Error())
  14. // return nil, mq.Failed(errorcode.OperationFailed, "new coordinator client failed")
  15. // }
  16. // defer stgglb.CoordinatorMQPool.Release(coorCli)
  17. // getStg, err := coorCli.GetStorageDetails(coormq.ReqGetStorageDetails([]cdssdk.StorageID{msg.StorageID}))
  18. // if err != nil {
  19. // return nil, mq.Failed(errorcode.OperationFailed, err.Error())
  20. // }
  21. // if getStg.Storages[0] == nil {
  22. // return nil, mq.Failed(errorcode.OperationFailed, "storage not found")
  23. // }
  24. // if getStg.Storages[0].Shared == nil {
  25. // return nil, mq.Failed(errorcode.OperationFailed, "storage has no shared storage")
  26. // }
  27. // fullPath := filepath.Clean(filepath.Join(getStg.Storages[0].Shared.LoadBase, msg.Path))
  28. // var uploadFilePathes []string
  29. // err = filepath.WalkDir(fullPath, func(fname string, fi os.DirEntry, err error) error {
  30. // if err != nil {
  31. // return nil
  32. // }
  33. // if !fi.IsDir() {
  34. // uploadFilePathes = append(uploadFilePathes, fname)
  35. // }
  36. // return nil
  37. // })
  38. // if err != nil {
  39. // logger.Warnf("opening directory %s: %s", fullPath, err.Error())
  40. // return nil, mq.Failed(errorcode.OperationFailed, "read directory failed")
  41. // }
  42. // objIter := iterator.NewUploadingObjectIterator(fullPath, uploadFilePathes)
  43. // tsk := svc.taskManager.StartNew(mytask.NewCreatePackage(msg.UserID, msg.BucketID, msg.Name, objIter, msg.StorageAffinity))
  44. // return mq.ReplyOK(agtmq.NewStartStorageCreatePackageResp(tsk.ID()))
  45. }
  46. func (svc *Service) WaitStorageCreatePackage(msg *agtmq.WaitStorageCreatePackage) (*agtmq.WaitStorageCreatePackageResp, *mq.CodeMessage) {
  47. tsk := svc.taskManager.FindByID(msg.TaskID)
  48. if tsk == nil {
  49. return nil, mq.Failed(errorcode.TaskNotFound, "task not found")
  50. }
  51. if msg.WaitTimeoutMs == 0 {
  52. tsk.Wait()
  53. } else if !tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs) * time.Millisecond) {
  54. return mq.ReplyOK(agtmq.NewWaitStorageCreatePackageResp(false, "", 0))
  55. }
  56. if tsk.Error() != nil {
  57. return mq.ReplyOK(agtmq.NewWaitStorageCreatePackageResp(true, tsk.Error().Error(), 0))
  58. }
  59. taskBody := tsk.Body().(*mytask.CreatePackage)
  60. return mq.ReplyOK(agtmq.NewWaitStorageCreatePackageResp(true, "", taskBody.Result.PackageID))
  61. }

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