Skip to content

Commit

Permalink
Merge pull request tuna#58 from tuna/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bigeagle authored Dec 12, 2016
2 parents c5cba66 + 9ffb101 commit 9ac3193
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/tunasync/tunasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/tunasynctl/tunasynctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package internal

const Version string = "0.2-dev"
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 9ac3193

Please sign in to comment.