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

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