diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-06-05 01:30:24 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-06-05 01:30:24 -0700 |
| commit | ede876cfdb0116557dd197a7951957dab6745c24 (patch) | |
| tree | 50bab90cbf757bb0ad6b3239ed938dfd8d55874e /weed/shell | |
| parent | b9e138713c8e2f53cf96132b5ff077ded67c5c20 (diff) | |
| download | seaweedfs-ede876cfdb0116557dd197a7951957dab6745c24.tar.xz seaweedfs-ede876cfdb0116557dd197a7951957dab6745c24.zip | |
periodic scripts exeuction from leader master
Diffstat (limited to 'weed/shell')
25 files changed, 109 insertions, 105 deletions
diff --git a/weed/shell/command_collection_delete.go b/weed/shell/command_collection_delete.go index e3356aba4..fbaddcd51 100644 --- a/weed/shell/command_collection_delete.go +++ b/weed/shell/command_collection_delete.go @@ -8,7 +8,7 @@ import ( ) func init() { - commands = append(commands, &commandCollectionDelete{}) + Commands = append(Commands, &commandCollectionDelete{}) } type commandCollectionDelete struct { @@ -26,7 +26,7 @@ func (c *commandCollectionDelete) Help() string { ` } -func (c *commandCollectionDelete) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) == 0 { return nil @@ -35,7 +35,7 @@ func (c *commandCollectionDelete) Do(args []string, commandEnv *commandEnv, writ collectionName := args[0] ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { _, err = client.CollectionDelete(ctx, &master_pb.CollectionDeleteRequest{ Name: collectionName, }) diff --git a/weed/shell/command_collection_list.go b/weed/shell/command_collection_list.go index d1124adde..c4325c66f 100644 --- a/weed/shell/command_collection_list.go +++ b/weed/shell/command_collection_list.go @@ -8,7 +8,7 @@ import ( ) func init() { - commands = append(commands, &commandCollectionList{}) + Commands = append(Commands, &commandCollectionList{}) } type commandCollectionList struct { @@ -22,7 +22,7 @@ func (c *commandCollectionList) Help() string { return `list all collections` } -func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandCollectionList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { collections, err := ListCollectionNames(commandEnv, true, true) @@ -39,10 +39,10 @@ func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer return nil } -func ListCollectionNames(commandEnv *commandEnv, includeNormalVolumes, includeEcVolumes bool) (collections []string, err error) { +func ListCollectionNames(commandEnv *CommandEnv, includeNormalVolumes, includeEcVolumes bool) (collections []string, err error) { var resp *master_pb.CollectionListResponse ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{ IncludeNormalVolumes: includeNormalVolumes, IncludeEcVolumes: includeEcVolumes, diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.go index 6d44a184b..424b63d9d 100644 --- a/weed/shell/command_ec_balance.go +++ b/weed/shell/command_ec_balance.go @@ -13,7 +13,7 @@ import ( ) func init() { - commands = append(commands, &commandEcBalance{}) + Commands = append(Commands, &commandEcBalance{}) } type commandEcBalance struct { @@ -53,7 +53,7 @@ func (c *commandEcBalance) Help() string { ` } -func (c *commandEcBalance) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection") @@ -65,7 +65,7 @@ func (c *commandEcBalance) Do(args []string, commandEnv *commandEnv, writer io.W var resp *master_pb.VolumeListResponse ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) @@ -104,7 +104,7 @@ func (c *commandEcBalance) Do(args []string, commandEnv *commandEnv, writer io.W return nil } -func balanceEcVolumes(commandEnv *commandEnv, collection string, applyBalancing bool) error { +func balanceEcVolumes(commandEnv *CommandEnv, collection string, applyBalancing bool) error { ctx := context.Background() @@ -142,7 +142,7 @@ func balanceEcVolumes(commandEnv *commandEnv, collection string, applyBalancing return nil } -func doBalanceEcShards(ctx context.Context, commandEnv *commandEnv, collection string, vid needle.VolumeId, locations []*EcNode, allEcNodes []*EcNode, applyBalancing bool) error { +func doBalanceEcShards(ctx context.Context, commandEnv *CommandEnv, collection string, vid needle.VolumeId, locations []*EcNode, allEcNodes []*EcNode, applyBalancing bool) error { // collect all ec nodes with at least one free slot var possibleDestinationEcNodes []*EcNode for _, ecNode := range allEcNodes { @@ -171,7 +171,7 @@ func doBalanceEcShards(ctx context.Context, commandEnv *commandEnv, collection s return nil } -func doDeduplicateEcShards(ctx context.Context, commandEnv *commandEnv, collection string, vid needle.VolumeId, locations []*EcNode, applyBalancing bool) error { +func doDeduplicateEcShards(ctx context.Context, commandEnv *CommandEnv, collection string, vid needle.VolumeId, locations []*EcNode, applyBalancing bool) error { // check whether this volume has ecNodes that are over average shardToLocations := make([][]*EcNode, erasure_coding.TotalShardsCount) @@ -205,7 +205,7 @@ func doDeduplicateEcShards(ctx context.Context, commandEnv *commandEnv, collecti return nil } -func spreadShardsIntoMoreDataNodes(ctx context.Context, commandEnv *commandEnv, averageShardsPerEcNode int, collection string, vid needle.VolumeId, existingLocations, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error { +func spreadShardsIntoMoreDataNodes(ctx context.Context, commandEnv *CommandEnv, averageShardsPerEcNode int, collection string, vid needle.VolumeId, existingLocations, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error { for _, ecNode := range existingLocations { @@ -232,7 +232,7 @@ func spreadShardsIntoMoreDataNodes(ctx context.Context, commandEnv *commandEnv, return nil } -func pickOneEcNodeAndMoveOneShard(ctx context.Context, commandEnv *commandEnv, averageShardsPerEcNode int, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error { +func pickOneEcNodeAndMoveOneShard(ctx context.Context, commandEnv *CommandEnv, averageShardsPerEcNode int, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error { sortEcNodes(possibleDestinationEcNodes) diff --git a/weed/shell/command_ec_common.go b/weed/shell/command_ec_common.go index b5560b560..4c53ba43b 100644 --- a/weed/shell/command_ec_common.go +++ b/weed/shell/command_ec_common.go @@ -14,7 +14,7 @@ import ( "google.golang.org/grpc" ) -func moveMountedShardToEcNode(ctx context.Context, commandEnv *commandEnv, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, destinationEcNode *EcNode, applyBalancing bool) error { +func moveMountedShardToEcNode(ctx context.Context, commandEnv *CommandEnv, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, destinationEcNode *EcNode, applyBalancing bool) error { fmt.Printf("moved ec shard %d.%d %s => %s\n", vid, shardId, existingLocation.info.Id, destinationEcNode.info.Id) @@ -124,11 +124,11 @@ type EcNode struct { freeEcSlot int } -func collectEcNodes(ctx context.Context, commandEnv *commandEnv) (ecNodes []*EcNode, totalFreeEcSlots int, err error) { +func collectEcNodes(ctx context.Context, commandEnv *CommandEnv) (ecNodes []*EcNode, totalFreeEcSlots int, err error) { // list all possible locations var resp *master_pb.VolumeListResponse - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.go index e0d4cf380..8b01f6cfc 100644 --- a/weed/shell/command_ec_encode.go +++ b/weed/shell/command_ec_encode.go @@ -18,7 +18,7 @@ import ( ) func init() { - commands = append(commands, &commandEcEncode{}) + Commands = append(Commands, &commandEcEncode{}) } type commandEcEncode struct { @@ -51,7 +51,7 @@ func (c *commandEcEncode) Help() string { ` } -func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeId := encodeCommand.Int("volumeId", 0, "the volume id") @@ -85,9 +85,9 @@ func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Wr return nil } -func doEcEncode(ctx context.Context, commandEnv *commandEnv, collection string, vid needle.VolumeId) (err error) { +func doEcEncode(ctx context.Context, commandEnv *CommandEnv, collection string, vid needle.VolumeId) (err error) { // find volume location - locations := commandEnv.masterClient.GetLocations(uint32(vid)) + locations := commandEnv.MasterClient.GetLocations(uint32(vid)) if len(locations) == 0 { return fmt.Errorf("volume %d not found", vid) } @@ -121,7 +121,7 @@ func generateEcShards(ctx context.Context, grpcDialOption grpc.DialOption, volum } -func spreadEcShards(ctx context.Context, commandEnv *commandEnv, volumeId needle.VolumeId, collection string, existingLocations []wdclient.Location) (err error) { +func spreadEcShards(ctx context.Context, commandEnv *CommandEnv, volumeId needle.VolumeId, collection string, existingLocations []wdclient.Location) (err error) { allEcNodes, totalFreeEcSlots, err := collectEcNodes(ctx, commandEnv) if err != nil { @@ -228,10 +228,10 @@ func balancedEcDistribution(servers []*EcNode) (allocated []int) { return allocated } -func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *commandEnv, selectedCollection string, fullPercentage float64, quietPeriod time.Duration) (vids []needle.VolumeId, err error) { +func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *CommandEnv, selectedCollection string, fullPercentage float64, quietPeriod time.Duration) (vids []needle.VolumeId, err error) { var resp *master_pb.VolumeListResponse - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) diff --git a/weed/shell/command_ec_rebuild.go b/weed/shell/command_ec_rebuild.go index 4b82f96c0..9a5ea3ca9 100644 --- a/weed/shell/command_ec_rebuild.go +++ b/weed/shell/command_ec_rebuild.go @@ -14,7 +14,7 @@ import ( ) func init() { - commands = append(commands, &commandEcRebuild{}) + Commands = append(Commands, &commandEcRebuild{}) } type commandEcRebuild struct { @@ -54,7 +54,7 @@ func (c *commandEcRebuild) Help() string { ` } -func (c *commandEcRebuild) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandEcRebuild) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { fixCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) collection := fixCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection") @@ -90,7 +90,7 @@ func (c *commandEcRebuild) Do(args []string, commandEnv *commandEnv, writer io.W return nil } -func rebuildEcVolumes(commandEnv *commandEnv, allEcNodes []*EcNode, collection string, writer io.Writer, applyChanges bool) error { +func rebuildEcVolumes(commandEnv *CommandEnv, allEcNodes []*EcNode, collection string, writer io.Writer, applyChanges bool) error { ctx := context.Background() @@ -125,7 +125,7 @@ func rebuildEcVolumes(commandEnv *commandEnv, allEcNodes []*EcNode, collection s return nil } -func rebuildOneEcVolume(ctx context.Context, commandEnv *commandEnv, rebuilder *EcNode, collection string, volumeId needle.VolumeId, locations EcShardLocations, writer io.Writer, applyChanges bool) error { +func rebuildOneEcVolume(ctx context.Context, commandEnv *CommandEnv, rebuilder *EcNode, collection string, volumeId needle.VolumeId, locations EcShardLocations, writer io.Writer, applyChanges bool) error { fmt.Printf("rebuildOneEcVolume %s %d\n", collection, volumeId) @@ -182,7 +182,7 @@ func generateMissingShards(ctx context.Context, grpcDialOption grpc.DialOption, return } -func prepareDataToRecover(ctx context.Context, commandEnv *commandEnv, rebuilder *EcNode, collection string, volumeId needle.VolumeId, locations EcShardLocations, writer io.Writer, applyBalancing bool) (copiedShardIds []uint32, localShardIds []uint32, err error) { +func prepareDataToRecover(ctx context.Context, commandEnv *CommandEnv, rebuilder *EcNode, collection string, volumeId needle.VolumeId, locations EcShardLocations, writer io.Writer, applyBalancing bool) (copiedShardIds []uint32, localShardIds []uint32, err error) { needEcxFile := true var localShardBits erasure_coding.ShardBits diff --git a/weed/shell/command_fs_cat.go b/weed/shell/command_fs_cat.go index a6c308d2a..66ced46c5 100644 --- a/weed/shell/command_fs_cat.go +++ b/weed/shell/command_fs_cat.go @@ -8,11 +8,10 @@ import ( "github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" - weed_server "github.com/chrislusf/seaweedfs/weed/server" ) func init() { - commands = append(commands, &commandFsCat{}) + Commands = append(Commands, &commandFsCat{}) } type commandFsCat struct { @@ -34,7 +33,7 @@ func (c *commandFsCat) Help() string { ` } -func (c *commandFsCat) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { input := findInputDirectory(args) @@ -62,7 +61,7 @@ func (c *commandFsCat) Do(args []string, commandEnv *commandEnv, writer io.Write return err } - return weed_server.StreamContent(commandEnv.masterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32) + return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32) }) diff --git a/weed/shell/command_fs_cd.go b/weed/shell/command_fs_cd.go index f14350f02..408ec86c8 100644 --- a/weed/shell/command_fs_cd.go +++ b/weed/shell/command_fs_cd.go @@ -6,7 +6,7 @@ import ( ) func init() { - commands = append(commands, &commandFsCd{}) + Commands = append(Commands, &commandFsCd{}) } type commandFsCd struct { @@ -29,7 +29,7 @@ func (c *commandFsCd) Help() string { ` } -func (c *commandFsCd) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsCd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { input := findInputDirectory(args) diff --git a/weed/shell/command_fs_du.go b/weed/shell/command_fs_du.go index f305cabdc..5e634c82a 100644 --- a/weed/shell/command_fs_du.go +++ b/weed/shell/command_fs_du.go @@ -11,7 +11,7 @@ import ( ) func init() { - commands = append(commands, &commandFsDu{}) + Commands = append(Commands, &commandFsDu{}) } type commandFsDu struct { @@ -30,7 +30,7 @@ func (c *commandFsDu) Help() string { ` } -func (c *commandFsDu) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsDu) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args)) if err != nil { @@ -106,7 +106,7 @@ func paginateDirectory(ctx context.Context, writer io.Writer, client filer_pb.Se } -func (env *commandEnv) withFilerClient(ctx context.Context, filerServer string, filerPort int64, fn func(filer_pb.SeaweedFilerClient) error) error { +func (env *CommandEnv) withFilerClient(ctx context.Context, filerServer string, filerPort int64, fn func(filer_pb.SeaweedFilerClient) error) error { filerGrpcAddress := fmt.Sprintf("%s:%d", filerServer, filerPort+10000) return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error { diff --git a/weed/shell/command_fs_ls.go b/weed/shell/command_fs_ls.go index 5c5130c53..6979635e1 100644 --- a/weed/shell/command_fs_ls.go +++ b/weed/shell/command_fs_ls.go @@ -13,7 +13,7 @@ import ( ) func init() { - commands = append(commands, &commandFsLs{}) + Commands = append(Commands, &commandFsLs{}) } type commandFsLs struct { @@ -35,7 +35,7 @@ func (c *commandFsLs) Help() string { ` } -func (c *commandFsLs) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsLs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { var isLongFormat, showHidden bool for _, arg := range args { diff --git a/weed/shell/command_fs_meta_load.go b/weed/shell/command_fs_meta_load.go index 2c5d19015..5ea8de9f5 100644 --- a/weed/shell/command_fs_meta_load.go +++ b/weed/shell/command_fs_meta_load.go @@ -13,7 +13,7 @@ import ( ) func init() { - commands = append(commands, &commandFsMetaLoad{}) + Commands = append(Commands, &commandFsMetaLoad{}) } type commandFsMetaLoad struct { @@ -31,7 +31,7 @@ func (c *commandFsMetaLoad) Help() string { ` } -func (c *commandFsMetaLoad) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) == 0 { fmt.Fprintf(writer, "missing a metadata file\n") diff --git a/weed/shell/command_fs_meta_notify.go b/weed/shell/command_fs_meta_notify.go index ca4d8da5b..13b272fbf 100644 --- a/weed/shell/command_fs_meta_notify.go +++ b/weed/shell/command_fs_meta_notify.go @@ -8,12 +8,12 @@ import ( "github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/notification" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" - weed_server "github.com/chrislusf/seaweedfs/weed/server" + "github.com/chrislusf/seaweedfs/weed/util" "github.com/spf13/viper" ) func init() { - commands = append(commands, &commandFsMetaNotify{}) + Commands = append(Commands, &commandFsMetaNotify{}) } type commandFsMetaNotify struct { @@ -33,14 +33,14 @@ func (c *commandFsMetaNotify) Help() string { ` } -func (c *commandFsMetaNotify) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsMetaNotify) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args)) if err != nil { return err } - weed_server.LoadConfiguration("notification", true) + util.LoadConfiguration("notification", true) v := viper.GetViper() notification.LoadConfiguration(v.Sub("notification")) diff --git a/weed/shell/command_fs_meta_save.go b/weed/shell/command_fs_meta_save.go index 47426a858..6ca395fae 100644 --- a/weed/shell/command_fs_meta_save.go +++ b/weed/shell/command_fs_meta_save.go @@ -14,7 +14,7 @@ import ( ) func init() { - commands = append(commands, &commandFsMetaSave{}) + Commands = append(Commands, &commandFsMetaSave{}) } type commandFsMetaSave struct { @@ -40,7 +40,7 @@ func (c *commandFsMetaSave) Help() string { ` } -func (c *commandFsMetaSave) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args)) if err != nil { diff --git a/weed/shell/command_fs_pwd.go b/weed/shell/command_fs_pwd.go index 0b0a7f176..084a5e90a 100644 --- a/weed/shell/command_fs_pwd.go +++ b/weed/shell/command_fs_pwd.go @@ -6,7 +6,7 @@ import ( ) func init() { - commands = append(commands, &commandFsPwd{}) + Commands = append(Commands, &commandFsPwd{}) } type commandFsPwd struct { @@ -20,7 +20,7 @@ func (c *commandFsPwd) Help() string { return `print out current directory` } -func (c *commandFsPwd) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsPwd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { fmt.Fprintf(writer, "http://%s:%d%s\n", commandEnv.option.FilerHost, diff --git a/weed/shell/command_fs_tree.go b/weed/shell/command_fs_tree.go index f1ffc9e4b..8474e43ea 100644 --- a/weed/shell/command_fs_tree.go +++ b/weed/shell/command_fs_tree.go @@ -10,7 +10,7 @@ import ( ) func init() { - commands = append(commands, &commandFsTree{}) + Commands = append(Commands, &commandFsTree{}) } type commandFsTree struct { @@ -27,7 +27,7 @@ func (c *commandFsTree) Help() string { ` } -func (c *commandFsTree) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandFsTree) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args)) if err != nil { diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 683e2dbe8..1ae031658 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -15,7 +15,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeBalance{}) + Commands = append(Commands, &commandVolumeBalance{}) } type commandVolumeBalance struct { @@ -59,7 +59,7 @@ func (c *commandVolumeBalance) Help() string { ` } -func (c *commandVolumeBalance) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or use \"ALL_COLLECTIONS\" across collections, \"EACH_COLLECTION\" for each collection") @@ -71,7 +71,7 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *commandEnv, writer var resp *master_pb.VolumeListResponse ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) @@ -108,7 +108,7 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *commandEnv, writer return nil } -func balanceVolumeServers(commandEnv *commandEnv, dataNodeInfos []*master_pb.DataNodeInfo, volumeSizeLimit uint64, collection string, applyBalancing bool) error { +func balanceVolumeServers(commandEnv *CommandEnv, dataNodeInfos []*master_pb.DataNodeInfo, volumeSizeLimit uint64, collection string, applyBalancing bool) error { var nodes []*Node for _, dn := range dataNodeInfos { nodes = append(nodes, &Node{ @@ -181,7 +181,7 @@ func sortReadOnlyVolumes(volumes []*master_pb.VolumeInformationMessage) { }) } -func balanceSelectedVolume(commandEnv *commandEnv, nodes []*Node, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) error { +func balanceSelectedVolume(commandEnv *CommandEnv, nodes []*Node, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) error { selectedVolumeCount := 0 for _, dn := range nodes { selectedVolumeCount += len(dn.selectedVolumes) @@ -223,7 +223,7 @@ func balanceSelectedVolume(commandEnv *commandEnv, nodes []*Node, sortCandidates return nil } -func moveVolume(commandEnv *commandEnv, v *master_pb.VolumeInformationMessage, fullNode *Node, emptyNode *Node, applyBalancing bool) error { +func moveVolume(commandEnv *CommandEnv, v *master_pb.VolumeInformationMessage, fullNode *Node, emptyNode *Node, applyBalancing bool) error { collectionPrefix := v.Collection + "_" if v.Collection == "" { collectionPrefix = "" diff --git a/weed/shell/command_volume_copy.go b/weed/shell/command_volume_copy.go index 8f14e25b3..1c83ba655 100644 --- a/weed/shell/command_volume_copy.go +++ b/weed/shell/command_volume_copy.go @@ -9,7 +9,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeCopy{}) + Commands = append(Commands, &commandVolumeCopy{}) } type commandVolumeCopy struct { @@ -30,7 +30,7 @@ func (c *commandVolumeCopy) Help() string { ` } -func (c *commandVolumeCopy) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) != 3 { fmt.Fprintf(writer, "received args: %+v\n", args) diff --git a/weed/shell/command_volume_delete.go b/weed/shell/command_volume_delete.go index 748c89eed..17d27ea3a 100644 --- a/weed/shell/command_volume_delete.go +++ b/weed/shell/command_volume_delete.go @@ -9,7 +9,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeDelete{}) + Commands = append(Commands, &commandVolumeDelete{}) } type commandVolumeDelete struct { @@ -29,7 +29,7 @@ func (c *commandVolumeDelete) Help() string { ` } -func (c *commandVolumeDelete) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) != 2 { fmt.Fprintf(writer, "received args: %+v\n", args) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index cff4adf89..09e1c19eb 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -13,7 +13,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeFixReplication{}) + Commands = append(Commands, &commandVolumeFixReplication{}) } type commandVolumeFixReplication struct { @@ -41,7 +41,7 @@ func (c *commandVolumeFixReplication) Help() string { ` } -func (c *commandVolumeFixReplication) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { takeAction := true if len(args) > 0 && args[0] == "-n" { @@ -50,7 +50,7 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *commandEnv, var resp *master_pb.VolumeListResponse ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) diff --git a/weed/shell/command_volume_list.go b/weed/shell/command_volume_list.go index a402c1e51..134580ffe 100644 --- a/weed/shell/command_volume_list.go +++ b/weed/shell/command_volume_list.go @@ -11,7 +11,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeList{}) + Commands = append(Commands, &commandVolumeList{}) } type commandVolumeList struct { @@ -29,11 +29,11 @@ func (c *commandVolumeList) Help() string { ` } -func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { var resp *master_pb.VolumeListResponse ctx := context.Background() - err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { + err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{}) return err }) diff --git a/weed/shell/command_volume_mount.go b/weed/shell/command_volume_mount.go index 37dd7765f..50a307492 100644 --- a/weed/shell/command_volume_mount.go +++ b/weed/shell/command_volume_mount.go @@ -12,7 +12,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeMount{}) + Commands = append(Commands, &commandVolumeMount{}) } type commandVolumeMount struct { @@ -32,7 +32,7 @@ func (c *commandVolumeMount) Help() string { ` } -func (c *commandVolumeMount) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeMount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) != 2 { fmt.Fprintf(writer, "received args: %+v\n", args) diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.go index 03b1446e6..08d87c988 100644 --- a/weed/shell/command_volume_move.go +++ b/weed/shell/command_volume_move.go @@ -14,7 +14,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeMove{}) + Commands = append(Commands, &commandVolumeMove{}) } type commandVolumeMove struct { @@ -42,7 +42,7 @@ func (c *commandVolumeMove) Help() string { ` } -func (c *commandVolumeMove) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) != 3 { fmt.Fprintf(writer, "received args: %+v\n", args) diff --git a/weed/shell/command_volume_unmount.go b/weed/shell/command_volume_unmount.go index ce9f666af..8096f34d8 100644 --- a/weed/shell/command_volume_unmount.go +++ b/weed/shell/command_volume_unmount.go @@ -12,7 +12,7 @@ import ( ) func init() { - commands = append(commands, &commandVolumeUnmount{}) + Commands = append(Commands, &commandVolumeUnmount{}) } type commandVolumeUnmount struct { @@ -32,7 +32,7 @@ func (c *commandVolumeUnmount) Help() string { ` } -func (c *commandVolumeUnmount) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) { +func (c *commandVolumeUnmount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { if len(args) != 2 { fmt.Fprintf(writer, "received args: %+v\n", args) diff --git a/weed/shell/commands.go b/weed/shell/commands.go index 6fade6e9d..ade8acd89 100644 --- a/weed/shell/commands.go +++ b/weed/shell/commands.go @@ -3,15 +3,16 @@ package shell import ( "context" "fmt" - "github.com/chrislusf/seaweedfs/weed/filer2" - "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" - "github.com/chrislusf/seaweedfs/weed/wdclient" - "google.golang.org/grpc" "io" "net/url" "path/filepath" "strconv" "strings" + + "github.com/chrislusf/seaweedfs/weed/filer2" + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "github.com/chrislusf/seaweedfs/weed/wdclient" + "google.golang.org/grpc" ) type ShellOptions struct { @@ -23,23 +24,33 @@ type ShellOptions struct { Directory string } -type commandEnv struct { +type CommandEnv struct { env map[string]string - masterClient *wdclient.MasterClient + MasterClient *wdclient.MasterClient option ShellOptions } type command interface { Name() string Help() string - Do([]string, *commandEnv, io.Writer) error + Do([]string, *CommandEnv, io.Writer) error } var ( - commands = []command{} + Commands = []command{} ) -func (ce *commandEnv) parseUrl(input string) (filerServer string, filerPort int64, path string, err error) { + +func NewCommandEnv(options ShellOptions) *CommandEnv { + return &CommandEnv{ + env: make(map[string]string), + MasterClient: wdclient.NewMasterClient(context.Background(), + options.GrpcDialOption, "shell", strings.Split(*options.Masters, ",")), + option: options, + } +} + +func (ce *CommandEnv) parseUrl(input string) (filerServer string, filerPort int64, path string, err error) { if strings.HasPrefix(input, "http") { return parseFilerUrl(input) } @@ -49,13 +60,13 @@ func (ce *commandEnv) parseUrl(input string) (filerServer string, filerPort int6 return ce.option.FilerHost, ce.option.FilerPort, input, err } -func (ce *commandEnv) isDirectory(ctx context.Context, filerServer string, filerPort int64, path string) bool { +func (ce *CommandEnv) isDirectory(ctx context.Context, filerServer string, filerPort int64, path string) bool { return ce.checkDirectory(ctx, filerServer, filerPort, path) == nil } -func (ce *commandEnv) checkDirectory(ctx context.Context, filerServer string, filerPort int64, path string) error { +func (ce *CommandEnv) checkDirectory(ctx context.Context, filerServer string, filerPort int64, path string) error { dir, name := filer2.FullPath(path).DirAndName() diff --git a/weed/shell/shell_liner.go b/weed/shell/shell_liner.go index 2c3058cbf..a4f17e0fa 100644 --- a/weed/shell/shell_liner.go +++ b/weed/shell/shell_liner.go @@ -1,17 +1,16 @@ package shell import ( - "context" "fmt" - "github.com/chrislusf/seaweedfs/weed/wdclient" "io" "os" "path" "regexp" "strings" - "github.com/peterh/liner" "sort" + + "github.com/peterh/liner" ) var ( @@ -33,15 +32,10 @@ func RunShell(options ShellOptions) { reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`) - commandEnv := &commandEnv{ - env: make(map[string]string), - masterClient: wdclient.NewMasterClient(context.Background(), - options.GrpcDialOption, "shell", strings.Split(*options.Masters, ",")), - option: options, - } + commandEnv := NewCommandEnv(options) - go commandEnv.masterClient.KeepConnectedToMaster() - commandEnv.masterClient.WaitUntilConnected() + go commandEnv.MasterClient.KeepConnectedToMaster() + commandEnv.MasterClient.WaitUntilConnected() for { cmd, err := line.Prompt("> ") @@ -71,7 +65,7 @@ func RunShell(options ShellOptions) { return } else { foundCommand := false - for _, c := range commands { + for _, c := range Commands { if c.Name() == cmd { if err := c.Do(args, commandEnv, os.Stdout); err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) @@ -94,10 +88,10 @@ func printGenericHelp() { ` fmt.Print(msg) - sort.Slice(commands, func(i, j int) bool { - return strings.Compare(commands[i].Name(), commands[j].Name()) < 0 + sort.Slice(Commands, func(i, j int) bool { + return strings.Compare(Commands[i].Name(), Commands[j].Name()) < 0 }) - for _, c := range commands { + for _, c := range Commands { helpTexts := strings.SplitN(c.Help(), "\n", 2) fmt.Printf(" %-30s\t# %s \n", c.Name(), helpTexts[0]) } @@ -112,11 +106,11 @@ func printHelp(cmds []string) { } else { cmd := strings.ToLower(args[0]) - sort.Slice(commands, func(i, j int) bool { - return strings.Compare(commands[i].Name(), commands[j].Name()) < 0 + sort.Slice(Commands, func(i, j int) bool { + return strings.Compare(Commands[i].Name(), Commands[j].Name()) < 0 }) - for _, c := range commands { + for _, c := range Commands { if c.Name() == cmd { fmt.Printf(" %s\t# %s\n", c.Name(), c.Help()) } @@ -126,7 +120,7 @@ func printHelp(cmds []string) { func setCompletionHandler() { line.SetCompleter(func(line string) (c []string) { - for _, i := range commands { + for _, i := range Commands { if strings.HasPrefix(i.Name(), strings.ToLower(line)) { c = append(c, i.Name()) } |
