From 17d773fac0b5dca8093f11a4ae1cb497c059a4a8 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 8 Oct 2014 21:55:53 -0700 Subject: [PATCH] ability to add and remove workers --- server/handler/worker.go | 26 +++++++++++++++++++++++--- server/main.go | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/server/handler/worker.go b/server/handler/worker.go index c8b7cd77..e6e9cf36 100644 --- a/server/handler/worker.go +++ b/server/handler/worker.go @@ -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) { ctx := context.FromC(c) - workers := pool.FromContext(ctx) - node := r.FormValue("node") - workers.Allocate(docker.NewHost(node)) + pool := pool.FromContext(ctx) + node := r.FormValue("address") + pool.Allocate(docker.NewHost(node)) 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 // of pending work and returns in JSON format. // diff --git a/server/main.go b/server/main.go index 74ee6da9..ac9ae002 100644 --- a/server/main.go +++ b/server/main.go @@ -163,6 +163,8 @@ func main() { work.Get("/api/work/pending", handler.GetWorkPending) work.Get("/api/work/assignments", handler.GetWorkAssigned) work.Get("/api/workers", handler.GetWorkers) + work.Post("/api/workers", handler.PostWorker) + work.Delete("/api/workers", handler.DelWorker) goji.Handle("/api/work*", work) // Include static resources