-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathcontrol.go
More file actions
62 lines (54 loc) · 2.01 KB
/
control.go
File metadata and controls
62 lines (54 loc) · 2.01 KB
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
56
57
58
59
60
61
62
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(apiContainer *restful.Container, path string, plug plug.Plug) {
canStart := plug != nil
ws := new(restful.WebService).
Path(path).
Doc("Check whether the controllers are running on this master")
ws.Route(ws.GET("/").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))
ws.Route(ws.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))
ws.Route(ws.DELETE(path).To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusAccepted)
fmt.Fprintf(resp, "terminating")
plug.Stop(nil)
}).Doc("Stop the master").
Returns(http.StatusAccepted, "if the master will stop", nil).
Produces(restful.MIME_JSON))
apiContainer.Add(ws)
}