DCAE Controller documentation DCAEGEN2-213
[dcaegen2.git] / docs / sections / components / component-specification / docker-specification.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.\r
2 .. http://creativecommons.org/licenses/by/4.0\r
3 \r
4 .. _docker-specification:\r
5 \r
6 Component specification (Docker)\r
7 ================================\r
8 \r
9 The Docker component specification contains the following groups of\r
10 information. Many of these are common to both Docker and CDAP components\r
11 and are therefore described in the common specification.\r
12 \r
13 -  :any:`Metadata <metadata>`\r
14 -  :any:`Interfaces <interfaces>` including the\r
15    associated :any:`Data Formats <data-formats>`\r
16 -  :any:`Parameters <parameters>`\r
17 -  :any:`Auxiliary Details <docker-auxiliary-details>`\r
18 -  :any:`List of Artifacts <artifacts>`\r
19 \r
20 .. _docker-auxiliary-details:\r
21 \r
22 Auxiliary Details\r
23 -----------------\r
24 \r
25 ``auxiliary`` contains Docker specific details like health check, port\r
26 mapping, volume mapping, and policy reconfiguration script details.\r
27 \r
28 +-------------+----+----------+\r
29 | Name        | Ty\| Descript\|\r
30 |             | pe | ion      |\r
31 +=============+====+==========+\r
32 | healthcheck | JS\| *Require\|\r
33 |             | ON | d*.      |\r
34 |             | ob\| Health   |\r
35 |             | je\| check    |\r
36 |             | ct | definiti\|\r
37 |             |    | on       |\r
38 |             |    | details  |\r
39 +-------------+----+----------+\r
40 | ports       | JS\| each     |\r
41 |             | ON | array    |\r
42 |             | ar\| item     |\r
43 |             | ra\| maps a   |\r
44 |             | y  | containe\|\r
45 |             |    | r        |\r
46 |             |    | port to  |\r
47 |             |    | the host |\r
48 |             |    | port.    |\r
49 |             |    | See      |\r
50 |             |    | example  |\r
51 |             |    | below.   |\r
52 +-------------+----+----------+\r
53 | volume      | JS\| each     |\r
54 |             | ON | array    |\r
55 |             | ar\| item     |\r
56 |             | ra\| contains |\r
57 |             | y  | a host   |\r
58 |             |    | and      |\r
59 |             |    | containe\|\r
60 |             |    | r        |\r
61 |             |    | object.  |\r
62 |             |    | See      |\r
63 |             |    | example  |\r
64 |             |    | below.   |\r
65 +-------------+----+----------+\r
66 | policy      | JS\| *Require\|\r
67 |             | ON | d*.      |\r
68 |             | ar\| Policy   |\r
69 |             | ra\| script   |\r
70 |             | y  | details  |\r
71 +-------------+----+----------+\r
72 \r
73 Health Check Definition\r
74 ~~~~~~~~~~~~~~~~~~~~~~~\r
75 \r
76 The platform uses Consul to perform periodic health check calls. Consul\r
77 provides different types of `check definitions <https://www.consul.io/docs/agent/checks.html>`_. The\r
78 platform currently supports http and docker health checks.\r
79 \r
80 When choosing a value for interval, consider that too frequent\r
81 healthchecks will put unnecessary load on Consul and DCAE. If there is a\r
82 problematic resource, then more frequent healthchecks are warranted (eg\r
83 15s or 60s), but as stablility increases, so can these values, (eg\r
84 300s).\r
85 \r
86 When choosing a value for timeout, consider that too small a number will\r
87 result in increasing timeout failures, and too large a number will\r
88 result in a delay in the notification of resource problem. A suggestion\r
89 is to start with 5s and workd from there.\r
90 \r
91 http\r
92 ^^^^\r
93 \r
94 +-------------+----+----------+\r
95 | Property    | Ty\| Descript\|\r
96 | Name        | pe | ion      |\r
97 +=============+====+==========+\r
98 | type        | st\| *Require\|\r
99 |             | ri\| d*.      |\r
100 |             | ng | ``http`` |\r
101 +-------------+----+----------+\r
102 | interval    | st\| Interval |\r
103 |             | ri\| duration |\r
104 |             | ng | in       |\r
105 |             |    | seconds  |\r
106 |             |    | i.e.     |\r
107 |             |    | ``60s``  |\r
108 +-------------+----+----------+\r
109 | timeout     | st\| Timeout  |\r
110 |             | ri\| in       |\r
111 |             | ng | seconds  |\r
112 |             |    | i.e.     |\r
113 |             |    | ``5s``   |\r
114 +-------------+----+----------+\r
115 | endpoint    | st\| *Require\|\r
116 |             | ri\| d*.      |\r
117 |             | ng | GET      |\r
118 |             |    | endpoint |\r
119 |             |    | provided |\r
120 |             |    | by the   |\r
121 |             |    | componen\|\r
122 |             |    | t        |\r
123 |             |    | for      |\r
124 |             |    | Consul   |\r
125 |             |    | to call  |\r
126 |             |    | to check |\r
127 |             |    | health   |\r
128 +-------------+----+----------+\r
129 \r
130 Example:\r
131 \r
132 .. code:: json\r
133 \r
134     "auxilary": {\r
135         "healthcheck": {\r
136             "type": "http",\r
137             "interval": "15s",\r
138             "timeout": "1s",\r
139             "endpoint": "/my-health"\r
140         }\r
141     }\r
142 \r
143 docker script example\r
144 ^^^^^^^^^^^^^^^^^^^^^\r
145 \r
146 +-------------+----+------------+\r
147 | Property    | Ty\| Descript\  |\r
148 | Name        | pe | ion        |\r
149 +=============+====+============+\r
150 | type        | st\| *Require\  |\r
151 |             | ri\| d*.        |\r
152 |             | ng | ``docker`` |\r
153 +-------------+----+------------+\r
154 | interval    | st\| Interval   |\r
155 |             | ri\| duration   |\r
156 |             | ng | in         |\r
157 |             |    | seconds    |\r
158 |             |    | i.e.       |\r
159 |             |    | ``15s``    |\r
160 +-------------+----+------------+\r
161 | timeout     | st\| Timeout    |\r
162 |             | ri\| in         |\r
163 |             | ng | seconds    |\r
164 |             |    | i.e.       |\r
165 |             |    | ``1s``     |\r
166 +-------------+----+------------+\r
167 | script      | st\| *Require\  |\r
168 |             | ri\| d*.        |\r
169 |             | ng | Full       |\r
170 |             |    | path of    |\r
171 |             |    | script     |\r
172 |             |    | that       |\r
173 |             |    | exists     |\r
174 |             |    | in the     |\r
175 |             |    | Docker     |\r
176 |             |    | containe\  |\r
177 |             |    | r          |\r
178 |             |    | to be      |\r
179 |             |    | executed   |\r
180 +-------------+----+------------+\r
181 \r
182 Consul will use the `Docker exec API <https://docs.docker.com/engine/api/v1.29/#tag/Exec>`_ to\r
183 periodically call your script in your container. It will examine the\r
184 script result to identify whether your component is healthy. Your\r
185 component is considered healthy when the script returns ``0`` otherwise\r
186 your component is considered not healthy.\r
187 \r
188 Example:\r
189 \r
190 .. code:: json\r
191 \r
192     "auxilary": {\r
193         "healthcheck": {\r
194             "type": "docker",\r
195             "script": "/app/resources/check_health.py",\r
196             "timeout": "30s",\r
197             "interval": "180s"\r
198         }\r
199     }\r
200 \r
201 Ports\r
202 ~~~~~\r
203 \r
204 .. code:: json\r
205 \r
206     "auxilary": {\r
207         "ports": ["8080:8000"]\r
208     }\r
209 \r
210 In the example above, container port 8080 maps to host port 8000.\r
211 \r
212 Volume Mapping\r
213 ~~~~~~~~~~~~~~\r
214 \r
215 .. code:: json\r
216 \r
217     "auxilary": {\r
218         "volumes": [\r
219             {\r
220                "container": {\r
221                    "bind": "/tmp/docker.sock",\r
222                    "mode": "ro"\r
223                 },\r
224                 "host": {\r
225                     "path": "/var/run/docker.sock"\r
226                 }\r
227             }\r
228         ]\r
229     }\r
230 \r
231 At the top-level:\r
232 \r
233 +---------------+-------+-------------------------------------+\r
234 | Property Name | Type  | Description                         |\r
235 +===============+=======+=====================================+\r
236 | volumes       | array | Contains container and host objects |\r
237 +---------------+-------+-------------------------------------+\r
238 \r
239 The ``container`` object contains:\r
240 \r
241 +----------------------+----------------------+----------------------+\r
242 | Property Name        | Type                 | Description          |\r
243 +======================+======================+======================+\r
244 | bind                 | string               | path to the          |\r
245 |                      |                      | container volume     |\r
246 +----------------------+----------------------+----------------------+\r
247 | mode                 | string               | “ro” - indicates     |\r
248 |                      |                      | read-only volume     |\r
249 |                      |                      | “” - indicates that  |\r
250 |                      |                      | the container can    |\r
251 |                      |                      | write into the bind  |\r
252 |                      |                      | mount                |\r
253 +----------------------+----------------------+----------------------+\r
254 \r
255 The ``host`` object contains:\r
256 \r
257 +---------------+--------+-------------------------+\r
258 | Property Name | Type   | Description             |\r
259 +===============+========+=========================+\r
260 | path          | string | path to the host volume |\r
261 +---------------+--------+-------------------------+\r
262 \r
263 Here’s an example of the minimal JSON that must be provided as an input:\r
264 \r
265 .. code:: json\r
266 \r
267     "auxilary": {\r
268         "volumes": [\r
269             {\r
270                "container": {\r
271                    "bind": "/tmp/docker.sock"\r
272                 },\r
273                 "host": {\r
274                     "path": "/var/run/docker.sock"\r
275                 }\r
276             }\r
277         ]\r
278     }\r
279 \r
280 In the example above, the container volume “/tmp/docker.sock” maps to\r
281 host volume “/var/run/docker.sock”.\r
282 \r
283 Policy\r
284 ~~~~~~\r
285 \r
286 Policy changes made in the Policy UI will be provided to the Docker\r
287 component by triggering a script that is defined here.\r
288 \r
289 +-------------+----+------------+\r
290 | Property    | Ty\| Descript\  |\r
291 | Name        | pe | ion        |\r
292 +=============+====+============+\r
293 | reconfigure | st\| *Require\  |\r
294 | _type       | ri\| d*.        |\r
295 |             | ng | Current    |\r
296 |             |    | value      |\r
297 |             |    | supporte   |\r
298 |             |    | d          |\r
299 |             |    | is         |\r
300 |             |    | ``policy`` |\r
301 +-------------+----+------------+\r
302 | script_path | st\| *Require\  |\r
303 |             | ri\| d*.        |\r
304 |             | ng | Current    |\r
305 |             |    | value      |\r
306 |             |    | for        |\r
307 |             |    | ‘policy’   |\r
308 |             |    | reconfig\  |\r
309 |             |    | ure_type   |\r
310 |             |    | must be    |\r
311 |             |    | “/opt/ap\  |\r
312 |             |    | p/reconf\  |\r
313 |             |    | igure.sh   |\r
314 |             |    | ”          |\r
315 +-------------+----+------------+\r
316 \r
317 Example:\r
318 \r
319 .. code:: json\r
320 \r
321     "auxilary": {\r
322         "policy": {\r
323             "reconfigure_type": "policy",\r
324             "script_path": "/opt/app/reconfigure.sh"\r
325         }\r
326     }\r
327 \r
328 The docker script interface is as follows: \`/opt/app/reconfigure.sh\r
329 $reconfigure_type {“updated policies”: , “application config”: }\r
330 \r
331 +-----+----+---------------------------+\r
332 | Na\ | Ty\| Descript\                 |\r
333 | me  | pe | ion                       |\r
334 +=====+====+===========================+\r
335 | re\ | st\| “policy”                  |\r
336 | co\ | ri\|                           |\r
337 | nf\ | ng |                           |\r
338 | ig\ |    |                           |\r
339 | ur\ |    |                           |\r
340 | e_t\|    |                           |\r
341 | y\  |    |                           |\r
342 | pe\ |    |                           |\r
343 +-----+----+---------------------------+\r
344 | up\ | js\| TBD                       |\r
345 | da\ | on |                           |\r
346 | te\ |    |                           |\r
347 | d_p\|    |                           |\r
348 | o\  |    |                           |\r
349 | li\ |    |                           |\r
350 | ci\ |    |                           |\r
351 | es  |    |                           |\r
352 +-----+----+---------------------------+\r
353 | up\ | js\| complete                  |\r
354 | da\ | on | generate\                 |\r
355 | te\ |    | d                         |\r
356 | d_a\|    | app_conf\                 |\r
357 | p\  |    | ig,                       |\r
358 | pl\ |    | not                       |\r
359 | _c\ |    | fully-re\                 |\r
360 | on\ |    | solved,                   |\r
361 | fi\ |    | but                       |\r
362 | g   |    | ``policy-enabled``        |\r
363 |     |    | paramete\                 |\r
364 |     |    | rs                        |\r
365 |     |    | have                      |\r
366 |     |    | been                      |\r
367 |     |    | updated.                  |\r
368 |     |    | In order                  |\r
369 |     |    | to get                    |\r
370 |     |    | the                       |\r
371 |     |    | complete                  |\r
372 |     |    | updated                   |\r
373 |     |    | app_conf\                 |\r
374 |     |    | ig,                       |\r
375 |     |    | the                       |\r
376 |     |    | componen\                 |\r
377 |     |    | t                         |\r
378 |     |    | would                     |\r
379 |     |    | have to                   |\r
380 |     |    | call                      |\r
381 |     |    | ``config-binding-service``|\r
382 |     |    | .                         |\r
383 +-----+----+---------------------------+\r
384 \r
385 Docker Component Spec - Complete Example\r
386 ----------------------------------------\r
387 \r
388 .. code:: json\r
389 \r
390     {\r
391         "self": {\r
392             "version": "1.0.0",\r
393             "name": "asimov.component.kpi_anomaly",\r
394             "description": "Classifies VNF KPI data as anomalous",\r
395             "component_type": "docker"\r
396         },\r
397         "streams": {\r
398             "subscribes": [{\r
399                 "format": "dcae.vnf.kpi",\r
400                 "version": "1.0.0",\r
401                 "route": "/data",\r
402                 "type": "http"\r
403             }],\r
404             "publishes": [{\r
405                 "format": "asimov.format.integerClassification",\r
406                 "version": "1.0.0",\r
407                 "config_key": "prediction",\r
408                 "type": "http"\r
409             }]\r
410         },\r
411         "services": {\r
412             "calls": [{\r
413                 "config_key": "vnf-db",\r
414                 "request": {\r
415                     "format": "dcae.vnf.meta",\r
416                     "version": "1.0.0"\r
417                     },\r
418                 "response": {\r
419                     "format": "dcae.vnf.kpi",\r
420                     "version": "1.0.0"\r
421                     }\r
422             }],\r
423             "provides": [{\r
424                 "route": "/score-vnf",\r
425                 "request": {\r
426                     "format": "dcae.vnf.meta",\r
427                     "version": "1.0.0"\r
428                     },\r
429                 "response": {\r
430                     "format": "asimov.format.integerClassification",\r
431                     "version": "1.0.0"\r
432                     }\r
433             }]\r
434         },\r
435         "parameters": [\r
436             {\r
437                 "name": "threshold",\r
438                 "value": 0.75,\r
439                 "description": "Probability threshold to exceed to be anomalous"\r
440             }\r
441         ],\r
442         "auxilary": {\r
443             "healthcheck": {\r
444                 "type": "http",\r
445                 "interval": "15s",\r
446                 "timeout": "1s",\r
447                 "endpoint": "/my-health"\r
448             }\r
449         },\r
450         "artifacts": [{\r
451             "uri": "fake.nexus.com/dcae/kpi_anomaly:1.0.0",\r
452             "type": "docker image"\r
453         }]\r
454     }\r