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.

commandSever.go 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package main
  2. import (
  3. //"context"
  4. "fmt"
  5. "path/filepath"
  6. //"sync"
  7. "encoding/json"
  8. "os"
  9. "rabbitmq"
  10. "strconv"
  11. //agentcaller "proto"
  12. //"github.com/pborman/uuid"
  13. //"github.com/streadway/amqp"
  14. //"google.golang.org/grpc"
  15. )
  16. func rabbitSend(c []byte, userId int) {
  17. queueName := "agentClientQueue" + strconv.Itoa(userId)
  18. rabbit := rabbitmq.NewRabbitMQSimple(queueName)
  19. fmt.Println(string(c))
  20. rabbit.PublishSimple(c)
  21. rabbit.Destroy()
  22. }
  23. func RepMove(command rabbitmq.RepMoveCommand) {
  24. fmt.Println("RepMove")
  25. fmt.Println(command.Hashs)
  26. hashs := command.Hashs
  27. //执行调度操作
  28. ipfsDir := "assets"
  29. goalDir := "assets2"
  30. goalName := command.BucketName + ":" + command.ObjectName + ":" + strconv.Itoa(command.UserId)
  31. //目标文件
  32. fDir, err := os.Executable()
  33. if err != nil {
  34. panic(err)
  35. }
  36. fURL := filepath.Join(filepath.Dir(fDir), goalDir)
  37. _, err = os.Stat(fURL)
  38. if os.IsNotExist(err) {
  39. os.MkdirAll(fURL, os.ModePerm)
  40. }
  41. fURL = filepath.Join(fURL, goalName)
  42. outFile, err := os.Create(fURL)
  43. fmt.Println(fURL)
  44. //源文件
  45. fURL = filepath.Join(filepath.Dir(fDir), ipfsDir)
  46. fURL = filepath.Join(fURL, hashs[0])
  47. inFile, _ := os.Open(fURL)
  48. fmt.Println(fURL)
  49. fileInfo, _ := inFile.Stat()
  50. fileSizeInBytes := fileInfo.Size()
  51. numWholePacket := fileSizeInBytes / packetSizeInBytes
  52. lastPacketInBytes := fileSizeInBytes % packetSizeInBytes
  53. fmt.Println(fileSizeInBytes)
  54. fmt.Println(numWholePacket)
  55. fmt.Println(lastPacketInBytes)
  56. for i := 0; int64(i) < numWholePacket; i++ {
  57. buf := make([]byte, packetSizeInBytes)
  58. inFile.Read(buf)
  59. outFile.Write(buf)
  60. }
  61. if lastPacketInBytes > 0 {
  62. buf := make([]byte, lastPacketInBytes)
  63. inFile.Read(buf)
  64. outFile.Write(buf)
  65. }
  66. inFile.Close()
  67. outFile.Close()
  68. //返回消息
  69. res := rabbitmq.AgentMoveRes{
  70. MoveCode: 0,
  71. }
  72. c, _ := json.Marshal(res)
  73. rabbitSend(c, command.UserId)
  74. //向coor报告临时缓存hash
  75. command1 := rabbitmq.TempCacheReport{
  76. Ip: LocalIp,
  77. Hashs: hashs,
  78. }
  79. c, _ = json.Marshal(command1)
  80. b := append([]byte("06"), c...)
  81. fmt.Println(b)
  82. rabbit := rabbitmq.NewRabbitMQSimple("coorQueue")
  83. rabbit.PublishSimple(b)
  84. rabbit.Destroy()
  85. }
  86. func EcMove(command rabbitmq.EcMoveCommand) {
  87. fmt.Println("EcMove")
  88. fmt.Println(command.Hashs)
  89. hashs := command.Hashs
  90. //执行调度操作
  91. //返回消息
  92. res := rabbitmq.WriteHashRes{
  93. MetaCode: 0,
  94. }
  95. c, _ := json.Marshal(res)
  96. rabbitSend(c, command.UserId)
  97. //向coor报告临时缓存hash
  98. command1 := rabbitmq.TempCacheReport{
  99. Ip: LocalIp,
  100. Hashs: hashs,
  101. }
  102. c, _ = json.Marshal(command1)
  103. b := append([]byte("06"), c...)
  104. fmt.Println(b)
  105. rabbit := rabbitmq.NewRabbitMQSimple("coorQueue")
  106. rabbit.PublishSimple(b)
  107. rabbit.Destroy()
  108. }

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

Contributors (1)