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.

67 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. }
  19. func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
  20. var resp *master_pb.VolumeListResponse
  21. ctx := context.Background()
  22. err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
  23. resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{})
  24. return err
  25. })
  26. if err != nil {
  27. return err
  28. }
  29. writeTopologyInfo(writer, resp.TopologyInfo)
  30. return nil
  31. }
  32. func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) {
  33. fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  34. for _, dc := range t.DataCenterInfos {
  35. writeDataCenterInfo(writer, dc)
  36. }
  37. }
  38. func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) {
  39. fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  40. for _, r := range t.RackInfos {
  41. writeRackInfo(writer, r)
  42. }
  43. }
  44. func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) {
  45. fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  46. for _, dn := range t.DataNodeInfos {
  47. writeDataNodeInfo(writer, dn)
  48. }
  49. }
  50. func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) {
  51. fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
  52. for _, vi := range t.VolumeInfos {
  53. writeVolumeInformationMessage(writer, vi)
  54. }
  55. }
  56. func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) {
  57. fmt.Fprintf(writer, " volume %+v \n", t)
  58. }