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