Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Adds Href to task resources for REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxbat committed Nov 21, 2015
1 parent 79007dd commit 998a891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions mgmt/rest/rbody/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type ScheduledTask struct {
FailedCount int `json:"failed_count,omitempty"`
LastFailureMessage string `json:"last_failure_message,omitempty"`
State string `json:"task_state"`
Href string `json:"href"`
}

func (s *ScheduledTask) CreationTime() time.Time {
Expand Down
7 changes: 7 additions & 0 deletions mgmt/rest/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (s *Server) addTask(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
}

taskB := rbody.AddSchedulerTaskFromTask(task)
taskB.Href = taskURI(r.Host, task)
respond(201, taskB, w)
}

Expand All @@ -119,6 +120,7 @@ func (s *Server) getTasks(w http.ResponseWriter, r *http.Request, _ httprouter.P
i := 0
for _, t := range sts {
tasks.ScheduledTasks[i] = *rbody.SchedulerTaskFromTask(t)
tasks.ScheduledTasks[i].Href = taskURI(r.Host, t)
i++
}
sort.Sort(tasks)
Expand All @@ -134,6 +136,7 @@ func (s *Server) getTask(w http.ResponseWriter, r *http.Request, p httprouter.Pa
}
task := &rbody.ScheduledTaskReturned{}
task.AddScheduledTask = *rbody.AddSchedulerTaskFromTask(t)
task.Href = taskURI(r.Host, t)
respond(200, task, w)
}

Expand Down Expand Up @@ -384,3 +387,7 @@ func (t *TaskWatchHandler) CatchTaskDisabled(why string) {
Message: why,
}
}

func taskURI(host string, t core.Task) string {
return fmt.Sprintf("%s://%s/v1/tasks/%s", protocolPrefix, host, t.ID())
}

0 comments on commit 998a891

Please sign in to comment.