2019-04-16 16:58:28 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/notification"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2019-06-05 16:30:24 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2019-04-16 16:58:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandFsMetaNotify{})
|
2019-04-16 16:58:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandFsMetaNotify struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsMetaNotify) Name() string {
|
|
|
|
return "fs.meta.notify"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsMetaNotify) Help() string {
|
|
|
|
return `recursively send directory and file meta data to notifiction message queue
|
|
|
|
|
|
|
|
fs.meta.notify # send meta data from current directory to notification message queue
|
|
|
|
|
|
|
|
The message queue will use it to trigger replication from this filer.
|
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandFsMetaNotify) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2020-03-24 12:26:15 +08:00
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
2019-04-16 16:58:28 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
util.LoadConfiguration("notification", true)
|
2020-01-30 01:09:55 +08:00
|
|
|
v := util.GetViper()
|
|
|
|
notification.LoadConfiguration(v, "notification.")
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
var dirCount, fileCount uint64
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2020-04-22 12:28:47 +08:00
|
|
|
err = filer_pb.TraverseBfs(commandEnv, util.FullPath(path), func(parentPath util.FullPath, entry *filer_pb.Entry) {
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
if entry.IsDirectory {
|
|
|
|
dirCount++
|
|
|
|
} else {
|
|
|
|
fileCount++
|
|
|
|
}
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
notifyErr := notification.Queue.SendMessage(
|
|
|
|
string(parentPath.Child(entry.Name)),
|
|
|
|
&filer_pb.EventNotification{
|
|
|
|
NewEntry: entry,
|
|
|
|
},
|
|
|
|
)
|
2019-04-16 16:58:28 +08:00
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
if notifyErr != nil {
|
|
|
|
fmt.Fprintf(writer, "fail to notify new entry event for %s: %v\n", parentPath.Child(entry.Name), notifyErr)
|
2019-04-16 16:58:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
if err == nil {
|
|
|
|
fmt.Fprintf(writer, "\ntotal notified %d directories, %d files\n", dirCount, fileCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
2019-04-16 16:58:28 +08:00
|
|
|
}
|