You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. "io"
  7. )
  8. func init() {
  9. commands = append(commands, &commandVolumeList{})
  10. }
  11. type commandVolumeList struct {
  12. }
  13. func (c *commandVolumeList) Name() string {
  14. return "volume.list"
  15. }
  16. func (c *commandVolumeList) Help() string {
  17. return `list all volumes
  18. This command list all volumes as a tree of dataCenter > rack > dataNode > volume.
  19. `
  20. }
  21. func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
  22. var resp *master_pb.VolumeListResponse
  23. ctx := context.Background()
  24. err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
  25. resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{})
  26. return err
  27. })
  28. if err != nil {
  29. return err
  30. }
  31. writeTopologyInfo(writer, resp.TopologyInfo)
  32. return nil
  33. }
  34. func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) {
  35. fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  36. for _, dc := range t.DataCenterInfos {
  37. writeDataCenterInfo(writer, dc)
  38. }
  39. }
  40. func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) {
  41. fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  42. for _, r := range t.RackInfos {
  43. writeRackInfo(writer, r)
  44. }
  45. }
  46. func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) {
  47. fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  48. for _, dn := range t.DataNodeInfos {
  49. writeDataNodeInfo(writer, dn)
  50. }
  51. }
  52. func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) {
  53. fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  54. for _, vi := range t.VolumeInfos {
  55. writeVolumeInformationMessage(writer, vi)
  56. }
  57. }
  58. func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) {
  59. fmt.Fprintf(writer, " volume %+v \n", t)
  60. }