blob: 02de0b4639ef8699964de170f6e2fd28440a60a0 [file] [log] [blame]
ramverma3b71c972019-07-10 11:25:37 +00001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3
4
5APEX User Manual
6****************
7
8.. contents::
9 :depth: 3
10
11Installation
12^^^^^^^^^^^^
13
14Requirements
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
25Installation Requirements
26#########################
27
28 .. container:: ulist
29
30 - Downloaded distribution: JAVA runtime environment
31 (JRE, Java 8 or later, APEX is tested with the
32 Oracle Java)
33
34 - Building from source: JAVA development kit (JDK,
35 Java 8 or later, APEX is tested with the Oracle
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 - RPM to install from the RPM distribution
69
70 .. container:: ulist
71
72 - Install: ``sudo apt-get install rpm``
73
74 - DPKG to install from the DEB distribution
75
76 .. container:: ulist
77
78 - Install: ``sudo apt-get install dpkg``
79
80Feature Requirements
81####################
82
83 .. container:: paragraph
84
85 APEX supports a number of features that require extra
86 software being installed.
87
88 .. container:: ulist
89
90 - `Apache Kafka <https://kafka.apache.org/>`__ to
91 connect APEX to a Kafka message bus
92
93 - `Hazelcast <https://hazelcast.com/>`__ to use
94 distributed hash maps for context
95
96 - `Infinispan <http://infinispan.org/>`__ for
97 distributed context and persistence
98
99 - `Docker <https://www.docker.com/>`__ to run APEX
100 inside a Docker container
101
102Build (Install from Source) Requirements
103########################################
104
105 .. container:: paragraph
106
107 Installation from source requires a few development
108 tools
109
110 .. container:: ulist
111
112 - GIT to retrieve the source code
113
114 - Java SDK, Java version 8 or later
115
116 - Apache Maven 3 (the APEX build environment)
117
118Get the APEX Source Code
119------------------------
120
121 .. container:: paragraph
122
123 The first APEX source code was hosted on Github in
124 January 2018. By the end of 2018, APEX was added as a
125 project in the ONAP Policy Framework, released later in
126 the ONAP Casablanca release.
127
128 .. container:: paragraph
129
130 The APEX source code is hosted in ONAP as project APEX.
131 The current stable version is in the master branch.
132 Simply clone the master branch from ONAP using HTTPS.
133
134 .. container:: listingblock
135
136 .. container:: content
137
ramverma760cce92019-07-11 12:57:49 +0000138 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000139 :number-lines:
140
141 git clone https://gerrit.onap.org/r/policy/apex-pdp
142
143Build APEX
144----------
145
146 .. container:: paragraph
147
148 The examples in this document assume that the APEX source
149 repositories are cloned to:
150
151 .. container:: ulist
152
153 - Unix, Cygwin: ``/usr/local/src/apex-pdp``
154
155 - Windows: ``C:\dev\apex-pdp``
156
157 - Cygwin: ``/cygdrive/c/dev/apex-pdp``
158
ramverma760cce92019-07-11 12:57:49 +0000159 .. important::
ramverma3b71c972019-07-10 11:25:37 +0000160 A Build requires ONAP Nexus
ramverma760cce92019-07-11 12:57:49 +0000161 APEX has a dependency to ONAP parent projects. You might need to adjust your Maven M2 settings. The most current
162 settings can be found in the ONAP oparent repo: `Settings <https://git.onap.org/oparent/plain/settings.xml>`__.
ramverma3b71c972019-07-10 11:25:37 +0000163
ramverma760cce92019-07-11 12:57:49 +0000164 .. important::
165 A Build needs Space
166 Building APEX requires approximately 2-3 GB of hard disc space, 1 GB for the actual build with full
167 distribution and 1-2 GB for the downloaded dependencies
ramverma3b71c972019-07-10 11:25:37 +0000168
ramverma760cce92019-07-11 12:57:49 +0000169 .. important::
ramverma3b71c972019-07-10 11:25:37 +0000170 A Build requires Internet (for first build)
ramverma760cce92019-07-11 12:57:49 +0000171 During the build, several (a lot) of Maven dependencies will be downloaded and stored in the configured local Maven
172 repository. The first standard build (and any first specific build) requires Internet access to download those
173 dependencies.
ramverma3b71c972019-07-10 11:25:37 +0000174
ramverma760cce92019-07-11 12:57:49 +0000175 .. important::
ramverma3b71c972019-07-10 11:25:37 +0000176 Building RPM distributions
ramverma760cce92019-07-11 12:57:49 +0000177 RPM images are only build if the ``rpm`` package is installed (Unix). To install ``rpm`` run ``sudo apt-get install rpm``,
178 then build APEX.
ramverma3b71c972019-07-10 11:25:37 +0000179
180 .. container:: paragraph
181
182 Use Maven to for a standard build without any tests.
183
184 +-------------------------------------------------------+--------------------------------------------------------+
185 | Unix, Cygwin | Windows |
186 +=======================================================+========================================================+
187 | .. container:: | .. container:: |
188 | | |
189 | .. container:: content | .. container:: content |
190 | | |
191 | .. code:: | .. code:: |
192 | :number-lines: | :number-lines: |
193 | | |
194 | # cd /usr/local/src/apex-pdp | >c: |
195 | # mvn clean install -DskipTest | >cd \dev\apex |
196 | | >mvn clean install -DskipTests |
197 +-------------------------------------------------------+--------------------------------------------------------+
198
199.. container:: paragraph
200
201 The build takes 2-3 minutes on a standard development laptop. It
202 should run through without errors, but with a lot of messages from
203 the build process.
204
205.. container:: paragraph
206
207 When Maven is finished with the build, the final screen should look
208 similar to this (omitting some ``success`` lines):
209
210.. container:: listingblock
211
212 .. container:: content
213
ramverma760cce92019-07-11 12:57:49 +0000214 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000215 :number-lines:
216
217 [INFO] tools .............................................. SUCCESS [ 0.248 s]
218 [INFO] tools-common ....................................... SUCCESS [ 0.784 s]
219 [INFO] simple-wsclient .................................... SUCCESS [ 3.303 s]
220 [INFO] model-generator .................................... SUCCESS [ 0.644 s]
221 [INFO] packages ........................................... SUCCESS [ 0.336 s]
222 [INFO] apex-pdp-package-full .............................. SUCCESS [01:10 min]
223 [INFO] Policy APEX PDP - Docker build 2.0.0-SNAPSHOT ...... SUCCESS [ 10.307 s]
224 [INFO] ------------------------------------------------------------------------
225 [INFO] BUILD SUCCESS
226 [INFO] ------------------------------------------------------------------------
227 [INFO] Total time: 03:43 min
228 [INFO] Finished at: 2018-09-03T11:56:01+01:00
229 [INFO] ------------------------------------------------------------------------
230
231.. container:: paragraph
232
233 The build will have created all artifacts required for an APEX
234 installation. The following example show how to change to the target
235 directory and how it should look like.
236
237+----------------------------------------------------------------------------------------------------------------------------+
238| Unix, Cygwin |
239+============================================================================================================================+
240| .. container:: |
241| |
242| .. container:: listingblock |
243| |
244| .. container:: content |
245| |
246| .. code:: |
247| :number-lines: |
248| |
249| -rwxrwx---+ 1 esvevan Domain Users 772 Sep 3 11:55 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes* |
250| -rwxrwx---+ 1 esvevan Domain Users 146328082 Sep 3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT.deb* |
251| -rwxrwx---+ 1 esvevan Domain Users 15633 Sep 3 11:54 apex-pdp-package-full-2.0.0-SNAPSHOT.jar* |
252| -rwxrwx---+ 1 esvevan Domain Users 146296819 Sep 3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz* |
253| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 archive-tmp/ |
254| -rwxrwx---+ 1 esvevan Domain Users 89 Sep 3 11:54 checkstyle-cachefile* |
255| -rwxrwx---+ 1 esvevan Domain Users 10621 Sep 3 11:54 checkstyle-checker.xml* |
256| -rwxrwx---+ 1 esvevan Domain Users 584 Sep 3 11:54 checkstyle-header.txt* |
257| -rwxrwx---+ 1 esvevan Domain Users 86 Sep 3 11:54 checkstyle-result.xml* |
258| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 classes/ |
259| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 dependency-maven-plugin-markers/ |
260| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 etc/ |
261| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 examples/ |
262| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:55 install_hierarchy/ |
263| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 maven-archiver/ |
264+----------------------------------------------------------------------------------------------------------------------------+
265
266+--------------------------------------------------------------------------------------------------------+
267| Windows |
268+========================================================================================================+
269| .. container:: |
270| |
271| .. container:: listingblock |
272| |
273| .. container:: content |
274| |
275| .. code:: |
276| :number-lines: |
277| |
278| 03/09/2018 11:55 <DIR> . |
279| 03/09/2018 11:55 <DIR> .. |
280| 03/09/2018 11:55 146,296,819 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz |
281| 03/09/2018 11:55 146,328,082 apex-pdp-package-full-2.0.0-SNAPSHOT.deb |
282| 03/09/2018 11:54 15,633 apex-pdp-package-full-2.0.0-SNAPSHOT.jar |
283| 03/09/2018 11:55 772 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes |
284| 03/09/2018 11:54 <DIR> archive-tmp |
285| 03/09/2018 11:54 89 checkstyle-cachefile |
286| 03/09/2018 11:54 10,621 checkstyle-checker.xml |
287| 03/09/2018 11:54 584 checkstyle-header.txt |
288| 03/09/2018 11:54 86 checkstyle-result.xml |
289| 03/09/2018 11:54 <DIR> classes |
290| 03/09/2018 11:54 <DIR> dependency-maven-plugin-markers |
291| 03/09/2018 11:54 <DIR> etc |
292| 03/09/2018 11:54 <DIR> examples |
293| 03/09/2018 11:55 <DIR> install_hierarchy |
294| 03/09/2018 11:54 <DIR> maven-archiver |
295| 8 File(s) 292,652,686 bytes |
296| 9 Dir(s) 14,138,720,256 bytes free |
297+--------------------------------------------------------------------------------------------------------+
298
299Install APEX
300------------
301
302 .. container:: paragraph
303
304 APEX can be installed in different ways:
305
306 .. container:: ulist
307
308 - Unix: automatically using ``rpm`` or ``dpkg`` from ``.rpm`` or
309 ``.deb`` archive
310
311 - Windows, Unix, Cygwin: manually from a ``.tar.gz`` archive
312
313 - Windows, Unix, Cygwin: build from source using Maven, then
314 install manually
315
316Install with RPM and DPKG
317#########################
318
319 .. container:: paragraph
320
321 The install distributions of APEX automatically install the
322 system. The installation directory is
323 ``/opt/app/policy/apex-pdp``. Log files are located in
324 ``/var/log/onap/policy/apex-pdp``. The latest APEX version will
325 be available as ``/opt/app/policy/apex-pdp/apex-pdp``.
326
327 .. container:: paragraph
328
329 For the installation, a new user ``apexuser`` and a new group
330 ``apexuser`` will be created. This user owns the installation
331 directories and the log file location. The user is also used by
332 the standard APEX start scripts to run APEX with this user’s
333 permissions.
334
335 +-----------------------------------------------------------------------+
336 | RPM Installation |
337 +=======================================================================+
338 | .. container:: |
339 | |
340 | .. container:: listingblock |
341 | |
342 | .. container:: content |
343 | |
344 | .. code:: |
345 | :number-lines: |
346 | |
347 | # sudo rpm -i apex-pdp-package-full-2.0.0-SNAPSHOT.rpm |
348 | ********************preinst******************* |
349 | arguments 1 |
350 | ********************************************** |
351 | creating group apexuser . . . |
352 | creating user apexuser . . . |
353 | ********************postinst**************** |
354 | arguments 1 |
355 | *********************************************** |
356 +-----------------------------------------------------------------------+
357
358+--------------------------------------------------------------------------------------+
359| DPKG Installation |
360+======================================================================================+
361| .. container:: |
362| |
363| .. container:: listingblock |
364| |
365| .. container:: content |
366| |
367| .. code:: |
ramverma760cce92019-07-11 12:57:49 +0000368| :number-lines: |
ramverma3b71c972019-07-10 11:25:37 +0000369| |
ramverma760cce92019-07-11 12:57:49 +0000370| # sudo dpkg -i apex-pdp-package-full-2.0.0-SNAPSHOT.deb |
ramverma3b71c972019-07-10 11:25:37 +0000371| Selecting previously unselected package apex-uservice. |
372| (Reading database ... 288458 files and directories currently installed.) |
373| Preparing to unpack apex-pdp-package-full-2.0.0-SNAPSHOT.deb ... |
374| ********************preinst******************* |
375| arguments install |
376| ********************************************** |
377| creating group apexuser . . . |
378| creating user apexuser . . . |
379| Unpacking apex-uservice (2.0.0-SNAPSHOT) ... |
380| Setting up apex-uservice (2.0.0-SNAPSHOT) ... |
381| ********************postinst**************** |
382| arguments configure |
383| *********************************************** |
384+--------------------------------------------------------------------------------------+
385
386.. container:: paragraph
387
388 Once the installation is finished, APEX is fully installed and ready
389 to run.
390
391Install Manually from Archive (Unix, Cygwin)
392############################################
393
394 .. container:: paragraph
395
396 Download a ``tar.gz`` archive. Create a directory where APEX
397 should be installed. Extract the ``tar`` archive. The following
398 example shows how to install APEX in ``/opt/apex`` and create a
399 link to ``/opt/apex/apex`` for the most recent installation.
400
401 .. container:: listingblock
402
403 .. container:: content
404
ramverma760cce92019-07-11 12:57:49 +0000405 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000406 :number-lines:
407
408 # cd /opt
409 # mkdir apex
410 # cd apex
411 # mkdir apex-full-2.0.0-SNAPSHOT
412 # tar xvfz ~/Downloads/apex-pdp-package-full-2.0.0-SNAPSHOT.tar.gz -C apex-full-2.0.0-SNAPSHOT
413 # ln -s apex apex-pdp-package-full-2.0.0-SNAPSHOT
414
415Install Manually from Archive (Windows, 7Zip, GUI)
416##################################################
417
418 .. container:: paragraph
419
420 Download a ``tar.gz`` archive and copy the file into the install
421 folder (in this example ``C:\apex``). Assuming you are using 7Zip,
422 right click on the file and extract the ``tar`` archive. Note: the
423 screenshots might show an older version than you have.
424
425 .. container:: imageblock
426
427 .. container:: content
428
429 |Extract the TAR archive|
430
431 .. container:: paragraph
432
433 The right-click on the new created TAR file and extract the actual
434 APEX distribution.
435
436 .. container:: imageblock
437
438 .. container:: content
439
440 |Extract the APEX distribution|
441
442 .. container:: paragraph
443
444 Inside the new APEX folder you see the main directories: ``bin``,
445 ``etc``, ``examples``, ``lib``, and ``war``
446
447 .. container:: paragraph
448
449 Once extracted, please rename the created folder to
450 ``apex-full-2.0.0-SNAPSHOT``. This will keep the directory name in
451 line with the rest of this documentation.
452
453Install Manually from Archive (Windows, 7Zip, CMD)
454##################################################
455
456 .. container:: paragraph
457
458 Download a ``tar.gz`` archive and copy the file into the install
459 folder (in this example ``C:\apex``). Start ``cmd``, for instance
460 typing ``Windows+R`` and then ``cmd`` in the dialog. Assuming
461 ``7Zip`` is installed in the standard folder, simply run the
462 following commands (for APEX version 2.0.0-SNAPSHOT full
463 distribution)
464
465 .. container:: listingblock
466
467 .. container:: content
468
ramverma760cce92019-07-11 12:57:49 +0000469 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000470 :number-lines:
471
472 >c:
473 >cd \apex
474 >"\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"
475
476.. container:: paragraph
477
478 APEX is now installed in the folder
479 ``C:\apex\apex-full-2.0.0-SNAPSHOT``.
480
481Build from Source
482-----------------
483
484Build and Install Manually (Unix, Windows, Cygwin)
485##################################################
486
487 .. container:: paragraph
488
489 Clone the APEX GIT repositories into a directory. Go to that
490 directory. Use Maven to build APEX (all details on building
491 APEX from source can be found in *APEX HowTo: Build*). Install
492 from the created artifacts (``rpm``, ``deb``, ``tar.gz``, or
493 copying manually).
494
ramverma760cce92019-07-11 12:57:49 +0000495 .. important::
496 Building RPM distributions
497 RPM images are only build if the ``rpm`` package is installed (Unix). To install ``rpm`` run
498 ``sudo apt-get install rpm``, then build APEX.
ramverma3b71c972019-07-10 11:25:37 +0000499
500 .. container:: paragraph
501
502 The following example shows how to build the APEX system,
503 without tests (``-DskipTests``) to safe some time. It assumes
504 that the APX GIT repositories are cloned to:
505
506 .. container:: ulist
507
508 - Unix, Cygwin: ``/usr/local/src/apex``
509
510 - Windows: ``C:\dev\apex``
511
ramverma760cce92019-07-11 12:57:49 +0000512 +-------------------------------------------------------+--------------------------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +0000513 | Unix, Cygwin | Windows |
514 +=======================================================+========================================================+
515 | .. container:: | .. container:: |
516 | | |
517 | .. container:: content | .. container:: content |
518 | | |
519 | .. code:: | .. code:: |
520 | :number-lines: | :number-lines: |
521 | | |
522 | # cd /usr/local/src/apex | >c: |
523 | # mvn clean install -DskipTests | >cd \dev\apex |
524 | | >mvn clean install -DskipTests |
525 +-------------------------------------------------------+--------------------------------------------------------+
526
527.. container:: paragraph
528
529 The build takes about 2 minutes without test and about 4-5 minutes
530 with tests on a standard development laptop. It should run through
531 without errors, but with a lot of messages from the build process. If
532 build with tests (i.e. without ``-DskipTests``), there will be error
533 messages and stack trace prints from some tests. This is normal, as
534 long as the build finishes successful.
535
536.. container:: paragraph
537
538 When Maven is finished with the build, the final screen should look
539 similar to this (omitting some ``success`` lines):
540
541.. container:: listingblock
542
543 .. container:: content
544
ramverma760cce92019-07-11 12:57:49 +0000545 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000546 :number-lines:
547
548 [INFO] tools .............................................. SUCCESS [ 0.248 s]
549 [INFO] tools-common ....................................... SUCCESS [ 0.784 s]
550 [INFO] simple-wsclient .................................... SUCCESS [ 3.303 s]
551 [INFO] model-generator .................................... SUCCESS [ 0.644 s]
552 [INFO] packages ........................................... SUCCESS [ 0.336 s]
553 [INFO] apex-pdp-package-full .............................. SUCCESS [01:10 min]
554 [INFO] Policy APEX PDP - Docker build 2.0.0-SNAPSHOT ...... SUCCESS [ 10.307 s]
555 [INFO] ------------------------------------------------------------------------
556 [INFO] BUILD SUCCESS
557 [INFO] ------------------------------------------------------------------------
558 [INFO] Total time: 03:43 min
559 [INFO] Finished at: 2018-09-03T11:56:01+01:00
560 [INFO] ------------------------------------------------------------------------
561
562.. container:: paragraph
563
564 The build will have created all artifacts required for an APEX
565 installation. The following example show how to change to the target
566 directory and how it should look like.
567
568+-----------------------------------------------------------------------------------------------------------------------------+
569| Unix, Cygwin |
570+=============================================================================================================================+
571| .. container:: |
572| |
573| .. container:: listingblock |
574| |
575| .. code:: |
576| :number-lines: |
577| |
578| # cd packages/apex-pdp-package-full/target |
579| # ls -l |
580| -rwxrwx---+ 1 esvevan Domain Users 772 Sep 3 11:55 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes* |
581| -rwxrwx---+ 1 esvevan Domain Users 146328082 Sep 3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT.deb* |
582| -rwxrwx---+ 1 esvevan Domain Users 15633 Sep 3 11:54 apex-pdp-package-full-2.0.0-SNAPSHOT.jar* |
583| -rwxrwx---+ 1 esvevan Domain Users 146296819 Sep 3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz* |
584| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 archive-tmp/ |
585| -rwxrwx---+ 1 esvevan Domain Users 89 Sep 3 11:54 checkstyle-cachefile* |
586| -rwxrwx---+ 1 esvevan Domain Users 10621 Sep 3 11:54 checkstyle-checker.xml* |
587| -rwxrwx---+ 1 esvevan Domain Users 584 Sep 3 11:54 checkstyle-header.txt* |
588| -rwxrwx---+ 1 esvevan Domain Users 86 Sep 3 11:54 checkstyle-result.xml* |
589| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 classes/ |
590| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 dependency-maven-plugin-markers/ |
591| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 etc/ |
592| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 examples/ |
593| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:55 install_hierarchy/ |
594| drwxrwx---+ 1 esvevan Domain Users 0 Sep 3 11:54 maven-archiver/ |
595+-----------------------------------------------------------------------------------------------------------------------------+
596
597+-----------------------------------------------------------------------------------------------------------------------------+
598| Windows |
599+=============================================================================================================================+
600| .. container:: |
601| |
602| .. container:: listingblock |
603| |
604| .. code:: |
605| :number-lines: |
606| |
607| >cd packages\apex-pdp-package-full\target |
608| >dir |
609| 03/09/2018 11:55 <DIR> . |
610| 03/09/2018 11:55 <DIR> .. |
611| 03/09/2018 11:55 146,296,819 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz |
612| 03/09/2018 11:55 146,328,082 apex-pdp-package-full-2.0.0-SNAPSHOT.deb |
613| 03/09/2018 11:54 15,633 apex-pdp-package-full-2.0.0-SNAPSHOT.jar |
614| 03/09/2018 11:55 772 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes |
615| 03/09/2018 11:54 <DIR> archive-tmp |
616| 03/09/2018 11:54 89 checkstyle-cachefile |
617| 03/09/2018 11:54 10,621 checkstyle-checker.xml |
618| 03/09/2018 11:54 584 checkstyle-header.txt |
619| 03/09/2018 11:54 86 checkstyle-result.xml |
620| 03/09/2018 11:54 <DIR> classes |
621| 03/09/2018 11:54 <DIR> dependency-maven-plugin-markers |
622| 03/09/2018 11:54 <DIR> etc |
623| 03/09/2018 11:54 <DIR> examples |
624| 03/09/2018 11:55 <DIR> install_hierarchy |
625| 03/09/2018 11:54 <DIR> maven-archiver |
626| 8 File(s) 292,652,686 bytes |
627| 9 Dir(s) 14,138,720,256 bytes free |
628+-----------------------------------------------------------------------------------------------------------------------------+
629
630.. container:: paragraph
631
632 Now, take the ``.deb`` or the ``.tar.gz`` file and install APEX.
633 Alternatively, copy the content of the folder ``install_hierarchy``
634 to your APEX directory.
635
636Installation Layout
637-------------------
638
639 .. container:: paragraph
640
641 A full installation of APEX comes with the following layout.
642
643 .. container:: listingblock
644
645 .. container:: content
646
647 ::
648
649 $APEX_HOME
650 ├───bin (1)
651 ├───etc (2)
652 │ ├───editor
653 │ ├───hazelcast
654 │ ├───infinispan
655 │ └───META-INF
656 ├───examples (3)
657 │ ├───config (4)
658 │ ├───docker (5)
659 │ ├───events (6)
660 │ ├───html (7)
661 │ ├───models (8)
662 │ └───scripts (9)
663 ├───lib (10)
664 │ └───applications (11)
665 └───war (12)
666
667 .. container:: colist arabic
668
669 +-----------------------------------+-----------------------------------+
670 | **1** | binaries, mainly scripts (bash |
671 | | and bat) to start the APEX engine |
672 | | and applications |
673 +-----------------------------------+-----------------------------------+
674 | **2** | configuration files, such as |
675 | | logback (logging) and third party |
676 | | library configurations |
677 +-----------------------------------+-----------------------------------+
678 | **3** | example policy models to get |
679 | | started |
680 +-----------------------------------+-----------------------------------+
681 | **4** | configurations for the examples |
682 | | (with sub directories for |
683 | | individual examples) |
684 +-----------------------------------+-----------------------------------+
685 | **5** | Docker files and additional |
686 | | Docker instructions for the |
687 | | exampples |
688 +-----------------------------------+-----------------------------------+
689 | **6** | example events for the examples |
690 | | (with sub directories for |
691 | | individual examples) |
692 +-----------------------------------+-----------------------------------+
693 | **7** | HTML files for some examples, |
694 | | e.g. the Decisionmaker example |
695 +-----------------------------------+-----------------------------------+
696 | **8** | the policy models, generated for |
697 | | each example (with sub |
698 | | directories for individual |
699 | | examples) |
700 +-----------------------------------+-----------------------------------+
701 | **9** | additional scripts for the |
702 | | examples (with sub directories |
703 | | for individual examples) |
704 +-----------------------------------+-----------------------------------+
705 | **10** | the library folder with all Java |
706 | | JAR files |
707 +-----------------------------------+-----------------------------------+
708 | **11** | applications, also known as jar |
709 | | with dependencies (or fat jars), |
710 | | individually deployable |
711 +-----------------------------------+-----------------------------------+
712 | **12** | WAR files for web applications |
713 +-----------------------------------+-----------------------------------+
714
715System Configuration
716--------------------
717
718 .. container:: paragraph
719
720 Once APEX is installed, a few configurations need to be done:
721
722 .. container:: ulist
723
724 - Create an APEX user and an APEX group (optional, if not
725 installed using RPM and DPKG)
726
727 - Create environment settings for ``APEX_HOME`` and
728 ``APEX_USER``, required by the start scripts
729
730 - Change settings of the logging framework (optional)
731
732 - Create directories for logging, required (execution might fail
733 if directories do not exist or cannot be created)
734
735APEX User and Group
736###################
737
738 .. container:: paragraph
739
740 On smaller installations and test systems, APEX can run as any
741 user or group.
742
743 .. container:: paragraph
744
745 However, if APEX is installed in production, we strongly
746 recommend you set up a dedicated user for running APEX. This
747 will isolate the execution of APEX to that user. We recommend
748 you use the userid ``apexuser`` but you may use any user you
749 choose.
750
751 .. container:: paragraph
752
753 The following example, for UNIX, creates a group called
754 ``apexuser``, an APEX user called ``apexuser``, adds the group
755 to the user, and changes ownership of the APEX installation to
756 the user. Substitute ``<apex-dir>`` with the directory where
757 APEX is installed.
758
759 .. container:: listingblock
760
761 .. container:: content
762
ramverma760cce92019-07-11 12:57:49 +0000763 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000764 :number-lines:
765
766 # sudo groupadd apexuser
767 # sudo useradd -g apexuser apexuser
768 # sudo chown -R apexuser:apexuser <apex-dir>
769
770.. container:: paragraph
771
772 For other operating systems please consult your manual or system
773 administrator.
774
775Environment Settings: APEX_HOME and APEX_USER
776#############################################
777
778 .. container:: paragraph
779
780 The provided start scripts for APEX require two environment
781 variables being set:
782
783 .. container:: ulist
784
785 - ``APEX_USER`` with the user under whos name and permission APEX
786 should be started (Unix only)
787
788 - ``APEX_HOME`` with the directory where APEX is installed (Unix,
789 Windows, Cygwin)
790
791 .. container:: paragraph
792
793 The first row in the following table shows how to set these
794 environment variables temporary (assuming the user is
795 ``apexuser``). The second row shows how to verify the settings.
796 The last row explains how to set those variables permanently.
797
798 +------------------------------------------------+---------------------------------------------------------+
799 | Unix, Cygwin (bash/tcsh) | Windows |
800 +================================================+=========================================================+
801 | .. container:: | .. container:: |
802 | | |
803 | .. container:: content | .. container:: content |
804 | | |
805 | .. code:: | .. code:: |
806 | :number-lines: | :number-lines: |
807 | | |
808 | # export APEX_USER=apexuser | >set APEX_HOME=C:\apex\apex-full-2.0.0-SNAPSHOT |
809 | # cd /opt/app/policy/apex-pdp | |
ramverma760cce92019-07-11 12:57:49 +0000810 | # export APEX_HOME=`pwd` | |
ramverma3b71c972019-07-10 11:25:37 +0000811 | | |
812 +------------------------------------------------+ |
813 | .. container:: | |
814 | | |
815 | .. container:: content | |
816 | | |
ramverma760cce92019-07-11 12:57:49 +0000817 | .. code::tcsh | |
ramverma3b71c972019-07-10 11:25:37 +0000818 | :number-lines: | |
819 | | |
820 | # setenv APEX_USER apexuser | |
821 | # cd /opt/app/policy/apex-pdp | |
ramverma760cce92019-07-11 12:57:49 +0000822 | # setenv APEX_HOME `pwd` | |
ramverma3b71c972019-07-10 11:25:37 +0000823 | | |
824 +------------------------------------------------+---------------------------------------------------------+
825 | .. container:: | .. container:: |
826 | | |
827 | .. container:: content | .. container:: content |
828 | | |
829 | .. code:: | .. code:: |
830 | :number-lines: | :number-lines: |
831 | | |
832 | # env | grep APEX | >set APEX_HOME |
833 | # APEX_USER=apexuser | APEX_HOME=\apex\apex-full-2.0.0-SNAPSHOT |
ramverma760cce92019-07-11 12:57:49 +0000834 | # APEX_HOME=/opt/app/policy/apex-pdp | |
ramverma3b71c972019-07-10 11:25:37 +0000835 | | |
836 +------------------------------------------------+---------------------------------------------------------+
837
838Making Environment Settings Permanent (Unix, Cygwin)
839====================================================
840
841 .. container:: paragraph
842
843 For a per-user setting, edit the a user’s ``bash`` or ``tcsh``
844 settings in ``~/.bashrc`` or ``~/.tcshrc``. For system-wide
845 settings, edit ``/etc/profiles`` (requires permissions).
846
847Making Environment Settings Permanent (Windows)
848===============================================
849
850 .. container:: paragraph
851
852 On Windows 7 do
853
854 .. container:: ulist
855
856 - Click on the **Start** Menu
857
858 - Right click on **Computer**
859
860 - Select **Properties**
861
862 .. container:: paragraph
863
864 On Windows 8/10 do
865
866 .. container:: ulist
867
868 - Click on the **Start** Menu
869
870 - Select **System**
871
872 .. container:: paragraph
873
874 Then do the following
875
876 .. container:: ulist
877
878 - Select **Advanced System Settings**
879
880 - On the **Advanced** tab, click the **Environment Variables**
881 button
882
883 - Edit an existing variable, or create a new System variable:
884 'Variable name'="APEX_HOME", 'Variable
885 value'="C:\apex\apex-full-2.0.0-SNAPSHOT"
886
887 .. container:: paragraph
888
889 For the settings to take effect, an application needs to be
890 restarted (e.g. any open ``cmd`` window).
891
892Edit the APEX Logging Settings
893##############################
894
895 .. container:: paragraph
896
897 Configure the APEX logging settings to your requirements, for
898 instance:
899
900 .. container:: ulist
901
902 - change the directory where logs are written to, or
903
904 - change the log levels
905
906 .. container:: paragraph
907
908 Edit the file ``$APEX_HOME/etc/logback.xml`` for any required
909 changes. To change the log directory change the line
910
911 .. container:: paragraph
912
913 ``<property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />``
914
915 .. container:: paragraph
916
917 to
918
919 .. container:: paragraph
920
921 ``<property name="VAR_LOG" value="/PATH/TO/LOG/DIRECTORY/" />``
922
923 .. container:: paragraph
924
925 On Windows, it is recommended to change the log directory to:
926
927 .. container:: paragraph
928
929 ``<property name="VAR_LOG" value="C:/apex/apex-full-2.0.0-SNAPSHOT/logs" />``
930
931 .. container:: paragraph
932
933 Note: Be careful about when to use ``\`` vs. ``/`` as the path
934 separator!
935
936Create Directories for Logging
937##############################
938
939 .. container:: paragraph
940
941 Make sure that the log directory exists. This is important when
942 APEX was installed manually or when the log directory was changed
943 in the settings (see above).
944
945 +------------------------------------------------------------------+-------------------------------------------------------+
946 | Unix, Cygwin | Windows |
947 +==================================================================+=======================================================+
948 | .. container:: | .. container:: |
949 | | |
950 | .. container:: content | .. container:: content |
951 | | |
952 | .. code:: | .. code:: |
953 | :number-lines: | :number-lines: |
954 | | |
955 | mkdir -p /var/log/onap/policy/apex-pdp | >mkdir C:\apex\apex-full-2.0.0-SNAPSHOT\logs |
956 | chown -R apexuser:apexuser /var/log/onap/policy/apex-pdp | |
957 +------------------------------------------------------------------+-------------------------------------------------------+
958
959Verify the APEX Installation
960----------------------------
961
962 .. container:: paragraph
963
964 When APEX is installed and all settings are realized, the
965 installation can be verified.
966
967Verify Installation - run Engine
968################################
969
970 .. container:: paragraph
971
972 A simple verification of an APEX installation can be done by
973 simply starting the APEX engine without any configuration. On
974 Unix (or Cygwin) start the engine using
975 ``$APEX_HOME/bin/apexEngine.sh``. On Windows start the engine
976 using ``%APEX_HOME%\bin\apexEngine.bat``. The engine will fail
977 to fully start. However, if the output looks similar to the
978 following line, the APEX installation is realized.
979
980 .. container:: listingblock
981
982 .. container:: content
983
ramverma760cce92019-07-11 12:57:49 +0000984 .. code::
ramverma3b71c972019-07-10 11:25:37 +0000985 :number-lines:
986
987 Starting Apex service with parameters [] . . .
988 start of Apex service failed: Apex configuration file was not specified as an argument
989 2018-09-03 13:11:33,914 Apex [main] ERROR o.o.p.a.service.engine.main.ApexMain - start of Apex service failed
990 org.onap.policy.apex.model.basicmodel.concepts.ApexException: Apex configuration file was not specified as an argument
991 at org.onap.policy.apex.service.engine.main.ApexCommandLineArguments.validateReadableFile(ApexCommandLineArguments.java:267)
992 at org.onap.policy.apex.service.engine.main.ApexCommandLineArguments.validate(ApexCommandLineArguments.java:161)
993 at org.onap.policy.apex.service.engine.main.ApexMain.<init>(ApexMain.java:68)
994 at org.onap.policy.apex.service.engine.main.ApexMain.main(ApexMain.java:165)
995 usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]
996 options
997 -c,--config-file <CONFIG_FILE>the full path to the configuration file to use, the configuration file must be a Json file
998 containing the Apex configuration parameters
999 -h,--help outputs the usage of this command
1000 -m,--model-file <MODEL_FILE> the full path to the model file to use, if set it overrides the model file set in the
1001 configuration file
1002 -v,--version outputs the version of Apex
1003
1004Verify Installation - run an Example
1005####################################
1006
1007 .. container:: paragraph
1008
1009 A full APEX installation comes with several examples. Here, we can
1010 fully verify the installation by running one of the examples.
1011
1012 .. container:: paragraph
1013
1014 We use the example called *SampleDomain* and configure the engine
1015 to use standard in and standard out for events. Run the engine
1016 with the provided configuration. Note: Cygwin executes scripts as
1017 Unix scripts but runs Java as a Windows application, thus the
1018 configuration file must be given as a Windows path.
1019
1020 .. container:: listingblock
1021
1022 .. container:: content
1023
ramverma760cce92019-07-11 12:57:49 +00001024 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001025 :number-lines:
1026
ramverma760cce92019-07-11 12:57:49 +00001027 # $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/SampleDomain/Stdin2StdoutJsonEventJava.json (1)
1028 # $APEX_HOME/bin/apexEngine.sh -c C:/apex/apex-full-2.0.0-SNAPSHOT/examples/config/SampleDomain/Stdin2StdoutJsonEventJava.json (2)
1029 >%APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\SampleDomain\Stdin2StdoutJsonEventJava.json :: (3)
ramverma3b71c972019-07-10 11:25:37 +00001030
1031.. container:: colist arabic
1032
1033 +-------+---------+
1034 | **1** | UNIX |
1035 +-------+---------+
1036 | **2** | Cygwin |
1037 +-------+---------+
1038 | **3** | Windows |
1039 +-------+---------+
1040
1041.. container:: paragraph
1042
1043 The engine should start successfully. Assuming the logging levels are
1044 not change (default level is ``info``), the output should look
1045 similar to this (last few lines)
1046
1047.. container:: listingblock
1048
1049 .. container:: content
1050
ramverma760cce92019-07-11 12:57:49 +00001051 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001052 :number-lines:
1053
1054 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] . . .
1055 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 .
1056 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 .
1057 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 .
1058 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 .
1059 2018-09-05 15:16:42,805 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - APEX service created.
1060 2018-09-05 15:16:43,962 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging starting . . .
1061 2018-09-05 15:16:43,963 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging started
1062 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
1063 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
1064 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
1065 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
1066 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
1067 Started Apex service
1068
1069.. container:: paragraph
1070
1071 Important are the last two line, stating that APEX has added the
1072 final action listener to the engine and that the engine is started.
1073
1074.. container:: paragraph
1075
1076 The engine is configured to read events from standard input and write
1077 produced events to standard output. The policy model is a very simple
1078 policy.
1079
1080.. container:: paragraph
1081
1082 The following table shows an input event in the left column and an
1083 output event in the right column. Past the input event into the
1084 console where APEX is running, and the output event should appear in
1085 the console. Pasting the input event multiple times will produce
1086 output events with different values.
1087
1088+-------------------------------------------------------------+-------------------------------------------------------------+
1089| Input Event | Example Output Event |
1090+=============================================================+=============================================================+
1091| .. container:: | .. container:: |
1092| | |
1093| .. container:: content | .. container:: content |
1094| | |
1095| .. code:: | .. code:: |
1096| :number-lines: | :number-lines: |
1097| | |
1098| { | { |
1099| "nameSpace": "org.onap.policy.apex.sample.events", | "name": "Event0004", |
1100| "name": "Event0000", | "version": "0.0.1", |
1101| "version": "0.0.1", | "nameSpace": "org.onap.policy.apex.sample.events", |
1102| "source": "test", | "source": "Act", |
1103| "target": "apex", | "target": "Outside", |
1104| "TestSlogan": "Test slogan for External Event0", | "TestActCaseSelected": 2, |
1105| "TestMatchCase": 0, | "TestActStateTime": 1536157104627, |
1106| "TestTimestamp": 1469781869269, | "TestDecideCaseSelected": 0, |
1107| "TestTemperature": 9080.866 | "TestDecideStateTime": 1536157104625, |
1108| } | "TestEstablishCaseSelected": 0, |
1109| | "TestEstablishStateTime": 1536157104623, |
1110| | "TestMatchCase": 0, |
1111| | "TestMatchCaseSelected": 1, |
1112| | "TestMatchStateTime": 1536157104620, |
1113| | "TestSlogan": "Test slogan for External Event0", |
1114| | "TestTemperature": 9080.866, |
1115| | "TestTimestamp": 1469781869269 |
1116| | } |
1117+-------------------------------------------------------------+-------------------------------------------------------------+
1118
1119.. container:: paragraph
1120
1121 Terminate APEX by simply using ``CTRL+C`` in the console.
1122
1123Verify a Full Installation - REST Editor
1124########################################
1125
1126 .. container:: paragraph
1127
1128 APEX has a REST application for viewing policy models. The
1129 application can also be used to create new policy models close to
1130 the engine native policy language. Start the REST editor as
1131 follows.
1132
1133 .. container:: listingblock
1134
1135 .. container:: content
1136
ramverma760cce92019-07-11 12:57:49 +00001137 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001138 :number-lines:
1139
1140 # $APEX_HOME/bin/apexApps.sh rest-editor
1141
1142.. container:: listingblock
1143
1144 .. container:: content
1145
ramverma760cce92019-07-11 12:57:49 +00001146 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001147 :number-lines:
1148
1149 >%APEX_HOME%\bin\apexApps.bat rest-editor
1150
1151.. container:: paragraph
1152
1153 The script will start a simple web server
1154 (`Grizzly <https://javaee.github.io/grizzly/>`__) and deploy a
1155 ``war`` web archive in it. Once the editor is started, it will be
1156 available on ``localhost:18989``. The last few line of the messages
1157 should be:
1158
1159.. container:: listingblock
1160
1161 .. container:: content
1162
ramverma760cce92019-07-11 12:57:49 +00001163 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001164 :number-lines:
1165
1166 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
1167 Sep 05, 2018 10:35:57 PM org.glassfish.grizzly.http.server.NetworkListener start
1168 INFO: Started listener bound to [localhost:18989]
1169 Sep 05, 2018 10:35:57 PM org.glassfish.grizzly.http.server.HttpServer start
1170 INFO: [HttpServer] Started.
1171 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
1172
1173.. container:: paragraph
1174
1175 Now open a browser (Firefox, Chrome, Opera, Internet Explorer) and
1176 use the URL ``http://localhost:18989/``. This will connect the
1177 browser to the started REST editor. The start screen should be as
1178 follows.
1179
1180.. container:: imageblock
1181
1182 .. container:: content
1183
1184 |REST Editor Start Screen|
1185
1186 .. container:: title
1187
1188 Figure 1. REST Editor Start Screen
1189
1190.. container:: paragraph
1191
1192 Now load a policy model by clicking the menu ``File`` and then
1193 ``Open``. In the opened dialog, go to the directory where APEX is
1194 installed, then ``examples``, ``models``, ``SampleDomain``, and there
1195 select the file ``SamplePolicyModelJAVA.json``. This will load the
1196 policy model used to verify the policy engine (see above). Once
1197 loaded, the screen should look as follows.
1198
1199.. container:: imageblock
1200
1201 .. container:: content
1202
1203 |REST Editor with loaded SampleDomain Policy Model|
1204
1205 .. container:: title
1206
1207 Figure 2. REST Editor with loaded SampleDomain Policy Model
1208
1209.. container:: paragraph
1210
1211 Now you can use the REST editor. To finish this verification, simply
1212 terminate your browser (or the tab), and then use ``CTRL+C`` in the
1213 console where you started the REST editor.
1214
1215Installing WAR Applications
1216---------------------------
1217
1218 .. container:: paragraph
1219
1220 APEX comes with a set of WAR files. These are complete
1221 applications that can be installed and run in an application
1222 server. All of these applications are realized as servlets. You
1223 can find the WAR applications in ``$APEX_HOME/war`` (UNIX, Cygwin)
1224 or ``%APEX_HOME%\war`` (Windows).
1225
1226 .. container:: paragraph
1227
1228 Installing and using the WAR applications requires a web server
1229 that can execute ``war`` web archives. We recommend to use `Apache
1230 Tomcat <https://tomcat.apache.org/>`__, however other web servers
1231 can be used as well.
1232
1233 .. container:: paragraph
1234
1235 Install Apache Tomcat including the ``Manager App``, see `V9.0
1236 Docs <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html#Configuring_Manager_Application_Access>`__
1237 for details. Start the Tomcat service, or make sure that Tomcat is
1238 running.
1239
1240 .. container:: paragraph
1241
1242 There are multiple ways to install the APEX WAR applications:
1243
1244 .. container:: ulist
1245
1246 - copy the ``.war`` file into the Tomcat ``webapps`` folder
1247
1248 - use the Tomcat ``Manager App`` to deploy via the web interface
1249
1250 - deploy using a REST call to Tomcat
1251
1252 .. container:: paragraph
1253
1254 For details on how to install ``war`` files please consult the
1255 `Tomcat
1256 Documentation <https://tomcat.apache.org/tomcat-9.0-doc/index.html>`__
1257 or the `Manager App
1258 HOW-TO <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html>`__.
1259 Once you installed an APEX WAR application (and wait for
1260 sufficient time for Tomcat to finalize the installation), open the
1261 ``Manager App`` in Tomcat. You should see the APEX WAR application
1262 being installed and running.
1263
1264 .. container:: paragraph
1265
1266 In case of errors, examine the log files in the Tomcat log
1267 directory. In a conventional install, those log files are in the
1268 logs directory where Tomcat is installed.
1269
1270 .. container:: paragraph
1271
1272 The current APEX version provides the following WAR applications:
1273
1274 .. container:: ulist
1275
1276 - client-deployment-2.0.0-SNAPSHOT.war - a client to deploy new
1277 policy models to a running engine
1278
1279 - client-editor-2.0.0-SNAPSHOT.war - the standard policy REST
1280 editor GUI
1281
1282 - client-monitoring-2.0.0-SNAPSHOT.war - a client for monitoring
1283 a running APEX engine
1284
1285 - client-full-2.0.0-SNAPSHOT.war - a full client with a
1286 one-stop-access to deployment, monitoring, and REST editor
1287
1288 - examples-servlet-2.0.0-SNAPSHOT.war - an example APEX servlet
1289
1290Running APEX in Docker
1291----------------------
1292
1293 .. container:: paragraph
1294
1295 Since APEX is in ONAP, we provide a full virtualization
1296 environment for the engine.
1297
1298Run in ONAP
1299###########
1300
1301 .. container:: paragraph
1302
1303 Running APEX from the ONAP docker repository only requires 2
1304 commands:
1305
1306 .. container:: olist arabic
1307
1308 #. Log into the ONAP docker repo
1309
1310 .. container:: listingblock
1311
1312 .. container:: content
1313
1314 ::
1315
1316 docker login -u docker -p docker nexus3.onap.org:10003
1317
1318 .. container:: olist arabic
1319
1320 #. Run the APEX docker image
1321
1322 .. container:: listingblock
1323
1324 .. container:: content
1325
1326 ::
1327
1328 docker run -it --rm nexus3.onap.org:10003/onap/policy-apex-pdp:latest
1329
1330Build a Docker Image
1331####################
1332
1333 .. container:: paragraph
1334
1335 Alternatively, one can use the Dockerfile defined in the Docker
1336 package to build an image.
1337
1338 .. container:: listingblock
1339
1340 .. container:: title
1341
1342 APEX Dockerfile
1343
1344 .. container:: content
1345
ramverma760cce92019-07-11 12:57:49 +00001346 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001347 :number-lines:
1348
1349 #
1350 # Docker file to build an image that runs APEX on Java 8 in Ubuntu
1351 #
1352 FROM ubuntu:16.04
1353
1354 RUN apt-get update && \
1355 apt-get upgrade -y && \
1356 apt-get install -y software-properties-common && \
1357 add-apt-repository ppa:openjdk-r/ppa -y && \
1358 apt-get update && \
1359 apt-get install -y openjdk-8-jdk
1360
1361 # Create apex user and group
1362 RUN groupadd apexuser
1363 RUN useradd --create-home -g apexuser apexuser
1364
1365 # Add Apex-specific directories and set ownership as the Apex admin user
1366 RUN mkdir -p /opt/app/policy/apex-pdp
1367 RUN mkdir -p /var/log/onap/policy/apex-pdp
1368 RUN chown -R apexuser:apexuser /var/log/onap/policy/apex-pdp
1369
1370 # Unpack the tarball
1371 RUN mkdir /packages
1372 COPY apex-pdp-package-full.tar.gz /packages
1373 RUN tar xvfz /packages/apex-pdp-package-full.tar.gz --directory /opt/app/policy/apex-pdp
1374 RUN rm /packages/apex-pdp-package-full.tar.gz
1375
1376 # Ensure everything has the correct permissions
1377 RUN find /opt/app -type d -perm 755
1378 RUN find /opt/app -type f -perm 644
1379 RUN chmod a+x /opt/app/policy/apex-pdp/bin/*
1380
1381 # Copy examples to Apex user area
1382 RUN cp -pr /opt/app/policy/apex-pdp/examples /home/apexuser
1383
1384 RUN apt-get clean
1385
1386 RUN chown -R apexuser:apexuser /home/apexuser/*
1387
1388 USER apexuser
1389 ENV PATH /opt/app/policy/apex-pdp/bin:$PATH
1390 WORKDIR /home/apexuser
1391
1392APEX Configurations Explained
1393^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1394
1395Introduction to APEX Configuration
1396----------------------------------
1397
1398 .. container:: paragraph
1399
1400 An APEX engine can be configured to use various combinations
1401 of event input handlers, event output handlers, event
1402 protocols, context handlers, and logic executors. The system
1403 is build using a plugin architecture. Each configuration
1404 option is realized by a plugin, which can be loaded and
1405 configured when the engine is started. New plugins can be
1406 added to the system at any time, though to benefit from a
1407 new plugin an engine will need to be restarted.
1408
1409 .. container:: imageblock
1410
1411 .. container:: content
1412
1413 |APEX Configuration Matrix|
1414
1415 .. container:: title
1416
1417 Figure 3. APEX Configuration Matrix
1418
1419 .. container:: paragraph
1420
1421 The APEX distribution already comes with a number of
1422 plugins. The figure above shows the provided plugins. Any
1423 combination of input, output, event protocol, context
1424 handlers, and executors is possible.
1425
1426General Configuration Format
1427----------------------------
1428
1429 .. container:: paragraph
1430
1431 The APEX configuration file is a JSON file containing a few
1432 main blocks for different parts of the configuration. Each
1433 block then holds the configuration details. The following
1434 code shows the main blocks:
1435
1436 .. container:: listingblock
1437
1438 .. container:: content
1439
ramverma760cce92019-07-11 12:57:49 +00001440 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001441
1442 {
1443 "engineServiceParameters":{
1444 ... (1)
1445 "engineParameters":{ (2)
1446 "engineParameters":{...}, (3)
1447 "contextParameters":{...} (4)
1448 }
1449 },
1450 "eventInputParameters":{ (5)
1451 "input1":{ (6)
1452 "carrierTechnologyParameters":{...},
1453 "eventProtocolParameters":{...}
1454 },
1455 "input2":{...}, (7)
1456 "carrierTechnologyParameters":{...},
1457 "eventProtocolParameters":{...}
1458 },
1459 ... (8)
1460 },
1461 "eventOutputParameters":{ (9)
1462 "output1":{ (10)
1463 "carrierTechnologyParameters":{...},
1464 "eventProtocolParameters":{...}
1465 },
1466 "output2":{ (11)
1467 "carrierTechnologyParameters":{...},
1468 "eventProtocolParameters":{...}
1469 },
1470 ... (12)
1471 }
1472 }
1473
1474 .. container:: colist arabic
1475
1476 +-----------------------------------+-----------------------------------+
1477 | **1** | main engine configuration |
1478 +-----------------------------------+-----------------------------------+
1479 | **2** | engine parameters for plugin |
1480 | | configurations (execution |
1481 | | environments and context |
1482 | | handling) |
1483 +-----------------------------------+-----------------------------------+
1484 | **3** | engine specific parameters, |
1485 | | mainly for executor plugins |
1486 +-----------------------------------+-----------------------------------+
1487 | **4** | context specific parameters, e.g. |
1488 | | for context schemas, persistence, |
1489 | | etc. |
1490 +-----------------------------------+-----------------------------------+
1491 | **5** | configuration of the input |
1492 | | interface |
1493 +-----------------------------------+-----------------------------------+
1494 | **6** | an example input called |
1495 | | ``input1`` with carrier |
1496 | | technology and event protocol |
1497 +-----------------------------------+-----------------------------------+
1498 | **7** | an example input called |
1499 | | ``input2`` with carrier |
1500 | | technology and event protocol |
1501 +-----------------------------------+-----------------------------------+
1502 | **8** | any further input configuration |
1503 +-----------------------------------+-----------------------------------+
1504 | **9** | configuration of the output |
1505 | | interface |
1506 +-----------------------------------+-----------------------------------+
1507 | **10** | an example output called |
1508 | | ``output1`` with carrier |
1509 | | technology and event protocol |
1510 +-----------------------------------+-----------------------------------+
1511 | **11** | an example output called |
1512 | | ``output2`` with carrier |
1513 | | technology and event protocol |
1514 +-----------------------------------+-----------------------------------+
1515 | **12** | any further output configuration |
1516 +-----------------------------------+-----------------------------------+
1517
1518Engine Service Parameters
1519-------------------------
1520
1521 .. container:: paragraph
1522
1523 The configuration provides a number of parameters to
1524 configure the engine. An example configuration with
1525 explanations of all options is shown below.
1526
1527 .. container:: listingblock
1528
1529 .. container:: content
1530
ramverma760cce92019-07-11 12:57:49 +00001531 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001532
1533 "engineServiceParameters" : {
1534 "name" : "AADMApexEngine", (1)
1535 "version" : "0.0.1", (2)
1536 "id" : 45, (3)
1537 "instanceCount" : 4, (4)
1538 "deploymentPort" : 12345, (5)
1539 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelJava.json", (6)
1540 "periodicEventPeriod": 1000, (7)
1541 "engineParameters":{ (8)
1542 "engineParameters":{...}, (9)
1543 "contextParameters":{...} (10)
1544 }
1545 }
1546
1547 .. container:: colist arabic
1548
1549 +-----------------------------------+-----------------------------------+
1550 | **1** | a name for the engine. The engine |
1551 | | name is used to create a key in a |
1552 | | runtime engine. An name matching |
1553 | | the following regular expression |
1554 | | can be used here: |
1555 | | ``[A-Za-z0-9\\-_\\.]+`` |
1556 +-----------------------------------+-----------------------------------+
1557 | **2** | a version of the engine, use |
1558 | | semantic versioning as explained |
1559 | | here: `Semantic |
1560 | | Versioning <http://semver.org/>`_ |
1561 | | _. |
1562 | | This version is used in a runtime |
1563 | | engine to create a version of the |
1564 | | engine. For that reason, the |
1565 | | version must match the following |
1566 | | regular expression ``[A-Z0-9.]+`` |
1567 +-----------------------------------+-----------------------------------+
1568 | **3** | a numeric identifier for the |
1569 | | engine |
1570 +-----------------------------------+-----------------------------------+
1571 | **4** | the number of threads (policy |
1572 | | instances executed in parallel) |
1573 | | the engine should use, use ``1`` |
1574 | | for single threaded engines |
1575 +-----------------------------------+-----------------------------------+
1576 | **5** | the port for the deployment |
1577 | | Websocket connection to the |
1578 | | engine |
1579 +-----------------------------------+-----------------------------------+
1580 | **6** | the model file to load into the |
1581 | | engine on startup (optional) |
1582 +-----------------------------------+-----------------------------------+
1583 | **7** | an optional timer for periodic |
1584 | | policies, in milliseconds (a |
1585 | | defined periodic policy will be |
1586 | | executed every ``X`` |
1587 | | milliseconds), not used of not |
1588 | | set or ``0`` |
1589 +-----------------------------------+-----------------------------------+
1590 | **8** | engine parameters for plugin |
1591 | | configurations (execution |
1592 | | environments and context |
1593 | | handling) |
1594 +-----------------------------------+-----------------------------------+
1595 | **9** | engine specific parameters, |
1596 | | mainly for executor plugins |
1597 +-----------------------------------+-----------------------------------+
1598 | **10** | context specific parameters, e.g. |
1599 | | for context schemas, persistence, |
1600 | | etc. |
1601 +-----------------------------------+-----------------------------------+
1602
1603 .. container:: paragraph
1604
1605 The model file is optional, it can also be specified via
1606 command line. In any case, make sure all execution and other
1607 required plug-ins for the loaded model are loaded as
1608 required.
1609
1610Input and Output Interfaces
1611---------------------------
1612
1613 .. container:: paragraph
1614
1615 An APEX engine has two main interfaces:
1616
1617 .. container:: ulist
1618
1619 - An *input* interface to receive events: also known as
1620 ingress interface or consumer, receiving (consuming)
1621 events commonly named triggers, and
1622
1623 - An *output* interface to publish produced events: also
1624 known as egress interface or producer, sending
1625 (publishing) events commonly named actions or action
1626 events.
1627
1628 .. container:: paragraph
1629
1630 The input and output interface is configured in terms of
1631 inputs and outputs, respectively. Each input and output is a
1632 combination of a carrier technology and an event protocol.
1633 Carrier technologies and event protocols are provided by
1634 plugins, each with its own specific configuration. Most
1635 carrier technologies can be configured for input as well as
1636 output. Most event protocols can be used for all carrier
1637 technologies. One exception is the JMS object event
1638 protocol, which can only be used for the JMS carrier
1639 technology. Some further restrictions apply (for instance
1640 for carrier technologies using bi- or uni-directional
1641 modes).
1642
1643 .. container:: paragraph
1644
1645 Input and output interface can be configured separately, in
1646 isolation, with any number of carrier technologies. The
1647 resulting general configuration options are:
1648
1649 .. container:: ulist
1650
1651 - Input interface with one or more inputs
1652
1653 .. container:: ulist
1654
1655 - each input with a carrier technology and an event
1656 protocol
1657
1658 - some inputs with optional synchronous mode
1659
1660 - some event protocols with additional parameters
1661
1662 - Output interface with one or more outputs
1663
1664 .. container:: ulist
1665
1666 - each output with a carrier technology and an event
1667 encoding
1668
1669 - some outputs with optional synchronous mode
1670
1671 - some event protocols with additional parameters
1672
1673 .. container:: paragraph
1674
1675 The configuration for input and output is contained in
1676 ``eventInputParameters`` and ``eventOutputParameters``,
1677 respectively. Inside here, one can configure any number of
1678 inputs and outputs. Each of them needs to have a unique
1679 identifier (name), the content of the name is free form. The
1680 example below shows a configuration for two inputs and two
1681 outputs.
1682
1683 .. container:: listingblock
1684
1685 .. container:: content
1686
ramverma760cce92019-07-11 12:57:49 +00001687 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001688
1689 "eventInputParameters": { (1)
1690 "FirstConsumer": { (2)
1691 "carrierTechnologyParameters" : {...}, (3)
1692 "eventProtocolParameters":{...}, (4)
1693 ... (5)
1694 },
1695 "SecondConsumer": { (6)
1696 "carrierTechnologyParameters" : {...}, (7)
1697 "eventProtocolParameters":{...}, (8)
1698 ... (9)
1699 },
1700 },
1701 "eventOutputParameters": { (10)
1702 "FirstProducer": { (11)
1703 "carrierTechnologyParameters":{...}, (12)
1704 "eventProtocolParameters":{...}, (13)
1705 ... (14)
1706 },
1707 "SecondProducer": { (15)
1708 "carrierTechnologyParameters":{...}, (16)
1709 "eventProtocolParameters":{...}, (17)
1710 ... (18)
1711 }
1712 }
1713
1714 .. container:: colist arabic
1715
1716 +--------+--------------------------------------------------------------------+
1717 | **1** | input interface configuration, APEX input plugins |
1718 +--------+--------------------------------------------------------------------+
1719 | **2** | first input called ``FirstConsumer`` |
1720 +--------+--------------------------------------------------------------------+
1721 | **3** | carrier technology for plugin |
1722 +--------+--------------------------------------------------------------------+
1723 | **4** | event protocol for plugin |
1724 +--------+--------------------------------------------------------------------+
1725 | **5** | any other input configuration (e.g. event name filter, see below) |
1726 +--------+--------------------------------------------------------------------+
1727 | **6** | second input called ``SecondConsumer`` |
1728 +--------+--------------------------------------------------------------------+
1729 | **7** | carrier technology for plugin |
1730 +--------+--------------------------------------------------------------------+
1731 | **8** | event protocol for plugin |
1732 +--------+--------------------------------------------------------------------+
1733 | **9** | any other plugin configuration |
1734 +--------+--------------------------------------------------------------------+
1735 | **10** | output interface configuration, APEX output plugins |
1736 +--------+--------------------------------------------------------------------+
1737 | **11** | first output called ``FirstProducer`` |
1738 +--------+--------------------------------------------------------------------+
1739 | **12** | carrier technology for plugin |
1740 +--------+--------------------------------------------------------------------+
1741 | **13** | event protocol for plugin |
1742 +--------+--------------------------------------------------------------------+
1743 | **14** | any other plugin configuration |
1744 +--------+--------------------------------------------------------------------+
1745 | **15** | second output called ``SecondProducer`` |
1746 +--------+--------------------------------------------------------------------+
1747 | **16** | carrier technology for plugin |
1748 +--------+--------------------------------------------------------------------+
1749 | **17** | event protocol for plugin |
1750 +--------+--------------------------------------------------------------------+
1751 | **18** | any other output configuration (e.g. event name filter, see below) |
1752 +--------+--------------------------------------------------------------------+
1753
1754Event Filters
1755#############
1756
1757 .. container:: paragraph
1758
1759 APEX will always send an event after a policy execution
1760 is finished. For a successful execution, the event sent
1761 is the output event created by the policy. In case the
1762 policy does not create an output event, APEX will create
1763 a new event with all input event fields plus an
1764 additional field ``exceptionMessage`` with an exception
1765 message.
1766
1767 .. container:: paragraph
1768
1769 There are situations in which this auto-generated error
1770 event might not be required or wanted:
1771
1772 .. container:: ulist
1773
1774 - when a policy failing should not result in an event
1775 send out via an output interface
1776
1777 - when the auto-generated event goes back in an APEX
1778 engine (or the same APEX engine), this can create
1779 endless loops
1780
1781 - the auto-generated event should go to a special output
1782 interface or channel
1783
1784 .. container:: paragraph
1785
1786 All of these situations are supported by a filter option
1787 using a wildecard (regular expression) configuration on
1788 APEX I/O interfaces. The parameter is called
1789 ``eventNameFilter`` and the value are `Java regular
1790 expressions <https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html>`__
1791 (a
1792 `tutorial <http://www.vogella.com/tutorials/JavaRegularExpressions/article.html>`__).
1793 The following code shows some examples:
1794
1795 .. container:: listingblock
1796
1797 .. container:: content
1798
ramverma760cce92019-07-11 12:57:49 +00001799 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001800
1801 "eventInputParameters": {
1802 "Input1": {
1803 "carrierTechnologyParameters" : {...},
1804 "eventProtocolParameters":{...},
1805 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]004$" (1)
1806 }
1807 },
1808 "eventOutputParameters": {
1809 "Output1": {
1810 "carrierTechnologyParameters":{...},
1811 "eventProtocolParameters":{...},
1812 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]104$" (2)
1813 }
1814 }
1815
1816Executors
1817---------
1818
1819 .. container:: paragraph
1820
1821 Executors are plugins that realize the execution of logic
1822 contained in a policy model. Logic can be in a task
1823 selector, a task, and a state finalizer. Using plugins for
1824 execution environments makes APEX very flexible to support
1825 virtually any executable logic expressions.
1826
1827 .. container:: paragraph
1828
1829 APEX 2.0.0-SNAPSHOT supports the following executors:
1830
1831 .. container:: ulist
1832
1833 - Java, for Java implemented logic
1834
1835 .. container:: ulist
1836
1837 - This executor requires logic implemented using the
1838 APEX Java interfaces.
1839
1840 - Generated JAR files must be in the classpath of the
1841 APEX engine at start time.
1842
1843 - Javascript
1844
1845 - JRuby,
1846
1847 - Jython,
1848
1849 - MVEL
1850
1851 .. container:: ulist
1852
1853 - This executor uses the latest version of the MVEL
1854 engine, which can be very hard to debug and can
1855 produce unwanted side effects during execution
1856
1857Configure the Javascript Executor
1858#################################
1859
1860 .. container:: paragraph
1861
1862 The Javascript executor is added to the configuration as
1863 follows:
1864
1865 .. container:: listingblock
1866
1867 .. container:: content
1868
ramverma760cce92019-07-11 12:57:49 +00001869 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001870
1871 "engineServiceParameters":{
1872 "engineParameters":{
1873 "executorParameters":{
1874 "JAVASCRIPT":{
1875 "parameterClassName" :
1876 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
1877 }
1878 }
1879 }
1880 }
1881
1882Configure the Jython Executor
1883#############################
1884
1885 .. container:: paragraph
1886
1887 The Jython executor is added to the configuration as
1888 follows:
1889
1890 .. container:: listingblock
1891
1892 .. container:: content
1893
ramverma760cce92019-07-11 12:57:49 +00001894 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001895
1896 "engineServiceParameters":{
1897 "engineParameters":{
1898 "executorParameters":{
1899 "JYTHON":{
1900 "parameterClassName" :
1901 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
1902 }
1903 }
1904 }
1905 }
1906
1907Configure the JRuby Executor
1908############################
1909
1910 .. container:: paragraph
1911
1912 The JRuby executor is added to the configuration as
1913 follows:
1914
1915 .. container:: listingblock
1916
1917 .. container:: content
1918
ramverma760cce92019-07-11 12:57:49 +00001919 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001920
1921 "engineServiceParameters":{
1922 "engineParameters":{
1923 "executorParameters":{
1924 "JRUBY":{
1925 "parameterClassName" :
1926 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
1927 }
1928 }
1929 }
1930 }
1931
1932Configure the Java Executor
1933###########################
1934
1935 .. container:: paragraph
1936
1937 The Java executor is added to the configuration as
1938 follows:
1939
1940 .. container:: listingblock
1941
1942 .. container:: content
1943
ramverma760cce92019-07-11 12:57:49 +00001944 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001945
1946 "engineServiceParameters":{
1947 "engineParameters":{
1948 "executorParameters":{
1949 "JAVA":{
1950 "parameterClassName" :
1951 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
1952 }
1953 }
1954 }
1955 }
1956
1957Configure the MVEL Executor
1958###########################
1959
1960 .. container:: paragraph
1961
1962 The MVEL executor is added to the configuration as
1963 follows:
1964
1965 .. container:: listingblock
1966
1967 .. container:: content
1968
ramverma760cce92019-07-11 12:57:49 +00001969 .. code::
ramverma3b71c972019-07-10 11:25:37 +00001970
1971 "engineServiceParameters":{
1972 "engineParameters":{
1973 "executorParameters":{
1974 "MVEL":{
1975 "parameterClassName" :
1976 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
1977 }
1978 }
1979 }
1980 }
1981
1982Context Handlers
1983----------------
1984
1985 .. container:: paragraph
1986
1987 Context handlers are responsible for all context processing.
1988 There are the following main areas:
1989
1990 .. container:: ulist
1991
1992 - Context schema: use schema handlers other than Java class
1993 (supported by default without configuration)
1994
1995 - Context distribution: distribute context across multiple
1996 APEX engines
1997
1998 - Context locking: mechanisms to lock context elements for
1999 read/write
2000
2001 - Context persistence: mechanisms to persist context
2002
2003 .. container:: paragraph
2004
2005 APEX provides plugins for each of the main areas.
2006
2007Configure AVRO Schema Handler
2008#############################
2009
2010 .. container:: paragraph
2011
2012 The AVRO schema handler is added to the configuration as
2013 follows:
2014
2015 .. container:: listingblock
2016
2017 .. container:: content
2018
ramverma760cce92019-07-11 12:57:49 +00002019 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002020
2021 "engineServiceParameters":{
2022 "engineParameters":{
2023 "contextParameters":{
2024 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
2025 "schemaParameters":{
2026 "Avro":{
2027 "parameterClassName" :
2028 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
2029 }
2030 }
2031 }
2032 }
2033 }
2034
2035 .. container:: paragraph
2036
2037 Using the AVRO schema handler has one limitation: AVRO
2038 only supports field names that represent valid Java class
2039 names. This means only letters and the character ``_``
2040 are supported. Characters commonly used in field names,
2041 such as ``.`` and ``-``, are not supported by AVRO. for
2042 more information see `Avro Spec:
2043 Names <https://avro.apache.org/docs/1.8.1/spec.html#names>`__.
2044
2045 .. container:: paragraph
2046
2047 To work with this limitation, the APEX Avro plugin will
2048 parse a given AVRO definition and replace *all*
2049 occurrences of ``.`` and ``-`` with a ``_``. This means
2050 that
2051
2052 .. container:: ulist
2053
2054 - In a policy model, if the AVRO schema defined a field
2055 as ``my-name`` the policy logic should access it as
2056 ``my_name``
2057
2058 - In a policy model, if the AVRO schema defined a field
2059 as ``my.name`` the policy logic should access it as
2060 ``my_name``
2061
2062 - There should be no field names that convert to the
2063 same internal name
2064
2065 .. container:: ulist
2066
2067 - For instance the simultaneous use of
2068 ``my_name``, ``my.name``, and ``my-name`` should
2069 be avoided
2070
2071 - If not avoided, the event processing might
2072 create unwanted side effects
2073
2074 - If field names use any other not-supported character,
2075 the AVRO plugin will reject it
2076
2077 .. container:: ulist
2078
2079 - Since AVRO uses lazy initialization, this
2080 rejection might only become visible at runtime
2081
2082Carrier Technologies
2083--------------------
2084
2085 .. container:: paragraph
2086
2087 Carrier technologies define how APEX receives (input) and
2088 sends (output) events. They can be used in any combination,
2089 using asynchronous or synchronous mode. There can also be
2090 any number of carrier technologies for the input (consume)
2091 and the output (produce) interface.
2092
2093 .. container:: paragraph
2094
2095 Supported *input* technologies are:
2096
2097 .. container:: ulist
2098
2099 - Standard input, read events from the standard input
2100 (console), not suitable for APEX background servers
2101
2102 - File input, read events from a file
2103
2104 - Kafka, read events from a Kafka system
2105
2106 - Websockets, read events from a Websocket
2107
2108 - JMS,
2109
2110 - REST (synchronous and asynchronous), additionally as
2111 client or server
2112
2113 - Event Requestor, allows reading of events that have been
2114 looped back into APEX
2115
2116 .. container:: paragraph
2117
2118 Supported *output* technologies are:
2119
2120 .. container:: ulist
2121
2122 - Standard output, write events to the standard output
2123 (console), not suitable for APEX background servers
2124
2125 - File output, write events to a file
2126
2127 - Kafka, write events to a Kafka system
2128
2129 - Websockets, write events to a Websocket
2130
2131 - JMS
2132
2133 - REST (synchronous and asynchronous), additionally as
2134 client or server
2135
2136 - Event Requestor, allows events to be looped back into
2137 APEX
2138
2139 .. container:: paragraph
2140
2141 New carrier technologies can be added as plugins to APEX or
2142 developed outside APEX and added to an APEX deployment.
2143
2144Standard IO
2145###########
2146
2147 .. container:: paragraph
2148
2149 Standard IO does not require a specific plugin, it is
2150 supported be default.
2151
2152Standard Input
2153==============
2154 .. container:: paragraph
2155
2156 APEX will take events from its standard input. This
2157 carrier is good for testing, but certainly not for a
2158 use case where APEX runs as a server. The
2159 configuration is as follows:
2160
2161 .. container:: listingblock
2162
2163 .. container:: content
2164
2165 ::
2166
2167 "carrierTechnologyParameters" : {
2168 "carrierTechnology" : "FILE", (1)
2169 "parameters" : {
2170 "standardIO" : true (2)
2171 }
2172 }
2173
2174 .. container:: colist arabic
2175
2176 +-------+---------------------------------------+
2177 | **1** | standard input is considered a file |
2178 +-------+---------------------------------------+
2179 | **2** | file descriptor set to standard input |
2180 +-------+---------------------------------------+
2181
2182Standard Output
2183===============
2184
2185 .. container:: paragraph
2186
2187 APEX will send events to its standard output. This
2188 carrier is good for testing, but certainly not for a
2189 use case where APEX runs as a server. The
2190 configuration is as follows:
2191
2192 .. container:: listingblock
2193
2194 .. container:: content
2195
ramverma760cce92019-07-11 12:57:49 +00002196 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002197
2198 "carrierTechnologyParameters" : {
2199 "carrierTechnology" : "FILE", (1)
2200 "parameters" : {
2201 "standardIO" : true (2)
2202 }
2203 }
2204
2205 .. container:: colist arabic
2206
2207 +-------+----------------------------------------+
2208 | **1** | standard output is considered a file |
2209 +-------+----------------------------------------+
2210 | **2** | file descriptor set to standard output |
2211 +-------+----------------------------------------+
2212
22132.7.2. File IO
2214##############
2215
2216 .. container:: paragraph
2217
2218 File IO does not require a specific plugin, it is
2219 supported be default.
2220
2221File Input
2222==========
2223
2224 .. container:: paragraph
2225
2226 APEX will take events from a file. The same file
2227 should not be used as an output. The configuration is
2228 as follows:
2229
2230 .. container:: listingblock
2231
2232 .. container:: content
2233
ramverma760cce92019-07-11 12:57:49 +00002234 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002235
2236 "carrierTechnologyParameters" : {
2237 "carrierTechnology" : "FILE", (1)
2238 "parameters" : {
2239 "fileName" : "examples/events/SampleDomain/EventsIn.xmlfile" (2)
2240 }
2241 }
2242
2243 .. container:: colist arabic
2244
2245 +-------+------------------------------------------+
2246 | **1** | set file input |
2247 +-------+------------------------------------------+
2248 | **2** | the name of the file to read events from |
2249 +-------+------------------------------------------+
2250
2251File Output
2252===========
2253 .. container:: paragraph
2254
2255 APEX will write events to a file. The same file should
2256 not be used as an input. The configuration is as
2257 follows:
2258
2259 .. container:: listingblock
2260
2261 .. container:: content
2262
ramverma760cce92019-07-11 12:57:49 +00002263 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002264
2265 "carrierTechnologyParameters" : {
2266 "carrierTechnology" : "FILE", (1)
2267 "parameters" : {
2268 "fileName" : "examples/events/SampleDomain/EventsOut.xmlfile" (2)
2269 }
2270 }
2271
2272 .. container:: colist arabic
2273
2274 +-------+-----------------------------------------+
2275 | **1** | set file output |
2276 +-------+-----------------------------------------+
2277 | **2** | the name of the file to write events to |
2278 +-------+-----------------------------------------+
2279
2280Event Requestor IO
2281##################
2282
2283 .. container:: paragraph
2284
2285 Event Requestor IO does not require a specific plugin, it
2286 is supported be default. It should only be used with the
2287 APEX event protocol.
2288
2289Event Requestor Input
2290=====================
2291
2292 .. container:: paragraph
2293
2294 APEX will take events from APEX.
2295
2296 .. container:: listingblock
2297
2298 .. container:: content
2299
ramverma760cce92019-07-11 12:57:49 +00002300 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002301
2302 "carrierTechnologyParameters" : {
2303 "carrierTechnology": "EVENT_REQUESTOR" (1)
2304 }
2305
2306 .. container:: colist arabic
2307
2308 +-------+---------------------------+
2309 | **1** | set event requestor input |
2310 +-------+---------------------------+
2311
2312Event Requestor Output
2313======================
2314
2315 .. container:: paragraph
2316
2317 APEX will write events to APEX.
2318
2319 .. container:: listingblock
2320
2321 .. container:: content
2322
ramverma760cce92019-07-11 12:57:49 +00002323 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002324
2325 "carrierTechnologyParameters" : {
2326 "carrierTechnology": "EVENT_REQUESTOR" (1)
2327 }
2328
2329Peering Event Requestors
2330========================
2331
2332 .. container:: paragraph
2333
2334 When using event requestors, they need to be peered.
2335 This means an event requestor output needs to be
2336 peered (associated) with an event requestor input. The
2337 following example shows the use of an event requestor
2338 with the APEX event protocol and the peering of output
2339 and input.
2340
2341 .. container:: listingblock
2342
2343 .. container:: content
2344
ramverma760cce92019-07-11 12:57:49 +00002345 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002346
2347 "eventInputParameters": {
2348 "EventRequestorConsumer": {
2349 "carrierTechnologyParameters": {
2350 "carrierTechnology": "EVENT_REQUESTOR" (1)
2351 },
2352 "eventProtocolParameters": {
2353 "eventProtocol": "APEX" (2)
2354 },
2355 "eventNameFilter": "InputEvent", (3)
2356 "requestorMode": true, (4)
2357 "requestorPeer": "EventRequestorProducer", (5)
2358 "requestorTimeout": 500 (6)
2359 }
2360 },
2361 "eventOutputParameters": {
2362 "EventRequestorProducer": {
2363 "carrierTechnologyParameters": {
2364 "carrierTechnology": "EVENT_REQUESTOR" (7)
2365 },
2366 "eventProtocolParameters": {
2367 "eventProtocol": "APEX" (8)
2368 },
2369 "eventNameFilter": "EventListEvent", (9)
2370 "requestorMode": true, (10)
2371 "requestorPeer": "EventRequestorConsumer", (11)
2372 "requestorTimeout": 500 (12)
2373 }
2374 }
2375
2376 .. container:: colist arabic
2377
2378 +-----------------------------------+-----------------------------------+
2379 | **1** | event requestor on a consumer |
2380 +-----------------------------------+-----------------------------------+
2381 | **2** | with APEX event protocol |
2382 +-----------------------------------+-----------------------------------+
2383 | **3** | optional filter (best to use a |
2384 | | filter to prevent unwanted events |
2385 | | on the consumer side) |
2386 +-----------------------------------+-----------------------------------+
2387 | **4** | activate requestor mode |
2388 +-----------------------------------+-----------------------------------+
2389 | **5** | the peer to the output (must |
2390 | | match the output carrier) |
2391 +-----------------------------------+-----------------------------------+
2392 | **6** | an optional timeout in |
2393 | | milliseconds |
2394 +-----------------------------------+-----------------------------------+
2395 | **7** | event requestor on a producer |
2396 +-----------------------------------+-----------------------------------+
2397 | **8** | with APEX event protocol |
2398 +-----------------------------------+-----------------------------------+
2399 | **9** | optional filter (best to use a |
2400 | | filter to prevent unwanted events |
2401 | | on the consumer side) |
2402 +-----------------------------------+-----------------------------------+
2403 | **10** | activate requestor mode |
2404 +-----------------------------------+-----------------------------------+
2405 | **11** | the peer to the output (must |
2406 | | match the input carrier) |
2407 +-----------------------------------+-----------------------------------+
2408 | **12** | an optional timeout in |
2409 | | milliseconds |
2410 +-----------------------------------+-----------------------------------+
2411
2412Kafka IO
2413########
2414
2415 .. container:: paragraph
2416
2417 Kafka IO is supported by the APEX Kafka plugin. The
2418 configurations below are examples. APEX will take any
2419 configuration inside the parameter object and forward it
2420 to Kafka. More information on Kafka specific
2421 configuration parameters can be found in the Kafka
2422 documentation:
2423
2424 .. container:: ulist
2425
2426 - `Kafka Consumer
2427 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html>`__
2428
2429 - `Kafka Producer
2430 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>`__
2431
2432Kafka Input
2433===========
2434 .. container:: paragraph
2435
2436 APEX will receive events from the Apache Kafka
2437 messaging system. The input is uni-directional, an
2438 engine will only receive events from the input but not
2439 send any event to the input.
2440
2441 .. container:: listingblock
2442
2443 .. container:: content
2444
ramverma760cce92019-07-11 12:57:49 +00002445 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002446
2447 "carrierTechnologyParameters" : {
2448 "carrierTechnology" : "KAFKA", (1)
2449 "parameterClassName" :
2450 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2451 "parameters" : {
2452 "bootstrapServers" : "localhost:49092", (2)
2453 "groupId" : "apex-group-id", (3)
2454 "enableAutoCommit" : true, (4)
2455 "autoCommitTime" : 1000, (5)
2456 "sessionTimeout" : 30000, (6)
2457 "consumerPollTime" : 100, (7)
2458 "consumerTopicList" : ["apex-in-0", "apex-in-1"], (8)
2459 "keyDeserializer" :
2460 "org.apache.kafka.common.serialization.StringDeserializer", (9)
2461 "valueDeserializer" :
2462 "org.apache.kafka.common.serialization.StringDeserializer" (10)
2463 }
2464 }
2465
2466 .. container:: colist arabic
2467
2468 +--------+-------------------------------------+
2469 | **1** | set Kafka as carrier technology |
2470 +--------+-------------------------------------+
2471 | **2** | bootstrap server and port |
2472 +--------+-------------------------------------+
2473 | **3** | a group identifier |
2474 +--------+-------------------------------------+
2475 | **4** | flag for auto-commit |
2476 +--------+-------------------------------------+
2477 | **5** | auto-commit timeout in milliseconds |
2478 +--------+-------------------------------------+
2479 | **6** | session timeout in milliseconds |
2480 +--------+-------------------------------------+
2481 | **7** | consumer poll time in milliseconds |
2482 +--------+-------------------------------------+
2483 | **8** | consumer topic list |
2484 +--------+-------------------------------------+
2485 | **9** | key for the Kafka de-serializer |
2486 +--------+-------------------------------------+
2487 | **10** | value for the Kafka de-serializer |
2488 +--------+-------------------------------------+
2489
2490Kafka Output
2491============
2492 .. container:: paragraph
2493
2494 APEX will send events to the Apache Kafka messaging
2495 system. The output is uni-directional, an engine will
2496 send events to the output but not receive any event
2497 from the output.
2498
2499 .. container:: listingblock
2500
2501 .. container:: content
2502
ramverma760cce92019-07-11 12:57:49 +00002503 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002504
2505 "carrierTechnologyParameters" : {
2506 "carrierTechnology" : "KAFKA", (1)
2507 "parameterClassName" :
2508 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2509 "parameters" : {
2510 "bootstrapServers" : "localhost:49092", (2)
2511 "acks" : "all", (3)
2512 "retries" : 0, (4)
2513 "batchSize" : 16384, (5)
2514 "lingerTime" : 1, (6)
2515 "bufferMemory" : 33554432, (7)
2516 "producerTopic" : "apex-out", (8)
2517 "keySerializer" :
2518 "org.apache.kafka.common.serialization.StringSerializer", (9)
2519 "valueSerializer" :
2520 "org.apache.kafka.common.serialization.StringSerializer" (10)
2521 }
2522 }
2523
2524 .. container:: colist arabic
2525
2526 +--------+---------------------------------+
2527 | **1** | set Kafka as carrier technology |
2528 +--------+---------------------------------+
2529 | **2** | bootstrap server and port |
2530 +--------+---------------------------------+
2531 | **3** | acknowledgement strategy |
2532 +--------+---------------------------------+
2533 | **4** | number of retries |
2534 +--------+---------------------------------+
2535 | **5** | batch size |
2536 +--------+---------------------------------+
2537 | **6** | time to linger in milliseconds |
2538 +--------+---------------------------------+
2539 | **7** | buffer memory in byte |
2540 +--------+---------------------------------+
2541 | **8** | producer topic |
2542 +--------+---------------------------------+
2543 | **9** | key for the Kafka serializer |
2544 +--------+---------------------------------+
2545 | **10** | value for the Kafka serializer |
2546 +--------+---------------------------------+
2547
2548JMS IO
2549#######
2550
2551 .. container:: paragraph
2552
2553 APEX supports the Java Messaging Service (JMS) as input
2554 as well as output. JMS IO is supported by the APEX JMS
2555 plugin. Input and output support an event encoding as
2556 text (JSON string) or object (serialized object). The
2557 input configuration is the same for both encodings, the
2558 output configuration differs.
2559
2560JMS Input
2561=========
2562 .. container:: paragraph
2563
2564 APEX will receive events from a JMS messaging system.
2565 The input is uni-directional, an engine will only
2566 receive events from the input but not send any event
2567 to the input.
2568
2569 .. container:: listingblock
2570
2571 .. container:: content
2572
ramverma760cce92019-07-11 12:57:49 +00002573 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002574
2575 "carrierTechnologyParameters" : {
2576 "carrierTechnology" : "JMS", (1)
2577 "parameterClassName" :
2578 "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2579 "parameters" : { (2)
2580 "initialContextFactory" :
2581 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2582 "connectionFactory" : "ConnectionFactory", (4)
2583 "providerURL" : "remote://localhost:5445", (5)
2584 "securityPrincipal" : "guest", (6)
2585 "securityCredentials" : "IAmAGuest", (7)
2586 "consumerTopic" : "jms/topic/apexIn" (8)
2587 }
2588 }
2589
2590 .. container:: colist arabic
2591
2592 +-----------------------------------+-----------------------------------+
2593 | **1** | set JMS as carrier technology |
2594 +-----------------------------------+-----------------------------------+
2595 | **2** | set all JMS specific parameters |
2596 +-----------------------------------+-----------------------------------+
2597 | **3** | the context factory, in this case |
2598 | | from JBOSS (it requires the |
2599 | | dependency |
2600 | | org.jboss:jboss-remote-naming:2.0 |
2601 | | .4.Final |
2602 | | or a different version to be in |
2603 | | the directory ``$APEX_HOME/lib`` |
2604 | | or ``%APEX_HOME%\lib`` |
2605 +-----------------------------------+-----------------------------------+
2606 | **4** | a connection factory for the JMS |
2607 | | connection |
2608 +-----------------------------------+-----------------------------------+
2609 | **5** | URL with host and port of the JMS |
2610 | | provider |
2611 +-----------------------------------+-----------------------------------+
2612 | **6** | access credentials, user name |
2613 +-----------------------------------+-----------------------------------+
2614 | **7** | access credentials, user password |
2615 +-----------------------------------+-----------------------------------+
2616 | **8** | the JMS topic to listen to |
2617 +-----------------------------------+-----------------------------------+
2618
2619JMS Output with Text
2620====================
2621
2622 .. container:: paragraph
2623
2624 APEX engine send events to a JMS messaging system. The
2625 output is uni-directional, an engine will send events
2626 to the output but not receive any event from output.
2627
2628 .. container:: listingblock
2629
2630 .. container:: content
2631
ramverma760cce92019-07-11 12:57:49 +00002632 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002633
2634 "carrierTechnologyParameters" : {
2635 "carrierTechnology" : "JMS", (1)
2636 "parameterClassName" :
2637 "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2638 "parameters" : { (2)
2639 "initialContextFactory" :
2640 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2641 "connectionFactory" : "ConnectionFactory", (4)
2642 "providerURL" : "remote://localhost:5445", (5)
2643 "securityPrincipal" : "guest", (6)
2644 "securityCredentials" : "IAmAGuest", (7)
2645 "producerTopic" : "jms/topic/apexOut", (8)
2646 "objectMessageSending": "false" (9)
2647 }
2648 }
2649
2650 .. container:: colist arabic
2651
2652 +-----------------------------------+-----------------------------------+
2653 | **1** | set JMS as carrier technology |
2654 +-----------------------------------+-----------------------------------+
2655 | **2** | set all JMS specific parameters |
2656 +-----------------------------------+-----------------------------------+
2657 | **3** | the context factory, in this case |
2658 | | from JBOSS (it requires the |
2659 | | dependency |
2660 | | org.jboss:jboss-remote-naming:2.0 |
2661 | | .4.Final |
2662 | | or a different version to be in |
2663 | | the directory ``$APEX_HOME/lib`` |
2664 | | or ``%APEX_HOME%\lib`` |
2665 +-----------------------------------+-----------------------------------+
2666 | **4** | a connection factory for the JMS |
2667 | | connection |
2668 +-----------------------------------+-----------------------------------+
2669 | **5** | URL with host and port of the JMS |
2670 | | provider |
2671 +-----------------------------------+-----------------------------------+
2672 | **6** | access credentials, user name |
2673 +-----------------------------------+-----------------------------------+
2674 | **7** | access credentials, user password |
2675 +-----------------------------------+-----------------------------------+
2676 | **8** | the JMS topic to write to |
2677 +-----------------------------------+-----------------------------------+
2678 | **9** | set object messaging to ``false`` |
2679 | | means it sends JSON text |
2680 +-----------------------------------+-----------------------------------+
2681
2682JMS Output with Object
2683======================
2684
2685 .. container:: paragraph
2686
2687 To configure APEX for JMS objects on the output
2688 interface use the same configuration as above (for
2689 output). Simply change the ``objectMessageSending``
2690 parameter to ``true``.
2691
2692Websocket (WS) IO
2693########################
2694
2695 .. container:: paragraph
2696
2697 APEX supports the Websockets as input as well as output.
2698 WS IO is supported by the APEX Websocket plugin. This
2699 carrier technology does only support uni-directional
2700 communication. APEX will not send events to a Websocket
2701 input and any event sent to a Websocket output will
2702 result in an error log.
2703
2704 .. container:: paragraph
2705
2706 The input can be configured as client (APEX connects to
2707 an existing Websocket server) or server (APEX starts a
2708 Websocket server). The same applies to the output. Input
2709 and output can both use a client or a server
2710 configuration, or separate configurations (input as
2711 client and output as server, input as server and output
2712 as client). Each configuration should use its own
2713 dedicated port to avoid any communication loops. The
2714 configuration of a Websocket client is the same for input
2715 and output. The configuration of a Websocket server is
2716 the same for input and output.
2717
2718Websocket Client
2719================
2720
2721 .. container:: paragraph
2722
2723 APEX will connect to a given Websocket server. As
2724 input, it will receive events from the server but not
2725 send any events. As output, it will send events to the
2726 server and any event received from the server will
2727 result in an error log.
2728
2729 .. container:: listingblock
2730
2731 .. container:: content
2732
ramverma760cce92019-07-11 12:57:49 +00002733 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002734
2735 "carrierTechnologyParameters" : {
2736 "carrierTechnology" : "WEBSOCKET", (1)
2737 "parameterClassName" :
2738 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2739 "parameters" : {
2740 "host" : "localhost", (2)
2741 "port" : 42451 (3)
2742 }
2743 }
2744
2745 .. container:: colist arabic
2746
2747 +-------+------------------------------------------------------+
2748 | **1** | set Websocket as carrier technology |
2749 +-------+------------------------------------------------------+
2750 | **2** | the host name on which a Websocket server is running |
2751 +-------+------------------------------------------------------+
2752 | **3** | the port of that Websocket server |
2753 +-------+------------------------------------------------------+
2754
2755Websocket Server
2756================
2757
2758 .. container:: paragraph
2759
2760 APEX will start a Websocket server, which will accept
2761 any Websocket clients to connect. As input, it will
2762 receive events from the server but not send any
2763 events. As output, it will send events to the server
2764 and any event received from the server will result in
2765 an error log.
2766
2767 .. container:: listingblock
2768
2769 .. container:: content
2770
ramverma760cce92019-07-11 12:57:49 +00002771 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002772
2773 "carrierTechnologyParameters" : {
2774 "carrierTechnology" : "WEBSOCKET", (1)
2775 "parameterClassName" :
2776 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2777 "parameters" : {
2778 "wsClient" : false, (2)
2779 "port" : 42450 (3)
2780 }
2781 }
2782
2783 .. container:: colist arabic
2784
2785 +-------+------------------------------------------------------------+
2786 | **1** | set Websocket as carrier technology |
2787 +-------+------------------------------------------------------------+
2788 | **2** | disable client, so that APEX will start a Websocket server |
2789 +-------+------------------------------------------------------------+
2790 | **3** | the port for the Websocket server APEX will start |
2791 +-------+------------------------------------------------------------+
2792
2793REST Client IO
2794##############
2795
2796 .. container:: paragraph
2797
2798 APEX can act as REST client on the input as well as on
2799 the output interface. The media type is
2800 ``application/json``, so this plugin does only work with
2801 the JSON Event protocol.
2802
2803REST Client Input
2804=================
2805
2806 .. container:: paragraph
2807
2808 APEX will connect to a given URL to receive events,
2809 but not send any events. The server is polled, i.e.
2810 APEX will do an HTTP GET, take the result, and then do
2811 the next GET. Any required timing needs to be handled
2812 by the server configured via the URL. For instance,
2813 the server could support a wait timeout via the URL as
2814 ``?timeout=100ms``.
Henry.Sun2941bc02019-07-22 08:32:32 +00002815 The httpCodeFilter is used for filtering the status
2816 code, and it can be configured as a regular expression
2817 string. The default httpCodeFilter is "[2][0-9][0-9]"
2818 - for successful response codes.
2819 The response with HTTP status code that matches the
2820 given regular expression is forwarded to the task,
2821 otherwise it is logged as a failure.
ramverma3b71c972019-07-10 11:25:37 +00002822
2823 .. container:: listingblock
2824
2825 .. container:: content
2826
ramverma760cce92019-07-11 12:57:49 +00002827 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002828
2829 "carrierTechnologyParameters" : {
2830 "carrierTechnology" : "RESTCLIENT", (1)
2831 "parameterClassName" :
2832 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2833 "parameters" : {
2834 "url" : "http://example.org:8080/triggers/events", (2)
Henry.Sun2941bc02019-07-22 08:32:32 +00002835 "httpCodeFilter" : "[2][0-9][0-9]" (3)
ramverma3b71c972019-07-10 11:25:37 +00002836 }
2837 }
2838
2839 .. container:: colist arabic
2840
Henry.Sun2941bc02019-07-22 08:32:32 +00002841 +-------+--------------------------------------------------+
2842 | **1** | set REST client as carrier technology |
2843 +-------+--------------------------------------------------+
2844 | **2** | the URL of the HTTP server for events |
2845 +-------+--------------------------------------------------+
2846 | **3** | use HTTP CODE FILTER for filtering status code |
2847 +-------+--------------------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +00002848
2849REST Client Output
2850==================
2851
2852 .. container:: paragraph
2853
2854 APEX will connect to a given URL to send events, but
2855 not receive any events. The default HTTP operation is
2856 POST (no configuration required). To change it to PUT
2857 simply add the configuration parameter (as shown in
2858 the example below).
ning.xi8bc537d2019-07-18 07:50:10 +00002859 The URL can be configured statically or tagged
2860 as ``?example.{site}.org:8080/{trig}/events``,
2861 all tags such as ``site`` and ``trig`` in the URL
Henry.Sun2941bc02019-07-22 08:32:32 +00002862 need to be set in the properties object available to
2863 the tasks. In addition, the keys should exactly match
2864 with the tags defined in url. The scope of the properties
2865 object is per HTTP call. Hence, key/value pairs set
2866 in the properties object by task are only available
2867 for that specific HTTP call.
ramverma3b71c972019-07-10 11:25:37 +00002868
2869 .. container:: listingblock
2870
2871 .. container:: content
2872
ramverma760cce92019-07-11 12:57:49 +00002873 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002874
2875 "carrierTechnologyParameters" : {
2876 "carrierTechnology" : "RESTCLIENT", (1)
2877 "parameterClassName" :
2878 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2879 "parameters" : {
2880 "url" : "http://example.com:8888/actions/events", (2)
ning.xi8bc537d2019-07-18 07:50:10 +00002881 "url" : "http://example.{site}.com:8888/{trig}/events", (2')
ramverma3b71c972019-07-10 11:25:37 +00002882 "httpMethod" : "PUT" (3)
2883 }
2884 }
2885
2886 .. container:: colist arabic
2887
2888 +-------+--------------------------------------------------+
2889 | **1** | set REST client as carrier technology |
2890 +-------+--------------------------------------------------+
ning.xi8bc537d2019-07-18 07:50:10 +00002891 | **2** | the static URL of the HTTP server for events |
2892 +-------+--------------------------------------------------+
2893 | **2'**| the tagged URL of the HTTP server for events |
ramverma3b71c972019-07-10 11:25:37 +00002894 +-------+--------------------------------------------------+
2895 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
2896 +-------+--------------------------------------------------+
2897
2898REST Server IO
2899##############
2900
2901 .. container:: paragraph
2902
2903 APEX supports a REST server for input and output.
2904
2905 .. container:: paragraph
2906
2907 The REST server plugin always uses a synchronous mode. A
2908 client does a HTTP GET on the APEX REST server with the
2909 input event and receives the generated output event in
2910 the server reply. This means that for the REST server
2911 there has to always to be an input with an associated
2912 output. Input or output only are not permitted.
2913
2914 .. container:: paragraph
2915
2916 The plugin will start a Grizzly server as REST server for
2917 a normal APEX engine. If the APEX engine is executed as a
2918 servlet, for instance inside Tomcat, then Tomcat will be
2919 used as REST server (this case requires configuration on
2920 Tomcat as well).
2921
2922 .. container:: paragraph
2923
2924 Some configuration restrictions apply for all scenarios:
2925
2926 .. container:: ulist
2927
2928 - Minimum port: 1024
2929
2930 - Maximum port: 65535
2931
2932 - The media type is ``application/json``, so this plugin
2933 does only work with the JSON Event protocol.
2934
2935 .. container:: paragraph
2936
2937 The URL the client calls is created using
2938
2939 .. container:: ulist
2940
2941 - the configured host and port, e.g.
2942 ``http://localhost:12345``
2943
2944 - the standard path, e.g. ``/apex/``
2945
2946 - the name of the input/output, e.g. ``FirstConsumer/``
2947
2948 - the input or output name, e.g. ``EventIn``.
2949
2950 .. container:: paragraph
2951
2952 The examples above lead to the URL
2953 ``http://localhost:12345/apex/FirstConsumer/EventIn``.
2954
2955 .. container:: paragraph
2956
2957 A client can also get status information of the REST
2958 server using ``/Status``, e.g.
2959 ``http://localhost:12345/apex/FirstConsumer/Status``.
2960
2961REST Server Stand-alone
2962=======================
2963
2964 .. container:: paragraph
2965
2966 We need to configure a REST server input and a REST
2967 server output. Input and output are associated with
2968 each other via there name.
2969
2970 .. container:: paragraph
2971
2972 Timeouts for REST calls need to be set carefully. If
2973 they are too short, the call might timeout before a
2974 policy finished creating an event.
2975
2976 .. container:: paragraph
2977
2978 The following example configures the input named as
2979 ``MyConsumer`` and associates an output named
2980 ``MyProducer`` with it.
2981
2982 .. container:: listingblock
2983
2984 .. container:: content
2985
ramverma760cce92019-07-11 12:57:49 +00002986 .. code::
ramverma3b71c972019-07-10 11:25:37 +00002987
2988 "eventInputParameters": {
2989 "MyConsumer": {
2990 "carrierTechnologyParameters" : {
2991 "carrierTechnology" : "RESTSERVER", (1)
2992 "parameterClassName" :
2993 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters",
2994 "parameters" : {
2995 "standalone" : true, (2)
2996 "host" : "localhost", (3)
2997 "port" : 12345 (4)
2998 }
2999 },
3000 "eventProtocolParameters":{
3001 "eventProtocol" : "JSON" (5)
3002 },
3003 "synchronousMode" : true, (6)
3004 "synchronousPeer" : "MyProducer", (7)
3005 "synchronousTimeout" : 500 (8)
3006 }
3007 }
3008
3009 .. container:: colist arabic
3010
3011 +-------+---------------------------------------+
3012 | **1** | set REST server as carrier technology |
3013 +-------+---------------------------------------+
3014 | **2** | set the server as stand-alone |
3015 +-------+---------------------------------------+
3016 | **3** | set the server host |
3017 +-------+---------------------------------------+
3018 | **4** | set the server listen port |
3019 +-------+---------------------------------------+
3020 | **5** | use JSON event protocol |
3021 +-------+---------------------------------------+
3022 | **6** | activate synchronous mode |
3023 +-------+---------------------------------------+
3024 | **7** | associate an output ``MyProducer`` |
3025 +-------+---------------------------------------+
3026 | **8** | set a timeout of 500 milliseconds |
3027 +-------+---------------------------------------+
3028
3029 .. container:: paragraph
3030
3031 The following example configures the output named as
3032 ``MyProducer`` and associates the input ``MyConsumer``
3033 with it. Note that for the output there are no more
3034 paramters (such as host or port), since they are
3035 already configured in the associated input
3036
3037 .. container:: listingblock
3038
3039 .. container:: content
3040
ramverma760cce92019-07-11 12:57:49 +00003041 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003042
3043 "eventOutputParameters": {
3044 "MyProducer": {
3045 "carrierTechnologyParameters":{
3046 "carrierTechnology" : "RESTSERVER",
3047 "parameterClassName" :
3048 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters"
3049 },
3050 "eventProtocolParameters":{
3051 "eventProtocol" : "JSON"
3052 },
3053 "synchronousMode" : true,
3054 "synchronousPeer" : "MyConsumer",
3055 "synchronousTimeout" : 500
3056 }
3057 }
3058
3059REST Server Stand-alone, multi input
3060====================================
3061
3062 .. container:: paragraph
3063
3064 Any number of input/output pairs for REST servers can
3065 be configured. For instance, we can configure an input
3066 ``FirstConsumer`` with output ``FirstProducer`` and an
3067 input ``SecondConsumer`` with output
3068 ``SecondProducer``. Important is that there is always
3069 one pair of input/output.
3070
3071REST Server Stand-alone in Servlet
3072==================================
3073
3074 .. container:: paragraph
3075
3076 If APEX is executed as a servlet, e.g. inside Tomcat,
3077 the configuration becomes easier since the plugin can
3078 now use Tomcat as the REST server. In this scenario,
3079 there are not parameters (port, host, etc.) and the
3080 key ``standalone`` must not be used (or set to false).
3081
3082 .. container:: paragraph
3083
3084 For the Tomcat configuration, we need to add the REST
3085 server plugin, e.g.
3086
3087 .. container:: listingblock
3088
3089 .. container:: content
3090
ramverma760cce92019-07-11 12:57:49 +00003091 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003092
3093 <servlet>
3094 ...
3095 <init-param>
3096 ...
3097 <param-value>org.onap.policy.apex.plugins.event.carrier.restserver</param-value>
3098 </init-param>
3099 ...
3100 </servlet>
3101
3102REST Requestor IO
3103##################
3104
3105 .. container:: paragraph
3106
3107 APEX can act as REST requestor on the input as well as on
3108 the output interface. The media type is
3109 ``application/json``, so this plugin does only work with
3110 the JSON Event protocol.
3111
3112REST Requestor Input
3113====================
3114
3115 .. container:: paragraph
3116
3117 APEX will connect to a given URL to request an input.
ning.xi8bc537d2019-07-18 07:50:10 +00003118 The URL can be configured statically or tagged
3119 as ``?example.{site}.org:8080/{trig}/events``,
3120 all tags such as ``site`` and ``trig`` in the URL
Henry.Sun2941bc02019-07-22 08:32:32 +00003121 need to be set in the properties object available to
3122 the tasks. In addition, the keys should exactly match
3123 with the tags defined in url. The scope of the properties
3124 object is per HTTP call. Hence, key/value pairs set
3125 in the properties object by task are only available
3126 for that specific HTTP call.
3127 The httpCodeFilter is used for filtering the status
3128 code, and it can be configured as a regular expression
3129 string. The default httpCodeFilter is "[2][0-9][0-9]"
3130 - for successful response codes.
3131 The response with HTTP status code that matches the
3132 given regular expression is forwarded to the task,
3133 otherwise it is logged as a failure.
ramverma3b71c972019-07-10 11:25:37 +00003134
3135 .. container:: listingblock
3136
3137 .. container:: content
3138
ramverma760cce92019-07-11 12:57:49 +00003139 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003140
3141 "carrierTechnologyParameters": {
3142 "carrierTechnology": "RESTREQUESTOR", (1)
3143 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters",
3144 "parameters": {
3145 "url": "http://localhost:54321/some/path/to/rest/resource", (2)
ning.xi8bc537d2019-07-18 07:50:10 +00003146 "url": "http://localhost:54321/{site}/path/to/rest/{resValue}", (2')
ramverma3b71c972019-07-10 11:25:37 +00003147 "httpMethod": "POST", (3)
Henry.Sun2941bc02019-07-22 08:32:32 +00003148 "restRequestTimeout": 2000, (4)
3149 "httpCodeFilter" : "[2][0-9][0-9]" (5)
ramverma3b71c972019-07-10 11:25:37 +00003150 }
3151 },
3152
3153 .. container:: colist arabic
3154
3155 +-------+--------------------------------------------------+
3156 | **1** | set REST requestor as carrier technology |
3157 +-------+--------------------------------------------------+
ning.xi8bc537d2019-07-18 07:50:10 +00003158 | **2** | the static URL of the HTTP server for events |
3159 +-------+--------------------------------------------------+
3160 | **2'**| the tagged URL of the HTTP server for events |
ramverma3b71c972019-07-10 11:25:37 +00003161 +-------+--------------------------------------------------+
3162 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
3163 +-------+--------------------------------------------------+
3164 | **4** | request timeout in milliseconds |
3165 +-------+--------------------------------------------------+
Henry.Sun2941bc02019-07-22 08:32:32 +00003166 | **5** | use HTTP CODE FILTER for filtering status code |
3167 +-------+--------------------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +00003168
3169 .. container:: paragraph
3170
3171 Further settings are required on the consumer to
3172 define the event that is requested, for example:
3173
3174 .. container:: listingblock
3175
3176 .. container:: content
3177
ramverma760cce92019-07-11 12:57:49 +00003178 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003179
3180 "eventName": "GuardResponseEvent", (1)
3181 "eventNameFilter": "GuardResponseEvent", (2)
3182 "requestorMode": true, (3)
3183 "requestorPeer": "GuardRequestorProducer", (4)
3184 "requestorTimeout": 500 (5)
3185
3186 .. container:: colist arabic
3187
3188 +-------+---------------------------+
3189 | **1** | the event name |
3190 +-------+---------------------------+
3191 | **2** | a filter on the event |
3192 +-------+---------------------------+
3193 | **3** | the mode of the requestor |
3194 +-------+---------------------------+
3195 | **4** | a peer for the requestor |
3196 +-------+---------------------------+
3197 | **5** | a general request timeout |
3198 +-------+---------------------------+
3199
3200REST Requestor Output
3201=====================
3202
3203 .. container:: paragraph
3204
3205 APEX will connect to a given URL to send events, but
3206 not receive any events.
3207
3208 .. container:: listingblock
3209
3210 .. container:: content
3211
ramverma760cce92019-07-11 12:57:49 +00003212 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003213
3214 "carrierTechnologyParameters": {
3215 "carrierTechnology": "RESTREQUESTOR", (1)
3216 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters"
3217 },
3218
3219 .. container:: colist arabic
3220
3221 +-------+------------------------------------------+
3222 | **1** | set REST requestor as carrier technology |
3223 +-------+------------------------------------------+
3224
3225 .. container:: paragraph
3226
3227 Further settings are required on the consumer to
3228 define the event that is requested, for example:
3229
3230 .. container:: listingblock
3231
3232 .. container:: content
3233
ramverma760cce92019-07-11 12:57:49 +00003234 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003235
3236 "eventNameFilter": "GuardRequestEvent", (1)
3237 "requestorMode": true, (2)
3238 "requestorPeer": "GuardRequestorConsumer", (3)
3239 "requestorTimeout": 500 (4)
3240
3241 .. container:: colist arabic
3242
3243 +-------+---------------------------+
3244 | **1** | a filter on the event |
3245 +-------+---------------------------+
3246 | **2** | the mode of the requestor |
3247 +-------+---------------------------+
3248 | **3** | a peer for the requestor |
3249 +-------+---------------------------+
3250 | **4** | a general request timeout |
3251 +-------+---------------------------+
3252
3253Event Protocols, Format and Encoding
3254------------------------------------
3255
3256 .. container:: paragraph
3257
3258 Event protocols define what event formats APEX can receive
3259 (input) and should send (output). They can be used in any
3260 combination for input and output, unless further restricted
3261 by a carrier technology plugin (for instance for JMS
3262 output). There can only be 1 event protocol per event
3263 plugin.
3264
3265 .. container:: paragraph
3266
3267 Supported *input* event protocols are:
3268
3269 .. container:: ulist
3270
3271 - JSON, the event as a JSON string
3272
3273 - APEX, an APEX event
3274
3275 - JMS object, the event as a JMS object,
3276
3277 - JMS text, the event as a JMS text,
3278
3279 - XML, the event as an XML string,
3280
3281 - YAML, the event as YAML text
3282
3283 .. container:: paragraph
3284
3285 Supported *output* event protocols are:
3286
3287 .. container:: ulist
3288
3289 - JSON, the event as a JSON string
3290
3291 - APEX, an APEX event
3292
3293 - JMS object, the event as a JMS object,
3294
3295 - JMS text, the event as a JMS text,
3296
3297 - XML, the event as an XML string,
3298
3299 - YAML, the event as YAML text
3300
3301 .. container:: paragraph
3302
3303 New event protocols can be added as plugins to APEX or
3304 developed outside APEX and added to an APEX deployment.
3305
3306JSON Event
3307##########
3308
3309 .. container:: paragraph
3310
3311 The event protocol for JSON encoding does not require a
3312 specific plugin, it is supported by default. Furthermore,
3313 there is no difference in the configuration for the input
3314 and output interface.
3315
3316 .. container:: paragraph
3317
3318 For an input, APEX requires a well-formed JSON string.
3319 Well-formed here means according to the definitions of a
3320 policy. Any JSON string that is not defined as a trigger
3321 event (consume) will not be consumed (errors will be
3322 thrown). For output JSON events, APEX will always produce
3323 valid JSON strings according to the definition in the
3324 policy model.
3325
3326 .. container:: paragraph
3327
3328 The following JSON shows the configuration.
3329
3330 .. container:: listingblock
3331
3332 .. container:: content
3333
ramverma760cce92019-07-11 12:57:49 +00003334 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003335
3336 "eventProtocolParameters":{
3337 "eventProtocol" : "JSON"
3338 }
3339
3340 .. container:: paragraph
3341
3342 For JSON events, there are a few more optional
3343 parameters, which allow to define a mapping for standard
3344 event fields. An APEX event must have the fields
3345 ``name``, ``version``, ``source``, and ``target``
3346 defined. Sometimes it is not possible to configure a
3347 trigger or actioning system to use those fields. However,
3348 they might be in an event generated outside APEX (or used
3349 outside APEX) just with different names. To configure
3350 APEX to map between the different event names, simply add
3351 the following parameters to a JSON event:
3352
3353 .. container:: listingblock
3354
3355 .. container:: content
3356
ramverma760cce92019-07-11 12:57:49 +00003357 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003358
3359 "eventProtocolParameters":{
3360 "eventProtocol" : "JSON",
3361 "nameAlias" : "policyName", (1)
3362 "versionAlias" : "policyVersion", (2)
3363 "sourceAlias" : "from", (3)
3364 "targetAlias" : "to", (4)
3365 "nameSpaceAlias": "my.name.space" (5)
3366 }
3367
3368 .. container:: colist arabic
3369
3370 +-----------------------------------+-----------------------------------+
3371 | **1** | mapping for the ``name`` field, |
3372 | | here from a field called |
3373 | | ``policyName`` |
3374 +-----------------------------------+-----------------------------------+
3375 | **2** | mapping for the ``version`` |
3376 | | field, here from a field called |
3377 | | ``policyVersion`` |
3378 +-----------------------------------+-----------------------------------+
3379 | **3** | mapping for the ``source`` field, |
3380 | | here from a field called ``from`` |
3381 | | (only for an input event) |
3382 +-----------------------------------+-----------------------------------+
3383 | **4** | mapping for the ``target`` field, |
3384 | | here from a field called ``to`` |
3385 | | (only for an output event) |
3386 +-----------------------------------+-----------------------------------+
3387 | **5** | mapping for the ``nameSpace`` |
3388 | | field, here from a field called |
3389 | | ``my.name.space`` |
3390 +-----------------------------------+-----------------------------------+
3391
3392APEX Event
3393##########
3394 .. container:: paragraph
3395
3396 The event protocol for APEX events does not require a
3397 specific plugin, it is supported by default. Furthermore,
3398 there is no difference in the configuration for the input
3399 and output interface.
3400
3401 .. container:: paragraph
3402
3403 For input and output APEX uses APEX events.
3404
3405 .. container:: paragraph
3406
3407 The following JSON shows the configuration.
3408
3409 .. container:: listingblock
3410
3411 .. container:: content
3412
ramverma760cce92019-07-11 12:57:49 +00003413 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003414
3415 "eventProtocolParameters":{
3416 "eventProtocol" : "APEX"
3417 }
3418
3419JMS Event
3420#########
3421
3422 .. container:: paragraph
3423
3424 The event protocol for JMS is provided by the APEX JMS
3425 plugin. The plugin supports encoding as JSON text or as
3426 object. There is no difference in the configuration for
3427 the input and output interface.
3428
3429JMS Text
3430========
3431 .. container:: paragraph
3432
3433 If used as input, APEX will take a JMS message and
3434 extract a JSON string, then proceed as if a JSON event
3435 was received. If used as output, APEX will take the
3436 event produced by a policy, create a JSON string, and
3437 then wrap it into a JMS message.
3438
3439 .. container:: paragraph
3440
3441 The configuration for JMS text is as follows:
3442
3443 .. container:: listingblock
3444
3445 .. container:: content
3446
ramverma760cce92019-07-11 12:57:49 +00003447 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003448
3449 "eventProtocolParameters":{
3450 "eventProtocol" : "JMSTEXT",
3451 "parameterClassName" :
3452 "org.onap.policy.apex.plugins.event.protocol.jms.JMSTextEventProtocolParameters"
3453 }
3454
3455JMS Object
3456==========
3457 .. container:: paragraph
3458
3459 If used as input, APEX will will take a JMS message,
3460 extract a Java Bean from the ``ObjectMessage``
3461 message, construct an APEX event and put the bean on
3462 the APEX event as a parameter. If used as output, APEX
3463 will take the event produced by a policy, create a
3464 Java Bean and send it as a JMS message.
3465
3466 .. container:: paragraph
3467
3468 The configuration for JMS object is as follows:
3469
3470 .. container:: listingblock
3471
3472 .. container:: content
3473
ramverma760cce92019-07-11 12:57:49 +00003474 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003475
3476 "eventProtocolParameters":{
3477 "eventProtocol" : "JMSOBJECT",
3478 "parameterClassName" :
3479 "org.onap.policy.apex.plugins.event.protocol.jms.JMSObjectEventProtocolParameters"
3480 }
3481
3482YAML Event
3483##########
3484
3485 .. container:: paragraph
3486
3487 The event protocol for YAML is provided by the APEX YAML
3488 plugin. There is no difference in the configuration for
3489 the input and output interface.
3490
3491 .. container:: paragraph
3492
3493 If used as input, APEX will consume events as YAML and
3494 map them to policy trigger events. Not well-formed YAML
3495 and not understood trigger events will be rejected. If
3496 used as output, APEX produce YAML encoded events from the
3497 event a policy produces. Those events will always be
3498 well-formed according to the definition in the policy
3499 model.
3500
3501 .. container:: paragraph
3502
3503 The following code shows the configuration.
3504
3505 .. container:: listingblock
3506
3507 .. container:: content
3508
ramverma760cce92019-07-11 12:57:49 +00003509 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003510
3511 "eventProtocolParameters":{
3512 "eventProtocol" : "XML",
3513 "parameterClassName" :
3514 "org.onap.policy.apex.plugins.event.protocol.yaml.YamlEventProtocolParameters"
3515 }
3516
3517XML Event
3518#########
3519 .. container:: paragraph
3520
3521 The event protocol for XML is provided by the APEX XML
3522 plugin. There is no difference in the configuration for
3523 the input and output interface.
3524
3525 .. container:: paragraph
3526
3527 If used as input, APEX will consume events as XML and map
3528 them to policy trigger events. Not well-formed XML and
3529 not understood trigger events will be rejected. If used
3530 as output, APEX produce XML encoded events from the event
3531 a policy produces. Those events will always be
3532 well-formed according to the definition in the policy
3533 model.
3534
3535 .. container:: paragraph
3536
3537 The following code shows the configuration.
3538
3539 .. container:: listingblock
3540
3541 .. container:: content
3542
ramverma760cce92019-07-11 12:57:49 +00003543 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003544
3545 "eventProtocolParameters":{
3546 "eventProtocol" : "XML",
3547 "parameterClassName" :
3548 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3549 }
3550
3551A configuration example
3552-----------------------
3553
3554 .. container:: paragraph
3555
3556 The following example loads all available plug-ins.
3557
3558 .. container:: paragraph
3559
3560 Events are consumed from a Websocket, APEX as client.
3561 Consumed event format is JSON.
3562
3563 .. container:: paragraph
3564
3565 Events are produced to Kafka. Produced event format is XML.
3566
3567 .. container:: listingblock
3568
3569 .. container:: content
3570
ramverma760cce92019-07-11 12:57:49 +00003571 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003572
3573 {
3574 "engineServiceParameters" : {
3575 "name" : "MyApexEngine",
3576 "version" : "0.0.1",
3577 "id" : 45,
3578 "instanceCount" : 4,
3579 "deploymentPort" : 12345,
3580 "policyModelFileName" : "examples/models/some-model.json",
3581 "engineParameters" : {
3582 "executorParameters" : {
3583 "JAVASCRIPT" : {
3584 "parameterClassName" :
3585 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
3586 },
3587 "JYTHON" : {
3588 "parameterClassName" :
3589 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
3590 },
3591 "JRUBY" : {
3592 "parameterClassName" :
3593 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
3594 },
3595 "JAVA" : {
3596 "parameterClassName" :
3597 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
3598 },
3599 "MVEL" : {
3600 "parameterClassName" :
3601 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
3602 }
3603 },
3604 "contextParameters" : {
3605 "parameterClassName" :
3606 "org.onap.policy.apex.context.parameters.ContextParameters",
3607 "schemaParameters" : {
3608 "Avro":{
3609 "parameterClassName" :
3610 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
3611 }
3612 }
3613 }
3614 }
3615 },
3616 "producerCarrierTechnologyParameters" : {
3617 "carrierTechnology" : "KAFKA",
3618 "parameterClassName" :
3619 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
3620 "parameters" : {
3621 "bootstrapServers" : "localhost:49092",
3622 "acks" : "all",
3623 "retries" : 0,
3624 "batchSize" : 16384,
3625 "lingerTime" : 1,
3626 "bufferMemory" : 33554432,
3627 "producerTopic" : "apex-out",
3628 "keySerializer" : "org.apache.kafka.common.serialization.StringSerializer",
3629 "valueSerializer" : "org.apache.kafka.common.serialization.StringSerializer"
3630 }
3631 },
3632 "producerEventProtocolParameters" : {
3633 "eventProtocol" : "XML",
3634 "parameterClassName" :
3635 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3636 },
3637 "consumerCarrierTechnologyParameters" : {
3638 "carrierTechnology" : "WEBSOCKET",
3639 "parameterClassName" :
3640 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
3641 "parameters" : {
3642 "host" : "localhost",
3643 "port" : 88888
3644 }
3645 },
3646 "consumerEventProtocolParameters" : {
3647 "eventProtocol" : "JSON"
3648 }
3649 }
3650
3651Engine and Applications of the APEX System
3652^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3653
3654Introduction to APEX Engine and Applications
3655--------------------------------------------
3656
3657 .. container:: paragraph
3658
3659 The core of APEX is the APEX Engine, also known as the APEX
3660 Policy Engine or the APEX PDP (since it is in fact a Policy
3661 Decision Point). Beside this engine, an APEX system comes
3662 with a few applications intended to help with policy
3663 authoring, deployment, and execution.
3664
3665 .. container:: paragraph
3666
3667 The engine itself and most applications are started from the
3668 command line with command line arguments. This is called a
3669 Command Line Interface (CLI). Some applications require an
3670 installation on a webserver, as for instance the REST
3671 Editor. Those applications can be accessed via a web
3672 browser.
3673
3674 .. container:: paragraph
3675
3676 You can also use the available APEX APIs and applications to
3677 develop other applications as required. This includes policy
3678 languages (and associated parsers and compilers /
3679 interpreters), GUIs to access APEX or to define policies,
3680 clients to connect to APEX, etc.
3681
3682 .. container:: paragraph
3683
3684 For this documentation, we assume an installation of APEX as
3685 a full system based on a current ONAP release.
3686
3687CLI on Unix, Windows, and Cygwin
3688--------------------------------
3689
3690 .. container:: paragraph
3691
3692 A note on APEX CLI applications: all applications and the
3693 engine itself have been deployed and tested on different
3694 operating systems: Red Hat, Ubuntu, Debian, Mac OSX,
3695 Windows, Cygwin. Each operating system comes with its own
3696 way of configuring and executing Java. The main items here
3697 are:
3698
3699 .. container:: ulist
3700
3701 - For UNIX systems (RHL, Ubuntu, Debian, Mac OSX), the
3702 provided bash scripts work as expected with absolute
3703 paths (e.g.
3704 ``/opt/app/policy/apex-pdp/apex-pdp-2.0.0-SNAPSHOT/examples``),
3705 indirect and linked paths (e.g. ``../apex/apex``), and
3706 path substitutions using environment settings (e.g.
3707 ``$APEX_HOME/bin/``)
3708
3709 - For Windows systems, the provided batch files (``.bat``)
3710 work as expected with with absolute paths (e.g.
3711 ``C:\apex\apex-2.0.0-SNAPSHOT\examples``), and path
3712 substitutions using environment settings (e.g.
3713 ``%APEX_HOME%\bin\``)
3714
3715 - For Cygwin system we assume a standard Cygwin
3716 installation with standard tools (mainly bash) using a
3717 Windows Java installation. This means that the bash
3718 scripts can be used as in UNIX, however any argument
3719 pointing to files and directories need to use either a
3720 DOS path (e.g.
3721 ``C:\apex\apex-2.0.0-SNAPSHOT\examples\config...``) or
3722 the command ``cygpath`` with a mixed option. The reason
3723 for that is: Cygwin executes Java using UNIX paths but
3724 then runs Java as a DOS/WINDOWS process, which requires
3725 DOS paths for file access.
3726
3727The APEX Engine
3728---------------
3729
3730 .. container:: paragraph
3731
3732 The APEX engine can be started in different ways, depending
3733 your requirements. All scripts are located in the APEX *bin*
3734 directory
3735
3736 .. container:: paragraph
3737
3738 On UNIX and Cygwin systems use:
3739
3740 .. container:: ulist
3741
3742 - ``apexEngine.sh`` - this script will
3743
3744 .. container:: ulist
3745
3746 - Test if ``$APEX_USER`` is set and if the user
3747 exists, terminate with an error otherwise
3748
3749 - Test if ``$APEX_HOME`` is set. If not set, it will
3750 use the default setting as
3751 ``/opt/app/policy/apex-pdp/apex-pdp``. Then the set
3752 directory is tested to exist, the script will
3753 terminate if not.
3754
3755 - When all tests are passed successfully, the script
3756 will call ``apexApps.sh`` with arguments to start
3757 the APEX engine.
3758
3759 - ``apexApps.sh engine`` - this is the general APEX
3760 application launcher, which will
3761
3762 .. container:: ulist
3763
3764 - Start the engine with the argument ``engine``
3765
3766 - Test if ``$APEX_HOME`` is set and points to an
3767 existing directory. If not set or directory does
3768 not exist, script terminates.
3769
3770 - Not test for any settings of ``$APEX_USER``.
3771
3772 .. container:: paragraph
3773
3774 On Windows systems use ``apexEngine.bat`` and
3775 ``apexApps.bat engine`` respectively. Note: none of the
3776 windows batch files will test for ``%APEX_USER%``.
3777
3778 .. container:: paragraph
3779
3780 Summary of alternatives to start the APEX Engine:
3781
3782 +--------------------------------------------------------+----------------------------------------------------------+
3783 | Unix, Cygwin | Windows |
3784 +========================================================+==========================================================+
3785 | .. container:: | .. container:: |
3786 | | |
3787 | .. container:: listingblock | .. container:: listingblock |
3788 | | |
3789 | .. container:: content | .. container:: content |
3790 | | |
3791 | .. code:: | .. code:: |
3792 | | |
3793 | # $APEX_HOME/bin/apexEngine.sh [args] | > %APEX_HOME%\bin\apexEngine.bat [args] |
3794 | # $APEX_HOME/bin/apexApps.sh engine [args] | > %APEX_HOME%\bin\apexApps.bat engine [args] |
3795 +--------------------------------------------------------+----------------------------------------------------------+
3796
3797 .. container:: paragraph
3798
3799 The APEX engine comes with a few CLI arguments for setting
3800 configuration and policy model. The configuration file is
3801 always required. The policy model file is only required if
3802 no model file is specified in the configuration, or if the
3803 specified model file should be over written. The option
3804 ``-h`` prints a help screen.
3805
3806 .. container:: listingblock
3807
3808 .. container:: content
3809
ramverma760cce92019-07-11 12:57:49 +00003810 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003811
3812 usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]
3813 options
3814 -c,--config-file <CONFIG_FILE> the full path to the configuration file to use, the configuration file must be a Json file
3815 containing the Apex configuration parameters
3816 -h,--help outputs the usage of this command
3817 -m,--model-file <MODEL_FILE> the full path to the model file to use, if set it overrides the model file set in the
3818 configuration file
3819 -v,--version outputs the version of Apex
3820
3821The APEX CLI Editor
3822-------------------
3823
3824 .. container:: paragraph
3825
3826 The CLI Editor allows to define policies from the command
3827 line. The application uses a simple language and supports
3828 all elements of an APEX policy. It can be used in to
3829 different ways:
3830
3831 .. container:: ulist
3832
3833 - non-interactive, specifying a file with the commands to
3834 create a policy
3835
3836 - interactive, using the editors CLI to create a policy
3837
3838 .. container:: paragraph
3839
3840 When a policy is fully specified, the editor will generate
3841 the APEX core policy specification in JSON. This core
3842 specification is called the policy model in the APEX engine
3843 and can be used directly with the APEX engine.
3844
3845 .. container:: paragraph
3846
3847 On UNIX and Cygwin systems use:
3848
3849 .. container:: ulist
3850
3851 - ``apexCLIEditor.sh`` - simply starts the CLI editor,
3852 arguments to the script determine the mode of the editor
3853
3854 - ``apexApps.sh cli-editor`` - simply starts the CLI
3855 editor, arguments to the script determine the mode of the
3856 editor
3857
3858 .. container:: paragraph
3859
3860 On Windows systems use:
3861
3862 .. container:: ulist
3863
3864 - ``apexCLIEditor.bat`` - simply starts the CLI editor,
3865 arguments to the script determine the mode of the editor
3866
3867 - ``apexApps.bat cli-editor`` - simply starts the CLI
3868 editor, arguments to the script determine the mode of the
3869 editor
3870
3871 .. container:: paragraph
3872
3873 Summary of alternatives to start the APEX CLI Editor:
3874
3875 +------------------------------------------------------------+--------------------------------------------------------------+
3876 | Unix, Cygwin | Windows |
3877 +============================================================+==============================================================+
3878 | .. container:: | .. container:: |
3879 | | |
3880 | .. container:: listingblock | .. container:: listingblock |
3881 | | |
3882 | .. container:: content | .. container:: content |
3883 | | |
3884 | .. code:: | .. code:: |
3885 | | |
3886 | # $APEX_HOME/bin/apexCLIEditor.sh.sh [args] | > %APEX_HOME%\bin\apexCLIEditor.bat [args] |
3887 | # $APEX_HOME/bin/apexApps.sh cli-editor [args] | > %APEX_HOME%\bin\apexApps.bat cli-editor [args] |
3888 +------------------------------------------------------------+--------------------------------------------------------------+
3889
3890 .. container:: paragraph
3891
3892 The option ``-h`` provides a help screen with all command
3893 line arguments.
3894
3895 .. container:: listingblock
3896
3897 .. container:: content
3898
ramverma760cce92019-07-11 12:57:49 +00003899 .. code::
ramverma3b71c972019-07-10 11:25:37 +00003900
3901 usage: org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain [options...]
3902 options
3903 -a,--model-props-file <MODEL_PROPS_FILE> name of the apex model properties file to use
3904 -c,--command-file <COMMAND_FILE> name of a file containing editor commands to run into the editor
3905 -h,--help outputs the usage of this command
3906 -i,--input-model-file <INPUT_MODEL_FILE> name of a file that contains an input model for the editor
3907 -if,--ignore-failures <IGNORE_FAILURES_FLAG> true or false, ignore failures of commands in command files and continue
3908 executing the command file
3909 -l,--log-file <LOG_FILE> name of a file that will contain command logs from the editor, will log
3910 to standard output if not specified or suppressed with "-nl" flag
3911 -m,--metadata-file <CMD_METADATA_FILE> name of the command metadata file to use
3912 -nl,--no-log if specified, no logging or output of commands to standard output or log
3913 file is carried out
3914 -nm,--no-model-output if specified, no output of a model to standard output or model output
3915 file is carried out, the user can use the "save" command in a script to
3916 save a model
3917 -o,--output-model-file <OUTPUT_MODEL_FILE> name of a file that will contain the output model for the editor, will
3918 output model to standard output if not specified or suppressed with
3919 "-nm" flag
3920 -wd,--working-directory <WORKING_DIRECTORY> the working directory that is the root for the CLI editor and is the
3921 root from which to look for included macro files
3922
a.sreekumar717a24a2019-07-26 13:47:42 +00003923The APEX CLI Tosca Editor
3924-------------------------
3925
3926 .. container:: paragraph
3927
3928 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.
3929
3930 .. container:: paragraph
3931
3932 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.
3933
3934 .. container:: paragraph
3935
3936 On UNIX and Cygwin systems use:
3937
3938 .. container:: ulist
3939
3940 - ``apexCLIToscaEditor.sh`` - starts the CLI Tosca editor,
3941 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3942
3943 - ``apexApps.sh cli-tosca-editor`` - starts the CLI Tosca editor,
3944 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3945
3946 .. container:: paragraph
3947
3948 On Windows systems use:
3949
3950 .. container:: ulist
3951
3952 - ``apexCLIToscaEditor.bat`` - starts the CLI Tosca editor,
3953 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3954
3955 - ``apexApps.bat cli-tosca-editor`` - starts the CLI Tosca
3956 editor, all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3957
3958 .. container:: paragraph
3959
3960 Summary of alternatives to start the APEX CLI Tosca Editor:
3961
3962 +-----------------------------------------------------------------+--------------------------------------------------------------------+
3963 | Unix, Cygwin | Windows |
3964 +=================================================================+====================================================================+
3965 | .. container:: | .. container:: |
3966 | | |
3967 | .. container:: listingblock | .. container:: listingblock |
3968 | | |
3969 | .. container:: content | .. container:: content |
3970 | | |
3971 | .. code:: | .. code:: |
3972 | | |
3973 | # $APEX_HOME/bin/apexCLIToscaEditor.sh.sh [args] | > %APEX_HOME%\bin\apexCLIToscaEditor.bat [args] |
3974 | # $APEX_HOME/bin/apexApps.sh cli-tosca-editor [args]| > %APEX_HOME%\bin\apexApps.bat cli-tosca-editor [args] |
3975 +-----------------------------------------------------------------+--------------------------------------------------------------------+
3976
3977 .. container:: paragraph
3978
3979 The option ``-h`` provides a help screen with all command
3980 line arguments.
3981
3982 .. container:: listingblock
3983
3984 .. container:: content
3985
3986 .. code::
3987
3988 usage: org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain [options...]
3989 options
3990 -a,--model-props-file <MODEL_PROPS_FILE> name of the apex model properties file to use
3991 -ac,--apex-config-file <APEX_CONFIG_FILE> name of the file containing apex configuration details
3992 -c,--command-file <COMMAND_FILE> name of a file containing editor commands to run into the editor
3993 -h,--help outputs the usage of this command
3994 -i,--input-model-file <INPUT_MODEL_FILE> name of a file that contains an input model for the editor
3995 -if,--ignore-failures <IGNORE_FAILURES_FLAG> true or false, ignore failures of commands in command files and
3996 continue executing the command file
3997 -l,--log-file <LOG_FILE> name of a file that will contain command logs from the editor, will
3998 log to standard output if not specified or suppressed with "-nl" flag
3999 -m,--metadata-file <CMD_METADATA_FILE> name of the command metadata file to use
4000 -nl,--no-log if specified, no logging or output of commands to standard output or
4001 log file is carried out
4002 -ot,--output-tosca-file <OUTPUT_TOSCA_FILE> name of a file that will contain the output ToscaServiceTemplate
4003 -t,--tosca-template-file <TOSCA_TEMPLATE_FILE> name of the input file containing tosca template which needs to be
4004 updated with policy
4005 -wd,--working-directory <WORKING_DIRECTORY> the working directory that is the root for the CLI editor and is the
4006 root from which to look for included macro files
4007
4008 .. container:: paragraph
4009
4010 An example command to run the APEX CLI Tosca editor on windows machine is given below.
4011
4012 .. container:: listingblock
4013
4014 .. container:: content
4015
4016 .. code::
4017
4018 %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
4019
ramverma3b71c972019-07-10 11:25:37 +00004020The APEX REST Editor
4021--------------------
4022
4023 .. container:: paragraph
4024
4025 The standard way to use the APEX REST Editor is via an
4026 installation of the *war* file on a webserver. However, the
4027 REST editor can also be started via command line. This will
4028 start a Grizzly webserver with the *war* deployed. Access to
4029 the REST Editor is then via the provided URL
4030
4031 .. container:: paragraph
4032
4033 On UNIX and Cygwin systems use:
4034
4035 .. container:: ulist
4036
4037 - ``apexRESTEditor.sh`` - simply starts the webserver with
4038 the REST editor
4039
4040 - ``apexApps.sh rest-editor`` - simply starts the webserver
4041 with the REST editor
4042
4043 .. container:: paragraph
4044
4045 On Windows systems use:
4046
4047 .. container:: ulist
4048
4049 - ``apexRESTEditor.bat`` - simply starts the webserver with
4050 the REST editor
4051
4052 - ``apexApps.bat rest-editor`` - simply starts the
4053 webserver with the REST editor
4054
4055 .. container:: paragraph
4056
4057 Summary of alternatives to start the APEX REST Editor:
4058
4059 +-------------------------------------------------------------+---------------------------------------------------------------+
4060 | Unix, Cygwin | Windows |
4061 +=============================================================+===============================================================+
4062 | .. container:: | .. container:: |
4063 | | |
4064 | .. container:: listingblock | .. container:: listingblock |
4065 | | |
4066 | .. container:: content | .. container:: content |
4067 | | |
4068 | .. code:: | .. code:: |
4069 | | |
4070 | # $APEX_HOME/bin/apexRESTEditor.sh.sh [args] | > %APEX_HOME%\bin\apexRESTEditor.bat [args] |
4071 | # $APEX_HOME/bin/apexApps.sh rest-editor [args] | > %APEX_HOME%\bin\apexApps.bat rest-editor [args] |
4072 +-------------------------------------------------------------+---------------------------------------------------------------+
4073
4074 .. container:: paragraph
4075
4076 The option ``-h`` provides a help screen with all command
4077 line arguments.
4078
4079 .. container:: listingblock
4080
4081 .. container:: content
4082
ramverma760cce92019-07-11 12:57:49 +00004083 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004084
4085 usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]
4086 -h,--help outputs the usage of this command
4087 -l,--listen <ADDRESS> the IP address to listen on. Default value is localhost to restrict access to the
4088 local machine only.
4089 -p,--port <PORT> port to use for the Apex RESTful editor REST calls.
4090 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating. Default
4091 value is -1 to run indefinitely.
4092
4093 .. container:: paragraph
4094
4095 If the REST Editor is started without any arguments the
4096 final messages will look similar to this:
4097
4098 .. container:: listingblock
4099
4100 .. container:: content
4101
ramverma760cce92019-07-11 12:57:49 +00004102 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004103
4104 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4105 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.NetworkListener start
4106 INFO: Started listener bound to [localhost:18989]
4107 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.HttpServer start
4108 INFO: [HttpServer] Started.
4109 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4110
4111 .. container:: paragraph
4112
4113 The last line states the URL on which the REST Editor can be
4114 accessed. The example above stated
4115 ``http://0.0.0.0:18989/apex/``. In a web browser use the URL
4116 ``http://localhost:18989`` and the REST Editor will start.
4117
4118The APEX Monitoring Client
4119--------------------------
4120
4121 .. container:: paragraph
4122
4123 The standard way to use the APEX Monitoring Client is via an
4124 installation of the *war* file on a webserver. However, the
4125 Monitoring Client can also be started via command line. This
4126 will start a Grizzly webserver with the *war* deployed.
4127 Access to the Monitoring Client is then via the provided URL
4128
4129 .. container:: paragraph
4130
4131 On UNIX and Cygwin systems use:
4132
4133 .. container:: ulist
4134
4135 - ``apexApps.sh eng-monitoring`` - simply starts the
4136 webserver with the Monitoring Client
4137
4138 .. container:: paragraph
4139
4140 On Windows systems use:
4141
4142 .. container:: ulist
4143
4144 - ``apexApps.bat eng-monitoring`` - simply starts the
4145 webserver with the Monitoring Client
4146
4147 .. container:: paragraph
4148
4149 The option ``-h`` provides a help screen with all command
4150 line arguments.
4151
4152 .. container:: listingblock
4153
4154 .. container:: content
4155
ramverma760cce92019-07-11 12:57:49 +00004156 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004157
4158 usage: org.onap.policy.apex.client.monitoring.rest.ApexMonitoringRestMain [options...]
4159 -h,--help outputs the usage of this command
4160 -p,--port <PORT> port to use for the Apex Services REST calls
4161 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4162
4163 .. container:: paragraph
4164
4165 If the Monitoring Client is started without any arguments
4166 the final messages will look similar to this:
4167
4168 .. container:: listingblock
4169
4170 .. container:: content
4171
ramverma760cce92019-07-11 12:57:49 +00004172 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004173
4174 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4175 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.NetworkListener start
4176 INFO: Started listener bound to [localhost:18989]
4177 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.HttpServer start
4178 INFO: [HttpServer] Started.
4179 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4180
4181 .. container:: paragraph
4182
4183 The last line states the URL on which the Monitoring Client
4184 can be accessed. The example above stated
4185 ``http://localhost:18989/apexservices``. In a web browser
4186 use the URL ``http://localhost:18989``.
4187
4188The APEX Deployment Client
4189--------------------------
4190
4191 .. container:: paragraph
4192
4193 The standard way to use the APEX Deployment Client is via an
4194 installation of the *war* file on a webserver. However, the
4195 Deployment Client can also be started via command line. This
4196 will start a Grizzly webserver with the *war* deployed.
4197 Access to the Deployment Client is then via the provided URL
4198
4199 .. container:: paragraph
4200
4201 On UNIX and Cygwin systems use:
4202
4203 .. container:: ulist
4204
4205 - ``apexApps.sh eng-deployment`` - simply starts the
4206 webserver with the Deployment Client
4207
4208 .. container:: paragraph
4209
4210 On Windows systems use:
4211
4212 .. container:: ulist
4213
4214 - ``apexApps.bat eng-deployment`` - simply starts the
4215 webserver with the Deployment Client
4216
4217 .. container:: paragraph
4218
4219 The option ``-h`` provides a help screen with all command
4220 line arguments.
4221
4222 .. container:: listingblock
4223
4224 .. container:: content
4225
ramverma760cce92019-07-11 12:57:49 +00004226 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004227
4228 usage: org.onap.policy.apex.client.deployment.rest.ApexDeploymentRestMain [options...]
4229 -h,--help outputs the usage of this command
4230 -p,--port <PORT> port to use for the Apex Services REST calls
4231 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4232
4233 .. container:: paragraph
4234
4235 If the Deployment Client is started without any arguments
4236 the final messages will look similar to this:
4237
4238 .. container:: listingblock
4239
4240 .. container:: content
4241
ramverma760cce92019-07-11 12:57:49 +00004242 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004243
4244 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4245 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.NetworkListener start
4246 INFO: Started listener bound to [localhost:18989]
4247 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.HttpServer start
4248 INFO: [HttpServer] Started.
4249 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4250
4251 .. container:: paragraph
4252
4253 The last line states the URL on which the Deployment Client
4254 can be accessed. The example above stated
4255 ``http://localhost:18989/apexservices``. In a web browser
4256 use the URL ``http://localhost:18989``.
4257
4258The APEX Full Client
4259--------------------
4260
4261 .. container:: paragraph
4262
4263 The APEX Full Client combines the REST Editor, the
4264 Monitoring Client, and the Deployment Client into a single
4265 application. The standard way to use the APEX Full Client is
4266 via an installation of the *war* file on a webserver.
4267 However, the Full Client can also be started via command
4268 line. This will start a Grizzly webserver with the *war*
4269 deployed. Access to the Full Client is then via the provided
4270 URL
4271
4272 .. container:: paragraph
4273
4274 On UNIX and Cygwin systems use:
4275
4276 .. container:: ulist
4277
4278 - ``apexApps.sh full-client`` - simply starts the webserver
4279 with the Full Client
4280
4281 .. container:: paragraph
4282
4283 On Windows systems use:
4284
4285 .. container:: ulist
4286
4287 - ``apexApps.bat full-client`` - simply starts the
4288 webserver with the Full Client
4289
4290 .. container:: paragraph
4291
4292 The option ``-h`` provides a help screen with all command
4293 line arguments.
4294
4295 .. container:: listingblock
4296
4297 .. container:: content
4298
ramverma760cce92019-07-11 12:57:49 +00004299 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004300
4301 usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4302 -h,--help outputs the usage of this command
4303 -p,--port <PORT> port to use for the Apex Services REST calls
4304 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4305
4306 .. container:: paragraph
4307
4308 If the Full Client is started without any arguments the
4309 final messages will look similar to this:
4310
4311 .. container:: listingblock
4312
4313 .. container:: content
4314
ramverma760cce92019-07-11 12:57:49 +00004315 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004316
4317 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4318 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4319 INFO: Started listener bound to [localhost:18989]
4320 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4321 INFO: [HttpServer] Started.
4322 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4323
4324 .. container:: paragraph
4325
4326 The last line states the URL on which the Monitoring Client
4327 can be accessed. The example above stated
4328 ``http://localhost:18989/apexservices``. In a web browser
4329 use the URL ``http://localhost:18989``.
4330
4331 The APEX Application Launcher
4332------------------------------
4333
4334 .. container:: paragraph
4335
4336 The standard applications (Engine, CLI Editor, REST Editor)
4337 come with dedicated start scripts. For all other APEX
4338 applications, we provide an application launcher.
4339
4340 .. container:: paragraph
4341
4342 On UNIX and Cygwin systems use:
4343
4344 .. container:: ulist
4345
4346 - apexApps.sh\` - simply starts the application launcher
4347
4348 .. container:: paragraph
4349
4350 On Windows systems use:
4351
4352 .. container:: ulist
4353
4354 - ``apexApps.bat`` - simply starts the application launcher
4355
4356 .. container:: paragraph
4357
4358 Summary of alternatives to start the APEX application
4359 launcher:
4360
4361 +-------------------------------------------------+---------------------------------------------------+
4362 | Unix, Cygwin | Windows |
4363 +=================================================+===================================================+
4364 | .. container:: | .. container:: |
4365 | | |
4366 | .. container:: listingblock | .. container:: listingblock |
4367 | | |
4368 | .. container:: content | .. container:: content |
4369 | | |
4370 | .. code:: | .. code:: |
4371 | | |
4372 | # $APEX_HOME/bin/apexApps.sh [args] | > %APEX_HOME%\bin\apexApps.bat [args] |
4373 +-------------------------------------------------+---------------------------------------------------+
4374
4375 .. container:: paragraph
4376
4377 The option ``-h`` provides a help screen with all launcher
4378 command line arguments.
4379
4380 .. container:: listingblock
4381
4382 .. container:: content
4383
ramverma760cce92019-07-11 12:57:49 +00004384 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004385
4386 apexApps.sh - runs APEX applications
4387
4388 Usage: apexApps.sh [options] | [<application> [<application options>]]
4389
4390 Options
4391 -d <app> - describes an application
4392 -l - lists all applications supported by this script
4393 -h - this help screen
4394
4395 .. container:: paragraph
4396
4397 Using ``-l`` lists all known application the launcher can
4398 start.
4399
4400 .. container:: listingblock
4401
4402 .. container:: content
4403
ramverma760cce92019-07-11 12:57:49 +00004404 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004405
4406 apexApps.sh: supported applications:
4407 --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4408
4409 .. container:: paragraph
4410
4411 Using the ``-d <name>`` option describes the named
4412 application, for instance for the ``ws-console``:
4413
4414 .. container:: listingblock
4415
4416 .. container:: content
4417
ramverma760cce92019-07-11 12:57:49 +00004418 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004419
4420 apexApps.sh: application 'ws-console'
4421 --> a simple console sending events to APEX, connect to APEX consumer port
4422
4423 .. container:: paragraph
4424
4425 Launching an application is done by calling the script with
4426 only the application name and any CLI arguments for the
4427 application. For instance, starting the ``ws-echo``
4428 application with port ``8888``:
4429
4430 .. container:: listingblock
4431
4432 .. container:: content
4433
ramverma760cce92019-07-11 12:57:49 +00004434 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004435
4436 apexApps.sh ws-echo -p 8888
4437
4438Application: Create Event Templates
4439-----------------------------------
4440
4441 .. container:: paragraph
4442
4443 **Status: Experimental**
4444
4445 .. container:: paragraph
4446
4447 This application takes a policy model (JSON or XML encoded)
4448 and generates templates for events in JSON format. This can
4449 help when a policy defines rather complex trigger or action
4450 events or complex events between states. The application can
4451 produce events for the types: stimuli (policy trigger
4452 events), internal (events between policy states), and
4453 response (action events).
4454
4455 +----------------------------------------------------------------+------------------------------------------------------------------+
4456 | Unix, Cygwin | Windows |
4457 +================================================================+==================================================================+
4458 | .. container:: | .. container:: |
4459 | | |
4460 | .. container:: listingblock | .. container:: listingblock |
4461 | | |
4462 | .. container:: content | .. container:: content |
4463 | | |
4464 | .. code:: | .. code:: |
4465 | | |
4466 | # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] | > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4467 +----------------------------------------------------------------+------------------------------------------------------------------+
4468
4469 .. container:: paragraph
4470
4471 The option ``-h`` provides a help screen.
4472
4473 .. container:: listingblock
4474
4475 .. container:: content
4476
ramverma760cce92019-07-11 12:57:49 +00004477 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004478
4479 gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4480 usage: gen-model2event
4481 -h,--help prints this help and usage screen
4482 -m,--model <MODEL-FILE> set the input policy model file
4483 -t,--type <TYPE> set the event type for generation, one of:
4484 stimuli (trigger events), response (action
4485 events), internal (events between states)
4486 -v,--version prints the application version
4487
4488 .. container:: paragraph
4489
4490 The created templates are not valid events, instead they use
4491 some markup for values one will need to change to actual
4492 values. For instance, running the tool with the *Sample
4493 Domain* policy model as:
4494
4495 .. container:: listingblock
4496
4497 .. container:: content
4498
ramverma760cce92019-07-11 12:57:49 +00004499 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004500
4501 apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4502
4503 .. container:: paragraph
4504
4505 will produce the following status messages:
4506
4507 .. container:: listingblock
4508
4509 .. container:: content
4510
ramverma760cce92019-07-11 12:57:49 +00004511 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004512
4513 gen-model2event: starting Event generator
4514 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4515 --> type: stimuli
4516
4517 .. container:: paragraph
4518
4519 and then run the generator application producing two event
4520 templates. The first template is called ``Event0000``.
4521
4522 .. container:: listingblock
4523
4524 .. container:: content
4525
4526 .. code::
4527
4528 {
4529 "name" : "Event0000",
4530 "nameSpace" : "org.onap.policy.apex.sample.events",
4531 "version" : "0.0.1",
4532 "source" : "Outside",
4533 "target" : "Match",
4534 "TestTemperature" : ###double: 0.0###,
4535 "TestTimestamp" : ###long: 0###,
4536 "TestMatchCase" : ###integer: 0###,
4537 "TestSlogan" : "###string###"
4538 }
4539
4540 .. container:: paragraph
4541
4542 The values for the keys are marked with ``#`` and the
4543 expected type of the value. To create an actual stimuli
4544 event, all these markers need to be change to actual values,
4545 for instance:
4546
4547 .. container:: listingblock
4548
4549 .. container:: content
4550
ramverma760cce92019-07-11 12:57:49 +00004551 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004552
4553 {
4554 "name" : "Event0000",
4555 "nameSpace" : "org.onap.policy.apex.sample.events",
4556 "version" : "0.0.1",
4557 "source" : "Outside",
4558 "target" : "Match",
4559 "TestTemperature" : 25,
4560 "TestTimestamp" : 123456789123456789,
4561 "TestMatchCase" : 1,
4562 "TestSlogan" : "Testing the Match Case with Temperature 25"
4563 }
4564
4565Application: Convert a Policy Model to CLI Editor Commands
4566----------------------------------------------------------
4567
4568 .. container:: paragraph
4569
4570 **Status: Experimental**
4571
4572 .. container:: paragraph
4573
4574 This application takes a policy model (JSON or XML encoded)
4575 and generates commands for the APEX CLI Editor. This
4576 effectively reverses a policy specification realized with
4577 the CLI Editor.
4578
4579 +-------------------------------------------------------------+---------------------------------------------------------------+
4580 | Unix, Cygwin | Windows |
4581 +=============================================================+===============================================================+
4582 | .. container:: | .. container:: |
4583 | | |
4584 | .. container:: listingblock | .. container:: listingblock |
4585 | | |
4586 | .. container:: content | .. container:: content |
4587 | | |
4588 | .. code:: | .. code:: |
4589 | | |
4590 | # $APEX_HOME/bin/apexApps.sh model-2-cli [args] | > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4591 +-------------------------------------------------------------+---------------------------------------------------------------+
4592
4593 .. container:: paragraph
4594
4595 The option ``-h`` provides a help screen.
4596
4597 .. container:: listingblock
4598
4599 .. container:: content
4600
ramverma760cce92019-07-11 12:57:49 +00004601 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004602
4603 usage: gen-model2cli
4604 -h,--help prints this help and usage screen
4605 -m,--model <MODEL-FILE> set the input policy model file
4606 -sv,--skip-validation switch of validation of the input file
4607 -v,--version prints the application version
4608
4609 .. container:: paragraph
4610
4611 For instance, running the tool with the *Sample Domain*
4612 policy model as:
4613
4614 .. container:: listingblock
4615
4616 .. container:: content
4617
ramverma760cce92019-07-11 12:57:49 +00004618 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004619
4620 apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4621
4622 .. container:: paragraph
4623
4624 will produce the following status messages:
4625
4626 .. container:: listingblock
4627
4628 .. container:: content
4629
ramverma760cce92019-07-11 12:57:49 +00004630 .. code::
ramverma3b71c972019-07-10 11:25:37 +00004631
4632 gen-model2cli: starting CLI generator
4633 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4634
4635 .. container:: paragraph
4636
4637 and then run the generator application producing all CLI
4638 Editor commands and printing them to standard out.
4639
4640Application: Websocket Clients (Echo and Console)
4641-------------------------------------------------
4642
4643 .. container:: paragraph
4644
4645 **Status: Production**
4646
4647 .. container:: paragraph
4648
4649 The application launcher also provides a Websocket echo
4650 client and a Websocket console client. The echo client
4651 connects to APEX and prints all events it receives from
4652 APEX. The console client connects to APEX, reads input from
4653 the command line, and sends this input as events to APEX.
4654
4655 +------------------------------------------------------------+--------------------------------------------------------------+
4656 | Unix, Cygwin | Windows |
4657 +============================================================+==============================================================+
4658 | .. container:: | .. container:: |
4659 | | |
4660 | .. container:: listingblock | .. container:: listingblock |
4661 | | |
4662 | .. container:: content | .. container:: content |
4663 | | |
4664 | .. code:: | .. code:: |
4665 | | |
4666 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
4667 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4668 +------------------------------------------------------------+--------------------------------------------------------------+
4669
4670 .. container:: paragraph
4671
4672 The arguments are the same for both applications:
4673
4674 .. container:: ulist
4675
4676 - ``-p`` defines the Websocket port to connect to (defaults
4677 to ``8887``)
4678
4679 - ``-s`` defines the host on which a Websocket server is
4680 running (defaults to ``localhost``)
4681
4682 .. container:: paragraph
4683
4684 A discussion on how to use these two applications to build
4685 an APEX system is detailed HowTo-Websockets.
4686
4687My First Policy
4688^^^^^^^^^^^^^^^
4689
4690Introduction
4691------------
4692 .. container:: paragraph
4693
4694 Consider a scenario where a supermarket chain called
4695 *HyperM* controls how it sells items in a policy-based
4696 manner. Each time an item is processed by *HyperM*'s
4697 point-of-sale (PoS) system an event is generated and
4698 published about that item of stock being sold. This event
4699 can then be used to update stock levels, etc..
4700
4701 .. container:: paragraph
4702
4703 *HyperM* want to extend this approach to allow some checks
4704 to be performed before the sale can be completed. This can
4705 be achieved by requesting a policy-controlled decision as
4706 each item is processed by for sale by each PoS system. The
4707 decision process is integrated with *HyperM*'s other IT
4708 systems that manage stock control, sourcing and purchasing,
4709 personnel systems, etc.
4710
4711 .. container:: paragraph
4712
4713 In this document we will show how APEX and APEX Policies can
4714 be used to achieve this, starting with a simple policy,
4715 building up to more complicated policy that demonstrates the
4716 features of APEX.
4717
4718Data Models
4719-----------
4720
4721Sales Input Event
4722#################
4723
4724 .. container:: paragraph
4725
4726 Each time a PoS system processes a sales item an event
4727 with the following format is emitted:
4728
4729 .. table:: Table 1. Sale Input Event
4730
4731 +----------------------+----------------------+-----------------------+
4732 | Event | Fields | Description |
4733 +======================+======================+=======================+
4734 | SALE_INPUT | time, sale_ID, | Event indicating a |
4735 | | amount, item_ID, | sale of an item is |
4736 | | quantity, | occurring |
4737 | | assistant_ID, | |
4738 | | branch_ID, notes, …​ | |
4739 +----------------------+----------------------+-----------------------+
4740
4741 .. container:: paragraph
4742
4743 In each ``SALE_INPUT`` event the ``sale_ID`` field is a
4744 unique ID generated by the PoS system. A timestamp for
4745 the event is stored in the ``time`` field. The ``amount``
4746 field refers to the value of the item(s) to be sold (in
4747 cents). The ``item_ID`` field is a unique identifier for
4748 each item type, and can be used to retrieve more
4749 information about the item from *HyperM*'s stock control
4750 system. The ``quantity`` field refers to the quantity of
4751 the item to be sold. The ``assistant_ID`` field is a
4752 unique identifier for the PoS operator, and can be used
4753 to retrieve more information about the operator from the
4754 *HyperM*'s personnel system. Since *HyperM* has many
4755 branches the ``branch_ID`` identifies the shop. The
4756 ``notes`` field contains arbitrary notes about the sale.
4757
4758Sales Decision Event
4759####################
4760
4761 .. container:: paragraph
4762
4763 After a ``SALE_INPUT`` event is emitted by the PoS system
4764 *HyperM*'s policy-based controlled sales checking system
4765 emits a Sale Authorization Event indicating whether the
4766 sale is authorized or denied. The PoS system can then
4767 listen for this event before continuing with the sale.
4768
4769 .. table:: Table 2. Sale Authorisation Event
4770
4771 +----------------------+----------------------+-----------------------+
4772 | Event | Fields | Description |
4773 +======================+======================+=======================+
4774 | SALE_AUTH | sale_ID, time, | Event indicating a |
4775 | | authorized, amount, | sale of an item is |
4776 | | item_ID, quantity, | authorized or denied |
4777 | | assistant_ID, | |
4778 | | branch_ID, notes, | |
4779 | | message…​ | |
4780 +----------------------+----------------------+-----------------------+
4781
4782 .. container:: paragraph
4783
4784 In each ``SALE_AUTH`` event the ``sale_ID`` field is
4785 copied from the ``SALE_INPUT`` event that trigger the
4786 decision request. The ``SALE_AUTH`` event is also
4787 timestamped using the ``time`` field, and a field called
4788 ``authorised`` is set to ``true`` or ``false`` depending
4789 on whether the sale is authorized or denied. The
4790 ``message`` field carries an optional message about why a
4791 sale was not authorized. The other fields from the
4792 ``SALE_INPUT`` event are also included for completeness.
4793
4794Stock Control: Items
4795####################
4796
4797 .. container:: paragraph
4798
4799 *HyperM* maintains information about each item for sale
4800 in a database table called ``ITEMS``.
4801
4802 .. table:: Table 3. Items Database
4803
4804 +----------------------+----------------------+-----------------------+
4805 | Table | Fields | Description |
4806 +======================+======================+=======================+
4807 | ITEMS | item_ID, | Database table |
4808 | | description, | describing each item |
4809 | | cost_price, barcode, | for sale |
4810 | | supplier_ID, | |
4811 | | category, …​ | |
4812 +----------------------+----------------------+-----------------------+
4813
4814 .. container:: paragraph
4815
4816 The database table ``ITEMS`` has a row for each items
4817 that *HyperM* sells. Each item is identified by an
4818 ``item_ID`` value. The ``description`` field stores a
4819 description of the item. The cost price of the item is
4820 given in ``cost_price``. The barcode of the item is
4821 encoded in ``barcode``, while the item supplier is
4822 identified by ``supplier_ID``. Items may also be
4823 classified into categories using the ``category`` field.
4824 Useful categories might include: ``soft drinks``,
4825 ``alcoholic drinks``, ``cigarettes``, ``knives``,
4826 ``confectionery``, ``bakery``, ``fruit&vegetables``,
4827 ``meat``, etc..
4828
4829Personnel System: Assistants
4830############################
4831
4832 .. table:: Table 4. Assistants Database
4833
4834 +----------------------+----------------------+-----------------------+
4835 | Table | Fields | Description |
4836 +======================+======================+=======================+
4837 | ASSISTANTS | assistant_ID, | Database table |
4838 | | surname, firstname, | describing each |
4839 | | middlename, age, | *HyperM* sales |
4840 | | grade, phone_number, | assistant |
4841 | | …​ | |
4842 +----------------------+----------------------+-----------------------+
4843
4844 .. container:: paragraph
4845
4846 The database table ``ASSISTANTS`` has a row for each
4847 sales assistant employed by *HyperM*. Each assistant is
4848 identified by an ``assistant_ID`` value, with their name
4849 given in the ``firstname``, ``middlename`` and
4850 ``surname`` fields. The assistant’s age in years is given
4851 in ``age``, while their phone number is contained in the
4852 ``phone_number`` field. The assistant’s grade is encoded
4853 in ``grade``. Useful values for ``grade`` might include:
4854 ``trainee``, ``operator``, ``supervisor``, etc..
4855
4856Locations: Branches
4857####################
4858
4859 .. table:: Table 5. Branches Database
4860
4861 +----------------------+----------------------+-----------------------+
4862 | Table | Fields | Description |
4863 +======================+======================+=======================+
4864 | BRANCHES | branch_ID, | Database table |
4865 | | branch_Name, | describing each |
4866 | | category, street, | *HyperM* branch |
4867 | | city, country, | |
4868 | | postcode, …​ | |
4869 +----------------------+----------------------+-----------------------+
4870
4871 .. container:: paragraph
4872
4873 *HyperM* operates a number of branches. Each branch is
4874 described in the ``BRANCHES`` database table. Each branch
4875 is identified by a ``branch_ID``, with a branch name
4876 given in ``branch_Name``. The address for the branch is
4877 encoded in ``street``, ``city``, ``country`` and
4878 ``postcode``. The branch category is given in the
4879 ``category`` field. Useful values for ``category`` might
4880 include: ``Small``, ``Large``, ``Super``, ``Hyper``,
4881 etc..
4882
4883Policy Step 1
4884-------------
4885
4886Scenario
4887#########
4888 .. container:: paragraph
4889
4890 For the first version of our policy, let’s start with
4891 something simple. Let us assume that there exists some
4892 restriction that alcohol products cannot be sold before
4893 11:30am. In this section we will go through the necessary
4894 steps to define a policy that can enforce this for
4895 *HyperM*.
4896
4897 .. container:: ulist
4898
4899 - Alcohol cannot be sold before 11:30am.
4900
4901Create the an new empty Policy Model ``MyFirstPolicyModel``
4902###########################################################
4903
4904 .. container:: paragraph
4905
4906 Since an organisation like *HyperM* may have many
4907 policies covering many different domains, policies should
4908 be grouped into policy sets. In order to edit or deploy a
4909 policy, or policy set, the definition of the policy(ies)
4910 and all required events, tasks, states, etc., are grouped
4911 together into a 'Policy Model'. An organization might
4912 define many Policy Models, each containing a different
4913 set of policies.
4914
4915 .. container:: paragraph
4916
4917 So the first step is to create a new empty Policy Model
4918 called ``MyFirstPolicyModel``. Using the APEX Policy
4919 Editor, click on the 'File' menus and select 'New'. Then
4920 define our new policy model called
4921 ``MyFirstPolicyModel``. Use the 'Generate UUID' button to
4922 create a new unique ID for the policy model, and fill in
4923 a description for the policy model. Press the ``Submit``
4924 button to save your changes.
4925
4926 .. container:: imageblock
4927
4928 .. container:: content
4929
4930 |File > New to create a new Policy Model|
4931
4932 .. container:: title
4933
4934 Figure 4. Create a new Policy Model 1/2
4935
4936 .. container:: imageblock
4937
4938 .. container:: content
4939
4940 |Create a new Policy Model|
4941
4942 .. container:: title
4943
4944 Figure 5. Create a new Policy Model 2/2
4945
4946Create the input event ``SALE_INPUT`` and the output event ``SALE_AUTH``
4947########################################################################
4948
4949 .. container:: paragraph
4950
4951 Using the APEX Policy Editor, click on the 'Events' tab.
4952 In the 'Events' pane, right click and select 'New':
4953
4954 .. container:: imageblock
4955
4956 .. container:: content
4957
4958 |Right click to create a new event|
4959
4960 .. container:: title
4961
4962 Figure 6. Create a new Event type
4963
4964 .. container:: paragraph
4965
4966 Create a new event type called ``SALE_INPUT``. Use the
4967 'Generate UUID' button to create a new unique ID for the
4968 event type, and fill in a description for the event. Add
4969 a namespace, e.g. ``com.hyperm``. We can add hard-coded
4970 strings for the ``Source`` and ``Target``, e.g. ``POS``
4971 and ``APEX``. At this stage we will not add any parameter
4972 fields, we will leave this until later. Use the
4973 ``Submit`` button to create the event.
4974
4975 .. container:: imageblock
4976
4977 .. container:: content
4978
4979 |Fill in the necessary information for the
4980 'SALE_INPUT' event and click 'Submit'|
4981
4982 .. container:: title
4983
4984 Figure 7. Populate the ``SALE_INPUT`` event
4985
4986 .. container:: paragraph
4987
4988 Repeat the same steps for a new event type called
4989 ``SALE_AUTH``. Just use ``APEX`` as source and ``POS`` as
4990 target, since this is the output event coming from APEX
4991 going to the sales point.
4992
4993 .. container:: paragraph
4994
4995 Before we can add parameter fields to an event we must
4996 first define APEX Context Item Schemas that can be used
4997 by those fields.
4998
4999 .. container:: paragraph
5000
5001 To create new item schemas, click on the 'Context Item
5002 Schemas' tab. In that 'Context Item Schemas' pane, right
5003 click and select 'Create new ContextSchema'.
5004
5005 .. container:: imageblock
5006
5007 .. container:: content
5008
5009 |Right click to create a new Item Schema|
5010
5011 .. container:: title
5012
5013 Figure 8. Create new Data Types
5014
5015 .. container:: paragraph
5016
5017 Create item schemas with the following characteristics,
5018 each with its own unique UUID:
5019
5020 .. table:: Table 6. Item Schemas
5021
5022 +-------------------+-----------------+-----------------+----------------------+
5023 | Name | Schema Flavour | Schema | Description |
5024 | | | Definition | |
5025 +===================+=================+=================+======================+
5026 | timestamp_type | Java | java.lang.Long | A type for |
5027 | | | | ``time`` values |
5028 +-------------------+-----------------+-----------------+----------------------+
5029 | sale_ID_type | Java | java.lang.Long | A type for |
5030 | | | | ``sale_ID`` |
5031 | | | | values |
5032 +-------------------+-----------------+-----------------+----------------------+
5033 | price_type | Java | java.lang.Long | A type for |
5034 | | | | ``amount``/``price`` |
5035 | | | | values |
5036 +-------------------+-----------------+-----------------+----------------------+
5037 | item_ID_type | Java | java.lang.Long | A type for |
5038 | | | | ``item_ID`` |
5039 | | | | values |
5040 +-------------------+-----------------+-----------------+----------------------+
5041 | assistant_ID_type | Java | java.lang.Long | A type for |
5042 | | | | ``assistant_ID`` |
5043 | | | | values |
5044 +-------------------+-----------------+-----------------+----------------------+
5045 | quantity_type | Java | java.lang.Integ | A type for |
5046 | | | er | ``quantity`` |
5047 | | | | values |
5048 +-------------------+-----------------+-----------------+----------------------+
5049 | branch_ID_type | Java | java.lang.Long | A type for |
5050 | | | | ``branch_ID`` |
5051 | | | | values |
5052 +-------------------+-----------------+-----------------+----------------------+
5053 | notes_type | Java | java.lang.Strin | A type for |
5054 | | | g | ``notes`` |
5055 | | | | values |
5056 +-------------------+-----------------+-----------------+----------------------+
5057 | authorised_type | Java | java.lang.Boole | A type for |
5058 | | | an | ``authorised`` |
5059 | | | | values |
5060 +-------------------+-----------------+-----------------+----------------------+
5061 | message_type | Java | java.lang.Strin | A type for |
5062 | | | g | ``message`` |
5063 | | | | values |
5064 +-------------------+-----------------+-----------------+----------------------+
5065
5066 .. container:: imageblock
5067
5068 .. container:: content
5069
5070 |Create a new Item Schema|
5071
5072 .. container:: title
5073
5074 Figure 9. Create new Item Schemas
5075
5076 .. container:: paragraph
5077
5078 The item schemas can now be seen on the 'Context Item
5079 Schemas' tab, and can be updated at any time by
5080 right-clicking on the item schemas on the 'Context Item
5081 Schemas' tab. Now we can go back to the event definitions
5082 for ``SALE_INPUT`` and ``SALE_AUTH`` and add some
5083 parameter fields.
5084
5085 .. tip
ramverma760cce92019-07-11 12:57:49 +00005086
5087 .. container:: title
5088
5089 Field Schema types
5090
5091 .. container:: paragraph
5092
5093 APEX natively supports schema definitions in ``Java`` and ``Avro``.
5094
5095 .. container:: paragraph
5096
5097 ``Java`` schema definitions are simply the name of a Java Class. There are some restrictions:
5098
5099 .. container:: ulist
5100
5101 - the class must be instantiatable, i.e. not an Java interface or abstract class
5102
5103 - primitive types are not supported, i.e. use ``java.lang.Integer`` instead of ``int``, etc.
5104
5105 - it must be possible to find the class, i.e. the class must be contained in the Java classpath.
5106
5107 .. container:: paragraph
5108
5109 ``Avro`` schema definitions can be any valid `Avro <https://avro.apache.org/docs/current/spec.html>`__
5110 schema. For events using fields defined with ``Avro`` schemas, any incoming event containing that field must
5111 contain a value that conforms to the Avro schema.
ramverma3b71c972019-07-10 11:25:37 +00005112
5113 .. container:: paragraph
5114
5115 Click on the 'Events' tab, then right click the
5116 ``SALE_INPUT`` row and select 'Edit Event
5117 :literal:`SALE_INPUT’. To add a new event parameter use the 'Add Event Parameter' button at the bottom of the screen. For the `SALE_INPUT`
5118 event add the following event parameters:
5119
5120 .. table:: Table 7. Event Parameter Fields for the ``SALE_INPUT`` Event
5121
5122 +----------------------+----------------------+-----------------------+
5123 | Parameter Name | Parameter Type | Optional |
5124 +======================+======================+=======================+
5125 | time | timestamp_type | no |
5126 +----------------------+----------------------+-----------------------+
5127 | sale_ID | sale_ID_type | no |
5128 +----------------------+----------------------+-----------------------+
5129 | amount | price_type | no |
5130 +----------------------+----------------------+-----------------------+
5131 | item_ID | item_ID_type | no |
5132 +----------------------+----------------------+-----------------------+
5133 | quantity | quantity_type | no |
5134 +----------------------+----------------------+-----------------------+
5135 | assistant_ID | assistant_ID_type | no |
5136 +----------------------+----------------------+-----------------------+
5137 | branch_ID | branch_ID_type | no |
5138 +----------------------+----------------------+-----------------------+
5139 | notes | notes_type | *yes* |
5140 +----------------------+----------------------+-----------------------+
5141
5142 .. container:: paragraph
5143
5144 Remember to click the 'Submit' button at the bottom of
5145 the event definition pane.
5146
5147 .. tip::
ramverma760cce92019-07-11 12:57:49 +00005148 Optional Fields in APEX Events
5149 Parameter fields can be *optional* in events. If a parameter is not marked as *optional* then by default it
5150 is *mandatory*, so it must appear in any input event passed to APEX. If an *optional* field is not set
5151 for an output event then value will be set to ``null``.
ramverma3b71c972019-07-10 11:25:37 +00005152
5153 .. container:: imageblock
5154
5155 .. container:: content
5156
5157 |Add new event parameters to an event|
5158
5159 .. container:: title
5160
5161 Figure 10. Add typed parameter fields to an event
5162
5163 .. container:: paragraph
5164
5165 Select the ``SALE_AUTH`` event and add the following
5166 event parameters:
5167
5168 .. table:: Table 8. Event Parameter Fields for the ``SALE_AUTH`` Event
5169
5170 +----------------------+----------------------+-----------------------+
5171 | Parameter Name | Parameter Type | no |
5172 +======================+======================+=======================+
5173 | sale_ID | sale_ID_type | no |
5174 +----------------------+----------------------+-----------------------+
5175 | time | timestamp_type | no |
5176 +----------------------+----------------------+-----------------------+
5177 | authorised | authorised_type | no |
5178 +----------------------+----------------------+-----------------------+
5179 | message | message_type | *yes* |
5180 +----------------------+----------------------+-----------------------+
5181 | amount | price_type | no |
5182 +----------------------+----------------------+-----------------------+
5183 | item_ID | item_ID_type | no |
5184 +----------------------+----------------------+-----------------------+
5185 | assistant_ID | assistant_ID_type | no |
5186 +----------------------+----------------------+-----------------------+
5187 | quantity | quantity_type | no |
5188 +----------------------+----------------------+-----------------------+
5189 | branch_ID | branch_ID_type | no |
5190 +----------------------+----------------------+-----------------------+
5191 | notes | notes_type | *yes* |
5192 +----------------------+----------------------+-----------------------+
5193
5194 .. container:: paragraph
5195
5196 Remember to click the 'Submit' button at the bottom of
5197 the event definition pane.
5198
5199 .. container:: paragraph
5200
5201 The events for our policy are now defined.
5202
5203Create a new Policy and add the *"No Booze before 11:30"* check
5204###############################################################
5205
5206 .. container:: paragraph
5207
5208 APEX policies are defined using a state-machine model.
5209 Each policy comprises one or more *states* that can be
5210 individually executed. Where there is more than one
5211 *state* the states are chained together to form a
5212 `Directed Acyclic Graph
5213 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__
5214 of states. A *state* is triggered by passing it a single
5215 input (or 'trigger') event and once executed each state
5216 then emits an output event. For each *state* the logic
5217 for the *state* is embedded in one or more *tasks*. Each
5218 *task* contains specific *task logic* that is executed by
5219 the APEX execution environment each time the *task* is
5220 invoked. Where there is more than one *task* in a *state*
5221 then the *state* also defines some *task selection logic*
5222 to select an appropriate task each time the *state* is
5223 executed.
5224
5225 .. container:: paragraph
5226
5227 Therefore, to create a new policy we must first define
5228 one or more tasks.
5229
5230 .. container:: paragraph
5231
5232 To create a new Task click on the 'Tasks' tab. In the
5233 'Tasks' pane, right click and select 'Create new Task'.
5234 Create a new Task called ``MorningBoozeCheck``. Use the
5235 'Generate UUID' button to create a new unique ID for the
5236 task, and fill in a description for the task.
5237
5238 .. container:: imageblock
5239
5240 .. container:: content
5241
5242 |Right click to create a new task|
5243
5244 .. container:: title
5245
5246 Figure 11. Create a new Task
5247
5248 .. container:: paragraph
5249
5250 Tasks are configured with a set of *input fields* and a
5251 set of *output fields*. To add new input/output fields
5252 for a task use the 'Add Task Input Field' and 'Add Task
5253 Output Field' button. The list of input and out fields to
5254 add for the ``MorningBoozeCheck`` task are given below.
5255 The input fields are drawn from the parameters in the
5256 state’s input event, and the task’s output fields are
5257 used to populate the state’s output event. The task’s
5258 input and output fields must be a subset of the event
5259 parameters defined for the input and output events for
5260 any state that uses that task. (You may have noticed that
5261 the input and output fields for the ``MorningBoozeCheck``
5262 task have the exact same names and reuse the item schemas
5263 that we used for the parameters in the ``SALE_INPUT`` and
5264 ``SALE_AUTH`` events respectively).
5265
5266 .. table:: Table 9. Input fields for ``MorningBoozeCheck`` task
5267
5268 +-----------------------------------+-----------------------------------+
5269 | Parameter Name | Parameter Type |
5270 +===================================+===================================+
5271 | time | timestamp_type |
5272 +-----------------------------------+-----------------------------------+
5273 | sale_ID | sale_ID_type |
5274 +-----------------------------------+-----------------------------------+
5275 | amount | price_type |
5276 +-----------------------------------+-----------------------------------+
5277 | item_ID | item_ID_type |
5278 +-----------------------------------+-----------------------------------+
5279 | quantity | quantity_type |
5280 +-----------------------------------+-----------------------------------+
5281 | assistant_ID | assistant_ID_type |
5282 +-----------------------------------+-----------------------------------+
5283 | branch_ID | branch_ID_type |
5284 +-----------------------------------+-----------------------------------+
5285 | notes | notes_type |
5286 +-----------------------------------+-----------------------------------+
5287
5288 .. table:: Table 10. Output fields for ``MorningBoozeCheck`` task
5289
5290 +-----------------------------------+-----------------------------------+
5291 | Parameter Name | Parameter Type |
5292 +===================================+===================================+
5293 | sale_ID | sale_ID_type |
5294 +-----------------------------------+-----------------------------------+
5295 | time | timestamp_type |
5296 +-----------------------------------+-----------------------------------+
5297 | authorised | authorised_type |
5298 +-----------------------------------+-----------------------------------+
5299 | message | message_type |
5300 +-----------------------------------+-----------------------------------+
5301 | amount | price_type |
5302 +-----------------------------------+-----------------------------------+
5303 | item_ID | item_ID_type |
5304 +-----------------------------------+-----------------------------------+
5305 | assistant_ID | assistant_ID_type |
5306 +-----------------------------------+-----------------------------------+
5307 | quantity | quantity_type |
5308 +-----------------------------------+-----------------------------------+
5309 | branch_ID | branch_ID_type |
5310 +-----------------------------------+-----------------------------------+
5311 | notes | notes_type |
5312 +-----------------------------------+-----------------------------------+
5313
5314 .. container:: imageblock
5315
5316 .. container:: content
5317
5318 |Add input and out fields for the task|
5319
5320 .. container:: title
5321
5322 Figure 12. Add input and out fields for the Task
5323
5324 .. container:: paragraph
5325
5326 Each task must include some 'Task Logic' that implements
5327 the behaviour for the task. Task logic can be defined in
5328 a number of different ways using a choice of languages.
5329 For this task we will author the logic using the
5330 Java-like scripting language called
5331 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__.
5332
5333 .. container:: paragraph
5334
5335 For simplicity use the following code for the task logic.
5336 Paste the script text into the 'Task Logic' box, and use
5337 "MVEL" as the 'Task Logic Type / Flavour'.
5338
5339 .. container:: paragraph
5340
5341 This logic assumes that all items with ``item_ID``
5342 between 1000 and 2000 contain alcohol, which is not very
5343 realistic, but we will see a better approach for this
5344 later. It also uses the standard ``Java`` time utilities
5345 to check if the current time is between ``00:00:00 GMT``
5346 and ``11:30:00 GMT``. For a detailed guide to how to
5347 write your own logic in
5348 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
5349 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
5350 of the other supported languages please refer to APEX
5351 Programmers Guide.
5352
5353 .. container:: listingblock
5354
5355 .. container:: title
5356
5357 MVEL code for the ``MorningBoozeCheck`` task
5358
5359 .. container:: content
5360
ramverma760cce92019-07-11 12:57:49 +00005361 .. code::
ramverma3b71c972019-07-10 11:25:37 +00005362
5363 /*
5364 * ============LICENSE_START=======================================================
5365 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5366 * ================================================================================
5367 * Licensed under the Apache License, Version 2.0 (the "License");
5368 * you may not use this file except in compliance with the License.
5369 * You may obtain a copy of the License at
5370 *
5371 * http://www.apache.org/licenses/LICENSE-2.0
5372 *
5373 * Unless required by applicable law or agreed to in writing, software
5374 * distributed under the License is distributed on an "AS IS" BASIS,
5375 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5376 * See the License for the specific language governing permissions and
5377 * limitations under the License.
5378 *
5379 * SPDX-License-Identifier: Apache-2.0
5380 * ============LICENSE_END=========================================================
5381 */
5382 import java.util.Date;
5383 import java.util.Calendar;
5384 import java.util.TimeZone;
5385 import java.text.SimpleDateFormat;
5386
5387 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
5388
5389 outFields.put("amount" , inFields.get("amount"));
5390 outFields.put("assistant_ID", inFields.get("assistant_ID"));
5391 outFields.put("notes" , inFields.get("notes"));
5392 outFields.put("quantity" , inFields.get("quantity"));
5393 outFields.put("branch_ID" , inFields.get("branch_ID"));
5394 outFields.put("item_ID" , inFields.get("item_ID"));
5395 outFields.put("time" , inFields.get("time"));
5396 outFields.put("sale_ID" , inFields.get("sale_ID"));
5397
5398 item_id = inFields.get("item_ID");
5399
5400 //The events used later to test this task use GMT timezone!
5401 gmt = TimeZone.getTimeZone("GMT");
5402 timenow = Calendar.getInstance(gmt);
5403 df = new SimpleDateFormat("HH:mm:ss z");
5404 df.setTimeZone(gmt);
5405 timenow.setTimeInMillis(inFields.get("time"));
5406
5407 midnight = timenow.clone();
5408 midnight.set(
5409 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5410 timenow.get(Calendar.DATE),0,0,0);
5411 eleven30 = timenow.clone();
5412 eleven30.set(
5413 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5414 timenow.get(Calendar.DATE),11,30,0);
5415
5416 itemisalcohol = false;
5417 if(item_id != null && item_id >=1000 && item_id < 2000)
5418 itemisalcohol = true;
5419
5420 if( itemisalcohol
5421 && timenow.after(midnight) && timenow.before(eleven30)){
5422 outFields.put("authorised", false);
5423 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
5424 " for time "+df.format(timenow.getTime())+
5425 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
5426 " and "+df.format(eleven30.getTime()));
5427 return true;
5428 }
5429 else{
5430 outFields.put("authorised", true);
5431 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
5432 " for time "+df.format(timenow.getTime()));
5433 return true;
5434 }
5435
5436 /*
5437 This task checks if a sale request is for an item that is an alcoholic drink.
5438 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5439 authorised. Otherwise the sale is authorised.
5440 In this implementation we assume that items with item_ID value between 1000 and
5441 2000 are all alcoholic drinks :-)
5442 */
5443
5444 .. container:: imageblock
5445
5446 .. container:: content
5447
5448 |Add task logic the task|
5449
5450 .. container:: title
5451
5452 Figure 13. Add Task Logic the Task
5453
5454 .. container:: paragraph
5455
5456 An alternative version of the same logic is available in
5457 JavaScript. Just use "JAVASCRIPT" as the 'Task Logic Type
5458 / Flavour' instead.
5459
5460 .. container:: listingblock
5461
5462 .. container:: title
5463
5464 Javascript alternative for the ``MorningBoozeCheck``
5465 task
5466
5467 .. container:: content
5468
ramverma760cce92019-07-11 12:57:49 +00005469 .. code::
ramverma3b71c972019-07-10 11:25:37 +00005470
5471 /*
5472 * ============LICENSE_START=======================================================
5473 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5474 * ================================================================================
5475 * Licensed under the Apache License, Version 2.0 (the "License");
5476 * you may not use this file except in compliance with the License.
5477 * You may obtain a copy of the License at
5478 *
5479 * http://www.apache.org/licenses/LICENSE-2.0
5480 *
5481 * Unless required by applicable law or agreed to in writing, software
5482 * distributed under the License is distributed on an "AS IS" BASIS,
5483 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5484 * See the License for the specific language governing permissions and
5485 * limitations under the License.
5486 *
5487 * SPDX-License-Identifier: Apache-2.0
5488 * ============LICENSE_END=========================================================
5489 */
5490
5491 var returnValueType = Java.type("java.lang.Boolean");
5492 var returnValue = new returnValueType(true);
5493
5494 // Load compatibility script for imports etc
5495 load("nashorn:mozilla_compat.js");
5496 importPackage(java.text);
5497 importClass(java.text.SimpleDateFormat);
5498
5499 executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'");
5500
5501 executor.outFields.put("amount" , executor.inFields.get("amount"));
5502 executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID"));
5503 executor.outFields.put("notes" , executor.inFields.get("notes"));
5504 executor.outFields.put("quantity" , executor.inFields.get("quantity"));
5505 executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID"));
5506 executor.outFields.put("item_ID" , executor.inFields.get("item_ID"));
5507 executor.outFields.put("time" , executor.inFields.get("time"));
5508 executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID"));
5509
5510 item_id = executor.inFields.get("item_ID");
5511
5512 //All times in this script are in GMT/UTC since the policy and events assume time is in GMT.
5513 var timenow_gmt = new Date(Number(executor.inFields.get("time")));
5514
5515 var midnight_gmt = new Date(Number(executor.inFields.get("time")));
5516 midnight_gmt.setUTCHours(0,0,0,0);
5517
5518 var eleven30_gmt = new Date(Number(executor.inFields.get("time")));
5519 eleven30_gmt.setUTCHours(11,30,0,0);
5520
5521 var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z");
5522
5523 var itemisalcohol = false;
5524 if(item_id != null && item_id >=1000 && item_id < 2000)
5525 itemisalcohol = true;
5526
5527 if( itemisalcohol
5528 && timenow_gmt.getTime() >= midnight_gmt.getTime()
5529 && timenow_gmt.getTime() < eleven30_gmt.getTime()) {
5530
5531 executor.outFields.put("authorised", false);
5532 executor.outFields.put("message", "Sale not authorised by policy task " +
5533 executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) +
5534 ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) +
5535 " and " + timeformatter.format(eleven30_gmt.getTime()));
5536 }
5537 else{
5538 executor.outFields.put("authorised", true);
5539 executor.outFields.put("message", "Sale authorised by policy task " +
5540 executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime()));
5541 }
5542
5543 /*
5544 This task checks if a sale request is for an item that is an alcoholic drink.
5545 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5546 authorised. Otherwise the sale is authorised.
5547 In this implementation we assume that items with item_ID value between 1000 and
5548 2000 are all alcoholic drinks :-)
5549 */
5550
5551 .. container:: paragraph
5552
5553 The task definition is now complete so click the 'Submit'
5554 button to save the task. The task can now be seen on the
5555 'Tasks' tab, and can be updated at any time by
5556 right-clicking on the task on the 'Task' tab. Now that we
5557 have created our task, we can can create a policy that
5558 uses that task.
5559
5560 .. container:: paragraph
5561
5562 To create a new Policy click on the 'Policies' tab. In
5563 the 'Policies' pane, right click and select 'Create new
5564 Policy':
5565
5566 .. container:: paragraph
5567
5568 Create a new Policy called ``MyFirstPolicy``. Use the
5569 'Generate UUID' button to create a new unique ID for the
5570 policy, and fill in a description for the policy. Use
5571 'FREEFORM' as the 'Policy Flavour'.
5572
5573 .. container:: paragraph
5574
5575 Each policy must have at least one state. Since this is
5576 'freeform' policy we can add as many states as we wish.
5577 Let’s start with one state. Add a new state called
5578 ``BoozeAuthDecide`` to this ``MyFirstPolicy`` policy
5579 using the 'Add new State' button after filling in the
5580 name of our new state.
5581
5582 .. container:: imageblock
5583
5584 .. container:: content
5585
5586 |Create a new policy|
5587
5588 .. container:: title
5589
5590 Figure 14. Create a new Policy
5591
5592 .. container:: paragraph
5593
5594 Each state must uses one input event type. For this new
5595 state select the ``SALE_INPUT`` event as the input event.
5596
5597 .. container:: paragraph
5598
5599 Each policy must define a 'First State' and a 'Policy
5600 Trigger Event'. The 'Policy Trigger Event' is the input
5601 event for the policy as a whole. This event is then
5602 passed to the first state in the chain of states in the
5603 policy, therefore the 'Policy Trigger Event' will be the
5604 input event for the first state. Each policy can only
5605 have one 'First State'. For our ``MyFirstPolicy`` policy,
5606 select ``BoozeAuthDecide`` as the 'First State'. This
5607 will automatically select ``SALE_INPUT`` as the 'Policy
5608 Trigger Event' for our policy.
5609
5610 .. container:: imageblock
5611
5612 .. container:: content
5613
5614 |Create a state|
5615
5616 .. container:: title
5617
5618 Figure 15. Create a new State
5619
5620 .. container:: paragraph
5621
5622 In this case we will create a reference the pre-existing
5623 ``MorningBoozeCheck`` task that we defined above using
5624 the 'Add New Task' button. Select the
5625 ``MorningBoozeCheck`` task, and use the name of the task
5626 as the 'Local Name' for the task.
5627
5628 .. container:: paragraph
5629
5630 in the case where a state references more than one task,
5631 a 'Default Task' must be selected for the state and some
5632 logic ('Task Selection Logic') must be specified to
5633 select the appropriate task at execution time. Since our
5634 new state ``BoozeAuthDecide`` only has one task the
5635 default task is automatically selected and no 'Task
5636 Selection Logic' is required.
5637
ramverma760cce92019-07-11 12:57:49 +00005638 .. note::
5639 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00005640
ramverma760cce92019-07-11 12:57:49 +00005641 State Output Mappings
ramverma3b71c972019-07-10 11:25:37 +00005642
ramverma760cce92019-07-11 12:57:49 +00005643 .. container:: paragraph
5644
5645 In a 'Policy' 'State' a 'State Output Mapping' has 3 roles:
5646 1) Select which 'State' should be executed next, 2) Select
5647 the type of the state’s 'Outgoing Event', and 3)
5648 Populate the state’s 'Outgoing Event'. This is how states are
5649 chained together to form a (`Directed Acyclic Graph
5650 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__ )
5651 of states. The final state(s) of a policy are those that do
5652 not select any 'next' state. Since a 'State' can only
5653 accept a single type of event, the type of the event emitted
5654 by a previous 'State' must be match the incoming event type
5655 of the next 'State'. This is also how the last state(s) in
5656 a policy can emit events of different types. The 'State
5657 Output Mapping' is also responsible for taking the
5658 fields that are output by the task executed in the state and
5659 populating the state’s output event before it is emitted.
5660
5661 .. container:: paragraph
5662
5663 Each 'Task' referenced in 'State' must have a defined
5664 'Output Mapping' to take the output of the task, select an
5665 'Outgoing Event' type for the state, populate the state’s
5666 outgoing event, and then select the next state to be
5667 executed (if any).
5668
5669 .. container:: paragraph
5670
5671 There are 2 basic types of output mappings:
5672
5673 .. container:: olist arabic
5674
5675 #. **Direct Output Mappings** have a single value for
5676 'Next State' and a single value for 'State Output
5677 Event'. The outgoing event for the state is
5678 automatically created, any outgoing event parameters
5679 that were present in the incoming event are copied
5680 into the outgoing event, then any task output fields
5681 that have the same name and type as parameters in the
5682 outgoing event are automatically copied into
5683 the outgoing event.
5684
5685 #. **Logic-based State Output Mappings / Finalizers**
5686 have some logic defined that dynamically selects
5687 and creates the 'State Outgoing Event', manages
5688 the population of the outgoing event parameters
5689 (perhaps changing or adding to the outputs from the
5690 task), and then dynamically selects the next state to
5691 be executed (if any).
ramverma3b71c972019-07-10 11:25:37 +00005692
5693 .. container:: paragraph
5694
5695 Each task reference must also have an associated 'Output
5696 State Mapping' so we need an 'Output State Mapping' for
5697 the ``BoozeAuthDecide`` state to use when the
5698 ``MorningBoozeCheck`` task is executed. The simplest type
5699 of output mapping is a 'Direct Output Mapping'.
5700
5701 .. container:: paragraph
5702
5703 Create a new 'Direct Output Mapping' for the state called
5704 ``MorningBoozeCheck_Output_Direct`` using the 'Add New
5705 Direct State Output Mapping' button. Select ``SALE_AUTH``
5706 as the output event and select ``None`` for the next
5707 state value. We can then select this output mapping for
5708 use when the the ``MorningBoozeCheck`` task is executed.
5709 Since there is only state, and only one task for that
5710 state, this output mapping ensures that the
5711 ``BoozeAuthDecide`` state is the only state executed and
5712 the state (and the policy) can only emit events of type
5713 ``SALE_AUTH``. (You may remember that the output fields
5714 for the ``MorningBoozeCheck`` task have the exact same
5715 names and reuse the item schemas that we used for the
5716 parameters in ``SALE_AUTH`` event. The
5717 ``MorningBoozeCheck_Output_Direct`` direct output mapping
5718 can now automatically copy the values from the
5719 ``MorningBoozeCheck`` task directly into outgoing
5720 ``SALE_AUTH`` events.)
5721
5722 .. container:: imageblock
5723
5724 .. container:: content
5725
5726 |Add a Task and Output Mapping|
5727
5728 .. container:: title
5729
5730 Figure 16. Add a Task and Output Mapping
5731
5732 .. container:: paragraph
5733
5734 Click the 'Submit' button to complete the definition of
5735 our ``MyFirstPolicy`` policy. The policy
5736 ``MyFirstPolicy`` can now be seen in the list of policies
5737 on the 'Policies' tab, and can be updated at any time by
5738 right-clicking on the policy on the 'Policies' tab.
5739
5740 .. container:: paragraph
5741
5742 The ``MyFirstPolicyModel``, including our
5743 ``MyFirstPolicy`` policy can now be checked for errors.
5744 Click on the 'Model' menu and select 'Validate'. The
5745 model should validate without any 'Warning' or 'Error'
5746 messages. If you see any 'Error' or 'Warning' messages,
5747 carefully read the message as a hint to find where you
5748 might have made a mistake when defining some aspect of
5749 your policy model.
5750
5751 .. container:: imageblock
5752
5753 .. container:: content
5754
5755 |Validate the policy model for error using the 'Model'
5756 > 'Validate' menu item|
5757
5758 .. container:: title
5759
5760 Figure 17. Validate a Policy Model
5761
5762 .. container:: paragraph
5763
5764 Congratulations, you have now completed your first APEX
5765 policy. The policy model containing our new policy can
5766 now be exported from the editor and saved. Click on the
5767 'File' menu and select 'Download' to save the policy
5768 model in JSON format. The exported policy model is then
5769 available in the directory you selected, for instance
5770 ``$APEX_HOME/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json``.
5771 The exported policy can now be loaded into the APEX
5772 Policy Engine, or can be re-loaded and edited by the APEX
5773 Policy Editor.
5774
5775 .. container:: imageblock
5776
5777 .. container:: content
5778
5779 |Download the completed policy model using the 'File'
5780 > 'Download' menu item|
5781
5782 .. container:: title
5783
5784 Figure 18. Export a Policy Model
5785
5786Test Policy Step 1
5787##################
5788
5789 .. container:: paragraph
5790
5791 To start a new APEX Engine you can use the following
5792 configuration. In a full APEX installation you can find
5793 this configuration in
5794 ``$APEX_HOME/examples/config/MyFirstPolicy/1/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
5795 This configuration expects incoming events to be in
5796 ``JSON`` format and to be passed into the APEX Engine
5797 from ``stdin``, and result events will be printed in
5798 ``JSON`` format to ``stdout``. This configuration loads
5799 the policy model stored in the file
5800 'MyFirstPolicyModel_0.0.1.json' as exported from the APEX
5801 Editor. Note, you may need to edit this file to provide
5802 the full path to wherever you stored the exported policy
5803 model file.
5804
5805 .. container:: listingblock
5806
5807 .. container:: title
5808
5809 JSON to load and execute *My First Policy*, read input
5810 JSON events from ``stdin``, and emit output events to
5811 ``stdout``
5812
5813 .. container:: content
5814
5815 .. code::
5816
5817 {
5818 "engineServiceParameters" : {
5819 "name" : "MyFirstPolicyApexEngine",
5820 "version" : "0.0.1",
5821 "id" : 101,
5822 "instanceCount" : 4,
5823 "deploymentPort" : 12345,
5824 "policyModelFileName" : "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json",
5825 "engineParameters" : {
5826 "executorParameters" : {
5827 "MVEL" : {
5828 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
5829 },
5830 "JAVASCRIPT" : {
5831 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
5832 }
5833 }
5834 }
5835 },
5836 "eventOutputParameters": {
5837 "FirstProducer": {
5838 "carrierTechnologyParameters" : {
5839 "carrierTechnology" : "FILE",
5840 "parameters" : {
5841 "standardIO" : true
5842 }
5843 },
5844 "eventProtocolParameters" : {
5845 "eventProtocol" : "JSON"
5846 }
5847 }
5848 },
5849 "eventInputParameters": {
5850 "FirstConsumer": {
5851 "carrierTechnologyParameters" : {
5852 "carrierTechnology" : "FILE",
5853 "parameters" : {
5854 "standardIO" : true
5855 }
5856 },
5857 "eventProtocolParameters" : {
5858 "eventProtocol" : "JSON"
5859 }
5860 }
5861 }
5862 }
5863
5864 .. container:: paragraph
5865
5866 To test the policy try paste the following events into
5867 the console as the APEX engine executes:
5868
5869 .. table:: Table 11. Inputs and Outputs when testing *My First Policy*
5870
5871 +------------------------------------------+-------------------------------------------+-----------+
5872 | Input Event (JSON) | Output Event (JSON) | comment |
5873 +==========================================+===========================================+===========+
5874 | .. container:: | .. container:: | Request |
5875 | | | to buy a |
5876 | .. container:: listingblock | .. container:: listingblock | non-alcoh |
5877 | | | olic |
5878 | | .. container:: content | item |
5879 | .. container:: content | | (``item_I |
5880 | | .. code:: | D=5123``) |
5881 | | | at |
5882 | .. code:: | { | *10:13:09 |
5883 | | "name": "SALE_AUTH", | * |
5884 | | | on |
5885 | { | "version": "0.0.1", | *Tuesday, |
5886 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | 10 |
5887 | "name" : "SALE_INPUT", | "source": "", | January |
5888 | "version": "0.0.1", | "target": "", | 2017*. |
5889 | "time" : 1483351989000, | "amount": 299, | Sale is |
5890 | "sale_ID": 99999991, | "assistant_ID": 23, | authorize |
5891 | "amount": 299, | "authorised": true, | d. |
5892 | "item_ID": 5123, | "branch_ID": 1, | |
5893 | "quantity": 1, | "item_ID": 5123, | |
5894 | "assistant_ID": 23, | "message": "Sale authorised | |
5895 | "branch_ID": 1, | by policy task MorningBo | |
5896 | "notes": "Special Offer!!" | ozeCheck for time 10:13:09 | |
5897 | } | GMT", | |
5898 | | "notes": "Special Offer!!", | |
5899 | | "quantity": 1, | |
5900 | | "sale_ID": 99999991, | |
5901 | | "time": 1483351989000 | |
5902 | | } | |
5903 | | | |
5904 | | | |
5905 | | | |
5906 +------------------------------------------+-------------------------------------------+-----------+
5907 | .. container:: | .. container:: | Request |
5908 | | | to buy |
5909 | .. container:: listingblock | .. container:: listingblock | alcohol |
5910 | | | item |
5911 | .. container:: content | .. container:: content | (``item_I |
5912 | | | D=1249``) |
5913 | .. code:: | .. code:: | at |
5914 | | | *08:41:06 |
5915 | { | { | * |
5916 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | on |
5917 | "name": "SALE_INPUT", | "name": "SALE_AUTH", | *Monday, |
5918 | "version": "0.0.1", | "source": "", | 02 |
5919 | "time": 1483346466000, | "target": "", | January |
5920 | "sale_ID": 99999992, | "amount": 1249, | 2017*. |
5921 | "version": "0.0.1", | "assistant_ID": 12, | |
5922 | "amount": 1249, | "authorised": false, | Sale is |
5923 | "item_ID": 1012, | "branch_ID": 2, | not |
5924 | "quantity": 1, | "item_ID": 1012, | authorize |
5925 | "assistant_ID": 12, | "message": "Sale not | d. |
5926 | "branch_ID": 2 | authorised by policy task | |
5927 | } | MorningBoozeCheck for time | |
5928 | | 08:41:06 GMT. Alcohol can | |
5929 | | not be sold between | |
5930 | | 00:00:00 GMT and 11:30:00 | |
5931 | | GMT", | |
5932 | | "notes": null, | |
5933 | | "quantity": 1, | |
5934 | | "sale_ID": 99999992, | |
5935 | | "time": 1483346466000 | |
5936 | | } | |
5937 +------------------------------------------+-------------------------------------------+-----------+
5938 | .. container:: | .. container:: | Request |
5939 | | | to buy |
5940 | .. container:: listingblock | .. container:: listingblock | alcohol |
5941 | | | (``item_I |
5942 | | .. container:: content | D=1943``) |
5943 | .. container:: content | | at |
5944 | | .. code:: | *20:17:13 |
5945 | | | * |
5946 | .. code:: | { | on |
5947 | | "name": "SALE_AUTH", | *Tuesday, |
5948 | { | "version": "0.0.1", | 20 |
5949 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | December |
5950 | "name" : "SALE_INPUT", | "source": "", | 2016*. |
5951 | "version": "0.0.1", | "target": "", | |
5952 | "time" : 1482265033000, | "amount": 4799, | Sale is |
5953 | "sale_ID": 99999993, | "assistant_ID": 9, | authorize |
5954 | "amount": 4799, | "authorised": true, | d. |
5955 | "item_ID": 1943, | "branch_ID": 3, | |
5956 | "quantity": 2, | "item_ID": 1943, | |
5957 | "assistant_ID": 9, | "message": "Sale authorised | |
5958 | "branch_ID": 3 | by policy task MorningBo | |
5959 | } | ozeCheck for time 20:17:13 | |
5960 | | GMT", | |
5961 | | "notes": null, | |
5962 | | "quantity": 2, | |
5963 | | "sale_ID": 99999993, | |
5964 | | "time": 1482265033000 | |
5965 | | } | |
5966 +------------------------------------------+-------------------------------------------+-----------+
5967
59684.3.6. Policy 1 in CLI Editor
5969#############################
5970
5971 .. container:: paragraph
5972
5973 An equivalent version of the ``MyFirstPolicyModel``
5974 policy model can again be generated using the APEX CLI
5975 editor. A sample APEX CLI script is shown below:
5976
5977 .. container:: listingblock
5978
5979 .. container:: title
5980
5981 APEX CLI Editor code for Policy 1
5982
5983 .. container:: content
5984
ramverma760cce92019-07-11 12:57:49 +00005985 .. code::
ramverma3b71c972019-07-10 11:25:37 +00005986
5987 #-------------------------------------------------------------------------------
5988 # ============LICENSE_START=======================================================
5989 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
5990 # ================================================================================
5991 # Licensed under the Apache License, Version 2.0 (the "License");
5992 # you may not use this file except in compliance with the License.
5993 # You may obtain a copy of the License at
5994 #
5995 # http://www.apache.org/licenses/LICENSE-2.0
5996 #
5997 # Unless required by applicable law or agreed to in writing, software
5998 # distributed under the License is distributed on an "AS IS" BASIS,
5999 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6000 # See the License for the specific language governing permissions and
6001 # limitations under the License.
6002 #
6003 # SPDX-License-Identifier: Apache-2.0
6004 # ============LICENSE_END=========================================================
6005 #-------------------------------------------------------------------------------
6006
6007 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6008
6009 schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long
6010
6011 schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean
6012
6013 schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long
6014
6015 schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long
6016
6017 schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String
6018
6019 schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String
6020
6021 schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long
6022
6023 schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer
6024
6025 schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long
6026
6027 schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long
6028
6029 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6030 This task checks if the sales request is for an item that contains alcohol.
6031 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6032 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6033 LE
6034 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6035 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6036 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6037 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6038 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6039 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6040 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6041 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6042 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6043 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6044 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6045 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6046 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6047 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6048 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6049 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6050 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6051 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6052 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6053 /*
6054 * ============LICENSE_START=======================================================
6055 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6056 * ================================================================================
6057 * Licensed under the Apache License, Version 2.0 (the "License");
6058 * you may not use this file except in compliance with the License.
6059 * You may obtain a copy of the License at
6060 *
6061 * http://www.apache.org/licenses/LICENSE-2.0
6062 *
6063 * Unless required by applicable law or agreed to in writing, software
6064 * distributed under the License is distributed on an "AS IS" BASIS,
6065 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6066 * See the License for the specific language governing permissions and
6067 * limitations under the License.
6068 *
6069 * SPDX-License-Identifier: Apache-2.0
6070 * ============LICENSE_END=========================================================
6071 */
6072 import java.util.Date;
6073 import java.util.Calendar;
6074 import java.util.TimeZone;
6075 import java.text.SimpleDateFormat;
6076
6077 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6078
6079 outFields.put("amount" , inFields.get("amount"));
6080 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6081 outFields.put("notes" , inFields.get("notes"));
6082 outFields.put("quantity" , inFields.get("quantity"));
6083 outFields.put("branch_ID" , inFields.get("branch_ID"));
6084 outFields.put("item_ID" , inFields.get("item_ID"));
6085 outFields.put("time" , inFields.get("time"));
6086 outFields.put("sale_ID" , inFields.get("sale_ID"));
6087
6088 item_id = inFields.get("item_ID");
6089
6090 //The events used later to test this task use GMT timezone!
6091 gmt = TimeZone.getTimeZone("GMT");
6092 timenow = Calendar.getInstance(gmt);
6093 df = new SimpleDateFormat("HH:mm:ss z");
6094 df.setTimeZone(gmt);
6095 timenow.setTimeInMillis(inFields.get("time"));
6096
6097 midnight = timenow.clone();
6098 midnight.set(
6099 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6100 timenow.get(Calendar.DATE),0,0,0);
6101 eleven30 = timenow.clone();
6102 eleven30.set(
6103 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6104 timenow.get(Calendar.DATE),11,30,0);
6105
6106 itemisalcohol = false;
6107 if(item_id != null && item_id >=1000 && item_id < 2000)
6108 itemisalcohol = true;
6109
6110 if( itemisalcohol
6111 && timenow.after(midnight) && timenow.before(eleven30)){
6112 outFields.put("authorised", false);
6113 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6114 " for time "+df.format(timenow.getTime())+
6115 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6116 " and "+df.format(eleven30.getTime()));
6117 return true;
6118 }
6119 else{
6120 outFields.put("authorised", true);
6121 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6122 " for time "+df.format(timenow.getTime()));
6123 return true;
6124 }
6125
6126 /*
6127 This task checks if a sale request is for an item that is an alcoholic drink.
6128 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6129 authorised. Otherwise the sale is authorised.
6130 In this implementation we assume that items with item_ID value between 1000 and
6131 2000 are all alcoholic drinks :-)
6132 */
6133 LE
6134
6135 event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS"
6136 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6137 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6138 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
6139 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6140 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6141 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6142 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6143 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6144 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6145 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6146
6147 event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX"
6148 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6149 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6150 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6151 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6152 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6153 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6154 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6155 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6156
6157
6158 policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide
6159 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
6160 policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL
6161 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
6162
6163Policy Step 2
6164-------------
6165
6166Scenario
6167#########
6168 .. container:: paragraph
6169
6170 *HyperM* have just opened a new branch in a different
6171 country, but that country has different rules about when
6172 alcohol can be sold! In this section we will go through
6173 the necessary steps to extend our policy to enforce this
6174 for *HyperM*.
6175
6176 .. container:: ulist
6177
6178 - In some branches alcohol cannot be sold before 1pm,
6179 and not at all on Sundays.
6180
6181 .. container:: paragraph
6182
6183 Although there are a number of ways to accomplish this
6184 the easiest approach for us is to define another task and
6185 then select which task is appropriate at runtime
6186 depending on the branch identifier in the incoming event.
6187
6188Extend the Policy with the new Scenario
6189#######################################
6190
6191 .. container:: paragraph
6192
6193 To create a new Task click on the 'Tasks' tab. In the
6194 'Tasks' pane, right click and select 'Create new Task':
6195
6196 .. container:: paragraph
6197
6198 Create a new Task called ``MorningBoozeCheckAlt1``. Use
6199 the 'Generate UUID' button to create a new unique ID for
6200 the task, and fill in a description for the task. Select
6201 the same input and output fields that we used earlier
6202 when we defined the ``MorningBoozeCheck`` task earlier.
6203
6204 .. table:: Table 12. Input fields for ``MorningBoozeCheckAlt1`` task
6205
6206 +-----------------------------------+-----------------------------------+
6207 | Parameter Name | Parameter Type |
6208 +===================================+===================================+
6209 | time | timestamp_type |
6210 +-----------------------------------+-----------------------------------+
6211 | sale_ID | sale_ID_type |
6212 +-----------------------------------+-----------------------------------+
6213 | amount | price_type |
6214 +-----------------------------------+-----------------------------------+
6215 | item_ID | item_ID_type |
6216 +-----------------------------------+-----------------------------------+
6217 | quantity | quantity_type |
6218 +-----------------------------------+-----------------------------------+
6219 | assistant_ID | assistant_ID_type |
6220 +-----------------------------------+-----------------------------------+
6221 | branch_ID | branch_ID_type |
6222 +-----------------------------------+-----------------------------------+
6223 | notes | notes_type |
6224 +-----------------------------------+-----------------------------------+
6225
6226 .. table:: Table 13. Output fields for ``MorningBoozeCheckAlt1`` task
6227
6228 +-----------------------------------+-----------------------------------+
6229 | Parameter Name | Parameter Type |
6230 +===================================+===================================+
6231 | sale_ID | sale_ID_type |
6232 +-----------------------------------+-----------------------------------+
6233 | time | timestamp_type |
6234 +-----------------------------------+-----------------------------------+
6235 | authorised | authorised_type |
6236 +-----------------------------------+-----------------------------------+
6237 | message | message_type |
6238 +-----------------------------------+-----------------------------------+
6239 | amount | price_type |
6240 +-----------------------------------+-----------------------------------+
6241 | item_ID | item_ID_type |
6242 +-----------------------------------+-----------------------------------+
6243 | assistant_ID | assistant_ID_type |
6244 +-----------------------------------+-----------------------------------+
6245 | quantity | quantity_type |
6246 +-----------------------------------+-----------------------------------+
6247 | branch_ID | branch_ID_type |
6248 +-----------------------------------+-----------------------------------+
6249 | notes | notes_type |
6250 +-----------------------------------+-----------------------------------+
6251
6252 .. container:: paragraph
6253
6254 This task also requires some 'Task Logic' to implement
6255 the new behaviour for this task.
6256
6257 .. container:: paragraph
6258
6259 For simplicity use the following code for the task logic.
6260 It again assumes that all items with ``item_ID`` between
6261 1000 and 2000 contain alcohol. We again use the standard
6262 ``Java`` time utilities to check if the current time is
6263 between ``00:00:00 CET`` and ``13:00:00 CET`` or if it is
6264 ``Sunday``.
6265
6266 .. container:: paragraph
6267
6268 For this task we will again author the logic using the
6269 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__
6270 scripting language. Sample task logic code (specified in
6271 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__) is
6272 given below. For a detailed guide to how to write your
6273 own logic in
6274 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
6275 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
6276 of the other supported languages please refer to APEX
6277 Programmers Guide.
6278
6279 .. container:: listingblock
6280
6281 .. container:: title
6282
6283 MVEL code for the ``MorningBoozeCheckAlt1`` task
6284
6285 .. container:: content
6286
ramverma760cce92019-07-11 12:57:49 +00006287 .. code::
ramverma3b71c972019-07-10 11:25:37 +00006288
6289 /*
6290 * ============LICENSE_START=======================================================
6291 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6292 * ================================================================================
6293 * Licensed under the Apache License, Version 2.0 (the "License");
6294 * you may not use this file except in compliance with the License.
6295 * You may obtain a copy of the License at
6296 *
6297 * http://www.apache.org/licenses/LICENSE-2.0
6298 *
6299 * Unless required by applicable law or agreed to in writing, software
6300 * distributed under the License is distributed on an "AS IS" BASIS,
6301 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6302 * See the License for the specific language governing permissions and
6303 * limitations under the License.
6304 *
6305 * SPDX-License-Identifier: Apache-2.0
6306 * ============LICENSE_END=========================================================
6307 */
6308 import java.util.Date;
6309 import java.util.Calendar;
6310 import java.util.TimeZone;
6311 import java.text.SimpleDateFormat;
6312
6313 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6314
6315 outFields.put("amount" , inFields.get("amount"));
6316 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6317 outFields.put("notes" , inFields.get("notes"));
6318 outFields.put("quantity" , inFields.get("quantity"));
6319 outFields.put("branch_ID" , inFields.get("branch_ID"));
6320 outFields.put("item_ID" , inFields.get("item_ID"));
6321 outFields.put("time" , inFields.get("time"));
6322 outFields.put("sale_ID" , inFields.get("sale_ID"));
6323
6324 item_id = inFields.get("item_ID");
6325
6326 //The events used later to test this task use CET timezone!
6327 cet = TimeZone.getTimeZone("CET");
6328 timenow = Calendar.getInstance(cet);
6329 df = new SimpleDateFormat("HH:mm:ss z");
6330 df.setTimeZone(cet);
6331 timenow.setTimeInMillis(inFields.get("time"));
6332
6333 midnight = timenow.clone();
6334 midnight.set(
6335 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6336 timenow.get(Calendar.DATE),0,0,0);
6337 onepm = timenow.clone();
6338 onepm.set(
6339 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6340 timenow.get(Calendar.DATE),13,0,0);
6341
6342 itemisalcohol = false;
6343 if(item_id != null && item_id >=1000 && item_id < 2000)
6344 itemisalcohol = true;
6345
6346 if( itemisalcohol &&
6347 ( (timenow.after(midnight) && timenow.before(onepm))
6348 ||
6349 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
6350 )){
6351 outFields.put("authorised", false);
6352 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6353 " for time "+df.format(timenow.getTime())+
6354 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6355 " and "+df.format(onepm.getTime()) +" or on Sunday");
6356 return true;
6357 }
6358 else{
6359 outFields.put("authorised", true);
6360 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6361 " for time "+df.format(timenow.getTime()));
6362 return true;
6363 }
6364
6365 /*
6366 This task checks if a sale request is for an item that is an alcoholic drink.
6367 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6368 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6369 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
6370 */
6371
6372 .. container:: imageblock
6373
6374 .. container:: content
6375
6376 |Create a new alternative task MorningBoozeCheckAlt1|
6377
6378 .. container:: title
6379
6380 Figure 19. Create a new Task
6381
6382 .. container:: paragraph
6383
6384 The task definition is now complete so click the 'Submit'
6385 button to save the task. Now that we have created our
6386 task, we can can add this task to the single pre-existing
6387 state (``BoozeAuthDecide``) in our policy.
6388
6389 .. container:: paragraph
6390
6391 To edit the ``BoozeAuthDecide`` state in our policy click
6392 on the 'Policies' tab. In the 'Policies' pane, right
6393 click on our ``MyFirstPolicy`` policy and select 'Edit'.
6394 Navigate to the ``BoozeAuthDecide`` state in the 'states'
6395 section at the bottom of the policy definition pane.
6396
6397 .. container:: imageblock
6398
6399 .. container:: content
6400
6401 |Right click to edit a policy|
6402
6403 .. container:: title
6404
6405 Figure 20. Edit a Policy
6406
6407 .. container:: paragraph
6408
6409 To add our new task ``MorningBoozeCheckAlt1``, scroll
6410 down to the ``BoozeAuthDecide`` state in the 'States'
6411 section. In the 'State Tasks' section for
6412 ``BoozeAuthDecide`` use the 'Add new task' button. Select
6413 our new ``MorningBoozeCheckAlt1`` task, and use the name
6414 of the task as the 'Local Name' for the task. The
6415 ``MorningBoozeCheckAlt1`` task can reuse the same
6416 ``MorningBoozeCheck_Output_Direct`` 'Direct State Output
6417 Mapping' that we used for the ``MorningBoozeCheck`` task.
6418 (Recall that the role of the 'State Output Mapping' is to
6419 select the output event for the state, and select the
6420 next state to be executed. These both remain the same as
6421 before.)
6422
6423 .. container:: paragraph
6424
6425 Since our state has more than one task we must define
6426 some logic to determine which task should be used each
6427 time the state is executed. This *task selection logic*
6428 is defined in the state definition. For our
6429 ``BoozeAuthDecide`` state we want the choice of which
6430 task to use to be based on the ``branch_ID`` from which
6431 the ``SALE_INPUT`` event originated. For simplicity sake
6432 let us assume that branches with ``branch_ID`` between
6433 ``0`` and ``999`` should use the ``MorningBoozeCheck``
6434 task, and the branches with with ``branch_ID`` between
6435 ``1000`` and ``1999`` should use the
6436 ``MorningBoozeCheckAlt1`` task.
6437
6438 .. container:: paragraph
6439
6440 This time, for variety, we will author the task selection
6441 logic using the
6442 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__
6443 scripting language. Sample task selection logic code
6444 (specified in
6445 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__)
6446 is given below. Paste the script text into the 'Task
6447 Selection Logic' box, and use "JAVASCRIPT" as the 'Task
6448 Selection Logic Type / Flavour'. It is necessary to mark
6449 one of the tasks as the 'Default Task' so that the task
6450 selection logic always has a fallback default option in
6451 cases where a particular task cannot be selected. In this
6452 case the ``MorningBoozeCheck`` task can be the default
6453 task.
6454
6455 .. container:: listingblock
6456
6457 .. container:: title
6458
6459 JavaScript code for the ``BoozeAuthDecide`` task
6460 selection logic
6461
6462 .. container:: content
6463
ramverma760cce92019-07-11 12:57:49 +00006464 .. code::
ramverma3b71c972019-07-10 11:25:37 +00006465
6466 /*
6467 * ============LICENSE_START=======================================================
6468 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6469 * ================================================================================
6470 * Licensed under the Apache License, Version 2.0 (the "License");
6471 * you may not use this file except in compliance with the License.
6472 * You may obtain a copy of the License at
6473 *
6474 * http://www.apache.org/licenses/LICENSE-2.0
6475 *
6476 * Unless required by applicable law or agreed to in writing, software
6477 * distributed under the License is distributed on an "AS IS" BASIS,
6478 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6479 * See the License for the specific language governing permissions and
6480 * limitations under the License.
6481 *
6482 * SPDX-License-Identifier: Apache-2.0
6483 * ============LICENSE_END=========================================================
6484 */
6485
6486
6487 var returnValueType = Java.type("java.lang.Boolean");
6488 var returnValue = new returnValueType(true);
6489
6490 executor.logger.info("Task Selection Execution: '"+executor.subject.id+
6491 "'. Input Event: '"+executor.inFields+"'");
6492
6493 branchid = executor.inFields.get("branch_ID");
6494 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
6495 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
6496 taskdef = executor.subject.getDefaultTaskKey();
6497
6498 if(branchid >=0 && branchid <1000){
6499 taskorig.copyTo(executor.selectedTask);
6500 }
6501 else if (branchid >=1000 && branchid <2000){
6502 taskalt.copyTo(executor.selectedTask);
6503 }
6504 else{
6505 taskdef.copyTo(executor.selectedTask);
6506 }
6507
6508 /*
6509 This task selection logic selects task "MorningBoozeCheck" for branches with
6510 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with
6511 1000<=branch_ID<2000. Otherwise the default task is selected.
6512 In this case the default task is also "MorningBoozeCheck"
6513 */
6514
6515 .. container:: imageblock
6516
6517 .. container:: content
6518
6519 |State definition with 2 Tasks and Task Selection
6520 Logic|
6521
6522 .. container:: title
6523
6524 Figure 21. State definition with 2 Tasks and Task
6525 Selection Logic
6526
6527 .. container:: paragraph
6528
6529 When complete don’t forget to click the 'Submit' button
6530 at the bottom of 'Policies' pane for our
6531 ``MyFirstPolicy`` policy after updating the
6532 ``BoozeAuthDecide`` state.
6533
6534 .. container:: paragraph
6535
6536 Congratulations, you have now completed the second step
6537 towards your first APEX policy. The policy model
6538 containing our new policy can again be validated and
6539 exported from the editor and saved as shown in Step 1.
6540
6541 .. container:: paragraph
6542
6543 The exported policy model is then available in the
6544 directory you selected, as
6545 `MyFirstPolicyModel_0.0.1.json <files/mfp-files/2/MyFirstPolicyModel_0.0.1.json>`__.
6546 The exported policy can now be loaded into the APEX
6547 Policy Engine, or can be re-loaded and edited by the APEX
6548 Policy Editor.
6549
6550Test Policy Step 2
6551##################
6552
6553 .. container:: paragraph
6554
6555 To start a new APEX Engine you can use the following
6556 configuration. In a full APEX installation you can find
6557 this configuration in
6558 ``$APEX_HOME/examples/config/MyFirstPolicy/2/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
6559 Note, this has changed from the configuration file in
6560 Step 1 to enable the ``JAVASCRIPT`` executor for our new
6561 'Task Selection Logic'.
6562
6563 .. container:: listingblock
6564
6565 .. container:: title
6566
6567 JSON to load and execute *My First Policy*, read input
6568 JSON events from ``stdin``, and emit output events to
6569 ``stdout``
6570
6571 .. container:: content
6572
ramverma760cce92019-07-11 12:57:49 +00006573 .. code::
ramverma3b71c972019-07-10 11:25:37 +00006574
6575 {
6576 "engineServiceParameters" : {
6577 "name" : "MyFirstPolicyApexEngine",
6578 "version" : "0.0.1",
6579 "id" : 102,
6580 "instanceCount" : 4,
6581 "deploymentPort" : 12345,
6582 "policyModelFileName" : "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json",
6583 "engineParameters" : {
6584 "executorParameters" : {
6585 "MVEL" : {
6586 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
6587 },
6588 "JAVASCRIPT" : {
6589 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
6590 }
6591 }
6592 }
6593 },
6594 "eventOutputParameters": {
6595 "FirstProducer": {
6596 "carrierTechnologyParameters" : {
6597 "carrierTechnology" : "FILE",
6598 "parameters" : {
6599 "standardIO" : true
6600 }
6601 },
6602 "eventProtocolParameters" : {
6603 "eventProtocol" : "JSON"
6604 }
6605 }
6606 },
6607 "eventInputParameters": {
6608 "FirstConsumer": {
6609 "carrierTechnologyParameters" : {
6610 "carrierTechnology" : "FILE",
6611 "parameters" : {
6612 "standardIO" : true
6613 }
6614 },
6615 "eventProtocolParameters" : {
6616 "eventProtocol" : "JSON"
6617 }
6618 }
6619 }
6620 }
6621
6622 .. container:: paragraph
6623
6624 To test the policy try paste the following events into
6625 the console as the APEX engine executes. Note, all tests
6626 from Step 1 will still work perfectly since none of those
6627 events originate from a branch with ``branch_ID`` between
6628 ``1000`` and ``2000``. The 'Task Selection Logic' will
6629 therefore pick the ``MorningBoozeCheck`` task as
6630 expected, and will therefore give the same results.
6631
6632 .. table:: Table 14. Inputs and Outputs when testing *My First Policy*
6633
6634 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6635 | Input Event (JSON) | Output Event (JSON) | comment |
6636 +==============================================+============================================================+===========================+
6637 | .. container:: | .. container:: | Request to buy |
6638 | | | alcohol item |
6639 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1249``) |
6640 | | | |
6641 | | | at *08:41:06 |
6642 | | .. container:: content | GMT* on *Monday, |
6643 | .. container:: content | | 02 January |
6644 | | .. code:: | 2017*. |
6645 | | | |
6646 | | { | Sale is not |
6647 | .. code:: | "nameSpace": "com.hyperm", | authorized. Uses |
6648 | | "name": "SALE_AUTH", | the |
6649 | | "version": "0.0.1", | ``MorningBoozeCheck`` |
6650 | { | "source": "", | |
6651 | "nameSpace": "com.hyperm", | "target": "", | task. |
6652 | "name": "SALE_INPUT", | "amount": 1249, | |
6653 | "version": "0.0.1", | "assistant_ID":12, | Note this test |
6654 | "time": 1483346466000, | "authorised": false, | is copied from |
6655 | "sale_ID": 99999992, | "branch_ID": 2, | Step 1 above, |
6656 | "amount": 1249, | "item_ID": 1012, | and demonstrates |
6657 | "item_ID": 1012, | "message": "Sale not authorised by policy ta | that the |
6658 | "quantity": 1, | sk MorningBoozeCheck for time 08:41:06 GMT.| original |
6659 | "assistant_ID": 12, | Alcohol can not be sold between 00:00:00 | ``MorningBoozeCheck`` |
6660 | "branch_ID": 2 | GMT and 11:30:00 GMT", | |
6661 | } | "notes": null, | task is |
6662 | | "quantity": 1, | executed. |
6663 | | "sale_ID": 99999992, | |
6664 | | "time": 1483346466000 | |
6665 | | } | |
6666 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6667 | .. container:: | .. container:: | Request to buy |
6668 | | | alcohol |
6669 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1047``) |
6670 | | | |
6671 | | | at *10:14:33* on |
6672 | | .. container:: content | *Thursday, 22 |
6673 | .. container:: content | | December 2016*. |
6674 | | .. code:: | |
6675 | | | Sale is not |
6676 | | { | authorized. Uses |
6677 | .. code:: | "nameSpace" : "com.hyperm", | the |
6678 | | "name" : "SALE_AUTH", | ``MorningBoozeCheckAlt1`` |
6679 | | "version" : "0.0.1", | task. |
6680 | { | "source" : "", | |
6681 | | "target" : "", | |
6682 | "nameSpace": "com.hyperm", | "sale_ID" : 99999981, | |
6683 | "name": "SALE_INPUT", | "amount" : 299, | |
6684 | "version": "0.0.1", | "assistant_ID": 1212, | |
6685 | "time": 1482398073000, | "notes" : null, | |
6686 | "sale_ID": 99999981, | "quantity" : 1, | |
6687 | "amount": 299, | "branch_ID" : 1002, | |
6688 | "item_ID": 1047, | "item_ID" : 1047, | |
6689 | "quantity": 1, | "authorised" : false, | |
6690 | "assistant_ID": 1212, | "time" : 1482398073000, | |
6691 | "branch_ID": 1002 | "message" : "Sale not authorised by policy t | |
6692 | } | ask MorningBoozeCheckAlt1 fortime | |
6693 | | 10:14:33 CET. Alcohol can not be sold | |
6694 | | between 00:00:00 CET and 13:00:00 CET or on | |
6695 | | Sunday" | |
6696 | | } | |
6697 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6698 | .. container:: | .. container:: | Request to buy |
6699 | | | alcohol |
6700 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1443``) |
6701 | | | |
6702 | | | at *17:19:37* on |
6703 | | .. container:: content | *Sunday, 18 |
6704 | .. container:: content | | December 2016*. |
6705 | | .. code:: | |
6706 | | | Sale is not |
6707 | | { | authorized. Uses |
6708 | .. code:: | "nameSpace" : "com.hyperm", | the |
6709 | | | ``MorningBoozeCheckAlt1`` |
6710 | | "name" : "SALE_AUTH", | task. |
6711 | { | | |
6712 | "nameSpace": "com.hyperm", | "version" : "0.0.1", | |
6713 | "name": "SALE_INPUT", | "source" : "", | |
6714 | "version": "0.0.1", | "target" : "", | |
6715 | "time": 1482077977000, | "sale_ID" : 99999982, | |
6716 | "sale_ID": 99999982, | "amount" : 2199, | |
6717 | "amount": 2199, | "assistant_ID" : 94, | |
6718 | "item_ID": 1443, | "notes" : "Buy 3, get 1 free!!", | |
6719 | "quantity": 12, | "quantity" : 12, | |
6720 | "assistant_ID": 94, | "branch_ID" : 1003, | |
6721 | "branch_ID": 1003, | "item_ID" : 1443, | |
6722 | "notes": "Buy 3, get 1 free!!" | "authorised" : false, | |
6723 | } | "time" : 1482077977000, | |
6724 | | "message" : "Sale not authorised by policy t | |
6725 | | ask MorningBoozeCheckAlt1 for | |
6726 | | time 17:19:37 CET. Alcohol c | |
6727 | | an not be sold between 00:00: | |
6728 | | 00 CET and 13:00:00 CET or on | |
6729 | | Sunday" | |
6730 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6731 | .. container:: | .. container:: | Request to buy |
6732 | | | non-alcoholic |
6733 | .. container:: listingblock | .. container:: listingblock | item |
6734 | | | (``item_ID=5321``) |
6735 | | | |
6736 | | .. container:: content | at *11:13:09* on |
6737 | .. container:: content | | *Monday, 2 |
6738 | | .. code:: | January 2017*. |
6739 | | | |
6740 | | { | Sale is |
6741 | .. code:: | "nameSpace" : "com.hyperm", | authorized. Uses |
6742 | | "name" : "SALE_AUTH", | the |
6743 | { | "version" : "0.0.1", | ``MorningBoozeCheckAlt1`` |
6744 | "nameSpace": "com.hyperm", | "source" : "", | task. |
6745 | "name": "SALE_INPUT", | "target" : "", | |
6746 | "version": "0.0.1", | "sale_ID" : 99999983, | |
6747 | "time": 1483351989000, | "amount" : 699, | |
6748 | "sale_ID": 99999983, | "assistant_ID" : 2323, | |
6749 | "amount": 699, | "notes" : "", | |
6750 | "item_ID": 5321, | "quantity" : 1, | |
6751 | "quantity": 1, | "branch_ID" : 1001, | |
6752 | "assistant_ID": 2323, | "item_ID" : 5321, | |
6753 | "branch_ID": 1001, | "authorised" : true, | |
6754 | "notes": "" | "time" : 1483351989000, | |
6755 | } | "message" : "Sale authorised by policy task | |
6756 | | MorningBoozeCheckAlt1 for time 11:13:09 CET"| |
6757 | | } | |
6758 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6759
6760Policy 2 in CLI Editor
6761######################
6762
6763 .. container:: paragraph
6764
6765 An equivalent version of the ``MyFirstPolicyModel``
6766 policy model can again be generated using the APEX CLI
6767 editor. A sample APEX CLI script is shown below:
6768
6769 .. container:: listingblock
6770
6771 .. container:: title
6772
6773 APEX CLI Editor code for Policy 2
6774
6775 .. container:: content
6776
ramverma760cce92019-07-11 12:57:49 +00006777 .. code::
ramverma3b71c972019-07-10 11:25:37 +00006778
6779 #-------------------------------------------------------------------------------
6780 # ============LICENSE_START=======================================================
6781 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
6782 # ================================================================================
6783 # Licensed under the Apache License, Version 2.0 (the "License");
6784 # you may not use this file except in compliance with the License.
6785 # You may obtain a copy of the License at
6786 #
6787 # http://www.apache.org/licenses/LICENSE-2.0
6788 #
6789 # Unless required by applicable law or agreed to in writing, software
6790 # distributed under the License is distributed on an "AS IS" BASIS,
6791 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6792 # See the License for the specific language governing permissions and
6793 # limitations under the License.
6794 #
6795 # SPDX-License-Identifier: Apache-2.0
6796 # ============LICENSE_END=========================================================
6797 #-------------------------------------------------------------------------------
6798
6799 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6800
6801 schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long
6802
6803 schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean
6804
6805 schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long
6806
6807 schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long
6808
6809 schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String
6810
6811 schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String
6812
6813 schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long
6814
6815 schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer
6816
6817 schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long
6818
6819 schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long
6820
6821 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6822 This task checks if the sales request is for an item that contains alcohol.
6823 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6824 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6825 LE
6826 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6827 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6828 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6829 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6830 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6831 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6832 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6833 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6834 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6835 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6836 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6837 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6838 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6839 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6840 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6841 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6842 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6843 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6844 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6845 /*
6846 * ============LICENSE_START=======================================================
6847 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6848 * ================================================================================
6849 * Licensed under the Apache License, Version 2.0 (the "License");
6850 * you may not use this file except in compliance with the License.
6851 * You may obtain a copy of the License at
6852 *
6853 * http://www.apache.org/licenses/LICENSE-2.0
6854 *
6855 * Unless required by applicable law or agreed to in writing, software
6856 * distributed under the License is distributed on an "AS IS" BASIS,
6857 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6858 * See the License for the specific language governing permissions and
6859 * limitations under the License.
6860 *
6861 * SPDX-License-Identifier: Apache-2.0
6862 * ============LICENSE_END=========================================================
6863 */
6864 import java.util.Date;
6865 import java.util.Calendar;
6866 import java.util.TimeZone;
6867 import java.text.SimpleDateFormat;
6868
6869 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6870
6871 outFields.put("amount" , inFields.get("amount"));
6872 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6873 outFields.put("notes" , inFields.get("notes"));
6874 outFields.put("quantity" , inFields.get("quantity"));
6875 outFields.put("branch_ID" , inFields.get("branch_ID"));
6876 outFields.put("item_ID" , inFields.get("item_ID"));
6877 outFields.put("time" , inFields.get("time"));
6878 outFields.put("sale_ID" , inFields.get("sale_ID"));
6879
6880 item_id = inFields.get("item_ID");
6881
6882 //The events used later to test this task use GMT timezone!
6883 gmt = TimeZone.getTimeZone("GMT");
6884 timenow = Calendar.getInstance(gmt);
6885 df = new SimpleDateFormat("HH:mm:ss z");
6886 df.setTimeZone(gmt);
6887 timenow.setTimeInMillis(inFields.get("time"));
6888
6889 midnight = timenow.clone();
6890 midnight.set(
6891 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6892 timenow.get(Calendar.DATE),0,0,0);
6893 eleven30 = timenow.clone();
6894 eleven30.set(
6895 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6896 timenow.get(Calendar.DATE),11,30,0);
6897
6898 itemisalcohol = false;
6899 if(item_id != null && item_id >=1000 && item_id < 2000)
6900 itemisalcohol = true;
6901
6902 if( itemisalcohol
6903 && timenow.after(midnight) && timenow.before(eleven30)){
6904 outFields.put("authorised", false);
6905 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6906 " for time "+df.format(timenow.getTime())+
6907 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6908 " and "+df.format(eleven30.getTime()));
6909 return true;
6910 }
6911 else{
6912 outFields.put("authorised", true);
6913 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6914 " for time "+df.format(timenow.getTime()));
6915 return true;
6916 }
6917
6918 /*
6919 This task checks if a sale request is for an item that is an alcoholic drink.
6920 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6921 authorised. Otherwise the sale is authorised.
6922 In this implementation we assume that items with item_ID value between 1000 and
6923 2000 are all alcoholic drinks :-)
6924 */
6925 LE
6926
6927 task create name=MorningBoozeCheckAlt1 version=0.0.1 uuid=bc6d90c9-c902-4686-afd3-925b30e39990 description=LS
6928 This task checks if a sale request is for an item that is an alcoholic drink.
6929 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6930 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6931 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks
6932 LE
6933 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6934 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6935 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6936 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6937 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6938 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6939 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6940 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6941 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6942 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6943 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6944 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6945 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6946 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6947 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6948 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6949 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6950 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6951 task logic create name=MorningBoozeCheckAlt1 version=0.0.1 logicFlavour=MVEL logic=LS
6952 /*
6953 * ============LICENSE_START=======================================================
6954 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6955 * ================================================================================
6956 * Licensed under the Apache License, Version 2.0 (the "License");
6957 * you may not use this file except in compliance with the License.
6958 * You may obtain a copy of the License at
6959 *
6960 * http://www.apache.org/licenses/LICENSE-2.0
6961 *
6962 * Unless required by applicable law or agreed to in writing, software
6963 * distributed under the License is distributed on an "AS IS" BASIS,
6964 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6965 * See the License for the specific language governing permissions and
6966 * limitations under the License.
6967 *
6968 * SPDX-License-Identifier: Apache-2.0
6969 * ============LICENSE_END=========================================================
6970 */
6971 import java.util.Date;
6972 import java.util.Calendar;
6973 import java.util.TimeZone;
6974 import java.text.SimpleDateFormat;
6975
6976 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6977
6978 outFields.put("amount" , inFields.get("amount"));
6979 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6980 outFields.put("notes" , inFields.get("notes"));
6981 outFields.put("quantity" , inFields.get("quantity"));
6982 outFields.put("branch_ID" , inFields.get("branch_ID"));
6983 outFields.put("item_ID" , inFields.get("item_ID"));
6984 outFields.put("time" , inFields.get("time"));
6985 outFields.put("sale_ID" , inFields.get("sale_ID"));
6986
6987 item_id = inFields.get("item_ID");
6988
6989 //The events used later to test this task use CET timezone!
6990 cet = TimeZone.getTimeZone("CET");
6991 timenow = Calendar.getInstance(cet);
6992 df = new SimpleDateFormat("HH:mm:ss z");
6993 df.setTimeZone(cet);
6994 timenow.setTimeInMillis(inFields.get("time"));
6995
6996 midnight = timenow.clone();
6997 midnight.set(
6998 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6999 timenow.get(Calendar.DATE),0,0,0);
7000 onepm = timenow.clone();
7001 onepm.set(
7002 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7003 timenow.get(Calendar.DATE),13,0,0);
7004
7005 itemisalcohol = false;
7006 if(item_id != null && item_id >=1000 && item_id < 2000)
7007 itemisalcohol = true;
7008
7009 if( itemisalcohol &&
7010 ( (timenow.after(midnight) && timenow.before(onepm))
7011 ||
7012 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
7013 )){
7014 outFields.put("authorised", false);
7015 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
7016 " for time "+df.format(timenow.getTime())+
7017 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
7018 " and "+df.format(onepm.getTime()) +" or on Sunday");
7019 return true;
7020 }
7021 else{
7022 outFields.put("authorised", true);
7023 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
7024 " for time "+df.format(timenow.getTime()));
7025 return true;
7026 }
7027
7028 /*
7029 This task checks if a sale request is for an item that is an alcoholic drink.
7030 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
7031 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
7032 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
7033 */
7034 LE
7035
7036 event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS"
7037 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7038 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7039 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
7040 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7041 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7042 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
7043 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7044 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7045 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7046 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7047
7048 event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX"
7049 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7050 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7051 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7052 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7053 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7054 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7055 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7056 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7057
7058
7059 policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide
7060 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
7061 policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL
7062 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheckAlt1 taskName=MorningBoozeCheckAlt1 taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
7063 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
7064 policy state selecttasklogic create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide logicFlavour=JAVASCRIPT logic=LS
7065 /*
7066 * ============LICENSE_START=======================================================
7067 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
7068 * ================================================================================
7069 * Licensed under the Apache License, Version 2.0 (the "License");
7070 * you may not use this file except in compliance with the License.
7071 * You may obtain a copy of the License at
7072 *
7073 * http://www.apache.org/licenses/LICENSE-2.0
7074 *
7075 * Unless required by applicable law or agreed to in writing, software
7076 * distributed under the License is distributed on an "AS IS" BASIS,
7077 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7078 * See the License for the specific language governing permissions and
7079 * limitations under the License.
7080 *
7081 * SPDX-License-Identifier: Apache-2.0
7082 * ============LICENSE_END=========================================================
7083 */
7084
7085 var returnValueType = Java.type("java.lang.Boolean");
7086 var returnValue = new returnValueType(true);
7087
7088 executor.logger.info("Task Selection Execution: '"+executor.subject.id+"'. Input Event: '"+executor.inFields+"'");
7089
7090 branchid = executor.inFields.get("branch_ID");
7091 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
7092 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
7093 taskdef = executor.subject.getDefaultTaskKey();
7094
7095 if(branchid >=0 && branchid <1000){
7096 taskorig.copyTo(executor.selectedTask);
7097 }
7098 else if (branchid >=1000 && branchid <2000){
7099 taskalt.copyTo(executor.selectedTask);
7100 }
7101 else{
7102 taskdef.copyTo(executor.selectedTask);
7103 }
7104
7105 /*
7106 This task selection logic selects task "MorningBoozeCheck" for branches with 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with 1000<=branch_ID<2000. Otherwise the default task is selected. In this case the default task is also "MorningBoozeCheck"
7107 */
7108 LE
7109
7110APEX Logging
7111^^^^^^^^^^^^
7112
7113Introduction to APEX Logging
7114----------------------------
7115
7116 .. container:: paragraph
7117
7118 All APEX components make extensive use of logging using the
7119 logging façade `SLF4J <https://www.slf4j.org/>`__ with the
7120 backend `Logback <https://logback.qos.ch/>`__. Both are used
7121 off-the-shelve, so the standard documentation and
7122 configuration apply to APEX logging. For details on how to
7123 work with logback please see the `logback
7124 manual <https://logback.qos.ch/manual/index.html>`__.
7125
7126 .. container:: paragraph
7127
7128 The APEX applications is the logback configuration file
7129 ``$APEX_HOME/etc/logback.xml`` (Windows:
7130 ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
7131 to no debug, i.e. logs from the logging framework should be
7132 hidden at runtime.
7133
7134 .. container:: paragraph
7135
7136 The configurable log levels work as expected:
7137
7138 .. container:: ulist
7139
7140 - *error* (or *ERROR*) is used for serious errors in the
7141 APEX runtime engine
7142
7143 - *warn* (or *WARN*) is used for warnings, which in general
7144 can be ignored but might indicate some deeper problems
7145
7146 - *info* (or *INFO*) is used to provide generally
7147 interesting messages for startup and policy execution
7148
7149 - *debug* (or *DEBUG*) provides more details on startup and
7150 policy execution
7151
7152 - *trace* (or *TRACE*) gives full details on every aspect
7153 of the APEX engine from start to end
7154
7155 .. container:: paragraph
7156
7157 The loggers can also be configured as expected. The standard
7158 configuration (after installing APEX) uses log level *info*
7159 on all APEX classes (components).
7160
7161 .. container:: paragraph
7162
7163 The applications and scripts in ``$APEX_HOME/bin`` (Windows:
7164 ``%APEX_HOME\bin``) are configured to use the logback
7165 configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
7166 ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
7167 use different logback configurations, for instance:
7168
7169 .. container:: ulist
7170
7171 - Maintain multiple configurations in ``etc``, for instance
7172 a ``logback-debug.xml`` for deep debugging and a
7173 ``logback-production.xml`` for APEX in production mode,
7174 then copy the required configuration file to the used
7175 ``logback.xml`` prior starting APEX
7176
7177 - Edit the scripts in ``bin`` to use a different logback
7178 configuration file (only recommended if you are familiar
7179 with editing bash scripts or windows batch files)
7180
7181Standard Logging Configuration
7182------------------------------
7183
7184 .. container:: paragraph
7185
7186 The standard logging configuration defines a context *APEX*,
7187 which is used in the standard output pattern. The location
7188 for log files is defined in the property ``VAR_LOG`` and set
7189 to ``/var/log/onap/policy/apex-pdp``. The standard status
7190 listener is set to *NOP* and the overall logback
7191 configuration is set to no debug.
7192
7193 .. container:: listingblock
7194
7195 .. container:: content
7196
ramverma760cce92019-07-11 12:57:49 +00007197 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007198 :number-lines:
7199
7200 <configuration debug="false">
7201 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7202
7203 <contextName>Apex</contextName>
7204 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7205
7206 ...appenders
7207 ...loggers
7208 </configuration>
7209
7210.. container:: paragraph
7211
7212 The first appender defined is called ``STDOUT`` for logs to standard
7213 out.
7214
7215.. container:: listingblock
7216
7217 .. container:: content
7218
ramverma760cce92019-07-11 12:57:49 +00007219 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007220 :number-lines:
7221
7222 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7223 <encoder>
7224 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7225 </encoder>
7226 </appender>
7227
7228.. container:: paragraph
7229
7230 The root level logger then is set to the level *info* using the
7231 standard out appender.
7232
7233.. container:: listingblock
7234
7235 .. container:: content
7236
ramverma760cce92019-07-11 12:57:49 +00007237 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007238 :number-lines:
7239
7240 <root level="info">
7241 <appender-ref ref="STDOUT" />
7242 </root>
7243
7244.. container:: paragraph
7245
7246 The second appender is called ``FILE``. It writes logs to a file
7247 ``apex.log``.
7248
7249.. container:: listingblock
7250
7251 .. container:: content
7252
ramverma760cce92019-07-11 12:57:49 +00007253 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007254 :number-lines:
7255
7256 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7257 <file>${VAR_LOG}/apex.log</file>
7258 <encoder>
7259 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7260 </encoder>
7261 </appender>
7262
7263.. container:: paragraph
7264
7265 The third appender is called ``CTXT_FILE``. It writes logs to a file
7266 ``apex_ctxt.log``.
7267
7268.. container:: listingblock
7269
7270 .. container:: content
7271
ramverma760cce92019-07-11 12:57:49 +00007272 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007273 :number-lines:
7274
7275 <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
7276 <file>${VAR_LOG}/apex_ctxt.log</file>
7277 <encoder>
7278 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7279 </encoder>
7280 </appender>
7281
7282.. container:: paragraph
7283
7284 The last definitions are for specific loggers. The first logger
7285 captures all standard APEX classes. It is configured for log level
7286 *info* and uses the standard output and file appenders. The second
7287 logger captures APEX context classes responsible for context
7288 monitoring. It is configured for log level *trace* and uses the
7289 context file appender.
7290
7291.. container:: listingblock
7292
7293 .. container:: content
7294
ramverma760cce92019-07-11 12:57:49 +00007295 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007296 :number-lines:
7297
7298
7299 <logger name="org.onap.policy.apex" level="info" additivity="false">
7300 <appender-ref ref="STDOUT" />
7301 <appender-ref ref="FILE" />
7302 </logger>
7303
7304 <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
7305 <appender-ref ref="CTXT_FILE" />
7306 </logger>
7307
7308Adding Logback Status and Debug
7309-------------------------------
7310
7311 .. container:: paragraph
7312
7313 To activate logback status messages change the status listener
7314 from 'NOP' to for instance console.
7315
7316 .. container:: listingblock
7317
7318 .. container:: content
7319
ramverma760cce92019-07-11 12:57:49 +00007320 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007321
7322 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
7323
7324 .. container:: paragraph
7325
7326 To activate all logback debugging, for instance to debug a new
7327 logback configuration, activate the debug attribute in the
7328 configuration.
7329
7330 .. container:: listingblock
7331
7332 .. container:: content
7333
ramverma760cce92019-07-11 12:57:49 +00007334 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007335
7336 <configuration debug="true">
7337 ...
7338 </configuration>
7339
7340Logging External Components
7341---------------------------
7342
7343 .. container:: paragraph
7344
7345 Logback can also be configured to log any other, external
7346 components APEX is using, if they are using the common logging
7347 framework.
7348
7349 .. container:: paragraph
7350
7351 For instance, the context component of APEX is using *Infinispan*
7352 and one can add a logger for this external component. The
7353 following example adds a logger for *Infinispan* using the
7354 standard output appender.
7355
7356 .. container:: listingblock
7357
7358 .. container:: content
7359
ramverma760cce92019-07-11 12:57:49 +00007360 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007361
7362 <logger name="org.infinispan" level="INFO" additivity="false">
7363 <appender-ref ref="STDOUT" />
7364 </logger>
7365
7366 .. container:: paragraph
7367
7368 Another example is Apache Zookeeper. The following example adds a
7369 logger for Zookeeper using the standard outout appender.
7370
7371 .. container:: listingblock
7372
7373 .. container:: content
7374
ramverma760cce92019-07-11 12:57:49 +00007375 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007376
7377 <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
7378 <appender-ref ref="STDOUT" />
7379 </logger>
7380
7381Configuring loggers for Policy Logic
7382------------------------------------
7383
7384 .. container:: paragraph
7385
7386 The logging for the logic inside a policy (task logic, task
7387 selection logic, state finalizer logic) can be configured separate
7388 from standard logging. The logger for policy logic is
7389 ``org.onap.policy.apex.executionlogging``. The following example
7390 defines
7391
7392 .. container:: ulist
7393
7394 - a new appender for standard out using a very simple pattern
7395 (simply the actual message)
7396
7397 - a logger for policy logic to standard out using the new
7398 appender and the already described file appender.
7399
7400 .. container:: listingblock
7401
7402 .. container:: content
7403
ramverma760cce92019-07-11 12:57:49 +00007404 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007405
7406 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7407 <encoder>
7408 <pattern>policy: %msg\n</pattern>
7409 </encoder>
7410 </appender>
7411
7412 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7413 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7414 <appender-ref ref="FILE" />
7415 </logger>
7416
7417 .. container:: paragraph
7418
7419 It is also possible to use specific logging for parts of policy
7420 logic. The following example defines a logger for task logic.
7421
7422 .. container:: listingblock
7423
7424 .. container:: content
7425
ramverma760cce92019-07-11 12:57:49 +00007426 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007427
7428 <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
7429 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7430 </logger>
7431
7432Rolling File Appenders
7433----------------------
7434
7435 .. container:: paragraph
7436
7437 Rolling file appenders are a good option for more complex logging
7438 of a production or complex testing APEX installation. The standard
7439 logback configuration can be used for these use cases. This
7440 section gives two examples for the standard logging and for
7441 context logging.
7442
7443 .. container:: paragraph
7444
7445 First the standard logging. The following example defines a
7446 rolling file appender. The appender rolls over on a daily basis.
7447 It allows for a file size of 100 MB.
7448
7449 .. container:: listingblock
7450
7451 .. container:: content
7452
ramverma760cce92019-07-11 12:57:49 +00007453 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007454
7455 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
7456 <file>${VAR_LOG}/apex.log</file>
7457 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7458 <!-- rollover daily -->
7459 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
7460 <fileNamePattern>${VAR_LOG}/apex_%d{yyyy-MM-dd}.%i.log.gz
7461 </fileNamePattern>
7462 <maxHistory>4</maxHistory>
7463 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7464 <!-- or whenever the file size reaches 100MB -->
7465 <maxFileSize>100MB</maxFileSize>
7466 </timeBasedFileNamingAndTriggeringPolicy>
7467 </rollingPolicy>
7468 <encoder>
7469 <pattern>
7470 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7471 </pattern>
7472 </encoder>
7473 </appender>
7474
7475 .. container:: paragraph
7476
7477 A very similar configuration can be used for a rolling file
7478 appender logging APEX context.
7479
7480 .. container:: listingblock
7481
7482 .. container:: content
7483
ramverma760cce92019-07-11 12:57:49 +00007484 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007485
7486 <appender name="CTXT-FILE"
7487 class="ch.qos.logback.core.rolling.RollingFileAppender">
7488 <file>${VAR_LOG}/apex_ctxt.log</file>
7489 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7490 <fileNamePattern>${VAR_LOG}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
7491 </fileNamePattern>
7492 <maxHistory>4</maxHistory>
7493 <timeBasedFileNamingAndTriggeringPolicy
7494 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7495 <maxFileSize>100MB</maxFileSize>
7496 </timeBasedFileNamingAndTriggeringPolicy>
7497 </rollingPolicy>
7498 <encoder>
7499 <pattern>
7500 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7501 </pattern>
7502 </encoder>
7503 </appender>
7504
7505Example Configuration for Logging Logic
7506---------------------------------------
7507
7508 .. container:: paragraph
7509
7510 The following example shows a configuration that logs policy logic
7511 to standard out and a file (*info*). All other APEX components are
7512 logging to a file (*debug*).. This configuration an be used in a
7513 pre-production phase with the APEX engine still running in a
7514 separate terminal to monitor policy execution. This logback
7515 configuration is in the APEX installation as
7516 ``etc/logback-logic.xml``.
7517
7518 .. container:: listingblock
7519
7520 .. container:: content
7521
ramverma760cce92019-07-11 12:57:49 +00007522 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007523
7524 <configuration debug="false">
7525 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7526
7527 <contextName>Apex</contextName>
7528 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7529
7530 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7531 <encoder>
7532 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7533 </encoder>
7534 </appender>
7535
7536 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7537 <file>${VAR_LOG}/apex.log</file>
7538 <encoder>
7539 <pattern>
7540 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7541 </pattern>
7542 </encoder>
7543 </appender>
7544
7545 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7546 <encoder>
7547 <pattern>policy: %msg\n</pattern>
7548 </encoder>
7549 </appender>
7550
7551 <root level="error">
7552 <appender-ref ref="STDOUT" />
7553 </root>
7554
7555 <logger name="org.onap.policy.apex" level="debug" additivity="false">
7556 <appender-ref ref="FILE" />
7557 </logger>
7558
7559 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7560 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7561 <appender-ref ref="FILE" />
7562 </logger>
7563 </configuration>
7564
7565Example Configuration for a Production Server
7566---------------------------------------------
7567
7568 .. container:: paragraph
7569
7570 The following example shows a configuration that logs all APEX
7571 components, including policy logic, to a file (*debug*). This
7572 configuration an be used in a production phase with the APEX
7573 engine being executed as a service on a system without console
7574 output. This logback configuration is in the APEX installation as
7575 ``logback-server.xml``
7576
7577 .. container:: listingblock
7578
7579 .. container:: content
7580
ramverma760cce92019-07-11 12:57:49 +00007581 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007582
7583 <configuration debug="false">
7584 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7585
7586 <contextName>Apex</contextName>
7587 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7588
7589 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7590 <file>${VAR_LOG}/apex.log</file>
7591 <encoder>
7592 <pattern>
7593 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7594 </pattern>
7595 </encoder>
7596 </appender>
7597
7598 <root level="debug">
7599 <appender-ref ref="FILE" />
7600 </root>
7601
7602 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
7603 <appender-ref ref="FILE" />
7604 </logger>
7605 </configuration>
7606
7607Building a System with Websocket Backend
7608^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7609
7610Websockets
7611----------
7612
7613 .. container:: paragraph
7614
7615 Websocket is a protocol to run sockets of HTTP. Since it in
7616 essence a socket, the connection is realized between a
7617 server (waiting for connections) and a client (connecting to
7618 a server). Server/client separation is only important for
7619 connection establishment, once connected, everyone can
7620 send/receive on the same socket (as any standard socket
7621 would allow).
7622
7623 .. container:: paragraph
7624
7625 Standard Websocket implementations are simple, no
7626 publish/subscribe and no special event handling. Most
7627 servers simply send all incoming messages to all
7628 connections. There is a PubSub definition on top of
7629 Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
7630 does not support WAMP at the moment.
7631
7632Websocket in Java
7633-----------------
7634
7635 .. container:: paragraph
7636
7637 In Java, `JSR
7638 356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7639 defines the standard Websocket API. This JSR is part of Jave
7640 EE 7 standard. For Java SE, several implementations exist in
7641 open source. Since Websockets are a stable standard and
7642 simple, most implementations are stable and ready to use. A
7643 lot of products support Websockets, like Spring, JBoss,
7644 Netty, … there are also Kafka extensions for Websockets.
7645
7646Websocket Example Code for Websocket clients (FOSS)
7647---------------------------------------------------
7648
7649 .. container:: paragraph
7650
7651 There are a lot of implementations and examples available on
7652 Github for Websocket clients. If one is using Java EE 7,
7653 then one can also use the native Websocket implementation.
7654 Good examples for clients using simply Java SE are here:
7655
7656 .. container:: ulist
7657
7658 - `Websocket
7659 implementation <https://github.com/TooTallNate/Java-WebSocket>`__
7660
7661 - `Websocket sending client example, using
7662 AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
7663
7664 - `Websocket receiving client example (simple echo
7665 client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
7666
7667 .. container:: paragraph
7668
7669 For Java EE, the native Websocket API is explained here:
7670
7671 .. container:: ulist
7672
7673 - `Oracle
7674 docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7675
7676 - link: `An
7677 example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
7678
7679BCP: Websocket Configuration
7680----------------------------
7681
7682 .. container:: paragraph
7683
7684 The probably best is to configure APEX for Websocket servers
7685 for input (ingress, consume) and output (egress, produce)
7686 interfaces. This means that APEX will start Websocket
7687 servers on named ports and wait for clients to connect.
7688 Advantage: once APEX is running all connectivity
7689 infrastructure is running as well. Consequence: if APEX is
7690 not running, everyone else is in the dark, too.
7691
7692 .. container:: paragraph
7693
7694 The best protocol to be used is JSON string. Each event on
7695 any interface is then a string with a JSON encoding. JSON
7696 string is a little bit slower than byte code, but we doubt
7697 that this will be noticeable. A further advantage of JSON
7698 strings over Websockets with APEX starting the servers: it
7699 is very easy to connect web browsers to such a system.
7700 Simple connect the web browser to the APEX sockets and
7701 send/read JSON strings.
7702
7703 .. container:: paragraph
7704
7705 Once APEX is started you simply connect Websocket clients to
7706 it, and send/receive event. When APEX is terminated, the
7707 Websocket servers go down, and the clients will be
7708 disconnected. APEX does not (yet) support auto-client
7709 reconnect nor WAMP, so clients might need to be restarted or
7710 reconnected manually after an APEX boot.
7711
7712Demo with VPN Policy Model
7713--------------------------
7714
7715 .. container:: paragraph
7716
7717 We assume that you have an APEX installation using the full
7718 package, i.e. APEX with all examples, of version ``0.5.6``
7719 or higher. We will use the VPN policy from the APEX examples
7720 here.
7721
7722 .. container:: paragraph
7723
7724 Now, have the following ready to start the demo:
7725
7726 .. container:: ulist
7727
7728 - 3 terminals on the host where APEX is running (we need 1
7729 for APEX and 1 for each client)
7730
7731 - the events in the file
7732 ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
7733 in an editor (we need to send those events to APEX)
7734
7735 - the events in the file
7736 ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
7737 in an editor (we need to send those events to APEX)
7738
7739A Websocket Configuration for the VPN Domain
7740############################################
7741
7742 .. container:: paragraph
7743
7744 Create a new APEX configuration using the VPN policy
7745 model and configuring APEX as discussed above for
7746 Websockets. Copy the following configuration into
7747 ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
7748 (for Windows use
7749 ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
7750
7751 .. container:: listingblock
7752
7753 .. container:: content
7754
ramverma760cce92019-07-11 12:57:49 +00007755 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007756 :number-lines:
7757
7758 {
7759 "engineServiceParameters" : {
7760 "name" : "VPNApexEngine",
7761 "version" : "0.0.1",
7762 "id" : 45,
7763 "instanceCount" : 1,
7764 "deploymentPort" : 12345,
7765 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
7766 "engineParameters" : {
7767 "executorParameters" : {
7768 "MVEL" : {
7769 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
7770 }
7771 },
7772 "contextParameters" : {
7773 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
7774 "schemaParameters":{
7775 "Avro":{
7776 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
7777 }
7778 }
7779 }
7780 }
7781 },
7782 "producerCarrierTechnologyParameters" : {
7783 "carrierTechnology" : "WEBSOCKET",
7784 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7785 "parameters" : {
7786 "wsClient" : false,
7787 "port" : 42452
7788 }
7789 },
7790 "producerEventProtocolParameters" : {
7791 "eventProtocol" : "JSON"
7792 },
7793 "consumerCarrierTechnologyParameters" : {
7794 "carrierTechnology" : "WEBSOCKET",
7795 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7796 "parameters" : {
7797 "wsClient" : false,
7798 "port" : 42450
7799 }
7800 },
7801 "consumerEventProtocolParameters" : {
7802 "eventProtocol" : "JSON"
7803 }
7804 }
7805
7806Start APEX Engine
7807#################
7808
7809 .. container:: paragraph
7810
7811 In a new terminal, start APEX with the new configuration for
7812 Websocket-Server ingress/egress:
7813
7814 .. container:: listingblock
7815
7816 .. container:: content
7817
ramverma760cce92019-07-11 12:57:49 +00007818 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007819 :number-lines:
7820
7821 #: $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
7822
7823.. container:: listingblock
7824
7825 .. container:: content
7826
ramverma760cce92019-07-11 12:57:49 +00007827 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007828 :number-lines:
7829
7830 #: %APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
7831
7832.. container:: paragraph
7833
7834 Wait for APEX to start, it takes a while to create all Websocket
7835 servers (about 8 seconds on a standard laptop without cached
7836 binaries). depending on your log messages, you will see no (some, a
7837 lot) log messages. If APEX starts correctly, the last few messages
7838 you should see are:
7839
7840.. container:: listingblock
7841
7842 .. container:: content
7843
ramverma760cce92019-07-11 12:57:49 +00007844 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007845 :number-lines:
7846
7847 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)
7848 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 ...
7849 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
7850 Started Apex service
7851
7852.. container:: paragraph
7853
7854 APEX is running in the new terminal and will produce output when the
7855 policy is triggered/executed.
7856
7857Run the Websocket Echo Client
7858#############################
7859
7860 .. container:: paragraph
7861
7862 The echo client is included in an APEX full installation. To run
7863 the client, open a new shell (Unix, Cygwin) or command prompt
7864 (``cmd`` on Windows). Then use the APEX application launcher to
7865 start the client.
7866
7867 .. important::
7868 APEX engine needs to run first
ramverma760cce92019-07-11 12:57:49 +00007869 The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
ramverma3b71c972019-07-10 11:25:37 +00007870
7871 +---------------------------------------------------------+-----------------------------------------------------------+
7872 | Unix, Cygwin | Windows |
7873 +=========================================================+===========================================================+
7874 | .. container:: | .. container:: |
7875 | | |
7876 | .. container:: listingblock | .. container:: listingblock |
7877 | | |
7878 | .. container:: content | .. container:: content |
7879 | | |
7880 | .. code:: | .. code:: |
7881 | | |
7882 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
7883 +---------------------------------------------------------+-----------------------------------------------------------+
7884
7885 .. container:: paragraph
7886
7887 Use the following command line arguments for server and port of
7888 the Websocket server. The port should be the same as configured in
7889 the APEX engine. The server host should be the host on which the
7890 APEX engine is running
7891
7892 .. container:: ulist
7893
7894 - ``-p`` defines the Websocket port to connect to (defaults to
7895 ``8887``)
7896
7897 - ``-s`` defines the host on which a Websocket server is running
7898 (defaults to ``localhost``)
7899
7900 .. container:: paragraph
7901
7902 Let’s assume that there is an APEX engine running, configured for
7903 produce Websocket carrier technology, as server, for port 42452,
7904 with produce event protocol JSON,. If we start the console client
7905 on the same host, we can omit the ``-s`` options. We start the
7906 console client as:
7907
7908 .. container:: listingblock
7909
7910 .. container:: content
7911
ramverma760cce92019-07-11 12:57:49 +00007912 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007913
7914 # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
7915 > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
7916
7917 .. container:: colist arabic
7918
7919 +-------+--------------------------------+
7920 | **1** | Start client on Unix or Cygwin |
7921 +-------+--------------------------------+
7922 | **2** | Start client on Windows |
7923 +-------+--------------------------------+
7924
7925 .. container:: paragraph
7926
7927 Once started successfully, the client will produce the following
7928 messages (assuming we used ``-p 42452`` and an APEX engine is
7929 running on ``localhost`` with the same port:
7930
7931 .. container:: listingblock
7932
7933 .. container:: content
7934
ramverma760cce92019-07-11 12:57:49 +00007935 .. code::
ramverma3b71c972019-07-10 11:25:37 +00007936
7937 ws-simple-echo: starting simple event echo
7938 --> server: localhost
7939 --> port: 42452
7940
7941 Once started, the application will simply print out all received events to standard out.
7942 Each received event will be prefixed by '---' and suffixed by '===='
7943
7944
7945 ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
7946
7947Run the Websocket Console Client
7948################################
7949
7950 .. container:: paragraph
7951
7952 The console client is included in an APEX full installation. To
7953 run the client, open a new shell (Unix, Cygwin) or command prompt
7954 (``cmd`` on Windows). Then use the APEX application launcher to
7955 start the client.
7956
7957 .. important::
7958 APEX engine needs to run first
ramverma760cce92019-07-11 12:57:49 +00007959 The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
7960 protocol is executed first.
ramverma3b71c972019-07-10 11:25:37 +00007961
7962 +------------------------------------------------------------+--------------------------------------------------------------+
7963 | Unix, Cygwin | Windows |
7964 +============================================================+==============================================================+
7965 | .. container:: | .. container:: |
7966 | | |
7967 | .. container:: listingblock | .. container:: listingblock |
7968 | | |
7969 | .. container:: content | .. container:: content |
7970 | | |
7971 | .. code:: | .. code:: |
7972 | | |
7973 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
7974 +------------------------------------------------------------+--------------------------------------------------------------+
7975
7976 .. container:: paragraph
7977
7978 Use the following command line arguments for server and port of
7979 the Websocket server. The port should be the same as configured in
7980 the APEX engine. The server host should be the host on which the
7981 APEX engine is running
7982
7983 .. container:: ulist
7984
7985 - ``-p`` defines the Websocket port to connect to (defaults to
7986 ``8887``)
7987
7988 - ``-s`` defines the host on which a Websocket server is running
7989 (defaults to ``localhost``)
7990
7991 .. container:: paragraph
7992
7993 Let’s assume that there is an APEX engine running, configured for
7994 consume Websocket carrier technology, as server, for port 42450,
7995 with consume event protocol JSON,. If we start the console client
7996 on the same host, we can omit the ``-s`` options. We start the
7997 console client as:
7998
7999 .. container:: listingblock
8000
8001 .. container:: content
8002
ramverma760cce92019-07-11 12:57:49 +00008003 .. code::
ramverma3b71c972019-07-10 11:25:37 +00008004
8005 # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
8006 > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
8007
8008 .. container:: colist arabic
8009
8010 +-------+--------------------------------+
8011 | **1** | Start client on Unix or Cygwin |
8012 +-------+--------------------------------+
8013 | **2** | Start client on Windows |
8014 +-------+--------------------------------+
8015
8016 .. container:: paragraph
8017
8018 Once started successfully, the client will produce the following
8019 messages (assuming we used ``-p 42450`` and an APEX engine is
8020 running on ``localhost`` with the same port:
8021
8022 .. container:: listingblock
8023
8024 .. container:: content
8025
ramverma760cce92019-07-11 12:57:49 +00008026 .. code::
ramverma3b71c972019-07-10 11:25:37 +00008027
8028 ws-simple-console: starting simple event console
8029 --> server: localhost
8030 --> port: 42450
8031
8032 - terminate the application typing 'exit<enter>' or using 'CTRL+C'
8033 - events are created by a non-blank starting line and terminated by a blank line
8034
8035
8036 ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
8037
8038Send Events
8039###########
8040
8041 .. container:: paragraph
8042
8043 Now you have the full system up and running:
8044
8045 .. container:: ulist
8046
8047 - Terminal 1: APEX ready and loaded
8048
8049 - Terminal 2: an echo client, printing received messages produced
8050 by the VPN policy
8051
8052 - Terminal 2: a console client, waiting for input on the console
8053 (standard in) and sending text to APEX
8054
8055 .. container:: paragraph
8056
8057 We started the engine with the VPN policy example. So all the
8058 events we are using now are located in files in the following
8059 example directory:
8060
8061 .. container:: listingblock
8062
8063 .. container:: content
8064
ramverma760cce92019-07-11 12:57:49 +00008065 .. code::
ramverma3b71c972019-07-10 11:25:37 +00008066 :number-lines:
8067
8068 #: $APEX_HOME/examples/events/VPN
8069 > %APEX_HOME%\examples\events\VPN
8070
8071.. container:: paragraph
8072
8073 To sends events, simply copy the content of the event files into
8074 Terminal 3 (the console client). It will read multi-line JSON text
8075 and send the events. So copy the content of ``SetupEvents.json`` into
8076 the client. APEX will trigger a policy and produce some output, the
8077 echo client will also print some events created in the policy. In
8078 Terminal 1 (APEX) you’ll see some status messages from the policy as:
8079
8080.. container:: listingblock
8081
8082 .. container:: content
8083
ramverma760cce92019-07-11 12:57:49 +00008084 .. code::
ramverma3b71c972019-07-10 11:25:37 +00008085 :number-lines:
8086
8087 {Link=L09, LinkUp=true}
8088 L09 true
8089 outFields: {Link=L09, LinkUp=true}
8090 {Link=L10, LinkUp=true}
8091 L09 true
8092 L10 true
8093 outFields: {Link=L10, LinkUp=true}
8094 {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8095 *** Customers ***
8096 C 300 300 [L09, L10]
8097 outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8098 {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8099 *** Customers ***
8100 A 300 50 [L09, L10]
8101 C 300 300 [L09, L10]
8102 outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8103 {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8104 *** Customers ***
8105 A 300 50 [L09, L10]
8106 C 300 300 [L09, L10]
8107 D 300 400 [L09, L10]
8108 outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8109 {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8110 *** Customers ***
8111 A 300 50 [L09, L10]
8112 B 300 299 [L09, L10]
8113 C 300 300 [L09, L10]
8114 D 300 400 [L09, L10]
8115 outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8116
8117.. container:: paragraph
8118
8119 In Terminal 2 (echo-client) you see the received events, the last two
8120 should look like:
8121
8122.. container:: listingblock
8123
8124 .. container:: content
8125
ramverma760cce92019-07-11 12:57:49 +00008126 .. code::
ramverma3b71c972019-07-10 11:25:37 +00008127 :number-lines:
8128
8129 ws-simple-echo: received
8130 ---------------------------------
8131 {
8132 "name": "VPNCustomerCtxtActEvent",
8133 "version": "0.0.1",
8134 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8135 "source": "Source",
8136 "target": "Target",
8137 "CustomerName": "C",
8138 "LinkList": "L09 L10",
8139 "SlaDT": 300,
8140 "YtdDT": 300
8141 }
8142 =================================
8143
8144 ws-simple-echo: received
8145 ---------------------------------
8146 {
8147 "name": "VPNCustomerCtxtActEvent",
8148 "version": "0.0.1",
8149 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8150 "source": "Source",
8151 "target": "Target",
8152 "CustomerName": "D",
8153 "LinkList": "L09 L10",
8154 "SlaDT": 300,
8155 "YtdDT": 400
8156 }
8157 =================================
8158
8159.. container:: paragraph
8160
8161 Congratulations, you have triggered a policy in APEX using
8162 Websockets, the policy did run through, created events, picked up by
8163 the echo-client.
8164
8165.. container:: paragraph
8166
8167 Now you can send the Link 09 and Link 10 events, they will trigger
8168 the actual VPN policy and some calculations are made. Let’s take the
8169 Link 09 events from ``Link09Events.json``, copy them all into
8170 Terminal 3 (the console). APEX will run the policy (with some status
8171 output), and the echo client will receive and print events.
8172
8173.. container:: paragraph
8174
8175 To terminate the applications, simply press ``CTRL+C`` in Terminal 1
8176 (APEX). This will also terminate the echo-client in Terminal 2. Then
8177 type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
8178 console-client.
8179
8180.. container::
8181 :name: footer
8182
8183 .. container::
8184 :name: footer-text
8185
8186 2.0.0-SNAPSHOT
8187 Last updated 2018-09-10 15:38:16 IST
8188
8189.. |Extract the TAR archive| image:: images/install-guide/win-extract-tar-gz.png
8190.. |Extract the APEX distribution| image:: images/install-guide/win-extract-tar.png
8191.. |REST Editor Start Screen| image:: images/install-guide/rest-start.png
8192.. |REST Editor with loaded SampleDomain Policy Model| image:: images/install-guide/rest-loaded.png
8193.. |APEX Configuration Matrix| image:: images/apex-intro/ApexEngineConfig.png
8194.. |File > New to create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel1.png
8195.. |Create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel2.png
8196.. |Right click to create a new event| image:: images/mfp/MyFirstPolicy_P1_newEvent1.png
8197.. |Fill in the necessary information for the 'SALE_INPUT' event and click 'Submit'| image:: images/mfp/MyFirstPolicy_P1_newEvent2.png
8198.. |Right click to create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema1.png
8199.. |Create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema2.png
8200.. |Add new event parameters to an event| image:: images/mfp/MyFirstPolicy_P1_newEvent3.png
8201.. |Right click to create a new task| image:: images/mfp/MyFirstPolicy_P1_newTask1.png
8202.. |Add input and out fields for the task| image:: images/mfp/MyFirstPolicy_P1_newTask2.png
8203.. |Add task logic the task| image:: images/mfp/MyFirstPolicy_P1_newTask3.png
8204.. |Create a new policy| image:: images/mfp/MyFirstPolicy_P1_newPolicy1.png
8205.. |Create a state| image:: images/mfp/MyFirstPolicy_P1_newState1.png
8206.. |Add a Task and Output Mapping| image:: images/mfp/MyFirstPolicy_P1_newState2.png
8207.. |Validate the policy model for error using the 'Model' > 'Validate' menu item| image:: images/mfp/MyFirstPolicy_P1_validatePolicyModel.png
8208.. |Download the completed policy model using the 'File' > 'Download' menu item| image:: images/mfp/MyFirstPolicy_P1_exportPolicyModel1.png
8209.. |Create a new alternative task MorningBoozeCheckAlt1| image:: images/mfp/MyFirstPolicy_P2_newTask1.png
8210.. |Right click to edit a policy| image:: images/mfp/MyFirstPolicy_P2_editPolicy1.png
8211.. |State definition with 2 Tasks and Task Selection Logic| image:: images/mfp/MyFirstPolicy_P2_editState1.png
8212