mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
Move the WebMirrorStatus to internal package. Fix the list command of tunasynctl
This commit is contained in:
parent
a475b044c6
commit
4fe7d03e54
@ -140,8 +140,7 @@ func listWorkers(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listJobs(c *cli.Context) error {
|
func listJobs(c *cli.Context) error {
|
||||||
// FIXME: there should be an API on manager server side that return MirrorStatus list to tunasynctl
|
var jobs []tunasync.WebMirrorStatus
|
||||||
var jobs []tunasync.MirrorStatus
|
|
||||||
if c.Bool("all") {
|
if c.Bool("all") {
|
||||||
_, err := tunasync.GetJSON(baseURL+listJobsPath, &jobs, client)
|
_, err := tunasync.GetJSON(baseURL+listJobsPath, &jobs, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -158,10 +157,10 @@ func listJobs(c *cli.Context) error {
|
|||||||
fmt.Sprintf("Usage Error: jobs command need at"+
|
fmt.Sprintf("Usage Error: jobs command need at"+
|
||||||
" least one arguments or \"--all\" flag."), 1)
|
" least one arguments or \"--all\" flag."), 1)
|
||||||
}
|
}
|
||||||
ans := make(chan []tunasync.MirrorStatus, len(args))
|
ans := make(chan []tunasync.WebMirrorStatus, len(args))
|
||||||
for _, workerID := range args {
|
for _, workerID := range args {
|
||||||
go func(workerID string) {
|
go func(workerID string) {
|
||||||
var workerJobs []tunasync.MirrorStatus
|
var workerJobs []tunasync.WebMirrorStatus
|
||||||
_, err := tunasync.GetJSON(fmt.Sprintf("%s/workers/%s/jobs",
|
_, err := tunasync.GetJSON(fmt.Sprintf("%s/workers/%s/jobs",
|
||||||
baseURL, workerID), &workerJobs, client)
|
baseURL, workerID), &workerJobs, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package manager
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/tuna/tunasync/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type textTime struct {
|
type textTime struct {
|
||||||
@ -38,8 +36,8 @@ func (t *stampTime) UnmarshalJSON(b []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// webMirrorStatus is the mirror status to be shown in the web page
|
// WebMirrorStatus is the mirror status to be shown in the web page
|
||||||
type webMirrorStatus struct {
|
type WebMirrorStatus struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsMaster bool `json:"is_master"`
|
IsMaster bool `json:"is_master"`
|
||||||
Status SyncStatus `json:"status"`
|
Status SyncStatus `json:"status"`
|
||||||
@ -49,8 +47,8 @@ type webMirrorStatus struct {
|
|||||||
Size string `json:"size"` // approximate size
|
Size string `json:"size"` // approximate size
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertMirrorStatus(m MirrorStatus) webMirrorStatus {
|
func BuildWebMirrorStatus(m MirrorStatus) WebMirrorStatus {
|
||||||
return webMirrorStatus{
|
return WebMirrorStatus{
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
IsMaster: m.IsMaster,
|
IsMaster: m.IsMaster,
|
||||||
Status: m.Status,
|
Status: m.Status,
|
@ -1,12 +1,10 @@
|
|||||||
package manager
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
tunasync "github.com/tuna/tunasync/internal"
|
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,9 +14,9 @@ func TestStatus(t *testing.T) {
|
|||||||
loc, err := time.LoadLocation(tz)
|
loc, err := time.LoadLocation(tz)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
t := time.Date(2016, time.April, 16, 23, 8, 10, 0, loc)
|
t := time.Date(2016, time.April, 16, 23, 8, 10, 0, loc)
|
||||||
m := webMirrorStatus{
|
m := WebMirrorStatus{
|
||||||
Name: "tunalinux",
|
Name: "tunalinux",
|
||||||
Status: tunasync.Success,
|
Status: Success,
|
||||||
LastUpdate: textTime{t},
|
LastUpdate: textTime{t},
|
||||||
LastUpdateTs: stampTime{t},
|
LastUpdateTs: stampTime{t},
|
||||||
Size: "5GB",
|
Size: "5GB",
|
||||||
@ -28,7 +26,7 @@ func TestStatus(t *testing.T) {
|
|||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
//fmt.Println(string(b))
|
//fmt.Println(string(b))
|
||||||
var m2 webMirrorStatus
|
var m2 WebMirrorStatus
|
||||||
err = json.Unmarshal(b, &m2)
|
err = json.Unmarshal(b, &m2)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
// fmt.Printf("%#v", m2)
|
// fmt.Printf("%#v", m2)
|
@ -135,11 +135,11 @@ func (s *Manager) listAllJobs(c *gin.Context) {
|
|||||||
s.returnErrJSON(c, http.StatusInternalServerError, err)
|
s.returnErrJSON(c, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
webMirStatusList := []webMirrorStatus{}
|
webMirStatusList := []WebMirrorStatus{}
|
||||||
for _, m := range mirrorStatusList {
|
for _, m := range mirrorStatusList {
|
||||||
webMirStatusList = append(
|
webMirStatusList = append(
|
||||||
webMirStatusList,
|
webMirStatusList,
|
||||||
convertMirrorStatus(m),
|
BuildWebMirrorStatus(m),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, webMirStatusList)
|
c.JSON(http.StatusOK, webMirStatusList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user