f6a5d23ae3648fceef21584f584b9d8468a6f125
[policy/parent.git] / docs / apex / APEX-User-Manual.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3
4
5 APEX User Manual
6 ****************
7
8 .. contents::
9     :depth: 3
10
11 Installation
12 ^^^^^^^^^^^^
13
14 Requirements
15 ------------
16
17             .. container:: paragraph
18
19                APEX is 100% written in Java and runs on any platform
20                that supports a JVM, e.g. Windows, Unix, Cygwin. Some
21                APEX applications (such as the monitoring application)
22                come as web archives, they do require a war-capable web
23                server installed.
24
25 Installation Requirements
26 #########################
27
28                .. container:: ulist
29
30                   -  Downloaded distribution: JAVA runtime environment
31                      (JRE, Java 11 or later, APEX is tested with the
32                      OpenJDK Java)
33
34                   -  Building from source: JAVA development kit (JDK,
35                      Java 11 or later, APEX is tested with the OpenJDK
36                      Java)
37
38                   -  A web archive capable webserver, for instance for
39                      the monitoring application
40
41                      .. container:: ulist
42
43                         -  for instance `Apache
44                            Tomcat <https://tomcat.apache.org/>`__
45
46                   -  Sufficient rights to install APEX on the system
47
48                   -  Installation tools depending on the installation
49                      method used:
50
51                      .. container:: ulist
52
53                         -  ZIP to extract from a ZIP distribution
54
55                            .. container:: ulist
56
57                               -  Windows for instance
58                                  `7Zip <http://www.7-zip.org/>`__
59
60                         -  TAR and GZ to extract from that TAR.GZ
61                            distribution
62
63                            .. container:: ulist
64
65                               -  Windows for instance
66                                  `7Zip <http://www.7-zip.org/>`__
67
68                         -  DPKG to install from the DEB distribution
69
70                            .. container:: ulist
71
72                               -  Install: ``sudo apt-get install dpkg``
73
74 Feature Requirements
75 ####################
76
77                .. container:: paragraph
78
79                   APEX supports a number of features that require extra
80                   software being installed.
81
82                .. container:: ulist
83
84                   -  `Apache Kafka <https://kafka.apache.org/>`__ to
85                      connect APEX to a Kafka message bus
86
87                   -  `Hazelcast <https://hazelcast.com/>`__ to use
88                      distributed hash maps for context
89
90                   -  `Infinispan <http://infinispan.org/>`__ for
91                      distributed context and persistence
92
93                   -  `Docker <https://www.docker.com/>`__ to run APEX
94                      inside a Docker container
95
96 Build (Install from Source) Requirements
97 ########################################
98
99                .. container:: paragraph
100
101                   Installation from source requires a few development
102                   tools
103
104                .. container:: ulist
105
106                   -  GIT to retrieve the source code
107
108                   -  Java SDK, Java version 8 or later
109
110                   -  Apache Maven 3 (the APEX build environment)
111
112 Get the APEX Source Code
113 ------------------------
114
115             .. container:: paragraph
116
117                The first APEX source code was hosted on Github in
118                January 2018. By the end of 2018, APEX was added as a
119                project in the ONAP Policy Framework, released later in
120                the ONAP Casablanca release.
121
122             .. container:: paragraph
123
124                The APEX source code is hosted in ONAP as project APEX.
125                The current stable version is in the master branch.
126                Simply clone the master branch from ONAP using HTTPS.
127
128             .. container:: listingblock
129
130                .. container:: content
131
132                   .. code::
133                      :number-lines:
134
135                      git clone https://gerrit.onap.org/r/policy/apex-pdp
136
137 Build APEX
138 ----------
139
140    .. container:: paragraph
141
142       The examples in this document assume that the APEX source
143       repositories are cloned to:
144
145    .. container:: ulist
146
147       -  Unix, Cygwin: ``/usr/local/src/apex-pdp``
148
149       -  Windows: ``C:\dev\apex-pdp``
150
151       -  Cygwin: ``/cygdrive/c/dev/apex-pdp``
152
153    .. important::
154       A Build requires ONAP Nexus
155       APEX has a dependency to ONAP parent projects. You might need to adjust your Maven M2 settings. The most current
156       settings can be found in the ONAP oparent repo: `Settings <https://git.onap.org/oparent/plain/settings.xml>`__.
157
158    .. important::
159       A Build needs Space
160       Building APEX requires approximately 2-3 GB of hard disc space, 1 GB for the actual build with full
161       distribution and 1-2 GB for the downloaded dependencies
162
163    .. important::
164       A Build requires Internet (for first build)
165       During the build, several (a lot) of Maven dependencies will be downloaded and stored in the configured local Maven
166       repository. The first standard build (and any first specific build) requires Internet access to download those
167       dependencies.
168
169    .. container:: paragraph
170
171       Use Maven to for a standard build without any tests.
172
173       +-------------------------------------------------------+--------------------------------------------------------+
174       | Unix, Cygwin                                          | Windows                                                |
175       +=======================================================+========================================================+
176       | .. container::                                        | .. container::                                         |
177       |                                                       |                                                        |
178       |    .. container:: content                             |    .. container:: content                              |
179       |                                                       |                                                        |
180       |       .. code::                                       |       .. code::                                        |
181       |         :number-lines:                                |         :number-lines:                                 |
182       |                                                       |                                                        |
183       |         # cd /usr/local/src/apex-pdp                  |          >c:                                           |
184       |         # mvn clean install -Pdocker -DskipTests      |          >cd \dev\apex                                 |
185       |                                                       |          >mvn clean install -Pdocker -DskipTests       |
186       +-------------------------------------------------------+--------------------------------------------------------+
187
188 .. container:: paragraph
189
190    The build takes 2-3 minutes on a standard development laptop. It
191    should run through without errors, but with a lot of messages from
192    the build process.
193
194 .. container:: paragraph
195
196    When Maven is finished with the build, the final screen should look
197    similar to this (omitting some ``success`` lines):
198
199 .. container:: listingblock
200
201    .. container:: content
202
203       .. code::
204         :number-lines:
205
206         [INFO] tools .............................................. SUCCESS [  0.248 s]
207         [INFO] tools-common ....................................... SUCCESS [  0.784 s]
208         [INFO] simple-wsclient .................................... SUCCESS [  3.303 s]
209         [INFO] model-generator .................................... SUCCESS [  0.644 s]
210         [INFO] packages ........................................... SUCCESS [  0.336 s]
211         [INFO] apex-pdp-package-full .............................. SUCCESS [01:10 min]
212         [INFO] Policy APEX PDP - Docker build 2.0.0-SNAPSHOT ...... SUCCESS [ 10.307 s]
213         [INFO] ------------------------------------------------------------------------
214         [INFO] BUILD SUCCESS
215         [INFO] ------------------------------------------------------------------------
216         [INFO] Total time: 03:43 min
217         [INFO] Finished at: 2018-09-03T11:56:01+01:00
218         [INFO] ------------------------------------------------------------------------
219
220 .. container:: paragraph
221
222    The build will have created all artifacts required for an APEX
223    installation. The following example show how to change to the target
224    directory and how it should look like.
225
226 +----------------------------------------------------------------------------------------------------------------+
227 | Unix, Cygwin                                                                                                   |
228 +================================================================================================================+
229 | .. container::                                                                                                 |
230 |                                                                                                                |
231 | .. container:: listingblock                                                                                    |
232 |                                                                                                                |
233 | .. container:: content                                                                                         |
234 |                                                                                                                |
235 | .. code::                                                                                                      |
236 | :number-lines:                                                                                                 |
237 |                                                                                                                |
238 | -rwxrwx---+ 1 esvevan Domain Users       772 Sep  3 11:55 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes*    |
239 | -rwxrwx---+ 1 esvevan Domain Users 146328082 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT.deb*            |
240 | -rwxrwx---+ 1 esvevan Domain Users     15633 Sep  3 11:54 apex-pdp-package-full-2.0.0-SNAPSHOT.jar*            |
241 | -rwxrwx---+ 1 esvevan Domain Users 146296819 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz* |
242 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 archive-tmp/                                         |
243 | -rwxrwx---+ 1 esvevan Domain Users        89 Sep  3 11:54 checkstyle-cachefile*                                |
244 | -rwxrwx---+ 1 esvevan Domain Users     10621 Sep  3 11:54 checkstyle-checker.xml*                              |
245 | -rwxrwx---+ 1 esvevan Domain Users       584 Sep  3 11:54 checkstyle-header.txt*                               |
246 | -rwxrwx---+ 1 esvevan Domain Users        86 Sep  3 11:54 checkstyle-result.xml*                               |
247 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 classes/                                             |
248 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 dependency-maven-plugin-markers/                     |
249 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 etc/                                                 |
250 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 examples/                                            |
251 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:55 install_hierarchy/                                   |
252 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 maven-archiver/                                      |
253 +----------------------------------------------------------------------------------------------------------------+
254
255 +-----------------------------------------------------------------------------------------+
256 | Windows                                                                                 |
257 +=========================================================================================+
258 | .. container::                                                                          |
259 |                                                                                         |
260 | .. container:: listingblock                                                             |
261 |                                                                                         |
262 | .. container:: content                                                                  |
263 |                                                                                         |
264 | .. code::                                                                               |
265 | :number-lines:                                                                          |
266 |                                                                                         |
267 | 03/09/2018  11:55    <DIR>          .                                                   |
268 | 03/09/2018  11:55    <DIR>          ..                                                  |
269 | 03/09/2018  11:55       146,296,819 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz |
270 | 03/09/2018  11:55       146,328,082 apex-pdp-package-full-2.0.0-SNAPSHOT.deb            |
271 | 03/09/2018  11:54            15,633 apex-pdp-package-full-2.0.0-SNAPSHOT.jar            |
272 | 03/09/2018  11:55               772 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes    |
273 | 03/09/2018  11:54    <DIR>          archive-tmp                                         |
274 | 03/09/2018  11:54                89 checkstyle-cachefile                                |
275 | 03/09/2018  11:54            10,621 checkstyle-checker.xml                              |
276 | 03/09/2018  11:54               584 checkstyle-header.txt                               |
277 | 03/09/2018  11:54                86 checkstyle-result.xml                               |
278 | 03/09/2018  11:54    <DIR>          classes                                             |
279 | 03/09/2018  11:54    <DIR>          dependency-maven-plugin-markers                     |
280 | 03/09/2018  11:54    <DIR>          etc                                                 |
281 | 03/09/2018  11:54    <DIR>          examples                                            |
282 | 03/09/2018  11:55    <DIR>          install_hierarchy                                   |
283 | 03/09/2018  11:54    <DIR>          maven-archiver                                      |
284 | 8 File(s)    292,652,686 bytes                                                          |
285 | 9 Dir(s)  14,138,720,256 bytes free                                                     |
286 +-----------------------------------------------------------------------------------------+
287
288 Install APEX
289 ------------
290
291    .. container:: paragraph
292
293       APEX can be installed in different ways:
294
295    .. container:: ulist
296
297       -  Unix: automatically using ``dpkg`` from
298          ``.deb`` archive
299
300       -  Windows, Unix, Cygwin: manually from a ``.tar.gz`` archive
301
302       -  Windows, Unix, Cygwin: build from source using Maven, then
303          install manually
304
305 Install with DPKG
306 #################
307
308       .. container:: paragraph
309
310          You can get the APEX debian package from the
311          `ONAP Nexus Repository <https://nexus.onap.org/content/groups/public/org/onap/policy/apex-pdp/packages/apex-pdp-package-full/>`__.
312
313          The install distributions of APEX automatically install the
314          system. The installation directory is
315          ``/opt/app/policy/apex-pdp``. Log files are located in
316          ``/var/log/onap/policy/apex-pdp``. The latest APEX version will
317          be available as ``/opt/app/policy/apex-pdp/apex-pdp``.
318
319       .. container:: paragraph
320
321          For the installation, a new user ``apexuser`` and a new group
322          ``apexuser`` will be created. This user owns the installation
323          directories and the log file location. The user is also used by
324          the standard APEX start scripts to run APEX with this user’s
325          permissions.
326
327 +--------------------------------------------------------------------------+
328 | DPKG Installation                                                        |
329 +==========================================================================+
330 | .. container::                                                           |
331 |                                                                          |
332 | .. container:: listingblock                                              |
333 |                                                                          |
334 | .. container:: content                                                   |
335 |                                                                          |
336 | .. code::                                                                |
337 | :number-lines:                                                           |
338 |                                                                          |
339 | # sudo dpkg -i apex-pdp-package-full-2.0.0-SNAPSHOT.deb                  |
340 | Selecting previously unselected package apex-uservice.                   |
341 | (Reading database ... 288458 files and directories currently installed.) |
342 | Preparing to unpack apex-pdp-package-full-2.0.0-SNAPSHOT.deb ...         |
343 | ********************preinst*******************                           |
344 | arguments install                                                        |
345 | **********************************************                           |
346 | creating group apexuser . . .                                            |
347 | creating user apexuser . . .                                             |
348 | Unpacking apex-uservice (2.0.0-SNAPSHOT) ...                             |
349 | Setting up apex-uservice (2.0.0-SNAPSHOT) ...                            |
350 | ********************postinst****************                             |
351 | arguments configure                                                      |
352 | ***********************************************                          |
353 +--------------------------------------------------------------------------+
354
355 .. container:: paragraph
356
357    Once the installation is finished, APEX is fully installed and ready
358    to run.
359
360 Install Manually from Archive (Unix, Cygwin)
361 ############################################
362
363    .. container:: paragraph
364
365       You can download a ``tar.gz`` archive from the
366       `ONAP Nexus Repository <https://nexus.onap.org/content/groups/public/org/onap/policy/apex-pdp/packages/apex-pdp-package-full/>`__.
367
368       Create a directory where APEX
369       should be installed. Extract the ``tar`` archive. The following
370       example shows how to install APEX in ``/opt/apex`` and create a
371       link to ``/opt/apex/apex`` for the most recent installation.
372
373    .. container:: listingblock
374
375       .. container:: content
376
377          .. code::
378             :number-lines:
379
380             # cd /opt
381             # mkdir apex
382             # cd apex
383             # mkdir apex-full-2.0.0-SNAPSHOT
384             # tar xvfz ~/Downloads/apex-pdp-package-full-2.0.0-SNAPSHOT.tar.gz -C apex-full-2.0.0-SNAPSHOT
385             # ln -s apex apex-pdp-package-full-2.0.0-SNAPSHOT
386
387 Install Manually from Archive (Windows, 7Zip, GUI)
388 ##################################################
389
390    .. container:: paragraph
391
392       You can download a ``tar.gz`` archive from the
393       `ONAP Nexus Repository <https://nexus.onap.org/content/groups/public/org/onap/policy/apex-pdp/packages/apex-pdp-package-full/>`__.
394
395       Copy the ``tar.gz`` file into the install
396       folder (in this example ``C:\apex``). Assuming you are using 7Zip,
397       right click on the file and extract the ``tar`` archive. Note: the
398       screenshots might show an older version than you have.
399
400    .. container:: imageblock
401
402       .. container:: content
403
404          |Extract the TAR archive|
405
406    .. container:: paragraph
407
408       The right-click on the new created TAR file and extract the actual
409       APEX distribution.
410
411    .. container:: imageblock
412
413       .. container:: content
414
415          |Extract the APEX distribution|
416
417    .. container:: paragraph
418
419       Inside the new APEX folder you see the main directories: ``bin``,
420       ``etc``, ``examples``, ``lib``, and ``war``
421
422    .. container:: paragraph
423
424       Once extracted, please rename the created folder to
425       ``apex-full-2.0.0-SNAPSHOT``. This will keep the directory name in
426       line with the rest of this documentation.
427
428 Install Manually from Archive (Windows, 7Zip, CMD)
429 ##################################################
430
431    .. container:: paragraph
432
433       You can download a ``tar.gz`` archive from the
434       `ONAP Nexus Repository <https://nexus.onap.org/content/groups/public/org/onap/policy/apex-pdp/packages/apex-pdp-package-full/>`__.
435
436       Copy the ``tar.gz`` file into the install
437       folder (in this example ``C:\apex``). Start ``cmd``, for instance
438       typing ``Windows+R`` and then ``cmd`` in the dialog. Assuming
439       ``7Zip`` is installed in the standard folder, simply run the
440       following commands (for APEX version 2.0.0-SNAPSHOT full
441       distribution)
442
443    .. container:: listingblock
444
445       .. container:: content
446
447          .. code::
448            :number-lines:
449
450             >c:
451             >cd \apex
452             >"\Program Files\7-Zip\7z.exe" x apex-pdp-package-full-2.0.0-SNAPSHOT.tar.gz -so | "\Program Files\7-Zip\7z.exe" x -aoa -si -ttar -o"apex-full-2.0.0-SNAPSHOT"
453
454 .. container:: paragraph
455
456    APEX is now installed in the folder
457    ``C:\apex\apex-full-2.0.0-SNAPSHOT``.
458
459 Build from Source
460 -----------------
461
462 Build and Install Manually (Unix, Windows, Cygwin)
463 ##################################################
464
465       .. container:: paragraph
466
467          Clone the APEX GIT repositories into a directory. Go to that
468          directory. Use Maven to build APEX (all details on building
469          APEX from source can be found in *APEX HowTo: Build*). Install
470          from the created artifacts (``rpm``, ``deb``, ``tar.gz``, or
471          copying manually).
472
473       .. container:: paragraph
474
475          The following example shows how to build the APEX system,
476          without tests (``-DskipTests``) to safe some time. It assumes
477          that the APX GIT repositories are cloned to:
478
479       .. container:: ulist
480
481          -  Unix, Cygwin: ``/usr/local/src/apex``
482
483          -  Windows: ``C:\dev\apex``
484
485          +-------------------------------------------------------+--------------------------------------------------------+
486          | Unix, Cygwin                                          | Windows                                                |
487          +=======================================================+========================================================+
488          | .. container::                                        | .. container::                                         |
489          |                                                       |                                                        |
490          |    .. container:: content                             |    .. container:: content                              |
491          |                                                       |                                                        |
492          |       .. code::                                       |       .. code::                                        |
493          |         :number-lines:                                |         :number-lines:                                 |
494          |                                                       |                                                        |
495          |         # cd /usr/local/src/apex                      |         >c:                                            |
496          |         # mvn clean install -Pdocker -DskipTests      |         >cd \dev\apex                                  |
497          |                                                       |         >mvn clean install -Pdocker -DskipTests        |
498          +-------------------------------------------------------+--------------------------------------------------------+
499
500 .. container:: paragraph
501
502    The build takes about 2 minutes without test and about 4-5 minutes
503    with tests on a standard development laptop. It should run through
504    without errors, but with a lot of messages from the build process. If
505    build with tests (i.e. without ``-DskipTests``), there will be error
506    messages and stack trace prints from some tests. This is normal, as
507    long as the build finishes successful.
508
509 .. container:: paragraph
510
511    When Maven is finished with the build, the final screen should look
512    similar to this (omitting some ``success`` lines):
513
514 .. container:: listingblock
515
516    .. container:: content
517
518       .. code::
519          :number-lines:
520
521          [INFO] tools .............................................. SUCCESS [  0.248 s]
522          [INFO] tools-common ....................................... SUCCESS [  0.784 s]
523          [INFO] simple-wsclient .................................... SUCCESS [  3.303 s]
524          [INFO] model-generator .................................... SUCCESS [  0.644 s]
525          [INFO] packages ........................................... SUCCESS [  0.336 s]
526          [INFO] apex-pdp-package-full .............................. SUCCESS [01:10 min]
527          [INFO] Policy APEX PDP - Docker build 2.0.0-SNAPSHOT ...... SUCCESS [ 10.307 s]
528          [INFO] ------------------------------------------------------------------------
529          [INFO] BUILD SUCCESS
530          [INFO] ------------------------------------------------------------------------
531          [INFO] Total time: 03:43 min
532          [INFO] Finished at: 2018-09-03T11:56:01+01:00
533          [INFO] ------------------------------------------------------------------------
534
535 .. container:: paragraph
536
537    The build will have created all artifacts required for an APEX
538    installation. The following example show how to change to the target
539    directory and how it should look like.
540
541 +----------------------------------------------------------------------------------------------------------------+
542 | Unix, Cygwin                                                                                                   |
543 +================================================================================================================+
544 | .. container::                                                                                                 |
545 |                                                                                                                |
546 | .. container:: listingblock                                                                                    |
547 |                                                                                                                |
548 | .. code::                                                                                                      |
549 | :number-lines:                                                                                                 |
550 |                                                                                                                |
551 | # cd packages/apex-pdp-package-full/target                                                                     |
552 | # ls -l                                                                                                        |
553 | -rwxrwx---+ 1 esvevan Domain Users       772 Sep  3 11:55 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes*    |
554 | -rwxrwx---+ 1 esvevan Domain Users 146328082 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT.deb*            |
555 | -rwxrwx---+ 1 esvevan Domain Users     15633 Sep  3 11:54 apex-pdp-package-full-2.0.0-SNAPSHOT.jar*            |
556 | -rwxrwx---+ 1 esvevan Domain Users 146296819 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz* |
557 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 archive-tmp/                                         |
558 | -rwxrwx---+ 1 esvevan Domain Users        89 Sep  3 11:54 checkstyle-cachefile*                                |
559 | -rwxrwx---+ 1 esvevan Domain Users     10621 Sep  3 11:54 checkstyle-checker.xml*                              |
560 | -rwxrwx---+ 1 esvevan Domain Users       584 Sep  3 11:54 checkstyle-header.txt*                               |
561 | -rwxrwx---+ 1 esvevan Domain Users        86 Sep  3 11:54 checkstyle-result.xml*                               |
562 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 classes/                                             |
563 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 dependency-maven-plugin-markers/                     |
564 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 etc/                                                 |
565 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 examples/                                            |
566 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:55 install_hierarchy/                                   |
567 | drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 maven-archiver/                                      |
568 +----------------------------------------------------------------------------------------------------------------+
569
570 +-----------------------------------------------------------------------------------------+
571 | Windows                                                                                 |
572 +=========================================================================================+
573 | .. container::                                                                          |
574 |                                                                                         |
575 | .. container:: listingblock                                                             |
576 |                                                                                         |
577 | .. code::                                                                               |
578 | :number-lines:                                                                          |
579 |                                                                                         |
580 | >cd packages\apex-pdp-package-full\target                                               |
581 | >dir                                                                                    |
582 | 03/09/2018  11:55    <DIR>          .                                                   |
583 | 03/09/2018  11:55    <DIR>          ..                                                  |
584 | 03/09/2018  11:55       146,296,819 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz |
585 | 03/09/2018  11:55       146,328,082 apex-pdp-package-full-2.0.0-SNAPSHOT.deb            |
586 | 03/09/2018  11:54            15,633 apex-pdp-package-full-2.0.0-SNAPSHOT.jar            |
587 | 03/09/2018  11:55               772 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes    |
588 | 03/09/2018  11:54    <DIR>          archive-tmp                                         |
589 | 03/09/2018  11:54                89 checkstyle-cachefile                                |
590 | 03/09/2018  11:54            10,621 checkstyle-checker.xml                              |
591 | 03/09/2018  11:54               584 checkstyle-header.txt                               |
592 | 03/09/2018  11:54                86 checkstyle-result.xml                               |
593 | 03/09/2018  11:54    <DIR>          classes                                             |
594 | 03/09/2018  11:54    <DIR>          dependency-maven-plugin-markers                     |
595 | 03/09/2018  11:54    <DIR>          etc                                                 |
596 | 03/09/2018  11:54    <DIR>          examples                                            |
597 | 03/09/2018  11:55    <DIR>          install_hierarchy                                   |
598 | 03/09/2018  11:54    <DIR>          maven-archiver                                      |
599 | 8 File(s)    292,652,686 bytes                                                          |
600 | 9 Dir(s)  14,138,720,256 bytes free                                                     |
601 +-----------------------------------------------------------------------------------------+
602
603 .. container:: paragraph
604
605    Now, take the ``.deb`` or the ``.tar.gz`` file and install APEX.
606    Alternatively, copy the content of the folder ``install_hierarchy``
607    to your APEX directory.
608
609 Installation Layout
610 -------------------
611
612    .. container:: paragraph
613
614       A full installation of APEX comes with the following layout.
615
616    .. container:: listingblock
617
618       .. container:: content
619
620 ::
621
622             $APEX_HOME
623                 ├───bin             (1)
624                 ├───etc             (2)
625                 │   ├───editor
626                 │   ├───hazelcast
627                 │   ├───infinispan
628                 │   └───META-INF
629                 ├───examples            (3)
630                 │   ├───config          (4)
631                 │   ├───docker          (5)
632                 │   ├───events          (6)
633                 │   ├───html            (7)
634                 │   ├───models          (8)
635                 │   └───scripts         (9)
636                 ├───lib             (10)
637                 │   └───applications        (11)
638                 └───war             (12)
639
640    .. container:: colist arabic
641
642       +-----------------------------------+-----------------------------------+
643       | **1**                             | binaries, mainly scripts (bash    |
644       |                                   | and bat) to start the APEX engine |
645       |                                   | and applications                  |
646       +-----------------------------------+-----------------------------------+
647       | **2**                             | configuration files, such as      |
648       |                                   | logback (logging) and third party |
649       |                                   | library configurations            |
650       +-----------------------------------+-----------------------------------+
651       | **3**                             | example policy models to get      |
652       |                                   | started                           |
653       +-----------------------------------+-----------------------------------+
654       | **4**                             | configurations for the examples   |
655       |                                   | (with sub directories for         |
656       |                                   | individual examples)              |
657       +-----------------------------------+-----------------------------------+
658       | **5**                             | Docker files and additional       |
659       |                                   | Docker instructions for the       |
660       |                                   | exampples                         |
661       +-----------------------------------+-----------------------------------+
662       | **6**                             | example events for the examples   |
663       |                                   | (with sub directories for         |
664       |                                   | individual examples)              |
665       +-----------------------------------+-----------------------------------+
666       | **7**                             | HTML files for some examples,     |
667       |                                   | e.g. the Decisionmaker example    |
668       +-----------------------------------+-----------------------------------+
669       | **8**                             | the policy models, generated for  |
670       |                                   | each example (with sub            |
671       |                                   | directories for individual        |
672       |                                   | examples)                         |
673       +-----------------------------------+-----------------------------------+
674       | **9**                             | additional scripts for the        |
675       |                                   | examples (with sub directories    |
676       |                                   | for individual examples)          |
677       +-----------------------------------+-----------------------------------+
678       | **10**                            | the library folder with all Java  |
679       |                                   | JAR files                         |
680       +-----------------------------------+-----------------------------------+
681       | **11**                            | applications, also known as jar   |
682       |                                   | with dependencies (or fat jars),  |
683       |                                   | individually deployable           |
684       +-----------------------------------+-----------------------------------+
685       | **12**                            | WAR files for web applications    |
686       +-----------------------------------+-----------------------------------+
687
688 System Configuration
689 --------------------
690
691    .. container:: paragraph
692
693       Once APEX is installed, a few configurations need to be done:
694
695    .. container:: ulist
696
697       -  Create an APEX user and an APEX group (optional, if not
698          installed using RPM and DPKG)
699
700       -  Create environment settings for ``APEX_HOME`` and
701          ``APEX_USER``, required by the start scripts
702
703       -  Change settings of the logging framework (optional)
704
705       -  Create directories for logging, required (execution might fail
706          if directories do not exist or cannot be created)
707
708 APEX User and Group
709 ###################
710
711       .. container:: paragraph
712
713          On smaller installations and test systems, APEX can run as any
714          user or group.
715
716       .. container:: paragraph
717
718          However, if APEX is installed in production, we strongly
719          recommend you set up a dedicated user for running APEX. This
720          will isolate the execution of APEX to that user. We recommend
721          you use the userid ``apexuser`` but you may use any user you
722          choose.
723
724       .. container:: paragraph
725
726          The following example, for UNIX, creates a group called
727          ``apexuser``, an APEX user called ``apexuser``, adds the group
728          to the user, and changes ownership of the APEX installation to
729          the user. Substitute ``<apex-dir>`` with the directory where
730          APEX is installed.
731
732          .. container:: listingblock
733
734             .. container:: content
735
736                .. code::
737                   :number-lines:
738
739                   # sudo groupadd apexuser
740                   # sudo useradd -g apexuser apexuser
741                   # sudo chown -R apexuser:apexuser <apex-dir>
742
743 .. container:: paragraph
744
745    For other operating systems please consult your manual or system
746    administrator.
747
748 Environment Settings: APEX_HOME and APEX_USER
749 #############################################
750
751    .. container:: paragraph
752
753       The provided start scripts for APEX require two environment
754       variables being set:
755
756    .. container:: ulist
757
758       -  ``APEX_USER`` with the user under whos name and permission APEX
759          should be started (Unix only)
760
761       -  ``APEX_HOME`` with the directory where APEX is installed (Unix,
762          Windows, Cygwin)
763
764    .. container:: paragraph
765
766       The first row in the following table shows how to set these
767       environment variables temporary (assuming the user is
768       ``apexuser``). The second row shows how to verify the settings.
769       The last row explains how to set those variables permanently.
770
771    +------------------------------------------------+---------------------------------------------------------+
772    | Unix, Cygwin (bash/tcsh)                       | Windows                                                 |
773    +================================================+=========================================================+
774    | .. container::                                 | .. container::                                          |
775    |                                                |                                                         |
776    |    .. container:: content                      |    .. container:: content                               |
777    |                                                |                                                         |
778    |       .. code::                                |       .. code::                                         |
779    |          :number-lines:                        |         :number-lines:                                  |
780    |                                                |                                                         |
781    |          # export APEX_USER=apexuser           |         >set APEX_HOME=C:\apex\apex-full-2.0.0-SNAPSHOT |
782    |          # cd /opt/app/policy/apex-pdp         |                                                         |
783    |          # export APEX_HOME=`pwd`              |                                                         |
784    |                                                |                                                         |
785    +------------------------------------------------+                                                         |
786    | .. container::                                 |                                                         |
787    |                                                |                                                         |
788    |    .. container:: content                      |                                                         |
789    |                                                |                                                         |
790    |       .. code::tcsh                            |                                                         |
791    |          :number-lines:                        |                                                         |
792    |                                                |                                                         |
793    |          # setenv APEX_USER apexuser           |                                                         |
794    |          # cd /opt/app/policy/apex-pdp         |                                                         |
795    |          # setenv APEX_HOME `pwd`              |                                                         |
796    |                                                |                                                         |
797    +------------------------------------------------+---------------------------------------------------------+
798    | .. container::                                 | .. container::                                          |
799    |                                                |                                                         |
800    |    .. container:: content                      |    .. container:: content                               |
801    |                                                |                                                         |
802    |       .. code::                                |       .. code::                                         |
803    |          :number-lines:                        |          :number-lines:                                 |
804    |                                                |                                                         |
805    |          # env | grep APEX                     |          >set APEX_HOME                                 |
806    |          # APEX_USER=apexuser                  |          APEX_HOME=\apex\apex-full-2.0.0-SNAPSHOT       |
807    |          # APEX_HOME=/opt/app/policy/apex-pdp  |                                                         |
808    |                                                |                                                         |
809    +------------------------------------------------+---------------------------------------------------------+
810
811 Making Environment Settings Permanent (Unix, Cygwin)
812 ====================================================
813
814    .. container:: paragraph
815
816       For a per-user setting, edit the a user’s ``bash`` or ``tcsh``
817       settings in ``~/.bashrc`` or ``~/.tcshrc``. For system-wide
818       settings, edit ``/etc/profiles`` (requires permissions).
819
820 Making Environment Settings Permanent (Windows)
821 ===============================================
822
823    .. container:: paragraph
824
825       On Windows 7 do
826
827    .. container:: ulist
828
829       -  Click on the **Start** Menu
830
831       -  Right click on **Computer**
832
833       -  Select **Properties**
834
835    .. container:: paragraph
836
837       On Windows 8/10 do
838
839    .. container:: ulist
840
841       -  Click on the **Start** Menu
842
843       -  Select **System**
844
845    .. container:: paragraph
846
847       Then do the following
848
849    .. container:: ulist
850
851       -  Select **Advanced System Settings**
852
853       -  On the **Advanced** tab, click the **Environment Variables**
854          button
855
856       -  Edit an existing variable, or create a new System variable:
857          'Variable name'="APEX_HOME", 'Variable
858          value'="C:\apex\apex-full-2.0.0-SNAPSHOT"
859
860    .. container:: paragraph
861
862       For the settings to take effect, an application needs to be
863       restarted (e.g. any open ``cmd`` window).
864
865 Edit the APEX Logging Settings
866 ##############################
867
868    .. container:: paragraph
869
870       Configure the APEX logging settings to your requirements, for
871       instance:
872
873    .. container:: ulist
874
875       -  change the directory where logs are written to, or
876
877       -  change the log levels
878
879    .. container:: paragraph
880
881       Edit the file ``$APEX_HOME/etc/logback.xml`` for any required
882       changes. To change the log directory change the line
883
884    .. container:: paragraph
885
886       ``<property name="logDir" value="/var/log/onap/policy/apex-pdp/" />``
887
888    .. container:: paragraph
889
890       to
891
892    .. container:: paragraph
893
894       ``<property name="logDir" value="/PATH/TO/LOG/DIRECTORY/" />``
895
896    .. container:: paragraph
897
898       On Windows, it is recommended to change the log directory to:
899
900    .. container:: paragraph
901
902       ``<property name="logDir" value="C:/apex/apex-full-2.0.0-SNAPSHOT/logs" />``
903
904    .. container:: paragraph
905
906       Note: Be careful about when to use ``\`` vs. ``/`` as the path
907       separator!
908
909 Create Directories for Logging
910 ##############################
911
912    .. container:: paragraph
913
914       Make sure that the log directory exists. This is important when
915       APEX was installed manually or when the log directory was changed
916       in the settings (see above).
917
918    +-----------------------------------------------------------------------+-------------------------------------------------------+
919    | Unix, Cygwin                                                          | Windows                                               |
920    +=======================================================================+=======================================================+
921    | .. container::                                                        | .. container::                                        |
922    |                                                                       |                                                       |
923    |    .. container:: content                                             |    .. container:: content                             |
924    |                                                                       |                                                       |
925    |       .. code::                                                       |       .. code::                                       |
926    |         :number-lines:                                                |         :number-lines:                                |
927    |                                                                       |                                                       |
928    |         sudo mkdir -p /var/log/onap/policy/apex-pdp                   |         >mkdir C:\apex\apex-full-2.0.0-SNAPSHOT\logs  |
929    |         sudo chown -R apexuser:apexuser /var/log/onap/policy/apex-pdp |                                                       |
930    +-----------------------------------------------------------------------+-------------------------------------------------------+
931
932 Verify the APEX Installation
933 ----------------------------
934
935    .. container:: paragraph
936
937       When APEX is installed and all settings are realized, the
938       installation can be verified.
939
940 Verify Installation - run Engine
941 ################################
942
943       .. container:: paragraph
944
945          A simple verification of an APEX installation can be done by
946          simply starting the APEX engine without specifying a tosca policy. On
947          Unix (or Cygwin) start the engine using
948          ``$APEX_HOME/bin/apexApps.sh engine``. On Windows start the engine
949          using ``%APEX_HOME%\bin\apexApps.bat engine``. The engine will fail
950          to fully start. However, if the output looks similar to the
951          following line, the APEX installation is realized.
952
953       .. container:: listingblock
954
955          .. container:: content
956
957             .. code::
958                :number-lines:
959
960                Starting Apex service with parameters [] . . .
961                start of Apex service failed.
962                org.onap.policy.apex.model.basicmodel.concepts.ApexException: Arguments validation failed.
963                 at org.onap.policy.apex.service.engine.main.ApexMain.populateApexParameters(ApexMain.java:238)
964                 at org.onap.policy.apex.service.engine.main.ApexMain.<init>(ApexMain.java:86)
965                 at org.onap.policy.apex.service.engine.main.ApexMain.main(ApexMain.java:351)
966                Caused by: org.onap.policy.apex.model.basicmodel.concepts.ApexException: Tosca Policy file was not specified as an argument
967                 at org.onap.policy.apex.service.engine.main.ApexCommandLineArguments.validateReadableFile(ApexCommandLineArguments.java:242)
968                 at org.onap.policy.apex.service.engine.main.ApexCommandLineArguments.validate(ApexCommandLineArguments.java:172)
969                 at org.onap.policy.apex.service.engine.main.ApexMain.populateApexParameters(ApexMain.java:235)
970                 ... 2 common frames omitted
971
972 Verify Installation - run an Example
973 ####################################
974
975    .. container:: paragraph
976
977       A full APEX installation comes with several examples. Here, we can
978       fully verify the installation by running one of the examples.
979
980    .. container:: paragraph
981
982       We use the example called *SampleDomain* and configure the engine
983       to use standard in and standard out for events. Run the engine
984       with the provided configuration. Note: Cygwin executes scripts as
985       Unix scripts but runs Java as a Windows application, thus the
986       configuration file must be given as a Windows path.
987
988    .. container:: paragraph
989
990       On Unix/Linux flavoured platforms, give the commands below:
991
992    .. container:: listingblock
993
994       .. container:: content
995
996         .. code::
997          :number-lines:
998
999           sudo su - apexuser
1000           export APEX_HOME <path to apex installation>
1001           export APEX_USER apexuser
1002
1003    .. container:: paragraph
1004
1005          Create a Tosca Policy for the SampleDomain example using ApexCliToscaEditor
1006          as explained in the section "The APEX CLI Tosca Editor". Assume the tosca policy name is SampleDomain_tosca.json.
1007          You can then try to run apex using the ToscaPolicy.
1008
1009    .. container:: listingblock
1010
1011       .. container:: content
1012
1013         .. code::
1014          :number-lines:
1015
1016           # $APEX_HOME/bin/apexApps.sh engine -p $APEX_HOME/examples/SampleDomain_tosca.json (1)
1017           >%APEX_HOME%\bin\apexApps.bat engine -p %APEX_HOME%\examples\SampleDomain_tosca.json(2)
1018
1019 .. container:: colist arabic
1020
1021    +-------+---------+
1022    | **1** | UNIX    |
1023    +-------+---------+
1024    | **2** | Windows |
1025    +-------+---------+
1026
1027 .. container:: paragraph
1028
1029    The engine should start successfully. Assuming the logging levels are set to ``info`` in the built system, the output
1030    should look similar to this (last few lines)
1031
1032 .. container:: listingblock
1033
1034    .. container:: content
1035
1036       .. code::
1037          :number-lines:
1038
1039          Starting Apex service with parameters [-p, /home/ubuntu/apex/SampleDomain_tosca.json] . . .
1040          2018-09-05 15:16:42,800 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Created apex engine MyApexEngine-0:0.0.1 .
1041          2018-09-05 15:16:42,804 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Created apex engine MyApexEngine-1:0.0.1 .
1042          2018-09-05 15:16:42,804 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Created apex engine MyApexEngine-2:0.0.1 .
1043          2018-09-05 15:16:42,805 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Created apex engine MyApexEngine-3:0.0.1 .
1044          2018-09-05 15:16:42,805 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - APEX service created.
1045          2018-09-05 15:16:43,962 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging starting . . .
1046          2018-09-05 15:16:43,963 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging started
1047          2018-09-05 15:16:44,987 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Registering apex model on engine MyApexEngine-0:0.0.1
1048          2018-09-05 15:16:45,112 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Registering apex model on engine MyApexEngine-1:0.0.1
1049          2018-09-05 15:16:45,113 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Registering apex model on engine MyApexEngine-2:0.0.1
1050          2018-09-05 15:16:45,113 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Registering apex model on engine MyApexEngine-3:0.0.1
1051          2018-09-05 15:16:45,120 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - Added the action listener to the engine
1052          Started Apex service
1053
1054 .. container:: paragraph
1055
1056    Important are the last two line, stating that APEX has added the
1057    final action listener to the engine and that the engine is started.
1058
1059 .. container:: paragraph
1060
1061    The engine is configured to read events from standard input and write
1062    produced events to standard output. The policy model is a very simple
1063    policy.
1064
1065 .. container:: paragraph
1066
1067    The following table shows an input event in the left column and an
1068    output event in the right column. Past the input event into the
1069    console where APEX is running, and the output event should appear in
1070    the console. Pasting the input event multiple times will produce
1071    output events with different values.
1072
1073 +----------------------------------------------------+----------------------------------------------------+
1074 | Input Event                                        | Example Output Event                               |
1075 +====================================================+====================================================+
1076 | .. container::                                     | .. container::                                     |
1077 |                                                    |                                                    |
1078 | .. container:: content                             | .. container:: content                             |
1079 |                                                    |                                                    |
1080 | .. code::                                          | .. code::                                          |
1081 | :number-lines:                                     | :number-lines:                                     |
1082 |                                                    |                                                    |
1083 | {                                                  | {                                                  |
1084 | "nameSpace": "org.onap.policy.apex.sample.events", | "name": "Event0004",                               |
1085 | "name": "Event0000",                               | "version": "0.0.1",                                |
1086 | "version": "0.0.1",                                | "nameSpace": "org.onap.policy.apex.sample.events", |
1087 | "source": "test",                                  | "source": "Act",                                   |
1088 | "target": "apex",                                  | "target": "Outside",                               |
1089 | "TestSlogan": "Test slogan for External Event0",   | "TestActCaseSelected": 2,                          |
1090 | "TestMatchCase": 0,                                | "TestActStateTime": 1536157104627,                 |
1091 | "TestTimestamp": 1469781869269,                    | "TestDecideCaseSelected": 0,                       |
1092 | "TestTemperature": 9080.866                        | "TestDecideStateTime": 1536157104625,              |
1093 | }                                                  | "TestEstablishCaseSelected": 0,                    |
1094 |                                                    | "TestEstablishStateTime": 1536157104623,           |
1095 |                                                    | "TestMatchCase": 0,                                |
1096 |                                                    | "TestMatchCaseSelected": 1,                        |
1097 |                                                    | "TestMatchStateTime": 1536157104620,               |
1098 |                                                    | "TestSlogan": "Test slogan for External Event0",   |
1099 |                                                    | "TestTemperature": 9080.866,                       |
1100 |                                                    | "TestTimestamp": 1469781869269                     |
1101 |                                                    | }                                                  |
1102 +----------------------------------------------------+----------------------------------------------------+
1103
1104 .. container:: paragraph
1105
1106    Terminate APEX by simply using ``CTRL+C`` in the console.
1107
1108 Verify a Full Installation - REST Client
1109 ########################################
1110
1111    .. container:: paragraph
1112
1113       APEX has a REST application for deploying, monitoring, and viewing policy models. The
1114       application can also be used to create new policy models close to
1115       the engine native policy language. Start the REST client as
1116       follows.
1117
1118    .. container:: listingblock
1119
1120       .. container:: content
1121
1122          .. code::
1123             :number-lines:
1124
1125             # $APEX_HOME/bin/apexApps.sh full-client
1126
1127 .. container:: listingblock
1128
1129    .. container:: content
1130
1131       .. code::
1132             :number-lines:
1133
1134             >%APEX_HOME%\bin\apexApps.bat full-client
1135
1136 .. container:: paragraph
1137
1138    The script will start a simple web server
1139    (`Grizzly <https://javaee.github.io/grizzly/>`__) and deploy a
1140    ``war`` web archive in it. Once the client is started, it will be
1141    available on ``localhost:18989``. The last few line of the messages
1142    should be:
1143
1144 .. container:: listingblock
1145
1146    .. container:: content
1147
1148       .. code::
1149          :number-lines:
1150
1151          Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
1152          Jul 02, 2020 2:57:39 PM org.glassfish.grizzly.http.server.NetworkListener start
1153          INFO: Started listener bound to [localhost:18989]
1154          Jul 02, 2020 2:57:39 PM org.glassfish.grizzly.http.server.HttpServer start
1155          INFO: [HttpServer] Started.
1156          Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
1157
1158
1159 .. container:: paragraph
1160
1161    Now open a browser (Firefox, Chrome, Opera, Internet Explorer) and
1162    use the URL ``http://localhost:18989/``. This will connect the
1163    browser to the started REST client. Click on the "Policy Editor" button and the Policy Editor start screen should be as
1164    follows.
1165
1166 .. container:: imageblock
1167
1168    .. container:: content
1169
1170       |Policy Editor Start Screen|
1171
1172    .. container:: title
1173
1174       Figure 1. Policy Editor Start Screen
1175
1176 .. container:: paragraph
1177
1178    Now load a policy model by clicking the menu ``File`` and then
1179    ``Open``. In the opened dialog, go to the directory where APEX is
1180    installed, then ``examples``, ``models``, ``SampleDomain``, and there
1181    select the file ``SamplePolicyModelJAVA.json``. This will load the
1182    policy model used to verify the policy engine (see above). Once
1183    loaded, the screen should look as follows.
1184
1185 .. container:: imageblock
1186
1187    .. container:: content
1188
1189       |Policy Editor with loaded SampleDomain Policy Model|
1190
1191    .. container:: title
1192
1193       Figure 2. Policy Editor with loaded SampleDomain Policy Model
1194
1195 .. container:: paragraph
1196
1197    Now you can use the Policy editor. To finish this verification, simply
1198    terminate your browser (or the tab), and then use ``CTRL+C`` in the
1199    console where you started the Policy editor.
1200
1201 Installing the WAR Application
1202 ------------------------------
1203
1204    .. container:: paragraph
1205
1206       The three APEX clients are packaged in a WAR file. This is a complete
1207       application that can be installed and run in an application
1208       server. The application is realized as a servlet. You
1209       can find the WAR application in the `ONAP Nexus Repository <https://nexus.onap.org/content/groups/public/org/onap/policy/apex-pdp/client/apex-client-full/>`__.
1210
1211
1212    .. container:: paragraph
1213
1214       Installing and using the WAR application requires a web server
1215       that can execute ``war`` web archives. We recommend to use `Apache
1216       Tomcat <https://tomcat.apache.org/>`__, however other web servers
1217       can be used as well.
1218
1219    .. container:: paragraph
1220
1221       Install Apache Tomcat including the ``Manager App``, see `V9.0
1222       Docs <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html#Configuring_Manager_Application_Access>`__
1223       for details. Start the Tomcat service, or make sure that Tomcat is
1224       running.
1225
1226    .. container:: paragraph
1227
1228       There are multiple ways to install the APEX WAR application:
1229
1230    .. container:: ulist
1231
1232       -  copy the ``.war`` file into the Tomcat ``webapps`` folder
1233
1234       -  use the Tomcat ``Manager App`` to deploy via the web interface
1235
1236       -  deploy using a REST call to Tomcat
1237
1238    .. container:: paragraph
1239
1240       For details on how to install ``war`` files please consult the
1241       `Tomcat
1242       Documentation <https://tomcat.apache.org/tomcat-9.0-doc/index.html>`__
1243       or the `Manager App
1244       HOW-TO <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html>`__.
1245       Once you installed an APEX WAR application (and wait for
1246       sufficient time for Tomcat to finalize the installation), open the
1247       ``Manager App`` in Tomcat. You should see the APEX WAR application
1248       being installed and running.
1249
1250    .. container:: paragraph
1251
1252       In case of errors, examine the log files in the Tomcat log
1253       directory. In a conventional install, those log files are in the
1254       logs directory where Tomcat is installed.
1255
1256    .. container:: paragraph
1257
1258       The WAR application file has a name similar to *apex-client-full-<VERSION>.war*.
1259
1260 Running APEX in Docker
1261 ----------------------
1262
1263    .. container:: paragraph
1264
1265       Since APEX is in ONAP, we provide a full virtualization
1266       environment for the engine.
1267
1268 Run in ONAP
1269 ###########
1270
1271       .. container:: paragraph
1272
1273          Running APEX from the ONAP docker repository only requires 2
1274          commands:
1275
1276       .. container:: olist arabic
1277
1278          #. Log into the ONAP docker repo
1279
1280       .. container:: listingblock
1281
1282          .. container:: content
1283
1284 ::
1285
1286                docker login -u docker -p docker nexus3.onap.org:10003
1287
1288       .. container:: olist arabic
1289
1290          #. Run the APEX docker image
1291
1292       .. container:: listingblock
1293
1294          .. container:: content
1295
1296             ::
1297
1298                docker run -it --rm  nexus3.onap.org:10003/onap/policy-apex-pdp:latest
1299
1300 Build a Docker Image
1301 ####################
1302
1303       .. container:: paragraph
1304
1305          Alternatively, one can use the Dockerfile defined in the Docker
1306          package to build an image.
1307
1308       .. container:: listingblock
1309
1310          .. container:: title
1311
1312             APEX Dockerfile
1313
1314          .. container:: content
1315
1316             .. code::
1317                :number-lines:
1318
1319                #
1320                # Docker file to build an image that runs APEX on Java 8 in Ubuntu
1321                #
1322                FROM ubuntu:16.04
1323
1324                RUN apt-get update && \
1325                        apt-get upgrade -y && \
1326                        apt-get install -y software-properties-common && \
1327                        add-apt-repository ppa:openjdk-r/ppa -y && \
1328                        apt-get update && \
1329                        apt-get install -y openjdk-8-jdk
1330
1331                # Create apex user and group
1332                RUN groupadd apexuser
1333                RUN useradd --create-home -g apexuser apexuser
1334
1335                # Add Apex-specific directories and set ownership as the Apex admin user
1336                RUN mkdir -p /opt/app/policy/apex-pdp
1337                RUN mkdir -p /var/log/onap/policy/apex-pdp
1338                RUN chown -R apexuser:apexuser /var/log/onap/policy/apex-pdp
1339
1340                # Unpack the tarball
1341                RUN mkdir /packages
1342                COPY apex-pdp-package-full.tar.gz /packages
1343                RUN tar xvfz /packages/apex-pdp-package-full.tar.gz --directory /opt/app/policy/apex-pdp
1344                RUN rm /packages/apex-pdp-package-full.tar.gz
1345
1346                # Ensure everything has the correct permissions
1347                RUN find /opt/app -type d -perm 755
1348                RUN find /opt/app -type f -perm 644
1349                RUN chmod a+x /opt/app/policy/apex-pdp/bin/*
1350
1351                # Copy examples to Apex user area
1352                RUN cp -pr /opt/app/policy/apex-pdp/examples /home/apexuser
1353
1354                RUN apt-get clean
1355
1356                RUN chown -R apexuser:apexuser /home/apexuser/*
1357
1358                USER apexuser
1359                ENV PATH /opt/app/policy/apex-pdp/bin:$PATH
1360                WORKDIR /home/apexuser
1361
1362 Running APEX in Standalone mode
1363 -------------------------------
1364
1365    .. container:: paragraph
1366
1367       APEX Engine can run in standalone mode by taking in a ToscaPolicy
1368       as an argument and executing it.
1369       Assume there is a tosca policy named ToscaPolicy.json in APEX_HOME directory
1370       This policy can be executed in standalone mode using any of the below methods.
1371
1372 Run in an APEX installation
1373 ###########################
1374
1375    .. container:: listingblock
1376
1377       .. container:: content
1378
1379         .. code::
1380          :number-lines:
1381
1382           # $APEX_HOME/bin/apexApps.sh engine -p $APEX_HOME/ToscaPolicy.json(1)
1383           >%APEX_HOME%\bin\apexApps.bat engine -p %APEX_HOME%\ToscaPolicy.json(2)
1384
1385 .. container:: colist arabic
1386
1387    +-------+---------+
1388    | **1** | UNIX    |
1389    +-------+---------+
1390    | **2** | Windows |
1391    +-------+---------+
1392
1393 Run in a docker container
1394 #########################
1395
1396    .. container:: listingblock
1397
1398       .. container:: content
1399
1400         .. code::
1401          :number-lines:
1402
1403           # docker run -p 6969:6969 -v $APEX_HOME/ToscaPolicy.json:/tmp/policy/ToscaPolicy.json \
1404             --name apex -it nexus3.onap.org:10001/onap/policy-apex-pdp:latest /bin/bash \
1405             -c "/opt/app/policy/apex-pdp/bin/apexEngine.sh -p /tmp/policy/ToscaPolicy.json"
1406
1407 APEX Configurations Explained
1408 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1409
1410 Introduction to APEX Configuration
1411 ----------------------------------
1412
1413          .. container:: paragraph
1414
1415             An APEX engine can be configured to use various combinations
1416             of event input handlers, event output handlers, event
1417             protocols, context handlers, and logic executors. The system
1418             is build using a plugin architecture. Each configuration
1419             option is realized by a plugin, which can be loaded and
1420             configured when the engine is started. New plugins can be
1421             added to the system at any time, though to benefit from a
1422             new plugin an engine will need to be restarted.
1423
1424          .. container:: imageblock
1425
1426             .. container:: content
1427
1428                |APEX Configuration Matrix|
1429
1430             .. container:: title
1431
1432                Figure 3. APEX Configuration Matrix
1433
1434          .. container:: paragraph
1435
1436             The APEX distribution already comes with a number of
1437             plugins. The figure above shows the provided plugins. Any
1438             combination of input, output, event protocol, context
1439             handlers, and executors is possible.
1440
1441 General Configuration Format
1442 ----------------------------
1443
1444          .. container:: paragraph
1445
1446             The APEX configuration file is a JSON file containing a few
1447             main blocks for different parts of the configuration. Each
1448             block then holds the configuration details. The following
1449             code shows the main blocks:
1450
1451          .. container:: listingblock
1452
1453             .. container:: content
1454
1455                .. code::
1456
1457                   {
1458                     "engineServiceParameters":{
1459                       ... (1)
1460                       "engineParameters":{ (2)
1461                         "executorParameters":{...}, (3)
1462                         "contextParameters":{...} (4)
1463                         "taskParameters":[...] (5)
1464                       }
1465                     },
1466                     "eventInputParameters":{ (6)
1467                       "input1":{ (7)
1468                         "carrierTechnologyParameters":{...},
1469                         "eventProtocolParameters":{...}
1470                       },
1471                       "input2":{...}, (8)
1472                         "carrierTechnologyParameters":{...},
1473                         "eventProtocolParameters":{...}
1474                       },
1475                       ... (9)
1476                     },
1477                     "eventOutputParameters":{ (10)
1478                       "output1":{ (11)
1479                         "carrierTechnologyParameters":{...},
1480                         "eventProtocolParameters":{...}
1481                       },
1482                       "output2":{ (12)
1483                         "carrierTechnologyParameters":{...},
1484                         "eventProtocolParameters":{...}
1485                       },
1486                       ... (13)
1487                     }
1488                   }
1489
1490          .. container:: colist arabic
1491
1492             +-----------------------------------+-----------------------------------+
1493             | **1**                             | main engine configuration         |
1494             +-----------------------------------+-----------------------------------+
1495             | **2**                             | engine parameters for plugin      |
1496             |                                   | configurations (execution         |
1497             |                                   | environments and context          |
1498             |                                   | handling)                         |
1499             +-----------------------------------+-----------------------------------+
1500             | **3**                             | engine specific parameters,       |
1501             |                                   | mainly for executor plugins       |
1502             +-----------------------------------+-----------------------------------+
1503             | **4**                             | context specific parameters, e.g. |
1504             |                                   | for context schemas, persistence, |
1505             |                                   | etc.                              |
1506             +-----------------------------------+-----------------------------------+
1507             | **5**                             | list of task parameters that      |
1508             |                                   | should be made available in task  |
1509             |                                   | logic (optional).                 |
1510             +-----------------------------------+-----------------------------------+
1511             | **6**                             | configuration of the input        |
1512             |                                   | interface                         |
1513             +-----------------------------------+-----------------------------------+
1514             | **7**                             | an example input called           |
1515             |                                   | ``input1`` with carrier           |
1516             |                                   | technology and event protocol     |
1517             +-----------------------------------+-----------------------------------+
1518             | **8**                             | an example input called           |
1519             |                                   | ``input2`` with carrier           |
1520             |                                   | technology and event protocol     |
1521             +-----------------------------------+-----------------------------------+
1522             | **9**                             | any further input configuration   |
1523             +-----------------------------------+-----------------------------------+
1524             | **10**                            | configuration of the output       |
1525             |                                   | interface                         |
1526             +-----------------------------------+-----------------------------------+
1527             | **11**                            | an example output called          |
1528             |                                   | ``output1`` with carrier          |
1529             |                                   | technology and event protocol     |
1530             +-----------------------------------+-----------------------------------+
1531             | **12**                            | an example output called          |
1532             |                                   | ``output2`` with carrier          |
1533             |                                   | technology and event protocol     |
1534             +-----------------------------------+-----------------------------------+
1535             | **13**                            | any further output configuration  |
1536             +-----------------------------------+-----------------------------------+
1537
1538 Engine Service Parameters
1539 -------------------------
1540
1541          .. container:: paragraph
1542
1543             The configuration provides a number of parameters to
1544             configure the engine. An example configuration with
1545             explanations of all options is shown below.
1546
1547          .. container:: listingblock
1548
1549             .. container:: content
1550
1551                .. code::
1552
1553                   "engineServiceParameters" : {
1554                     "name"          : "AADMApexEngine", (1)
1555                     "version"        : "0.0.1",  (2)
1556                     "id"             :  45,  (3)
1557                     "instanceCount"  : 4,  (4)
1558                     "deploymentPort" : 12345,  (5)
1559                     "policy_type_impl" : {...}, (6)
1560                     "periodicEventPeriod": 1000, (7)
1561                     "engineParameters":{ (8)
1562                       "executorParameters":{...}, (9)
1563                       "contextParameters":{...}, (10)
1564                       "taskParameters":[...] (11)
1565                     }
1566                   }
1567
1568          .. container:: colist arabic
1569
1570             +-----------------------------------+-----------------------------------+
1571             | **1**                             | a name for the engine. The engine |
1572             |                                   | name is used to create a key in a |
1573             |                                   | runtime engine. An name matching  |
1574             |                                   | the following regular expression  |
1575             |                                   | can be used here:                 |
1576             |                                   | ``[A-Za-z0-9\\-_\\.]+``           |
1577             +-----------------------------------+-----------------------------------+
1578             | **2**                             | a version of the engine, use      |
1579             |                                   | semantic versioning as explained  |
1580             |                                   | here: `Semantic                   |
1581             |                                   | Versioning <http://semver.org/>`_ |
1582             |                                   | _.                                |
1583             |                                   | This version is used in a runtime |
1584             |                                   | engine to create a version of the |
1585             |                                   | engine. For that reason, the      |
1586             |                                   | version must match the following  |
1587             |                                   | regular expression ``[A-Z0-9.]+`` |
1588             +-----------------------------------+-----------------------------------+
1589             | **3**                             | a numeric identifier for the      |
1590             |                                   | engine                            |
1591             +-----------------------------------+-----------------------------------+
1592             | **4**                             | the number of threads (policy     |
1593             |                                   | instances executed in parallel)   |
1594             |                                   | the engine should use, use ``1``  |
1595             |                                   | for single threaded engines       |
1596             +-----------------------------------+-----------------------------------+
1597             | **5**                             | the port for the deployment       |
1598             |                                   | Websocket connection to the       |
1599             |                                   | engine                            |
1600             +-----------------------------------+-----------------------------------+
1601             | **6**                             | the APEX policy model as a JSON   |
1602             |                                   | or YAML block to load into the    |
1603             |                                   | engine on startup when            |
1604             |                                   | APEX is running a policy that has |
1605             |                                   | its logic and parameters          |
1606             |                                   | specified in TOSCA                |
1607             |                                   | (optional)                        |
1608             +-----------------------------------+-----------------------------------+
1609             | **7**                             | an optional timer for periodic    |
1610             |                                   | policies, in milliseconds (a      |
1611             |                                   | defined periodic policy will be   |
1612             |                                   | executed every ``X``              |
1613             |                                   | milliseconds), not used of not    |
1614             |                                   | set or ``0``                      |
1615             +-----------------------------------+-----------------------------------+
1616             | **8**                             | engine parameters for plugin      |
1617             |                                   | configurations (execution         |
1618             |                                   | environments and context          |
1619             |                                   | handling)                         |
1620             +-----------------------------------+-----------------------------------+
1621             | **9**                             | engine specific parameters,       |
1622             |                                   | mainly for executor plugins       |
1623             +-----------------------------------+-----------------------------------+
1624             | **10**                            | context specific parameters, e.g. |
1625             |                                   | for context schemas, persistence, |
1626             |                                   | etc.                              |
1627             +-----------------------------------+-----------------------------------+
1628             | **11**                            | list of task parameters that      |
1629             |                                   | should be made available in task  |
1630             |                                   | logic (optional).                 |
1631             +-----------------------------------+-----------------------------------+
1632
1633          .. container:: paragraph
1634
1635             The model file is optional, it can also be specified via
1636             command line. In any case, make sure all execution and other
1637             required plug-ins for the loaded model are loaded as
1638             required.
1639
1640 Input and Output Interfaces
1641 ---------------------------
1642
1643          .. container:: paragraph
1644
1645             An APEX engine has two main interfaces:
1646
1647          .. container:: ulist
1648
1649             -  An *input* interface to receive events: also known as
1650                ingress interface or consumer, receiving (consuming)
1651                events commonly named triggers, and
1652
1653             -  An *output* interface to publish produced events: also
1654                known as egress interface or producer, sending
1655                (publishing) events commonly named actions or action
1656                events.
1657
1658          .. container:: paragraph
1659
1660             The input and output interface is configured in terms of
1661             inputs and outputs, respectively. Each input and output is a
1662             combination of a carrier technology and an event protocol.
1663             Carrier technologies and event protocols are provided by
1664             plugins, each with its own specific configuration. Most
1665             carrier technologies can be configured for input as well as
1666             output. Most event protocols can be used for all carrier
1667             technologies. One exception is the JMS object event
1668             protocol, which can only be used for the JMS carrier
1669             technology. Some further restrictions apply (for instance
1670             for carrier technologies using bi- or uni-directional
1671             modes).
1672
1673          .. container:: paragraph
1674
1675             Input and output interface can be configured separately, in
1676             isolation, with any number of carrier technologies. The
1677             resulting general configuration options are:
1678
1679          .. container:: ulist
1680
1681             -  Input interface with one or more inputs
1682
1683                .. container:: ulist
1684
1685                   -  each input with a carrier technology and an event
1686                      protocol
1687
1688                   -  some inputs with optional synchronous mode
1689
1690                   -  some event protocols with additional parameters
1691
1692             -  Output interface with one or more outputs
1693
1694                .. container:: ulist
1695
1696                   -  each output with a carrier technology and an event
1697                      encoding
1698
1699                   -  some outputs with optional synchronous mode
1700
1701                   -  some event protocols with additional parameters
1702
1703          .. container:: paragraph
1704
1705             The configuration for input and output is contained in
1706             ``eventInputParameters`` and ``eventOutputParameters``,
1707             respectively. Inside here, one can configure any number of
1708             inputs and outputs. Each of them needs to have a unique
1709             identifier (name), the content of the name is free form. The
1710             example below shows a configuration for two inputs and two
1711             outputs.
1712
1713          .. container:: listingblock
1714
1715             .. container:: content
1716
1717                .. code::
1718
1719                   "eventInputParameters": { (1)
1720                     "FirstConsumer": { (2)
1721                       "carrierTechnologyParameters" : {...}, (3)
1722                       "eventProtocolParameters":{...}, (4)
1723                       ... (5)
1724                     },
1725                     "SecondConsumer": { (6)
1726                       "carrierTechnologyParameters" : {...}, (7)
1727                       "eventProtocolParameters":{...}, (8)
1728                       ... (9)
1729                     },
1730                   },
1731                   "eventOutputParameters": { (10)
1732                     "FirstProducer": { (11)
1733                       "carrierTechnologyParameters":{...}, (12)
1734                       "eventProtocolParameters":{...}, (13)
1735                       ... (14)
1736                     },
1737                     "SecondProducer": { (15)
1738                       "carrierTechnologyParameters":{...}, (16)
1739                       "eventProtocolParameters":{...}, (17)
1740                       ... (18)
1741                     }
1742                   }
1743
1744          .. container:: colist arabic
1745
1746             +--------+--------------------------------------------------------------------+
1747             | **1**  | input interface configuration, APEX input plugins                  |
1748             +--------+--------------------------------------------------------------------+
1749             | **2**  | first input called ``FirstConsumer``                               |
1750             +--------+--------------------------------------------------------------------+
1751             | **3**  | carrier technology for plugin                                      |
1752             +--------+--------------------------------------------------------------------+
1753             | **4**  | event protocol for plugin                                          |
1754             +--------+--------------------------------------------------------------------+
1755             | **5**  | any other input configuration (e.g. event name filter, see below)  |
1756             +--------+--------------------------------------------------------------------+
1757             | **6**  | second input called ``SecondConsumer``                             |
1758             +--------+--------------------------------------------------------------------+
1759             | **7**  | carrier technology for plugin                                      |
1760             +--------+--------------------------------------------------------------------+
1761             | **8**  | event protocol for plugin                                          |
1762             +--------+--------------------------------------------------------------------+
1763             | **9**  | any other plugin configuration                                     |
1764             +--------+--------------------------------------------------------------------+
1765             | **10** | output interface configuration, APEX output plugins                |
1766             +--------+--------------------------------------------------------------------+
1767             | **11** | first output called ``FirstProducer``                              |
1768             +--------+--------------------------------------------------------------------+
1769             | **12** | carrier technology for plugin                                      |
1770             +--------+--------------------------------------------------------------------+
1771             | **13** | event protocol for plugin                                          |
1772             +--------+--------------------------------------------------------------------+
1773             | **14** | any other plugin configuration                                     |
1774             +--------+--------------------------------------------------------------------+
1775             | **15** | second output called ``SecondProducer``                            |
1776             +--------+--------------------------------------------------------------------+
1777             | **16** | carrier technology for plugin                                      |
1778             +--------+--------------------------------------------------------------------+
1779             | **17** | event protocol for plugin                                          |
1780             +--------+--------------------------------------------------------------------+
1781             | **18** | any other output configuration (e.g. event name filter, see below) |
1782             +--------+--------------------------------------------------------------------+
1783
1784 Event Filters
1785 #############
1786
1787             .. container:: paragraph
1788
1789                APEX will always send an event after a policy execution
1790                is finished. For a successful execution, the event sent
1791                is the output event created by the policy. In case the
1792                policy does not create an output event, APEX will create
1793                a new event with all input event fields plus an
1794                additional field ``exceptionMessage`` with an exception
1795                message.
1796
1797             .. container:: paragraph
1798
1799                There are situations in which this auto-generated error
1800                event might not be required or wanted:
1801
1802             .. container:: ulist
1803
1804                -  when a policy failing should not result in an event
1805                   send out via an output interface
1806
1807                -  when the auto-generated event goes back in an APEX
1808                   engine (or the same APEX engine), this can create
1809                   endless loops
1810
1811                -  the auto-generated event should go to a special output
1812                   interface or channel
1813
1814             .. container:: paragraph
1815
1816                All of these situations are supported by a filter option
1817                using a wildecard (regular expression) configuration on
1818                APEX I/O interfaces. The parameter is called
1819                ``eventNameFilter`` and the value are `Java regular
1820                expressions <https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html>`__
1821                (a
1822                `tutorial <http://www.vogella.com/tutorials/JavaRegularExpressions/article.html>`__).
1823                The following code shows some examples:
1824
1825             .. container:: listingblock
1826
1827                .. container:: content
1828
1829                   .. code::
1830
1831                      "eventInputParameters": {
1832                        "Input1": {
1833                          "carrierTechnologyParameters" : {...},
1834                          "eventProtocolParameters":{...},
1835                          "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]004$" (1)
1836                        }
1837                      },
1838                      "eventOutputParameters": {
1839                        "Output1": {
1840                          "carrierTechnologyParameters":{...},
1841                          "eventProtocolParameters":{...},
1842                          "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]104$" (2)
1843                        }
1844                      }
1845
1846 Executors
1847 ---------
1848
1849          .. container:: paragraph
1850
1851             Executors are plugins that realize the execution of logic
1852             contained in a policy model. Logic can be in a task
1853             selector, a task, and a state finalizer. Using plugins for
1854             execution environments makes APEX very flexible to support
1855             virtually any executable logic expressions.
1856
1857          .. container:: paragraph
1858
1859             APEX 2.0.0-SNAPSHOT supports the following executors:
1860
1861          .. container:: ulist
1862
1863             -  Java, for Java implemented logic
1864
1865                .. container:: ulist
1866
1867                   -  This executor requires logic implemented using the
1868                      APEX Java interfaces.
1869
1870                   -  Generated JAR files must be in the classpath of the
1871                      APEX engine at start time.
1872
1873             -  Javascript
1874
1875             -  JRuby,
1876
1877             -  Jython,
1878
1879             -  MVEL
1880
1881                .. container:: ulist
1882
1883                   -  This executor uses the latest version of the MVEL
1884                      engine, which can be very hard to debug and can
1885                      produce unwanted side effects during execution
1886
1887 Configure the Javascript Executor
1888 #################################
1889
1890             .. container:: paragraph
1891
1892                The Javascript executor is added to the configuration as
1893                follows:
1894
1895             .. container:: listingblock
1896
1897                .. container:: content
1898
1899                   .. code::
1900
1901                      "engineServiceParameters":{
1902                        "engineParameters":{
1903                          "executorParameters":{
1904                            "JAVASCRIPT":{
1905                              "parameterClassName" :
1906                              "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
1907                            }
1908                          }
1909                        }
1910                      }
1911
1912 Configure the Jython Executor
1913 #############################
1914
1915             .. container:: paragraph
1916
1917                The Jython executor is added to the configuration as
1918                follows:
1919
1920             .. container:: listingblock
1921
1922                .. container:: content
1923
1924                   .. code::
1925
1926                      "engineServiceParameters":{
1927                        "engineParameters":{
1928                          "executorParameters":{
1929                            "JYTHON":{
1930                              "parameterClassName" :
1931                              "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
1932                            }
1933                          }
1934                        }
1935                      }
1936
1937 Configure the JRuby Executor
1938 ############################
1939
1940             .. container:: paragraph
1941
1942                The JRuby executor is added to the configuration as
1943                follows:
1944
1945             .. container:: listingblock
1946
1947                .. container:: content
1948
1949                   .. code::
1950
1951                      "engineServiceParameters":{
1952                        "engineParameters":{
1953                          "executorParameters":{
1954                            "JRUBY":{
1955                              "parameterClassName" :
1956                              "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
1957                            }
1958                          }
1959                        }
1960                      }
1961
1962 Configure the Java Executor
1963 ###########################
1964
1965             .. container:: paragraph
1966
1967                The Java executor is added to the configuration as
1968                follows:
1969
1970             .. container:: listingblock
1971
1972                .. container:: content
1973
1974                   .. code::
1975
1976                      "engineServiceParameters":{
1977                        "engineParameters":{
1978                          "executorParameters":{
1979                            "JAVA":{
1980                              "parameterClassName" :
1981                              "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
1982                            }
1983                          }
1984                        }
1985                      }
1986
1987 Configure the MVEL Executor
1988 ###########################
1989
1990             .. container:: paragraph
1991
1992                The MVEL executor is added to the configuration as
1993                follows:
1994
1995             .. container:: listingblock
1996
1997                .. container:: content
1998
1999                   .. code::
2000
2001                      "engineServiceParameters":{
2002                        "engineParameters":{
2003                          "executorParameters":{
2004                            "MVEL":{
2005                              "parameterClassName" :
2006                              "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
2007                            }
2008                          }
2009                        }
2010                      }
2011
2012 Context Handlers
2013 ----------------
2014
2015          .. container:: paragraph
2016
2017             Context handlers are responsible for all context processing.
2018             There are the following main areas:
2019
2020          .. container:: ulist
2021
2022             -  Context schema: use schema handlers other than Java class
2023                (supported by default without configuration)
2024
2025             -  Context distribution: distribute context across multiple
2026                APEX engines
2027
2028             -  Context locking: mechanisms to lock context elements for
2029                read/write
2030
2031             -  Context persistence: mechanisms to persist context
2032
2033          .. container:: paragraph
2034
2035             APEX provides plugins for each of the main areas.
2036
2037 Configure AVRO Schema Handler
2038 #############################
2039
2040             .. container:: paragraph
2041
2042                The AVRO schema handler is added to the configuration as
2043                follows:
2044
2045             .. container:: listingblock
2046
2047                .. container:: content
2048
2049                   .. code::
2050
2051                      "engineServiceParameters":{
2052                        "engineParameters":{
2053                          "contextParameters":{
2054                            "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
2055                            "schemaParameters":{
2056                              "Avro":{
2057                                "parameterClassName" :
2058                                  "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
2059                              }
2060                            }
2061                          }
2062                        }
2063                      }
2064
2065             .. container:: paragraph
2066
2067                Using the AVRO schema handler has one limitation: AVRO
2068                only supports field names that represent valid Java class
2069                names. This means only letters and the character ``_``
2070                are supported. Characters commonly used in field names,
2071                such as ``.`` and ``-``, are not supported by AVRO. for
2072                more information see `Avro Spec:
2073                Names <https://avro.apache.org/docs/1.8.1/spec.html#names>`__.
2074
2075             .. container:: paragraph
2076
2077                To work with this limitation, the APEX Avro plugin will
2078                parse a given AVRO definition and replace *all*
2079                occurrences of ``.`` and ``-`` with a ``_``. This means
2080                that
2081
2082             .. container:: ulist
2083
2084                -  In a policy model, if the AVRO schema defined a field
2085                   as ``my-name`` the policy logic should access it as
2086                   ``my_name``
2087
2088                -  In a policy model, if the AVRO schema defined a field
2089                   as ``my.name`` the policy logic should access it as
2090                   ``my_name``
2091
2092                -  There should be no field names that convert to the
2093                   same internal name
2094
2095                   .. container:: ulist
2096
2097                      -  For instance the simultaneous use of
2098                         ``my_name``, ``my.name``, and ``my-name`` should
2099                         be avoided
2100
2101                      -  If not avoided, the event processing might
2102                         create unwanted side effects
2103
2104                -  If field names use any other not-supported character,
2105                   the AVRO plugin will reject it
2106
2107                   .. container:: ulist
2108
2109                      -  Since AVRO uses lazy initialization, this
2110                         rejection might only become visible at runtime
2111
2112 Configure Task Parameters
2113 #########################
2114
2115             .. container:: paragraph
2116
2117                The Task Parameters are added to the configuration as
2118                follows:
2119
2120             .. container:: listingblock
2121
2122                .. container:: content
2123
2124                   .. code::
2125
2126                      "engineServiceParameters": {
2127                        "engineParameters": {
2128                          "taskParameters": [
2129                            {
2130                              "key": "ParameterKey1",
2131                              "value": "ParameterValue1"
2132                            },
2133                            {
2134                              "taskId": "Task_Act0",
2135                              "key": "ParameterKey2",
2136                              "value": "ParameterValue2"
2137                            }
2138                          ]
2139                        }
2140                      }
2141
2142             .. container:: paragraph
2143
2144                TaskParameters can be used to pass parameters from ApexConfig
2145                to the policy logic. In the config, these are optional.
2146                The list of task parameters provided in the config may be added
2147                to the tasks or existing task parameters in the task will be overriden.
2148
2149             .. container:: paragraph
2150
2151                If taskId is provided in ApexConfig for an entry, then that
2152                parameter is updated only for that particular task. Otherwise,
2153                the task parameter is added to all tasks.
2154
2155 Carrier Technologies
2156 --------------------
2157
2158          .. container:: paragraph
2159
2160             Carrier technologies define how APEX receives (input) and
2161             sends (output) events. They can be used in any combination,
2162             using asynchronous or synchronous mode. There can also be
2163             any number of carrier technologies for the input (consume)
2164             and the output (produce) interface.
2165
2166          .. container:: paragraph
2167
2168             Supported *input* technologies are:
2169
2170          .. container:: ulist
2171
2172             -  Standard input, read events from the standard input
2173                (console), not suitable for APEX background servers
2174
2175             -  File input, read events from a file
2176
2177             -  Kafka, read events from a Kafka system
2178
2179             -  Websockets, read events from a Websocket
2180
2181             -  JMS,
2182
2183             -  REST (synchronous and asynchronous), additionally as
2184                client or server
2185
2186             -  Event Requestor, allows reading of events that have been
2187                looped back into APEX
2188
2189          .. container:: paragraph
2190
2191             Supported *output* technologies are:
2192
2193          .. container:: ulist
2194
2195             -  Standard output, write events to the standard output
2196                (console), not suitable for APEX background servers
2197
2198             -  File output, write events to a file
2199
2200             -  Kafka, write events to a Kafka system
2201
2202             -  Websockets, write events to a Websocket
2203
2204             -  JMS
2205
2206             -  REST (synchronous and asynchronous), additionally as
2207                client or server
2208
2209             -  Event Requestor, allows events to be looped back into
2210                APEX
2211
2212          .. container:: paragraph
2213
2214             New carrier technologies can be added as plugins to APEX or
2215             developed outside APEX and added to an APEX deployment.
2216
2217 Standard IO
2218 ###########
2219
2220             .. container:: paragraph
2221
2222                Standard IO does not require a specific plugin, it is
2223                supported be default.
2224
2225 Standard Input
2226 ==============
2227                .. container:: paragraph
2228
2229                   APEX will take events from its standard input. This
2230                   carrier is good for testing, but certainly not for a
2231                   use case where APEX runs as a server. The
2232                   configuration is as follows:
2233
2234                .. container:: listingblock
2235
2236                   .. container:: content
2237
2238 ::
2239
2240                         "carrierTechnologyParameters" : {
2241                           "carrierTechnology" : "FILE", (1)
2242                           "parameters" : {
2243                             "standardIO" : true (2)
2244                           }
2245                         }
2246
2247                .. container:: colist arabic
2248
2249                   +-------+---------------------------------------+
2250                   | **1** | standard input is considered a file   |
2251                   +-------+---------------------------------------+
2252                   | **2** | file descriptor set to standard input |
2253                   +-------+---------------------------------------+
2254
2255 Standard Output
2256 ===============
2257
2258                .. container:: paragraph
2259
2260                   APEX will send events to its standard output. This
2261                   carrier is good for testing, but certainly not for a
2262                   use case where APEX runs as a server. The
2263                   configuration is as follows:
2264
2265                .. container:: listingblock
2266
2267                   .. container:: content
2268
2269                      .. code::
2270
2271                         "carrierTechnologyParameters" : {
2272                           "carrierTechnology" : "FILE", (1)
2273                           "parameters" : {
2274                             "standardIO" : true  (2)
2275                           }
2276                         }
2277
2278                .. container:: colist arabic
2279
2280                   +-------+----------------------------------------+
2281                   | **1** | standard output is considered a file   |
2282                   +-------+----------------------------------------+
2283                   | **2** | file descriptor set to standard output |
2284                   +-------+----------------------------------------+
2285
2286 2.7.2. File IO
2287 ##############
2288
2289             .. container:: paragraph
2290
2291                File IO does not require a specific plugin, it is
2292                supported be default.
2293
2294 File Input
2295 ==========
2296
2297                .. container:: paragraph
2298
2299                   APEX will take events from a file. The same file
2300                   should not be used as an output. The configuration is
2301                   as follows:
2302
2303                .. container:: listingblock
2304
2305                   .. container:: content
2306
2307                      .. code::
2308
2309                         "carrierTechnologyParameters" : {
2310                           "carrierTechnology" : "FILE", (1)
2311                           "parameters" : {
2312                             "fileName" : "examples/events/SampleDomain/EventsIn.xmlfile" (2)
2313                           }
2314                         }
2315
2316                .. container:: colist arabic
2317
2318                   +-------+------------------------------------------+
2319                   | **1** | set file input                           |
2320                   +-------+------------------------------------------+
2321                   | **2** | the name of the file to read events from |
2322                   +-------+------------------------------------------+
2323
2324 File Output
2325 ===========
2326                .. container:: paragraph
2327
2328                   APEX will write events to a file. The same file should
2329                   not be used as an input. The configuration is as
2330                   follows:
2331
2332                .. container:: listingblock
2333
2334                   .. container:: content
2335
2336                      .. code::
2337
2338                         "carrierTechnologyParameters" : {
2339                           "carrierTechnology" : "FILE", (1)
2340                           "parameters" : {
2341                             "fileName"  : "examples/events/SampleDomain/EventsOut.xmlfile" (2)
2342                           }
2343                         }
2344
2345                .. container:: colist arabic
2346
2347                   +-------+-----------------------------------------+
2348                   | **1** | set file output                         |
2349                   +-------+-----------------------------------------+
2350                   | **2** | the name of the file to write events to |
2351                   +-------+-----------------------------------------+
2352
2353 Event Requestor IO
2354 ##################
2355
2356             .. container:: paragraph
2357
2358                Event Requestor IO does not require a specific plugin, it
2359                is supported be default. It should only be used with the
2360                APEX event protocol.
2361
2362 Event Requestor Input
2363 =====================
2364
2365                .. container:: paragraph
2366
2367                   APEX will take events from APEX.
2368
2369                .. container:: listingblock
2370
2371                   .. container:: content
2372
2373                      .. code::
2374
2375                         "carrierTechnologyParameters" : {
2376                           "carrierTechnology": "EVENT_REQUESTOR" (1)
2377                         }
2378
2379                .. container:: colist arabic
2380
2381                   +-------+---------------------------+
2382                   | **1** | set event requestor input |
2383                   +-------+---------------------------+
2384
2385 Event Requestor Output
2386 ======================
2387
2388                .. container:: paragraph
2389
2390                   APEX will write events to APEX.
2391
2392                .. container:: listingblock
2393
2394                   .. container:: content
2395
2396                      .. code::
2397
2398                         "carrierTechnologyParameters" : {
2399                           "carrierTechnology": "EVENT_REQUESTOR" (1)
2400                         }
2401
2402 Peering Event Requestors
2403 ========================
2404
2405                .. container:: paragraph
2406
2407                   When using event requestors, they need to be peered.
2408                   This means an event requestor output needs to be
2409                   peered (associated) with an event requestor input. The
2410                   following example shows the use of an event requestor
2411                   with the APEX event protocol and the peering of output
2412                   and input.
2413
2414                .. container:: listingblock
2415
2416                   .. container:: content
2417
2418                      .. code::
2419
2420                         "eventInputParameters": {
2421                           "EventRequestorConsumer": {
2422                             "carrierTechnologyParameters": {
2423                               "carrierTechnology": "EVENT_REQUESTOR" (1)
2424                             },
2425                             "eventProtocolParameters": {
2426                               "eventProtocol": "APEX" (2)
2427                             },
2428                             "eventNameFilter": "InputEvent", (3)
2429                             "requestorMode": true, (4)
2430                             "requestorPeer": "EventRequestorProducer", (5)
2431                             "requestorTimeout": 500 (6)
2432                           }
2433                         },
2434                         "eventOutputParameters": {
2435                           "EventRequestorProducer": {
2436                             "carrierTechnologyParameters": {
2437                               "carrierTechnology": "EVENT_REQUESTOR" (7)
2438                             },
2439                             "eventProtocolParameters": {
2440                               "eventProtocol": "APEX" (8)
2441                             },
2442                             "eventNameFilter": "EventListEvent", (9)
2443                             "requestorMode": true, (10)
2444                             "requestorPeer": "EventRequestorConsumer", (11)
2445                             "requestorTimeout": 500 (12)
2446                           }
2447                         }
2448
2449                .. container:: colist arabic
2450
2451                   +-----------------------------------+-----------------------------------+
2452                   | **1**                             | event requestor on a consumer     |
2453                   +-----------------------------------+-----------------------------------+
2454                   | **2**                             | with APEX event protocol          |
2455                   +-----------------------------------+-----------------------------------+
2456                   | **3**                             | optional filter (best to use a    |
2457                   |                                   | filter to prevent unwanted events |
2458                   |                                   | on the consumer side)             |
2459                   +-----------------------------------+-----------------------------------+
2460                   | **4**                             | activate requestor mode           |
2461                   +-----------------------------------+-----------------------------------+
2462                   | **5**                             | the peer to the output (must      |
2463                   |                                   | match the output carrier)         |
2464                   +-----------------------------------+-----------------------------------+
2465                   | **6**                             | an optional timeout in            |
2466                   |                                   | milliseconds                      |
2467                   +-----------------------------------+-----------------------------------+
2468                   | **7**                             | event requestor on a producer     |
2469                   +-----------------------------------+-----------------------------------+
2470                   | **8**                             | with APEX event protocol          |
2471                   +-----------------------------------+-----------------------------------+
2472                   | **9**                             | optional filter (best to use a    |
2473                   |                                   | filter to prevent unwanted events |
2474                   |                                   | on the consumer side)             |
2475                   +-----------------------------------+-----------------------------------+
2476                   | **10**                            | activate requestor mode           |
2477                   +-----------------------------------+-----------------------------------+
2478                   | **11**                            | the peer to the output (must      |
2479                   |                                   | match the input carrier)          |
2480                   +-----------------------------------+-----------------------------------+
2481                   | **12**                            | an optional timeout in            |
2482                   |                                   | milliseconds                      |
2483                   +-----------------------------------+-----------------------------------+
2484
2485 Kafka IO
2486 ########
2487
2488             .. container:: paragraph
2489
2490                Kafka IO is supported by the APEX Kafka plugin. The
2491                configurations below are examples. APEX will take any
2492                configuration inside the parameter object and forward it
2493                to Kafka. More information on Kafka specific
2494                configuration parameters can be found in the Kafka
2495                documentation:
2496
2497             .. container:: ulist
2498
2499                -  `Kafka Consumer
2500                   Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html>`__
2501
2502                -  `Kafka Producer
2503                   Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>`__
2504
2505 Kafka Input
2506 ===========
2507                .. container:: paragraph
2508
2509                   APEX will receive events from the Apache Kafka
2510                   messaging system. The input is uni-directional, an
2511                   engine will only receive events from the input but not
2512                   send any event to the input.
2513
2514                .. container:: listingblock
2515
2516                   .. container:: content
2517
2518                      .. code::
2519
2520                         "carrierTechnologyParameters" : {
2521                           "carrierTechnology" : "KAFKA", (1)
2522                           "parameterClassName" :
2523                             "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2524                           "parameters" : {
2525                             "bootstrapServers"  : "localhost:49092", (2)
2526                             "groupId"           : "apex-group-id", (3)
2527                             "enableAutoCommit"  : true, (4)
2528                             "autoCommitTime"    : 1000, (5)
2529                             "sessionTimeout"    : 30000, (6)
2530                             "consumerPollTime"  : 100, (7)
2531                             "consumerTopicList" : ["apex-in-0", "apex-in-1"], (8)
2532                             "keyDeserializer"   :
2533                                 "org.apache.kafka.common.serialization.StringDeserializer", (9)
2534                             "valueDeserializer" :
2535                                 "org.apache.kafka.common.serialization.StringDeserializer" (10)
2536                           }
2537                         }
2538
2539                .. container:: colist arabic
2540
2541                   +--------+-------------------------------------+
2542                   | **1**  | set Kafka as carrier technology     |
2543                   +--------+-------------------------------------+
2544                   | **2**  | bootstrap server and port           |
2545                   +--------+-------------------------------------+
2546                   | **3**  | a group identifier                  |
2547                   +--------+-------------------------------------+
2548                   | **4**  | flag for auto-commit                |
2549                   +--------+-------------------------------------+
2550                   | **5**  | auto-commit timeout in milliseconds |
2551                   +--------+-------------------------------------+
2552                   | **6**  | session timeout in milliseconds     |
2553                   +--------+-------------------------------------+
2554                   | **7**  | consumer poll time in milliseconds  |
2555                   +--------+-------------------------------------+
2556                   | **8**  | consumer topic list                 |
2557                   +--------+-------------------------------------+
2558                   | **9**  | key for the Kafka de-serializer     |
2559                   +--------+-------------------------------------+
2560                   | **10** | value for the Kafka de-serializer   |
2561                   +--------+-------------------------------------+
2562
2563 Kafka Output
2564 ============
2565                .. container:: paragraph
2566
2567                   APEX will send events to the Apache Kafka messaging
2568                   system. The output is uni-directional, an engine will
2569                   send events to the output but not receive any event
2570                   from the output.
2571
2572                .. container:: listingblock
2573
2574                   .. container:: content
2575
2576                      .. code::
2577
2578                         "carrierTechnologyParameters" : {
2579                           "carrierTechnology" : "KAFKA", (1)
2580                           "parameterClassName" :
2581                             "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2582                           "parameters" : {
2583                             "bootstrapServers"  : "localhost:49092", (2)
2584                             "acks"              : "all", (3)
2585                             "retries"           : 0, (4)
2586                             "batchSize"         : 16384, (5)
2587                             "lingerTime"        : 1, (6)
2588                             "bufferMemory"      : 33554432, (7)
2589                             "producerTopic"     : "apex-out", (8)
2590                             "keySerializer"     :
2591                                 "org.apache.kafka.common.serialization.StringSerializer", (9)
2592                             "valueSerializer"   :
2593                                 "org.apache.kafka.common.serialization.StringSerializer" (10)
2594                           }
2595                         }
2596
2597                .. container:: colist arabic
2598
2599                   +--------+---------------------------------+
2600                   | **1**  | set Kafka as carrier technology |
2601                   +--------+---------------------------------+
2602                   | **2**  | bootstrap server and port       |
2603                   +--------+---------------------------------+
2604                   | **3**  | acknowledgement strategy        |
2605                   +--------+---------------------------------+
2606                   | **4**  | number of retries               |
2607                   +--------+---------------------------------+
2608                   | **5**  | batch size                      |
2609                   +--------+---------------------------------+
2610                   | **6**  | time to linger in milliseconds  |
2611                   +--------+---------------------------------+
2612                   | **7**  | buffer memory in byte           |
2613                   +--------+---------------------------------+
2614                   | **8**  | producer topic                  |
2615                   +--------+---------------------------------+
2616                   | **9**  | key for the Kafka serializer    |
2617                   +--------+---------------------------------+
2618                   | **10** | value for the Kafka serializer  |
2619                   +--------+---------------------------------+
2620
2621 JMS IO
2622 ######
2623
2624             .. container:: paragraph
2625
2626                APEX supports the Java Messaging Service (JMS) as input
2627                as well as output. JMS IO is supported by the APEX JMS
2628                plugin. Input and output support an event encoding as
2629                text (JSON string) or object (serialized object). The
2630                input configuration is the same for both encodings, the
2631                output configuration differs.
2632
2633 JMS Input
2634 =========
2635                .. container:: paragraph
2636
2637                   APEX will receive events from a JMS messaging system.
2638                   The input is uni-directional, an engine will only
2639                   receive events from the input but not send any event
2640                   to the input.
2641
2642                .. container:: listingblock
2643
2644                   .. container:: content
2645
2646                      .. code::
2647
2648                         "carrierTechnologyParameters" : {
2649                           "carrierTechnology" : "JMS", (1)
2650                           "parameterClassName" :
2651                               "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2652                           "parameters" : { (2)
2653                             "initialContextFactory" :
2654                                 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2655                             "connectionFactory" : "ConnectionFactory", (4)
2656                             "providerURL" : "remote://localhost:5445", (5)
2657                             "securityPrincipal" : "guest", (6)
2658                             "securityCredentials" : "IAmAGuest", (7)
2659                             "consumerTopic" : "jms/topic/apexIn" (8)
2660                           }
2661                         }
2662
2663                .. container:: colist arabic
2664
2665                   +-----------------------------------+-----------------------------------+
2666                   | **1**                             | set JMS as carrier technology     |
2667                   +-----------------------------------+-----------------------------------+
2668                   | **2**                             | set all JMS specific parameters   |
2669                   +-----------------------------------+-----------------------------------+
2670                   | **3**                             | the context factory, in this case |
2671                   |                                   | from JBOSS (it requires the       |
2672                   |                                   | dependency                        |
2673                   |                                   | org.jboss:jboss-remote-naming:2.0 |
2674                   |                                   | .4.Final                          |
2675                   |                                   | or a different version to be in   |
2676                   |                                   | the directory ``$APEX_HOME/lib``  |
2677                   |                                   | or ``%APEX_HOME%\lib``            |
2678                   +-----------------------------------+-----------------------------------+
2679                   | **4**                             | a connection factory for the JMS  |
2680                   |                                   | connection                        |
2681                   +-----------------------------------+-----------------------------------+
2682                   | **5**                             | URL with host and port of the JMS |
2683                   |                                   | provider                          |
2684                   +-----------------------------------+-----------------------------------+
2685                   | **6**                             | access credentials, user name     |
2686                   +-----------------------------------+-----------------------------------+
2687                   | **7**                             | access credentials, user password |
2688                   +-----------------------------------+-----------------------------------+
2689                   | **8**                             | the JMS topic to listen to        |
2690                   +-----------------------------------+-----------------------------------+
2691
2692 JMS Output with Text
2693 ====================
2694
2695                .. container:: paragraph
2696
2697                   APEX engine send events to a JMS messaging system. The
2698                   output is uni-directional, an engine will send events
2699                   to the output but not receive any event from output.
2700
2701                .. container:: listingblock
2702
2703                   .. container:: content
2704
2705                      .. code::
2706
2707                         "carrierTechnologyParameters" : {
2708                           "carrierTechnology" : "JMS", (1)
2709                           "parameterClassName" :
2710                               "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2711                           "parameters" : { (2)
2712                             "initialContextFactory" :
2713                                 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2714                             "connectionFactory" : "ConnectionFactory", (4)
2715                             "providerURL" : "remote://localhost:5445", (5)
2716                             "securityPrincipal" : "guest", (6)
2717                             "securityCredentials" : "IAmAGuest", (7)
2718                             "producerTopic" : "jms/topic/apexOut", (8)
2719                             "objectMessageSending": "false" (9)
2720                           }
2721                         }
2722
2723                .. container:: colist arabic
2724
2725                   +-----------------------------------+-----------------------------------+
2726                   | **1**                             | set JMS as carrier technology     |
2727                   +-----------------------------------+-----------------------------------+
2728                   | **2**                             | set all JMS specific parameters   |
2729                   +-----------------------------------+-----------------------------------+
2730                   | **3**                             | the context factory, in this case |
2731                   |                                   | from JBOSS (it requires the       |
2732                   |                                   | dependency                        |
2733                   |                                   | org.jboss:jboss-remote-naming:2.0 |
2734                   |                                   | .4.Final                          |
2735                   |                                   | or a different version to be in   |
2736                   |                                   | the directory ``$APEX_HOME/lib``  |
2737                   |                                   | or ``%APEX_HOME%\lib``            |
2738                   +-----------------------------------+-----------------------------------+
2739                   | **4**                             | a connection factory for the JMS  |
2740                   |                                   | connection                        |
2741                   +-----------------------------------+-----------------------------------+
2742                   | **5**                             | URL with host and port of the JMS |
2743                   |                                   | provider                          |
2744                   +-----------------------------------+-----------------------------------+
2745                   | **6**                             | access credentials, user name     |
2746                   +-----------------------------------+-----------------------------------+
2747                   | **7**                             | access credentials, user password |
2748                   +-----------------------------------+-----------------------------------+
2749                   | **8**                             | the JMS topic to write to         |
2750                   +-----------------------------------+-----------------------------------+
2751                   | **9**                             | set object messaging to ``false`` |
2752                   |                                   | means it sends JSON text          |
2753                   +-----------------------------------+-----------------------------------+
2754
2755 JMS Output with Object
2756 ======================
2757
2758                .. container:: paragraph
2759
2760                   To configure APEX for JMS objects on the output
2761                   interface use the same configuration as above (for
2762                   output). Simply change the ``objectMessageSending``
2763                   parameter to ``true``.
2764
2765 Websocket (WS) IO
2766 #################
2767
2768             .. container:: paragraph
2769
2770                APEX supports the Websockets as input as well as output.
2771                WS IO is supported by the APEX Websocket plugin. This
2772                carrier technology does only support uni-directional
2773                communication. APEX will not send events to a Websocket
2774                input and any event sent to a Websocket output will
2775                result in an error log.
2776
2777             .. container:: paragraph
2778
2779                The input can be configured as client (APEX connects to
2780                an existing Websocket server) or server (APEX starts a
2781                Websocket server). The same applies to the output. Input
2782                and output can both use a client or a server
2783                configuration, or separate configurations (input as
2784                client and output as server, input as server and output
2785                as client). Each configuration should use its own
2786                dedicated port to avoid any communication loops. The
2787                configuration of a Websocket client is the same for input
2788                and output. The configuration of a Websocket server is
2789                the same for input and output.
2790
2791 Websocket Client
2792 ================
2793
2794                .. container:: paragraph
2795
2796                   APEX will connect to a given Websocket server. As
2797                   input, it will receive events from the server but not
2798                   send any events. As output, it will send events to the
2799                   server and any event received from the server will
2800                   result in an error log.
2801
2802                .. container:: listingblock
2803
2804                   .. container:: content
2805
2806                      .. code::
2807
2808                         "carrierTechnologyParameters" : {
2809                           "carrierTechnology" : "WEBSOCKET", (1)
2810                           "parameterClassName" :
2811                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2812                           "parameters" : {
2813                             "host" : "localhost", (2)
2814                             "port" : 42451 (3)
2815                           }
2816                         }
2817
2818                .. container:: colist arabic
2819
2820                   +-------+------------------------------------------------------+
2821                   | **1** | set Websocket as carrier technology                  |
2822                   +-------+------------------------------------------------------+
2823                   | **2** | the host name on which a Websocket server is running |
2824                   +-------+------------------------------------------------------+
2825                   | **3** | the port of that Websocket server                    |
2826                   +-------+------------------------------------------------------+
2827
2828 Websocket Server
2829 ================
2830
2831                .. container:: paragraph
2832
2833                   APEX will start a Websocket server, which will accept
2834                   any Websocket clients to connect. As input, it will
2835                   receive events from the server but not send any
2836                   events. As output, it will send events to the server
2837                   and any event received from the server will result in
2838                   an error log.
2839
2840                .. container:: listingblock
2841
2842                   .. container:: content
2843
2844                      .. code::
2845
2846                         "carrierTechnologyParameters" : {
2847                           "carrierTechnology" : "WEBSOCKET", (1)
2848                           "parameterClassName" :
2849                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2850                           "parameters" : {
2851                             "wsClient" : false, (2)
2852                             "port"     : 42450 (3)
2853                           }
2854                         }
2855
2856                .. container:: colist arabic
2857
2858                   +-------+------------------------------------------------------------+
2859                   | **1** | set Websocket as carrier technology                        |
2860                   +-------+------------------------------------------------------------+
2861                   | **2** | disable client, so that APEX will start a Websocket server |
2862                   +-------+------------------------------------------------------------+
2863                   | **3** | the port for the Websocket server APEX will start          |
2864                   +-------+------------------------------------------------------------+
2865
2866 REST Client IO
2867 ##############
2868
2869             .. container:: paragraph
2870
2871                APEX can act as REST client on the input as well as on
2872                the output interface. The media type is
2873                ``application/json``, so this plugin only works with
2874                the JSON Event protocol.
2875
2876 REST Client Input
2877 =================
2878
2879                .. container:: paragraph
2880
2881                   APEX will connect to a given URL to receive events,
2882                   but not send any events. The server is polled, i.e.
2883                   APEX will do an HTTP GET, take the result, and then do
2884                   the next GET. Any required timing needs to be handled
2885                   by the server configured via the URL. For instance,
2886                   the server could support a wait timeout via the URL as
2887                   ``?timeout=100ms``.
2888                   The httpCodeFilter is used for filtering the status
2889                   code, and it can be configured as a regular expression
2890                   string. The default httpCodeFilter is "[2][0-9][0-9]"
2891                   - for successful response codes.
2892                   The response with HTTP status code that matches the
2893                   given regular expression is forwarded to the task,
2894                   otherwise it is logged as a failure.
2895
2896                .. container:: listingblock
2897
2898                   .. container:: content
2899
2900                      .. code::
2901
2902                         "carrierTechnologyParameters" : {
2903                           "carrierTechnology" : "RESTCLIENT", (1)
2904                           "parameterClassName" :
2905                             "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2906                           "parameters" : {
2907                             "url" : "http://example.org:8080/triggers/events", (2)
2908                             "httpMethod": "GET", (3)
2909                             "httpCodeFilter" : "[2][0-9][0-9]", (4)
2910                              "httpHeaders" : [ (5)
2911                                 ["Keep-Alive", "300"],
2912                                 ["Cache-Control", "no-cache"]
2913                              ]
2914                           }
2915                         }
2916
2917                .. container:: colist arabic
2918
2919                   +-------+--------------------------------------------------+
2920                   | **1** | set REST client as carrier technology            |
2921                   +-------+--------------------------------------------------+
2922                   | **2** | the URL of the HTTP server for events            |
2923                   +-------+--------------------------------------------------+
2924                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
2925                   |       | optional, defaults to GET                        |
2926                   +-------+--------------------------------------------------+
2927                   | **4** | use HTTP CODE FILTER for filtering status code,  |
2928                   |       | optional, defaults to [2][0-9][0-9]              |
2929                   +-------+--------------------------------------------------+
2930                   | **5** | HTTP headers to use on the REST request,         |
2931                   |       | optional                                         |
2932                   +-------+--------------------------------------------------+
2933
2934 REST Client Output
2935 ==================
2936
2937                .. container:: paragraph
2938
2939                   APEX will connect to a given URL to send events, but
2940                   not receive any events. The default HTTP operation is
2941                   POST (no configuration required). To change it to PUT
2942                   simply add the configuration parameter (as shown in
2943                   the example below).
2944                   The URL can be configured statically or tagged
2945                   as ``?example.{site}.org:8080/{trig}/events``,
2946                   all tags such as ``site`` and ``trig`` in the URL
2947                   need to be set in the properties object available to
2948                   the tasks. In addition, the keys should exactly match
2949                   with the tags defined in url. The scope of the properties
2950                   object is per HTTP call. Hence, key/value pairs set
2951                   in the properties object by task are only available
2952                   for that specific HTTP call.
2953
2954                .. container:: listingblock
2955
2956                   .. container:: content
2957
2958                      .. code::
2959
2960                         "carrierTechnologyParameters" : {
2961                           "carrierTechnology" : "RESTCLIENT", (1)
2962                           "parameterClassName" :
2963                             "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2964                           "parameters" : {
2965                             "url" : "http://example.com:8888/actions/events", (2)
2966                             "url" : "http://example.{site}.com:8888/{trig}/events", (2')
2967                             "httpMethod" : "PUT". (3)
2968                             "httpHeaders" : [ (4)
2969                                ["Keep-Alive", "300"],
2970                                ["Cache-Control", "no-cache"]
2971                             ]                          }
2972                         }
2973
2974                .. container:: colist arabic
2975
2976                   +-------+--------------------------------------------------+
2977                   | **1** | set REST client as carrier technology            |
2978                   +-------+--------------------------------------------------+
2979                   | **2** | the static URL of the HTTP server for events     |
2980                   +-------+--------------------------------------------------+
2981                   | **2'**| the tagged URL of the HTTP server for events     |
2982                   +-------+--------------------------------------------------+
2983                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
2984                   |       | optional, defaults to POST                       |
2985                   +-------+--------------------------------------------------+
2986                   | **4** | HTTP headers to use on the REST request,         |
2987                   |       | optional                                         |
2988                   +-------+--------------------------------------------------+
2989
2990 REST Server IO
2991 ##############
2992
2993             .. container:: paragraph
2994
2995                APEX supports a REST server for input and output.
2996
2997             .. container:: paragraph
2998
2999                The REST server plugin always uses a synchronous mode. A
3000                client does a HTTP GET on the APEX REST server with the
3001                input event and receives the generated output event in
3002                the server reply. This means that for the REST server
3003                there has to always to be an input with an associated
3004                output. Input or output only are not permitted.
3005
3006             .. container:: paragraph
3007
3008                The plugin will start a Grizzly server as REST server for
3009                a normal APEX engine. If the APEX engine is executed as a
3010                servlet, for instance inside Tomcat, then Tomcat will be
3011                used as REST server (this case requires configuration on
3012                Tomcat as well).
3013
3014             .. container:: paragraph
3015
3016                Some configuration restrictions apply for all scenarios:
3017
3018             .. container:: ulist
3019
3020                -  Minimum port: 1024
3021
3022                -  Maximum port: 65535
3023
3024                -  The media type is ``application/json``, so this plugin
3025                   only works with the JSON Event protocol.
3026
3027             .. container:: paragraph
3028
3029                The URL the client calls is created using
3030
3031             .. container:: ulist
3032
3033                -  the configured host and port, e.g.
3034                   ``http://localhost:12345``
3035
3036                -  the standard path, e.g. ``/apex/``
3037
3038                -  the name of the input/output, e.g. ``FirstConsumer/``
3039
3040                -  the input or output name, e.g. ``EventIn``.
3041
3042             .. container:: paragraph
3043
3044                The examples above lead to the URL
3045                ``http://localhost:12345/apex/FirstConsumer/EventIn``.
3046
3047             .. container:: paragraph
3048
3049                A client can also get status information of the REST
3050                server using ``/Status``, e.g.
3051                ``http://localhost:12345/apex/FirstConsumer/Status``.
3052
3053 REST Server Stand-alone
3054 =======================
3055
3056                .. container:: paragraph
3057
3058                   We need to configure a REST server input and a REST
3059                   server output. Input and output are associated with
3060                   each other via there name.
3061
3062                .. container:: paragraph
3063
3064                   Timeouts for REST calls need to be set carefully. If
3065                   they are too short, the call might timeout before a
3066                   policy finished creating an event.
3067
3068                .. container:: paragraph
3069
3070                   The following example configures the input named as
3071                   ``MyConsumer`` and associates an output named
3072                   ``MyProducer`` with it.
3073
3074                .. container:: listingblock
3075
3076                   .. container:: content
3077
3078                      .. code::
3079
3080                         "eventInputParameters": {
3081                           "MyConsumer": {
3082                             "carrierTechnologyParameters" : {
3083                               "carrierTechnology" : "RESTSERVER", (1)
3084                               "parameterClassName" :
3085                                 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters",
3086                               "parameters" : {
3087                                 "standalone" : true, (2)
3088                                 "host" : "localhost", (3)
3089                                 "port" : 12345 (4)
3090                               }
3091                             },
3092                             "eventProtocolParameters":{
3093                               "eventProtocol" : "JSON" (5)
3094                             },
3095                             "synchronousMode"    : true, (6)
3096                             "synchronousPeer"    : "MyProducer", (7)
3097                             "synchronousTimeout" : 500 (8)
3098                           }
3099                         }
3100
3101                .. container:: colist arabic
3102
3103                   +-------+---------------------------------------+
3104                   | **1** | set REST server as carrier technology |
3105                   +-------+---------------------------------------+
3106                   | **2** | set the server as stand-alone         |
3107                   +-------+---------------------------------------+
3108                   | **3** | set the server host                   |
3109                   +-------+---------------------------------------+
3110                   | **4** | set the server listen port            |
3111                   +-------+---------------------------------------+
3112                   | **5** | use JSON event protocol               |
3113                   +-------+---------------------------------------+
3114                   | **6** | activate synchronous mode             |
3115                   +-------+---------------------------------------+
3116                   | **7** | associate an output ``MyProducer``    |
3117                   +-------+---------------------------------------+
3118                   | **8** | set a timeout of 500 milliseconds     |
3119                   +-------+---------------------------------------+
3120
3121                .. container:: paragraph
3122
3123                   The following example configures the output named as
3124                   ``MyProducer`` and associates the input ``MyConsumer``
3125                   with it. Note that for the output there are no more
3126                   paramters (such as host or port), since they are
3127                   already configured in the associated input
3128
3129                .. container:: listingblock
3130
3131                   .. container:: content
3132
3133                      .. code::
3134
3135                         "eventOutputParameters": {
3136                           "MyProducer": {
3137                             "carrierTechnologyParameters":{
3138                               "carrierTechnology" : "RESTSERVER",
3139                               "parameterClassName" :
3140                                 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters"
3141                             },
3142                             "eventProtocolParameters":{
3143                               "eventProtocol" : "JSON"
3144                             },
3145                             "synchronousMode"    : true,
3146                             "synchronousPeer"    : "MyConsumer",
3147                             "synchronousTimeout" : 500
3148                           }
3149                         }
3150
3151 REST Server Stand-alone, multi input
3152 ====================================
3153
3154                .. container:: paragraph
3155
3156                   Any number of input/output pairs for REST servers can
3157                   be configured. For instance, we can configure an input
3158                   ``FirstConsumer`` with output ``FirstProducer`` and an
3159                   input ``SecondConsumer`` with output
3160                   ``SecondProducer``. Important is that there is always
3161                   one pair of input/output.
3162
3163 REST Server Stand-alone in Servlet
3164 ==================================
3165
3166                .. container:: paragraph
3167
3168                   If APEX is executed as a servlet, e.g. inside Tomcat,
3169                   the configuration becomes easier since the plugin can
3170                   now use Tomcat as the REST server. In this scenario,
3171                   there are not parameters (port, host, etc.) and the
3172                   key ``standalone`` must not be used (or set to false).
3173
3174                .. container:: paragraph
3175
3176                   For the Tomcat configuration, we need to add the REST
3177                   server plugin, e.g.
3178
3179                .. container:: listingblock
3180
3181                   .. container:: content
3182
3183                      .. code::
3184
3185                         <servlet>
3186                           ...
3187                           <init-param>
3188                             ...
3189                             <param-value>org.onap.policy.apex.plugins.event.carrier.restserver</param-value>
3190                           </init-param>
3191                           ...
3192                         </servlet>
3193
3194 REST Requestor IO
3195 #################
3196
3197             .. container:: paragraph
3198
3199                APEX can act as REST requestor on the input as well as on
3200                the output interface. The media type is
3201                ``application/json``, so this plugin only works with
3202                the JSON Event protocol. This plugin allows APEX to send REST requests
3203                and to receive the reply of that request without tying up APEX resources
3204                while the request is being processed. The REST Requestor pairs a REST
3205                requestor producer and consumer together to handle the REST request
3206                and response. The REST request is created from an APEX output event
3207                and the REST response is input into APEX as a new input event.
3208
3209 REST Requestor Output (REST Request Producer)
3210 =============================================
3211
3212                .. container:: paragraph
3213
3214                   APEX sends a REST request when events are output by APEX, the REST
3215                   request configuration is specified on the REST Request Consumer (see
3216                   below).
3217
3218                .. container:: listingblock
3219
3220                   .. container:: content
3221
3222                      .. code::
3223
3224                         "carrierTechnologyParameters": {
3225                           "carrierTechnology": "RESTREQUESTOR", (1)
3226                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters"
3227                         },
3228
3229                .. container:: colist arabic
3230
3231                   +-------+------------------------------------------+
3232                   | **1** | set REST requestor as carrier technology |
3233                   +-------+------------------------------------------+
3234
3235                .. container:: paragraph
3236
3237                   The settings below are required on the producer to
3238                   define the event that triggers the REST request and
3239                   to specify the peered consumer configuration for the
3240                   REST request, for example:
3241
3242                .. container:: listingblock
3243
3244                   .. container:: content
3245
3246                      .. code::
3247
3248                         "eventNameFilter": "GuardRequestEvent", (1)
3249                         "requestorMode": true, (2)
3250                         "requestorPeer": "GuardRequestorConsumer", (3)
3251                         "requestorTimeout": 500 (4)
3252
3253                .. container:: colist arabic
3254
3255                   +-------+-------------------------------------------+
3256                   | **1** | a filter on the event                     |
3257                   +-------+-------------------------------------------+
3258                   | **2** | requestor mode must be set to *true*      |
3259                   +-------+-------------------------------------------+
3260                   | **3** | the peered consumer for REST requests,    |
3261                   |       | that consumer specifies the full          |
3262                   |       | configuration for REST requests           |
3263                   +-------+-------------------------------------------+
3264                   | **4** | the request timeout in milliseconds,      |
3265                   |       | overridden by timeout on consumer if that |
3266                   |       | is set, optional defaults to 500          |
3267                   |       | millisconds                               |
3268                   +-------+-------------------------------------------+
3269
3270 REST Requestor Input (REST Request Consumer)
3271 ============================================
3272
3273                .. container:: paragraph
3274
3275                   APEX will connect to a given URL to issue a REST request and
3276                   wait for a REST response.
3277                   The URL can be configured statically or tagged
3278                   as ``?example.{site}.org:8080/{trig}/events``,
3279                   all tags such as ``site`` and ``trig`` in the URL
3280                   need to be set in the properties object available to
3281                   the tasks. In addition, the keys should exactly match
3282                   with the tags defined in url. The scope of the properties
3283                   object is per HTTP call. Hence, key/value pairs set
3284                   in the properties object by task are only available
3285                   for that specific HTTP call.
3286                   The httpCodeFilter is used for filtering the status
3287                   code, and it can be configured as a regular expression
3288                   string. The default httpCodeFilter is "[2][0-9][0-9]"
3289                   - for successful response codes.
3290                   The response with HTTP status code that matches the
3291                   given regular expression is forwarded to the task,
3292                   otherwise it is logged as a failure.
3293
3294                .. container:: listingblock
3295
3296                   .. container:: content
3297
3298                      .. code::
3299
3300                         "carrierTechnologyParameters": {
3301                           "carrierTechnology": "RESTREQUESTOR", (1)
3302                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters",
3303                           "parameters": {
3304                             "url": "http://localhost:54321/some/path/to/rest/resource", (2)
3305                             "url": "http://localhost:54321/{site}/path/to/rest/{resValue}", (2')
3306                             "httpMethod": "POST", (3)
3307                             "requestorMode": true, (4)
3308                             "requestorPeer": "GuardRequestorProducer", (5)
3309                             "restRequestTimeout": 2000, (6)
3310                             "httpCodeFilter" : "[2][0-9][0-9]" (7)
3311                             "httpHeaders" : [ (8)
3312                                ["Keep-Alive", "300"],
3313                                ["Cache-Control", "no-cache"]
3314                             ]                          }
3315                         },
3316
3317                .. container:: colist arabic
3318
3319                   +-------+--------------------------------------------------+
3320                   | **1** | set REST requestor as carrier technology         |
3321                   +-------+--------------------------------------------------+
3322                   | **2** | the static URL of the HTTP server for events     |
3323                   +-------+--------------------------------------------------+
3324                   | **2'**| the tagged URL of the HTTP server for events     |
3325                   +-------+--------------------------------------------------+
3326                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
3327                   |       | optional, defaults to GET                        |
3328                   +-------+--------------------------------------------------+
3329                   | **4** | requestor mode must be set to *true*             |
3330                   +-------+--------------------------------------------------+
3331                   | **5** | the peered producer for REST requests, that      |
3332                   |       | producer specifies the APEX output event that    |
3333                   |       | triggers the REST request                        |
3334                   +-------+--------------------------------------------------+
3335                   | **6** | request timeout in milliseconds, overrides any   |
3336                   |       | value set in the REST Requestor Producer,        |
3337                   |       | optional, defaults to 500 millisconds            |
3338                   +-------+--------------------------------------------------+
3339                   | **7** | use HTTP CODE FILTER for filtering status code   |
3340                   |       | optional, defaults to [2][0-9][0-9]              |
3341                   +-------+--------------------------------------------------+
3342                   | **8** | HTTP headers to use on the REST request,         |
3343                   |       | optional                                         |
3344                   +-------+--------------------------------------------------+
3345
3346                .. container:: paragraph
3347
3348                   Further settings may be required on the consumer to
3349                   define the input event that is produced and forwarded into
3350                   APEX, for example:
3351
3352                .. container:: listingblock
3353
3354                   .. container:: content
3355
3356                      .. code::
3357
3358                         "eventName": "GuardResponseEvent", (1)
3359                         "eventNameFilter": "GuardResponseEvent" (2)
3360
3361                .. container:: colist arabic
3362
3363                   +-------+---------------------------+
3364                   | **1** | the event name            |
3365                   +-------+---------------------------+
3366                   | **2** | a filter on the event     |
3367                   +-------+---------------------------+
3368
3369 gRPC IO
3370 #######
3371
3372             .. container:: paragraph
3373
3374                APEX can send requests over gRPC at the output side, and get back
3375                response at the input side. This can be used to send requests to CDS
3376                over gRPC. The media type is ``application/json``, so this plugin
3377                only works with the JSON Event protocol.
3378
3379 gRPC Output
3380 ===========
3381
3382                .. container:: paragraph
3383
3384                   APEX will connect to a given host to send a request over
3385                   gRPC.
3386
3387                .. container:: listingblock
3388
3389                   .. container:: content
3390
3391                      .. code::
3392
3393                         "carrierTechnologyParameters": {
3394                           "carrierTechnology": "GRPC", (1)
3395                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters",
3396                           "parameters": {
3397                             "host": "cds-blueprints-processor-grpc", (2)
3398                             "port": 9111, (2')
3399                             "username": "ccsdkapps", (3)
3400                             "password": ccsdkapps, (4)
3401                             "timeout" : 10 (5)
3402                           }
3403                         },
3404
3405                .. container:: colist arabic
3406
3407                   +-------+--------------------------------------------------+
3408                   | **1** | set GRPC as carrier technology                   |
3409                   +-------+--------------------------------------------------+
3410                   | **2** | the host to which request is sent                |
3411                   +-------+--------------------------------------------------+
3412                   | **2'**| the value for port                               |
3413                   +-------+--------------------------------------------------+
3414                   | **3** | username required to initiate connection         |
3415                   +-------+--------------------------------------------------+
3416                   | **4** | password required to initiate connection         |
3417                   +-------+--------------------------------------------------+
3418                   | **5** | the timeout value for completing the request     |
3419                   +-------+--------------------------------------------------+
3420
3421                .. container:: paragraph
3422
3423                   Further settings are required on the producer to
3424                   define the event that is requested, for example:
3425
3426                .. container:: listingblock
3427
3428                   .. container:: content
3429
3430                      .. code::
3431
3432                         "eventName": "GRPCRequestEvent", (1)
3433                         "eventNameFilter": "GRPCRequestEvent", (2)
3434                         "requestorMode": true, (3)
3435                         "requestorPeer": "GRPCRequestConsumer", (4)
3436                         "requestorTimeout": 500 (5)
3437
3438                .. container:: colist arabic
3439
3440                   +-------+---------------------------+
3441                   | **1** | the event name            |
3442                   +-------+---------------------------+
3443                   | **2** | a filter on the event     |
3444                   +-------+---------------------------+
3445                   | **3** | the mode of the requestor |
3446                   +-------+---------------------------+
3447                   | **4** | a peer for the requestor  |
3448                   +-------+---------------------------+
3449                   | **5** | a general request timeout |
3450                   +-------+---------------------------+
3451
3452 gRPC Input
3453 ==========
3454
3455                .. container:: paragraph
3456
3457                   APEX will connect to the host specified in the producer
3458                   side, anad take in response back at the consumer side.
3459
3460                .. container:: listingblock
3461
3462                   .. container:: content
3463
3464                      .. code::
3465
3466                         "carrierTechnologyParameters": {
3467                           "carrierTechnology": "GRPC", (1)
3468                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters"
3469                         },
3470
3471                .. container:: colist arabic
3472
3473                   +-------+------------------------------------------+
3474                   | **1** | set GRPC as carrier technology           |
3475                   +-------+------------------------------------------+
3476
3477                .. container:: paragraph
3478
3479                   Further settings are required on the consumer to
3480                   define the event that is requested, for example:
3481
3482                .. container:: listingblock
3483
3484                   .. container:: content
3485
3486                      .. code::
3487
3488                         "eventNameFilter": "GRPCResponseEvent", (1)
3489                         "requestorMode": true, (2)
3490                         "requestorPeer": "GRPCRequestProducer", (3)
3491                         "requestorTimeout": 500 (4)
3492
3493                .. container:: colist arabic
3494
3495                   +-------+---------------------------+
3496                   | **1** | a filter on the event     |
3497                   +-------+---------------------------+
3498                   | **2** | the mode of the requestor |
3499                   +-------+---------------------------+
3500                   | **3** | a peer for the requestor  |
3501                   +-------+---------------------------+
3502                   | **4** | a general request timeout |
3503                   +-------+---------------------------+
3504
3505 Event Protocols, Format and Encoding
3506 ------------------------------------
3507
3508          .. container:: paragraph
3509
3510             Event protocols define what event formats APEX can receive
3511             (input) and should send (output). They can be used in any
3512             combination for input and output, unless further restricted
3513             by a carrier technology plugin (for instance for JMS
3514             output). There can only be 1 event protocol per event
3515             plugin.
3516
3517          .. container:: paragraph
3518
3519             Supported *input* event protocols are:
3520
3521          .. container:: ulist
3522
3523             -  JSON, the event as a JSON string
3524
3525             -  APEX, an APEX event
3526
3527             -  JMS object, the event as a JMS object,
3528
3529             -  JMS text, the event as a JMS text,
3530
3531             -  XML, the event as an XML string,
3532
3533             -  YAML, the event as YAML text
3534
3535          .. container:: paragraph
3536
3537             Supported *output* event protocols are:
3538
3539          .. container:: ulist
3540
3541             -  JSON, the event as a JSON string
3542
3543             -  APEX, an APEX event
3544
3545             -  JMS object, the event as a JMS object,
3546
3547             -  JMS text, the event as a JMS text,
3548
3549             -  XML, the event as an XML string,
3550
3551             -  YAML, the event as YAML text
3552
3553          .. container:: paragraph
3554
3555             New event protocols can be added as plugins to APEX or
3556             developed outside APEX and added to an APEX deployment.
3557
3558 JSON Event
3559 ##########
3560
3561             .. container:: paragraph
3562
3563                The event protocol for JSON encoding does not require a
3564                specific plugin, it is supported by default. Furthermore,
3565                there is no difference in the configuration for the input
3566                and output interface.
3567
3568             .. container:: paragraph
3569
3570                For an input, APEX requires a well-formed JSON string.
3571                Well-formed here means according to the definitions of a
3572                policy. Any JSON string that is not defined as a trigger
3573                event (consume) will not be consumed (errors will be
3574                thrown). For output JSON events, APEX will always produce
3575                valid JSON strings according to the definition in the
3576                policy model.
3577
3578             .. container:: paragraph
3579
3580                The following JSON shows the configuration.
3581
3582             .. container:: listingblock
3583
3584                .. container:: content
3585
3586                   .. code::
3587
3588                      "eventProtocolParameters":{
3589                        "eventProtocol" : "JSON"
3590                      }
3591
3592             .. container:: paragraph
3593
3594                For JSON events, there are a few more optional
3595                parameters, which allow to define a mapping for standard
3596                event fields. An APEX event must have the fields
3597                ``name``, ``version``, ``source``, and ``target``
3598                defined. Sometimes it is not possible to configure a
3599                trigger or actioning system to use those fields. However,
3600                they might be in an event generated outside APEX (or used
3601                outside APEX) just with different names. To configure
3602                APEX to map between the different event names, simply add
3603                the following parameters to a JSON event:
3604
3605             .. container:: listingblock
3606
3607                .. container:: content
3608
3609                   .. code::
3610
3611                      "eventProtocolParameters":{
3612                        "eventProtocol" : "JSON",
3613                        "nameAlias"     : "policyName", (1)
3614                        "versionAlias"  : "policyVersion", (2)
3615                        "sourceAlias"   : "from", (3)
3616                        "targetAlias"   : "to", (4)
3617                        "nameSpaceAlias": "my.name.space" (5)
3618                      }
3619
3620             .. container:: colist arabic
3621
3622                +-----------------------------------+-----------------------------------+
3623                | **1**                             | mapping for the ``name`` field,   |
3624                |                                   | here from a field called          |
3625                |                                   | ``policyName``                    |
3626                +-----------------------------------+-----------------------------------+
3627                | **2**                             | mapping for the ``version``       |
3628                |                                   | field, here from a field called   |
3629                |                                   | ``policyVersion``                 |
3630                +-----------------------------------+-----------------------------------+
3631                | **3**                             | mapping for the ``source`` field, |
3632                |                                   | here from a field called ``from`` |
3633                |                                   | (only for an input event)         |
3634                +-----------------------------------+-----------------------------------+
3635                | **4**                             | mapping for the ``target`` field, |
3636                |                                   | here from a field called ``to``   |
3637                |                                   | (only for an output event)        |
3638                +-----------------------------------+-----------------------------------+
3639                | **5**                             | mapping for the ``nameSpace``     |
3640                |                                   | field, here from a field called   |
3641                |                                   | ``my.name.space``                 |
3642                +-----------------------------------+-----------------------------------+
3643
3644 APEX Event
3645 ##########
3646             .. container:: paragraph
3647
3648                The event protocol for APEX events does not require a
3649                specific plugin, it is supported by default. Furthermore,
3650                there is no difference in the configuration for the input
3651                and output interface.
3652
3653             .. container:: paragraph
3654
3655                For input and output APEX uses APEX events.
3656
3657             .. container:: paragraph
3658
3659                The following JSON shows the configuration.
3660
3661             .. container:: listingblock
3662
3663                .. container:: content
3664
3665                   .. code::
3666
3667                      "eventProtocolParameters":{
3668                        "eventProtocol" : "APEX"
3669                      }
3670
3671 JMS Event
3672 #########
3673
3674             .. container:: paragraph
3675
3676                The event protocol for JMS is provided by the APEX JMS
3677                plugin. The plugin supports encoding as JSON text or as
3678                object. There is no difference in the configuration for
3679                the input and output interface.
3680
3681 JMS Text
3682 ========
3683                .. container:: paragraph
3684
3685                   If used as input, APEX will take a JMS message and
3686                   extract a JSON string, then proceed as if a JSON event
3687                   was received. If used as output, APEX will take the
3688                   event produced by a policy, create a JSON string, and
3689                   then wrap it into a JMS message.
3690
3691                .. container:: paragraph
3692
3693                   The configuration for JMS text is as follows:
3694
3695                .. container:: listingblock
3696
3697                   .. container:: content
3698
3699                      .. code::
3700
3701                         "eventProtocolParameters":{
3702                           "eventProtocol" : "JMSTEXT",
3703                           "parameterClassName" :
3704                             "org.onap.policy.apex.plugins.event.protocol.jms.JMSTextEventProtocolParameters"
3705                         }
3706
3707 JMS Object
3708 ==========
3709                .. container:: paragraph
3710
3711                   If used as input, APEX will will take a JMS message,
3712                   extract a Java Bean from the ``ObjectMessage``
3713                   message, construct an APEX event and put the bean on
3714                   the APEX event as a parameter. If used as output, APEX
3715                   will take the event produced by a policy, create a
3716                   Java Bean and send it as a JMS message.
3717
3718                .. container:: paragraph
3719
3720                   The configuration for JMS object is as follows:
3721
3722                .. container:: listingblock
3723
3724                   .. container:: content
3725
3726                      .. code::
3727
3728                         "eventProtocolParameters":{
3729                           "eventProtocol" : "JMSOBJECT",
3730                           "parameterClassName" :
3731                             "org.onap.policy.apex.plugins.event.protocol.jms.JMSObjectEventProtocolParameters"
3732                         }
3733
3734 YAML Event
3735 ##########
3736
3737             .. container:: paragraph
3738
3739                The event protocol for YAML is provided by the APEX YAML
3740                plugin. There is no difference in the configuration for
3741                the input and output interface.
3742
3743             .. container:: paragraph
3744
3745                If used as input, APEX will consume events as YAML and
3746                map them to policy trigger events. Not well-formed YAML
3747                and not understood trigger events will be rejected. If
3748                used as output, APEX produce YAML encoded events from the
3749                event a policy produces. Those events will always be
3750                well-formed according to the definition in the policy
3751                model.
3752
3753             .. container:: paragraph
3754
3755                The following code shows the configuration.
3756
3757             .. container:: listingblock
3758
3759                .. container:: content
3760
3761                   .. code::
3762
3763                      "eventProtocolParameters":{
3764                        "eventProtocol" : "XML",
3765                        "parameterClassName" :
3766                            "org.onap.policy.apex.plugins.event.protocol.yaml.YamlEventProtocolParameters"
3767                      }
3768
3769 XML Event
3770 #########
3771             .. container:: paragraph
3772
3773                The event protocol for XML is provided by the APEX XML
3774                plugin. There is no difference in the configuration for
3775                the input and output interface.
3776
3777             .. container:: paragraph
3778
3779                If used as input, APEX will consume events as XML and map
3780                them to policy trigger events. Not well-formed XML and
3781                not understood trigger events will be rejected. If used
3782                as output, APEX produce XML encoded events from the event
3783                a policy produces. Those events will always be
3784                well-formed according to the definition in the policy
3785                model.
3786
3787             .. container:: paragraph
3788
3789                The following code shows the configuration.
3790
3791             .. container:: listingblock
3792
3793                .. container:: content
3794
3795                   .. code::
3796
3797                      "eventProtocolParameters":{
3798                        "eventProtocol" : "XML",
3799                        "parameterClassName" :
3800                            "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3801                      }
3802
3803 A configuration example
3804 -----------------------
3805
3806          .. container:: paragraph
3807
3808             The following example loads all available plug-ins.
3809
3810          .. container:: paragraph
3811
3812             Events are consumed from a Websocket, APEX as client.
3813             Consumed event format is JSON.
3814
3815          .. container:: paragraph
3816
3817             Events are produced to Kafka. Produced event format is XML.
3818
3819          .. container:: listingblock
3820
3821             .. container:: content
3822
3823                .. code::
3824
3825                   {
3826                     "engineServiceParameters" : {
3827                       "name"          : "MyApexEngine",
3828                       "version"        : "0.0.1",
3829                       "id"             :  45,
3830                       "instanceCount"  : 4,
3831                       "deploymentPort" : 12345,
3832                       "engineParameters"    : {
3833                         "executorParameters" : {
3834                           "JAVASCRIPT" : {
3835                             "parameterClassName" :
3836                                 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
3837                           },
3838                           "JYTHON" : {
3839                             "parameterClassName" :
3840                                 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
3841                           },
3842                           "JRUBY" : {
3843                             "parameterClassName" :
3844                                 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
3845                           },
3846                           "JAVA" : {
3847                             "parameterClassName" :
3848                                 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
3849                           },
3850                           "MVEL" : {
3851                             "parameterClassName" :
3852                                 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
3853                           }
3854                         },
3855                         "contextParameters" : {
3856                           "parameterClassName" :
3857                               "org.onap.policy.apex.context.parameters.ContextParameters",
3858                           "schemaParameters" : {
3859                             "Avro":{
3860                                "parameterClassName" :
3861                                    "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
3862                             }
3863                           }
3864                         }
3865                       }
3866                     },
3867                     "producerCarrierTechnologyParameters" : {
3868                       "carrierTechnology" : "KAFKA",
3869                       "parameterClassName" :
3870                           "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
3871                       "parameters" : {
3872                         "bootstrapServers"  : "localhost:49092",
3873                         "acks"              : "all",
3874                         "retries"           : 0,
3875                         "batchSize"         : 16384,
3876                         "lingerTime"        : 1,
3877                         "bufferMemory"      : 33554432,
3878                         "producerTopic"     : "apex-out",
3879                         "keySerializer"     : "org.apache.kafka.common.serialization.StringSerializer",
3880                         "valueSerializer"   : "org.apache.kafka.common.serialization.StringSerializer"
3881                       }
3882                     },
3883                     "producerEventProtocolParameters" : {
3884                       "eventProtocol" : "XML",
3885                            "parameterClassName" :
3886                                "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3887                     },
3888                     "consumerCarrierTechnologyParameters" : {
3889                       "carrierTechnology" : "WEBSOCKET",
3890                       "parameterClassName" :
3891                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
3892                       "parameters" : {
3893                         "host" : "localhost",
3894                         "port" : 88888
3895                       }
3896                     },
3897                     "consumerEventProtocolParameters" : {
3898                       "eventProtocol" : "JSON"
3899                     }
3900                   }
3901
3902 Engine and Applications of the APEX System
3903 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3904
3905 Introduction to APEX Engine and Applications
3906 --------------------------------------------
3907
3908          .. container:: paragraph
3909
3910             The core of APEX is the APEX Engine, also known as the APEX
3911             Policy Engine or the APEX PDP (since it is in fact a Policy
3912             Decision Point). Beside this engine, an APEX system comes
3913             with a few applications intended to help with policy
3914             authoring, deployment, and execution.
3915
3916          .. container:: paragraph
3917
3918             The engine itself and most applications are started from the
3919             command line with command line arguments. This is called a
3920             Command Line Interface (CLI). Some applications require an
3921             installation on a webserver, as for instance the REST
3922             Editor. Those applications can be accessed via a web
3923             browser.
3924
3925          .. container:: paragraph
3926
3927             You can also use the available APEX APIs and applications to
3928             develop other applications as required. This includes policy
3929             languages (and associated parsers and compilers /
3930             interpreters), GUIs to access APEX or to define policies,
3931             clients to connect to APEX, etc.
3932
3933          .. container:: paragraph
3934
3935             For this documentation, we assume an installation of APEX as
3936             a full system based on a current ONAP release.
3937
3938 CLI on Unix, Windows, and Cygwin
3939 --------------------------------
3940
3941          .. container:: paragraph
3942
3943             A note on APEX CLI applications: all applications and the
3944             engine itself have been deployed and tested on different
3945             operating systems: Red Hat, Ubuntu, Debian, Mac OSX,
3946             Windows, Cygwin. Each operating system comes with its own
3947             way of configuring and executing Java. The main items here
3948             are:
3949
3950          .. container:: ulist
3951
3952             -  For UNIX systems (RHL, Ubuntu, Debian, Mac OSX), the
3953                provided bash scripts work as expected with absolute
3954                paths (e.g.
3955                ``/opt/app/policy/apex-pdp/apex-pdp-2.0.0-SNAPSHOT/examples``),
3956                indirect and linked paths (e.g. ``../apex/apex``), and
3957                path substitutions using environment settings (e.g.
3958                ``$APEX_HOME/bin/``)
3959
3960             -  For Windows systems, the provided batch files (``.bat``)
3961                work as expected with with absolute paths (e.g.
3962                ``C:\apex\apex-2.0.0-SNAPSHOT\examples``), and path
3963                substitutions using environment settings (e.g.
3964                ``%APEX_HOME%\bin\``)
3965
3966             -  For Cygwin system we assume a standard Cygwin
3967                installation with standard tools (mainly bash) using a
3968                Windows Java installation. This means that the bash
3969                scripts can be used as in UNIX, however any argument
3970                pointing to files and directories need to use either a
3971                DOS path (e.g.
3972                ``C:\apex\apex-2.0.0-SNAPSHOT\examples\config...``) or
3973                the command ``cygpath`` with a mixed option. The reason
3974                for that is: Cygwin executes Java using UNIX paths but
3975                then runs Java as a DOS/WINDOWS process, which requires
3976                DOS paths for file access.
3977
3978 The APEX Engine
3979 ---------------
3980
3981          .. container:: paragraph
3982
3983             The APEX engine can be started in different ways, depending
3984             your requirements. All scripts are located in the APEX *bin*
3985             directory
3986
3987          .. container:: paragraph
3988
3989             On UNIX and Cygwin systems use:
3990
3991          .. container:: ulist
3992
3993             -  ``apexEngine.sh`` - this script will
3994
3995                .. container:: ulist
3996
3997                   -  Test if ``$APEX_USER`` is set and if the user
3998                      exists, terminate with an error otherwise
3999
4000                   -  Test if ``$APEX_HOME`` is set. If not set, it will
4001                      use the default setting as
4002                      ``/opt/app/policy/apex-pdp/apex-pdp``. Then the set
4003                      directory is tested to exist, the script will
4004                      terminate if not.
4005
4006                   -  When all tests are passed successfully, the script
4007                      will call ``apexApps.sh`` with arguments to start
4008                      the APEX engine.
4009
4010             -  ``apexApps.sh engine`` - this is the general APEX
4011                application launcher, which will
4012
4013                .. container:: ulist
4014
4015                   -  Start the engine with the argument ``engine``
4016
4017                   -  Test if ``$APEX_HOME`` is set and points to an
4018                      existing directory. If not set or directory does
4019                      not exist, script terminates.
4020
4021                   -  Not test for any settings of ``$APEX_USER``.
4022
4023          .. container:: paragraph
4024
4025             On Windows systems use ``apexEngine.bat`` and
4026             ``apexApps.bat engine`` respectively. Note: none of the
4027             windows batch files will test for ``%APEX_USER%``.
4028
4029          .. container:: paragraph
4030
4031             Summary of alternatives to start the APEX Engine:
4032
4033          +--------------------------------------------------------+----------------------------------------------------------+
4034          | Unix, Cygwin                                           | Windows                                                  |
4035          +========================================================+==========================================================+
4036          | .. container::                                         | .. container::                                           |
4037          |                                                        |                                                          |
4038          |    .. container:: listingblock                         |    .. container:: listingblock                           |
4039          |                                                        |                                                          |
4040          |       .. container:: content                           |       .. container:: content                             |
4041          |                                                        |                                                          |
4042          |          .. code::                                     |          .. code::                                       |
4043          |                                                        |                                                          |
4044          |             # $APEX_HOME/bin/apexEngine.sh [args]      |             > %APEX_HOME%\bin\apexEngine.bat [args]      |
4045          |             # $APEX_HOME/bin/apexApps.sh engine [args] |             > %APEX_HOME%\bin\apexApps.bat engine [args] |
4046          +--------------------------------------------------------+----------------------------------------------------------+
4047
4048          .. container:: paragraph
4049
4050             The APEX engine comes with a few CLI arguments, the main one is for setting
4051             the tosca policy file for execution. The tosca policy file is
4052             always required. The option ``-h`` prints a help screen.
4053
4054          .. container:: listingblock
4055
4056             .. container:: content
4057
4058                .. code::
4059
4060                   usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]
4061                   options
4062                   -p,--tosca-policy-file <TOSCA_POLICY_FILE>     the full path to the ToscaPolicy file to use.
4063                   -h,--help                                      outputs the usage of this command
4064                   -v,--version                                   outputs the version of Apex
4065
4066 The APEX CLI Editor
4067 -------------------
4068
4069          .. container:: paragraph
4070
4071             The CLI Editor allows to define policies from the command
4072             line. The application uses a simple language and supports
4073             all elements of an APEX policy. It can be used in to
4074             different ways:
4075
4076          .. container:: ulist
4077
4078             -  non-interactive, specifying a file with the commands to
4079                create a policy
4080
4081             -  interactive, using the editors CLI to create a policy
4082
4083          .. container:: paragraph
4084
4085             When a policy is fully specified, the editor will generate
4086             the APEX core policy specification in JSON. This core
4087             specification is called the policy model in the APEX engine
4088             and can be used directly with the APEX engine.
4089
4090          .. container:: paragraph
4091
4092             On UNIX and Cygwin systems use:
4093
4094          .. container:: ulist
4095
4096             -  ``apexCLIEditor.sh`` - simply starts the CLI editor,
4097                arguments to the script determine the mode of the editor
4098
4099             -  ``apexApps.sh cli-editor`` - simply starts the CLI
4100                editor, arguments to the script determine the mode of the
4101                editor
4102
4103          .. container:: paragraph
4104
4105             On Windows systems use:
4106
4107          .. container:: ulist
4108
4109             -  ``apexCLIEditor.bat`` - simply starts the CLI editor,
4110                arguments to the script determine the mode of the editor
4111
4112             -  ``apexApps.bat cli-editor`` - simply starts the CLI
4113                editor, arguments to the script determine the mode of the
4114                editor
4115
4116          .. container:: paragraph
4117
4118             Summary of alternatives to start the APEX CLI Editor:
4119
4120          +------------------------------------------------------------+--------------------------------------------------------------+
4121          | Unix, Cygwin                                               | Windows                                                      |
4122          +============================================================+==============================================================+
4123          | .. container::                                             | .. container::                                               |
4124          |                                                            |                                                              |
4125          |    .. container:: listingblock                             |    .. container:: listingblock                               |
4126          |                                                            |                                                              |
4127          |       .. container:: content                               |       .. container:: content                                 |
4128          |                                                            |                                                              |
4129          |          .. code::                                         |          .. code::                                           |
4130          |                                                            |                                                              |
4131          |             # $APEX_HOME/bin/apexCLIEditor.sh.sh [args]    |             > %APEX_HOME%\bin\apexCLIEditor.bat [args]       |
4132          |             # $APEX_HOME/bin/apexApps.sh cli-editor [args] |             > %APEX_HOME%\bin\apexApps.bat cli-editor [args] |
4133          +------------------------------------------------------------+--------------------------------------------------------------+
4134
4135          .. container:: paragraph
4136
4137             The option ``-h`` provides a help screen with all command
4138             line arguments.
4139
4140          .. container:: listingblock
4141
4142             .. container:: content
4143
4144                .. code::
4145
4146                   usage: org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain [options...]
4147                   options
4148                    -a,--model-props-file <MODEL_PROPS_FILE>       name of the apex model properties file to use
4149                    -c,--command-file <COMMAND_FILE>               name of a file containing editor commands to run into the editor
4150                    -h,--help                                      outputs the usage of this command
4151                    -i,--input-model-file <INPUT_MODEL_FILE>       name of a file that contains an input model for the editor
4152                    -if,--ignore-failures <IGNORE_FAILURES_FLAG>   true or false, ignore failures of commands in command files and continue
4153                                                                   executing the command file
4154                    -l,--log-file <LOG_FILE>                       name of a file that will contain command logs from the editor, will log
4155                                                                   to standard output if not specified or suppressed with "-nl" flag
4156                    -m,--metadata-file <CMD_METADATA_FILE>         name of the command metadata file to use
4157                    -nl,--no-log                                   if specified, no logging or output of commands to standard output or log
4158                                                                   file is carried out
4159                    -nm,--no-model-output                          if specified, no output of a model to standard output or model output
4160                                                                   file is carried out, the user can use the "save" command in a script to
4161                                                                   save a model
4162                    -o,--output-model-file <OUTPUT_MODEL_FILE>     name of a file that will contain the output model for the editor, will
4163                                                                   output model to standard output if not specified or suppressed with
4164                                                                   "-nm" flag
4165                    -wd,--working-directory <WORKING_DIRECTORY>    the working directory that is the root for the CLI editor and is the
4166                                                                   root from which to look for included macro files
4167
4168 The APEX CLI Tosca Editor
4169 -------------------------
4170
4171          .. container:: paragraph
4172
4173             As per the new Policy LifeCycle API, the policies are expected to be defined as ToscaServiceTemplate. The CLI Tosca Editor is an extended version of the APEX CLI Editor which can generate the policies in ToscaServiceTemplate way.
4174
4175          .. container:: paragraph
4176
4177             The APEX config file(.json), command file(.apex) and the tosca template skeleton(.json) file paths need to be passed as input arguments to the CLI Tosca Editor. Policy in ToscaServiceTemplate format is generated as the output. This can be used as the input to Policy API for creating policies.
4178
4179          .. container:: paragraph
4180
4181             On UNIX and Cygwin systems use:
4182
4183          .. container:: ulist
4184
4185             -  ``apexCLIToscaEditor.sh`` - starts the CLI Tosca editor,
4186                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4187
4188             -  ``apexApps.sh cli-tosca-editor`` - starts the CLI Tosca editor,
4189                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4190
4191          .. container:: paragraph
4192
4193             On Windows systems use:
4194
4195          .. container:: ulist
4196
4197             -  ``apexCLIToscaEditor.bat`` - starts the CLI Tosca editor,
4198                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4199
4200             -  ``apexApps.bat cli-tosca-editor`` - starts the CLI Tosca
4201                editor, all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4202
4203          .. container:: paragraph
4204
4205             Summary of alternatives to start the APEX CLI Tosca Editor:
4206
4207      +-----------------------------------------------------------------+--------------------------------------------------------------------+
4208      | Unix, Cygwin                                                    | Windows                                                            |
4209      +=================================================================+====================================================================+
4210      | .. container::                                                  | .. container::                                                     |
4211      |                                                                 |                                                                    |
4212      |    .. container:: listingblock                                  |    .. container:: listingblock                                     |
4213      |                                                                 |                                                                    |
4214      |       .. container:: content                                    |       .. container:: content                                       |
4215      |                                                                 |                                                                    |
4216      |          .. code::                                              |          .. code::                                                 |
4217      |                                                                 |                                                                    |
4218      |             # $APEX_HOME/bin/apexCLIToscaEditor.sh.sh [args]    |             > %APEX_HOME%\bin\apexCLIToscaEditor.bat [args]        |
4219      |             # $APEX_HOME/bin/apexApps.sh cli-tosca-editor [args]|             > %APEX_HOME%\bin\apexApps.bat cli-tosca-editor [args] |
4220      +-----------------------------------------------------------------+--------------------------------------------------------------------+
4221
4222          .. container:: paragraph
4223
4224             The option ``-h`` provides a help screen with all command
4225             line arguments.
4226
4227          .. container:: listingblock
4228
4229             .. container:: content
4230
4231                .. code::
4232
4233                   usage: org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain [options...]
4234                   options
4235                    -a,--model-props-file <MODEL_PROPS_FILE>         name of the apex model properties file to use
4236                    -ac,--apex-config-file <APEX_CONFIG_FILE>        name of the file containing apex configuration details
4237                    -c,--command-file <COMMAND_FILE>                 name of a file containing editor commands to run into the editor
4238                    -h,--help                                        outputs the usage of this command
4239                    -i,--input-model-file <INPUT_MODEL_FILE>         name of a file that contains an input model for the editor
4240                    -if,--ignore-failures <IGNORE_FAILURES_FLAG>     true or false, ignore failures of commands in command files and
4241                                                                     continue executing the command file
4242                    -l,--log-file <LOG_FILE>                         name of a file that will contain command logs from the editor, will
4243                                                                     log to standard output if not specified or suppressed with "-nl" flag
4244                    -m,--metadata-file <CMD_METADATA_FILE>           name of the command metadata file to use
4245                    -nl,--no-log                                     if specified, no logging or output of commands to standard output or
4246                                                                     log file is carried out
4247                    -ot,--output-tosca-file <OUTPUT_TOSCA_FILE>      name of a file that will contain the output ToscaServiceTemplate
4248                    -t,--tosca-template-file <TOSCA_TEMPLATE_FILE>   name of the input file containing tosca template which needs to be
4249                                                                     updated with policy
4250                    -wd,--working-directory <WORKING_DIRECTORY>      the working directory that is the root for the CLI editor and is the
4251                                                                     root from which to look for included macro files
4252
4253          .. container:: paragraph
4254
4255             An example command to run the APEX CLI Tosca editor on windows machine is given below.
4256
4257          .. container:: listingblock
4258
4259             .. container:: content
4260
4261                .. code::
4262
4263                   %APEX_HOME%/\bin/\apexCLIToscaEditor.bat -c %APEX_HOME%\examples\PolicyModel.apex -ot %APEX_HOME%\examples\test.json  -l %APEX_HOME%\examples\test.log -ac %APEX_HOME%\examples\RESTServerStandaloneJsonEvent.json -t %APEX_HOME%\examples\ToscaTemplate.json
4264
4265
4266 The APEX Client
4267 ---------------
4268
4269          .. container:: paragraph
4270
4271             The APEX Client combines the Policy Editor, the
4272             Monitoring Client, and the Deployment Client into a single
4273             application. The standard way to use the APEX Full Client is
4274             via an installation of the *war* file on a webserver.
4275             However, the Full Client can also be started via command
4276             line. This will start a Grizzly webserver with the *war*
4277             deployed. Access to the Full Client is then via the provided
4278             URL
4279
4280          .. container:: paragraph
4281
4282             On UNIX and Cygwin systems use:
4283
4284          .. container:: ulist
4285
4286             -  ``apexApps.sh full-client`` - simply starts the webserver
4287                with the Full Client
4288
4289          .. container:: paragraph
4290
4291             On Windows systems use:
4292
4293          .. container:: ulist
4294
4295             -  ``apexApps.bat full-client`` - simply starts the
4296                webserver with the Full Client
4297
4298          .. container:: paragraph
4299
4300             The option ``-h`` provides a help screen with all command
4301             line arguments.
4302
4303          .. container:: listingblock
4304
4305             .. container:: content
4306
4307                .. code::
4308
4309                   usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4310                   -h,--help                        outputs the usage of this command
4311                   -p,--port <PORT>                 port to use for the Apex Services REST calls
4312                   -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4313
4314          .. container:: paragraph
4315
4316             If the Full Client is started without any arguments the
4317             final messages will look similar to this:
4318
4319          .. container:: listingblock
4320
4321             .. container:: content
4322
4323                .. code::
4324
4325                   Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4326                   Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4327                   INFO: Started listener bound to [localhost:18989]
4328                   Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4329                   INFO: [HttpServer] Started.
4330                   Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4331
4332          .. container:: paragraph
4333
4334             The last line states the URL on which the Monitoring Client
4335             can be accessed. The example above stated
4336             ``http://localhost:18989/apexservices``. In a web browser
4337             use the URL ``http://localhost:18989``.
4338
4339 The APEX Application Launcher
4340 -----------------------------
4341
4342          .. container:: paragraph
4343
4344             The standard applications (Engine and CLI Editor)
4345             come with dedicated start scripts. For all other APEX
4346             applications, we provide an application launcher.
4347
4348          .. container:: paragraph
4349
4350             On UNIX and Cygwin systems use:
4351
4352          .. container:: ulist
4353
4354             -  apexApps.sh\` - simply starts the application launcher
4355
4356          .. container:: paragraph
4357
4358             On Windows systems use:
4359
4360          .. container:: ulist
4361
4362             -  ``apexApps.bat`` - simply starts the application launcher
4363
4364          .. container:: paragraph
4365
4366             Summary of alternatives to start the APEX application
4367             launcher:
4368
4369          +-------------------------------------------------+---------------------------------------------------+
4370          | Unix, Cygwin                                    | Windows                                           |
4371          +=================================================+===================================================+
4372          | .. container::                                  | .. container::                                    |
4373          |                                                 |                                                   |
4374          |    .. container:: listingblock                  |    .. container:: listingblock                    |
4375          |                                                 |                                                   |
4376          |       .. container:: content                    |       .. container:: content                      |
4377          |                                                 |                                                   |
4378          |          .. code::                              |          .. code::                                |
4379          |                                                 |                                                   |
4380          |             # $APEX_HOME/bin/apexApps.sh [args] |             > %APEX_HOME%\bin\apexApps.bat [args] |
4381          +-------------------------------------------------+---------------------------------------------------+
4382
4383          .. container:: paragraph
4384
4385             The option ``-h`` provides a help screen with all launcher
4386             command line arguments.
4387
4388          .. container:: listingblock
4389
4390             .. container:: content
4391
4392                .. code::
4393
4394                   apexApps.sh - runs APEX applications
4395
4396                          Usage:  apexApps.sh [options] | [<application> [<application options>]]
4397
4398                          Options
4399                            -d <app>    - describes an application
4400                            -l          - lists all applications supported by this script
4401                            -h          - this help screen
4402
4403          .. container:: paragraph
4404
4405             Using ``-l`` lists all known application the launcher can
4406             start.
4407
4408          .. container:: listingblock
4409
4410             .. container:: content
4411
4412                .. code::
4413
4414                   apexApps.sh: supported applications:
4415                    --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4416
4417          .. container:: paragraph
4418
4419             Using the ``-d <name>`` option describes the named
4420             application, for instance for the ``ws-console``:
4421
4422          .. container:: listingblock
4423
4424             .. container:: content
4425
4426                .. code::
4427
4428                   apexApps.sh: application 'ws-console'
4429                    --> a simple console sending events to APEX, connect to APEX consumer port
4430
4431          .. container:: paragraph
4432
4433             Launching an application is done by calling the script with
4434             only the application name and any CLI arguments for the
4435             application. For instance, starting the ``ws-echo``
4436             application with port ``8888``:
4437
4438          .. container:: listingblock
4439
4440             .. container:: content
4441
4442                .. code::
4443
4444                   apexApps.sh ws-echo -p 8888
4445
4446 Application: Create Event Templates
4447 -----------------------------------
4448
4449          .. container:: paragraph
4450
4451             **Status: Experimental**
4452
4453          .. container:: paragraph
4454
4455             This application takes a policy model (JSON or XML encoded)
4456             and generates templates for events in JSON format. This can
4457             help when a policy defines rather complex trigger or action
4458             events or complex events between states. The application can
4459             produce events for the types: stimuli (policy trigger
4460             events), internal (events between policy states), and
4461             response (action events).
4462
4463          +----------------------------------------------------------------+------------------------------------------------------------------+
4464          | Unix, Cygwin                                                   | Windows                                                          |
4465          +================================================================+==================================================================+
4466          | .. container::                                                 | .. container::                                                   |
4467          |                                                                |                                                                  |
4468          |    .. container:: listingblock                                 |    .. container:: listingblock                                   |
4469          |                                                                |                                                                  |
4470          |       .. container:: content                                   |       .. container:: content                                     |
4471          |                                                                |                                                                  |
4472          |          .. code::                                             |          .. code::                                               |
4473          |                                                                |                                                                  |
4474          |             # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] |             > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4475          +----------------------------------------------------------------+------------------------------------------------------------------+
4476
4477          .. container:: paragraph
4478
4479             The option ``-h`` provides a help screen.
4480
4481          .. container:: listingblock
4482
4483             .. container:: content
4484
4485                .. code::
4486
4487                   gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4488                   usage: gen-model2event
4489                    -h,--help                 prints this help and usage screen
4490                    -m,--model <MODEL-FILE>   set the input policy model file
4491                    -t,--type <TYPE>          set the event type for generation, one of:
4492                                              stimuli (trigger events), response (action
4493                                              events), internal (events between states)
4494                    -v,--version              prints the application version
4495
4496          .. container:: paragraph
4497
4498             The created templates are not valid events, instead they use
4499             some markup for values one will need to change to actual
4500             values. For instance, running the tool with the *Sample
4501             Domain* policy model as:
4502
4503          .. container:: listingblock
4504
4505             .. container:: content
4506
4507                .. code::
4508
4509                   apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4510
4511          .. container:: paragraph
4512
4513             will produce the following status messages:
4514
4515          .. container:: listingblock
4516
4517             .. container:: content
4518
4519                .. code::
4520
4521                   gen-model2event: starting Event generator
4522                    --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4523                    --> type: stimuli
4524
4525          .. container:: paragraph
4526
4527             and then run the generator application producing two event
4528             templates. The first template is called ``Event0000``.
4529
4530          .. container:: listingblock
4531
4532             .. container:: content
4533
4534                .. code::
4535
4536                   {
4537                           "name" : "Event0000",
4538                           "nameSpace" : "org.onap.policy.apex.sample.events",
4539                           "version" : "0.0.1",
4540                           "source" : "Outside",
4541                           "target" : "Match",
4542                           "TestTemperature" : ###double: 0.0###,
4543                           "TestTimestamp" : ###long: 0###,
4544                           "TestMatchCase" : ###integer: 0###,
4545                           "TestSlogan" : "###string###"
4546                   }
4547
4548          .. container:: paragraph
4549
4550             The values for the keys are marked with ``#`` and the
4551             expected type of the value. To create an actual stimuli
4552             event, all these markers need to be change to actual values,
4553             for instance:
4554
4555          .. container:: listingblock
4556
4557             .. container:: content
4558
4559                .. code::
4560
4561                   {
4562                           "name" : "Event0000",
4563                           "nameSpace" : "org.onap.policy.apex.sample.events",
4564                           "version" : "0.0.1",
4565                           "source" : "Outside",
4566                           "target" : "Match",
4567                           "TestTemperature" : 25,
4568                           "TestTimestamp" : 123456789123456789,
4569                           "TestMatchCase" : 1,
4570                           "TestSlogan" : "Testing the Match Case with Temperature 25"
4571                   }
4572
4573 Application: Convert a Policy Model to CLI Editor Commands
4574 ----------------------------------------------------------
4575
4576          .. container:: paragraph
4577
4578             **Status: Experimental**
4579
4580          .. container:: paragraph
4581
4582             This application takes a policy model (JSON or XML encoded)
4583             and generates commands for the APEX CLI Editor. This
4584             effectively reverses a policy specification realized with
4585             the CLI Editor.
4586
4587          +-------------------------------------------------------------+---------------------------------------------------------------+
4588          | Unix, Cygwin                                                | Windows                                                       |
4589          +=============================================================+===============================================================+
4590          | .. container::                                              | .. container::                                                |
4591          |                                                             |                                                               |
4592          |    .. container:: listingblock                              |    .. container:: listingblock                                |
4593          |                                                             |                                                               |
4594          |       .. container:: content                                |       .. container:: content                                  |
4595          |                                                             |                                                               |
4596          |          .. code::                                          |          .. code::                                            |
4597          |                                                             |                                                               |
4598          |             # $APEX_HOME/bin/apexApps.sh model-2-cli [args] |             > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4599          +-------------------------------------------------------------+---------------------------------------------------------------+
4600
4601          .. container:: paragraph
4602
4603             The option ``-h`` provides a help screen.
4604
4605          .. container:: listingblock
4606
4607             .. container:: content
4608
4609                .. code::
4610
4611                   usage: gen-model2cli
4612                    -h,--help                 prints this help and usage screen
4613                    -m,--model <MODEL-FILE>   set the input policy model file
4614                    -sv,--skip-validation     switch of validation of the input file
4615                    -v,--version              prints the application version
4616
4617          .. container:: paragraph
4618
4619             For instance, running the tool with the *Sample Domain*
4620             policy model as:
4621
4622          .. container:: listingblock
4623
4624             .. container:: content
4625
4626                .. code::
4627
4628                   apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4629
4630          .. container:: paragraph
4631
4632             will produce the following status messages:
4633
4634          .. container:: listingblock
4635
4636             .. container:: content
4637
4638                .. code::
4639
4640                   gen-model2cli: starting CLI generator
4641                    --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4642
4643          .. container:: paragraph
4644
4645             and then run the generator application producing all CLI
4646             Editor commands and printing them to standard out.
4647
4648 Application: Websocket Clients (Echo and Console)
4649 -------------------------------------------------
4650
4651          .. container:: paragraph
4652
4653             **Status: Production**
4654
4655          .. container:: paragraph
4656
4657             The application launcher also provides a Websocket echo
4658             client and a Websocket console client. The echo client
4659             connects to APEX and prints all events it receives from
4660             APEX. The console client connects to APEX, reads input from
4661             the command line, and sends this input as events to APEX.
4662
4663          +------------------------------------------------------------+--------------------------------------------------------------+
4664          | Unix, Cygwin                                               | Windows                                                      |
4665          +============================================================+==============================================================+
4666          | .. container::                                             | .. container::                                               |
4667          |                                                            |                                                              |
4668          |    .. container:: listingblock                             |    .. container:: listingblock                               |
4669          |                                                            |                                                              |
4670          |       .. container:: content                               |       .. container:: content                                 |
4671          |                                                            |                                                              |
4672          |          .. code::                                         |          .. code::                                           |
4673          |                                                            |                                                              |
4674          |             # $APEX_HOME/bin/apexApps.sh ws-echo [args]    |             > %APEX_HOME%\bin\apexApps.bat ws-echo [args]    |
4675          |             # $APEX_HOME/bin/apexApps.sh ws-console [args] |             > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4676          +------------------------------------------------------------+--------------------------------------------------------------+
4677
4678          .. container:: paragraph
4679
4680             The arguments are the same for both applications:
4681
4682          .. container:: ulist
4683
4684             -  ``-p`` defines the Websocket port to connect to (defaults
4685                to ``8887``)
4686
4687             -  ``-s`` defines the host on which a Websocket server is
4688                running (defaults to ``localhost``)
4689
4690          .. container:: paragraph
4691
4692             A discussion on how to use these two applications to build
4693             an APEX system is detailed HowTo-Websockets.
4694
4695 APEX Logging
4696 ^^^^^^^^^^^^
4697
4698 Introduction to APEX Logging
4699 ----------------------------
4700
4701          .. container:: paragraph
4702
4703             All APEX components make extensive use of logging using the
4704             logging façade `SLF4J <https://www.slf4j.org/>`__ with the
4705             backend `Logback <https://logback.qos.ch/>`__. Both are used
4706             off-the-shelve, so the standard documentation and
4707             configuration apply to APEX logging. For details on how to
4708             work with logback please see the `logback
4709             manual <https://logback.qos.ch/manual/index.html>`__.
4710
4711          .. container:: paragraph
4712
4713             The APEX applications is the logback configuration file
4714             ``$APEX_HOME/etc/logback.xml`` (Windows:
4715             ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
4716             to no debug, i.e. logs from the logging framework should be
4717             hidden at runtime.
4718
4719          .. container:: paragraph
4720
4721             The configurable log levels work as expected:
4722
4723          .. container:: ulist
4724
4725             -  *error* (or *ERROR*) is used for serious errors in the
4726                APEX runtime engine
4727
4728             -  *warn* (or *WARN*) is used for warnings, which in general
4729                can be ignored but might indicate some deeper problems
4730
4731             -  *info* (or *INFO*) is used to provide generally
4732                interesting messages for startup and policy execution
4733
4734             -  *debug* (or *DEBUG*) provides more details on startup and
4735                policy execution
4736
4737             -  *trace* (or *TRACE*) gives full details on every aspect
4738                of the APEX engine from start to end
4739
4740          .. container:: paragraph
4741
4742             The loggers can also be configured as expected. The standard
4743             configuration (after installing APEX) uses log level *info*
4744             on all APEX classes (components).
4745
4746          .. container:: paragraph
4747
4748             The applications and scripts in ``$APEX_HOME/bin`` (Windows:
4749             ``%APEX_HOME\bin``) are configured to use the logback
4750             configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
4751             ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
4752             use different logback configurations, for instance:
4753
4754          .. container:: ulist
4755
4756             -  Maintain multiple configurations in ``etc``, for instance
4757                a ``logback-debug.xml`` for deep debugging and a
4758                ``logback-production.xml`` for APEX in production mode,
4759                then copy the required configuration file to the used
4760                ``logback.xml`` prior starting APEX
4761
4762             -  Edit the scripts in ``bin`` to use a different logback
4763                configuration file (only recommended if you are familiar
4764                with editing bash scripts or windows batch files)
4765
4766 Standard Logging Configuration
4767 ------------------------------
4768
4769          .. container:: paragraph
4770
4771             The standard logging configuration defines a context *APEX*,
4772             which is used in the standard output pattern. The location
4773             for log files is defined in the property ``logDir`` and set
4774             to ``/var/log/onap/policy/apex-pdp``. The standard status
4775             listener is set to *NOP* and the overall logback
4776             configuration is set to no debug.
4777
4778          .. container:: listingblock
4779
4780             .. container:: content
4781
4782                .. code::
4783                  :number-lines:
4784
4785                  <configuration debug="false">
4786                    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
4787
4788                     <contextName>Apex</contextName>
4789                     <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
4790
4791                    ...appenders
4792                    ...loggers
4793                  </configuration>
4794
4795 .. container:: paragraph
4796
4797    The first appender defined is called ``STDOUT`` for logs to standard
4798    out.
4799
4800 .. container:: listingblock
4801
4802    .. container:: content
4803
4804       .. code::
4805         :number-lines:
4806
4807         <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4808          <encoder>
4809             <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
4810           </encoder>
4811         </appender>
4812
4813 .. container:: paragraph
4814
4815    The root level logger then is set to the level *info* using the
4816    standard out appender.
4817
4818 .. container:: listingblock
4819
4820    .. container:: content
4821
4822       .. code::
4823         :number-lines:
4824
4825         <root level="info">
4826           <appender-ref ref="STDOUT" />
4827         </root>
4828
4829 .. container:: paragraph
4830
4831    The second appender is called ``FILE``. It writes logs to a file
4832    ``apex.log``.
4833
4834 .. container:: listingblock
4835
4836    .. container:: content
4837
4838       .. code::
4839         :number-lines:
4840
4841         <appender name="FILE" class="ch.qos.logback.core.FileAppender">
4842           <file>${logDir}/apex.log</file>
4843           <encoder>
4844             <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
4845           </encoder>
4846         </appender>
4847
4848 .. container:: paragraph
4849
4850    The third appender is called ``CTXT_FILE``. It writes logs to a file
4851    ``apex_ctxt.log``.
4852
4853 .. container:: listingblock
4854
4855    .. container:: content
4856
4857       .. code::
4858         :number-lines:
4859
4860         <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
4861           <file>${logDir}/apex_ctxt.log</file>
4862           <encoder>
4863             <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
4864           </encoder>
4865         </appender>
4866
4867 .. container:: paragraph
4868
4869    The last definitions are for specific loggers. The first logger
4870    captures all standard APEX classes. It is configured for log level
4871    *info* and uses the standard output and file appenders. The second
4872    logger captures APEX context classes responsible for context
4873    monitoring. It is configured for log level *trace* and uses the
4874    context file appender.
4875
4876 .. container:: listingblock
4877
4878    .. container:: content
4879
4880       .. code::
4881         :number-lines:
4882
4883
4884         <logger name="org.onap.policy.apex" level="info" additivity="false">
4885           <appender-ref ref="STDOUT" />
4886           <appender-ref ref="FILE" />
4887         </logger>
4888
4889         <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
4890           <appender-ref ref="CTXT_FILE" />
4891         </logger>
4892
4893 Adding Logback Status and Debug
4894 -------------------------------
4895
4896    .. container:: paragraph
4897
4898       To activate logback status messages change the status listener
4899       from 'NOP' to for instance console.
4900
4901    .. container:: listingblock
4902
4903       .. container:: content
4904
4905          .. code::
4906
4907             <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
4908
4909    .. container:: paragraph
4910
4911       To activate all logback debugging, for instance to debug a new
4912       logback configuration, activate the debug attribute in the
4913       configuration.
4914
4915    .. container:: listingblock
4916
4917       .. container:: content
4918
4919          .. code::
4920
4921             <configuration debug="true">
4922             ...
4923             </configuration>
4924
4925 Logging External Components
4926 ---------------------------
4927
4928    .. container:: paragraph
4929
4930       Logback can also be configured to log any other, external
4931       components APEX is using, if they are using the common logging
4932       framework.
4933
4934    .. container:: paragraph
4935
4936       For instance, the context component of APEX is using *Infinispan*
4937       and one can add a logger for this external component. The
4938       following example adds a logger for *Infinispan* using the
4939       standard output appender.
4940
4941    .. container:: listingblock
4942
4943       .. container:: content
4944
4945          .. code::
4946
4947             <logger name="org.infinispan" level="INFO" additivity="false">
4948               <appender-ref ref="STDOUT" />
4949             </logger>
4950
4951    .. container:: paragraph
4952
4953       Another example is Apache Zookeeper. The following example adds a
4954       logger for Zookeeper using the standard outout appender.
4955
4956    .. container:: listingblock
4957
4958       .. container:: content
4959
4960          .. code::
4961
4962             <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
4963               <appender-ref ref="STDOUT" />
4964             </logger>
4965
4966 Configuring loggers for Policy Logic
4967 ------------------------------------
4968
4969    .. container:: paragraph
4970
4971       The logging for the logic inside a policy (task logic, task
4972       selection logic, state finalizer logic) can be configured separate
4973       from standard logging. The logger for policy logic is
4974       ``org.onap.policy.apex.executionlogging``. The following example
4975       defines
4976
4977    .. container:: ulist
4978
4979       -  a new appender for standard out using a very simple pattern
4980          (simply the actual message)
4981
4982       -  a logger for policy logic to standard out using the new
4983          appender and the already described file appender.
4984
4985    .. container:: listingblock
4986
4987       .. container:: content
4988
4989          .. code::
4990
4991             <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4992               <encoder>
4993                 <pattern>policy: %msg\n</pattern>
4994               </encoder>
4995             </appender>
4996
4997             <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
4998               <appender-ref ref="POLICY_APPENDER_STDOUT" />
4999               <appender-ref ref="FILE" />
5000             </logger>
5001
5002    .. container:: paragraph
5003
5004       It is also possible to use specific logging for parts of policy
5005       logic. The following example defines a logger for task logic.
5006
5007    .. container:: listingblock
5008
5009       .. container:: content
5010
5011          .. code::
5012
5013             <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
5014               <appender-ref ref="POLICY_APPENDER_STDOUT" />
5015             </logger>
5016
5017 Rolling File Appenders
5018 ----------------------
5019
5020    .. container:: paragraph
5021
5022       Rolling file appenders are a good option for more complex logging
5023       of a production or complex testing APEX installation. The standard
5024       logback configuration can be used for these use cases. This
5025       section gives two examples for the standard logging and for
5026       context logging.
5027
5028    .. container:: paragraph
5029
5030       First the standard logging. The following example defines a
5031       rolling file appender. The appender rolls over on a daily basis.
5032       It allows for a file size of 100 MB.
5033
5034    .. container:: listingblock
5035
5036       .. container:: content
5037
5038          .. code::
5039
5040             <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
5041               <file>${logDir}/apex.log</file>
5042               <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
5043                 <!-- rollover daily -->
5044                 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
5045                 <fileNamePattern>${logDir}/apex_%d{yyyy-MM-dd}.%i.log.gz
5046                 </fileNamePattern>
5047                 <maxHistory>4</maxHistory>
5048                 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
5049                   <!-- or whenever the file size reaches 100MB -->
5050                   <maxFileSize>100MB</maxFileSize>
5051                 </timeBasedFileNamingAndTriggeringPolicy>
5052               </rollingPolicy>
5053               <encoder>
5054                 <pattern>
5055                   %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
5056                 </pattern>
5057               </encoder>
5058             </appender>
5059
5060    .. container:: paragraph
5061
5062       A very similar configuration can be used for a rolling file
5063       appender logging APEX context.
5064
5065    .. container:: listingblock
5066
5067       .. container:: content
5068
5069          .. code::
5070
5071             <appender name="CTXT-FILE"
5072                   class="ch.qos.logback.core.rolling.RollingFileAppender">
5073               <file>${logDir}/apex_ctxt.log</file>
5074               <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
5075                 <fileNamePattern>${logDir}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
5076                 </fileNamePattern>
5077                 <maxHistory>4</maxHistory>
5078                 <timeBasedFileNamingAndTriggeringPolicy
5079                     class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
5080                   <maxFileSize>100MB</maxFileSize>
5081                 </timeBasedFileNamingAndTriggeringPolicy>
5082               </rollingPolicy>
5083               <encoder>
5084                 <pattern>
5085                   %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
5086                 </pattern>
5087               </encoder>
5088             </appender>
5089
5090 Example Configuration for Logging Logic
5091 ---------------------------------------
5092
5093    .. container:: paragraph
5094
5095       The following example shows a configuration that logs policy logic
5096       to standard out and a file (*info*). All other APEX components are
5097       logging to a file (*debug*).. This configuration an be used in a
5098       pre-production phase with the APEX engine still running in a
5099       separate terminal to monitor policy execution. This logback
5100       configuration is in the APEX installation as
5101       ``etc/logback-logic.xml``.
5102
5103    .. container:: listingblock
5104
5105       .. container:: content
5106
5107          .. code::
5108
5109             <configuration debug="false">
5110                 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
5111
5112                 <contextName>Apex</contextName>
5113                 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
5114
5115                 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5116                     <encoder>
5117                         <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
5118                     </encoder>
5119                 </appender>
5120
5121                 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
5122                     <file>${logDir}/apex.log</file>
5123                     <encoder>
5124                         <pattern>
5125                             %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
5126                         </pattern>
5127                     </encoder>
5128                 </appender>
5129
5130                 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5131                     <encoder>
5132                         <pattern>policy: %msg\n</pattern>
5133                     </encoder>
5134                 </appender>
5135
5136                 <root level="error">
5137                     <appender-ref ref="STDOUT" />
5138                 </root>
5139
5140                 <logger name="org.onap.policy.apex" level="debug" additivity="false">
5141                     <appender-ref ref="FILE" />
5142                 </logger>
5143
5144                 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
5145                     <appender-ref ref="POLICY_APPENDER_STDOUT" />
5146                     <appender-ref ref="FILE" />
5147                 </logger>
5148             </configuration>
5149
5150 Example Configuration for a Production Server
5151 ---------------------------------------------
5152
5153    .. container:: paragraph
5154
5155       The following example shows a configuration that logs all APEX
5156       components, including policy logic, to a file (*debug*). This
5157       configuration an be used in a production phase with the APEX
5158       engine being executed as a service on a system without console
5159       output. This logback configuration is in the APEX installation as
5160       ``logback-server.xml``
5161
5162    .. container:: listingblock
5163
5164       .. container:: content
5165
5166          .. code::
5167
5168             <configuration debug="false">
5169                 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
5170
5171                 <contextName>Apex</contextName>
5172                 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
5173
5174                 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
5175                     <file>${logDir}/apex.log</file>
5176                     <encoder>
5177                         <pattern>
5178                             %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
5179                         </pattern>
5180                     </encoder>
5181                 </appender>
5182
5183                 <root level="debug">
5184                     <appender-ref ref="FILE" />
5185                 </root>
5186
5187                 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
5188                     <appender-ref ref="FILE" />
5189                 </logger>
5190             </configuration>
5191
5192 Unsupported Features
5193 ^^^^^^^^^^^^^^^^^^^^
5194
5195          .. container:: paragraph
5196
5197             This section documents some legacy and unsupported features
5198             in apex-pdp. The documentation here has not been updated for
5199             recent versions of apex-pdp. For example, the apex-pdp models
5200             specified in this example should now be in TOSCA format.
5201
5202 Building a System with Websocket Backend
5203 ----------------------------------------
5204
5205 Websockets
5206 ##########
5207
5208          .. container:: paragraph
5209
5210             Websocket is a protocol to run sockets of HTTP. Since it in
5211             essence a socket, the connection is realized between a
5212             server (waiting for connections) and a client (connecting to
5213             a server). Server/client separation is only important for
5214             connection establishment, once connected, everyone can
5215             send/receive on the same socket (as any standard socket
5216             would allow).
5217
5218          .. container:: paragraph
5219
5220             Standard Websocket implementations are simple, no
5221             publish/subscribe and no special event handling. Most
5222             servers simply send all incoming messages to all
5223             connections. There is a PubSub definition on top of
5224             Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
5225             does not support WAMP at the moment.
5226
5227 Websocket in Java
5228 #################
5229
5230          .. container:: paragraph
5231
5232             In Java, `JSR
5233             356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
5234             defines the standard Websocket API. This JSR is part of Jave
5235             EE 7 standard. For Java SE, several implementations exist in
5236             open source. Since Websockets are a stable standard and
5237             simple, most implementations are stable and ready to use. A
5238             lot of products support Websockets, like Spring, JBoss,
5239             Netty, … there are also Kafka extensions for Websockets.
5240
5241 Websocket Example Code for Websocket clients (FOSS)
5242 ###################################################
5243
5244          .. container:: paragraph
5245
5246             There are a lot of implementations and examples available on
5247             Github for Websocket clients. If one is using Java EE 7,
5248             then one can also use the native Websocket implementation.
5249             Good examples for clients using simply Java SE are here:
5250
5251          .. container:: ulist
5252
5253             -  `Websocket
5254                implementation <https://github.com/TooTallNate/Java-WebSocket>`__
5255
5256             -  `Websocket sending client example, using
5257                AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
5258
5259             -  `Websocket receiving client example (simple echo
5260                client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
5261
5262          .. container:: paragraph
5263
5264             For Java EE, the native Websocket API is explained here:
5265
5266          .. container:: ulist
5267
5268             -  `Oracle
5269                docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
5270
5271             -  link: `An
5272                example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
5273
5274 BCP: Websocket Configuration
5275 ############################
5276
5277          .. container:: paragraph
5278
5279             The probably best is to configure APEX for Websocket servers
5280             for input (ingress, consume) and output (egress, produce)
5281             interfaces. This means that APEX will start Websocket
5282             servers on named ports and wait for clients to connect.
5283             Advantage: once APEX is running all connectivity
5284             infrastructure is running as well. Consequence: if APEX is
5285             not running, everyone else is in the dark, too.
5286
5287          .. container:: paragraph
5288
5289             The best protocol to be used is JSON string. Each event on
5290             any interface is then a string with a JSON encoding. JSON
5291             string is a little bit slower than byte code, but we doubt
5292             that this will be noticeable. A further advantage of JSON
5293             strings over Websockets with APEX starting the servers: it
5294             is very easy to connect web browsers to such a system.
5295             Simple connect the web browser to the APEX sockets and
5296             send/read JSON strings.
5297
5298          .. container:: paragraph
5299
5300             Once APEX is started you simply connect Websocket clients to
5301             it, and send/receive event. When APEX is terminated, the
5302             Websocket servers go down, and the clients will be
5303             disconnected. APEX does not (yet) support auto-client
5304             reconnect nor WAMP, so clients might need to be restarted or
5305             reconnected manually after an APEX boot.
5306
5307 Demo with VPN Policy Model
5308 ##########################
5309
5310          .. container:: paragraph
5311
5312             We assume that you have an APEX installation using the full
5313             package, i.e. APEX with all examples, of version ``0.5.6``
5314             or higher. We will use the VPN policy from the APEX examples
5315             here.
5316
5317          .. container:: paragraph
5318
5319             Now, have the following ready to start the demo:
5320
5321          .. container:: ulist
5322
5323             -  3 terminals on the host where APEX is running (we need 1
5324                for APEX and 1 for each client)
5325
5326             -  the events in the file
5327                ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
5328                in an editor (we need to send those events to APEX)
5329
5330             -  the events in the file
5331                ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
5332                in an editor (we need to send those events to APEX)
5333
5334 A Websocket Configuration for the VPN Domain
5335 ********************************************
5336
5337             .. container:: paragraph
5338
5339                Create a new APEX configuration using the VPN policy
5340                model and configuring APEX as discussed above for
5341                Websockets. Copy the following configuration into
5342                ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
5343                (for Windows use
5344                ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
5345
5346             .. container:: listingblock
5347
5348                .. container:: content
5349
5350                   .. code::
5351                     :number-lines:
5352
5353                     {
5354                       "engineServiceParameters" : {
5355                         "name"          : "VPNApexEngine",
5356                         "version"        : "0.0.1",
5357                         "id"             :  45,
5358                         "instanceCount"  : 1,
5359                         "deploymentPort" : 12345,
5360                         "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
5361                         "engineParameters"    : {
5362                           "executorParameters" : {
5363                             "MVEL" : {
5364                               "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
5365                             }
5366                           },
5367                           "contextParameters" : {
5368                             "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
5369                             "schemaParameters":{
5370                               "Avro":{
5371                                 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
5372                               }
5373                             }
5374                           }
5375                         }
5376                       },
5377                       "producerCarrierTechnologyParameters" : {
5378                         "carrierTechnology" : "WEBSOCKET",
5379                         "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
5380                         "parameters" : {
5381                           "wsClient" : false,
5382                           "port"     : 42452
5383                         }
5384                       },
5385                       "producerEventProtocolParameters" : {
5386                         "eventProtocol" : "JSON"
5387                       },
5388                       "consumerCarrierTechnologyParameters" : {
5389                         "carrierTechnology" : "WEBSOCKET",
5390                         "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
5391                         "parameters" : {
5392                          "wsClient" : false,
5393                           "port"     : 42450
5394                         }
5395                       },
5396                       "consumerEventProtocolParameters" : {
5397                         "eventProtocol" : "JSON"
5398                       }
5399                     }
5400
5401 Start APEX Engine
5402 *****************
5403
5404    .. container:: paragraph
5405
5406       In a new terminal, start APEX with the new configuration for
5407       Websocket-Server ingress/egress:
5408
5409    .. container:: listingblock
5410
5411       .. container:: content
5412
5413          .. code::
5414             :number-lines:
5415
5416             #: $APEX_HOME/bin/apexApps.sh engine -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
5417
5418 .. container:: listingblock
5419
5420    .. container:: content
5421
5422       .. code::
5423         :number-lines:
5424
5425         #: %APEX_HOME%\bin\apexApps.bat engine -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
5426
5427 .. container:: paragraph
5428
5429    Wait for APEX to start, it takes a while to create all Websocket
5430    servers (about 8 seconds on a standard laptop without cached
5431    binaries). depending on your log messages, you will see no (some, a
5432    lot) log messages. If APEX starts correctly, the last few messages
5433    you should see are:
5434
5435 .. container:: listingblock
5436
5437    .. container:: content
5438
5439       .. code::
5440         :number-lines:
5441
5442          2017-07-28 13:17:20,834 Apex [main] INFO c.e.a.s.engine.runtime.EngineService - engine model VPNPolicyModelAvro:0.0.1 added to the engine-AxArtifactKey:(name=VPNApexEngine-0,version=0.0.1)
5443          2017-07-28 13:17:21,057 Apex [Apex-apex-engine-service-0:0] INFO c.e.a.s.engine.runtime.EngineService - Engine AxArtifactKey:(name=VPNApexEngine-0,version=0.0.1) processing ...
5444          2017-07-28 13:17:21,296 Apex [main] INFO c.e.a.s.e.r.impl.EngineServiceImpl - Added the action listener to the engine
5445          Started Apex service
5446
5447 .. container:: paragraph
5448
5449    APEX is running in the new terminal and will produce output when the
5450    policy is triggered/executed.
5451
5452 Run the Websocket Echo Client
5453 *****************************
5454
5455    .. container:: paragraph
5456
5457       The echo client is included in an APEX full installation. To run
5458       the client, open a new shell (Unix, Cygwin) or command prompt
5459       (``cmd`` on Windows). Then use the APEX application launcher to
5460       start the client.
5461
5462    .. important::
5463       APEX engine needs to run first
5464       The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
5465
5466    +---------------------------------------------------------+-----------------------------------------------------------+
5467    | Unix, Cygwin                                            | Windows                                                   |
5468    +=========================================================+===========================================================+
5469    | .. container::                                          | .. container::                                            |
5470    |                                                         |                                                           |
5471    |    .. container:: listingblock                          |    .. container:: listingblock                            |
5472    |                                                         |                                                           |
5473    |       .. container:: content                            |       .. container:: content                              |
5474    |                                                         |                                                           |
5475    |          .. code::                                      |          .. code::                                        |
5476    |                                                         |                                                           |
5477    |             # $APEX_HOME/bin/apexApps.sh ws-echo [args] |             > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
5478    +---------------------------------------------------------+-----------------------------------------------------------+
5479
5480    .. container:: paragraph
5481
5482       Use the following command line arguments for server and port of
5483       the Websocket server. The port should be the same as configured in
5484       the APEX engine. The server host should be the host on which the
5485       APEX engine is running
5486
5487    .. container:: ulist
5488
5489       -  ``-p`` defines the Websocket port to connect to (defaults to
5490          ``8887``)
5491
5492       -  ``-s`` defines the host on which a Websocket server is running
5493          (defaults to ``localhost``)
5494
5495    .. container:: paragraph
5496
5497       Let’s assume that there is an APEX engine running, configured for
5498       produce Websocket carrier technology, as server, for port 42452,
5499       with produce event protocol JSON,. If we start the console client
5500       on the same host, we can omit the ``-s`` options. We start the
5501       console client as:
5502
5503    .. container:: listingblock
5504
5505       .. container:: content
5506
5507          .. code::
5508
5509             # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
5510             > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
5511
5512    .. container:: colist arabic
5513
5514       +-------+--------------------------------+
5515       | **1** | Start client on Unix or Cygwin |
5516       +-------+--------------------------------+
5517       | **2** | Start client on Windows        |
5518       +-------+--------------------------------+
5519
5520    .. container:: paragraph
5521
5522       Once started successfully, the client will produce the following
5523       messages (assuming we used ``-p 42452`` and an APEX engine is
5524       running on ``localhost`` with the same port:
5525
5526    .. container:: listingblock
5527
5528       .. container:: content
5529
5530          .. code::
5531
5532             ws-simple-echo: starting simple event echo
5533              --> server: localhost
5534              --> port: 42452
5535
5536             Once started, the application will simply print out all received events to standard out.
5537             Each received event will be prefixed by '---' and suffixed by '===='
5538
5539
5540             ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
5541
5542 Run the Websocket Console Client
5543 ********************************
5544
5545    .. container:: paragraph
5546
5547       The console client is included in an APEX full installation. To
5548       run the client, open a new shell (Unix, Cygwin) or command prompt
5549       (``cmd`` on Windows). Then use the APEX application launcher to
5550       start the client.
5551
5552    .. important::
5553       APEX engine needs to run first
5554       The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
5555       protocol is executed first.
5556
5557    +------------------------------------------------------------+--------------------------------------------------------------+
5558    | Unix, Cygwin                                               | Windows                                                      |
5559    +============================================================+==============================================================+
5560    | .. container::                                             | .. container::                                               |
5561    |                                                            |                                                              |
5562    |    .. container:: listingblock                             |    .. container:: listingblock                               |
5563    |                                                            |                                                              |
5564    |       .. container:: content                               |       .. container:: content                                 |
5565    |                                                            |                                                              |
5566    |          .. code::                                         |          .. code::                                           |
5567    |                                                            |                                                              |
5568    |             # $APEX_HOME/bin/apexApps.sh ws-console [args] |             > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
5569    +------------------------------------------------------------+--------------------------------------------------------------+
5570
5571    .. container:: paragraph
5572
5573       Use the following command line arguments for server and port of
5574       the Websocket server. The port should be the same as configured in
5575       the APEX engine. The server host should be the host on which the
5576       APEX engine is running
5577
5578    .. container:: ulist
5579
5580       -  ``-p`` defines the Websocket port to connect to (defaults to
5581          ``8887``)
5582
5583       -  ``-s`` defines the host on which a Websocket server is running
5584          (defaults to ``localhost``)
5585
5586    .. container:: paragraph
5587
5588       Let’s assume that there is an APEX engine running, configured for
5589       consume Websocket carrier technology, as server, for port 42450,
5590       with consume event protocol JSON,. If we start the console client
5591       on the same host, we can omit the ``-s`` options. We start the
5592       console client as:
5593
5594    .. container:: listingblock
5595
5596       .. container:: content
5597
5598          .. code::
5599
5600             # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
5601             > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
5602
5603    .. container:: colist arabic
5604
5605       +-------+--------------------------------+
5606       | **1** | Start client on Unix or Cygwin |
5607       +-------+--------------------------------+
5608       | **2** | Start client on Windows        |
5609       +-------+--------------------------------+
5610
5611    .. container:: paragraph
5612
5613       Once started successfully, the client will produce the following
5614       messages (assuming we used ``-p 42450`` and an APEX engine is
5615       running on ``localhost`` with the same port:
5616
5617    .. container:: listingblock
5618
5619       .. container:: content
5620
5621          .. code::
5622
5623             ws-simple-console: starting simple event console
5624              --> server: localhost
5625              --> port: 42450
5626
5627              - terminate the application typing 'exit<enter>' or using 'CTRL+C'
5628              - events are created by a non-blank starting line and terminated by a blank line
5629
5630
5631             ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
5632
5633 Send Events
5634 ***********
5635
5636    .. container:: paragraph
5637
5638       Now you have the full system up and running:
5639
5640    .. container:: ulist
5641
5642       -  Terminal 1: APEX ready and loaded
5643
5644       -  Terminal 2: an echo client, printing received messages produced
5645          by the VPN policy
5646
5647       -  Terminal 2: a console client, waiting for input on the console
5648          (standard in) and sending text to APEX
5649
5650    .. container:: paragraph
5651
5652       We started the engine with the VPN policy example. So all the
5653       events we are using now are located in files in the following
5654       example directory:
5655
5656    .. container:: listingblock
5657
5658       .. container:: content
5659
5660          .. code::
5661            :number-lines:
5662
5663            #: $APEX_HOME/examples/events/VPN
5664            > %APEX_HOME%\examples\events\VPN
5665
5666 .. container:: paragraph
5667
5668    To sends events, simply copy the content of the event files into
5669    Terminal 3 (the console client). It will read multi-line JSON text
5670    and send the events. So copy the content of ``SetupEvents.json`` into
5671    the client. APEX will trigger a policy and produce some output, the
5672    echo client will also print some events created in the policy. In
5673    Terminal 1 (APEX) you’ll see some status messages from the policy as:
5674
5675 .. container:: listingblock
5676
5677    .. container:: content
5678
5679       .. code::
5680         :number-lines:
5681
5682         {Link=L09, LinkUp=true}
5683         L09     true
5684         outFields: {Link=L09, LinkUp=true}
5685         {Link=L10, LinkUp=true}
5686         L09     true
5687         L10     true
5688         outFields: {Link=L10, LinkUp=true}
5689         {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
5690         *** Customers ***
5691         C       300     300     [L09, L10]
5692         outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
5693         {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
5694         *** Customers ***
5695         A       300     50      [L09, L10]
5696         C       300     300     [L09, L10]
5697         outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
5698         {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
5699         *** Customers ***
5700         A       300     50      [L09, L10]
5701         C       300     300     [L09, L10]
5702         D       300     400     [L09, L10]
5703         outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
5704         {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
5705         *** Customers ***
5706         A       300     50      [L09, L10]
5707         B       300     299     [L09, L10]
5708         C       300     300     [L09, L10]
5709         D       300     400     [L09, L10]
5710         outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
5711
5712 .. container:: paragraph
5713
5714    In Terminal 2 (echo-client) you see the received events, the last two
5715    should look like:
5716
5717 .. container:: listingblock
5718
5719    .. container:: content
5720
5721       .. code::
5722         :number-lines:
5723
5724         ws-simple-echo: received
5725         ---------------------------------
5726         {
5727           "name": "VPNCustomerCtxtActEvent",
5728           "version": "0.0.1",
5729           "nameSpace": "org.onap.policy.apex.domains.vpn.events",
5730           "source": "Source",
5731           "target": "Target",
5732           "CustomerName": "C",
5733           "LinkList": "L09 L10",
5734           "SlaDT": 300,
5735           "YtdDT": 300
5736         }
5737         =================================
5738
5739         ws-simple-echo: received
5740         ---------------------------------
5741         {
5742           "name": "VPNCustomerCtxtActEvent",
5743           "version": "0.0.1",
5744           "nameSpace": "org.onap.policy.apex.domains.vpn.events",
5745           "source": "Source",
5746           "target": "Target",
5747           "CustomerName": "D",
5748           "LinkList": "L09 L10",
5749           "SlaDT": 300,
5750           "YtdDT": 400
5751         }
5752         =================================
5753
5754 .. container:: paragraph
5755
5756    Congratulations, you have triggered a policy in APEX using
5757    Websockets, the policy did run through, created events, picked up by
5758    the echo-client.
5759
5760 .. container:: paragraph
5761
5762    Now you can send the Link 09 and Link 10 events, they will trigger
5763    the actual VPN policy and some calculations are made. Let’s take the
5764    Link 09 events from ``Link09Events.json``, copy them all into
5765    Terminal 3 (the console). APEX will run the policy (with some status
5766    output), and the echo client will receive and print events.
5767
5768 .. container:: paragraph
5769
5770    To terminate the applications, simply press ``CTRL+C`` in Terminal 1
5771    (APEX). This will also terminate the echo-client in Terminal 2. Then
5772    type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
5773    console-client.
5774
5775 .. container::
5776    :name: footer
5777
5778    .. container::
5779       :name: footer-text
5780
5781
5782