Update APEX documentation with the usage of eventName
[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 Name
1785 ##########
1786
1787             .. container:: paragraph
1788
1789                Any event defined in APEX has to be unique. The "name" of
1790                of an event is used as an identifier for an ApexEvent. Every
1791                event has to be tagged to an eventName. This can be done in different
1792                ways. Either the actual event can have a field called "name". Or, the
1793                event has some other field that can act as the identifier, which can be
1794                specified using "nameAlias". But in other cases, where a "name" or "nameAlias"
1795                cannot be specified, the incoming event coming over an endpoint can be
1796                manually tagged to an "eventName" before consuming it.
1797
1798             .. container:: paragraph
1799
1800                The "eventName" can have a single event's name if the event coming
1801                over the endpoint has to be always mapped to the specified eventName's
1802                definition. Otherwise, if different events can come over the endpoint,
1803                then "eventName" field can consist of multiple event names separated by
1804                "|" symbol. In this case, based on the received event's structure, it is
1805                mapped to any one of the event name specified in the "eventName" field.
1806
1807             .. container:: paragraph
1808
1809                The following code shows some examples on how to specify the eventName field:
1810
1811             .. container:: listingblock
1812
1813                .. container:: content
1814
1815                   .. code::
1816
1817                      "eventInputParameters": {
1818                        "Input1": {
1819                          "carrierTechnologyParameters" : {...},
1820                          "eventProtocolParameters":{...},
1821                          "eventName" : "VesEvent" (1)
1822                        },
1823                        "Input2": {
1824                          "carrierTechnologyParameters" : {...},
1825                          "eventProtocolParameters":{...},
1826                          "eventName" : "AAISuccessResponseEvent|AAIFailureResponseEvent" (2)
1827                        }
1828                      }
1829
1830 Event Filters
1831 #############
1832
1833             .. container:: paragraph
1834
1835                APEX will always send an event after a policy execution
1836                is finished. For a successful execution, the event sent
1837                is the output event created by the policy. In case the
1838                policy does not create an output event, APEX will create
1839                a new event with all input event fields plus an
1840                additional field ``exceptionMessage`` with an exception
1841                message.
1842
1843             .. container:: paragraph
1844
1845                There are situations in which this auto-generated error
1846                event might not be required or wanted:
1847
1848             .. container:: ulist
1849
1850                -  when a policy failing should not result in an event
1851                   send out via an output interface
1852
1853                -  when the auto-generated event goes back in an APEX
1854                   engine (or the same APEX engine), this can create
1855                   endless loops
1856
1857                -  the auto-generated event should go to a special output
1858                   interface or channel
1859
1860             .. container:: paragraph
1861
1862                All of these situations are supported by a filter option
1863                using a wildecard (regular expression) configuration on
1864                APEX I/O interfaces. The parameter is called
1865                ``eventNameFilter`` and the value are `Java regular
1866                expressions <https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html>`__
1867                (a
1868                `tutorial <http://www.vogella.com/tutorials/JavaRegularExpressions/article.html>`__).
1869                The following code shows some examples:
1870
1871             .. container:: listingblock
1872
1873                .. container:: content
1874
1875                   .. code::
1876
1877                      "eventInputParameters": {
1878                        "Input1": {
1879                          "carrierTechnologyParameters" : {...},
1880                          "eventProtocolParameters":{...},
1881                          "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]004$" (1)
1882                        }
1883                      },
1884                      "eventOutputParameters": {
1885                        "Output1": {
1886                          "carrierTechnologyParameters":{...},
1887                          "eventProtocolParameters":{...},
1888                          "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]104$" (2)
1889                        }
1890                      }
1891
1892 Executors
1893 ---------
1894
1895          .. container:: paragraph
1896
1897             Executors are plugins that realize the execution of logic
1898             contained in a policy model. Logic can be in a task
1899             selector, a task, and a state finalizer. Using plugins for
1900             execution environments makes APEX very flexible to support
1901             virtually any executable logic expressions.
1902
1903          .. container:: paragraph
1904
1905             APEX 2.0.0-SNAPSHOT supports the following executors:
1906
1907          .. container:: ulist
1908
1909             -  Java, for Java implemented logic
1910
1911                .. container:: ulist
1912
1913                   -  This executor requires logic implemented using the
1914                      APEX Java interfaces.
1915
1916                   -  Generated JAR files must be in the classpath of the
1917                      APEX engine at start time.
1918
1919             -  Javascript
1920
1921             -  JRuby,
1922
1923             -  Jython,
1924
1925             -  MVEL
1926
1927                .. container:: ulist
1928
1929                   -  This executor uses the latest version of the MVEL
1930                      engine, which can be very hard to debug and can
1931                      produce unwanted side effects during execution
1932
1933 Configure the Javascript Executor
1934 #################################
1935
1936             .. container:: paragraph
1937
1938                The Javascript executor is added to the configuration as
1939                follows:
1940
1941             .. container:: listingblock
1942
1943                .. container:: content
1944
1945                   .. code::
1946
1947                      "engineServiceParameters":{
1948                        "engineParameters":{
1949                          "executorParameters":{
1950                            "JAVASCRIPT":{
1951                              "parameterClassName" :
1952                              "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
1953                            }
1954                          }
1955                        }
1956                      }
1957
1958 Configure the Jython Executor
1959 #############################
1960
1961             .. container:: paragraph
1962
1963                The Jython executor is added to the configuration as
1964                follows:
1965
1966             .. container:: listingblock
1967
1968                .. container:: content
1969
1970                   .. code::
1971
1972                      "engineServiceParameters":{
1973                        "engineParameters":{
1974                          "executorParameters":{
1975                            "JYTHON":{
1976                              "parameterClassName" :
1977                              "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
1978                            }
1979                          }
1980                        }
1981                      }
1982
1983 Configure the JRuby Executor
1984 ############################
1985
1986             .. container:: paragraph
1987
1988                The JRuby executor is added to the configuration as
1989                follows:
1990
1991             .. container:: listingblock
1992
1993                .. container:: content
1994
1995                   .. code::
1996
1997                      "engineServiceParameters":{
1998                        "engineParameters":{
1999                          "executorParameters":{
2000                            "JRUBY":{
2001                              "parameterClassName" :
2002                              "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
2003                            }
2004                          }
2005                        }
2006                      }
2007
2008 Configure the Java Executor
2009 ###########################
2010
2011             .. container:: paragraph
2012
2013                The Java executor is added to the configuration as
2014                follows:
2015
2016             .. container:: listingblock
2017
2018                .. container:: content
2019
2020                   .. code::
2021
2022                      "engineServiceParameters":{
2023                        "engineParameters":{
2024                          "executorParameters":{
2025                            "JAVA":{
2026                              "parameterClassName" :
2027                              "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
2028                            }
2029                          }
2030                        }
2031                      }
2032
2033 Configure the MVEL Executor
2034 ###########################
2035
2036             .. container:: paragraph
2037
2038                The MVEL executor is added to the configuration as
2039                follows:
2040
2041             .. container:: listingblock
2042
2043                .. container:: content
2044
2045                   .. code::
2046
2047                      "engineServiceParameters":{
2048                        "engineParameters":{
2049                          "executorParameters":{
2050                            "MVEL":{
2051                              "parameterClassName" :
2052                              "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
2053                            }
2054                          }
2055                        }
2056                      }
2057
2058 Context Handlers
2059 ----------------
2060
2061          .. container:: paragraph
2062
2063             Context handlers are responsible for all context processing.
2064             There are the following main areas:
2065
2066          .. container:: ulist
2067
2068             -  Context schema: use schema handlers other than Java class
2069                (supported by default without configuration)
2070
2071             -  Context distribution: distribute context across multiple
2072                APEX engines
2073
2074             -  Context locking: mechanisms to lock context elements for
2075                read/write
2076
2077             -  Context persistence: mechanisms to persist context
2078
2079          .. container:: paragraph
2080
2081             APEX provides plugins for each of the main areas.
2082
2083 Configure AVRO Schema Handler
2084 #############################
2085
2086             .. container:: paragraph
2087
2088                The AVRO schema handler is added to the configuration as
2089                follows:
2090
2091             .. container:: listingblock
2092
2093                .. container:: content
2094
2095                   .. code::
2096
2097                      "engineServiceParameters":{
2098                        "engineParameters":{
2099                          "contextParameters":{
2100                            "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
2101                            "schemaParameters":{
2102                              "Avro":{
2103                                "parameterClassName" :
2104                                  "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
2105                              }
2106                            }
2107                          }
2108                        }
2109                      }
2110
2111             .. container:: paragraph
2112
2113                Using the AVRO schema handler has one limitation: AVRO
2114                only supports field names that represent valid Java class
2115                names. This means only letters and the character ``_``
2116                are supported. Characters commonly used in field names,
2117                such as ``.`` and ``-``, are not supported by AVRO. for
2118                more information see `Avro Spec:
2119                Names <https://avro.apache.org/docs/1.8.1/spec.html#names>`__.
2120
2121             .. container:: paragraph
2122
2123                To work with this limitation, the APEX Avro plugin will
2124                parse a given AVRO definition and replace *all*
2125                occurrences of ``.`` and ``-`` with a ``_``. This means
2126                that
2127
2128             .. container:: ulist
2129
2130                -  In a policy model, if the AVRO schema defined a field
2131                   as ``my-name`` the policy logic should access it as
2132                   ``my_name``
2133
2134                -  In a policy model, if the AVRO schema defined a field
2135                   as ``my.name`` the policy logic should access it as
2136                   ``my_name``
2137
2138                -  There should be no field names that convert to the
2139                   same internal name
2140
2141                   .. container:: ulist
2142
2143                      -  For instance the simultaneous use of
2144                         ``my_name``, ``my.name``, and ``my-name`` should
2145                         be avoided
2146
2147                      -  If not avoided, the event processing might
2148                         create unwanted side effects
2149
2150                -  If field names use any other not-supported character,
2151                   the AVRO plugin will reject it
2152
2153                   .. container:: ulist
2154
2155                      -  Since AVRO uses lazy initialization, this
2156                         rejection might only become visible at runtime
2157
2158 Configure Task Parameters
2159 #########################
2160
2161             .. container:: paragraph
2162
2163                The Task Parameters are added to the configuration as
2164                follows:
2165
2166             .. container:: listingblock
2167
2168                .. container:: content
2169
2170                   .. code::
2171
2172                      "engineServiceParameters": {
2173                        "engineParameters": {
2174                          "taskParameters": [
2175                            {
2176                              "key": "ParameterKey1",
2177                              "value": "ParameterValue1"
2178                            },
2179                            {
2180                              "taskId": "Task_Act0",
2181                              "key": "ParameterKey2",
2182                              "value": "ParameterValue2"
2183                            }
2184                          ]
2185                        }
2186                      }
2187
2188             .. container:: paragraph
2189
2190                TaskParameters can be used to pass parameters from ApexConfig
2191                to the policy logic. In the config, these are optional.
2192                The list of task parameters provided in the config may be added
2193                to the tasks or existing task parameters in the task will be overriden.
2194
2195             .. container:: paragraph
2196
2197                If taskId is provided in ApexConfig for an entry, then that
2198                parameter is updated only for that particular task. Otherwise,
2199                the task parameter is added to all tasks.
2200
2201 Carrier Technologies
2202 --------------------
2203
2204          .. container:: paragraph
2205
2206             Carrier technologies define how APEX receives (input) and
2207             sends (output) events. They can be used in any combination,
2208             using asynchronous or synchronous mode. There can also be
2209             any number of carrier technologies for the input (consume)
2210             and the output (produce) interface.
2211
2212          .. container:: paragraph
2213
2214             Supported *input* technologies are:
2215
2216          .. container:: ulist
2217
2218             -  Standard input, read events from the standard input
2219                (console), not suitable for APEX background servers
2220
2221             -  File input, read events from a file
2222
2223             -  Kafka, read events from a Kafka system
2224
2225             -  Websockets, read events from a Websocket
2226
2227             -  JMS,
2228
2229             -  REST (synchronous and asynchronous), additionally as
2230                client or server
2231
2232             -  Event Requestor, allows reading of events that have been
2233                looped back into APEX
2234
2235          .. container:: paragraph
2236
2237             Supported *output* technologies are:
2238
2239          .. container:: ulist
2240
2241             -  Standard output, write events to the standard output
2242                (console), not suitable for APEX background servers
2243
2244             -  File output, write events to a file
2245
2246             -  Kafka, write events to a Kafka system
2247
2248             -  Websockets, write events to a Websocket
2249
2250             -  JMS
2251
2252             -  REST (synchronous and asynchronous), additionally as
2253                client or server
2254
2255             -  Event Requestor, allows events to be looped back into
2256                APEX
2257
2258          .. container:: paragraph
2259
2260             New carrier technologies can be added as plugins to APEX or
2261             developed outside APEX and added to an APEX deployment.
2262
2263 Standard IO
2264 ###########
2265
2266             .. container:: paragraph
2267
2268                Standard IO does not require a specific plugin, it is
2269                supported be default.
2270
2271 Standard Input
2272 ==============
2273                .. container:: paragraph
2274
2275                   APEX will take events from its standard input. This
2276                   carrier is good for testing, but certainly not for a
2277                   use case where APEX runs as a server. The
2278                   configuration is as follows:
2279
2280                .. container:: listingblock
2281
2282                   .. container:: content
2283
2284 ::
2285
2286                         "carrierTechnologyParameters" : {
2287                           "carrierTechnology" : "FILE", (1)
2288                           "parameters" : {
2289                             "standardIO" : true (2)
2290                           }
2291                         }
2292
2293                .. container:: colist arabic
2294
2295                   +-------+---------------------------------------+
2296                   | **1** | standard input is considered a file   |
2297                   +-------+---------------------------------------+
2298                   | **2** | file descriptor set to standard input |
2299                   +-------+---------------------------------------+
2300
2301 Standard Output
2302 ===============
2303
2304                .. container:: paragraph
2305
2306                   APEX will send events to its standard output. This
2307                   carrier is good for testing, but certainly not for a
2308                   use case where APEX runs as a server. The
2309                   configuration is as follows:
2310
2311                .. container:: listingblock
2312
2313                   .. container:: content
2314
2315                      .. code::
2316
2317                         "carrierTechnologyParameters" : {
2318                           "carrierTechnology" : "FILE", (1)
2319                           "parameters" : {
2320                             "standardIO" : true  (2)
2321                           }
2322                         }
2323
2324                .. container:: colist arabic
2325
2326                   +-------+----------------------------------------+
2327                   | **1** | standard output is considered a file   |
2328                   +-------+----------------------------------------+
2329                   | **2** | file descriptor set to standard output |
2330                   +-------+----------------------------------------+
2331
2332 2.7.2. File IO
2333 ##############
2334
2335             .. container:: paragraph
2336
2337                File IO does not require a specific plugin, it is
2338                supported be default.
2339
2340 File Input
2341 ==========
2342
2343                .. container:: paragraph
2344
2345                   APEX will take events from a file. The same file
2346                   should not be used as an output. The configuration is
2347                   as follows:
2348
2349                .. container:: listingblock
2350
2351                   .. container:: content
2352
2353                      .. code::
2354
2355                         "carrierTechnologyParameters" : {
2356                           "carrierTechnology" : "FILE", (1)
2357                           "parameters" : {
2358                             "fileName" : "examples/events/SampleDomain/EventsIn.xmlfile" (2)
2359                           }
2360                         }
2361
2362                .. container:: colist arabic
2363
2364                   +-------+------------------------------------------+
2365                   | **1** | set file input                           |
2366                   +-------+------------------------------------------+
2367                   | **2** | the name of the file to read events from |
2368                   +-------+------------------------------------------+
2369
2370 File Output
2371 ===========
2372                .. container:: paragraph
2373
2374                   APEX will write events to a file. The same file should
2375                   not be used as an input. The configuration is as
2376                   follows:
2377
2378                .. container:: listingblock
2379
2380                   .. container:: content
2381
2382                      .. code::
2383
2384                         "carrierTechnologyParameters" : {
2385                           "carrierTechnology" : "FILE", (1)
2386                           "parameters" : {
2387                             "fileName"  : "examples/events/SampleDomain/EventsOut.xmlfile" (2)
2388                           }
2389                         }
2390
2391                .. container:: colist arabic
2392
2393                   +-------+-----------------------------------------+
2394                   | **1** | set file output                         |
2395                   +-------+-----------------------------------------+
2396                   | **2** | the name of the file to write events to |
2397                   +-------+-----------------------------------------+
2398
2399 Event Requestor IO
2400 ##################
2401
2402             .. container:: paragraph
2403
2404                Event Requestor IO does not require a specific plugin, it
2405                is supported be default. It should only be used with the
2406                APEX event protocol.
2407
2408 Event Requestor Input
2409 =====================
2410
2411                .. container:: paragraph
2412
2413                   APEX will take events from APEX.
2414
2415                .. container:: listingblock
2416
2417                   .. container:: content
2418
2419                      .. code::
2420
2421                         "carrierTechnologyParameters" : {
2422                           "carrierTechnology": "EVENT_REQUESTOR" (1)
2423                         }
2424
2425                .. container:: colist arabic
2426
2427                   +-------+---------------------------+
2428                   | **1** | set event requestor input |
2429                   +-------+---------------------------+
2430
2431 Event Requestor Output
2432 ======================
2433
2434                .. container:: paragraph
2435
2436                   APEX will write events to APEX.
2437
2438                .. container:: listingblock
2439
2440                   .. container:: content
2441
2442                      .. code::
2443
2444                         "carrierTechnologyParameters" : {
2445                           "carrierTechnology": "EVENT_REQUESTOR" (1)
2446                         }
2447
2448 Peering Event Requestors
2449 ========================
2450
2451                .. container:: paragraph
2452
2453                   When using event requestors, they need to be peered.
2454                   This means an event requestor output needs to be
2455                   peered (associated) with an event requestor input. The
2456                   following example shows the use of an event requestor
2457                   with the APEX event protocol and the peering of output
2458                   and input.
2459
2460                .. container:: listingblock
2461
2462                   .. container:: content
2463
2464                      .. code::
2465
2466                         "eventInputParameters": {
2467                           "EventRequestorConsumer": {
2468                             "carrierTechnologyParameters": {
2469                               "carrierTechnology": "EVENT_REQUESTOR" (1)
2470                             },
2471                             "eventProtocolParameters": {
2472                               "eventProtocol": "APEX" (2)
2473                             },
2474                             "eventNameFilter": "InputEvent", (3)
2475                             "requestorMode": true, (4)
2476                             "requestorPeer": "EventRequestorProducer", (5)
2477                             "requestorTimeout": 500 (6)
2478                           }
2479                         },
2480                         "eventOutputParameters": {
2481                           "EventRequestorProducer": {
2482                             "carrierTechnologyParameters": {
2483                               "carrierTechnology": "EVENT_REQUESTOR" (7)
2484                             },
2485                             "eventProtocolParameters": {
2486                               "eventProtocol": "APEX" (8)
2487                             },
2488                             "eventNameFilter": "EventListEvent", (9)
2489                             "requestorMode": true, (10)
2490                             "requestorPeer": "EventRequestorConsumer", (11)
2491                             "requestorTimeout": 500 (12)
2492                           }
2493                         }
2494
2495                .. container:: colist arabic
2496
2497                   +-----------------------------------+-----------------------------------+
2498                   | **1**                             | event requestor on a consumer     |
2499                   +-----------------------------------+-----------------------------------+
2500                   | **2**                             | with APEX event protocol          |
2501                   +-----------------------------------+-----------------------------------+
2502                   | **3**                             | optional filter (best to use a    |
2503                   |                                   | filter to prevent unwanted events |
2504                   |                                   | on the consumer side)             |
2505                   +-----------------------------------+-----------------------------------+
2506                   | **4**                             | activate requestor mode           |
2507                   +-----------------------------------+-----------------------------------+
2508                   | **5**                             | the peer to the output (must      |
2509                   |                                   | match the output carrier)         |
2510                   +-----------------------------------+-----------------------------------+
2511                   | **6**                             | an optional timeout in            |
2512                   |                                   | milliseconds                      |
2513                   +-----------------------------------+-----------------------------------+
2514                   | **7**                             | event requestor on a producer     |
2515                   +-----------------------------------+-----------------------------------+
2516                   | **8**                             | with APEX event protocol          |
2517                   +-----------------------------------+-----------------------------------+
2518                   | **9**                             | optional filter (best to use a    |
2519                   |                                   | filter to prevent unwanted events |
2520                   |                                   | on the consumer side)             |
2521                   +-----------------------------------+-----------------------------------+
2522                   | **10**                            | activate requestor mode           |
2523                   +-----------------------------------+-----------------------------------+
2524                   | **11**                            | the peer to the output (must      |
2525                   |                                   | match the input carrier)          |
2526                   +-----------------------------------+-----------------------------------+
2527                   | **12**                            | an optional timeout in            |
2528                   |                                   | milliseconds                      |
2529                   +-----------------------------------+-----------------------------------+
2530
2531 Kafka IO
2532 ########
2533
2534             .. container:: paragraph
2535
2536                Kafka IO is supported by the APEX Kafka plugin. The
2537                configurations below are examples. APEX will take any
2538                configuration inside the parameter object and forward it
2539                to Kafka. More information on Kafka specific
2540                configuration parameters can be found in the Kafka
2541                documentation:
2542
2543             .. container:: ulist
2544
2545                -  `Kafka Consumer
2546                   Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html>`__
2547
2548                -  `Kafka Producer
2549                   Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>`__
2550
2551 Kafka Input
2552 ===========
2553                .. container:: paragraph
2554
2555                   APEX will receive events from the Apache Kafka
2556                   messaging system. The input is uni-directional, an
2557                   engine will only receive events from the input but not
2558                   send any event to the input.
2559
2560                .. container:: listingblock
2561
2562                   .. container:: content
2563
2564                      .. code::
2565
2566                         "carrierTechnologyParameters" : {
2567                           "carrierTechnology" : "KAFKA", (1)
2568                           "parameterClassName" :
2569                             "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2570                           "parameters" : {
2571                             "bootstrapServers"  : "localhost:49092", (2)
2572                             "groupId"           : "apex-group-id", (3)
2573                             "enableAutoCommit"  : true, (4)
2574                             "autoCommitTime"    : 1000, (5)
2575                             "sessionTimeout"    : 30000, (6)
2576                             "consumerPollTime"  : 100, (7)
2577                             "consumerTopicList" : ["apex-in-0", "apex-in-1"], (8)
2578                             "keyDeserializer"   :
2579                                 "org.apache.kafka.common.serialization.StringDeserializer", (9)
2580                             "valueDeserializer" :
2581                                 "org.apache.kafka.common.serialization.StringDeserializer" (10)
2582                           }
2583                         }
2584
2585                .. container:: colist arabic
2586
2587                   +--------+-------------------------------------+
2588                   | **1**  | set Kafka as carrier technology     |
2589                   +--------+-------------------------------------+
2590                   | **2**  | bootstrap server and port           |
2591                   +--------+-------------------------------------+
2592                   | **3**  | a group identifier                  |
2593                   +--------+-------------------------------------+
2594                   | **4**  | flag for auto-commit                |
2595                   +--------+-------------------------------------+
2596                   | **5**  | auto-commit timeout in milliseconds |
2597                   +--------+-------------------------------------+
2598                   | **6**  | session timeout in milliseconds     |
2599                   +--------+-------------------------------------+
2600                   | **7**  | consumer poll time in milliseconds  |
2601                   +--------+-------------------------------------+
2602                   | **8**  | consumer topic list                 |
2603                   +--------+-------------------------------------+
2604                   | **9**  | key for the Kafka de-serializer     |
2605                   +--------+-------------------------------------+
2606                   | **10** | value for the Kafka de-serializer   |
2607                   +--------+-------------------------------------+
2608
2609 Kafka Output
2610 ============
2611                .. container:: paragraph
2612
2613                   APEX will send events to the Apache Kafka messaging
2614                   system. The output is uni-directional, an engine will
2615                   send events to the output but not receive any event
2616                   from the output.
2617
2618                .. container:: listingblock
2619
2620                   .. container:: content
2621
2622                      .. code::
2623
2624                         "carrierTechnologyParameters" : {
2625                           "carrierTechnology" : "KAFKA", (1)
2626                           "parameterClassName" :
2627                             "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2628                           "parameters" : {
2629                             "bootstrapServers"  : "localhost:49092", (2)
2630                             "acks"              : "all", (3)
2631                             "retries"           : 0, (4)
2632                             "batchSize"         : 16384, (5)
2633                             "lingerTime"        : 1, (6)
2634                             "bufferMemory"      : 33554432, (7)
2635                             "producerTopic"     : "apex-out", (8)
2636                             "keySerializer"     :
2637                                 "org.apache.kafka.common.serialization.StringSerializer", (9)
2638                             "valueSerializer"   :
2639                                 "org.apache.kafka.common.serialization.StringSerializer" (10)
2640                           }
2641                         }
2642
2643                .. container:: colist arabic
2644
2645                   +--------+---------------------------------+
2646                   | **1**  | set Kafka as carrier technology |
2647                   +--------+---------------------------------+
2648                   | **2**  | bootstrap server and port       |
2649                   +--------+---------------------------------+
2650                   | **3**  | acknowledgement strategy        |
2651                   +--------+---------------------------------+
2652                   | **4**  | number of retries               |
2653                   +--------+---------------------------------+
2654                   | **5**  | batch size                      |
2655                   +--------+---------------------------------+
2656                   | **6**  | time to linger in milliseconds  |
2657                   +--------+---------------------------------+
2658                   | **7**  | buffer memory in byte           |
2659                   +--------+---------------------------------+
2660                   | **8**  | producer topic                  |
2661                   +--------+---------------------------------+
2662                   | **9**  | key for the Kafka serializer    |
2663                   +--------+---------------------------------+
2664                   | **10** | value for the Kafka serializer  |
2665                   +--------+---------------------------------+
2666
2667 JMS IO
2668 ######
2669
2670             .. container:: paragraph
2671
2672                APEX supports the Java Messaging Service (JMS) as input
2673                as well as output. JMS IO is supported by the APEX JMS
2674                plugin. Input and output support an event encoding as
2675                text (JSON string) or object (serialized object). The
2676                input configuration is the same for both encodings, the
2677                output configuration differs.
2678
2679 JMS Input
2680 =========
2681                .. container:: paragraph
2682
2683                   APEX will receive events from a JMS messaging system.
2684                   The input is uni-directional, an engine will only
2685                   receive events from the input but not send any event
2686                   to the input.
2687
2688                .. container:: listingblock
2689
2690                   .. container:: content
2691
2692                      .. code::
2693
2694                         "carrierTechnologyParameters" : {
2695                           "carrierTechnology" : "JMS", (1)
2696                           "parameterClassName" :
2697                               "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2698                           "parameters" : { (2)
2699                             "initialContextFactory" :
2700                                 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2701                             "connectionFactory" : "ConnectionFactory", (4)
2702                             "providerURL" : "remote://localhost:5445", (5)
2703                             "securityPrincipal" : "guest", (6)
2704                             "securityCredentials" : "IAmAGuest", (7)
2705                             "consumerTopic" : "jms/topic/apexIn" (8)
2706                           }
2707                         }
2708
2709                .. container:: colist arabic
2710
2711                   +-----------------------------------+-----------------------------------+
2712                   | **1**                             | set JMS as carrier technology     |
2713                   +-----------------------------------+-----------------------------------+
2714                   | **2**                             | set all JMS specific parameters   |
2715                   +-----------------------------------+-----------------------------------+
2716                   | **3**                             | the context factory, in this case |
2717                   |                                   | from JBOSS (it requires the       |
2718                   |                                   | dependency                        |
2719                   |                                   | org.jboss:jboss-remote-naming:2.0 |
2720                   |                                   | .4.Final                          |
2721                   |                                   | or a different version to be in   |
2722                   |                                   | the directory ``$APEX_HOME/lib``  |
2723                   |                                   | or ``%APEX_HOME%\lib``            |
2724                   +-----------------------------------+-----------------------------------+
2725                   | **4**                             | a connection factory for the JMS  |
2726                   |                                   | connection                        |
2727                   +-----------------------------------+-----------------------------------+
2728                   | **5**                             | URL with host and port of the JMS |
2729                   |                                   | provider                          |
2730                   +-----------------------------------+-----------------------------------+
2731                   | **6**                             | access credentials, user name     |
2732                   +-----------------------------------+-----------------------------------+
2733                   | **7**                             | access credentials, user password |
2734                   +-----------------------------------+-----------------------------------+
2735                   | **8**                             | the JMS topic to listen to        |
2736                   +-----------------------------------+-----------------------------------+
2737
2738 JMS Output with Text
2739 ====================
2740
2741                .. container:: paragraph
2742
2743                   APEX engine send events to a JMS messaging system. The
2744                   output is uni-directional, an engine will send events
2745                   to the output but not receive any event from output.
2746
2747                .. container:: listingblock
2748
2749                   .. container:: content
2750
2751                      .. code::
2752
2753                         "carrierTechnologyParameters" : {
2754                           "carrierTechnology" : "JMS", (1)
2755                           "parameterClassName" :
2756                               "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2757                           "parameters" : { (2)
2758                             "initialContextFactory" :
2759                                 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2760                             "connectionFactory" : "ConnectionFactory", (4)
2761                             "providerURL" : "remote://localhost:5445", (5)
2762                             "securityPrincipal" : "guest", (6)
2763                             "securityCredentials" : "IAmAGuest", (7)
2764                             "producerTopic" : "jms/topic/apexOut", (8)
2765                             "objectMessageSending": "false" (9)
2766                           }
2767                         }
2768
2769                .. container:: colist arabic
2770
2771                   +-----------------------------------+-----------------------------------+
2772                   | **1**                             | set JMS as carrier technology     |
2773                   +-----------------------------------+-----------------------------------+
2774                   | **2**                             | set all JMS specific parameters   |
2775                   +-----------------------------------+-----------------------------------+
2776                   | **3**                             | the context factory, in this case |
2777                   |                                   | from JBOSS (it requires the       |
2778                   |                                   | dependency                        |
2779                   |                                   | org.jboss:jboss-remote-naming:2.0 |
2780                   |                                   | .4.Final                          |
2781                   |                                   | or a different version to be in   |
2782                   |                                   | the directory ``$APEX_HOME/lib``  |
2783                   |                                   | or ``%APEX_HOME%\lib``            |
2784                   +-----------------------------------+-----------------------------------+
2785                   | **4**                             | a connection factory for the JMS  |
2786                   |                                   | connection                        |
2787                   +-----------------------------------+-----------------------------------+
2788                   | **5**                             | URL with host and port of the JMS |
2789                   |                                   | provider                          |
2790                   +-----------------------------------+-----------------------------------+
2791                   | **6**                             | access credentials, user name     |
2792                   +-----------------------------------+-----------------------------------+
2793                   | **7**                             | access credentials, user password |
2794                   +-----------------------------------+-----------------------------------+
2795                   | **8**                             | the JMS topic to write to         |
2796                   +-----------------------------------+-----------------------------------+
2797                   | **9**                             | set object messaging to ``false`` |
2798                   |                                   | means it sends JSON text          |
2799                   +-----------------------------------+-----------------------------------+
2800
2801 JMS Output with Object
2802 ======================
2803
2804                .. container:: paragraph
2805
2806                   To configure APEX for JMS objects on the output
2807                   interface use the same configuration as above (for
2808                   output). Simply change the ``objectMessageSending``
2809                   parameter to ``true``.
2810
2811 Websocket (WS) IO
2812 #################
2813
2814             .. container:: paragraph
2815
2816                APEX supports the Websockets as input as well as output.
2817                WS IO is supported by the APEX Websocket plugin. This
2818                carrier technology does only support uni-directional
2819                communication. APEX will not send events to a Websocket
2820                input and any event sent to a Websocket output will
2821                result in an error log.
2822
2823             .. container:: paragraph
2824
2825                The input can be configured as client (APEX connects to
2826                an existing Websocket server) or server (APEX starts a
2827                Websocket server). The same applies to the output. Input
2828                and output can both use a client or a server
2829                configuration, or separate configurations (input as
2830                client and output as server, input as server and output
2831                as client). Each configuration should use its own
2832                dedicated port to avoid any communication loops. The
2833                configuration of a Websocket client is the same for input
2834                and output. The configuration of a Websocket server is
2835                the same for input and output.
2836
2837 Websocket Client
2838 ================
2839
2840                .. container:: paragraph
2841
2842                   APEX will connect to a given Websocket server. As
2843                   input, it will receive events from the server but not
2844                   send any events. As output, it will send events to the
2845                   server and any event received from the server will
2846                   result in an error log.
2847
2848                .. container:: listingblock
2849
2850                   .. container:: content
2851
2852                      .. code::
2853
2854                         "carrierTechnologyParameters" : {
2855                           "carrierTechnology" : "WEBSOCKET", (1)
2856                           "parameterClassName" :
2857                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2858                           "parameters" : {
2859                             "host" : "localhost", (2)
2860                             "port" : 42451 (3)
2861                           }
2862                         }
2863
2864                .. container:: colist arabic
2865
2866                   +-------+------------------------------------------------------+
2867                   | **1** | set Websocket as carrier technology                  |
2868                   +-------+------------------------------------------------------+
2869                   | **2** | the host name on which a Websocket server is running |
2870                   +-------+------------------------------------------------------+
2871                   | **3** | the port of that Websocket server                    |
2872                   +-------+------------------------------------------------------+
2873
2874 Websocket Server
2875 ================
2876
2877                .. container:: paragraph
2878
2879                   APEX will start a Websocket server, which will accept
2880                   any Websocket clients to connect. As input, it will
2881                   receive events from the server but not send any
2882                   events. As output, it will send events to the server
2883                   and any event received from the server will result in
2884                   an error log.
2885
2886                .. container:: listingblock
2887
2888                   .. container:: content
2889
2890                      .. code::
2891
2892                         "carrierTechnologyParameters" : {
2893                           "carrierTechnology" : "WEBSOCKET", (1)
2894                           "parameterClassName" :
2895                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2896                           "parameters" : {
2897                             "wsClient" : false, (2)
2898                             "port"     : 42450 (3)
2899                           }
2900                         }
2901
2902                .. container:: colist arabic
2903
2904                   +-------+------------------------------------------------------------+
2905                   | **1** | set Websocket as carrier technology                        |
2906                   +-------+------------------------------------------------------------+
2907                   | **2** | disable client, so that APEX will start a Websocket server |
2908                   +-------+------------------------------------------------------------+
2909                   | **3** | the port for the Websocket server APEX will start          |
2910                   +-------+------------------------------------------------------------+
2911
2912 REST Client IO
2913 ##############
2914
2915             .. container:: paragraph
2916
2917                APEX can act as REST client on the input as well as on
2918                the output interface. The media type is
2919                ``application/json``, so this plugin only works with
2920                the JSON Event protocol.
2921
2922 REST Client Input
2923 =================
2924
2925                .. container:: paragraph
2926
2927                   APEX will connect to a given URL to receive events,
2928                   but not send any events. The server is polled, i.e.
2929                   APEX will do an HTTP GET, take the result, and then do
2930                   the next GET. Any required timing needs to be handled
2931                   by the server configured via the URL. For instance,
2932                   the server could support a wait timeout via the URL as
2933                   ``?timeout=100ms``.
2934                   The httpCodeFilter is used for filtering the status
2935                   code, and it can be configured as a regular expression
2936                   string. The default httpCodeFilter is "[2][0-9][0-9]"
2937                   - for successful response codes.
2938                   The response with HTTP status code that matches the
2939                   given regular expression is forwarded to the task,
2940                   otherwise it is logged as a failure.
2941
2942                .. container:: listingblock
2943
2944                   .. container:: content
2945
2946                      .. code::
2947
2948                         "carrierTechnologyParameters" : {
2949                           "carrierTechnology" : "RESTCLIENT", (1)
2950                           "parameterClassName" :
2951                             "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2952                           "parameters" : {
2953                             "url" : "http://example.org:8080/triggers/events", (2)
2954                             "httpMethod": "GET", (3)
2955                             "httpCodeFilter" : "[2][0-9][0-9]", (4)
2956                              "httpHeaders" : [ (5)
2957                                 ["Keep-Alive", "300"],
2958                                 ["Cache-Control", "no-cache"]
2959                              ]
2960                           }
2961                         }
2962
2963                .. container:: colist arabic
2964
2965                   +-------+--------------------------------------------------+
2966                   | **1** | set REST client as carrier technology            |
2967                   +-------+--------------------------------------------------+
2968                   | **2** | the URL of the HTTP server for events            |
2969                   +-------+--------------------------------------------------+
2970                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
2971                   |       | optional, defaults to GET                        |
2972                   +-------+--------------------------------------------------+
2973                   | **4** | use HTTP CODE FILTER for filtering status code,  |
2974                   |       | optional, defaults to [2][0-9][0-9]              |
2975                   +-------+--------------------------------------------------+
2976                   | **5** | HTTP headers to use on the REST request,         |
2977                   |       | optional                                         |
2978                   +-------+--------------------------------------------------+
2979
2980 REST Client Output
2981 ==================
2982
2983                .. container:: paragraph
2984
2985                   APEX will connect to a given URL to send events, but
2986                   not receive any events. The default HTTP operation is
2987                   POST (no configuration required). To change it to PUT
2988                   simply add the configuration parameter (as shown in
2989                   the example below).
2990                   The URL can be configured statically or tagged
2991                   as ``?example.{site}.org:8080/{trig}/events``,
2992                   all tags such as ``site`` and ``trig`` in the URL
2993                   need to be set in the properties object available to
2994                   the tasks. In addition, the keys should exactly match
2995                   with the tags defined in url. The scope of the properties
2996                   object is per HTTP call. Hence, key/value pairs set
2997                   in the properties object by task are only available
2998                   for that specific HTTP call.
2999
3000                .. container:: listingblock
3001
3002                   .. container:: content
3003
3004                      .. code::
3005
3006                         "carrierTechnologyParameters" : {
3007                           "carrierTechnology" : "RESTCLIENT", (1)
3008                           "parameterClassName" :
3009                             "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
3010                           "parameters" : {
3011                             "url" : "http://example.com:8888/actions/events", (2)
3012                             "url" : "http://example.{site}.com:8888/{trig}/events", (2')
3013                             "httpMethod" : "PUT". (3)
3014                             "httpHeaders" : [ (4)
3015                                ["Keep-Alive", "300"],
3016                                ["Cache-Control", "no-cache"]
3017                             ]                          }
3018                         }
3019
3020                .. container:: colist arabic
3021
3022                   +-------+--------------------------------------------------+
3023                   | **1** | set REST client as carrier technology            |
3024                   +-------+--------------------------------------------------+
3025                   | **2** | the static URL of the HTTP server for events     |
3026                   +-------+--------------------------------------------------+
3027                   | **2'**| the tagged URL of the HTTP server for events     |
3028                   +-------+--------------------------------------------------+
3029                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
3030                   |       | optional, defaults to POST                       |
3031                   +-------+--------------------------------------------------+
3032                   | **4** | HTTP headers to use on the REST request,         |
3033                   |       | optional                                         |
3034                   +-------+--------------------------------------------------+
3035
3036 REST Server IO
3037 ##############
3038
3039             .. container:: paragraph
3040
3041                APEX supports a REST server for input and output.
3042
3043             .. container:: paragraph
3044
3045                The REST server plugin always uses a synchronous mode. A
3046                client does a HTTP GET on the APEX REST server with the
3047                input event and receives the generated output event in
3048                the server reply. This means that for the REST server
3049                there has to always to be an input with an associated
3050                output. Input or output only are not permitted.
3051
3052             .. container:: paragraph
3053
3054                The plugin will start a Grizzly server as REST server for
3055                a normal APEX engine. If the APEX engine is executed as a
3056                servlet, for instance inside Tomcat, then Tomcat will be
3057                used as REST server (this case requires configuration on
3058                Tomcat as well).
3059
3060             .. container:: paragraph
3061
3062                Some configuration restrictions apply for all scenarios:
3063
3064             .. container:: ulist
3065
3066                -  Minimum port: 1024
3067
3068                -  Maximum port: 65535
3069
3070                -  The media type is ``application/json``, so this plugin
3071                   only works with the JSON Event protocol.
3072
3073             .. container:: paragraph
3074
3075                The URL the client calls is created using
3076
3077             .. container:: ulist
3078
3079                -  the configured host and port, e.g.
3080                   ``http://localhost:12345``
3081
3082                -  the standard path, e.g. ``/apex/``
3083
3084                -  the name of the input/output, e.g. ``FirstConsumer/``
3085
3086                -  the input or output name, e.g. ``EventIn``.
3087
3088             .. container:: paragraph
3089
3090                The examples above lead to the URL
3091                ``http://localhost:12345/apex/FirstConsumer/EventIn``.
3092
3093             .. container:: paragraph
3094
3095                A client can also get status information of the REST
3096                server using ``/Status``, e.g.
3097                ``http://localhost:12345/apex/FirstConsumer/Status``.
3098
3099 REST Server Stand-alone
3100 =======================
3101
3102                .. container:: paragraph
3103
3104                   We need to configure a REST server input and a REST
3105                   server output. Input and output are associated with
3106                   each other via there name.
3107
3108                .. container:: paragraph
3109
3110                   Timeouts for REST calls need to be set carefully. If
3111                   they are too short, the call might timeout before a
3112                   policy finished creating an event.
3113
3114                .. container:: paragraph
3115
3116                   The following example configures the input named as
3117                   ``MyConsumer`` and associates an output named
3118                   ``MyProducer`` with it.
3119
3120                .. container:: listingblock
3121
3122                   .. container:: content
3123
3124                      .. code::
3125
3126                         "eventInputParameters": {
3127                           "MyConsumer": {
3128                             "carrierTechnologyParameters" : {
3129                               "carrierTechnology" : "RESTSERVER", (1)
3130                               "parameterClassName" :
3131                                 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters",
3132                               "parameters" : {
3133                                 "standalone" : true, (2)
3134                                 "host" : "localhost", (3)
3135                                 "port" : 12345 (4)
3136                               }
3137                             },
3138                             "eventProtocolParameters":{
3139                               "eventProtocol" : "JSON" (5)
3140                             },
3141                             "synchronousMode"    : true, (6)
3142                             "synchronousPeer"    : "MyProducer", (7)
3143                             "synchronousTimeout" : 500 (8)
3144                           }
3145                         }
3146
3147                .. container:: colist arabic
3148
3149                   +-------+---------------------------------------+
3150                   | **1** | set REST server as carrier technology |
3151                   +-------+---------------------------------------+
3152                   | **2** | set the server as stand-alone         |
3153                   +-------+---------------------------------------+
3154                   | **3** | set the server host                   |
3155                   +-------+---------------------------------------+
3156                   | **4** | set the server listen port            |
3157                   +-------+---------------------------------------+
3158                   | **5** | use JSON event protocol               |
3159                   +-------+---------------------------------------+
3160                   | **6** | activate synchronous mode             |
3161                   +-------+---------------------------------------+
3162                   | **7** | associate an output ``MyProducer``    |
3163                   +-------+---------------------------------------+
3164                   | **8** | set a timeout of 500 milliseconds     |
3165                   +-------+---------------------------------------+
3166
3167                .. container:: paragraph
3168
3169                   The following example configures the output named as
3170                   ``MyProducer`` and associates the input ``MyConsumer``
3171                   with it. Note that for the output there are no more
3172                   paramters (such as host or port), since they are
3173                   already configured in the associated input
3174
3175                .. container:: listingblock
3176
3177                   .. container:: content
3178
3179                      .. code::
3180
3181                         "eventOutputParameters": {
3182                           "MyProducer": {
3183                             "carrierTechnologyParameters":{
3184                               "carrierTechnology" : "RESTSERVER",
3185                               "parameterClassName" :
3186                                 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters"
3187                             },
3188                             "eventProtocolParameters":{
3189                               "eventProtocol" : "JSON"
3190                             },
3191                             "synchronousMode"    : true,
3192                             "synchronousPeer"    : "MyConsumer",
3193                             "synchronousTimeout" : 500
3194                           }
3195                         }
3196
3197 REST Server Stand-alone, multi input
3198 ====================================
3199
3200                .. container:: paragraph
3201
3202                   Any number of input/output pairs for REST servers can
3203                   be configured. For instance, we can configure an input
3204                   ``FirstConsumer`` with output ``FirstProducer`` and an
3205                   input ``SecondConsumer`` with output
3206                   ``SecondProducer``. Important is that there is always
3207                   one pair of input/output.
3208
3209 REST Server Stand-alone in Servlet
3210 ==================================
3211
3212                .. container:: paragraph
3213
3214                   If APEX is executed as a servlet, e.g. inside Tomcat,
3215                   the configuration becomes easier since the plugin can
3216                   now use Tomcat as the REST server. In this scenario,
3217                   there are not parameters (port, host, etc.) and the
3218                   key ``standalone`` must not be used (or set to false).
3219
3220                .. container:: paragraph
3221
3222                   For the Tomcat configuration, we need to add the REST
3223                   server plugin, e.g.
3224
3225                .. container:: listingblock
3226
3227                   .. container:: content
3228
3229                      .. code::
3230
3231                         <servlet>
3232                           ...
3233                           <init-param>
3234                             ...
3235                             <param-value>org.onap.policy.apex.plugins.event.carrier.restserver</param-value>
3236                           </init-param>
3237                           ...
3238                         </servlet>
3239
3240 REST Requestor IO
3241 #################
3242
3243             .. container:: paragraph
3244
3245                APEX can act as REST requestor on the input as well as on
3246                the output interface. The media type is
3247                ``application/json``, so this plugin only works with
3248                the JSON Event protocol. This plugin allows APEX to send REST requests
3249                and to receive the reply of that request without tying up APEX resources
3250                while the request is being processed. The REST Requestor pairs a REST
3251                requestor producer and consumer together to handle the REST request
3252                and response. The REST request is created from an APEX output event
3253                and the REST response is input into APEX as a new input event.
3254
3255 REST Requestor Output (REST Request Producer)
3256 =============================================
3257
3258                .. container:: paragraph
3259
3260                   APEX sends a REST request when events are output by APEX, the REST
3261                   request configuration is specified on the REST Request Consumer (see
3262                   below).
3263
3264                .. container:: listingblock
3265
3266                   .. container:: content
3267
3268                      .. code::
3269
3270                         "carrierTechnologyParameters": {
3271                           "carrierTechnology": "RESTREQUESTOR", (1)
3272                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters"
3273                         },
3274
3275                .. container:: colist arabic
3276
3277                   +-------+------------------------------------------+
3278                   | **1** | set REST requestor as carrier technology |
3279                   +-------+------------------------------------------+
3280
3281                .. container:: paragraph
3282
3283                   The settings below are required on the producer to
3284                   define the event that triggers the REST request and
3285                   to specify the peered consumer configuration for the
3286                   REST request, for example:
3287
3288                .. container:: listingblock
3289
3290                   .. container:: content
3291
3292                      .. code::
3293
3294                         "eventNameFilter": "GuardRequestEvent", (1)
3295                         "requestorMode": true, (2)
3296                         "requestorPeer": "GuardRequestorConsumer", (3)
3297                         "requestorTimeout": 500 (4)
3298
3299                .. container:: colist arabic
3300
3301                   +-------+-------------------------------------------+
3302                   | **1** | a filter on the event                     |
3303                   +-------+-------------------------------------------+
3304                   | **2** | requestor mode must be set to *true*      |
3305                   +-------+-------------------------------------------+
3306                   | **3** | the peered consumer for REST requests,    |
3307                   |       | that consumer specifies the full          |
3308                   |       | configuration for REST requests           |
3309                   +-------+-------------------------------------------+
3310                   | **4** | the request timeout in milliseconds,      |
3311                   |       | overridden by timeout on consumer if that |
3312                   |       | is set, optional defaults to 500          |
3313                   |       | millisconds                               |
3314                   +-------+-------------------------------------------+
3315
3316 REST Requestor Input (REST Request Consumer)
3317 ============================================
3318
3319                .. container:: paragraph
3320
3321                   APEX will connect to a given URL to issue a REST request and
3322                   wait for a REST response.
3323                   The URL can be configured statically or tagged
3324                   as ``?example.{site}.org:8080/{trig}/events``,
3325                   all tags such as ``site`` and ``trig`` in the URL
3326                   need to be set in the properties object available to
3327                   the tasks. In addition, the keys should exactly match
3328                   with the tags defined in url. The scope of the properties
3329                   object is per HTTP call. Hence, key/value pairs set
3330                   in the properties object by task are only available
3331                   for that specific HTTP call.
3332                   The httpCodeFilter is used for filtering the status
3333                   code, and it can be configured as a regular expression
3334                   string. The default httpCodeFilter is "[2][0-9][0-9]"
3335                   - for successful response codes.
3336                   The response with HTTP status code that matches the
3337                   given regular expression is forwarded to the task,
3338                   otherwise it is logged as a failure.
3339
3340                .. container:: listingblock
3341
3342                   .. container:: content
3343
3344                      .. code::
3345
3346                         "carrierTechnologyParameters": {
3347                           "carrierTechnology": "RESTREQUESTOR", (1)
3348                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters",
3349                           "parameters": {
3350                             "url": "http://localhost:54321/some/path/to/rest/resource", (2)
3351                             "url": "http://localhost:54321/{site}/path/to/rest/{resValue}", (2')
3352                             "httpMethod": "POST", (3)
3353                             "requestorMode": true, (4)
3354                             "requestorPeer": "GuardRequestorProducer", (5)
3355                             "restRequestTimeout": 2000, (6)
3356                             "httpCodeFilter" : "[2][0-9][0-9]" (7)
3357                             "httpHeaders" : [ (8)
3358                                ["Keep-Alive", "300"],
3359                                ["Cache-Control", "no-cache"]
3360                             ]                          }
3361                         },
3362
3363                .. container:: colist arabic
3364
3365                   +-------+--------------------------------------------------+
3366                   | **1** | set REST requestor as carrier technology         |
3367                   +-------+--------------------------------------------------+
3368                   | **2** | the static URL of the HTTP server for events     |
3369                   +-------+--------------------------------------------------+
3370                   | **2'**| the tagged URL of the HTTP server for events     |
3371                   +-------+--------------------------------------------------+
3372                   | **3** | the HTTP method to use (GET/PUT/POST/DELETE),    |
3373                   |       | optional, defaults to GET                        |
3374                   +-------+--------------------------------------------------+
3375                   | **4** | requestor mode must be set to *true*             |
3376                   +-------+--------------------------------------------------+
3377                   | **5** | the peered producer for REST requests, that      |
3378                   |       | producer specifies the APEX output event that    |
3379                   |       | triggers the REST request                        |
3380                   +-------+--------------------------------------------------+
3381                   | **6** | request timeout in milliseconds, overrides any   |
3382                   |       | value set in the REST Requestor Producer,        |
3383                   |       | optional, defaults to 500 millisconds            |
3384                   +-------+--------------------------------------------------+
3385                   | **7** | use HTTP CODE FILTER for filtering status code   |
3386                   |       | optional, defaults to [2][0-9][0-9]              |
3387                   +-------+--------------------------------------------------+
3388                   | **8** | HTTP headers to use on the REST request,         |
3389                   |       | optional                                         |
3390                   +-------+--------------------------------------------------+
3391
3392                .. container:: paragraph
3393
3394                   Further settings may be required on the consumer to
3395                   define the input event that is produced and forwarded into
3396                   APEX, for example:
3397
3398                .. container:: listingblock
3399
3400                   .. container:: content
3401
3402                      .. code::
3403
3404                         "eventName": "GuardResponseEvent", (1)
3405                         "eventNameFilter": "GuardResponseEvent" (2)
3406
3407                .. container:: colist arabic
3408
3409                   +-------+---------------------------+
3410                   | **1** | the event name            |
3411                   +-------+---------------------------+
3412                   | **2** | a filter on the event     |
3413                   +-------+---------------------------+
3414
3415 gRPC IO
3416 #######
3417
3418             .. container:: paragraph
3419
3420                APEX can send requests over gRPC at the output side, and get back
3421                response at the input side. This can be used to send requests to CDS
3422                over gRPC. The media type is ``application/json``, so this plugin
3423                only works with the JSON Event protocol.
3424
3425 gRPC Output
3426 ===========
3427
3428                .. container:: paragraph
3429
3430                   APEX will connect to a given host to send a request over
3431                   gRPC.
3432
3433                .. container:: listingblock
3434
3435                   .. container:: content
3436
3437                      .. code::
3438
3439                         "carrierTechnologyParameters": {
3440                           "carrierTechnology": "GRPC", (1)
3441                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters",
3442                           "parameters": {
3443                             "host": "cds-blueprints-processor-grpc", (2)
3444                             "port": 9111, (2')
3445                             "username": "ccsdkapps", (3)
3446                             "password": ccsdkapps, (4)
3447                             "timeout" : 10 (5)
3448                           }
3449                         },
3450
3451                .. container:: colist arabic
3452
3453                   +-------+--------------------------------------------------+
3454                   | **1** | set GRPC as carrier technology                   |
3455                   +-------+--------------------------------------------------+
3456                   | **2** | the host to which request is sent                |
3457                   +-------+--------------------------------------------------+
3458                   | **2'**| the value for port                               |
3459                   +-------+--------------------------------------------------+
3460                   | **3** | username required to initiate connection         |
3461                   +-------+--------------------------------------------------+
3462                   | **4** | password required to initiate connection         |
3463                   +-------+--------------------------------------------------+
3464                   | **5** | the timeout value for completing the request     |
3465                   +-------+--------------------------------------------------+
3466
3467                .. container:: paragraph
3468
3469                   Further settings are required on the producer to
3470                   define the event that is requested, for example:
3471
3472                .. container:: listingblock
3473
3474                   .. container:: content
3475
3476                      .. code::
3477
3478                         "eventName": "GRPCRequestEvent", (1)
3479                         "eventNameFilter": "GRPCRequestEvent", (2)
3480                         "requestorMode": true, (3)
3481                         "requestorPeer": "GRPCRequestConsumer", (4)
3482                         "requestorTimeout": 500 (5)
3483
3484                .. container:: colist arabic
3485
3486                   +-------+---------------------------+
3487                   | **1** | the event name            |
3488                   +-------+---------------------------+
3489                   | **2** | a filter on the event     |
3490                   +-------+---------------------------+
3491                   | **3** | the mode of the requestor |
3492                   +-------+---------------------------+
3493                   | **4** | a peer for the requestor  |
3494                   +-------+---------------------------+
3495                   | **5** | a general request timeout |
3496                   +-------+---------------------------+
3497
3498 gRPC Input
3499 ==========
3500
3501                .. container:: paragraph
3502
3503                   APEX will connect to the host specified in the producer
3504                   side, anad take in response back at the consumer side.
3505
3506                .. container:: listingblock
3507
3508                   .. container:: content
3509
3510                      .. code::
3511
3512                         "carrierTechnologyParameters": {
3513                           "carrierTechnology": "GRPC", (1)
3514                           "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters"
3515                         },
3516
3517                .. container:: colist arabic
3518
3519                   +-------+------------------------------------------+
3520                   | **1** | set GRPC as carrier technology           |
3521                   +-------+------------------------------------------+
3522
3523                .. container:: paragraph
3524
3525                   Further settings are required on the consumer to
3526                   define the event that is requested, for example:
3527
3528                .. container:: listingblock
3529
3530                   .. container:: content
3531
3532                      .. code::
3533
3534                         "eventNameFilter": "GRPCResponseEvent", (1)
3535                         "requestorMode": true, (2)
3536                         "requestorPeer": "GRPCRequestProducer", (3)
3537                         "requestorTimeout": 500 (4)
3538
3539                .. container:: colist arabic
3540
3541                   +-------+---------------------------+
3542                   | **1** | a filter on the event     |
3543                   +-------+---------------------------+
3544                   | **2** | the mode of the requestor |
3545                   +-------+---------------------------+
3546                   | **3** | a peer for the requestor  |
3547                   +-------+---------------------------+
3548                   | **4** | a general request timeout |
3549                   +-------+---------------------------+
3550
3551 Event Protocols, Format and Encoding
3552 ------------------------------------
3553
3554          .. container:: paragraph
3555
3556             Event protocols define what event formats APEX can receive
3557             (input) and should send (output). They can be used in any
3558             combination for input and output, unless further restricted
3559             by a carrier technology plugin (for instance for JMS
3560             output). There can only be 1 event protocol per event
3561             plugin.
3562
3563          .. container:: paragraph
3564
3565             Supported *input* event protocols are:
3566
3567          .. container:: ulist
3568
3569             -  JSON, the event as a JSON string
3570
3571             -  APEX, an APEX event
3572
3573             -  JMS object, the event as a JMS object,
3574
3575             -  JMS text, the event as a JMS text,
3576
3577             -  XML, the event as an XML string,
3578
3579             -  YAML, the event as YAML text
3580
3581          .. container:: paragraph
3582
3583             Supported *output* event protocols are:
3584
3585          .. container:: ulist
3586
3587             -  JSON, the event as a JSON string
3588
3589             -  APEX, an APEX event
3590
3591             -  JMS object, the event as a JMS object,
3592
3593             -  JMS text, the event as a JMS text,
3594
3595             -  XML, the event as an XML string,
3596
3597             -  YAML, the event as YAML text
3598
3599          .. container:: paragraph
3600
3601             New event protocols can be added as plugins to APEX or
3602             developed outside APEX and added to an APEX deployment.
3603
3604 JSON Event
3605 ##########
3606
3607             .. container:: paragraph
3608
3609                The event protocol for JSON encoding does not require a
3610                specific plugin, it is supported by default. Furthermore,
3611                there is no difference in the configuration for the input
3612                and output interface.
3613
3614             .. container:: paragraph
3615
3616                For an input, APEX requires a well-formed JSON string.
3617                Well-formed here means according to the definitions of a
3618                policy. Any JSON string that is not defined as a trigger
3619                event (consume) will not be consumed (errors will be
3620                thrown). For output JSON events, APEX will always produce
3621                valid JSON strings according to the definition in the
3622                policy model.
3623
3624             .. container:: paragraph
3625
3626                The following JSON shows the configuration.
3627
3628             .. container:: listingblock
3629
3630                .. container:: content
3631
3632                   .. code::
3633
3634                      "eventProtocolParameters":{
3635                        "eventProtocol" : "JSON"
3636                      }
3637
3638             .. container:: paragraph
3639
3640                For JSON events, there are a few more optional
3641                parameters, which allow to define a mapping for standard
3642                event fields. An APEX event must have the fields
3643                ``name``, ``version``, ``source``, and ``target``
3644                defined. Sometimes it is not possible to configure a
3645                trigger or actioning system to use those fields. However,
3646                they might be in an event generated outside APEX (or used
3647                outside APEX) just with different names. To configure
3648                APEX to map between the different event names, simply add
3649                the following parameters to a JSON event:
3650
3651             .. container:: listingblock
3652
3653                .. container:: content
3654
3655                   .. code::
3656
3657                      "eventProtocolParameters":{
3658                        "eventProtocol" : "JSON",
3659                        "nameAlias"     : "policyName", (1)
3660                        "versionAlias"  : "policyVersion", (2)
3661                        "sourceAlias"   : "from", (3)
3662                        "targetAlias"   : "to", (4)
3663                        "nameSpaceAlias": "my.name.space" (5)
3664                      }
3665
3666             .. container:: colist arabic
3667
3668                +-----------------------------------+-----------------------------------+
3669                | **1**                             | mapping for the ``name`` field,   |
3670                |                                   | here from a field called          |
3671                |                                   | ``policyName``                    |
3672                +-----------------------------------+-----------------------------------+
3673                | **2**                             | mapping for the ``version``       |
3674                |                                   | field, here from a field called   |
3675                |                                   | ``policyVersion``                 |
3676                +-----------------------------------+-----------------------------------+
3677                | **3**                             | mapping for the ``source`` field, |
3678                |                                   | here from a field called ``from`` |
3679                |                                   | (only for an input event)         |
3680                +-----------------------------------+-----------------------------------+
3681                | **4**                             | mapping for the ``target`` field, |
3682                |                                   | here from a field called ``to``   |
3683                |                                   | (only for an output event)        |
3684                +-----------------------------------+-----------------------------------+
3685                | **5**                             | mapping for the ``nameSpace``     |
3686                |                                   | field, here from a field called   |
3687                |                                   | ``my.name.space``                 |
3688                +-----------------------------------+-----------------------------------+
3689
3690 APEX Event
3691 ##########
3692             .. container:: paragraph
3693
3694                The event protocol for APEX events does not require a
3695                specific plugin, it is supported by default. Furthermore,
3696                there is no difference in the configuration for the input
3697                and output interface.
3698
3699             .. container:: paragraph
3700
3701                For input and output APEX uses APEX events.
3702
3703             .. container:: paragraph
3704
3705                The following JSON shows the configuration.
3706
3707             .. container:: listingblock
3708
3709                .. container:: content
3710
3711                   .. code::
3712
3713                      "eventProtocolParameters":{
3714                        "eventProtocol" : "APEX"
3715                      }
3716
3717 JMS Event
3718 #########
3719
3720             .. container:: paragraph
3721
3722                The event protocol for JMS is provided by the APEX JMS
3723                plugin. The plugin supports encoding as JSON text or as
3724                object. There is no difference in the configuration for
3725                the input and output interface.
3726
3727 JMS Text
3728 ========
3729                .. container:: paragraph
3730
3731                   If used as input, APEX will take a JMS message and
3732                   extract a JSON string, then proceed as if a JSON event
3733                   was received. If used as output, APEX will take the
3734                   event produced by a policy, create a JSON string, and
3735                   then wrap it into a JMS message.
3736
3737                .. container:: paragraph
3738
3739                   The configuration for JMS text is as follows:
3740
3741                .. container:: listingblock
3742
3743                   .. container:: content
3744
3745                      .. code::
3746
3747                         "eventProtocolParameters":{
3748                           "eventProtocol" : "JMSTEXT",
3749                           "parameterClassName" :
3750                             "org.onap.policy.apex.plugins.event.protocol.jms.JMSTextEventProtocolParameters"
3751                         }
3752
3753 JMS Object
3754 ==========
3755                .. container:: paragraph
3756
3757                   If used as input, APEX will will take a JMS message,
3758                   extract a Java Bean from the ``ObjectMessage``
3759                   message, construct an APEX event and put the bean on
3760                   the APEX event as a parameter. If used as output, APEX
3761                   will take the event produced by a policy, create a
3762                   Java Bean and send it as a JMS message.
3763
3764                .. container:: paragraph
3765
3766                   The configuration for JMS object is as follows:
3767
3768                .. container:: listingblock
3769
3770                   .. container:: content
3771
3772                      .. code::
3773
3774                         "eventProtocolParameters":{
3775                           "eventProtocol" : "JMSOBJECT",
3776                           "parameterClassName" :
3777                             "org.onap.policy.apex.plugins.event.protocol.jms.JMSObjectEventProtocolParameters"
3778                         }
3779
3780 YAML Event
3781 ##########
3782
3783             .. container:: paragraph
3784
3785                The event protocol for YAML is provided by the APEX YAML
3786                plugin. There is no difference in the configuration for
3787                the input and output interface.
3788
3789             .. container:: paragraph
3790
3791                If used as input, APEX will consume events as YAML and
3792                map them to policy trigger events. Not well-formed YAML
3793                and not understood trigger events will be rejected. If
3794                used as output, APEX produce YAML encoded events from the
3795                event a policy produces. Those events will always be
3796                well-formed according to the definition in the policy
3797                model.
3798
3799             .. container:: paragraph
3800
3801                The following code shows the configuration.
3802
3803             .. container:: listingblock
3804
3805                .. container:: content
3806
3807                   .. code::
3808
3809                      "eventProtocolParameters":{
3810                        "eventProtocol" : "XML",
3811                        "parameterClassName" :
3812                            "org.onap.policy.apex.plugins.event.protocol.yaml.YamlEventProtocolParameters"
3813                      }
3814
3815 XML Event
3816 #########
3817             .. container:: paragraph
3818
3819                The event protocol for XML is provided by the APEX XML
3820                plugin. There is no difference in the configuration for
3821                the input and output interface.
3822
3823             .. container:: paragraph
3824
3825                If used as input, APEX will consume events as XML and map
3826                them to policy trigger events. Not well-formed XML and
3827                not understood trigger events will be rejected. If used
3828                as output, APEX produce XML encoded events from the event
3829                a policy produces. Those events will always be
3830                well-formed according to the definition in the policy
3831                model.
3832
3833             .. container:: paragraph
3834
3835                The following code shows the configuration.
3836
3837             .. container:: listingblock
3838
3839                .. container:: content
3840
3841                   .. code::
3842
3843                      "eventProtocolParameters":{
3844                        "eventProtocol" : "XML",
3845                        "parameterClassName" :
3846                            "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3847                      }
3848
3849 A configuration example
3850 -----------------------
3851
3852          .. container:: paragraph
3853
3854             The following example loads all available plug-ins.
3855
3856          .. container:: paragraph
3857
3858             Events are consumed from a Websocket, APEX as client.
3859             Consumed event format is JSON.
3860
3861          .. container:: paragraph
3862
3863             Events are produced to Kafka. Produced event format is XML.
3864
3865          .. container:: listingblock
3866
3867             .. container:: content
3868
3869                .. code::
3870
3871                   {
3872                     "engineServiceParameters" : {
3873                       "name"          : "MyApexEngine",
3874                       "version"        : "0.0.1",
3875                       "id"             :  45,
3876                       "instanceCount"  : 4,
3877                       "deploymentPort" : 12345,
3878                       "engineParameters"    : {
3879                         "executorParameters" : {
3880                           "JAVASCRIPT" : {
3881                             "parameterClassName" :
3882                                 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
3883                           },
3884                           "JYTHON" : {
3885                             "parameterClassName" :
3886                                 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
3887                           },
3888                           "JRUBY" : {
3889                             "parameterClassName" :
3890                                 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
3891                           },
3892                           "JAVA" : {
3893                             "parameterClassName" :
3894                                 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
3895                           },
3896                           "MVEL" : {
3897                             "parameterClassName" :
3898                                 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
3899                           }
3900                         },
3901                         "contextParameters" : {
3902                           "parameterClassName" :
3903                               "org.onap.policy.apex.context.parameters.ContextParameters",
3904                           "schemaParameters" : {
3905                             "Avro":{
3906                                "parameterClassName" :
3907                                    "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
3908                             }
3909                           }
3910                         }
3911                       }
3912                     },
3913                     "producerCarrierTechnologyParameters" : {
3914                       "carrierTechnology" : "KAFKA",
3915                       "parameterClassName" :
3916                           "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
3917                       "parameters" : {
3918                         "bootstrapServers"  : "localhost:49092",
3919                         "acks"              : "all",
3920                         "retries"           : 0,
3921                         "batchSize"         : 16384,
3922                         "lingerTime"        : 1,
3923                         "bufferMemory"      : 33554432,
3924                         "producerTopic"     : "apex-out",
3925                         "keySerializer"     : "org.apache.kafka.common.serialization.StringSerializer",
3926                         "valueSerializer"   : "org.apache.kafka.common.serialization.StringSerializer"
3927                       }
3928                     },
3929                     "producerEventProtocolParameters" : {
3930                       "eventProtocol" : "XML",
3931                            "parameterClassName" :
3932                                "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3933                     },
3934                     "consumerCarrierTechnologyParameters" : {
3935                       "carrierTechnology" : "WEBSOCKET",
3936                       "parameterClassName" :
3937                           "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
3938                       "parameters" : {
3939                         "host" : "localhost",
3940                         "port" : 88888
3941                       }
3942                     },
3943                     "consumerEventProtocolParameters" : {
3944                       "eventProtocol" : "JSON"
3945                     }
3946                   }
3947
3948 Engine and Applications of the APEX System
3949 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3950
3951 Introduction to APEX Engine and Applications
3952 --------------------------------------------
3953
3954          .. container:: paragraph
3955
3956             The core of APEX is the APEX Engine, also known as the APEX
3957             Policy Engine or the APEX PDP (since it is in fact a Policy
3958             Decision Point). Beside this engine, an APEX system comes
3959             with a few applications intended to help with policy
3960             authoring, deployment, and execution.
3961
3962          .. container:: paragraph
3963
3964             The engine itself and most applications are started from the
3965             command line with command line arguments. This is called a
3966             Command Line Interface (CLI). Some applications require an
3967             installation on a webserver, as for instance the REST
3968             Editor. Those applications can be accessed via a web
3969             browser.
3970
3971          .. container:: paragraph
3972
3973             You can also use the available APEX APIs and applications to
3974             develop other applications as required. This includes policy
3975             languages (and associated parsers and compilers /
3976             interpreters), GUIs to access APEX or to define policies,
3977             clients to connect to APEX, etc.
3978
3979          .. container:: paragraph
3980
3981             For this documentation, we assume an installation of APEX as
3982             a full system based on a current ONAP release.
3983
3984 CLI on Unix, Windows, and Cygwin
3985 --------------------------------
3986
3987          .. container:: paragraph
3988
3989             A note on APEX CLI applications: all applications and the
3990             engine itself have been deployed and tested on different
3991             operating systems: Red Hat, Ubuntu, Debian, Mac OSX,
3992             Windows, Cygwin. Each operating system comes with its own
3993             way of configuring and executing Java. The main items here
3994             are:
3995
3996          .. container:: ulist
3997
3998             -  For UNIX systems (RHL, Ubuntu, Debian, Mac OSX), the
3999                provided bash scripts work as expected with absolute
4000                paths (e.g.
4001                ``/opt/app/policy/apex-pdp/apex-pdp-2.0.0-SNAPSHOT/examples``),
4002                indirect and linked paths (e.g. ``../apex/apex``), and
4003                path substitutions using environment settings (e.g.
4004                ``$APEX_HOME/bin/``)
4005
4006             -  For Windows systems, the provided batch files (``.bat``)
4007                work as expected with with absolute paths (e.g.
4008                ``C:\apex\apex-2.0.0-SNAPSHOT\examples``), and path
4009                substitutions using environment settings (e.g.
4010                ``%APEX_HOME%\bin\``)
4011
4012             -  For Cygwin system we assume a standard Cygwin
4013                installation with standard tools (mainly bash) using a
4014                Windows Java installation. This means that the bash
4015                scripts can be used as in UNIX, however any argument
4016                pointing to files and directories need to use either a
4017                DOS path (e.g.
4018                ``C:\apex\apex-2.0.0-SNAPSHOT\examples\config...``) or
4019                the command ``cygpath`` with a mixed option. The reason
4020                for that is: Cygwin executes Java using UNIX paths but
4021                then runs Java as a DOS/WINDOWS process, which requires
4022                DOS paths for file access.
4023
4024 The APEX Engine
4025 ---------------
4026
4027          .. container:: paragraph
4028
4029             The APEX engine can be started in different ways, depending
4030             your requirements. All scripts are located in the APEX *bin*
4031             directory
4032
4033          .. container:: paragraph
4034
4035             On UNIX and Cygwin systems use:
4036
4037          .. container:: ulist
4038
4039             -  ``apexEngine.sh`` - this script will
4040
4041                .. container:: ulist
4042
4043                   -  Test if ``$APEX_USER`` is set and if the user
4044                      exists, terminate with an error otherwise
4045
4046                   -  Test if ``$APEX_HOME`` is set. If not set, it will
4047                      use the default setting as
4048                      ``/opt/app/policy/apex-pdp/apex-pdp``. Then the set
4049                      directory is tested to exist, the script will
4050                      terminate if not.
4051
4052                   -  When all tests are passed successfully, the script
4053                      will call ``apexApps.sh`` with arguments to start
4054                      the APEX engine.
4055
4056             -  ``apexApps.sh engine`` - this is the general APEX
4057                application launcher, which will
4058
4059                .. container:: ulist
4060
4061                   -  Start the engine with the argument ``engine``
4062
4063                   -  Test if ``$APEX_HOME`` is set and points to an
4064                      existing directory. If not set or directory does
4065                      not exist, script terminates.
4066
4067                   -  Not test for any settings of ``$APEX_USER``.
4068
4069          .. container:: paragraph
4070
4071             On Windows systems use ``apexEngine.bat`` and
4072             ``apexApps.bat engine`` respectively. Note: none of the
4073             windows batch files will test for ``%APEX_USER%``.
4074
4075          .. container:: paragraph
4076
4077             Summary of alternatives to start the APEX Engine:
4078
4079          +--------------------------------------------------------+----------------------------------------------------------+
4080          | Unix, Cygwin                                           | Windows                                                  |
4081          +========================================================+==========================================================+
4082          | .. container::                                         | .. container::                                           |
4083          |                                                        |                                                          |
4084          |    .. container:: listingblock                         |    .. container:: listingblock                           |
4085          |                                                        |                                                          |
4086          |       .. container:: content                           |       .. container:: content                             |
4087          |                                                        |                                                          |
4088          |          .. code::                                     |          .. code::                                       |
4089          |                                                        |                                                          |
4090          |             # $APEX_HOME/bin/apexEngine.sh [args]      |             > %APEX_HOME%\bin\apexEngine.bat [args]      |
4091          |             # $APEX_HOME/bin/apexApps.sh engine [args] |             > %APEX_HOME%\bin\apexApps.bat engine [args] |
4092          +--------------------------------------------------------+----------------------------------------------------------+
4093
4094          .. container:: paragraph
4095
4096             The APEX engine comes with a few CLI arguments, the main one is for setting
4097             the tosca policy file for execution. The tosca policy file is
4098             always required. The option ``-h`` prints a help screen.
4099
4100          .. container:: listingblock
4101
4102             .. container:: content
4103
4104                .. code::
4105
4106                   usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]
4107                   options
4108                   -p,--tosca-policy-file <TOSCA_POLICY_FILE>     the full path to the ToscaPolicy file to use.
4109                   -h,--help                                      outputs the usage of this command
4110                   -v,--version                                   outputs the version of Apex
4111
4112 The APEX CLI Editor
4113 -------------------
4114
4115          .. container:: paragraph
4116
4117             The CLI Editor allows to define policies from the command
4118             line. The application uses a simple language and supports
4119             all elements of an APEX policy. It can be used in to
4120             different ways:
4121
4122          .. container:: ulist
4123
4124             -  non-interactive, specifying a file with the commands to
4125                create a policy
4126
4127             -  interactive, using the editors CLI to create a policy
4128
4129          .. container:: paragraph
4130
4131             When a policy is fully specified, the editor will generate
4132             the APEX core policy specification in JSON. This core
4133             specification is called the policy model in the APEX engine
4134             and can be used directly with the APEX engine.
4135
4136          .. container:: paragraph
4137
4138             On UNIX and Cygwin systems use:
4139
4140          .. container:: ulist
4141
4142             -  ``apexCLIEditor.sh`` - simply starts the CLI editor,
4143                arguments to the script determine the mode of the editor
4144
4145             -  ``apexApps.sh cli-editor`` - simply starts the CLI
4146                editor, arguments to the script determine the mode of the
4147                editor
4148
4149          .. container:: paragraph
4150
4151             On Windows systems use:
4152
4153          .. container:: ulist
4154
4155             -  ``apexCLIEditor.bat`` - simply starts the CLI editor,
4156                arguments to the script determine the mode of the editor
4157
4158             -  ``apexApps.bat cli-editor`` - simply starts the CLI
4159                editor, arguments to the script determine the mode of the
4160                editor
4161
4162          .. container:: paragraph
4163
4164             Summary of alternatives to start the APEX CLI Editor:
4165
4166          +------------------------------------------------------------+--------------------------------------------------------------+
4167          | Unix, Cygwin                                               | Windows                                                      |
4168          +============================================================+==============================================================+
4169          | .. container::                                             | .. container::                                               |
4170          |                                                            |                                                              |
4171          |    .. container:: listingblock                             |    .. container:: listingblock                               |
4172          |                                                            |                                                              |
4173          |       .. container:: content                               |       .. container:: content                                 |
4174          |                                                            |                                                              |
4175          |          .. code::                                         |          .. code::                                           |
4176          |                                                            |                                                              |
4177          |             # $APEX_HOME/bin/apexCLIEditor.sh.sh [args]    |             > %APEX_HOME%\bin\apexCLIEditor.bat [args]       |
4178          |             # $APEX_HOME/bin/apexApps.sh cli-editor [args] |             > %APEX_HOME%\bin\apexApps.bat cli-editor [args] |
4179          +------------------------------------------------------------+--------------------------------------------------------------+
4180
4181          .. container:: paragraph
4182
4183             The option ``-h`` provides a help screen with all command
4184             line arguments.
4185
4186          .. container:: listingblock
4187
4188             .. container:: content
4189
4190                .. code::
4191
4192                   usage: org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain [options...]
4193                   options
4194                    -a,--model-props-file <MODEL_PROPS_FILE>       name of the apex model properties file to use
4195                    -c,--command-file <COMMAND_FILE>               name of a file containing editor commands to run into the editor
4196                    -h,--help                                      outputs the usage of this command
4197                    -i,--input-model-file <INPUT_MODEL_FILE>       name of a file that contains an input model for the editor
4198                    -if,--ignore-failures <IGNORE_FAILURES_FLAG>   true or false, ignore failures of commands in command files and continue
4199                                                                   executing the command file
4200                    -l,--log-file <LOG_FILE>                       name of a file that will contain command logs from the editor, will log
4201                                                                   to standard output if not specified or suppressed with "-nl" flag
4202                    -m,--metadata-file <CMD_METADATA_FILE>         name of the command metadata file to use
4203                    -nl,--no-log                                   if specified, no logging or output of commands to standard output or log
4204                                                                   file is carried out
4205                    -nm,--no-model-output                          if specified, no output of a model to standard output or model output
4206                                                                   file is carried out, the user can use the "save" command in a script to
4207                                                                   save a model
4208                    -o,--output-model-file <OUTPUT_MODEL_FILE>     name of a file that will contain the output model for the editor, will
4209                                                                   output model to standard output if not specified or suppressed with
4210                                                                   "-nm" flag
4211                    -wd,--working-directory <WORKING_DIRECTORY>    the working directory that is the root for the CLI editor and is the
4212                                                                   root from which to look for included macro files
4213
4214 The APEX CLI Tosca Editor
4215 -------------------------
4216
4217          .. container:: paragraph
4218
4219             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.
4220
4221          .. container:: paragraph
4222
4223             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.
4224
4225          .. container:: paragraph
4226
4227             On UNIX and Cygwin systems use:
4228
4229          .. container:: ulist
4230
4231             -  ``apexCLIToscaEditor.sh`` - starts the CLI Tosca editor,
4232                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4233
4234             -  ``apexApps.sh cli-tosca-editor`` - starts the CLI Tosca editor,
4235                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4236
4237          .. container:: paragraph
4238
4239             On Windows systems use:
4240
4241          .. container:: ulist
4242
4243             -  ``apexCLIToscaEditor.bat`` - starts the CLI Tosca editor,
4244                all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4245
4246             -  ``apexApps.bat cli-tosca-editor`` - starts the CLI Tosca
4247                editor, all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4248
4249          .. container:: paragraph
4250
4251             Summary of alternatives to start the APEX CLI Tosca Editor:
4252
4253      +-----------------------------------------------------------------+--------------------------------------------------------------------+
4254      | Unix, Cygwin                                                    | Windows                                                            |
4255      +=================================================================+====================================================================+
4256      | .. container::                                                  | .. container::                                                     |
4257      |                                                                 |                                                                    |
4258      |    .. container:: listingblock                                  |    .. container:: listingblock                                     |
4259      |                                                                 |                                                                    |
4260      |       .. container:: content                                    |       .. container:: content                                       |
4261      |                                                                 |                                                                    |
4262      |          .. code::                                              |          .. code::                                                 |
4263      |                                                                 |                                                                    |
4264      |             # $APEX_HOME/bin/apexCLIToscaEditor.sh.sh [args]    |             > %APEX_HOME%\bin\apexCLIToscaEditor.bat [args]        |
4265      |             # $APEX_HOME/bin/apexApps.sh cli-tosca-editor [args]|             > %APEX_HOME%\bin\apexApps.bat cli-tosca-editor [args] |
4266      +-----------------------------------------------------------------+--------------------------------------------------------------------+
4267
4268          .. container:: paragraph
4269
4270             The option ``-h`` provides a help screen with all command
4271             line arguments.
4272
4273          .. container:: listingblock
4274
4275             .. container:: content
4276
4277                .. code::
4278
4279                   usage: org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain [options...]
4280                   options
4281                    -a,--model-props-file <MODEL_PROPS_FILE>         name of the apex model properties file to use
4282                    -ac,--apex-config-file <APEX_CONFIG_FILE>        name of the file containing apex configuration details
4283                    -c,--command-file <COMMAND_FILE>                 name of a file containing editor commands to run into the editor
4284                    -h,--help                                        outputs the usage of this command
4285                    -i,--input-model-file <INPUT_MODEL_FILE>         name of a file that contains an input model for the editor
4286                    -if,--ignore-failures <IGNORE_FAILURES_FLAG>     true or false, ignore failures of commands in command files and
4287                                                                     continue executing the command file
4288                    -l,--log-file <LOG_FILE>                         name of a file that will contain command logs from the editor, will
4289                                                                     log to standard output if not specified or suppressed with "-nl" flag
4290                    -m,--metadata-file <CMD_METADATA_FILE>           name of the command metadata file to use
4291                    -nl,--no-log                                     if specified, no logging or output of commands to standard output or
4292                                                                     log file is carried out
4293                    -ot,--output-tosca-file <OUTPUT_TOSCA_FILE>      name of a file that will contain the output ToscaServiceTemplate
4294                    -t,--tosca-template-file <TOSCA_TEMPLATE_FILE>   name of the input file containing tosca template which needs to be
4295                                                                     updated with policy
4296                    -wd,--working-directory <WORKING_DIRECTORY>      the working directory that is the root for the CLI editor and is the
4297                                                                     root from which to look for included macro files
4298
4299          .. container:: paragraph
4300
4301             An example command to run the APEX CLI Tosca editor on windows machine is given below.
4302
4303          .. container:: listingblock
4304
4305             .. container:: content
4306
4307                .. code::
4308
4309                   %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
4310
4311
4312 The APEX Client
4313 ---------------
4314
4315          .. container:: paragraph
4316
4317             The APEX Client combines the Policy Editor, the
4318             Monitoring Client, and the Deployment Client into a single
4319             application. The standard way to use the APEX Full Client is
4320             via an installation of the *war* file on a webserver.
4321             However, the Full Client can also be started via command
4322             line. This will start a Grizzly webserver with the *war*
4323             deployed. Access to the Full Client is then via the provided
4324             URL
4325
4326          .. container:: paragraph
4327
4328             On UNIX and Cygwin systems use:
4329
4330          .. container:: ulist
4331
4332             -  ``apexApps.sh full-client`` - simply starts the webserver
4333                with the Full Client
4334
4335          .. container:: paragraph
4336
4337             On Windows systems use:
4338
4339          .. container:: ulist
4340
4341             -  ``apexApps.bat full-client`` - simply starts the
4342                webserver with the Full Client
4343
4344          .. container:: paragraph
4345
4346             The option ``-h`` provides a help screen with all command
4347             line arguments.
4348
4349          .. container:: listingblock
4350
4351             .. container:: content
4352
4353                .. code::
4354
4355                   usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4356                   -h,--help                        outputs the usage of this command
4357                   -p,--port <PORT>                 port to use for the Apex Services REST calls
4358                   -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4359
4360          .. container:: paragraph
4361
4362             If the Full Client is started without any arguments the
4363             final messages will look similar to this:
4364
4365          .. container:: listingblock
4366
4367             .. container:: content
4368
4369                .. code::
4370
4371                   Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4372                   Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4373                   INFO: Started listener bound to [localhost:18989]
4374                   Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4375                   INFO: [HttpServer] Started.
4376                   Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4377
4378          .. container:: paragraph
4379
4380             The last line states the URL on which the Monitoring Client
4381             can be accessed. The example above stated
4382             ``http://localhost:18989/apexservices``. In a web browser
4383             use the URL ``http://localhost:18989``.
4384
4385 The APEX Application Launcher
4386 -----------------------------
4387
4388          .. container:: paragraph
4389
4390             The standard applications (Engine and CLI Editor)
4391             come with dedicated start scripts. For all other APEX
4392             applications, we provide an application launcher.
4393
4394          .. container:: paragraph
4395
4396             On UNIX and Cygwin systems use:
4397
4398          .. container:: ulist
4399
4400             -  apexApps.sh\` - simply starts the application launcher
4401
4402          .. container:: paragraph
4403
4404             On Windows systems use:
4405
4406          .. container:: ulist
4407
4408             -  ``apexApps.bat`` - simply starts the application launcher
4409
4410          .. container:: paragraph
4411
4412             Summary of alternatives to start the APEX application
4413             launcher:
4414
4415          +-------------------------------------------------+---------------------------------------------------+
4416          | Unix, Cygwin                                    | Windows                                           |
4417          +=================================================+===================================================+
4418          | .. container::                                  | .. container::                                    |
4419          |                                                 |                                                   |
4420          |    .. container:: listingblock                  |    .. container:: listingblock                    |
4421          |                                                 |                                                   |
4422          |       .. container:: content                    |       .. container:: content                      |
4423          |                                                 |                                                   |
4424          |          .. code::                              |          .. code::                                |
4425          |                                                 |                                                   |
4426          |             # $APEX_HOME/bin/apexApps.sh [args] |             > %APEX_HOME%\bin\apexApps.bat [args] |
4427          +-------------------------------------------------+---------------------------------------------------+
4428
4429          .. container:: paragraph
4430
4431             The option ``-h`` provides a help screen with all launcher
4432             command line arguments.
4433
4434          .. container:: listingblock
4435
4436             .. container:: content
4437
4438                .. code::
4439
4440                   apexApps.sh - runs APEX applications
4441
4442                          Usage:  apexApps.sh [options] | [<application> [<application options>]]
4443
4444                          Options
4445                            -d <app>    - describes an application
4446                            -l          - lists all applications supported by this script
4447                            -h          - this help screen
4448
4449          .. container:: paragraph
4450
4451             Using ``-l`` lists all known application the launcher can
4452             start.
4453
4454          .. container:: listingblock
4455
4456             .. container:: content
4457
4458                .. code::
4459
4460                   apexApps.sh: supported applications:
4461                    --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4462
4463          .. container:: paragraph
4464
4465             Using the ``-d <name>`` option describes the named
4466             application, for instance for the ``ws-console``:
4467
4468          .. container:: listingblock
4469
4470             .. container:: content
4471
4472                .. code::
4473
4474                   apexApps.sh: application 'ws-console'
4475                    --> a simple console sending events to APEX, connect to APEX consumer port
4476
4477          .. container:: paragraph
4478
4479             Launching an application is done by calling the script with
4480             only the application name and any CLI arguments for the
4481             application. For instance, starting the ``ws-echo``
4482             application with port ``8888``:
4483
4484          .. container:: listingblock
4485
4486             .. container:: content
4487
4488                .. code::
4489
4490                   apexApps.sh ws-echo -p 8888
4491
4492 Application: Create Event Templates
4493 -----------------------------------
4494
4495          .. container:: paragraph
4496
4497             **Status: Experimental**
4498
4499          .. container:: paragraph
4500
4501             This application takes a policy model (JSON or XML encoded)
4502             and generates templates for events in JSON format. This can
4503             help when a policy defines rather complex trigger or action
4504             events or complex events between states. The application can
4505             produce events for the types: stimuli (policy trigger
4506             events), internal (events between policy states), and
4507             response (action events).
4508
4509          +----------------------------------------------------------------+------------------------------------------------------------------+
4510          | Unix, Cygwin                                                   | Windows                                                          |
4511          +================================================================+==================================================================+
4512          | .. container::                                                 | .. container::                                                   |
4513          |                                                                |                                                                  |
4514          |    .. container:: listingblock                                 |    .. container:: listingblock                                   |
4515          |                                                                |                                                                  |
4516          |       .. container:: content                                   |       .. container:: content                                     |
4517          |                                                                |                                                                  |
4518          |          .. code::                                             |          .. code::                                               |
4519          |                                                                |                                                                  |
4520          |             # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] |             > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4521          +----------------------------------------------------------------+------------------------------------------------------------------+
4522
4523          .. container:: paragraph
4524
4525             The option ``-h`` provides a help screen.
4526
4527          .. container:: listingblock
4528
4529             .. container:: content
4530
4531                .. code::
4532
4533                   gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4534                   usage: gen-model2event
4535                    -h,--help                 prints this help and usage screen
4536                    -m,--model <MODEL-FILE>   set the input policy model file
4537                    -t,--type <TYPE>          set the event type for generation, one of:
4538                                              stimuli (trigger events), response (action
4539                                              events), internal (events between states)
4540                    -v,--version              prints the application version
4541
4542          .. container:: paragraph
4543
4544             The created templates are not valid events, instead they use
4545             some markup for values one will need to change to actual
4546             values. For instance, running the tool with the *Sample
4547             Domain* policy model as:
4548
4549          .. container:: listingblock
4550
4551             .. container:: content
4552
4553                .. code::
4554
4555                   apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4556
4557          .. container:: paragraph
4558
4559             will produce the following status messages:
4560
4561          .. container:: listingblock
4562
4563             .. container:: content
4564
4565                .. code::
4566
4567                   gen-model2event: starting Event generator
4568                    --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4569                    --> type: stimuli
4570
4571          .. container:: paragraph
4572
4573             and then run the generator application producing two event
4574             templates. The first template is called ``Event0000``.
4575
4576          .. container:: listingblock
4577
4578             .. container:: content
4579
4580                .. code::
4581
4582                   {
4583                           "name" : "Event0000",
4584                           "nameSpace" : "org.onap.policy.apex.sample.events",
4585                           "version" : "0.0.1",
4586                           "source" : "Outside",
4587                           "target" : "Match",
4588                           "TestTemperature" : ###double: 0.0###,
4589                           "TestTimestamp" : ###long: 0###,
4590                           "TestMatchCase" : ###integer: 0###,
4591                           "TestSlogan" : "###string###"
4592                   }
4593
4594          .. container:: paragraph
4595
4596             The values for the keys are marked with ``#`` and the
4597             expected type of the value. To create an actual stimuli
4598             event, all these markers need to be change to actual values,
4599             for instance:
4600
4601          .. container:: listingblock
4602
4603             .. container:: content
4604
4605                .. code::
4606
4607                   {
4608                           "name" : "Event0000",
4609                           "nameSpace" : "org.onap.policy.apex.sample.events",
4610                           "version" : "0.0.1",
4611                           "source" : "Outside",
4612                           "target" : "Match",
4613                           "TestTemperature" : 25,
4614                           "TestTimestamp" : 123456789123456789,
4615                           "TestMatchCase" : 1,
4616                           "TestSlogan" : "Testing the Match Case with Temperature 25"
4617                   }
4618
4619 Application: Convert a Policy Model to CLI Editor Commands
4620 ----------------------------------------------------------
4621
4622          .. container:: paragraph
4623
4624             **Status: Experimental**
4625
4626          .. container:: paragraph
4627
4628             This application takes a policy model (JSON or XML encoded)
4629             and generates commands for the APEX CLI Editor. This
4630             effectively reverses a policy specification realized with
4631             the CLI Editor.
4632
4633          +-------------------------------------------------------------+---------------------------------------------------------------+
4634          | Unix, Cygwin                                                | Windows                                                       |
4635          +=============================================================+===============================================================+
4636          | .. container::                                              | .. container::                                                |
4637          |                                                             |                                                               |
4638          |    .. container:: listingblock                              |    .. container:: listingblock                                |
4639          |                                                             |                                                               |
4640          |       .. container:: content                                |       .. container:: content                                  |
4641          |                                                             |                                                               |
4642          |          .. code::                                          |          .. code::                                            |
4643          |                                                             |                                                               |
4644          |             # $APEX_HOME/bin/apexApps.sh model-2-cli [args] |             > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4645          +-------------------------------------------------------------+---------------------------------------------------------------+
4646
4647          .. container:: paragraph
4648
4649             The option ``-h`` provides a help screen.
4650
4651          .. container:: listingblock
4652
4653             .. container:: content
4654
4655                .. code::
4656
4657                   usage: gen-model2cli
4658                    -h,--help                 prints this help and usage screen
4659                    -m,--model <MODEL-FILE>   set the input policy model file
4660                    -sv,--skip-validation     switch of validation of the input file
4661                    -v,--version              prints the application version
4662
4663          .. container:: paragraph
4664
4665             For instance, running the tool with the *Sample Domain*
4666             policy model as:
4667
4668          .. container:: listingblock
4669
4670             .. container:: content
4671
4672                .. code::
4673
4674                   apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4675
4676          .. container:: paragraph
4677
4678             will produce the following status messages:
4679
4680          .. container:: listingblock
4681
4682             .. container:: content
4683
4684                .. code::
4685
4686                   gen-model2cli: starting CLI generator
4687                    --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4688
4689          .. container:: paragraph
4690
4691             and then run the generator application producing all CLI
4692             Editor commands and printing them to standard out.
4693
4694 Application: Websocket Clients (Echo and Console)
4695 -------------------------------------------------
4696
4697          .. container:: paragraph
4698
4699             **Status: Production**
4700
4701          .. container:: paragraph
4702
4703             The application launcher also provides a Websocket echo
4704             client and a Websocket console client. The echo client
4705             connects to APEX and prints all events it receives from
4706             APEX. The console client connects to APEX, reads input from
4707             the command line, and sends this input as events to APEX.
4708
4709          +------------------------------------------------------------+--------------------------------------------------------------+
4710          | Unix, Cygwin                                               | Windows                                                      |
4711          +============================================================+==============================================================+
4712          | .. container::                                             | .. container::                                               |
4713          |                                                            |                                                              |
4714          |    .. container:: listingblock                             |    .. container:: listingblock                               |
4715          |                                                            |                                                              |
4716          |       .. container:: content                               |       .. container:: content                                 |
4717          |                                                            |                                                              |
4718          |          .. code::                                         |          .. code::                                           |
4719          |                                                            |                                                              |
4720          |             # $APEX_HOME/bin/apexApps.sh ws-echo [args]    |             > %APEX_HOME%\bin\apexApps.bat ws-echo [args]    |
4721          |             # $APEX_HOME/bin/apexApps.sh ws-console [args] |             > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4722          +------------------------------------------------------------+--------------------------------------------------------------+
4723
4724          .. container:: paragraph
4725
4726             The arguments are the same for both applications:
4727
4728          .. container:: ulist
4729
4730             -  ``-p`` defines the Websocket port to connect to (defaults
4731                to ``8887``)
4732
4733             -  ``-s`` defines the host on which a Websocket server is
4734                running (defaults to ``localhost``)
4735
4736          .. container:: paragraph
4737
4738             A discussion on how to use these two applications to build
4739             an APEX system is detailed HowTo-Websockets.
4740
4741 APEX Logging
4742 ^^^^^^^^^^^^
4743
4744 Introduction to APEX Logging
4745 ----------------------------
4746
4747          .. container:: paragraph
4748
4749             All APEX components make extensive use of logging using the
4750             logging façade `SLF4J <https://www.slf4j.org/>`__ with the
4751             backend `Logback <https://logback.qos.ch/>`__. Both are used
4752             off-the-shelve, so the standard documentation and
4753             configuration apply to APEX logging. For details on how to
4754             work with logback please see the `logback
4755             manual <https://logback.qos.ch/manual/index.html>`__.
4756
4757          .. container:: paragraph
4758
4759             The APEX applications is the logback configuration file
4760             ``$APEX_HOME/etc/logback.xml`` (Windows:
4761             ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
4762             to no debug, i.e. logs from the logging framework should be
4763             hidden at runtime.
4764
4765          .. container:: paragraph
4766
4767             The configurable log levels work as expected:
4768
4769          .. container:: ulist
4770
4771             -  *error* (or *ERROR*) is used for serious errors in the
4772                APEX runtime engine
4773
4774             -  *warn* (or *WARN*) is used for warnings, which in general
4775                can be ignored but might indicate some deeper problems
4776
4777             -  *info* (or *INFO*) is used to provide generally
4778                interesting messages for startup and policy execution
4779
4780             -  *debug* (or *DEBUG*) provides more details on startup and
4781                policy execution
4782
4783             -  *trace* (or *TRACE*) gives full details on every aspect
4784                of the APEX engine from start to end
4785
4786          .. container:: paragraph
4787
4788             The loggers can also be configured as expected. The standard
4789             configuration (after installing APEX) uses log level *info*
4790             on all APEX classes (components).
4791
4792          .. container:: paragraph
4793
4794             The applications and scripts in ``$APEX_HOME/bin`` (Windows:
4795             ``%APEX_HOME\bin``) are configured to use the logback
4796             configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
4797             ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
4798             use different logback configurations, for instance:
4799
4800          .. container:: ulist
4801
4802             -  Maintain multiple configurations in ``etc``, for instance
4803                a ``logback-debug.xml`` for deep debugging and a
4804                ``logback-production.xml`` for APEX in production mode,
4805                then copy the required configuration file to the used
4806                ``logback.xml`` prior starting APEX
4807
4808             -  Edit the scripts in ``bin`` to use a different logback
4809                configuration file (only recommended if you are familiar
4810                with editing bash scripts or windows batch files)
4811
4812 Standard Logging Configuration
4813 ------------------------------
4814
4815          .. container:: paragraph
4816
4817             The standard logging configuration defines a context *APEX*,
4818             which is used in the standard output pattern. The location
4819             for log files is defined in the property ``logDir`` and set
4820             to ``/var/log/onap/policy/apex-pdp``. The standard status
4821             listener is set to *NOP* and the overall logback
4822             configuration is set to no debug.
4823
4824          .. container:: listingblock
4825
4826             .. container:: content
4827
4828                .. code::
4829                  :number-lines:
4830
4831                  <configuration debug="false">
4832                    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
4833
4834                     <contextName>Apex</contextName>
4835                     <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
4836
4837                    ...appenders
4838                    ...loggers
4839                  </configuration>
4840
4841 .. container:: paragraph
4842
4843    The first appender defined is called ``STDOUT`` for logs to standard
4844    out.
4845
4846 .. container:: listingblock
4847
4848    .. container:: content
4849
4850       .. code::
4851         :number-lines:
4852
4853         <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4854          <encoder>
4855             <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
4856           </encoder>
4857         </appender>
4858
4859 .. container:: paragraph
4860
4861    The root level logger then is set to the level *info* using the
4862    standard out appender.
4863
4864 .. container:: listingblock
4865
4866    .. container:: content
4867
4868       .. code::
4869         :number-lines:
4870
4871         <root level="info">
4872           <appender-ref ref="STDOUT" />
4873         </root>
4874
4875 .. container:: paragraph
4876
4877    The second appender is called ``FILE``. It writes logs to a file
4878    ``apex.log``.
4879
4880 .. container:: listingblock
4881
4882    .. container:: content
4883
4884       .. code::
4885         :number-lines:
4886
4887         <appender name="FILE" class="ch.qos.logback.core.FileAppender">
4888           <file>${logDir}/apex.log</file>
4889           <encoder>
4890             <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
4891           </encoder>
4892         </appender>
4893
4894 .. container:: paragraph
4895
4896    The third appender is called ``CTXT_FILE``. It writes logs to a file
4897    ``apex_ctxt.log``.
4898
4899 .. container:: listingblock
4900
4901    .. container:: content
4902
4903       .. code::
4904         :number-lines:
4905
4906         <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
4907           <file>${logDir}/apex_ctxt.log</file>
4908           <encoder>
4909             <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
4910           </encoder>
4911         </appender>
4912
4913 .. container:: paragraph
4914
4915    The last definitions are for specific loggers. The first logger
4916    captures all standard APEX classes. It is configured for log level
4917    *info* and uses the standard output and file appenders. The second
4918    logger captures APEX context classes responsible for context
4919    monitoring. It is configured for log level *trace* and uses the
4920    context file appender.
4921
4922 .. container:: listingblock
4923
4924    .. container:: content
4925
4926       .. code::
4927         :number-lines:
4928
4929
4930         <logger name="org.onap.policy.apex" level="info" additivity="false">
4931           <appender-ref ref="STDOUT" />
4932           <appender-ref ref="FILE" />
4933         </logger>
4934
4935         <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
4936           <appender-ref ref="CTXT_FILE" />
4937         </logger>
4938
4939 Adding Logback Status and Debug
4940 -------------------------------
4941
4942    .. container:: paragraph
4943
4944       To activate logback status messages change the status listener
4945       from 'NOP' to for instance console.
4946
4947    .. container:: listingblock
4948
4949       .. container:: content
4950
4951          .. code::
4952
4953             <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
4954
4955    .. container:: paragraph
4956
4957       To activate all logback debugging, for instance to debug a new
4958       logback configuration, activate the debug attribute in the
4959       configuration.
4960
4961    .. container:: listingblock
4962
4963       .. container:: content
4964
4965          .. code::
4966
4967             <configuration debug="true">
4968             ...
4969             </configuration>
4970
4971 Logging External Components
4972 ---------------------------
4973
4974    .. container:: paragraph
4975
4976       Logback can also be configured to log any other, external
4977       components APEX is using, if they are using the common logging
4978       framework.
4979
4980    .. container:: paragraph
4981
4982       For instance, the context component of APEX is using *Infinispan*
4983       and one can add a logger for this external component. The
4984       following example adds a logger for *Infinispan* using the
4985       standard output appender.
4986
4987    .. container:: listingblock
4988
4989       .. container:: content
4990
4991          .. code::
4992
4993             <logger name="org.infinispan" level="INFO" additivity="false">
4994               <appender-ref ref="STDOUT" />
4995             </logger>
4996
4997    .. container:: paragraph
4998
4999       Another example is Apache Zookeeper. The following example adds a
5000       logger for Zookeeper using the standard outout appender.
5001
5002    .. container:: listingblock
5003
5004       .. container:: content
5005
5006          .. code::
5007
5008             <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
5009               <appender-ref ref="STDOUT" />
5010             </logger>
5011
5012 Configuring loggers for Policy Logic
5013 ------------------------------------
5014
5015    .. container:: paragraph
5016
5017       The logging for the logic inside a policy (task logic, task
5018       selection logic, state finalizer logic) can be configured separate
5019       from standard logging. The logger for policy logic is
5020       ``org.onap.policy.apex.executionlogging``. The following example
5021       defines
5022
5023    .. container:: ulist
5024
5025       -  a new appender for standard out using a very simple pattern
5026          (simply the actual message)
5027
5028       -  a logger for policy logic to standard out using the new
5029          appender and the already described file appender.
5030
5031    .. container:: listingblock
5032
5033       .. container:: content
5034
5035          .. code::
5036
5037             <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5038               <encoder>
5039                 <pattern>policy: %msg\n</pattern>
5040               </encoder>
5041             </appender>
5042
5043             <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
5044               <appender-ref ref="POLICY_APPENDER_STDOUT" />
5045               <appender-ref ref="FILE" />
5046             </logger>
5047
5048    .. container:: paragraph
5049
5050       It is also possible to use specific logging for parts of policy
5051       logic. The following example defines a logger for task logic.
5052
5053    .. container:: listingblock
5054
5055       .. container:: content
5056
5057          .. code::
5058
5059             <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
5060               <appender-ref ref="POLICY_APPENDER_STDOUT" />
5061             </logger>
5062
5063 Rolling File Appenders
5064 ----------------------
5065
5066    .. container:: paragraph
5067
5068       Rolling file appenders are a good option for more complex logging
5069       of a production or complex testing APEX installation. The standard
5070       logback configuration can be used for these use cases. This
5071       section gives two examples for the standard logging and for
5072       context logging.
5073
5074    .. container:: paragraph
5075
5076       First the standard logging. The following example defines a
5077       rolling file appender. The appender rolls over on a daily basis.
5078       It allows for a file size of 100 MB.
5079
5080    .. container:: listingblock
5081
5082       .. container:: content
5083
5084          .. code::
5085
5086             <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
5087               <file>${logDir}/apex.log</file>
5088               <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
5089                 <!-- rollover daily -->
5090                 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
5091                 <fileNamePattern>${logDir}/apex_%d{yyyy-MM-dd}.%i.log.gz
5092                 </fileNamePattern>
5093                 <maxHistory>4</maxHistory>
5094                 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
5095                   <!-- or whenever the file size reaches 100MB -->
5096                   <maxFileSize>100MB</maxFileSize>
5097                 </timeBasedFileNamingAndTriggeringPolicy>
5098               </rollingPolicy>
5099               <encoder>
5100                 <pattern>
5101                   %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
5102                 </pattern>
5103               </encoder>
5104             </appender>
5105
5106    .. container:: paragraph
5107
5108       A very similar configuration can be used for a rolling file
5109       appender logging APEX context.
5110
5111    .. container:: listingblock
5112
5113       .. container:: content
5114
5115          .. code::
5116
5117             <appender name="CTXT-FILE"
5118                   class="ch.qos.logback.core.rolling.RollingFileAppender">
5119               <file>${logDir}/apex_ctxt.log</file>
5120               <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
5121                 <fileNamePattern>${logDir}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
5122                 </fileNamePattern>
5123                 <maxHistory>4</maxHistory>
5124                 <timeBasedFileNamingAndTriggeringPolicy
5125                     class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
5126                   <maxFileSize>100MB</maxFileSize>
5127                 </timeBasedFileNamingAndTriggeringPolicy>
5128               </rollingPolicy>
5129               <encoder>
5130                 <pattern>
5131                   %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
5132                 </pattern>
5133               </encoder>
5134             </appender>
5135
5136 Example Configuration for Logging Logic
5137 ---------------------------------------
5138
5139    .. container:: paragraph
5140
5141       The following example shows a configuration that logs policy logic
5142       to standard out and a file (*info*). All other APEX components are
5143       logging to a file (*debug*).. This configuration an be used in a
5144       pre-production phase with the APEX engine still running in a
5145       separate terminal to monitor policy execution. This logback
5146       configuration is in the APEX installation as
5147       ``etc/logback-logic.xml``.
5148
5149    .. container:: listingblock
5150
5151       .. container:: content
5152
5153          .. code::
5154
5155             <configuration debug="false">
5156                 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
5157
5158                 <contextName>Apex</contextName>
5159                 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
5160
5161                 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5162                     <encoder>
5163                         <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
5164                     </encoder>
5165                 </appender>
5166
5167                 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
5168                     <file>${logDir}/apex.log</file>
5169                     <encoder>
5170                         <pattern>
5171                             %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
5172                         </pattern>
5173                     </encoder>
5174                 </appender>
5175
5176                 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5177                     <encoder>
5178                         <pattern>policy: %msg\n</pattern>
5179                     </encoder>
5180                 </appender>
5181
5182                 <root level="error">
5183                     <appender-ref ref="STDOUT" />
5184                 </root>
5185
5186                 <logger name="org.onap.policy.apex" level="debug" additivity="false">
5187                     <appender-ref ref="FILE" />
5188                 </logger>
5189
5190                 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
5191                     <appender-ref ref="POLICY_APPENDER_STDOUT" />
5192                     <appender-ref ref="FILE" />
5193                 </logger>
5194             </configuration>
5195
5196 Example Configuration for a Production Server
5197 ---------------------------------------------
5198
5199    .. container:: paragraph
5200
5201       The following example shows a configuration that logs all APEX
5202       components, including policy logic, to a file (*debug*). This
5203       configuration an be used in a production phase with the APEX
5204       engine being executed as a service on a system without console
5205       output. This logback configuration is in the APEX installation as
5206       ``logback-server.xml``
5207
5208    .. container:: listingblock
5209
5210       .. container:: content
5211
5212          .. code::
5213
5214             <configuration debug="false">
5215                 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
5216
5217                 <contextName>Apex</contextName>
5218                 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
5219
5220                 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
5221                     <file>${logDir}/apex.log</file>
5222                     <encoder>
5223                         <pattern>
5224                             %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
5225                         </pattern>
5226                     </encoder>
5227                 </appender>
5228
5229                 <root level="debug">
5230                     <appender-ref ref="FILE" />
5231                 </root>
5232
5233                 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
5234                     <appender-ref ref="FILE" />
5235                 </logger>
5236             </configuration>
5237
5238 Unsupported Features
5239 ^^^^^^^^^^^^^^^^^^^^
5240
5241          .. container:: paragraph
5242
5243             This section documents some legacy and unsupported features
5244             in apex-pdp. The documentation here has not been updated for
5245             recent versions of apex-pdp. For example, the apex-pdp models
5246             specified in this example should now be in TOSCA format.
5247
5248 Building a System with Websocket Backend
5249 ----------------------------------------
5250
5251 Websockets
5252 ##########
5253
5254          .. container:: paragraph
5255
5256             Websocket is a protocol to run sockets of HTTP. Since it in
5257             essence a socket, the connection is realized between a
5258             server (waiting for connections) and a client (connecting to
5259             a server). Server/client separation is only important for
5260             connection establishment, once connected, everyone can
5261             send/receive on the same socket (as any standard socket
5262             would allow).
5263
5264          .. container:: paragraph
5265
5266             Standard Websocket implementations are simple, no
5267             publish/subscribe and no special event handling. Most
5268             servers simply send all incoming messages to all
5269             connections. There is a PubSub definition on top of
5270             Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
5271             does not support WAMP at the moment.
5272
5273 Websocket in Java
5274 #################
5275
5276          .. container:: paragraph
5277
5278             In Java, `JSR
5279             356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
5280             defines the standard Websocket API. This JSR is part of Jave
5281             EE 7 standard. For Java SE, several implementations exist in
5282             open source. Since Websockets are a stable standard and
5283             simple, most implementations are stable and ready to use. A
5284             lot of products support Websockets, like Spring, JBoss,
5285             Netty, … there are also Kafka extensions for Websockets.
5286
5287 Websocket Example Code for Websocket clients (FOSS)
5288 ###################################################
5289
5290          .. container:: paragraph
5291
5292             There are a lot of implementations and examples available on
5293             Github for Websocket clients. If one is using Java EE 7,
5294             then one can also use the native Websocket implementation.
5295             Good examples for clients using simply Java SE are here:
5296
5297          .. container:: ulist
5298
5299             -  `Websocket
5300                implementation <https://github.com/TooTallNate/Java-WebSocket>`__
5301
5302             -  `Websocket sending client example, using
5303                AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
5304
5305             -  `Websocket receiving client example (simple echo
5306                client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
5307
5308          .. container:: paragraph
5309
5310             For Java EE, the native Websocket API is explained here:
5311
5312          .. container:: ulist
5313
5314             -  `Oracle
5315                docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
5316
5317             -  link: `An
5318                example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
5319
5320 BCP: Websocket Configuration
5321 ############################
5322
5323          .. container:: paragraph
5324
5325             The probably best is to configure APEX for Websocket servers
5326             for input (ingress, consume) and output (egress, produce)
5327             interfaces. This means that APEX will start Websocket
5328             servers on named ports and wait for clients to connect.
5329             Advantage: once APEX is running all connectivity
5330             infrastructure is running as well. Consequence: if APEX is
5331             not running, everyone else is in the dark, too.
5332
5333          .. container:: paragraph
5334
5335             The best protocol to be used is JSON string. Each event on
5336             any interface is then a string with a JSON encoding. JSON
5337             string is a little bit slower than byte code, but we doubt
5338             that this will be noticeable. A further advantage of JSON
5339             strings over Websockets with APEX starting the servers: it
5340             is very easy to connect web browsers to such a system.
5341             Simple connect the web browser to the APEX sockets and
5342             send/read JSON strings.
5343
5344          .. container:: paragraph
5345
5346             Once APEX is started you simply connect Websocket clients to
5347             it, and send/receive event. When APEX is terminated, the
5348             Websocket servers go down, and the clients will be
5349             disconnected. APEX does not (yet) support auto-client
5350             reconnect nor WAMP, so clients might need to be restarted or
5351             reconnected manually after an APEX boot.
5352
5353 Demo with VPN Policy Model
5354 ##########################
5355
5356          .. container:: paragraph
5357
5358             We assume that you have an APEX installation using the full
5359             package, i.e. APEX with all examples, of version ``0.5.6``
5360             or higher. We will use the VPN policy from the APEX examples
5361             here.
5362
5363          .. container:: paragraph
5364
5365             Now, have the following ready to start the demo:
5366
5367          .. container:: ulist
5368
5369             -  3 terminals on the host where APEX is running (we need 1
5370                for APEX and 1 for each client)
5371
5372             -  the events in the file
5373                ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
5374                in an editor (we need to send those events to APEX)
5375
5376             -  the events in the file
5377                ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
5378                in an editor (we need to send those events to APEX)
5379
5380 A Websocket Configuration for the VPN Domain
5381 ********************************************
5382
5383             .. container:: paragraph
5384
5385                Create a new APEX configuration using the VPN policy
5386                model and configuring APEX as discussed above for
5387                Websockets. Copy the following configuration into
5388                ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
5389                (for Windows use
5390                ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
5391
5392             .. container:: listingblock
5393
5394                .. container:: content
5395
5396                   .. code::
5397                     :number-lines:
5398
5399                     {
5400                       "engineServiceParameters" : {
5401                         "name"          : "VPNApexEngine",
5402                         "version"        : "0.0.1",
5403                         "id"             :  45,
5404                         "instanceCount"  : 1,
5405                         "deploymentPort" : 12345,
5406                         "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
5407                         "engineParameters"    : {
5408                           "executorParameters" : {
5409                             "MVEL" : {
5410                               "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
5411                             }
5412                           },
5413                           "contextParameters" : {
5414                             "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
5415                             "schemaParameters":{
5416                               "Avro":{
5417                                 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
5418                               }
5419                             }
5420                           }
5421                         }
5422                       },
5423                       "producerCarrierTechnologyParameters" : {
5424                         "carrierTechnology" : "WEBSOCKET",
5425                         "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
5426                         "parameters" : {
5427                           "wsClient" : false,
5428                           "port"     : 42452
5429                         }
5430                       },
5431                       "producerEventProtocolParameters" : {
5432                         "eventProtocol" : "JSON"
5433                       },
5434                       "consumerCarrierTechnologyParameters" : {
5435                         "carrierTechnology" : "WEBSOCKET",
5436                         "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
5437                         "parameters" : {
5438                          "wsClient" : false,
5439                           "port"     : 42450
5440                         }
5441                       },
5442                       "consumerEventProtocolParameters" : {
5443                         "eventProtocol" : "JSON"
5444                       }
5445                     }
5446
5447 Start APEX Engine
5448 *****************
5449
5450    .. container:: paragraph
5451
5452       In a new terminal, start APEX with the new configuration for
5453       Websocket-Server ingress/egress:
5454
5455    .. container:: listingblock
5456
5457       .. container:: content
5458
5459          .. code::
5460             :number-lines:
5461
5462             #: $APEX_HOME/bin/apexApps.sh engine -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
5463
5464 .. container:: listingblock
5465
5466    .. container:: content
5467
5468       .. code::
5469         :number-lines:
5470
5471         #: %APEX_HOME%\bin\apexApps.bat engine -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
5472
5473 .. container:: paragraph
5474
5475    Wait for APEX to start, it takes a while to create all Websocket
5476    servers (about 8 seconds on a standard laptop without cached
5477    binaries). depending on your log messages, you will see no (some, a
5478    lot) log messages. If APEX starts correctly, the last few messages
5479    you should see are:
5480
5481 .. container:: listingblock
5482
5483    .. container:: content
5484
5485       .. code::
5486         :number-lines:
5487
5488          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)
5489          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 ...
5490          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
5491          Started Apex service
5492
5493 .. container:: paragraph
5494
5495    APEX is running in the new terminal and will produce output when the
5496    policy is triggered/executed.
5497
5498 Run the Websocket Echo Client
5499 *****************************
5500
5501    .. container:: paragraph
5502
5503       The echo client is included in an APEX full installation. To run
5504       the client, open a new shell (Unix, Cygwin) or command prompt
5505       (``cmd`` on Windows). Then use the APEX application launcher to
5506       start the client.
5507
5508    .. important::
5509       APEX engine needs to run first
5510       The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
5511
5512    +---------------------------------------------------------+-----------------------------------------------------------+
5513    | Unix, Cygwin                                            | Windows                                                   |
5514    +=========================================================+===========================================================+
5515    | .. container::                                          | .. container::                                            |
5516    |                                                         |                                                           |
5517    |    .. container:: listingblock                          |    .. container:: listingblock                            |
5518    |                                                         |                                                           |
5519    |       .. container:: content                            |       .. container:: content                              |
5520    |                                                         |                                                           |
5521    |          .. code::                                      |          .. code::                                        |
5522    |                                                         |                                                           |
5523    |             # $APEX_HOME/bin/apexApps.sh ws-echo [args] |             > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
5524    +---------------------------------------------------------+-----------------------------------------------------------+
5525
5526    .. container:: paragraph
5527
5528       Use the following command line arguments for server and port of
5529       the Websocket server. The port should be the same as configured in
5530       the APEX engine. The server host should be the host on which the
5531       APEX engine is running
5532
5533    .. container:: ulist
5534
5535       -  ``-p`` defines the Websocket port to connect to (defaults to
5536          ``8887``)
5537
5538       -  ``-s`` defines the host on which a Websocket server is running
5539          (defaults to ``localhost``)
5540
5541    .. container:: paragraph
5542
5543       Let’s assume that there is an APEX engine running, configured for
5544       produce Websocket carrier technology, as server, for port 42452,
5545       with produce event protocol JSON,. If we start the console client
5546       on the same host, we can omit the ``-s`` options. We start the
5547       console client as:
5548
5549    .. container:: listingblock
5550
5551       .. container:: content
5552
5553          .. code::
5554
5555             # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
5556             > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
5557
5558    .. container:: colist arabic
5559
5560       +-------+--------------------------------+
5561       | **1** | Start client on Unix or Cygwin |
5562       +-------+--------------------------------+
5563       | **2** | Start client on Windows        |
5564       +-------+--------------------------------+
5565
5566    .. container:: paragraph
5567
5568       Once started successfully, the client will produce the following
5569       messages (assuming we used ``-p 42452`` and an APEX engine is
5570       running on ``localhost`` with the same port:
5571
5572    .. container:: listingblock
5573
5574       .. container:: content
5575
5576          .. code::
5577
5578             ws-simple-echo: starting simple event echo
5579              --> server: localhost
5580              --> port: 42452
5581
5582             Once started, the application will simply print out all received events to standard out.
5583             Each received event will be prefixed by '---' and suffixed by '===='
5584
5585
5586             ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
5587
5588 Run the Websocket Console Client
5589 ********************************
5590
5591    .. container:: paragraph
5592
5593       The console client is included in an APEX full installation. To
5594       run the client, open a new shell (Unix, Cygwin) or command prompt
5595       (``cmd`` on Windows). Then use the APEX application launcher to
5596       start the client.
5597
5598    .. important::
5599       APEX engine needs to run first
5600       The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
5601       protocol is executed first.
5602
5603    +------------------------------------------------------------+--------------------------------------------------------------+
5604    | Unix, Cygwin                                               | Windows                                                      |
5605    +============================================================+==============================================================+
5606    | .. container::                                             | .. container::                                               |
5607    |                                                            |                                                              |
5608    |    .. container:: listingblock                             |    .. container:: listingblock                               |
5609    |                                                            |                                                              |
5610    |       .. container:: content                               |       .. container:: content                                 |
5611    |                                                            |                                                              |
5612    |          .. code::                                         |          .. code::                                           |
5613    |                                                            |                                                              |
5614    |             # $APEX_HOME/bin/apexApps.sh ws-console [args] |             > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
5615    +------------------------------------------------------------+--------------------------------------------------------------+
5616
5617    .. container:: paragraph
5618
5619       Use the following command line arguments for server and port of
5620       the Websocket server. The port should be the same as configured in
5621       the APEX engine. The server host should be the host on which the
5622       APEX engine is running
5623
5624    .. container:: ulist
5625
5626       -  ``-p`` defines the Websocket port to connect to (defaults to
5627          ``8887``)
5628
5629       -  ``-s`` defines the host on which a Websocket server is running
5630          (defaults to ``localhost``)
5631
5632    .. container:: paragraph
5633
5634       Let’s assume that there is an APEX engine running, configured for
5635       consume Websocket carrier technology, as server, for port 42450,
5636       with consume event protocol JSON,. If we start the console client
5637       on the same host, we can omit the ``-s`` options. We start the
5638       console client as:
5639
5640    .. container:: listingblock
5641
5642       .. container:: content
5643
5644          .. code::
5645
5646             # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
5647             > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
5648
5649    .. container:: colist arabic
5650
5651       +-------+--------------------------------+
5652       | **1** | Start client on Unix or Cygwin |
5653       +-------+--------------------------------+
5654       | **2** | Start client on Windows        |
5655       +-------+--------------------------------+
5656
5657    .. container:: paragraph
5658
5659       Once started successfully, the client will produce the following
5660       messages (assuming we used ``-p 42450`` and an APEX engine is
5661       running on ``localhost`` with the same port:
5662
5663    .. container:: listingblock
5664
5665       .. container:: content
5666
5667          .. code::
5668
5669             ws-simple-console: starting simple event console
5670              --> server: localhost
5671              --> port: 42450
5672
5673              - terminate the application typing 'exit<enter>' or using 'CTRL+C'
5674              - events are created by a non-blank starting line and terminated by a blank line
5675
5676
5677             ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
5678
5679 Send Events
5680 ***********
5681
5682    .. container:: paragraph
5683
5684       Now you have the full system up and running:
5685
5686    .. container:: ulist
5687
5688       -  Terminal 1: APEX ready and loaded
5689
5690       -  Terminal 2: an echo client, printing received messages produced
5691          by the VPN policy
5692
5693       -  Terminal 2: a console client, waiting for input on the console
5694          (standard in) and sending text to APEX
5695
5696    .. container:: paragraph
5697
5698       We started the engine with the VPN policy example. So all the
5699       events we are using now are located in files in the following
5700       example directory:
5701
5702    .. container:: listingblock
5703
5704       .. container:: content
5705
5706          .. code::
5707            :number-lines:
5708
5709            #: $APEX_HOME/examples/events/VPN
5710            > %APEX_HOME%\examples\events\VPN
5711
5712 .. container:: paragraph
5713
5714    To sends events, simply copy the content of the event files into
5715    Terminal 3 (the console client). It will read multi-line JSON text
5716    and send the events. So copy the content of ``SetupEvents.json`` into
5717    the client. APEX will trigger a policy and produce some output, the
5718    echo client will also print some events created in the policy. In
5719    Terminal 1 (APEX) you’ll see some status messages from the policy as:
5720
5721 .. container:: listingblock
5722
5723    .. container:: content
5724
5725       .. code::
5726         :number-lines:
5727
5728         {Link=L09, LinkUp=true}
5729         L09     true
5730         outFields: {Link=L09, LinkUp=true}
5731         {Link=L10, LinkUp=true}
5732         L09     true
5733         L10     true
5734         outFields: {Link=L10, LinkUp=true}
5735         {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
5736         *** Customers ***
5737         C       300     300     [L09, L10]
5738         outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
5739         {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
5740         *** Customers ***
5741         A       300     50      [L09, L10]
5742         C       300     300     [L09, L10]
5743         outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
5744         {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
5745         *** Customers ***
5746         A       300     50      [L09, L10]
5747         C       300     300     [L09, L10]
5748         D       300     400     [L09, L10]
5749         outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
5750         {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
5751         *** Customers ***
5752         A       300     50      [L09, L10]
5753         B       300     299     [L09, L10]
5754         C       300     300     [L09, L10]
5755         D       300     400     [L09, L10]
5756         outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
5757
5758 .. container:: paragraph
5759
5760    In Terminal 2 (echo-client) you see the received events, the last two
5761    should look like:
5762
5763 .. container:: listingblock
5764
5765    .. container:: content
5766
5767       .. code::
5768         :number-lines:
5769
5770         ws-simple-echo: received
5771         ---------------------------------
5772         {
5773           "name": "VPNCustomerCtxtActEvent",
5774           "version": "0.0.1",
5775           "nameSpace": "org.onap.policy.apex.domains.vpn.events",
5776           "source": "Source",
5777           "target": "Target",
5778           "CustomerName": "C",
5779           "LinkList": "L09 L10",
5780           "SlaDT": 300,
5781           "YtdDT": 300
5782         }
5783         =================================
5784
5785         ws-simple-echo: received
5786         ---------------------------------
5787         {
5788           "name": "VPNCustomerCtxtActEvent",
5789           "version": "0.0.1",
5790           "nameSpace": "org.onap.policy.apex.domains.vpn.events",
5791           "source": "Source",
5792           "target": "Target",
5793           "CustomerName": "D",
5794           "LinkList": "L09 L10",
5795           "SlaDT": 300,
5796           "YtdDT": 400
5797         }
5798         =================================
5799
5800 .. container:: paragraph
5801
5802    Congratulations, you have triggered a policy in APEX using
5803    Websockets, the policy did run through, created events, picked up by
5804    the echo-client.
5805
5806 .. container:: paragraph
5807
5808    Now you can send the Link 09 and Link 10 events, they will trigger
5809    the actual VPN policy and some calculations are made. Let’s take the
5810    Link 09 events from ``Link09Events.json``, copy them all into
5811    Terminal 3 (the console). APEX will run the policy (with some status
5812    output), and the echo client will receive and print events.
5813
5814 .. container:: paragraph
5815
5816    To terminate the applications, simply press ``CTRL+C`` in Terminal 1
5817    (APEX). This will also terminate the echo-client in Terminal 2. Then
5818    type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
5819    console-client.
5820
5821 .. container::
5822    :name: footer
5823
5824    .. container::
5825       :name: footer-text