diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go index 13c66543b..6f7cf1ad6 100644 --- a/weed/server/filer_grpc_server.go +++ b/weed/server/filer_grpc_server.go @@ -238,7 +238,12 @@ func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVol func (fs *FilerServer) DeleteCollection(ctx context.Context, req *filer_pb.DeleteCollectionRequest) (resp *filer_pb.DeleteCollectionResponse, err error) { - err = fs.filer.MasterClient.CollectionDelete(ctx, req.GetCollection()) + err = fs.filer.MasterClient.WithClient(ctx, func(ctx context.Context, client master_pb.SeaweedClient) error { + _, err := client.CollectionDelete(ctx, &master_pb.CollectionDeleteRequest{ + Name: req.GetCollection(), + }) + return err + }) return &filer_pb.DeleteCollectionResponse{}, err } diff --git a/weed/shell/command_collection_list.go b/weed/shell/command_collection_list.go index 34a406d67..0797e56fb 100644 --- a/weed/shell/command_collection_list.go +++ b/weed/shell/command_collection_list.go @@ -3,6 +3,7 @@ package shell import ( "context" "fmt" + "github.com/chrislusf/seaweedfs/weed/pb/master_pb" "io" ) @@ -21,9 +22,14 @@ func (c *commandCollectionList) Help() string { return "# list all collections" } -func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error { +func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { - resp, err := commandEnv.masterClient.CollectionList(context.Background()) + var resp *master_pb.CollectionListResponse + + err = commandEnv.masterClient.WithClient(context.Background(), func(ctx context.Context, client master_pb.SeaweedClient) error { + resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{}) + return err + }) if err != nil { return err diff --git a/weed/shell/command_volume_list.go b/weed/shell/command_volume_list.go index 971e18f10..52ac4865a 100644 --- a/weed/shell/command_volume_list.go +++ b/weed/shell/command_volume_list.go @@ -22,16 +22,18 @@ func (c *commandVolumeList) Help() string { return "# list all volumes" } -func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error { - - resp, err := commandEnv.masterClient.VolumeList(context.Background()) +func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { + var resp *master_pb.VolumeListResponse + err = commandEnv.masterClient.WithClient(context.Background(), func(ctx context.Context, client master_pb.SeaweedClient) error { + resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) + return err + }) if err != nil { return err } writeTopologyInfo(writer, resp.TopologyInfo) - return nil } diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index b3b277c74..5f147e594 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -116,3 +116,9 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di return fn(ctx, client) } + +func (mc *MasterClient) WithClient(ctx context.Context, fn func(ctx context.Context, client master_pb.SeaweedClient) error) error { + return withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error { + return fn(ctx, client) + }) +} diff --git a/weed/wdclient/masterclient_collection.go b/weed/wdclient/masterclient_collection.go deleted file mode 100644 index 1a9215a7e..000000000 --- a/weed/wdclient/masterclient_collection.go +++ /dev/null @@ -1,31 +0,0 @@ -package wdclient - -import ( - "context" - "github.com/chrislusf/seaweedfs/weed/pb/master_pb" -) - -func (mc *MasterClient) CollectionDelete(ctx context.Context, collection string) error { - return withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error { - _, err := client.CollectionDelete(ctx, &master_pb.CollectionDeleteRequest{ - Name: collection, - }) - return err - }) -} - -func (mc *MasterClient) CollectionList(ctx context.Context) (resp *master_pb.CollectionListResponse, err error) { - err = withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error { - resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{}) - return err - }) - return -} - -func (mc *MasterClient) VolumeList(ctx context.Context) (resp *master_pb.VolumeListResponse, err error) { - err = withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error { - resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) - return err - }) - return -}