|
@ -5,41 +5,40 @@ import ( |
|
|
"golang.org/x/exp/slices" |
|
|
"golang.org/x/exp/slices" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type TopologyMap struct { |
|
|
|
|
|
|
|
|
type TopologyInfo struct { |
|
|
Max int64 `json:"Max"` |
|
|
Max int64 `json:"Max"` |
|
|
Free int64 `json:"Free"` |
|
|
Free int64 `json:"Free"` |
|
|
DataCenters []DataCenterMap `json:"DataCenters"` |
|
|
|
|
|
Layouts []interface{} `json:"Layouts"` |
|
|
|
|
|
|
|
|
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() { |
|
|
for _, c := range t.Children() { |
|
|
dc := c.(*DataCenter) |
|
|
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 |
|
|
return a.Id < b.Id |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
m.DataCenters = dcs |
|
|
|
|
|
var layouts []interface{} |
|
|
|
|
|
|
|
|
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["collection"] = c.Name |
|
|
|
|
|
|
|
|
tmp := layout.(*VolumeLayout).ToInfo() |
|
|
|
|
|
tmp.Collection = c.Name |
|
|
layouts = append(layouts, tmp) |
|
|
layouts = append(layouts, tmp) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
m.Layouts = layouts |
|
|
|
|
|
return m |
|
|
|
|
|
|
|
|
info.Layouts = layouts |
|
|
|
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *Topology) ToVolumeMap() interface{} { |
|
|
func (t *Topology) ToVolumeMap() interface{} { |