Skip to content

Commit

Permalink
fix(worker): fixed multi-manager configuration
Browse files Browse the repository at this point in the history
the worker must be registerred on the manager

`extra_status_manager` option is replaced by `api_base_list`, which overrides the `api_base` option
  • Loading branch information
bigeagle committed Dec 12, 2016
1 parent 97e9725 commit fd27738
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
14 changes: 11 additions & 3 deletions worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
25 changes: 10 additions & 15 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand All @@ -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())
}
Expand All @@ -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())
Expand Down

0 comments on commit fd27738

Please sign in to comment.