blob: 128c006d1791fc5bd6af1cf7f3d8f7c6f80c98bc [file] [log] [blame]
Ralph Knag1fca6ac2017-12-05 12:05:57 -05001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3
4.. _docker-specification:
5
6Component specification (Docker)
7================================
8
9The Docker component specification contains the following groups of
10information. Many of these are common to both Docker and CDAP components
11and are therefore described in the common specification.
12
13- :any:`Metadata <metadata>`
14- :any:`Interfaces <interfaces>` including the
15 associated :any:`Data Formats <data-formats>`
16- :any:`Parameters <parameters>`
17- :any:`Auxiliary Details <docker-auxiliary-details>`
18- :any:`List of Artifacts <artifacts>`
19
20.. _docker-auxiliary-details:
21
22Auxiliary Details
23-----------------
24
25``auxiliary`` contains Docker specific details like health check, port
Ralph Knagd2cd31b2018-04-02 16:27:46 -040026mapping, volume mapping and policy reconfiguration script details.
27(Policy reconfiguration is not yet supported).
Ralph Knag1fca6ac2017-12-05 12:05:57 -050028
Ralph Knagd2cd31b2018-04-02 16:27:46 -040029+--------------------------------+---------+---------------------------+
30| Name | Type | Description |
31+================================+=========+===========================+
32| healthcheck | JSON | *Required*. Health check |
33| | object | definition details |
34+--------------------------------+---------+---------------------------+
35| ports | JSON | each array item maps a |
36| | array | container port to the |
37| | | host port. See example |
38| | | below. |
39+--------------------------------+---------+---------------------------+
40| volume | JSON | each array item contains |
41| | array | a host and container |
42| | | object. See example |
43| | | below. |
44+--------------------------------+---------+---------------------------+
45| *Planned for 1806* | | |
46+--------------------------------+---------+---------------------------+
47| policy | JSON | *Required*. Policy |
48| | array | reconfiguration script |
49| | | details |
50+--------------------------------+---------+---------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -050051
52Health Check Definition
53~~~~~~~~~~~~~~~~~~~~~~~
54
55The platform uses Consul to perform periodic health check calls. Consul
Ralph Knagd2cd31b2018-04-02 16:27:46 -040056provides different types of `check
57definitions <https://www.consul.io/docs/agent/checks.html>`__. The
Ralph Knag1fca6ac2017-12-05 12:05:57 -050058platform currently supports http and docker health checks.
59
60When choosing a value for interval, consider that too frequent
61healthchecks will put unnecessary load on Consul and DCAE. If there is a
62problematic resource, then more frequent healthchecks are warranted (eg
Stanislav Chlebece7933a02018-11-15 10:08:31 +01006315s or 60s), but as stability increases, so can these values, (eg
Ralph Knag1fca6ac2017-12-05 12:05:57 -050064300s).
65
66When choosing a value for timeout, consider that too small a number will
67result in increasing timeout failures, and too large a number will
Ralph Knagd2cd31b2018-04-02 16:27:46 -040068result in a delay in the notification of the resource problem. A
69suggestion is to start with 5s and work from there.
Ralph Knag1fca6ac2017-12-05 12:05:57 -050070
71http
72^^^^
73
Ralph Knagd2cd31b2018-04-02 16:27:46 -040074+--------------------------------+---------+---------------------------+
75| Property Name | Type | Description |
76+================================+=========+===========================+
77| type | string | *Required*. ``http`` |
78+--------------------------------+---------+---------------------------+
79| interval | string | Interval duration in |
80| | | seconds i.e. ``60s`` |
81+--------------------------------+---------+---------------------------+
82| timeout | string | Timeout in seconds i.e. |
83| | | ``5s`` |
84+--------------------------------+---------+---------------------------+
85| endpoint | string | *Required*. GET endpoint |
86| | | provided by the component |
87| | | for Consul to call to |
88| | | check health |
89+--------------------------------+---------+---------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -050090
91Example:
92
93.. code:: json
94
95 "auxilary": {
96 "healthcheck": {
97 "type": "http",
98 "interval": "15s",
99 "timeout": "1s",
100 "endpoint": "/my-health"
101 }
102 }
103
104docker script example
105^^^^^^^^^^^^^^^^^^^^^
106
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400107+--------------------------------+---------+---------------------------+
108| Property Name | Type | Description |
109+================================+=========+===========================+
110| type | string | *Required*. ``docker`` |
111+--------------------------------+---------+---------------------------+
112| interval | string | Interval duration in |
113| | | seconds i.e. ``15s`` |
114+--------------------------------+---------+---------------------------+
115| timeout | string | Timeout in seconds i.e. |
116| | | ``1s`` |
117+--------------------------------+---------+---------------------------+
118| script | string | *Required*. Full path of |
119| | | script that exists in the |
120| | | Docker container to be |
121| | | executed |
122+--------------------------------+---------+---------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500123
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400124Consul will use the `Docker exec
125API <https://docs.docker.com/engine/api/v1.29/#tag/Exec>`__ to
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500126periodically call your script in your container. It will examine the
127script result to identify whether your component is healthy. Your
128component is considered healthy when the script returns ``0`` otherwise
129your component is considered not healthy.
130
131Example:
132
133.. code:: json
134
135 "auxilary": {
136 "healthcheck": {
137 "type": "docker",
138 "script": "/app/resources/check_health.py",
139 "timeout": "30s",
140 "interval": "180s"
141 }
142 }
143
144Ports
145~~~~~
146
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400147This method of exposing/mapping a local port to a host port is NOT
148RECOMMENDED because of the possibility of port conflicts. If multiple
149instances of a docker container will be running, there definitely will
150be port conflicts. Use at your own risk. (The preferred way to expose a
151port is to do so in the Dockerfile as described
152:any:`here <dcae-cli-docker-ports>`).
153
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500154.. code:: json
155
156 "auxilary": {
157 "ports": ["8080:8000"]
158 }
159
160In the example above, container port 8080 maps to host port 8000.
161
162Volume Mapping
163~~~~~~~~~~~~~~
164
165.. code:: json
166
167 "auxilary": {
168 "volumes": [
169 {
170 "container": {
171 "bind": "/tmp/docker.sock",
172 "mode": "ro"
173 },
174 "host": {
175 "path": "/var/run/docker.sock"
176 }
177 }
178 ]
179 }
180
181At the top-level:
182
183+---------------+-------+-------------------------------------+
184| Property Name | Type | Description |
185+===============+=======+=====================================+
186| volumes | array | Contains container and host objects |
187+---------------+-------+-------------------------------------+
188
189The ``container`` object contains:
190
Lusheng Jieaac78d2018-06-06 00:20:03 -0400191
192+-----------------------+-----------------------+-------------------------------+
193| Property Name | Type | Description |
194+=======================+=======================+===============================+
195| bind | string | path to the container |
196| | | volume |
197+-----------------------+-----------------------+-------------------------------+
198| mode | string | ro - indicates |
199| | | read-only volume |
200+-----------------------+-----------------------+-------------------------------+
201| | | w - indicates that |
202| | | the contain can write |
203| | | into the bind mount |
204+-----------------------+-----------------------+-------------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500205
206The ``host`` object contains:
207
208+---------------+--------+-------------------------+
209| Property Name | Type | Description |
210+===============+========+=========================+
211| path | string | path to the host volume |
212+---------------+--------+-------------------------+
213
214Heres an example of the minimal JSON that must be provided as an input:
215
216.. code:: json
217
218 "auxilary": {
219 "volumes": [
220 {
221 "container": {
222 "bind": "/tmp/docker.sock"
223 },
224 "host": {
225 "path": "/var/run/docker.sock"
226 }
227 }
228 ]
229 }
230
231In the example above, the container volume “/tmp/docker.sock maps to
232host volume “/var/run/docker.sock”.
233
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400234
235Policy (not yet supported)
236~~~~~~~~~~~~~~~~~~~~~~~~~~
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500237
238Policy changes made in the Policy UI will be provided to the Docker
239component by triggering a script that is defined here.
240
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400241+--------------------------------+---------+---------------------------+
242| Property Name | Type | Description |
243+================================+=========+===========================+
244| reconfigure_type | string | *Required*. Current value |
245| | | supported is ``policy`` |
246+--------------------------------+---------+---------------------------+
247| script_path | string | *Required*. Current value |
248| | | for policy |
249| | | reconfigure_type must be |
250| | | “/opt/app/reconfigure.sh |
251+--------------------------------+---------+---------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500252
253Example:
254
255.. code:: json
256
257 "auxilary": {
258 "policy": {
259 "reconfigure_type": "policy",
260 "script_path": "/opt/app/reconfigure.sh"
261 }
262 }
263
264The docker script interface is as follows: \`/opt/app/reconfigure.sh
265$reconfigure_type {“updated policies”: , application config”: }
266
Lusheng Jieaac78d2018-06-06 00:20:03 -0400267+---------------------+--------------+----------------------------------------+
268| Name | Type | Description |
269+=====================+==============+========================================+
270| reconfigure_type | string | policy |
271+---------------------+--------------+----------------------------------------+
272| updated_policies | json | TBD |
273+---------------------+--------------+----------------------------------------+
274| updated_appl_config | json | complete generated app_config, not |
275| | | fully-resolved, but ``policy-enabled`` |
276| | | parameters have been updated. In order |
277| | | to get the complete updated |
278| | | app_config, the component would have |
279| | | to call ``config-binding-service``. |
280+---------------------+--------------+----------------------------------------+
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500281
282Docker Component Spec - Complete Example
283----------------------------------------
284
285.. code:: json
286
287 {
288 "self": {
289 "version": "1.0.0",
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400290 "name": "yourapp.component.kpi_anomaly",
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500291 "description": "Classifies VNF KPI data as anomalous",
292 "component_type": "docker"
293 },
294 "streams": {
295 "subscribes": [{
296 "format": "dcae.vnf.kpi",
297 "version": "1.0.0",
298 "route": "/data",
299 "type": "http"
300 }],
301 "publishes": [{
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400302 "format": "yourapp.format.integerClassification",
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500303 "version": "1.0.0",
304 "config_key": "prediction",
305 "type": "http"
306 }]
307 },
308 "services": {
309 "calls": [{
310 "config_key": "vnf-db",
311 "request": {
312 "format": "dcae.vnf.meta",
313 "version": "1.0.0"
314 },
315 "response": {
316 "format": "dcae.vnf.kpi",
317 "version": "1.0.0"
318 }
319 }],
320 "provides": [{
321 "route": "/score-vnf",
322 "request": {
323 "format": "dcae.vnf.meta",
324 "version": "1.0.0"
325 },
326 "response": {
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400327 "format": "yourapp.format.integerClassification",
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500328 "version": "1.0.0"
329 }
330 }]
331 },
332 "parameters": [
333 {
334 "name": "threshold",
335 "value": 0.75,
336 "description": "Probability threshold to exceed to be anomalous"
337 }
338 ],
339 "auxilary": {
340 "healthcheck": {
341 "type": "http",
342 "interval": "15s",
343 "timeout": "1s",
344 "endpoint": "/my-health"
345 }
346 },
347 "artifacts": [{
Ralph Knagd2cd31b2018-04-02 16:27:46 -0400348 "uri": "fake.nexus.att.com/dcae/kpi_anomaly:1.0.0",
Ralph Knag1fca6ac2017-12-05 12:05:57 -0500349 "type": "docker image"
350 }]
351 }