From fd277388d5b3a54d5451462312625747472bf4a1 Mon Sep 17 00:00:00 2001 From: bigeagle Date: Mon, 12 Dec 2016 23:11:23 +0800 Subject: [PATCH 1/2] fix(worker): fixed multi-manager configuration the worker must be registerred on the manager `extra_status_manager` option is replaced by `api_base_list`, which overrides the `api_base` option --- worker/config.go | 14 +++++++++++--- worker/worker.go | 25 ++++++++++--------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/worker/config.go b/worker/config.go index 138c9b0..97da0ff 100644 --- a/worker/config.go +++ b/worker/config.go @@ -55,12 +55,20 @@ type globalConfig struct { } type managerConfig struct { - APIBase string `toml:"api_base"` - CACert string `toml:"ca_cert"` - ExtraStatusAPIs []string `toml:"extra_status_managers"` + APIBase string `toml:"api_base"` + // this option overrides the APIBase + APIList []string `toml:"api_base_list"` + CACert string `toml:"ca_cert"` // Token string `toml:"token"` } +func (mc managerConfig) APIBaseList() []string { + if len(mc.APIList) > 0 { + return mc.APIList + } + return []string{mc.APIBase} +} + type serverConfig struct { Hostname string `toml:"hostname"` Addr string `toml:"listen_addr"` diff --git a/worker/worker.go b/worker/worker.go index 5bfb6f0..877b526 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -386,18 +386,17 @@ func (w *Worker) URL() string { } func (w *Worker) registorWorker() { - url := fmt.Sprintf( - "%s/workers", - w.cfg.Manager.APIBase, - ) - msg := WorkerStatus{ ID: w.Name(), URL: w.URL(), } - if _, err := PostJSON(url, msg, w.httpClient); err != nil { - logger.Errorf("Failed to register worker") + for _, root := range w.cfg.Manager.APIBaseList() { + url := fmt.Sprintf("%s/workers", root) + logger.Debugf("register on manager url: %s", url) + if _, err := PostJSON(url, msg, w.httpClient); err != nil { + logger.Errorf("Failed to register worker") + } } } @@ -413,12 +412,11 @@ func (w *Worker) updateStatus(job *mirrorJob, jobMsg jobMessage) { ErrorMsg: jobMsg.msg, } - apiBases := []string{w.cfg.Manager.APIBase} - apiBases = append(apiBases, w.cfg.Manager.ExtraStatusAPIs...) - for _, root := range apiBases { + for _, root := range w.cfg.Manager.APIBaseList() { url := fmt.Sprintf( "%s/workers/%s/jobs/%s", root, w.Name(), jobMsg.name, ) + logger.Debugf("reporting on manager url: %s", url) if _, err := PostJSON(url, smsg, w.httpClient); err != nil { logger.Errorf("Failed to update mirror(%s) status: %s", jobMsg.name, err.Error()) } @@ -427,12 +425,9 @@ func (w *Worker) updateStatus(job *mirrorJob, jobMsg jobMessage) { func (w *Worker) fetchJobStatus() []MirrorStatus { var mirrorList []MirrorStatus + apiBase := w.cfg.Manager.APIBaseList()[0] - url := fmt.Sprintf( - "%s/workers/%s/jobs", - w.cfg.Manager.APIBase, - w.Name(), - ) + url := fmt.Sprintf("%s/workers/%s/jobs", apiBase, w.Name()) if _, err := GetJSON(url, &mirrorList, w.httpClient); err != nil { logger.Errorf("Failed to fetch job status: %s", err.Error()) From 9ffb101cc7d8d6084d41fa4cde34cdd6b2d93819 Mon Sep 17 00:00:00 2001 From: bigeagle Date: Mon, 12 Dec 2016 23:23:00 +0800 Subject: [PATCH 2/2] chore(tunasync): bump version to 0.2-dev --- cmd/tunasync/tunasync.go | 2 +- cmd/tunasynctl/tunasynctl.go | 2 +- internal/version.go | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 internal/version.go diff --git a/cmd/tunasync/tunasync.go b/cmd/tunasync/tunasync.go index c9bed28..9e1ec41 100644 --- a/cmd/tunasync/tunasync.go +++ b/cmd/tunasync/tunasync.go @@ -134,7 +134,7 @@ func main() { app.Name = "tunasync" app.Usage = "tunasync mirror job management tool" app.EnableBashCompletion = true - app.Version = "0.1" + app.Version = tunasync.Version app.Commands = []cli.Command{ { Name: "manager", diff --git a/cmd/tunasynctl/tunasynctl.go b/cmd/tunasynctl/tunasynctl.go index ecea717..36a18a6 100644 --- a/cmd/tunasynctl/tunasynctl.go +++ b/cmd/tunasynctl/tunasynctl.go @@ -325,7 +325,7 @@ func main() { app := cli.NewApp() app.EnableBashCompletion = true - app.Version = "0.1" + app.Version = tunasync.Version app.Name = "tunasynctl" app.Usage = "control client for tunasync manager" diff --git a/internal/version.go b/internal/version.go new file mode 100644 index 0000000..b818a8e --- /dev/null +++ b/internal/version.go @@ -0,0 +1,3 @@ +package internal + +const Version string = "0.2-dev"