Browse Source

refactoring

pull/893/head
Chris Lu 6 years ago
parent
commit
eb4a54d9fe
  1. 7
      weed/server/filer_grpc_server.go
  2. 10
      weed/shell/command_collection_list.go
  3. 10
      weed/shell/command_volume_list.go
  4. 6
      weed/wdclient/masterclient.go
  5. 31
      weed/wdclient/masterclient_collection.go

7
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) { 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
} }

10
weed/shell/command_collection_list.go

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

10
weed/shell/command_volume_list.go

@ -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 {
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 { if err != nil {
return err return err
} }
writeTopologyInfo(writer, resp.TopologyInfo) writeTopologyInfo(writer, resp.TopologyInfo)
return nil return nil
} }

6
weed/wdclient/masterclient.go

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

31
weed/wdclient/masterclient_collection.go

@ -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
}
Loading…
Cancel
Save