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