You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/chrislusf/seaweedfs/weed/filer2"
  7. "github.com/chrislusf/seaweedfs/weed/notification"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/util"
  10. "github.com/spf13/viper"
  11. )
  12. func init() {
  13. Commands = append(Commands, &commandFsMetaNotify{})
  14. }
  15. type commandFsMetaNotify struct {
  16. }
  17. func (c *commandFsMetaNotify) Name() string {
  18. return "fs.meta.notify"
  19. }
  20. func (c *commandFsMetaNotify) Help() string {
  21. return `recursively send directory and file meta data to notifiction message queue
  22. fs.meta.notify # send meta data from current directory to notification message queue
  23. The message queue will use it to trigger replication from this filer.
  24. `
  25. }
  26. func (c *commandFsMetaNotify) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args))
  28. if err != nil {
  29. return err
  30. }
  31. util.LoadConfiguration("notification", true)
  32. v := viper.GetViper()
  33. notification.LoadConfiguration(v.Sub("notification"))
  34. ctx := context.Background()
  35. return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
  36. var dirCount, fileCount uint64
  37. err = doTraverse(ctx, writer, client, filer2.FullPath(path), func(parentPath filer2.FullPath, entry *filer_pb.Entry) error {
  38. if entry.IsDirectory {
  39. dirCount++
  40. } else {
  41. fileCount++
  42. }
  43. return notification.Queue.SendMessage(
  44. string(parentPath.Child(entry.Name)),
  45. &filer_pb.EventNotification{
  46. NewEntry: entry,
  47. },
  48. )
  49. })
  50. if err == nil {
  51. fmt.Fprintf(writer, "\ntotal notified %d directories, %d files\n", dirCount, fileCount)
  52. }
  53. return err
  54. })
  55. }