ability to add and remove workers
This commit is contained in:
parent
33721e54aa
commit
17d773fac0
2 changed files with 25 additions and 3 deletions
|
@ -31,12 +31,32 @@ func GetWorkers(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
//
|
//
|
||||||
func PostWorker(c web.C, w http.ResponseWriter, r *http.Request) {
|
func PostWorker(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := context.FromC(c)
|
ctx := context.FromC(c)
|
||||||
workers := pool.FromContext(ctx)
|
pool := pool.FromContext(ctx)
|
||||||
node := r.FormValue("node")
|
node := r.FormValue("address")
|
||||||
workers.Allocate(docker.NewHost(node))
|
pool.Allocate(docker.NewHost(node))
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete accepts a request to delete a worker
|
||||||
|
// from the pool.
|
||||||
|
//
|
||||||
|
// DELETE /api/workers
|
||||||
|
//
|
||||||
|
func DelWorker(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := context.FromC(c)
|
||||||
|
pool := pool.FromContext(ctx)
|
||||||
|
uuid := r.FormValue("id")
|
||||||
|
|
||||||
|
for _, worker := range pool.List() {
|
||||||
|
if worker.(*docker.Docker).UUID != uuid {
|
||||||
|
pool.Deallocate(worker)
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
// GetWorkPending accepts a request to retrieve the list
|
// GetWorkPending accepts a request to retrieve the list
|
||||||
// of pending work and returns in JSON format.
|
// of pending work and returns in JSON format.
|
||||||
//
|
//
|
||||||
|
|
|
@ -163,6 +163,8 @@ func main() {
|
||||||
work.Get("/api/work/pending", handler.GetWorkPending)
|
work.Get("/api/work/pending", handler.GetWorkPending)
|
||||||
work.Get("/api/work/assignments", handler.GetWorkAssigned)
|
work.Get("/api/work/assignments", handler.GetWorkAssigned)
|
||||||
work.Get("/api/workers", handler.GetWorkers)
|
work.Get("/api/workers", handler.GetWorkers)
|
||||||
|
work.Post("/api/workers", handler.PostWorker)
|
||||||
|
work.Delete("/api/workers", handler.DelWorker)
|
||||||
goji.Handle("/api/work*", work)
|
goji.Handle("/api/work*", work)
|
||||||
|
|
||||||
// Include static resources
|
// Include static resources
|
||||||
|
|
Loading…
Reference in a new issue