weed shell: simplify CLI option for filer

This commit is contained in:
Chris Lu 2020-04-08 23:57:15 -07:00
parent 2329d9e0c1
commit f6a7e79dc3
4 changed files with 31 additions and 12 deletions

View file

@ -364,7 +364,8 @@ scripts = """
sleep_minutes = 17 # sleep minutes between each script execution sleep_minutes = 17 # sleep minutes between each script execution
[master.filer] [master.filer]
default_filer_url = "http://localhost:8888/" default = "localhost:8888" # used by maintenance scripts if the scripts needs to use fs related commands
[master.sequencer] [master.sequencer]
type = "memory" # Choose [memory|etcd] type for storing the file id sequence type = "memory" # Choose [memory|etcd] type for storing the file id sequence

View file

@ -9,14 +9,14 @@ import (
) )
var ( var (
shellOptions shell.ShellOptions shellOptions shell.ShellOptions
shellInitialFilerUrl *string shellInitialFiler *string
) )
func init() { func init() {
cmdShell.Run = runShell // break init cycle cmdShell.Run = runShell // break init cycle
shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers") shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url") shellInitialFiler = cmdShell.Flag.String("filer", "localhost:8888", "filer host and port")
} }
var cmdShell = &Command{ var cmdShell = &Command{
@ -32,12 +32,13 @@ func runShell(command *Command, args []string) bool {
util.LoadConfiguration("security", false) util.LoadConfiguration("security", false)
shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client") shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
var filerPwdErr error var err error
shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, filerPwdErr = util.ParseFilerUrl(*shellInitialFilerUrl) shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(*shellInitialFiler)
if filerPwdErr != nil { if err != nil {
fmt.Printf("failed to parse url filer.url=%s : %v\n", *shellInitialFilerUrl, filerPwdErr) fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
return false return false
} }
shellOptions.Directory = "/"
shell.RunShell(shellOptions) shell.RunShell(shellOptions)

View file

@ -197,8 +197,8 @@ func (ms *MasterServer) startAdminScripts() {
v.SetDefault("master.maintenance.sleep_minutes", 17) v.SetDefault("master.maintenance.sleep_minutes", 17)
sleepMinutes := v.GetInt("master.maintenance.sleep_minutes") sleepMinutes := v.GetInt("master.maintenance.sleep_minutes")
v.SetDefault("master.filer.default_filer_url", "http://localhost:8888/") v.SetDefault("master.filer.default", "localhost:8888")
filerURL := v.GetString("master.filer.default_filer_url") filerHostPort := v.GetString("master.filer.default")
scriptLines := strings.Split(adminScripts, "\n") scriptLines := strings.Split(adminScripts, "\n")
@ -208,9 +208,10 @@ func (ms *MasterServer) startAdminScripts() {
shellOptions.GrpcDialOption = security.LoadClientTLS(v, "grpc.master") shellOptions.GrpcDialOption = security.LoadClientTLS(v, "grpc.master")
shellOptions.Masters = &masterAddress shellOptions.Masters = &masterAddress
shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, err = util.ParseFilerUrl(filerURL) shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(filerHostPort)
shellOptions.Directory = "/"
if err != nil { if err != nil {
glog.V(0).Infof("failed to parse master.filer.default_filer_urll=%s : %v\n", filerURL, err) glog.V(0).Infof("failed to parse master.filer.default = %s : %v\n", filerHostPort, err)
return return
} }

View file

@ -1,6 +1,7 @@
package util package util
import ( import (
"fmt"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -45,3 +46,18 @@ func ParseFilerUrl(entryPath string) (filerServer string, filerPort int64, path
path = u.Path path = u.Path
return return
} }
func ParseHostPort(hostPort string) (filerServer string, filerPort int64, err error) {
parts := strings.Split(hostPort, ":")
if len(parts) != 2 {
err = fmt.Errorf("failed to parse %s\n", hostPort)
return
}
filerPort, err = strconv.ParseInt(parts[1], 10, 64)
if err == nil {
filerServer = parts[0]
}
return
}