optimiz: master ui will render data in order

This commit is contained in:
ningfd 2022-07-22 14:34:17 +08:00
parent 7a6c559ab4
commit 6f882eb354
4 changed files with 70 additions and 25 deletions

View file

@ -2,6 +2,7 @@ package topology
import ( import (
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"golang.org/x/exp/slices"
) )
type DataCenter struct { type DataCenter struct {
@ -30,15 +31,24 @@ func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
return rack return rack
} }
func (dc *DataCenter) ToMap() interface{} { type DataCenterMap struct {
m := make(map[string]interface{}) Id NodeId `json:"Id"`
m["Id"] = dc.Id() Racks []RackMap `json:"Racks"`
var racks []interface{} }
func (dc *DataCenter) ToMap() DataCenterMap {
m := DataCenterMap{}
m.Id = dc.Id()
var racks []RackMap
for _, c := range dc.Children() { for _, c := range dc.Children() {
rack := c.(*Rack) rack := c.(*Rack)
racks = append(racks, rack.ToMap()) racks = append(racks, rack.ToMap())
} }
m["Racks"] = racks
slices.SortFunc(racks, func(a, b RackMap) bool {
return a.Id < b.Id
})
m.Racks = racks
return m return m
} }

View file

@ -217,10 +217,19 @@ func (dn *DataNode) ServerAddress() pb.ServerAddress {
return pb.NewServerAddress(dn.Ip, dn.Port, dn.GrpcPort) return pb.NewServerAddress(dn.Ip, dn.Port, dn.GrpcPort)
} }
func (dn *DataNode) ToMap() interface{} { type DataNodeMap struct {
ret := make(map[string]interface{}) Url string `json:"Url"`
ret["Url"] = dn.Url() PublicUrl string `json:"PublicUrl"`
ret["PublicUrl"] = dn.PublicUrl Volumes int64 `json:"Volumes"`
EcShards int64 `json:"EcShards"`
Max int64 `json:"Max"`
VolumeIds string `json:"VolumeIds"`
}
func (dn *DataNode) ToMap() DataNodeMap {
ret := DataNodeMap{}
ret.Url = dn.Url()
ret.PublicUrl = dn.PublicUrl
// aggregated volume info // aggregated volume info
var volumeCount, ecShardCount, maxVolumeCount int64 var volumeCount, ecShardCount, maxVolumeCount int64
@ -236,10 +245,10 @@ func (dn *DataNode) ToMap() interface{} {
volumeIds += " " + d.GetVolumeIds() volumeIds += " " + d.GetVolumeIds()
} }
ret["Volumes"] = volumeCount ret.Volumes = volumeCount
ret["EcShards"] = ecShardCount ret.EcShards = ecShardCount
ret["Max"] = maxVolumeCount ret.Max = maxVolumeCount
ret["VolumeIds"] = volumeIds ret.VolumeIds = volumeIds
return ret return ret
} }

View file

@ -4,6 +4,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"github.com/chrislusf/seaweedfs/weed/storage/types" "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"golang.org/x/exp/slices"
"time" "time"
) )
@ -53,15 +54,25 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl
return dn return dn
} }
func (r *Rack) ToMap() interface{} { type RackMap struct {
m := make(map[string]interface{}) Id NodeId `json:"Id"`
m["Id"] = r.Id() DataNodes []DataNodeMap `json:"DataNodes"`
var dns []interface{} }
func (r *Rack) ToMap() RackMap {
m := RackMap{}
m.Id = r.Id()
var dns []DataNodeMap
for _, c := range r.Children() { for _, c := range r.Children() {
dn := c.(*DataNode) dn := c.(*DataNode)
dns = append(dns, dn.ToMap()) dns = append(dns, dn.ToMap())
} }
m["DataNodes"] = dns
slices.SortFunc(dns, func(a, b DataNodeMap) bool {
return a.Url < b.Url
})
m.DataNodes = dns
return m return m
} }

View file

@ -1,17 +1,32 @@
package topology package topology
import "github.com/chrislusf/seaweedfs/weed/pb/master_pb" import (
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"golang.org/x/exp/slices"
)
type TopologyMap struct {
Max int64 `json:"Max"`
Free int64 `json:"Free"`
DataCenters []DataCenterMap `json:"DataCenters"`
Layouts []interface{} `json:"Layouts"`
}
func (t *Topology) ToMap() interface{} { func (t *Topology) ToMap() interface{} {
m := make(map[string]interface{}) m := TopologyMap{}
m["Max"] = t.diskUsages.GetMaxVolumeCount() m.Max = t.diskUsages.GetMaxVolumeCount()
m["Free"] = t.diskUsages.FreeSpace() m.Free = t.diskUsages.FreeSpace()
var dcs []interface{} var dcs []DataCenterMap
for _, c := range t.Children() { for _, c := range t.Children() {
dc := c.(*DataCenter) dc := c.(*DataCenter)
dcs = append(dcs, dc.ToMap()) dcs = append(dcs, dc.ToMap())
} }
m["DataCenters"] = dcs
slices.SortFunc(dcs, func(a, b DataCenterMap) bool {
return a.Id < b.Id
})
m.DataCenters = dcs
var layouts []interface{} var layouts []interface{}
for _, col := range t.collectionMap.Items() { for _, col := range t.collectionMap.Items() {
c := col.(*Collection) c := col.(*Collection)
@ -23,7 +38,7 @@ func (t *Topology) ToMap() interface{} {
} }
} }
} }
m["Layouts"] = layouts m.Layouts = layouts
return m return m
} }