mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-25 03:29:10 +08:00
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
|
"io"
|
|
)
|
|
|
|
func init() {
|
|
commands = append(commands, &commandVolumeList{})
|
|
}
|
|
|
|
type commandVolumeList struct {
|
|
}
|
|
|
|
func (c *commandVolumeList) Name() string {
|
|
return "volume.list"
|
|
}
|
|
|
|
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())
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
writeTopologyInfo(writer,resp.TopologyInfo)
|
|
|
|
return nil
|
|
}
|
|
|
|
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) {
|
|
fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
|
for _, dc := range t.DataCenterInfos {
|
|
writeDataCenterInfo(writer, dc)
|
|
}
|
|
}
|
|
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) {
|
|
fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
|
for _, r := range t.RackInfos {
|
|
writeRackInfo(writer, r)
|
|
}
|
|
}
|
|
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) {
|
|
fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
|
for _, dn := range t.DataNodeInfos {
|
|
writeDataNodeInfo(writer, dn)
|
|
}
|
|
}
|
|
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) {
|
|
fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
|
for _, vi := range t.VolumeInfos {
|
|
writeVolumeInformationMessage(writer, vi)
|
|
}
|
|
}
|
|
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) {
|
|
fmt.Fprintf(writer, " volume %+v \n", t)
|
|
}
|