forked from fabric8-services/fabric8-wit
/
deployments.go
276 lines (246 loc) · 9.05 KB
/
deployments.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package design
import (
d "github.com/goadesign/goa/design"
a "github.com/goadesign/goa/design/apidsl"
)
// SimpleSpace describe a space
var simpleSpace = a.Type("SimpleSpace", func() {
a.Description(`a space consisting of multiple applications`)
a.Attribute("type", d.String, "The type of the related resource", func() {
a.Enum("space")
a.Default("space")
})
a.Attribute("id", d.UUID, "ID of the space", func() {
a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04")
})
a.Attribute("attributes", simpleSpaceAttributes)
a.Required("type", "id", "attributes")
})
var simpleSpaceAttributes = a.Type("SimpleSpaceAttributes", func() {
a.Description(`a space consisting of multiple applications`)
a.Attribute("name", d.String)
a.Attribute("applications", a.ArrayOf(simpleApp))
a.Required("name", "applications")
})
// SimpleApp describe an application within a space
var simpleApp = a.Type("SimpleApp", func() {
a.Description(`a description of an application`)
a.Attribute("type", d.String, "The type of the related resource", func() {
a.Enum("application")
})
a.Attribute("id", d.String, "ID of the application (same as 'name')")
a.Attribute("attributes", simpleAppAttributes)
a.Required("type", "id", "attributes")
})
var simpleAppAttributes = a.Type("SimpleAppAttributes", func() {
a.Description(`a description of an application`)
a.Attribute("name", d.String)
a.Attribute("deployments", a.ArrayOf(simpleDeployment))
a.Required("name", "deployments")
})
// simpleDeployment describe an element of an application pipeline
var simpleDeployment = a.Type("SimpleDeployment", func() {
a.Description(`a deployment (a step in a pipeline, e.g. 'build')`)
a.Attribute("type", d.String, "The type of the related resource", func() {
a.Enum("deployment")
})
a.Attribute("id", d.String, "ID of the deployment (same as 'name')")
a.Attribute("attributes", simpleDeploymentAttributes)
a.Attribute("links", genericLinksForDeployment)
a.Required("type", "id", "attributes")
})
var genericLinksForDeployment = a.Type("GenericLinksForDeployment", func() {
a.Attribute("console", d.String)
a.Attribute("logs", d.String)
a.Attribute("application", d.String)
// in the future perhaps: a.Attribute("self", d.String)
})
var simpleDeploymentAttributes = a.Type("SimpleDeploymentAttributes", func() {
a.Description(`a deployment (a step in a pipeline, e.g. 'build')`)
a.Attribute("id", d.UUID)
a.Attribute("name", d.String)
a.Attribute("version", d.String)
a.Attribute("pods", a.ArrayOf(a.ArrayOf(d.String)))
a.Attribute("pod_total", d.Integer)
a.Attribute("pods_quota", podsQuota)
a.Required("name")
a.Required("pods")
})
var podsQuota = a.Type("PodsQuota", func() {
a.Description(`resource quotas for pods of a deployment`)
a.Attribute("cpucores", d.Number)
a.Attribute("memory", d.Number)
})
var simpleEnvironment = a.Type("SimpleEnvironment", func() {
a.Description(`a shared environment`)
a.Attribute("type", d.String, "The type of the related resource", func() {
a.Enum("environment")
})
a.Attribute("id", d.String, "ID of the environment (same as 'name')")
a.Attribute("attributes", simpleEnvironmentAttributes)
a.Required("type", "id", "attributes")
})
var simpleEnvironmentAttributes = a.Type("SimpleEnvironmentAttributes", func() {
a.Description(`a shared environment`)
a.Attribute("name", d.String)
a.Attribute("quota", envStats)
})
var envStats = a.Type("EnvStats", func() {
a.Description("resource usage and quotas for an environment")
a.Attribute("cpucores", envStatCores)
a.Attribute("memory", envStatMemory)
})
var envStatCores = a.Type("EnvStatCores", func() {
a.Description(`CPU core stats`)
a.Attribute("used", d.Number)
a.Attribute("quota", d.Number)
})
var envStatMemory = a.Type("EnvStatMemory", func() {
a.Description(`memory stats`)
a.Attribute("used", d.Number)
a.Attribute("quota", d.Number)
a.Attribute("units", d.String)
})
var timedNumberTuple = a.Type("TimedNumberTuple", func() {
a.Description("a set of time and number values")
a.Attribute("time", d.Number)
a.Attribute("value", d.Number)
})
var simpleDeploymentStats = a.Type("SimpleDeploymentStats", func() {
a.Description("current deployment stats")
a.Attribute("type", d.String, "The type of the related resource", func() {
a.Enum("deploymentstats")
})
a.Attribute("id", d.String, "ID of the deployment (same as 'name')")
a.Attribute("attributes", simpleDeploymentStatsAttributes)
a.Required("type", "id", "attributes")
})
var simpleDeploymentStatsAttributes = a.Type("SimpleDeploymentStatsAttributes", func() {
a.Description("current deployment stats")
a.Attribute("cores", timedNumberTuple)
a.Attribute("memory", timedNumberTuple)
a.Attribute("net_tx", timedNumberTuple)
a.Attribute("net_rx", timedNumberTuple)
})
var simpleDeploymentStatSeries = a.Type("SimpleDeploymentStatSeries", func() {
a.Description("pod stat series")
a.Attribute("start", d.Number)
a.Attribute("end", d.Number)
a.Attribute("memory", a.ArrayOf(timedNumberTuple))
a.Attribute("cores", a.ArrayOf(timedNumberTuple))
a.Attribute("net_tx", a.ArrayOf(timedNumberTuple))
a.Attribute("net_rx", a.ArrayOf(timedNumberTuple))
})
var simpleSpaceSingle = JSONSingle(
"SimpleSpace", "Holds a single response to a space request",
simpleSpace,
nil)
var simpleEnvironmentMultiple = JSONList(
"SimpleEnvironment", "Holds a response to a space/environment request",
simpleEnvironment,
nil,
nil)
var simpleDeploymentStatsSingle = JSONSingle(
"SimpleDeploymentStats", "Holds a single response to a space/application/deployment/stats request",
simpleDeploymentStats,
nil)
var simpleDeploymentStatSeriesSingle = JSONSingle(
"SimpleDeploymentStatSeries", "Holds a response to a stat series query",
simpleDeploymentStatSeries,
nil)
var _ = a.Resource("deployments", func() {
a.BasePath("/deployments")
// An auth token is required to call the auth API to get an OpenShift auth token.
a.Security("jwt")
a.Action("showSpace", func() {
a.Routing(
a.GET("/spaces/:spaceID"),
)
a.Description("list applications in a space")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
})
a.Response(d.OK, simpleSpaceSingle)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("showDeploymentStats", func() {
a.Routing(
a.GET("/spaces/:spaceID/applications/:appName/deployments/:deployName/stats"),
)
a.Description("get deployment statistics")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
a.Param("appName", d.String, "Name of the application")
a.Param("deployName", d.String, "Name of the deployment")
a.Param("start", d.Number, "start time in millis")
})
a.Response(d.OK, simpleDeploymentStatsSingle)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("showDeploymentStatSeries", func() {
a.Routing(
a.GET("/spaces/:spaceID/applications/:appName/deployments/:deployName/statseries"),
)
a.Description("list deployment statistics")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
a.Param("appName", d.String, "Name of the application")
a.Param("deployName", d.String, "Name of the deployment")
a.Param("start", d.Number, "start time in millis")
a.Param("end", d.Number, "end time in millis")
a.Param("limit", d.Integer, "maximum number of data points to return")
})
a.Response(d.OK, simpleDeploymentStatSeriesSingle)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("setDeployment", func() {
a.Routing(
a.PUT("/spaces/:spaceID/applications/:appName/deployments/:deployName"),
)
a.Description("set deployment pod count")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
a.Param("appName", d.String, "Name of the application")
a.Param("deployName", d.String, "Name of the deployment")
a.Param("podCount", d.Integer, "desired running pod count")
})
a.Response(d.OK)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("deleteDeployment", func() {
a.Routing(
a.DELETE("/spaces/:spaceID/applications/:appName/deployments/:deployName"),
)
a.Description("Delete a deployment of an application")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
a.Param("appName", d.String, "Name of the application")
a.Param("deployName", d.String, "Name of the deployment")
})
a.Response(d.OK)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("showSpaceEnvironments", func() {
a.Routing(
a.GET("/spaces/:spaceID/environments"),
)
a.Description("list all environments for a space")
a.Params(func() {
a.Param("spaceID", d.UUID, "ID of the space")
})
a.Response(d.OK, simpleEnvironmentMultiple)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
})