Browse Source

change topology mapping definition, improve spelling

pull/3348/head
ningfd 2 years ago
parent
commit
58f2dd6740
  1. 2
      weed/server/master_server_handlers_admin.go
  2. 4
      weed/server/master_server_handlers_ui.go
  3. 21
      weed/topology/data_center.go
  4. 19
      weed/topology/data_node.go
  5. 21
      weed/topology/rack.go
  6. 35
      weed/topology/topology_info.go
  7. 18
      weed/topology/volume_layout.go

2
weed/server/master_server_handlers_admin.go

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

4
weed/server/master_server_handlers_ui.go

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

21
weed/topology/data_center.go

@ -31,25 +31,24 @@ func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
return rack
}
type DataCenterMap struct {
Id NodeId `json:"Id"`
Racks []RackMap `json:"Racks"`
type DataCenterInfo struct {
Id NodeId `json:"Id"`
Racks []RackInfo `json:"Racks"`
}
func (dc *DataCenter) ToMap() DataCenterMap {
m := DataCenterMap{}
m.Id = dc.Id()
var racks []RackMap
func (dc *DataCenter) ToInfo() (info DataCenterInfo) {
info.Id = dc.Id()
var racks []RackInfo
for _, c := range dc.Children() {
rack := c.(*Rack)
racks = append(racks, rack.ToMap())
racks = append(racks, rack.ToInfo())
}
slices.SortFunc(racks, func(a, b RackMap) bool {
slices.SortFunc(racks, func(a, b RackInfo) bool {
return a.Id < b.Id
})
m.Racks = racks
return m
info.Racks = racks
return
}
func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {

19
weed/topology/data_node.go

@ -217,7 +217,7 @@ func (dn *DataNode) ServerAddress() pb.ServerAddress {
return pb.NewServerAddress(dn.Ip, dn.Port, dn.GrpcPort)
}
type DataNodeMap struct {
type DataNodeInfo struct {
Url string `json:"Url"`
PublicUrl string `json:"PublicUrl"`
Volumes int64 `json:"Volumes"`
@ -226,10 +226,9 @@ type DataNodeMap struct {
VolumeIds string `json:"VolumeIds"`
}
func (dn *DataNode) ToMap() DataNodeMap {
ret := DataNodeMap{}
ret.Url = dn.Url()
ret.PublicUrl = dn.PublicUrl
func (dn *DataNode) ToInfo() (info DataNodeInfo) {
info.Url = dn.Url()
info.PublicUrl = dn.PublicUrl
// aggregated volume info
var volumeCount, ecShardCount, maxVolumeCount int64
@ -245,12 +244,12 @@ func (dn *DataNode) ToMap() DataNodeMap {
volumeIds += " " + d.GetVolumeIds()
}
ret.Volumes = volumeCount
ret.EcShards = ecShardCount
ret.Max = maxVolumeCount
ret.VolumeIds = volumeIds
info.Volumes = volumeCount
info.EcShards = ecShardCount
info.Max = maxVolumeCount
info.VolumeIds = volumeIds
return ret
return
}
func (dn *DataNode) ToDataNodeInfo() *master_pb.DataNodeInfo {

21
weed/topology/rack.go

@ -54,26 +54,25 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl
return dn
}
type RackMap struct {
Id NodeId `json:"Id"`
DataNodes []DataNodeMap `json:"DataNodes"`
type RackInfo struct {
Id NodeId `json:"Id"`
DataNodes []DataNodeInfo `json:"DataNodes"`
}
func (r *Rack) ToMap() RackMap {
m := RackMap{}
m.Id = r.Id()
var dns []DataNodeMap
func (r *Rack) ToInfo() (info RackInfo) {
info.Id = r.Id()
var dns []DataNodeInfo
for _, c := range r.Children() {
dn := c.(*DataNode)
dns = append(dns, dn.ToMap())
dns = append(dns, dn.ToInfo())
}
slices.SortFunc(dns, func(a, b DataNodeMap) bool {
slices.SortFunc(dns, func(a, b DataNodeInfo) bool {
return a.Url < b.Url
})
m.DataNodes = dns
return m
info.DataNodes = dns
return
}
func (r *Rack) ToRackInfo() *master_pb.RackInfo {

35
weed/topology/topology_map.go → weed/topology/topology_info.go

@ -5,41 +5,40 @@ import (
"golang.org/x/exp/slices"
)
type TopologyMap struct {
Max int64 `json:"Max"`
Free int64 `json:"Free"`
DataCenters []DataCenterMap `json:"DataCenters"`
Layouts []interface{} `json:"Layouts"`
type TopologyInfo struct {
Max int64 `json:"Max"`
Free int64 `json:"Free"`
DataCenters []DataCenterInfo `json:"DataCenters"`
Layouts []VolumeLayoutInfo `json:"Layouts"`
}
func (t *Topology) ToMap() interface{} {
m := TopologyMap{}
m.Max = t.diskUsages.GetMaxVolumeCount()
m.Free = t.diskUsages.FreeSpace()
var dcs []DataCenterMap
func (t *Topology) ToInfo() (info TopologyInfo) {
info.Max = t.diskUsages.GetMaxVolumeCount()
info.Free = t.diskUsages.FreeSpace()
var dcs []DataCenterInfo
for _, c := range t.Children() {
dc := c.(*DataCenter)
dcs = append(dcs, dc.ToMap())
dcs = append(dcs, dc.ToInfo())
}
slices.SortFunc(dcs, func(a, b DataCenterMap) bool {
slices.SortFunc(dcs, func(a, b DataCenterInfo) bool {
return a.Id < b.Id
})
m.DataCenters = dcs
var layouts []interface{}
info.DataCenters = dcs
var layouts []VolumeLayoutInfo
for _, col := range t.collectionMap.Items() {
c := col.(*Collection)
for _, layout := range c.storageType2VolumeLayout.Items() {
if layout != nil {
tmp := layout.(*VolumeLayout).ToMap()
tmp["collection"] = c.Name
tmp := layout.(*VolumeLayout).ToInfo()
tmp.Collection = c.Name
layouts = append(layouts, tmp)
}
}
}
m.Layouts = layouts
return m
info.Layouts = layouts
return
}
func (t *Topology) ToVolumeMap() interface{} {

18
weed/topology/volume_layout.go

@ -473,13 +473,19 @@ func (vl *VolumeLayout) SetVolumeCrowded(vid needle.VolumeId) {
}
}
func (vl *VolumeLayout) ToMap() map[string]interface{} {
m := make(map[string]interface{})
m["replication"] = vl.rp.String()
m["ttl"] = vl.ttl.String()
m["writables"] = vl.writables
type VolumeLayoutInfo struct {
Replication string `json:"replication"`
TTL string `json:"ttl"`
Writables []needle.VolumeId `json:"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
return m
return
}
func (vl *VolumeLayout) Stats() *VolumeLayoutStats {

Loading…
Cancel
Save