mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
a04bd4d26f
* Bump github.com/rclone/rclone from 1.63.1 to 1.64.0 Bumps [github.com/rclone/rclone](https://github.com/rclone/rclone) from 1.63.1 to 1.64.0. - [Release notes](https://github.com/rclone/rclone/releases) - [Changelog](https://github.com/rclone/rclone/blob/master/RELEASE.md) - [Commits](https://github.com/rclone/rclone/compare/v1.63.1...v1.64.0) --- updated-dependencies: - dependency-name: github.com/rclone/rclone dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * API changes * go mod --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: chrislu <chris.lu@gmail.com>
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package topology
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"golang.org/x/exp/slices"
|
|
"strings"
|
|
)
|
|
|
|
type DataCenter struct {
|
|
NodeImpl
|
|
}
|
|
|
|
func NewDataCenter(id string) *DataCenter {
|
|
dc := &DataCenter{}
|
|
dc.id = NodeId(id)
|
|
dc.nodeType = "DataCenter"
|
|
dc.diskUsages = newDiskUsages()
|
|
dc.children = make(map[NodeId]Node)
|
|
dc.NodeImpl.value = dc
|
|
return dc
|
|
}
|
|
|
|
func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
|
|
dc.Lock()
|
|
defer dc.Unlock()
|
|
for _, c := range dc.children {
|
|
rack := c.(*Rack)
|
|
if string(rack.Id()) == rackName {
|
|
return rack
|
|
}
|
|
}
|
|
rack := NewRack(rackName)
|
|
dc.doLinkChildNode(rack)
|
|
return rack
|
|
}
|
|
|
|
type DataCenterInfo struct {
|
|
Id NodeId `json:"Id"`
|
|
Racks []RackInfo `json:"Racks"`
|
|
}
|
|
|
|
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.ToInfo())
|
|
}
|
|
|
|
slices.SortFunc(racks, func(a, b RackInfo) int {
|
|
return strings.Compare(string(a.Id), string(b.Id))
|
|
})
|
|
info.Racks = racks
|
|
return
|
|
}
|
|
|
|
func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {
|
|
m := &master_pb.DataCenterInfo{
|
|
Id: string(dc.Id()),
|
|
DiskInfos: dc.diskUsages.ToDiskInfo(),
|
|
}
|
|
for _, c := range dc.Children() {
|
|
rack := c.(*Rack)
|
|
m.RackInfos = append(m.RackInfos, rack.ToRackInfo())
|
|
}
|
|
return m
|
|
}
|