forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformation.go
More file actions
85 lines (70 loc) · 1.88 KB
/
formation.go
File metadata and controls
85 lines (70 loc) · 1.88 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package controllers
import (
"net/http"
"strconv"
"github.com/convox/rack/api/httperr"
"github.com/convox/rack/api/models"
"github.com/gorilla/mux"
)
func FormationList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
app := mux.Vars(r)["app"]
formation, err := models.Provider().FormationList(app)
if err != nil {
return httperr.Server(err)
}
return RenderJson(rw, formation)
}
func FormationSet(rw http.ResponseWriter, r *http.Request) *httperr.Error {
vars := mux.Vars(r)
app := vars["app"]
process := vars["process"]
pf, err := models.Provider().FormationGet(app, process)
if err != nil {
return httperr.Server(err)
}
// update based on form input
if cc := GetForm(r, "count"); cc != "" {
c, err := strconv.Atoi(cc)
if err != nil {
return httperr.Errorf(403, "count must be numeric")
}
switch {
// critical fix: old clients default to count=-1 for "no change"
// assert a minimum client version before setting count=-1 which now deletes a service / ELB
case r.Header.Get("Version") < "20160602213113" && c == -1:
// backwards compatibility: other old clients use count=-2 for "no change"
case c == -2:
default:
pf.Count = c
}
}
if cc := GetForm(r, "cpu"); cc != "" {
c, err := strconv.Atoi(cc)
if err != nil {
return httperr.Errorf(403, "cpu must be numeric")
}
switch {
// backwards compatibility: other old clients use cpu=-1 for "no change"
case c == -1:
default:
pf.CPU = c
}
}
if mm := GetForm(r, "memory"); mm != "" {
m, err := strconv.Atoi(mm)
if err != nil {
return httperr.Errorf(403, "memory must be numeric")
}
switch {
// backwards compatibility: other old clients use memory=-1 or memory=0 for "no change"
case m == -1 || m == 0:
default:
pf.Memory = m
}
}
err = models.Provider().FormationSave(app, pf)
if err != nil {
return httperr.Server(err)
}
return RenderSuccess(rw)
}