Merge pull request #3348 from ningfdx/remote

optimiz: master ui will render data in order
This commit is contained in:
Chris Lu 2022-07-22 02:43:07 -07:00 committed by GitHub
commit 8d97add89c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 45 deletions

View file

@ -48,7 +48,7 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R
func (ms *MasterServer) dirStatusHandler(w http.ResponseWriter, r *http.Request) { func (ms *MasterServer) dirStatusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{}) m := make(map[string]interface{})
m["Version"] = util.Version() m["Version"] = util.Version()
m["Topology"] = ms.Topo.ToMap() m["Topology"] = ms.Topo.ToInfo()
writeJsonQuiet(w, r, http.StatusOK, m) writeJsonQuiet(w, r, http.StatusOK, m)
} }

View file

@ -26,7 +26,7 @@ func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request)
VolumeSizeLimitMB uint32 VolumeSizeLimitMB uint32
}{ }{
util.Version(), util.Version(),
ms.Topo.ToMap(), ms.Topo.ToInfo(),
ms.Topo.RaftServer, ms.Topo.RaftServer,
infos, infos,
serverStats, serverStats,
@ -43,7 +43,7 @@ func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request)
VolumeSizeLimitMB uint32 VolumeSizeLimitMB uint32
}{ }{
util.Version(), util.Version(),
ms.Topo.ToMap(), ms.Topo.ToInfo(),
ms.Topo.HashicorpRaft, ms.Topo.HashicorpRaft,
infos, infos,
serverStats, serverStats,

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,16 +31,24 @@ func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
return rack return rack
} }
func (dc *DataCenter) ToMap() interface{} { type DataCenterInfo struct {
m := make(map[string]interface{}) Id NodeId `json:"Id"`
m["Id"] = dc.Id() Racks []RackInfo `json:"Racks"`
var racks []interface{} }
func (dc *DataCenter) ToInfo() (info DataCenterInfo) {
info.Id = dc.Id()
var racks []RackInfo
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.ToInfo())
} }
m["Racks"] = racks
return m slices.SortFunc(racks, func(a, b RackInfo) bool {
return a.Id < b.Id
})
info.Racks = racks
return
} }
func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo { func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {

View file

@ -217,10 +217,18 @@ 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 DataNodeInfo 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) ToInfo() (info DataNodeInfo) {
info.Url = dn.Url()
info.PublicUrl = dn.PublicUrl
// aggregated volume info // aggregated volume info
var volumeCount, ecShardCount, maxVolumeCount int64 var volumeCount, ecShardCount, maxVolumeCount int64
@ -236,12 +244,12 @@ func (dn *DataNode) ToMap() interface{} {
volumeIds += " " + d.GetVolumeIds() volumeIds += " " + d.GetVolumeIds()
} }
ret["Volumes"] = volumeCount info.Volumes = volumeCount
ret["EcShards"] = ecShardCount info.EcShards = ecShardCount
ret["Max"] = maxVolumeCount info.Max = maxVolumeCount
ret["VolumeIds"] = volumeIds info.VolumeIds = volumeIds
return ret return
} }
func (dn *DataNode) ToDataNodeInfo() *master_pb.DataNodeInfo { func (dn *DataNode) ToDataNodeInfo() *master_pb.DataNodeInfo {

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,16 +54,25 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl
return dn return dn
} }
func (r *Rack) ToMap() interface{} { type RackInfo struct {
m := make(map[string]interface{}) Id NodeId `json:"Id"`
m["Id"] = r.Id() DataNodes []DataNodeInfo `json:"DataNodes"`
var dns []interface{} }
func (r *Rack) ToInfo() (info RackInfo) {
info.Id = r.Id()
var dns []DataNodeInfo
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.ToInfo())
} }
m["DataNodes"] = dns
return m slices.SortFunc(dns, func(a, b DataNodeInfo) bool {
return a.Url < b.Url
})
info.DataNodes = dns
return
} }
func (r *Rack) ToRackInfo() *master_pb.RackInfo { func (r *Rack) ToRackInfo() *master_pb.RackInfo {

View file

@ -1,30 +1,44 @@
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"
)
func (t *Topology) ToMap() interface{} { type TopologyInfo struct {
m := make(map[string]interface{}) Max int64 `json:"Max"`
m["Max"] = t.diskUsages.GetMaxVolumeCount() Free int64 `json:"Free"`
m["Free"] = t.diskUsages.FreeSpace() DataCenters []DataCenterInfo `json:"DataCenters"`
var dcs []interface{} Layouts []VolumeLayoutInfo `json:"Layouts"`
}
func (t *Topology) ToInfo() (info TopologyInfo) {
info.Max = t.diskUsages.GetMaxVolumeCount()
info.Free = t.diskUsages.FreeSpace()
var dcs []DataCenterInfo
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.ToInfo())
} }
m["DataCenters"] = dcs
var layouts []interface{} slices.SortFunc(dcs, func(a, b DataCenterInfo) bool {
return a.Id < b.Id
})
info.DataCenters = dcs
var layouts []VolumeLayoutInfo
for _, col := range t.collectionMap.Items() { for _, col := range t.collectionMap.Items() {
c := col.(*Collection) c := col.(*Collection)
for _, layout := range c.storageType2VolumeLayout.Items() { for _, layout := range c.storageType2VolumeLayout.Items() {
if layout != nil { if layout != nil {
tmp := layout.(*VolumeLayout).ToMap() tmp := layout.(*VolumeLayout).ToInfo()
tmp["collection"] = c.Name tmp.Collection = c.Name
layouts = append(layouts, tmp) layouts = append(layouts, tmp)
} }
} }
} }
m["Layouts"] = layouts info.Layouts = layouts
return m return
} }
func (t *Topology) ToVolumeMap() interface{} { func (t *Topology) ToVolumeMap() interface{} {

View file

@ -473,13 +473,19 @@ func (vl *VolumeLayout) SetVolumeCrowded(vid needle.VolumeId) {
} }
} }
func (vl *VolumeLayout) ToMap() map[string]interface{} { type VolumeLayoutInfo struct {
m := make(map[string]interface{}) Replication string `json:"replication"`
m["replication"] = vl.rp.String() TTL string `json:"ttl"`
m["ttl"] = vl.ttl.String() Writables []needle.VolumeId `json:"writables"`
m["writables"] = vl.writables Collection string `json:"collection"`
}
func (vl *VolumeLayout) ToInfo() (info VolumeLayoutInfo) {
info.Replication = vl.rp.String()
info.TTL = vl.ttl.String()
info.Writables = vl.writables
//m["locations"] = vl.vid2location //m["locations"] = vl.vid2location
return m return
} }
func (vl *VolumeLayout) Stats() *VolumeLayoutStats { func (vl *VolumeLayout) Stats() *VolumeLayoutStats {