mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
ece9d13312
commit
eb4a54d9fe
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue