Exemple #1
0
// PostWorker accepts a request to allocate a new
// worker to the pool.
//
//     POST /api/workers
//
func PostWorker(c web.C, w http.ResponseWriter, r *http.Request) {
	ctx := context.FromC(c)
	pool := pool.FromContext(ctx)
	node := r.FormValue("address")
	pool.Allocate(docker.NewHost(node))
	w.WriteHeader(http.StatusOK)
}
Exemple #2
0
// 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)
}
Exemple #3
0
// do is a blocking function that waits for an
// available worker to process work.
func (d *Director) do(c context.Context, work *worker.Work) {
	d.markPending(work)
	var pool = pool.FromContext(c)
	var worker = <-pool.Reserve()

	//	var worker worker.Worker
	//
	//	// waits for an available worker. This is a blocking
	//	// operation and will reject any nil workers to avoid
	//	// a potential panic.
	//	select {
	//	case worker = <-pool.Reserve():
	//		if worker != nil {
	//			break
	//		}
	//	}

	d.markStarted(work, worker)
	worker.Do(c, work)
	d.markComplete(work)
	pool.Release(worker)
}
Exemple #4
0
// GetWorkers accepts a request to retrieve the list
// of registered workers and return the results
// in JSON format.
//
//     GET /api/workers
//
func GetWorkers(c web.C, w http.ResponseWriter, r *http.Request) {
	ctx := context.FromC(c)
	workers := pool.FromContext(ctx).List()
	json.NewEncoder(w).Encode(workers)
}