forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
50 lines (40 loc) · 1.13 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package containerserver
import (
"encoding/json"
"io/ioutil"
"net/http"
"code.cloudfoundry.org/lager"
)
func (s *Server) ReportWorkerContainers(w http.ResponseWriter, r *http.Request) {
workerName := r.URL.Query().Get("worker_name")
w.Header().Set("Content-Type", "application/json")
logger := s.logger.Session("report-containers-for-worker", lager.Data{"name": workerName})
if workerName != "" {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
logger.Error("failed-to-read-body", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var handles []string
err = json.Unmarshal(data, &handles)
if err != nil {
logger.Error("failed-to-unmarshal-body", err)
w.WriteHeader(http.StatusBadRequest)
return
}
logger.Debug("handles-info", lager.Data{
"num-handles": len(handles),
})
err = s.destroyer.DestroyContainers(workerName, handles)
if err != nil {
logger.Error("failed-to-destroy-containers", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
} else {
logger.Info("missing-worker-name")
w.WriteHeader(http.StatusNotFound)
}
}