refactoring

This commit is contained in:
Chris Lu 2019-03-19 05:19:37 -07:00
parent ece9d13312
commit eb4a54d9fe
5 changed files with 26 additions and 38 deletions

View File

@ -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) { 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 return &filer_pb.DeleteCollectionResponse{}, err
} }

View File

@ -3,6 +3,7 @@ package shell
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"io" "io"
) )
@ -21,9 +22,14 @@ func (c *commandCollectionList) Help() string {
return "# list all collections" 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 { if err != nil {
return err return err

View File

@ -22,16 +22,18 @@ func (c *commandVolumeList) Help() string {
return "# list all volumes" return "# list all volumes"
} }
func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error { func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
resp, err := commandEnv.masterClient.VolumeList(context.Background())
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 { if err != nil {
return err return err
} }
writeTopologyInfo(writer, resp.TopologyInfo) writeTopologyInfo(writer, resp.TopologyInfo)
return nil return nil
} }

View File

@ -116,3 +116,9 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di
return fn(ctx, client) 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)
})
}

View File

@ -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
}