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