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.

load.go 2.0 kB

7 months ago
7 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package cmdline
  2. /*
  3. import (
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "github.com/spf13/cobra"
  9. clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
  10. )
  11. func init() {
  12. var useID bool
  13. cmd := cobra.Command{
  14. Use: "load",
  15. Short: "Load data from CDS to a storage service",
  16. Args: cobra.ExactArgs(3),
  17. Run: func(cmd *cobra.Command, args []string) {
  18. cmdCtx := GetCmdCtx(cmd)
  19. if useID {
  20. pkgID, err := strconv.ParseInt(args[0], 10, 64)
  21. if err != nil {
  22. fmt.Printf("Invalid package ID: %s\n", args[0])
  23. }
  24. userSpaceID, err := strconv.ParseInt(args[1], 10, 64)
  25. if err != nil {
  26. fmt.Printf("Invalid user space ID: %s\n", args[1])
  27. }
  28. loadByID(cmdCtx, clitypes.PackageID(pkgID), clitypes.UserSpaceID(userSpaceID), args[2])
  29. } else {
  30. loadByPath(cmdCtx, args[0], args[1], args[2])
  31. }
  32. },
  33. }
  34. cmd.Flags().BoolVarP(&useID, "id", "i", false, "Use ID for both package and storage service instead of their name or path")
  35. RootCmd.AddCommand(&cmd)
  36. }
  37. func loadByPath(cmdCtx *CommandContext, pkgPath string, stgName string, rootPath string) {
  38. comps := strings.Split(strings.Trim(pkgPath, clitypes.ObjectPathSeparator), clitypes.ObjectPathSeparator)
  39. if len(comps) != 2 {
  40. fmt.Printf("Package path must be in format of <bucket>/<package>")
  41. return
  42. }
  43. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().GetByFullName(comps[0], comps[1])
  44. if err != nil {
  45. fmt.Println(err)
  46. return
  47. }
  48. // stg, err := cmdCtx.Cmdline.Svc.StorageSvc().GetByName(stgName)
  49. if err != nil {
  50. fmt.Println(err)
  51. return
  52. }
  53. loadByID(cmdCtx, pkg.PackageID, stg.StorageID, rootPath)
  54. }
  55. func loadByID(cmdCtx *CommandContext, pkgID clitypes.PackageID, stgID clitypes.StorageID, rootPath string) {
  56. startTime := time.Now()
  57. err := cmdCtx.Cmdline.Svc.StorageSvc().LoadPackage(pkgID, stgID, rootPath)
  58. if err != nil {
  59. fmt.Println(err)
  60. return
  61. }
  62. fmt.Printf("Package loaded to: %v:%v in %v\n", stgID, rootPath, time.Since(startTime))
  63. }
  64. */

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