mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Merge pull request #128 from yanyiwu/master
[ui] Ordered VolumeInfos is more Human-readable
This commit is contained in:
commit
5c760523be
|
@ -223,7 +223,9 @@ func (s *Store) Status() []*VolumeInfo {
|
||||||
var stats []*VolumeInfo
|
var stats []*VolumeInfo
|
||||||
for _, location := range s.Locations {
|
for _, location := range s.Locations {
|
||||||
for k, v := range location.volumes {
|
for k, v := range location.volumes {
|
||||||
s := &VolumeInfo{Id: VolumeId(k), Size: v.ContentSize(),
|
s := &VolumeInfo{
|
||||||
|
Id: VolumeId(k),
|
||||||
|
Size: v.ContentSize(),
|
||||||
Collection: v.Collection,
|
Collection: v.Collection,
|
||||||
ReplicaPlacement: v.ReplicaPlacement,
|
ReplicaPlacement: v.ReplicaPlacement,
|
||||||
Version: v.Version(),
|
Version: v.Version(),
|
||||||
|
@ -235,6 +237,7 @@ func (s *Store) Status() []*VolumeInfo {
|
||||||
stats = append(stats, s)
|
stats = append(stats, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sortVolumeInfos(stats)
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/go/operation"
|
"github.com/chrislusf/seaweedfs/go/operation"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VolumeInfo struct {
|
type VolumeInfo struct {
|
||||||
|
@ -42,3 +43,23 @@ func (vi VolumeInfo) String() string {
|
||||||
return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
|
return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
|
||||||
vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
|
vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*VolumesInfo sorting*/
|
||||||
|
|
||||||
|
type volumeInfos []*VolumeInfo
|
||||||
|
|
||||||
|
func (vis volumeInfos) Len() int {
|
||||||
|
return len(vis)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vis volumeInfos) Less(i, j int) bool {
|
||||||
|
return vis[i].Id < vis[j].Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vis volumeInfos) Swap(i, j int) {
|
||||||
|
vis[i], vis[j] = vis[j], vis[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortVolumeInfos(vis volumeInfos) {
|
||||||
|
sort.Sort(vis)
|
||||||
|
}
|
||||||
|
|
23
go/storage/volume_info_test.go
Normal file
23
go/storage/volume_info_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSortVolumeInfos(t *testing.T) {
|
||||||
|
vis := []*VolumeInfo{
|
||||||
|
&VolumeInfo{
|
||||||
|
Id: 2,
|
||||||
|
},
|
||||||
|
&VolumeInfo{
|
||||||
|
Id: 1,
|
||||||
|
},
|
||||||
|
&VolumeInfo{
|
||||||
|
Id: 3,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
sortVolumeInfos(vis)
|
||||||
|
for i := 0; i < len(vis); i++ {
|
||||||
|
if vis[i].Id != VolumeId(i+1) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue