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.

64 lines
1.9 KiB

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