2b8f5dc8a088b28d19eff8af9dd11edf856bcb5b
[optf/has.git] / conductor / doc / distribution / README.md
1 # Python/Linux Distribution Notes
2
3 *Updated: 10 Nov 2017 23:30 GMT*
4
5 This document exists to help bridge the gap between the Conductor python package and any downstream distribution. The steps outlined herein may be taken into consideration when creating an AT&T SWM package, Ubuntu/Debian package, Chef cookbook, or Ansible playbook.
6
7 ## Components
8
9 Conductor consists of five services that work together:
10
11 * **``conductor-api``**: An HTTP REST API
12 * **``conductor-controller``**: Validation, translation, and status/results
13 * **``conductor-data``**: Inventory provider and service controller gateway
14 * **``conductor-solver``**: Processing and solution calculation
15 * **``conductor-reservation``**: Reserves the suggested solution solved by Solver component.
16
17 ## Workflow
18
19 * Deployment **plans** are created, viewed, and deleted via ``conductor-api`` and its  [REST API](doc/api/README.md).
20 * Included within each ``conductor-api`` plan request is a [Homing Template](doc/template/README.md).
21 * Homing Templates describe a set of inventory demands and constraints to be solved against.
22 * ``conductor-api`` hands off all API requests to ``conductor-controller`` for handling.
23 * All deployment plans are assigned a unique identifier (UUID-4), which can be used to check for solution status asynchronously. (Conductor does not support callbacks at this time.)
24 * ``conductor-controller`` ensures templates are well-formed and valid. Errors and remediation are made visible through ``conductor-api``. When running in debug mode, the API will also include a python traceback in the response body, if available.
25 * ``conductor-controller`` uses ``conductor-data`` to resolve demands against a particular **inventory provider** (e.g., A&AI).
26 * ``conductor-controller`` translates the template into a format suitable for solving.
27 * As each template is translated, ``conductor-solver`` begins working on it.
28 * ``conductor-solver`` uses ``conductor-data`` to resolve constraints against a particular **service controller** (e.g., SDN-C).
29 * ``conductor-solver`` determines the most suitable inventory to recommend.
30 * ``conductor-reservation`` attempts to reserve the solved solution in SDN-GC
31
32 **NOTE**: There is no Command Line Interface or Python API Library at this time.
33
34 ## Pre-Flight and Pre-Installation Considerations
35
36 ### AT&T Application Identifiers and Roles
37
38 * App/Tool Name: ECOMP Conductor
39 * MOTS Application ID: 26213
40 * MechID: m04308
41 * ECOMP Feature ID: F13704
42 * PMT: 461306
43 * UAM Role Name: Conductor Production Support
44 * UAM Role id: 0000025248
45
46 ### Root
47
48 Be aware that some commands may require ``sudo``, depending on the account being used to perform the installation.
49
50 ### Proxy
51
52 If line-of-sight to internet-facing repositories is permitted and available, set the following shell environment variables if AT&T proxy services are required:
53
54 ```bash
55 $ export http_proxy="http://one.proxy.att.com:8080/"
56 $ export https_proxy="http://one.proxy.att.com:8080/"
57 ```
58
59 ### Requirements
60
61 Conductor is officially supported on [Ubuntu 14.04 LTS (Trusty Tahr)](http://releases.ubuntu.com/14.04/), though it should also work on newer releases.
62
63 Ensure the following Ubuntu packages are present, as they may not be included by default:
64
65 * [libffi-dev](http://packages.ubuntu.com/trusty/libffi-dev)
66 * [postgresql-server-dev-9.3](http://packages.ubuntu.com/trusty/postgresql-server-dev-9.3)
67 * [python2.7](http://packages.ubuntu.com/trusty/python2.7)
68
69 ``conductor-api`` may be run as-is for development and test purposes. When used in a production environment, it is recommended that ``conductor-api`` run under a multithreaded httpd service supporting [WSGI](https://www.wikipedia.org/wiki/Web_Server_Gateway_Interface), tuned as appropriate.
70
71 Configuration instructions for **apache2 httpd** and **nginx** are included herein. Respective package requirements are:
72
73 * [apache2](http://packages.ubuntu.com/trusty/apache2) and [libapache2-mod-wsgi](http://packages.ubuntu.com/trusty/libapache2-mod-wsgi)
74 * [nginx](http://packages.ubuntu.com/trusty/nginx) and [uwsgi](http://packages.ubuntu.com/trusty/uwsgi)
75
76 All Conductor services use AT&T [Music](https://github.com/att/music) for data storage/persistence and/or as a RPC transport mechanism. Consult the [Music Local Installation Guide](https://github.com/att/music/blob/master/README.md) for installation/configuration steps.
77
78 ### Networking
79
80 All conductor services require line-of-sight access to all Music servers/ports.
81
82 The ``conductor-api`` service uses TCP port 8091.
83
84 ### Security
85
86 ``conductor-api`` is accessed via HTTP. SSL/TLS certificates and AuthN/AuthZ (e.g., AAF) are not supported at this time.
87
88 Conductor makes use of plugins that act as gateways to *inventory providers* and *service controllers*. At present, two plugins are supported out-of-the-box: **A&AI** and **SDN-C**, respectively.
89
90 A&AI requires two-way SSL/TLS. Certificates must be registered and whitelisted with A&AI. SDN-C uses HTTP Basic Authentication. Consult with each respective service for official information on how to obtain access.
91
92 ### Storage
93
94 For a cloud environment in particular, it may be desirable to use a separate block storage device (e.g., an OpenStack Cinder volume) for logs, configuration, and other data persistence. In this way, it becomes a trivial matter to replace the entire VM if necessary, followed by reinstallation of the app and any supplemental configuration. Take this into consideration when setting various Conductor config options.
95
96 ### Python Virtual Environments
97
98 At present, Conductor installation is only supported at the (upstream) python package level and not the (downstream) Ubuntu distribution or SWM package levels.
99
100 To mitigate/eliminate the risk of introducing conflicts with other python applications or Ubuntu/SWM package dependencies, consider installing Conductor in a [python virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/) (or *venv* for short).
101
102 Example venv-aware WSGI app configurations, sysvinit scripts, and upstart scripts can be found in the Conductor repository under [examples](/examples/).
103
104 ### Python Package Dependencies
105
106 Conductor is installed using the python ``pip`` command. ``pip`` uses a python project's [requirements manifest](/requirements.txt) to install all python module dependencies.
107
108 **NOTE**: When line-of-sight access to a PyPI-compatible package index is not available, advance installation of Conductor's python package dependencies is required *before* installation.
109
110 ### Other Production Environment Considerations
111
112 TBD. ``:)``
113
114 Over time, considerations may include services such as:
115
116 * AAF
117 * AppMetrics
118 * Introscope
119 * Nagios
120 * Splunk
121 * UAM
122
123 ## Installation and Configuration
124
125 **IMPORTANT**: Perform the steps in this section after *optionally* configuring and activating a python virtual environment.
126
127 ### Installing From a PyPI Repository
128
129 In ONAP, the ``conductor`` package can be found on ````.
130
131 Installation is via the ``pip`` command. Here is an example ``pip.conf`` file that uses both the internet and intranet-facing PyPI repositories:
132
133 ```ini
134 [global]
135 index = https://pypi.python.org/pypi
136 index-url = https://pypi.python.org/simple
137 extra-index-url = 
138 trusted-host = 
139 ```
140
141 Once the configuration is in place, installation is simple:
142
143 ```bash
144 $ pip install of-has
145 ```
146
147 To upgrade or downgrade, simply re-run ``pip install`` using the appropriate ``pip`` command line options.
148
149 **NOTE**: Be sure proxy settings are in place if they're required to access ``pypi.python.org``.
150
151 ### Installing From Source
152
153 Conductor source in ONAP is maintained in https://gerrit.onap.org/r/optf/has.
154
155 Clone the git repository, and then install from within the ``conductor`` directory:
156
157 ```bash
158 $ git clone https://gerrit.onap.org/r/optf/has
159 Cloning into 'conductor'...
160 remote: Counting objects: 2291, done.
161 remote: Compressing objects:  88% (1918/2179)   
162 remote: Compressing objects: 100% (2179/2179), done.
163 remote: Total 2291 (delta 1422), reused 0 (delta 0)
164 Receiving objects: 100% (2291/2291), 477.59 KiB | 0 bytes/s, done.
165 Resolving deltas: 100% (1422/1422), done.
166 $ cd conductor
167 $ pip install .
168 ```
169
170 The latest source can be pulled from ONAP at any time and reinstalled:
171
172 ```bash
173 $ git pull
174 $ pip install .
175 ```
176
177 ### Verifying Installation
178
179 Each of the five Conductor services may be invoked with the ``--help`` option:
180
181 ```bash
182 $ conductor-api -- --help
183 $ conductor-controller --help
184 $ conductor-data --help
185 $ conductor-solver --help
186 $ conductor-reservation --help
187 ```
188
189 **NOTE**: The ``conductor-api`` command is deliberate. ``--`` is used as as separator between the arguments used to start the WSGI server and the arguments passed to the WSGI application.
190
191 ## Post-Flight and Post-Installation Considerations
192
193 ### User and Group
194
195 It's good practice to create an unprivileged account (e.g., a user/group named ``conductor``) and run all Conductor services as that user:
196
197 ```bash
198 $ sudo addgroup --system conductor 
199 $ sudo adduser --system --home /var/lib/conductor --ingroup conductor --no-create-home --shell /bin/false conductor
200 ```
201
202 ### SSL/TLS Certificates
203  
204 The A&AI Inventory Provider Plugin requiries two-way SSL/TLS. After provisioning a certificate per A&AI guidelines, it will be necessary to securely install the certificate, key, and certificate authority bundle.
205
206 When running conductor services as ``conductor:conductor`` (recommended), consider co-locating all of these files under the configuration directory. For example, when using ``/etc/conductor``:
207
208 ```bash
209 $ # Certificate files (crt extension, 644 permissions)
210 $ sudo mkdir /etc/conductor/ssl/certs
211 $ # Private Certificate Key files (key extension, 640 permissions)
212 $ sudo mkdir /etc/conductor/ssl/private
213 $ # Certificate Authority (CA) Bundles (crt extension, 644 permissions)
214 $ sudo mkdir /etc/conductor/ssl/ca-certificates
215 $ # Add files to newly created directories, then set ownership
216 $ sudo chmod -R conductor:conductor /etc/conductor/ssl
217 ```
218
219 For a hypothetical domain name ``imacculate.client.research.att.com``, example filenames could be as follows:
220
221 ```bash
222 $ find ssl -type f -printf '%M %u:%g %f\n'
223 -rw-r----- conductor:conductor imacculate.client.research.att.com.key
224 -rw-r--r-- conductor:conductor Symantec_Class_3_Secure_Server_CA.crt
225 -rw-r--r-- conductor:conductor imacculate.client.research.att.com.crt
226 ```
227
228 When running conductor services as ``root``, consider these existing Ubuntu filesystem locations for SSL/TLS files:
229
230 **Certificate** files (``crt`` extension) are typically stored in ``/etc/ssl/certs`` with ``root:root`` ownership and 644 permissions.
231
232 **Private Certificate Key** files (``key`` extension) are typically stored in ``/etc/ssl/private`` with ``root:root`` ownership and 640 permissions.
233
234 **Certificate Authority (CA) Bundles** (``crt`` extension) are typically stored in ``/usr/share/ca-certificates/conductor`` with ``root:root`` ownership, and 644 permissions. These Bundle files are then symlinked within ``/etc/ssl/certs`` using equivalent filenames, a ``pem`` extension, and ``root:root`` ownership.
235
236 **NOTE**: LUKS (Linux Unified Key Setup) is not supported by Conductor at this time.
237
238 ### Configuration
239
240 Configuration files are located in ``etc/conductor`` relative to the python environment Conductor is installed in.
241
242 To generate a sample configuration file, change to the directory just above where ``etc/conductor`` is located (e.g., `/` for the default environment, or the virtual environment root directory). Then:
243
244 ```bash
245 $ oslo-config-generator --config-file=etc/conductor/conductor-config-generator.conf
246 ```
247
248 This will generate ``etc/conductor/conductor.conf.sample``.
249
250 Because the configuration directory and files will include credentials, consider removing world permissions:
251
252 ```bash
253 $ find etc/conductor -type f -exec chmod 640 {} +
254 $ find etc/conductor -type d -exec chmod 750 {} +
255 ```
256
257 The sample config may then be copied and edited. Be sure to backup any previous ``conductor.conf`` if necessary.
258
259 ```bash
260 $ cd etc/conductor
261 $ cp -p conductor.conf.sample conductor.conf
262 ```
263
264 ``conductor.conf`` is fully annotated with descriptions of all options. Defaults are included, with all options commented out. Conductor will use defaults even if an option is not present in the file. To change an option, simply uncomment it and edit its value.
265
266 With the exception of the ``DEFAULT`` section, it's best to restart the Conductor services after making any config changes. In some cases, only one particular service actually needs to be restarted. When in doubt, however, it's best to restart all of them.
267
268 A few options in particular warrant special attention:
269
270 ```
271 [DEFAULT]
272
273 # If set to true, the logging level will be set to DEBUG instead of the default
274 # INFO level. (boolean value)
275 # Note: This option can be changed without restarting.
276 #debug = false
277 ```
278
279 For more verbose logging across all Conductor services, set ``debug`` to true.
280
281 ```
282 [aai]
283                     
284 # Base URL for A&AI, up to and not including the version, and without a
285 # trailing slash. (string value)
286 #server_url = https://controller:8443/aai
287
288 # SSL/TLS certificate file in pem format. This certificate must be registered
289 # with the A&AI endpoint. (string value)
290 #certificate_file = certificate.pem
291
292 # Private Certificate Key file in pem format. (string value)
293 #certificate_key_file = certificate_key.pem
294
295 # Certificate Authority Bundle file in pem format. Must contain the appropriate
296 # trust chain for the Certificate file. (string value)
297 #certificate_authority_bundle_file = certificate_authority_bundle.pem
298 ```
299
300 Set ``server_url`` to the A&AI server URL, to but not including the version, omitting any trailing slash. Conductor supports A&AI API v9 at a minimum.
301
302 Set the ``certificate`` prefixed keys to the appropriate SSL/TLS-related files.
303
304 **IMPORTANT**: The A&AI server may have a mismatched host/domain name and SSL/TLS certificate. In such cases, certificate verification will fail. To mitigate this, ``certificate_authority_bundle_file`` may be set to an empty value. While Conductor normally requires a CA Bundle (otherwise why bother using SSL/TLS), this requirement has been temporarily relaxed so that development and testing may continue.
305
306 ```
307 [messaging_server]
308
309 # Log debug messages. Default value is False. (boolean value)
310 #debug = false
311 ```
312
313 When the ``DEFAULT`` section's ``debug`` option is ``true``, set this section's ``debug`` option to ``true`` to enable detailed Conductor-side RPC-over-Music debug messages.
314
315 Be aware, it is voluminous. "You have been warned." ``:)``
316
317 ```
318 [music_api]
319
320 # List of hostnames (round-robin access) (list value)
321 #hostnames = localhost
322
323 # Log debug messages. Default value is False. (boolean value)
324 #debug = false
325 ```
326
327 Set ``hostnames`` to match wherever the Music REST API is being hosted (wherever Apache Tomcat and ``MUSIC.war`` are located).
328
329 When the ``DEFAULT`` section's ``debug`` option is ``true``, set this section's ``debug`` option to ``true`` to enable detailed Conductor-side MUSIC API debug messages.
330
331 The previous comment around the volume of log lines applies even more so here. (Srsly. We're not kidding.)
332
333 **IMPORTANT**: Conductor does not presently use Music's atomic consistency features due to concern around lock creation/acquisition. Instead, Conductor uses eventual consistency. For this reason, consistency issues may occur when using Music in a multi-server, High Availability configuration.
334
335 ```
336 [sdnc]
337
338 # Base URL for SDN-C. (string value)
339 #server_url = https://controller:8443/restconf
340
341 # Basic Authentication Username (string value)
342 #username = <None>
343
344 # Basic Authentication Password (string value)
345 #password = <None>
346
347 ```
348
349 Set ``server_url`` to the SDN-C server URL, omitting any trailing slash.
350
351 Set ``username`` and ``password`` to the appropriate values as directed by SDN-C.
352
353 ### Running for the First Time
354
355 Each Conductor component may be run interactively. In this case, the user does not necessarily matter.
356
357 When running interactively, it is suggested to run each command in a separate terminal session and in the following order:
358
359 ```bash
360 conductor-data --config-file=/etc/conductor/conductor.conf
361 conductor-controller --config-file=/etc/conductor/conductor.conf
362 conductor-solver --config-file=/etc/conductor/conductor.conf
363 conductor-reservation --config-file=/etc/conductor/conductor.conf
364 conductor-api --port=8091 -- --config-file=/etc/conductor/conductor.conf
365 ```
366
367 Optionally, use an application like [screen](http://packages.ubuntu.com/trusty/screen) to nest all five terminal sessions within one detachable session. (This is also the same package used by [DevStack](https://docs.openstack.org/developer/devstack/).)
368
369 To verify that ``conductor-api`` can be reached, browse to ``http://HOST:8091/``, where HOST is the hostname ``conductor-api`` is running on. No AuthN/AuthZ is required at this time. Depending on network considerations, it may be necessary to use a command like ``wget`` instead of a desktop browser.
370
371 The response should look similar to:
372
373 ```json
374 {
375   "versions": {
376     "values": [
377       {
378         "status": "development",
379         "updated": "2016-11-01T00:00:00Z",
380         "media-types": [
381           {
382             "base": "application/json",
383             "type": "application/vnd.ecomp.homing-v1+json"
384           }
385         ],
386         "id": "v1",
387         "links": [
388           {
389             "href": "http://127.0.0.1:8091/v1",
390             "rel": "self"
391           },
392           {
393             "href": "http://conductor.research.att.com/",
394             "type": "text/html",
395             "rel": "describedby"
396           }
397         ]
398       }
399     ]
400   }
401 }
402 ```
403
404 ### Sample API Calls and Homing Templates
405
406 A [Postman](http://getpostman.com/) collection illustrating sample requests is available upon request. The collection will also be added in a future revision.
407  
408 [Sample homing templates](/doc/examples/README.md) are also available.
409
410 ### Ubuntu Service Scripts
411
412 Ubuntu sysvinit (init.d) and upstart (init) scripts are typically installed at the Ubuntu package level. Since there is no such packaging at this time, example scripts have been provided in the repository.
413
414 To install, place all Conductor [sysvinit scripts](/examples/distribution/ubuntu/init.d) in ``/etc/init.d``, and all [upstart scripts](/examples/distribution/ubuntu/init) in ``/etc/init``.
415
416 Set file permissions:
417
418 ```bash
419 $ sudo chmod 644 /etc/init/conductor*
420 $ sudo chmod 755 /etc/init.d/conductor*
421 ```
422
423 If a python virtual environment is being used, edit each ``/etc/init/conductor*`` and ``/etc/init.d/conductor*`` prefixed file so that ``PYTHON_HOME`` is set to the python virtual environment root directory.
424
425 Next, enable the scripts:
426
427 ```bash
428 $ sudo update-rc.d conductor-api defaults
429 $ sudo update-rc.d conductor-controller defaults
430 $ sudo update-rc.d conductor-data defaults
431 $ sudo update-rc.d conductor-solver defaults
432 $ sudo update-rc.d conductor-reservation defaults
433 $ sudo initctl reload-configuration
434 ```
435
436 Conductor components may now be started/stopped like any other Ubuntu service, for example:
437
438 ```bash
439 $ sudo service conductor-api start
440 $ sudo service conductor-api status
441 $ sudo service conductor-api restart
442 $ sudo service conductor-api stop
443 ```
444
445 Conductor service scripts automatically create directories for ``log``, ``lock``, ``run``, ``lib``, and ``log`` files, e.g., ``/var/log/conductor`` and so on.
446
447 ### Log File Rotation
448
449 Sample ``logrotate.d`` configuration files have been provided in the repository.
450
451 To install, place all Conductor [logrotate files](/examples/distribution/ubuntu/logrotate.d) in ``/etc/logrotate.d``.
452
453 Set file ownership and permissions:
454
455 ```bash
456 $ sudo chown root:root /etc/logrotate.d/conductor*
457 $ sudo chmod 644 /etc/logrotate.d/conductor*
458 ```
459
460 ``logrotate.d`` automatically recognizes new files at the next log rotation opportunity and does not require restarting.
461
462 ## Running conductor-api Under apache2 httpd and mod_wsgi
463
464 Sample configuration files have been provided in the repository.
465
466 These instructions presume a ``conductor`` user exists. See the **Service Scripts** section for details.
467
468 First, set up a few directories:
469
470 ```bash
471 $ sudo mkdir -p /var/www/conductor
472 $ sudo mkdir /var/log/apache2/conductor
473 ```
474
475 To install, place the Conductor [WSGI application file](/conductor/api/app.wsgi) in ``/var/www/conductor``.
476
477 Set the owner/group of both directories/files to ``conductor``:
478
479 ```bash
480 $ sudo chown -R conductor:conductor /var/log/apache2/conductor /var/www/conductor
481 ```
482
483 Next, place the Conductor [apache2 httpd site config file](/examples/apache2/conductor.conf) in ``/etc/apache2/sites-available``.
484
485 Set the owner/group to ``root``:
486
487 ```bash
488 $ sudo chown -R root:root /etc/apache2/sites-available/conductor.conf
489 ```
490
491 If Conductor was installed in a python virtual environment, append ``python-home=VENV`` to ``WSGIDaemonProcess``, where ``VENV`` is the python virtual environment root directory.
492
493 **IMPORTANT**: Before proceeding, disable the ``conductor-api`` sysvinit and upstart services, as the REST API will now be handled by apache2 httpd. Otherwise there will be a port conflict, and you will be sad.
494
495 Enable the Conductor site, ensure the configuration syntax is valid, and gracefully restart apache2 httpd. 
496
497 ```bash
498 $ sudo a2ensite conductor
499 $ sudo apachectl -t
500 Syntax OK
501 $ sudo apachectl graceful
502 ```
503
504 To disable the Conductor site, run ``sudo a2dissite conductor``, then gracefully restart once again. Optionally, re-enable the ``conductor-api`` sysvinit and upstart services.
505
506 ## Running conductor-api Under nginx and uWSGI
507
508 Sample configuration files have been provided in the repository.
509
510 These instructions presume a ``conductor`` user exists. See the **Service Scripts** section for details.
511
512 To install, place the Conductor [nginx config files](/examples/nginx/) and [WSGI application file](/conductor/api/app.wsgi) in ``/etc/nginx`` (taking care to backup any prior configuration files). It may be desirable to incorporate Conductor's ``nginx.conf`` into the existing config.
513
514 Rename ``app.wsgi`` to ``conductor.wsgi``:
515
516 ```bash
517 $ cd /etc/nginx
518 $ sudo mv app.wsgi conductor.wsgi
519 ```
520
521 In ``nginx.conf``, set ``CONDUCTOR_API_FQDN`` to the server name.
522
523 **IMPORTANT**: Before proceeding, disable the ``conductor-api`` sysvinit and upstart services, as the REST API will now be handled by nginx. Otherwise there will be a port conflict, and you will be sad.
524
525 Restart nginx:
526
527 ```bash
528 $ sudo service nginx restart
529 ```
530
531 Then, run ``conductor-api`` under nginx  using uWSGI:
532
533 ```bash
534 $ sudo uwsgi -s /tmp/uwsgi.sock --chmod-socket=777 --wsgi-file /etc/nginx/conductor.wsgi --callable application --set port=8091
535 ```
536
537 To use a python virtual environment, add ``--venv VENV`` to the ``uwsgi`` command, where ``VENV`` is the python virtual environment root directory.
538
539 ## Uninstallation
540
541 Activate a virtual environment (venv) first, if necessary, then uninstall with:
542
543 ```bash
544 $ pip uninstall ecomp-conductor
545 ```
546
547 Remove any previously made configuration file changes, user accounts, Ubuntu/SWM packages, and other settings as needed.
548
549 ## Bug Reporting and Feedback
550
551 ... is encouraged. Please raise an issue at: https://jira.onap.org/projects/OPTFRA/summary