diff options
| author | henry <zhanggm@sugon.com> | 2021-01-04 14:50:01 +0800 |
|---|---|---|
| committer | henry <zhanggm@sugon.com> | 2021-01-04 14:50:01 +0800 |
| commit | 97a94eddab407219faf6b5a5f809057cde331eaa (patch) | |
| tree | f0f2111f812daa43dca31218bfa62f3f53ee7bd4 /weed/command/upload.go | |
| parent | 14ddd155082a455542a992220d6c61e658420c6b (diff) | |
| parent | 2ce86f308ea4836cf534e50dc1388932253b5cd5 (diff) | |
| download | seaweedfs-97a94eddab407219faf6b5a5f809057cde331eaa.tar.xz seaweedfs-97a94eddab407219faf6b5a5f809057cde331eaa.zip | |
Merge branch 'master' of https://github.com/fuyouyshengwu/seaweedfs
Diffstat (limited to 'weed/command/upload.go')
| -rw-r--r-- | weed/command/upload.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/weed/command/upload.go b/weed/command/upload.go index 45b15535b..7115da587 100644 --- a/weed/command/upload.go +++ b/weed/command/upload.go @@ -1,8 +1,12 @@ package command import ( + "context" "encoding/json" "fmt" + "github.com/chrislusf/seaweedfs/weed/pb" + "github.com/chrislusf/seaweedfs/weed/pb/master_pb" + "google.golang.org/grpc" "os" "path/filepath" @@ -65,6 +69,15 @@ func runUpload(cmd *Command, args []string) bool { util.LoadConfiguration("security", false) grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client") + defaultCollection, err := readMasterConfiguration(grpcDialOption, *upload.master) + if err != nil { + fmt.Printf("upload: %v", err) + return false + } + if *upload.replication == "" { + *upload.replication = defaultCollection + } + if len(args) == 0 { if *upload.dir == "" { return false @@ -104,3 +117,15 @@ func runUpload(cmd *Command, args []string) bool { } return true } + +func readMasterConfiguration(grpcDialOption grpc.DialOption, masterAddress string) (replication string, err error) { + err = pb.WithMasterClient(masterAddress, grpcDialOption, func(client master_pb.SeaweedClient) error { + resp, err := client.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{}) + if err != nil { + return fmt.Errorf("get master %s configuration: %v", masterAddress, err) + } + replication = resp.DefaultReplication + return nil + }) + return +} |
