forked from openshift/origin
/
control.go
55 lines (49 loc) · 1.87 KB
/
control.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
51
52
53
54
55
package origin
import (
"fmt"
"net/http"
restful "github.com/emicklei/go-restful"
"github.com/openshift/origin/pkg/cmd/util/plug"
)
// initControllerRoutes adds a web service endpoint for managing the execution
// state of the controllers.
func initControllerRoutes(root *restful.WebService, path string, canStart bool, plug plug.Plug) {
root.Route(root.GET(path).To(func(req *restful.Request, resp *restful.Response) {
if !canStart {
resp.ResponseWriter.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(resp, "disabled")
return
}
if plug.IsStarted() {
resp.ResponseWriter.WriteHeader(http.StatusOK)
fmt.Fprintf(resp, "ok")
} else {
resp.ResponseWriter.WriteHeader(http.StatusAccepted)
fmt.Fprintf(resp, "waiting")
}
}).Doc("Check whether the controllers are running on this master").
Returns(http.StatusOK, "if controllers are running", nil).
Returns(http.StatusMethodNotAllowed, "if controllers are disabled", nil).
Returns(http.StatusAccepted, "if controllers are waiting to be started", nil).
Produces(restful.MIME_JSON))
root.Route(root.PUT(path).To(func(req *restful.Request, resp *restful.Response) {
if !canStart {
resp.ResponseWriter.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(resp, "disabled")
return
}
plug.Start()
resp.ResponseWriter.WriteHeader(http.StatusOK)
fmt.Fprintf(resp, "ok")
}).Doc("Start controllers on this master").
Returns(http.StatusOK, "if controllers have started", nil).
Returns(http.StatusMethodNotAllowed, "if controllers are disabled", nil).
Produces(restful.MIME_JSON))
root.Route(root.DELETE(path).To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusAccepted)
fmt.Fprintf(resp, "terminating")
plug.Stop()
}).Doc("Stop the master").
Returns(http.StatusAccepted, "if the master will stop", nil).
Produces(restful.MIME_JSON))
}