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