seaweedfs/weed/shell/command_volume_list.go

72 lines
2.1 KiB
Go
Raw Normal View History

2019-03-18 03:27:08 +00:00
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 {
2019-03-23 18:54:26 +00:00
return `list all volumes
This command list all volumes as a tree of dataCenter > rack > dataNode > volume.
`
2019-03-18 03:27:08 +00:00
}
2019-03-19 12:19:37 +00:00
func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
2019-03-18 03:27:08 +00:00
2019-03-19 12:19:37 +00:00
var resp *master_pb.VolumeListResponse
2019-03-20 06:01:23 +00:00
ctx := context.Background()
err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
2019-03-19 12:19:37 +00:00
resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{})
return err
})
2019-03-18 03:27:08 +00:00
if err != nil {
return err
}
2019-03-18 03:27:36 +00:00
writeTopologyInfo(writer, resp.TopologyInfo)
2019-03-18 03:27:08 +00:00
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)
}