1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
17 .. container:: paragraph
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
25 Installation Requirements
26 #########################
30 - Downloaded distribution: JAVA runtime environment
31 (JRE, Java 8 or later, APEX is tested with the
34 - Building from source: JAVA development kit (JDK,
35 Java 8 or later, APEX is tested with the Oracle
38 - A web archive capable webserver, for instance for
39 the monitoring application
43 - for instance `Apache
44 Tomcat <https://tomcat.apache.org/>`__
46 - Sufficient rights to install APEX on the system
48 - Installation tools depending on the installation
53 - ZIP to extract from a ZIP distribution
57 - Windows for instance
58 `7Zip <http://www.7-zip.org/>`__
60 - TAR and GZ to extract from that TAR.GZ
65 - Windows for instance
66 `7Zip <http://www.7-zip.org/>`__
68 - RPM to install from the RPM distribution
72 - Install: ``sudo apt-get install rpm``
74 - DPKG to install from the DEB distribution
78 - Install: ``sudo apt-get install dpkg``
83 .. container:: paragraph
85 APEX supports a number of features that require extra
86 software being installed.
90 - `Apache Kafka <https://kafka.apache.org/>`__ to
91 connect APEX to a Kafka message bus
93 - `Hazelcast <https://hazelcast.com/>`__ to use
94 distributed hash maps for context
96 - `Infinispan <http://infinispan.org/>`__ for
97 distributed context and persistence
99 - `Docker <https://www.docker.com/>`__ to run APEX
100 inside a Docker container
102 Build (Install from Source) Requirements
103 ########################################
105 .. container:: paragraph
107 Installation from source requires a few development
112 - GIT to retrieve the source code
114 - Java SDK, Java version 8 or later
116 - Apache Maven 3 (the APEX build environment)
118 Get the APEX Source Code
119 ------------------------
121 .. container:: paragraph
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.
128 .. container:: paragraph
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.
134 .. container:: listingblock
136 .. container:: content
141 git clone https://gerrit.onap.org/r/policy/apex-pdp
146 .. container:: paragraph
148 The examples in this document assume that the APEX source
149 repositories are cloned to:
153 - Unix, Cygwin: ``/usr/local/src/apex-pdp``
155 - Windows: ``C:\dev\apex-pdp``
157 - Cygwin: ``/cygdrive/c/dev/apex-pdp``
160 A Build requires ONAP Nexus
161 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>`__.
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
170 A Build requires Internet (for first build)
171 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
176 Building RPM distributions
177 RPM images are only build if the ``rpm`` package is installed (Unix). To install ``rpm`` run ``sudo apt-get install rpm``,
180 .. container:: paragraph
182 Use Maven to for a standard build without any tests.
184 +-------------------------------------------------------+--------------------------------------------------------+
185 | Unix, Cygwin | Windows |
186 +=======================================================+========================================================+
187 | .. container:: | .. container:: |
189 | .. container:: content | .. container:: content |
191 | .. code:: | .. code:: |
192 | :number-lines: | :number-lines: |
194 | # cd /usr/local/src/apex-pdp | >c: |
195 | # mvn clean install -DskipTest | >cd \dev\apex |
196 | | >mvn clean install -DskipTests |
197 +-------------------------------------------------------+--------------------------------------------------------+
199 .. container:: paragraph
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
205 .. container:: paragraph
207 When Maven is finished with the build, the final screen should look
208 similar to this (omitting some ``success`` lines):
210 .. container:: listingblock
212 .. container:: content
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] ------------------------------------------------------------------------
226 [INFO] ------------------------------------------------------------------------
227 [INFO] Total time: 03:43 min
228 [INFO] Finished at: 2018-09-03T11:56:01+01:00
229 [INFO] ------------------------------------------------------------------------
231 .. container:: paragraph
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.
237 +----------------------------------------------------------------------------------------------------------------------------+
239 +============================================================================================================================+
242 | .. container:: listingblock |
244 | .. container:: content |
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 +----------------------------------------------------------------------------------------------------------------------------+
266 +--------------------------------------------------------------------------------------------------------+
268 +========================================================================================================+
271 | .. container:: listingblock |
273 | .. container:: content |
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 +--------------------------------------------------------------------------------------------------------+
302 .. container:: paragraph
304 APEX can be installed in different ways:
308 - Unix: automatically using ``rpm`` or ``dpkg`` from ``.rpm`` or
311 - Windows, Unix, Cygwin: manually from a ``.tar.gz`` archive
313 - Windows, Unix, Cygwin: build from source using Maven, then
316 Install with RPM and DPKG
317 #########################
319 .. container:: paragraph
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``.
327 .. container:: paragraph
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
335 +-----------------------------------------------------------------------+
337 +=======================================================================+
340 | .. container:: listingblock |
342 | .. container:: content |
347 | # sudo rpm -i apex-pdp-package-full-2.0.0-SNAPSHOT.rpm |
348 | ********************preinst******************* |
350 | ********************************************** |
351 | creating group apexuser . . . |
352 | creating user apexuser . . . |
353 | ********************postinst**************** |
355 | *********************************************** |
356 +-----------------------------------------------------------------------+
358 +--------------------------------------------------------------------------------------+
359 | DPKG Installation |
360 +======================================================================================+
363 | .. container:: listingblock |
365 | .. container:: content |
370 | # sudo dpkg -i apex-pdp-package-full-2.0.0-SNAPSHOT.deb |
371 | 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 +--------------------------------------------------------------------------------------+
386 .. container:: paragraph
388 Once the installation is finished, APEX is fully installed and ready
391 Install Manually from Archive (Unix, Cygwin)
392 ############################################
394 .. container:: paragraph
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.
401 .. container:: listingblock
403 .. container:: content
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
415 Install Manually from Archive (Windows, 7Zip, GUI)
416 ##################################################
418 .. container:: paragraph
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.
425 .. container:: imageblock
427 .. container:: content
429 |Extract the TAR archive|
431 .. container:: paragraph
433 The right-click on the new created TAR file and extract the actual
436 .. container:: imageblock
438 .. container:: content
440 |Extract the APEX distribution|
442 .. container:: paragraph
444 Inside the new APEX folder you see the main directories: ``bin``,
445 ``etc``, ``examples``, ``lib``, and ``war``
447 .. container:: paragraph
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.
453 Install Manually from Archive (Windows, 7Zip, CMD)
454 ##################################################
456 .. container:: paragraph
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
465 .. container:: listingblock
467 .. container:: content
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"
476 .. container:: paragraph
478 APEX is now installed in the folder
479 ``C:\apex\apex-full-2.0.0-SNAPSHOT``.
484 Build and Install Manually (Unix, Windows, Cygwin)
485 ##################################################
487 .. container:: paragraph
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
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.
500 .. container:: paragraph
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:
508 - Unix, Cygwin: ``/usr/local/src/apex``
510 - Windows: ``C:\dev\apex``
512 +-------------------------------------------------------+--------------------------------------------------------+
513 | Unix, Cygwin | Windows |
514 +=======================================================+========================================================+
515 | .. container:: | .. container:: |
517 | .. container:: content | .. container:: content |
519 | .. code:: | .. code:: |
520 | :number-lines: | :number-lines: |
522 | # cd /usr/local/src/apex | >c: |
523 | # mvn clean install -DskipTests | >cd \dev\apex |
524 | | >mvn clean install -DskipTests |
525 +-------------------------------------------------------+--------------------------------------------------------+
527 .. container:: paragraph
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.
536 .. container:: paragraph
538 When Maven is finished with the build, the final screen should look
539 similar to this (omitting some ``success`` lines):
541 .. container:: listingblock
543 .. container:: content
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] ------------------------------------------------------------------------
557 [INFO] ------------------------------------------------------------------------
558 [INFO] Total time: 03:43 min
559 [INFO] Finished at: 2018-09-03T11:56:01+01:00
560 [INFO] ------------------------------------------------------------------------
562 .. container:: paragraph
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.
568 +-----------------------------------------------------------------------------------------------------------------------------+
570 +=============================================================================================================================+
573 | .. container:: listingblock |
578 | # cd packages/apex-pdp-package-full/target |
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 +-----------------------------------------------------------------------------------------------------------------------------+
597 +-----------------------------------------------------------------------------------------------------------------------------+
599 +=============================================================================================================================+
602 | .. container:: listingblock |
607 | >cd packages\apex-pdp-package-full\target |
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 +-----------------------------------------------------------------------------------------------------------------------------+
630 .. container:: paragraph
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.
639 .. container:: paragraph
641 A full installation of APEX comes with the following layout.
643 .. container:: listingblock
645 .. container:: content
664 │ └───applications (11)
667 .. container:: colist arabic
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 |
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 |
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 |
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 |
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 +-----------------------------------+-----------------------------------+
718 .. container:: paragraph
720 Once APEX is installed, a few configurations need to be done:
724 - Create an APEX user and an APEX group (optional, if not
725 installed using RPM and DPKG)
727 - Create environment settings for ``APEX_HOME`` and
728 ``APEX_USER``, required by the start scripts
730 - Change settings of the logging framework (optional)
732 - Create directories for logging, required (execution might fail
733 if directories do not exist or cannot be created)
738 .. container:: paragraph
740 On smaller installations and test systems, APEX can run as any
743 .. container:: paragraph
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
751 .. container:: paragraph
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
759 .. container:: listingblock
761 .. container:: content
766 # sudo groupadd apexuser
767 # sudo useradd -g apexuser apexuser
768 # sudo chown -R apexuser:apexuser <apex-dir>
770 .. container:: paragraph
772 For other operating systems please consult your manual or system
775 Environment Settings: APEX_HOME and APEX_USER
776 #############################################
778 .. container:: paragraph
780 The provided start scripts for APEX require two environment
785 - ``APEX_USER`` with the user under whos name and permission APEX
786 should be started (Unix only)
788 - ``APEX_HOME`` with the directory where APEX is installed (Unix,
791 .. container:: paragraph
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.
798 +------------------------------------------------+---------------------------------------------------------+
799 | Unix, Cygwin (bash/tcsh) | Windows |
800 +================================================+=========================================================+
801 | .. container:: | .. container:: |
803 | .. container:: content | .. container:: content |
805 | .. code:: | .. code:: |
806 | :number-lines: | :number-lines: |
808 | # export APEX_USER=apexuser | >set APEX_HOME=C:\apex\apex-full-2.0.0-SNAPSHOT |
809 | # cd /opt/app/policy/apex-pdp | |
810 | # export APEX_HOME=`pwd` | |
812 +------------------------------------------------+ |
815 | .. container:: content | |
820 | # setenv APEX_USER apexuser | |
821 | # cd /opt/app/policy/apex-pdp | |
822 | # setenv APEX_HOME `pwd` | |
824 +------------------------------------------------+---------------------------------------------------------+
825 | .. container:: | .. container:: |
827 | .. container:: content | .. container:: content |
829 | .. code:: | .. code:: |
830 | :number-lines: | :number-lines: |
832 | # env | grep APEX | >set APEX_HOME |
833 | # APEX_USER=apexuser | APEX_HOME=\apex\apex-full-2.0.0-SNAPSHOT |
834 | # APEX_HOME=/opt/app/policy/apex-pdp | |
836 +------------------------------------------------+---------------------------------------------------------+
838 Making Environment Settings Permanent (Unix, Cygwin)
839 ====================================================
841 .. container:: paragraph
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).
847 Making Environment Settings Permanent (Windows)
848 ===============================================
850 .. container:: paragraph
856 - Click on the **Start** Menu
858 - Right click on **Computer**
860 - Select **Properties**
862 .. container:: paragraph
868 - Click on the **Start** Menu
872 .. container:: paragraph
874 Then do the following
878 - Select **Advanced System Settings**
880 - On the **Advanced** tab, click the **Environment Variables**
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"
887 .. container:: paragraph
889 For the settings to take effect, an application needs to be
890 restarted (e.g. any open ``cmd`` window).
892 Edit the APEX Logging Settings
893 ##############################
895 .. container:: paragraph
897 Configure the APEX logging settings to your requirements, for
902 - change the directory where logs are written to, or
904 - change the log levels
906 .. container:: paragraph
908 Edit the file ``$APEX_HOME/etc/logback.xml`` for any required
909 changes. To change the log directory change the line
911 .. container:: paragraph
913 ``<property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />``
915 .. container:: paragraph
919 .. container:: paragraph
921 ``<property name="VAR_LOG" value="/PATH/TO/LOG/DIRECTORY/" />``
923 .. container:: paragraph
925 On Windows, it is recommended to change the log directory to:
927 .. container:: paragraph
929 ``<property name="VAR_LOG" value="C:/apex/apex-full-2.0.0-SNAPSHOT/logs" />``
931 .. container:: paragraph
933 Note: Be careful about when to use ``\`` vs. ``/`` as the path
936 Create Directories for Logging
937 ##############################
939 .. container:: paragraph
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).
945 +------------------------------------------------------------------+-------------------------------------------------------+
946 | Unix, Cygwin | Windows |
947 +==================================================================+=======================================================+
948 | .. container:: | .. container:: |
950 | .. container:: content | .. container:: content |
952 | .. code:: | .. code:: |
953 | :number-lines: | :number-lines: |
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 +------------------------------------------------------------------+-------------------------------------------------------+
959 Verify the APEX Installation
960 ----------------------------
962 .. container:: paragraph
964 When APEX is installed and all settings are realized, the
965 installation can be verified.
967 Verify Installation - run Engine
968 ################################
970 .. container:: paragraph
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.
980 .. container:: listingblock
982 .. container:: content
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...]
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
1002 -v,--version outputs the version of Apex
1004 Verify Installation - run an Example
1005 ####################################
1007 .. container:: paragraph
1009 A full APEX installation comes with several examples. Here, we can
1010 fully verify the installation by running one of the examples.
1012 .. container:: paragraph
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.
1020 .. container:: listingblock
1022 .. container:: content
1027 # $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)
1031 .. container:: colist arabic
1041 .. container:: paragraph
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)
1047 .. container:: listingblock
1049 .. container:: content
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
1069 .. container:: paragraph
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.
1074 .. container:: paragraph
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
1080 .. container:: paragraph
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.
1088 +-------------------------------------------------------------+-------------------------------------------------------------+
1089 | Input Event | Example Output Event |
1090 +=============================================================+=============================================================+
1091 | .. container:: | .. container:: |
1093 | .. container:: content | .. container:: content |
1095 | .. code:: | .. code:: |
1096 | :number-lines: | :number-lines: |
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 |
1117 +-------------------------------------------------------------+-------------------------------------------------------------+
1119 .. container:: paragraph
1121 Terminate APEX by simply using ``CTRL+C`` in the console.
1123 Verify a Full Installation - REST Editor
1124 ########################################
1126 .. container:: paragraph
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
1133 .. container:: listingblock
1135 .. container:: content
1140 # $APEX_HOME/bin/apexApps.sh rest-editor
1142 .. container:: listingblock
1144 .. container:: content
1149 >%APEX_HOME%\bin\apexApps.bat rest-editor
1151 .. container:: paragraph
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
1159 .. container:: listingblock
1161 .. container:: content
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/
1173 .. container:: paragraph
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
1180 .. container:: imageblock
1182 .. container:: content
1184 |REST Editor Start Screen|
1186 .. container:: title
1188 Figure 1. REST Editor Start Screen
1190 .. container:: paragraph
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.
1199 .. container:: imageblock
1201 .. container:: content
1203 |REST Editor with loaded SampleDomain Policy Model|
1205 .. container:: title
1207 Figure 2. REST Editor with loaded SampleDomain Policy Model
1209 .. container:: paragraph
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.
1215 Installing WAR Applications
1216 ---------------------------
1218 .. container:: paragraph
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).
1226 .. container:: paragraph
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.
1233 .. container:: paragraph
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
1240 .. container:: paragraph
1242 There are multiple ways to install the APEX WAR applications:
1244 .. container:: ulist
1246 - copy the ``.war`` file into the Tomcat ``webapps`` folder
1248 - use the Tomcat ``Manager App`` to deploy via the web interface
1250 - deploy using a REST call to Tomcat
1252 .. container:: paragraph
1254 For details on how to install ``war`` files please consult the
1256 Documentation <https://tomcat.apache.org/tomcat-9.0-doc/index.html>`__
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.
1264 .. container:: paragraph
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.
1270 .. container:: paragraph
1272 The current APEX version provides the following WAR applications:
1274 .. container:: ulist
1276 - client-deployment-2.0.0-SNAPSHOT.war - a client to deploy new
1277 policy models to a running engine
1279 - client-editor-2.0.0-SNAPSHOT.war - the standard policy REST
1282 - client-monitoring-2.0.0-SNAPSHOT.war - a client for monitoring
1283 a running APEX engine
1285 - client-full-2.0.0-SNAPSHOT.war - a full client with a
1286 one-stop-access to deployment, monitoring, and REST editor
1288 - examples-servlet-2.0.0-SNAPSHOT.war - an example APEX servlet
1290 Running APEX in Docker
1291 ----------------------
1293 .. container:: paragraph
1295 Since APEX is in ONAP, we provide a full virtualization
1296 environment for the engine.
1301 .. container:: paragraph
1303 Running APEX from the ONAP docker repository only requires 2
1306 .. container:: olist arabic
1308 #. Log into the ONAP docker repo
1310 .. container:: listingblock
1312 .. container:: content
1316 docker login -u docker -p docker nexus3.onap.org:10003
1318 .. container:: olist arabic
1320 #. Run the APEX docker image
1322 .. container:: listingblock
1324 .. container:: content
1328 docker run -it --rm nexus3.onap.org:10003/onap/policy-apex-pdp:latest
1330 Build a Docker Image
1331 ####################
1333 .. container:: paragraph
1335 Alternatively, one can use the Dockerfile defined in the Docker
1336 package to build an image.
1338 .. container:: listingblock
1340 .. container:: title
1344 .. container:: content
1350 # Docker file to build an image that runs APEX on Java 8 in Ubuntu
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 && \
1359 apt-get install -y openjdk-8-jdk
1361 # Create apex user and group
1362 RUN groupadd apexuser
1363 RUN useradd --create-home -g apexuser apexuser
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
1370 # Unpack the tarball
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
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/*
1381 # Copy examples to Apex user area
1382 RUN cp -pr /opt/app/policy/apex-pdp/examples /home/apexuser
1386 RUN chown -R apexuser:apexuser /home/apexuser/*
1389 ENV PATH /opt/app/policy/apex-pdp/bin:$PATH
1390 WORKDIR /home/apexuser
1392 APEX Configurations Explained
1393 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1395 Introduction to APEX Configuration
1396 ----------------------------------
1398 .. container:: paragraph
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.
1409 .. container:: imageblock
1411 .. container:: content
1413 |APEX Configuration Matrix|
1415 .. container:: title
1417 Figure 3. APEX Configuration Matrix
1419 .. container:: paragraph
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.
1426 General Configuration Format
1427 ----------------------------
1429 .. container:: paragraph
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:
1436 .. container:: listingblock
1438 .. container:: content
1443 "engineServiceParameters":{
1445 "engineParameters":{ (2)
1446 "engineParameters":{...}, (3)
1447 "contextParameters":{...} (4)
1450 "eventInputParameters":{ (5)
1452 "carrierTechnologyParameters":{...},
1453 "eventProtocolParameters":{...}
1456 "carrierTechnologyParameters":{...},
1457 "eventProtocolParameters":{...}
1461 "eventOutputParameters":{ (9)
1463 "carrierTechnologyParameters":{...},
1464 "eventProtocolParameters":{...}
1467 "carrierTechnologyParameters":{...},
1468 "eventProtocolParameters":{...}
1474 .. container:: colist arabic
1476 +-----------------------------------+-----------------------------------+
1477 | **1** | main engine configuration |
1478 +-----------------------------------+-----------------------------------+
1479 | **2** | engine parameters for plugin |
1480 | | configurations (execution |
1481 | | environments and context |
1483 +-----------------------------------+-----------------------------------+
1484 | **3** | engine specific parameters, |
1485 | | mainly for executor plugins |
1486 +-----------------------------------+-----------------------------------+
1487 | **4** | context specific parameters, e.g. |
1488 | | for context schemas, persistence, |
1490 +-----------------------------------+-----------------------------------+
1491 | **5** | configuration of the input |
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 |
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 +-----------------------------------+-----------------------------------+
1518 Engine Service Parameters
1519 -------------------------
1521 .. container:: paragraph
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.
1527 .. container:: listingblock
1529 .. container:: content
1533 "engineServiceParameters" : {
1534 "name" : "AADMApexEngine", (1)
1535 "version" : "0.0.1", (2)
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)
1547 .. container:: colist arabic
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/>`_ |
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 |
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 |
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 |
1589 +-----------------------------------+-----------------------------------+
1590 | **8** | engine parameters for plugin |
1591 | | configurations (execution |
1592 | | environments and context |
1594 +-----------------------------------+-----------------------------------+
1595 | **9** | engine specific parameters, |
1596 | | mainly for executor plugins |
1597 +-----------------------------------+-----------------------------------+
1598 | **10** | context specific parameters, e.g. |
1599 | | for context schemas, persistence, |
1601 +-----------------------------------+-----------------------------------+
1603 .. container:: paragraph
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
1610 Input and Output Interfaces
1611 ---------------------------
1613 .. container:: paragraph
1615 An APEX engine has two main interfaces:
1617 .. container:: ulist
1619 - An *input* interface to receive events: also known as
1620 ingress interface or consumer, receiving (consuming)
1621 events commonly named triggers, and
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
1628 .. container:: paragraph
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
1643 .. container:: paragraph
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:
1649 .. container:: ulist
1651 - Input interface with one or more inputs
1653 .. container:: ulist
1655 - each input with a carrier technology and an event
1658 - some inputs with optional synchronous mode
1660 - some event protocols with additional parameters
1662 - Output interface with one or more outputs
1664 .. container:: ulist
1666 - each output with a carrier technology and an event
1669 - some outputs with optional synchronous mode
1671 - some event protocols with additional parameters
1673 .. container:: paragraph
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
1683 .. container:: listingblock
1685 .. container:: content
1689 "eventInputParameters": { (1)
1690 "FirstConsumer": { (2)
1691 "carrierTechnologyParameters" : {...}, (3)
1692 "eventProtocolParameters":{...}, (4)
1695 "SecondConsumer": { (6)
1696 "carrierTechnologyParameters" : {...}, (7)
1697 "eventProtocolParameters":{...}, (8)
1701 "eventOutputParameters": { (10)
1702 "FirstProducer": { (11)
1703 "carrierTechnologyParameters":{...}, (12)
1704 "eventProtocolParameters":{...}, (13)
1707 "SecondProducer": { (15)
1708 "carrierTechnologyParameters":{...}, (16)
1709 "eventProtocolParameters":{...}, (17)
1714 .. container:: colist arabic
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 +--------+--------------------------------------------------------------------+
1757 .. container:: paragraph
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
1767 .. container:: paragraph
1769 There are situations in which this auto-generated error
1770 event might not be required or wanted:
1772 .. container:: ulist
1774 - when a policy failing should not result in an event
1775 send out via an output interface
1777 - when the auto-generated event goes back in an APEX
1778 engine (or the same APEX engine), this can create
1781 - the auto-generated event should go to a special output
1782 interface or channel
1784 .. container:: paragraph
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>`__
1792 `tutorial <http://www.vogella.com/tutorials/JavaRegularExpressions/article.html>`__).
1793 The following code shows some examples:
1795 .. container:: listingblock
1797 .. container:: content
1801 "eventInputParameters": {
1803 "carrierTechnologyParameters" : {...},
1804 "eventProtocolParameters":{...},
1805 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]004$" (1)
1808 "eventOutputParameters": {
1810 "carrierTechnologyParameters":{...},
1811 "eventProtocolParameters":{...},
1812 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]104$" (2)
1819 .. container:: paragraph
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.
1827 .. container:: paragraph
1829 APEX 2.0.0-SNAPSHOT supports the following executors:
1831 .. container:: ulist
1833 - Java, for Java implemented logic
1835 .. container:: ulist
1837 - This executor requires logic implemented using the
1838 APEX Java interfaces.
1840 - Generated JAR files must be in the classpath of the
1841 APEX engine at start time.
1851 .. container:: ulist
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
1857 Configure the Javascript Executor
1858 #################################
1860 .. container:: paragraph
1862 The Javascript executor is added to the configuration as
1865 .. container:: listingblock
1867 .. container:: content
1871 "engineServiceParameters":{
1872 "engineParameters":{
1873 "executorParameters":{
1875 "parameterClassName" :
1876 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
1882 Configure the Jython Executor
1883 #############################
1885 .. container:: paragraph
1887 The Jython executor is added to the configuration as
1890 .. container:: listingblock
1892 .. container:: content
1896 "engineServiceParameters":{
1897 "engineParameters":{
1898 "executorParameters":{
1900 "parameterClassName" :
1901 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
1907 Configure the JRuby Executor
1908 ############################
1910 .. container:: paragraph
1912 The JRuby executor is added to the configuration as
1915 .. container:: listingblock
1917 .. container:: content
1921 "engineServiceParameters":{
1922 "engineParameters":{
1923 "executorParameters":{
1925 "parameterClassName" :
1926 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
1932 Configure the Java Executor
1933 ###########################
1935 .. container:: paragraph
1937 The Java executor is added to the configuration as
1940 .. container:: listingblock
1942 .. container:: content
1946 "engineServiceParameters":{
1947 "engineParameters":{
1948 "executorParameters":{
1950 "parameterClassName" :
1951 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
1957 Configure the MVEL Executor
1958 ###########################
1960 .. container:: paragraph
1962 The MVEL executor is added to the configuration as
1965 .. container:: listingblock
1967 .. container:: content
1971 "engineServiceParameters":{
1972 "engineParameters":{
1973 "executorParameters":{
1975 "parameterClassName" :
1976 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
1985 .. container:: paragraph
1987 Context handlers are responsible for all context processing.
1988 There are the following main areas:
1990 .. container:: ulist
1992 - Context schema: use schema handlers other than Java class
1993 (supported by default without configuration)
1995 - Context distribution: distribute context across multiple
1998 - Context locking: mechanisms to lock context elements for
2001 - Context persistence: mechanisms to persist context
2003 .. container:: paragraph
2005 APEX provides plugins for each of the main areas.
2007 Configure AVRO Schema Handler
2008 #############################
2010 .. container:: paragraph
2012 The AVRO schema handler is added to the configuration as
2015 .. container:: listingblock
2017 .. container:: content
2021 "engineServiceParameters":{
2022 "engineParameters":{
2023 "contextParameters":{
2024 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
2025 "schemaParameters":{
2027 "parameterClassName" :
2028 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
2035 .. container:: paragraph
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>`__.
2045 .. container:: paragraph
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
2052 .. container:: ulist
2054 - In a policy model, if the AVRO schema defined a field
2055 as ``my-name`` the policy logic should access it as
2058 - In a policy model, if the AVRO schema defined a field
2059 as ``my.name`` the policy logic should access it as
2062 - There should be no field names that convert to the
2065 .. container:: ulist
2067 - For instance the simultaneous use of
2068 ``my_name``, ``my.name``, and ``my-name`` should
2071 - If not avoided, the event processing might
2072 create unwanted side effects
2074 - If field names use any other not-supported character,
2075 the AVRO plugin will reject it
2077 .. container:: ulist
2079 - Since AVRO uses lazy initialization, this
2080 rejection might only become visible at runtime
2082 Carrier Technologies
2083 --------------------
2085 .. container:: paragraph
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.
2093 .. container:: paragraph
2095 Supported *input* technologies are:
2097 .. container:: ulist
2099 - Standard input, read events from the standard input
2100 (console), not suitable for APEX background servers
2102 - File input, read events from a file
2104 - Kafka, read events from a Kafka system
2106 - Websockets, read events from a Websocket
2110 - REST (synchronous and asynchronous), additionally as
2113 - Event Requestor, allows reading of events that have been
2114 looped back into APEX
2116 .. container:: paragraph
2118 Supported *output* technologies are:
2120 .. container:: ulist
2122 - Standard output, write events to the standard output
2123 (console), not suitable for APEX background servers
2125 - File output, write events to a file
2127 - Kafka, write events to a Kafka system
2129 - Websockets, write events to a Websocket
2133 - REST (synchronous and asynchronous), additionally as
2136 - Event Requestor, allows events to be looped back into
2139 .. container:: paragraph
2141 New carrier technologies can be added as plugins to APEX or
2142 developed outside APEX and added to an APEX deployment.
2147 .. container:: paragraph
2149 Standard IO does not require a specific plugin, it is
2150 supported be default.
2154 .. container:: paragraph
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:
2161 .. container:: listingblock
2163 .. container:: content
2167 "carrierTechnologyParameters" : {
2168 "carrierTechnology" : "FILE", (1)
2170 "standardIO" : true (2)
2174 .. container:: colist arabic
2176 +-------+---------------------------------------+
2177 | **1** | standard input is considered a file |
2178 +-------+---------------------------------------+
2179 | **2** | file descriptor set to standard input |
2180 +-------+---------------------------------------+
2185 .. container:: paragraph
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:
2192 .. container:: listingblock
2194 .. container:: content
2198 "carrierTechnologyParameters" : {
2199 "carrierTechnology" : "FILE", (1)
2201 "standardIO" : true (2)
2205 .. container:: colist arabic
2207 +-------+----------------------------------------+
2208 | **1** | standard output is considered a file |
2209 +-------+----------------------------------------+
2210 | **2** | file descriptor set to standard output |
2211 +-------+----------------------------------------+
2216 .. container:: paragraph
2218 File IO does not require a specific plugin, it is
2219 supported be default.
2224 .. container:: paragraph
2226 APEX will take events from a file. The same file
2227 should not be used as an output. The configuration is
2230 .. container:: listingblock
2232 .. container:: content
2236 "carrierTechnologyParameters" : {
2237 "carrierTechnology" : "FILE", (1)
2239 "fileName" : "examples/events/SampleDomain/EventsIn.xmlfile" (2)
2243 .. container:: colist arabic
2245 +-------+------------------------------------------+
2246 | **1** | set file input |
2247 +-------+------------------------------------------+
2248 | **2** | the name of the file to read events from |
2249 +-------+------------------------------------------+
2253 .. container:: paragraph
2255 APEX will write events to a file. The same file should
2256 not be used as an input. The configuration is as
2259 .. container:: listingblock
2261 .. container:: content
2265 "carrierTechnologyParameters" : {
2266 "carrierTechnology" : "FILE", (1)
2268 "fileName" : "examples/events/SampleDomain/EventsOut.xmlfile" (2)
2272 .. container:: colist arabic
2274 +-------+-----------------------------------------+
2275 | **1** | set file output |
2276 +-------+-----------------------------------------+
2277 | **2** | the name of the file to write events to |
2278 +-------+-----------------------------------------+
2283 .. container:: paragraph
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.
2289 Event Requestor Input
2290 =====================
2292 .. container:: paragraph
2294 APEX will take events from APEX.
2296 .. container:: listingblock
2298 .. container:: content
2302 "carrierTechnologyParameters" : {
2303 "carrierTechnology": "EVENT_REQUESTOR" (1)
2306 .. container:: colist arabic
2308 +-------+---------------------------+
2309 | **1** | set event requestor input |
2310 +-------+---------------------------+
2312 Event Requestor Output
2313 ======================
2315 .. container:: paragraph
2317 APEX will write events to APEX.
2319 .. container:: listingblock
2321 .. container:: content
2325 "carrierTechnologyParameters" : {
2326 "carrierTechnology": "EVENT_REQUESTOR" (1)
2329 Peering Event Requestors
2330 ========================
2332 .. container:: paragraph
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
2341 .. container:: listingblock
2343 .. container:: content
2347 "eventInputParameters": {
2348 "EventRequestorConsumer": {
2349 "carrierTechnologyParameters": {
2350 "carrierTechnology": "EVENT_REQUESTOR" (1)
2352 "eventProtocolParameters": {
2353 "eventProtocol": "APEX" (2)
2355 "eventNameFilter": "InputEvent", (3)
2356 "requestorMode": true, (4)
2357 "requestorPeer": "EventRequestorProducer", (5)
2358 "requestorTimeout": 500 (6)
2361 "eventOutputParameters": {
2362 "EventRequestorProducer": {
2363 "carrierTechnologyParameters": {
2364 "carrierTechnology": "EVENT_REQUESTOR" (7)
2366 "eventProtocolParameters": {
2367 "eventProtocol": "APEX" (8)
2369 "eventNameFilter": "EventListEvent", (9)
2370 "requestorMode": true, (10)
2371 "requestorPeer": "EventRequestorConsumer", (11)
2372 "requestorTimeout": 500 (12)
2376 .. container:: colist arabic
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 |
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 |
2410 +-----------------------------------+-----------------------------------+
2415 .. container:: paragraph
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
2424 .. container:: ulist
2427 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html>`__
2430 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>`__
2434 .. container:: paragraph
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.
2441 .. container:: listingblock
2443 .. container:: content
2447 "carrierTechnologyParameters" : {
2448 "carrierTechnology" : "KAFKA", (1)
2449 "parameterClassName" :
2450 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
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)
2460 "org.apache.kafka.common.serialization.StringDeserializer", (9)
2461 "valueDeserializer" :
2462 "org.apache.kafka.common.serialization.StringDeserializer" (10)
2466 .. container:: colist arabic
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 +--------+-------------------------------------+
2492 .. container:: paragraph
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
2499 .. container:: listingblock
2501 .. container:: content
2505 "carrierTechnologyParameters" : {
2506 "carrierTechnology" : "KAFKA", (1)
2507 "parameterClassName" :
2508 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2510 "bootstrapServers" : "localhost:49092", (2)
2513 "batchSize" : 16384, (5)
2514 "lingerTime" : 1, (6)
2515 "bufferMemory" : 33554432, (7)
2516 "producerTopic" : "apex-out", (8)
2518 "org.apache.kafka.common.serialization.StringSerializer", (9)
2520 "org.apache.kafka.common.serialization.StringSerializer" (10)
2524 .. container:: colist arabic
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 +--------+---------------------------------+
2551 .. container:: paragraph
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.
2562 .. container:: paragraph
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
2569 .. container:: listingblock
2571 .. container:: content
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)
2590 .. container:: colist arabic
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 |
2600 | | org.jboss:jboss-remote-naming:2.0 |
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 |
2608 +-----------------------------------+-----------------------------------+
2609 | **5** | URL with host and port of the JMS |
2611 +-----------------------------------+-----------------------------------+
2612 | **6** | access credentials, user name |
2613 +-----------------------------------+-----------------------------------+
2614 | **7** | access credentials, user password |
2615 +-----------------------------------+-----------------------------------+
2616 | **8** | the JMS topic to listen to |
2617 +-----------------------------------+-----------------------------------+
2619 JMS Output with Text
2620 ====================
2622 .. container:: paragraph
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.
2628 .. container:: listingblock
2630 .. container:: content
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)
2650 .. container:: colist arabic
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 |
2660 | | org.jboss:jboss-remote-naming:2.0 |
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 |
2668 +-----------------------------------+-----------------------------------+
2669 | **5** | URL with host and port of the JMS |
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 +-----------------------------------+-----------------------------------+
2682 JMS Output with Object
2683 ======================
2685 .. container:: paragraph
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``.
2693 ########################
2695 .. container:: paragraph
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.
2704 .. container:: paragraph
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.
2721 .. container:: paragraph
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.
2729 .. container:: listingblock
2731 .. container:: content
2735 "carrierTechnologyParameters" : {
2736 "carrierTechnology" : "WEBSOCKET", (1)
2737 "parameterClassName" :
2738 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2740 "host" : "localhost", (2)
2745 .. container:: colist arabic
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 +-------+------------------------------------------------------+
2758 .. container:: paragraph
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
2767 .. container:: listingblock
2769 .. container:: content
2773 "carrierTechnologyParameters" : {
2774 "carrierTechnology" : "WEBSOCKET", (1)
2775 "parameterClassName" :
2776 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2778 "wsClient" : false, (2)
2783 .. container:: colist arabic
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 +-------+------------------------------------------------------------+
2796 .. container:: paragraph
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.
2806 .. container:: paragraph
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
2815 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.
2823 .. container:: listingblock
2825 .. container:: content
2829 "carrierTechnologyParameters" : {
2830 "carrierTechnology" : "RESTCLIENT", (1)
2831 "parameterClassName" :
2832 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2834 "url" : "http://example.org:8080/triggers/events", (2)
2835 "httpCodeFilter" : "[2][0-9][0-9]" (3)
2839 .. container:: colist arabic
2841 +-------+--------------------------------------------------+
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 +-------+--------------------------------------------------+
2852 .. container:: paragraph
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
2859 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
2862 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.
2869 .. container:: listingblock
2871 .. container:: content
2875 "carrierTechnologyParameters" : {
2876 "carrierTechnology" : "RESTCLIENT", (1)
2877 "parameterClassName" :
2878 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2880 "url" : "http://example.com:8888/actions/events", (2)
2881 "url" : "http://example.{site}.com:8888/{trig}/events", (2')
2882 "httpMethod" : "PUT" (3)
2886 .. container:: colist arabic
2888 +-------+--------------------------------------------------+
2889 | **1** | set REST client as carrier technology |
2890 +-------+--------------------------------------------------+
2891 | **2** | the static URL of the HTTP server for events |
2892 +-------+--------------------------------------------------+
2893 | **2'**| the tagged URL of the HTTP server for events |
2894 +-------+--------------------------------------------------+
2895 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
2896 +-------+--------------------------------------------------+
2901 .. container:: paragraph
2903 APEX supports a REST server for input and output.
2905 .. container:: paragraph
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.
2914 .. container:: paragraph
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
2922 .. container:: paragraph
2924 Some configuration restrictions apply for all scenarios:
2926 .. container:: ulist
2928 - Minimum port: 1024
2930 - Maximum port: 65535
2932 - The media type is ``application/json``, so this plugin
2933 does only work with the JSON Event protocol.
2935 .. container:: paragraph
2937 The URL the client calls is created using
2939 .. container:: ulist
2941 - the configured host and port, e.g.
2942 ``http://localhost:12345``
2944 - the standard path, e.g. ``/apex/``
2946 - the name of the input/output, e.g. ``FirstConsumer/``
2948 - the input or output name, e.g. ``EventIn``.
2950 .. container:: paragraph
2952 The examples above lead to the URL
2953 ``http://localhost:12345/apex/FirstConsumer/EventIn``.
2955 .. container:: paragraph
2957 A client can also get status information of the REST
2958 server using ``/Status``, e.g.
2959 ``http://localhost:12345/apex/FirstConsumer/Status``.
2961 REST Server Stand-alone
2962 =======================
2964 .. container:: paragraph
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.
2970 .. container:: paragraph
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.
2976 .. container:: paragraph
2978 The following example configures the input named as
2979 ``MyConsumer`` and associates an output named
2980 ``MyProducer`` with it.
2982 .. container:: listingblock
2984 .. container:: content
2988 "eventInputParameters": {
2990 "carrierTechnologyParameters" : {
2991 "carrierTechnology" : "RESTSERVER", (1)
2992 "parameterClassName" :
2993 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters",
2995 "standalone" : true, (2)
2996 "host" : "localhost", (3)
3000 "eventProtocolParameters":{
3001 "eventProtocol" : "JSON" (5)
3003 "synchronousMode" : true, (6)
3004 "synchronousPeer" : "MyProducer", (7)
3005 "synchronousTimeout" : 500 (8)
3009 .. container:: colist arabic
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 +-------+---------------------------------------+
3029 .. container:: paragraph
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
3037 .. container:: listingblock
3039 .. container:: content
3043 "eventOutputParameters": {
3045 "carrierTechnologyParameters":{
3046 "carrierTechnology" : "RESTSERVER",
3047 "parameterClassName" :
3048 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters"
3050 "eventProtocolParameters":{
3051 "eventProtocol" : "JSON"
3053 "synchronousMode" : true,
3054 "synchronousPeer" : "MyConsumer",
3055 "synchronousTimeout" : 500
3059 REST Server Stand-alone, multi input
3060 ====================================
3062 .. container:: paragraph
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.
3071 REST Server Stand-alone in Servlet
3072 ==================================
3074 .. container:: paragraph
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).
3082 .. container:: paragraph
3084 For the Tomcat configuration, we need to add the REST
3087 .. container:: listingblock
3089 .. container:: content
3097 <param-value>org.onap.policy.apex.plugins.event.carrier.restserver</param-value>
3105 .. container:: paragraph
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.
3112 REST Requestor Input
3113 ====================
3115 .. container:: paragraph
3117 APEX will connect to a given URL to request an input.
3118 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
3121 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.
3135 .. container:: listingblock
3137 .. container:: content
3141 "carrierTechnologyParameters": {
3142 "carrierTechnology": "RESTREQUESTOR", (1)
3143 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters",
3145 "url": "http://localhost:54321/some/path/to/rest/resource", (2)
3146 "url": "http://localhost:54321/{site}/path/to/rest/{resValue}", (2')
3147 "httpMethod": "POST", (3)
3148 "restRequestTimeout": 2000, (4)
3149 "httpCodeFilter" : "[2][0-9][0-9]" (5)
3153 .. container:: colist arabic
3155 +-------+--------------------------------------------------+
3156 | **1** | set REST requestor as carrier technology |
3157 +-------+--------------------------------------------------+
3158 | **2** | the static URL of the HTTP server for events |
3159 +-------+--------------------------------------------------+
3160 | **2'**| the tagged URL of the HTTP server for events |
3161 +-------+--------------------------------------------------+
3162 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
3163 +-------+--------------------------------------------------+
3164 | **4** | request timeout in milliseconds |
3165 +-------+--------------------------------------------------+
3166 | **5** | use HTTP CODE FILTER for filtering status code |
3167 +-------+--------------------------------------------------+
3169 .. container:: paragraph
3171 Further settings are required on the consumer to
3172 define the event that is requested, for example:
3174 .. container:: listingblock
3176 .. container:: content
3180 "eventName": "GuardResponseEvent", (1)
3181 "eventNameFilter": "GuardResponseEvent", (2)
3182 "requestorMode": true, (3)
3183 "requestorPeer": "GuardRequestorProducer", (4)
3184 "requestorTimeout": 500 (5)
3186 .. container:: colist arabic
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 +-------+---------------------------+
3200 REST Requestor Output
3201 =====================
3203 .. container:: paragraph
3205 APEX will connect to a given URL to send events, but
3206 not receive any events.
3208 .. container:: listingblock
3210 .. container:: content
3214 "carrierTechnologyParameters": {
3215 "carrierTechnology": "RESTREQUESTOR", (1)
3216 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters"
3219 .. container:: colist arabic
3221 +-------+------------------------------------------+
3222 | **1** | set REST requestor as carrier technology |
3223 +-------+------------------------------------------+
3225 .. container:: paragraph
3227 Further settings are required on the consumer to
3228 define the event that is requested, for example:
3230 .. container:: listingblock
3232 .. container:: content
3236 "eventNameFilter": "GuardRequestEvent", (1)
3237 "requestorMode": true, (2)
3238 "requestorPeer": "GuardRequestorConsumer", (3)
3239 "requestorTimeout": 500 (4)
3241 .. container:: colist arabic
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 +-------+---------------------------+
3253 Event Protocols, Format and Encoding
3254 ------------------------------------
3256 .. container:: paragraph
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
3265 .. container:: paragraph
3267 Supported *input* event protocols are:
3269 .. container:: ulist
3271 - JSON, the event as a JSON string
3273 - APEX, an APEX event
3275 - JMS object, the event as a JMS object,
3277 - JMS text, the event as a JMS text,
3279 - XML, the event as an XML string,
3281 - YAML, the event as YAML text
3283 .. container:: paragraph
3285 Supported *output* event protocols are:
3287 .. container:: ulist
3289 - JSON, the event as a JSON string
3291 - APEX, an APEX event
3293 - JMS object, the event as a JMS object,
3295 - JMS text, the event as a JMS text,
3297 - XML, the event as an XML string,
3299 - YAML, the event as YAML text
3301 .. container:: paragraph
3303 New event protocols can be added as plugins to APEX or
3304 developed outside APEX and added to an APEX deployment.
3309 .. container:: paragraph
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.
3316 .. container:: paragraph
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
3326 .. container:: paragraph
3328 The following JSON shows the configuration.
3330 .. container:: listingblock
3332 .. container:: content
3336 "eventProtocolParameters":{
3337 "eventProtocol" : "JSON"
3340 .. container:: paragraph
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:
3353 .. container:: listingblock
3355 .. container:: content
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)
3368 .. container:: colist arabic
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 +-----------------------------------+-----------------------------------+
3394 .. container:: paragraph
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.
3401 .. container:: paragraph
3403 For input and output APEX uses APEX events.
3405 .. container:: paragraph
3407 The following JSON shows the configuration.
3409 .. container:: listingblock
3411 .. container:: content
3415 "eventProtocolParameters":{
3416 "eventProtocol" : "APEX"
3422 .. container:: paragraph
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.
3431 .. container:: paragraph
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.
3439 .. container:: paragraph
3441 The configuration for JMS text is as follows:
3443 .. container:: listingblock
3445 .. container:: content
3449 "eventProtocolParameters":{
3450 "eventProtocol" : "JMSTEXT",
3451 "parameterClassName" :
3452 "org.onap.policy.apex.plugins.event.protocol.jms.JMSTextEventProtocolParameters"
3457 .. container:: paragraph
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.
3466 .. container:: paragraph
3468 The configuration for JMS object is as follows:
3470 .. container:: listingblock
3472 .. container:: content
3476 "eventProtocolParameters":{
3477 "eventProtocol" : "JMSOBJECT",
3478 "parameterClassName" :
3479 "org.onap.policy.apex.plugins.event.protocol.jms.JMSObjectEventProtocolParameters"
3485 .. container:: paragraph
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.
3491 .. container:: paragraph
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
3501 .. container:: paragraph
3503 The following code shows the configuration.
3505 .. container:: listingblock
3507 .. container:: content
3511 "eventProtocolParameters":{
3512 "eventProtocol" : "XML",
3513 "parameterClassName" :
3514 "org.onap.policy.apex.plugins.event.protocol.yaml.YamlEventProtocolParameters"
3519 .. container:: paragraph
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.
3525 .. container:: paragraph
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
3535 .. container:: paragraph
3537 The following code shows the configuration.
3539 .. container:: listingblock
3541 .. container:: content
3545 "eventProtocolParameters":{
3546 "eventProtocol" : "XML",
3547 "parameterClassName" :
3548 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3551 A configuration example
3552 -----------------------
3554 .. container:: paragraph
3556 The following example loads all available plug-ins.
3558 .. container:: paragraph
3560 Events are consumed from a Websocket, APEX as client.
3561 Consumed event format is JSON.
3563 .. container:: paragraph
3565 Events are produced to Kafka. Produced event format is XML.
3567 .. container:: listingblock
3569 .. container:: content
3574 "engineServiceParameters" : {
3575 "name" : "MyApexEngine",
3576 "version" : "0.0.1",
3578 "instanceCount" : 4,
3579 "deploymentPort" : 12345,
3580 "policyModelFileName" : "examples/models/some-model.json",
3581 "engineParameters" : {
3582 "executorParameters" : {
3584 "parameterClassName" :
3585 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
3588 "parameterClassName" :
3589 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
3592 "parameterClassName" :
3593 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
3596 "parameterClassName" :
3597 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
3600 "parameterClassName" :
3601 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
3604 "contextParameters" : {
3605 "parameterClassName" :
3606 "org.onap.policy.apex.context.parameters.ContextParameters",
3607 "schemaParameters" : {
3609 "parameterClassName" :
3610 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
3616 "producerCarrierTechnologyParameters" : {
3617 "carrierTechnology" : "KAFKA",
3618 "parameterClassName" :
3619 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
3621 "bootstrapServers" : "localhost:49092",
3624 "batchSize" : 16384,
3626 "bufferMemory" : 33554432,
3627 "producerTopic" : "apex-out",
3628 "keySerializer" : "org.apache.kafka.common.serialization.StringSerializer",
3629 "valueSerializer" : "org.apache.kafka.common.serialization.StringSerializer"
3632 "producerEventProtocolParameters" : {
3633 "eventProtocol" : "XML",
3634 "parameterClassName" :
3635 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3637 "consumerCarrierTechnologyParameters" : {
3638 "carrierTechnology" : "WEBSOCKET",
3639 "parameterClassName" :
3640 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
3642 "host" : "localhost",
3646 "consumerEventProtocolParameters" : {
3647 "eventProtocol" : "JSON"
3651 Engine and Applications of the APEX System
3652 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3654 Introduction to APEX Engine and Applications
3655 --------------------------------------------
3657 .. container:: paragraph
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.
3665 .. container:: paragraph
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
3674 .. container:: paragraph
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.
3682 .. container:: paragraph
3684 For this documentation, we assume an installation of APEX as
3685 a full system based on a current ONAP release.
3687 CLI on Unix, Windows, and Cygwin
3688 --------------------------------
3690 .. container:: paragraph
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
3699 .. container:: ulist
3701 - For UNIX systems (RHL, Ubuntu, Debian, Mac OSX), the
3702 provided bash scripts work as expected with absolute
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/``)
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\``)
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
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.
3730 .. container:: paragraph
3732 The APEX engine can be started in different ways, depending
3733 your requirements. All scripts are located in the APEX *bin*
3736 .. container:: paragraph
3738 On UNIX and Cygwin systems use:
3740 .. container:: ulist
3742 - ``apexEngine.sh`` - this script will
3744 .. container:: ulist
3746 - Test if ``$APEX_USER`` is set and if the user
3747 exists, terminate with an error otherwise
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
3755 - When all tests are passed successfully, the script
3756 will call ``apexApps.sh`` with arguments to start
3759 - ``apexApps.sh engine`` - this is the general APEX
3760 application launcher, which will
3762 .. container:: ulist
3764 - Start the engine with the argument ``engine``
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.
3770 - Not test for any settings of ``$APEX_USER``.
3772 .. container:: paragraph
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%``.
3778 .. container:: paragraph
3780 Summary of alternatives to start the APEX Engine:
3782 +--------------------------------------------------------+----------------------------------------------------------+
3783 | Unix, Cygwin | Windows |
3784 +========================================================+==========================================================+
3785 | .. container:: | .. container:: |
3787 | .. container:: listingblock | .. container:: listingblock |
3789 | .. container:: content | .. container:: content |
3791 | .. code:: | .. code:: |
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 +--------------------------------------------------------+----------------------------------------------------------+
3797 .. container:: paragraph
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.
3806 .. container:: listingblock
3808 .. container:: content
3812 usage: org.onap.policy.apex.service.engine.main.ApexMain [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
3819 -v,--version outputs the version of Apex
3824 .. container:: paragraph
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
3831 .. container:: ulist
3833 - non-interactive, specifying a file with the commands to
3836 - interactive, using the editors CLI to create a policy
3838 .. container:: paragraph
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.
3845 .. container:: paragraph
3847 On UNIX and Cygwin systems use:
3849 .. container:: ulist
3851 - ``apexCLIEditor.sh`` - simply starts the CLI editor,
3852 arguments to the script determine the mode of the editor
3854 - ``apexApps.sh cli-editor`` - simply starts the CLI
3855 editor, arguments to the script determine the mode of the
3858 .. container:: paragraph
3860 On Windows systems use:
3862 .. container:: ulist
3864 - ``apexCLIEditor.bat`` - simply starts the CLI editor,
3865 arguments to the script determine the mode of the editor
3867 - ``apexApps.bat cli-editor`` - simply starts the CLI
3868 editor, arguments to the script determine the mode of the
3871 .. container:: paragraph
3873 Summary of alternatives to start the APEX CLI Editor:
3875 +------------------------------------------------------------+--------------------------------------------------------------+
3876 | Unix, Cygwin | Windows |
3877 +============================================================+==============================================================+
3878 | .. container:: | .. container:: |
3880 | .. container:: listingblock | .. container:: listingblock |
3882 | .. container:: content | .. container:: content |
3884 | .. code:: | .. code:: |
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 +------------------------------------------------------------+--------------------------------------------------------------+
3890 .. container:: paragraph
3892 The option ``-h`` provides a help screen with all command
3895 .. container:: listingblock
3897 .. container:: content
3901 usage: org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain [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
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
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
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
3923 The APEX REST Editor
3924 --------------------
3926 .. container:: paragraph
3928 The standard way to use the APEX REST Editor is via an
3929 installation of the *war* file on a webserver. However, the
3930 REST editor can also be started via command line. This will
3931 start a Grizzly webserver with the *war* deployed. Access to
3932 the REST Editor is then via the provided URL
3934 .. container:: paragraph
3936 On UNIX and Cygwin systems use:
3938 .. container:: ulist
3940 - ``apexRESTEditor.sh`` - simply starts the webserver with
3943 - ``apexApps.sh rest-editor`` - simply starts the webserver
3944 with the REST editor
3946 .. container:: paragraph
3948 On Windows systems use:
3950 .. container:: ulist
3952 - ``apexRESTEditor.bat`` - simply starts the webserver with
3955 - ``apexApps.bat rest-editor`` - simply starts the
3956 webserver with the REST editor
3958 .. container:: paragraph
3960 Summary of alternatives to start the APEX REST Editor:
3962 +-------------------------------------------------------------+---------------------------------------------------------------+
3963 | Unix, Cygwin | Windows |
3964 +=============================================================+===============================================================+
3965 | .. container:: | .. container:: |
3967 | .. container:: listingblock | .. container:: listingblock |
3969 | .. container:: content | .. container:: content |
3971 | .. code:: | .. code:: |
3973 | # $APEX_HOME/bin/apexRESTEditor.sh.sh [args] | > %APEX_HOME%\bin\apexRESTEditor.bat [args] |
3974 | # $APEX_HOME/bin/apexApps.sh rest-editor [args] | > %APEX_HOME%\bin\apexApps.bat rest-editor [args] |
3975 +-------------------------------------------------------------+---------------------------------------------------------------+
3977 .. container:: paragraph
3979 The option ``-h`` provides a help screen with all command
3982 .. container:: listingblock
3984 .. container:: content
3988 usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]
3989 -h,--help outputs the usage of this command
3990 -l,--listen <ADDRESS> the IP address to listen on. Default value is localhost to restrict access to the
3992 -p,--port <PORT> port to use for the Apex RESTful editor REST calls.
3993 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating. Default
3994 value is -1 to run indefinitely.
3996 .. container:: paragraph
3998 If the REST Editor is started without any arguments the
3999 final messages will look similar to this:
4001 .. container:: listingblock
4003 .. container:: content
4007 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4008 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.NetworkListener start
4009 INFO: Started listener bound to [localhost:18989]
4010 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.HttpServer start
4011 INFO: [HttpServer] Started.
4012 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4014 .. container:: paragraph
4016 The last line states the URL on which the REST Editor can be
4017 accessed. The example above stated
4018 ``http://0.0.0.0:18989/apex/``. In a web browser use the URL
4019 ``http://localhost:18989`` and the REST Editor will start.
4021 The APEX Monitoring Client
4022 --------------------------
4024 .. container:: paragraph
4026 The standard way to use the APEX Monitoring Client is via an
4027 installation of the *war* file on a webserver. However, the
4028 Monitoring Client can also be started via command line. This
4029 will start a Grizzly webserver with the *war* deployed.
4030 Access to the Monitoring Client is then via the provided URL
4032 .. container:: paragraph
4034 On UNIX and Cygwin systems use:
4036 .. container:: ulist
4038 - ``apexApps.sh eng-monitoring`` - simply starts the
4039 webserver with the Monitoring Client
4041 .. container:: paragraph
4043 On Windows systems use:
4045 .. container:: ulist
4047 - ``apexApps.bat eng-monitoring`` - simply starts the
4048 webserver with the Monitoring Client
4050 .. container:: paragraph
4052 The option ``-h`` provides a help screen with all command
4055 .. container:: listingblock
4057 .. container:: content
4061 usage: org.onap.policy.apex.client.monitoring.rest.ApexMonitoringRestMain [options...]
4062 -h,--help outputs the usage of this command
4063 -p,--port <PORT> port to use for the Apex Services REST calls
4064 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4066 .. container:: paragraph
4068 If the Monitoring Client is started without any arguments
4069 the final messages will look similar to this:
4071 .. container:: listingblock
4073 .. container:: content
4077 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4078 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.NetworkListener start
4079 INFO: Started listener bound to [localhost:18989]
4080 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.HttpServer start
4081 INFO: [HttpServer] Started.
4082 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4084 .. container:: paragraph
4086 The last line states the URL on which the Monitoring Client
4087 can be accessed. The example above stated
4088 ``http://localhost:18989/apexservices``. In a web browser
4089 use the URL ``http://localhost:18989``.
4091 The APEX Deployment Client
4092 --------------------------
4094 .. container:: paragraph
4096 The standard way to use the APEX Deployment Client is via an
4097 installation of the *war* file on a webserver. However, the
4098 Deployment Client can also be started via command line. This
4099 will start a Grizzly webserver with the *war* deployed.
4100 Access to the Deployment Client is then via the provided URL
4102 .. container:: paragraph
4104 On UNIX and Cygwin systems use:
4106 .. container:: ulist
4108 - ``apexApps.sh eng-deployment`` - simply starts the
4109 webserver with the Deployment Client
4111 .. container:: paragraph
4113 On Windows systems use:
4115 .. container:: ulist
4117 - ``apexApps.bat eng-deployment`` - simply starts the
4118 webserver with the Deployment Client
4120 .. container:: paragraph
4122 The option ``-h`` provides a help screen with all command
4125 .. container:: listingblock
4127 .. container:: content
4131 usage: org.onap.policy.apex.client.deployment.rest.ApexDeploymentRestMain [options...]
4132 -h,--help outputs the usage of this command
4133 -p,--port <PORT> port to use for the Apex Services REST calls
4134 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4136 .. container:: paragraph
4138 If the Deployment Client is started without any arguments
4139 the final messages will look similar to this:
4141 .. container:: listingblock
4143 .. container:: content
4147 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4148 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.NetworkListener start
4149 INFO: Started listener bound to [localhost:18989]
4150 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.HttpServer start
4151 INFO: [HttpServer] Started.
4152 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4154 .. container:: paragraph
4156 The last line states the URL on which the Deployment Client
4157 can be accessed. The example above stated
4158 ``http://localhost:18989/apexservices``. In a web browser
4159 use the URL ``http://localhost:18989``.
4161 The APEX Full Client
4162 --------------------
4164 .. container:: paragraph
4166 The APEX Full Client combines the REST Editor, the
4167 Monitoring Client, and the Deployment Client into a single
4168 application. The standard way to use the APEX Full Client is
4169 via an installation of the *war* file on a webserver.
4170 However, the Full Client can also be started via command
4171 line. This will start a Grizzly webserver with the *war*
4172 deployed. Access to the Full Client is then via the provided
4175 .. container:: paragraph
4177 On UNIX and Cygwin systems use:
4179 .. container:: ulist
4181 - ``apexApps.sh full-client`` - simply starts the webserver
4182 with the Full Client
4184 .. container:: paragraph
4186 On Windows systems use:
4188 .. container:: ulist
4190 - ``apexApps.bat full-client`` - simply starts the
4191 webserver with the Full Client
4193 .. container:: paragraph
4195 The option ``-h`` provides a help screen with all command
4198 .. container:: listingblock
4200 .. container:: content
4204 usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4205 -h,--help outputs the usage of this command
4206 -p,--port <PORT> port to use for the Apex Services REST calls
4207 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4209 .. container:: paragraph
4211 If the Full Client is started without any arguments the
4212 final messages will look similar to this:
4214 .. container:: listingblock
4216 .. container:: content
4220 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4221 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4222 INFO: Started listener bound to [localhost:18989]
4223 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4224 INFO: [HttpServer] Started.
4225 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4227 .. container:: paragraph
4229 The last line states the URL on which the Monitoring Client
4230 can be accessed. The example above stated
4231 ``http://localhost:18989/apexservices``. In a web browser
4232 use the URL ``http://localhost:18989``.
4234 The APEX Application Launcher
4235 ------------------------------
4237 .. container:: paragraph
4239 The standard applications (Engine, CLI Editor, REST Editor)
4240 come with dedicated start scripts. For all other APEX
4241 applications, we provide an application launcher.
4243 .. container:: paragraph
4245 On UNIX and Cygwin systems use:
4247 .. container:: ulist
4249 - apexApps.sh\` - simply starts the application launcher
4251 .. container:: paragraph
4253 On Windows systems use:
4255 .. container:: ulist
4257 - ``apexApps.bat`` - simply starts the application launcher
4259 .. container:: paragraph
4261 Summary of alternatives to start the APEX application
4264 +-------------------------------------------------+---------------------------------------------------+
4265 | Unix, Cygwin | Windows |
4266 +=================================================+===================================================+
4267 | .. container:: | .. container:: |
4269 | .. container:: listingblock | .. container:: listingblock |
4271 | .. container:: content | .. container:: content |
4273 | .. code:: | .. code:: |
4275 | # $APEX_HOME/bin/apexApps.sh [args] | > %APEX_HOME%\bin\apexApps.bat [args] |
4276 +-------------------------------------------------+---------------------------------------------------+
4278 .. container:: paragraph
4280 The option ``-h`` provides a help screen with all launcher
4281 command line arguments.
4283 .. container:: listingblock
4285 .. container:: content
4289 apexApps.sh - runs APEX applications
4291 Usage: apexApps.sh [options] | [<application> [<application options>]]
4294 -d <app> - describes an application
4295 -l - lists all applications supported by this script
4296 -h - this help screen
4298 .. container:: paragraph
4300 Using ``-l`` lists all known application the launcher can
4303 .. container:: listingblock
4305 .. container:: content
4309 apexApps.sh: supported applications:
4310 --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4312 .. container:: paragraph
4314 Using the ``-d <name>`` option describes the named
4315 application, for instance for the ``ws-console``:
4317 .. container:: listingblock
4319 .. container:: content
4323 apexApps.sh: application 'ws-console'
4324 --> a simple console sending events to APEX, connect to APEX consumer port
4326 .. container:: paragraph
4328 Launching an application is done by calling the script with
4329 only the application name and any CLI arguments for the
4330 application. For instance, starting the ``ws-echo``
4331 application with port ``8888``:
4333 .. container:: listingblock
4335 .. container:: content
4339 apexApps.sh ws-echo -p 8888
4341 Application: Create Event Templates
4342 -----------------------------------
4344 .. container:: paragraph
4346 **Status: Experimental**
4348 .. container:: paragraph
4350 This application takes a policy model (JSON or XML encoded)
4351 and generates templates for events in JSON format. This can
4352 help when a policy defines rather complex trigger or action
4353 events or complex events between states. The application can
4354 produce events for the types: stimuli (policy trigger
4355 events), internal (events between policy states), and
4356 response (action events).
4358 +----------------------------------------------------------------+------------------------------------------------------------------+
4359 | Unix, Cygwin | Windows |
4360 +================================================================+==================================================================+
4361 | .. container:: | .. container:: |
4363 | .. container:: listingblock | .. container:: listingblock |
4365 | .. container:: content | .. container:: content |
4367 | .. code:: | .. code:: |
4369 | # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] | > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4370 +----------------------------------------------------------------+------------------------------------------------------------------+
4372 .. container:: paragraph
4374 The option ``-h`` provides a help screen.
4376 .. container:: listingblock
4378 .. container:: content
4382 gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4383 usage: gen-model2event
4384 -h,--help prints this help and usage screen
4385 -m,--model <MODEL-FILE> set the input policy model file
4386 -t,--type <TYPE> set the event type for generation, one of:
4387 stimuli (trigger events), response (action
4388 events), internal (events between states)
4389 -v,--version prints the application version
4391 .. container:: paragraph
4393 The created templates are not valid events, instead they use
4394 some markup for values one will need to change to actual
4395 values. For instance, running the tool with the *Sample
4396 Domain* policy model as:
4398 .. container:: listingblock
4400 .. container:: content
4404 apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4406 .. container:: paragraph
4408 will produce the following status messages:
4410 .. container:: listingblock
4412 .. container:: content
4416 gen-model2event: starting Event generator
4417 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4420 .. container:: paragraph
4422 and then run the generator application producing two event
4423 templates. The first template is called ``Event0000``.
4425 .. container:: listingblock
4427 .. container:: content
4432 "name" : "Event0000",
4433 "nameSpace" : "org.onap.policy.apex.sample.events",
4434 "version" : "0.0.1",
4435 "source" : "Outside",
4437 "TestTemperature" : ###double: 0.0###,
4438 "TestTimestamp" : ###long: 0###,
4439 "TestMatchCase" : ###integer: 0###,
4440 "TestSlogan" : "###string###"
4443 .. container:: paragraph
4445 The values for the keys are marked with ``#`` and the
4446 expected type of the value. To create an actual stimuli
4447 event, all these markers need to be change to actual values,
4450 .. container:: listingblock
4452 .. container:: content
4457 "name" : "Event0000",
4458 "nameSpace" : "org.onap.policy.apex.sample.events",
4459 "version" : "0.0.1",
4460 "source" : "Outside",
4462 "TestTemperature" : 25,
4463 "TestTimestamp" : 123456789123456789,
4464 "TestMatchCase" : 1,
4465 "TestSlogan" : "Testing the Match Case with Temperature 25"
4468 Application: Convert a Policy Model to CLI Editor Commands
4469 ----------------------------------------------------------
4471 .. container:: paragraph
4473 **Status: Experimental**
4475 .. container:: paragraph
4477 This application takes a policy model (JSON or XML encoded)
4478 and generates commands for the APEX CLI Editor. This
4479 effectively reverses a policy specification realized with
4482 +-------------------------------------------------------------+---------------------------------------------------------------+
4483 | Unix, Cygwin | Windows |
4484 +=============================================================+===============================================================+
4485 | .. container:: | .. container:: |
4487 | .. container:: listingblock | .. container:: listingblock |
4489 | .. container:: content | .. container:: content |
4491 | .. code:: | .. code:: |
4493 | # $APEX_HOME/bin/apexApps.sh model-2-cli [args] | > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4494 +-------------------------------------------------------------+---------------------------------------------------------------+
4496 .. container:: paragraph
4498 The option ``-h`` provides a help screen.
4500 .. container:: listingblock
4502 .. container:: content
4506 usage: gen-model2cli
4507 -h,--help prints this help and usage screen
4508 -m,--model <MODEL-FILE> set the input policy model file
4509 -sv,--skip-validation switch of validation of the input file
4510 -v,--version prints the application version
4512 .. container:: paragraph
4514 For instance, running the tool with the *Sample Domain*
4517 .. container:: listingblock
4519 .. container:: content
4523 apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4525 .. container:: paragraph
4527 will produce the following status messages:
4529 .. container:: listingblock
4531 .. container:: content
4535 gen-model2cli: starting CLI generator
4536 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4538 .. container:: paragraph
4540 and then run the generator application producing all CLI
4541 Editor commands and printing them to standard out.
4543 Application: Websocket Clients (Echo and Console)
4544 -------------------------------------------------
4546 .. container:: paragraph
4548 **Status: Production**
4550 .. container:: paragraph
4552 The application launcher also provides a Websocket echo
4553 client and a Websocket console client. The echo client
4554 connects to APEX and prints all events it receives from
4555 APEX. The console client connects to APEX, reads input from
4556 the command line, and sends this input as events to APEX.
4558 +------------------------------------------------------------+--------------------------------------------------------------+
4559 | Unix, Cygwin | Windows |
4560 +============================================================+==============================================================+
4561 | .. container:: | .. container:: |
4563 | .. container:: listingblock | .. container:: listingblock |
4565 | .. container:: content | .. container:: content |
4567 | .. code:: | .. code:: |
4569 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
4570 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4571 +------------------------------------------------------------+--------------------------------------------------------------+
4573 .. container:: paragraph
4575 The arguments are the same for both applications:
4577 .. container:: ulist
4579 - ``-p`` defines the Websocket port to connect to (defaults
4582 - ``-s`` defines the host on which a Websocket server is
4583 running (defaults to ``localhost``)
4585 .. container:: paragraph
4587 A discussion on how to use these two applications to build
4588 an APEX system is detailed HowTo-Websockets.
4595 .. container:: paragraph
4597 Consider a scenario where a supermarket chain called
4598 *HyperM* controls how it sells items in a policy-based
4599 manner. Each time an item is processed by *HyperM*'s
4600 point-of-sale (PoS) system an event is generated and
4601 published about that item of stock being sold. This event
4602 can then be used to update stock levels, etc..
4604 .. container:: paragraph
4606 *HyperM* want to extend this approach to allow some checks
4607 to be performed before the sale can be completed. This can
4608 be achieved by requesting a policy-controlled decision as
4609 each item is processed by for sale by each PoS system. The
4610 decision process is integrated with *HyperM*'s other IT
4611 systems that manage stock control, sourcing and purchasing,
4612 personnel systems, etc.
4614 .. container:: paragraph
4616 In this document we will show how APEX and APEX Policies can
4617 be used to achieve this, starting with a simple policy,
4618 building up to more complicated policy that demonstrates the
4627 .. container:: paragraph
4629 Each time a PoS system processes a sales item an event
4630 with the following format is emitted:
4632 .. table:: Table 1. Sale Input Event
4634 +----------------------+----------------------+-----------------------+
4635 | Event | Fields | Description |
4636 +======================+======================+=======================+
4637 | SALE_INPUT | time, sale_ID, | Event indicating a |
4638 | | amount, item_ID, | sale of an item is |
4639 | | quantity, | occurring |
4640 | | assistant_ID, | |
4641 | | branch_ID, notes, … | |
4642 +----------------------+----------------------+-----------------------+
4644 .. container:: paragraph
4646 In each ``SALE_INPUT`` event the ``sale_ID`` field is a
4647 unique ID generated by the PoS system. A timestamp for
4648 the event is stored in the ``time`` field. The ``amount``
4649 field refers to the value of the item(s) to be sold (in
4650 cents). The ``item_ID`` field is a unique identifier for
4651 each item type, and can be used to retrieve more
4652 information about the item from *HyperM*'s stock control
4653 system. The ``quantity`` field refers to the quantity of
4654 the item to be sold. The ``assistant_ID`` field is a
4655 unique identifier for the PoS operator, and can be used
4656 to retrieve more information about the operator from the
4657 *HyperM*'s personnel system. Since *HyperM* has many
4658 branches the ``branch_ID`` identifies the shop. The
4659 ``notes`` field contains arbitrary notes about the sale.
4661 Sales Decision Event
4662 ####################
4664 .. container:: paragraph
4666 After a ``SALE_INPUT`` event is emitted by the PoS system
4667 *HyperM*'s policy-based controlled sales checking system
4668 emits a Sale Authorization Event indicating whether the
4669 sale is authorized or denied. The PoS system can then
4670 listen for this event before continuing with the sale.
4672 .. table:: Table 2. Sale Authorisation Event
4674 +----------------------+----------------------+-----------------------+
4675 | Event | Fields | Description |
4676 +======================+======================+=======================+
4677 | SALE_AUTH | sale_ID, time, | Event indicating a |
4678 | | authorized, amount, | sale of an item is |
4679 | | item_ID, quantity, | authorized or denied |
4680 | | assistant_ID, | |
4681 | | branch_ID, notes, | |
4683 +----------------------+----------------------+-----------------------+
4685 .. container:: paragraph
4687 In each ``SALE_AUTH`` event the ``sale_ID`` field is
4688 copied from the ``SALE_INPUT`` event that trigger the
4689 decision request. The ``SALE_AUTH`` event is also
4690 timestamped using the ``time`` field, and a field called
4691 ``authorised`` is set to ``true`` or ``false`` depending
4692 on whether the sale is authorized or denied. The
4693 ``message`` field carries an optional message about why a
4694 sale was not authorized. The other fields from the
4695 ``SALE_INPUT`` event are also included for completeness.
4697 Stock Control: Items
4698 ####################
4700 .. container:: paragraph
4702 *HyperM* maintains information about each item for sale
4703 in a database table called ``ITEMS``.
4705 .. table:: Table 3. Items Database
4707 +----------------------+----------------------+-----------------------+
4708 | Table | Fields | Description |
4709 +======================+======================+=======================+
4710 | ITEMS | item_ID, | Database table |
4711 | | description, | describing each item |
4712 | | cost_price, barcode, | for sale |
4713 | | supplier_ID, | |
4714 | | category, … | |
4715 +----------------------+----------------------+-----------------------+
4717 .. container:: paragraph
4719 The database table ``ITEMS`` has a row for each items
4720 that *HyperM* sells. Each item is identified by an
4721 ``item_ID`` value. The ``description`` field stores a
4722 description of the item. The cost price of the item is
4723 given in ``cost_price``. The barcode of the item is
4724 encoded in ``barcode``, while the item supplier is
4725 identified by ``supplier_ID``. Items may also be
4726 classified into categories using the ``category`` field.
4727 Useful categories might include: ``soft drinks``,
4728 ``alcoholic drinks``, ``cigarettes``, ``knives``,
4729 ``confectionery``, ``bakery``, ``fruit&vegetables``,
4732 Personnel System: Assistants
4733 ############################
4735 .. table:: Table 4. Assistants Database
4737 +----------------------+----------------------+-----------------------+
4738 | Table | Fields | Description |
4739 +======================+======================+=======================+
4740 | ASSISTANTS | assistant_ID, | Database table |
4741 | | surname, firstname, | describing each |
4742 | | middlename, age, | *HyperM* sales |
4743 | | grade, phone_number, | assistant |
4745 +----------------------+----------------------+-----------------------+
4747 .. container:: paragraph
4749 The database table ``ASSISTANTS`` has a row for each
4750 sales assistant employed by *HyperM*. Each assistant is
4751 identified by an ``assistant_ID`` value, with their name
4752 given in the ``firstname``, ``middlename`` and
4753 ``surname`` fields. The assistant’s age in years is given
4754 in ``age``, while their phone number is contained in the
4755 ``phone_number`` field. The assistant’s grade is encoded
4756 in ``grade``. Useful values for ``grade`` might include:
4757 ``trainee``, ``operator``, ``supervisor``, etc..
4760 ####################
4762 .. table:: Table 5. Branches Database
4764 +----------------------+----------------------+-----------------------+
4765 | Table | Fields | Description |
4766 +======================+======================+=======================+
4767 | BRANCHES | branch_ID, | Database table |
4768 | | branch_Name, | describing each |
4769 | | category, street, | *HyperM* branch |
4770 | | city, country, | |
4771 | | postcode, … | |
4772 +----------------------+----------------------+-----------------------+
4774 .. container:: paragraph
4776 *HyperM* operates a number of branches. Each branch is
4777 described in the ``BRANCHES`` database table. Each branch
4778 is identified by a ``branch_ID``, with a branch name
4779 given in ``branch_Name``. The address for the branch is
4780 encoded in ``street``, ``city``, ``country`` and
4781 ``postcode``. The branch category is given in the
4782 ``category`` field. Useful values for ``category`` might
4783 include: ``Small``, ``Large``, ``Super``, ``Hyper``,
4791 .. container:: paragraph
4793 For the first version of our policy, let’s start with
4794 something simple. Let us assume that there exists some
4795 restriction that alcohol products cannot be sold before
4796 11:30am. In this section we will go through the necessary
4797 steps to define a policy that can enforce this for
4800 .. container:: ulist
4802 - Alcohol cannot be sold before 11:30am.
4804 Create the an new empty Policy Model ``MyFirstPolicyModel``
4805 ###########################################################
4807 .. container:: paragraph
4809 Since an organisation like *HyperM* may have many
4810 policies covering many different domains, policies should
4811 be grouped into policy sets. In order to edit or deploy a
4812 policy, or policy set, the definition of the policy(ies)
4813 and all required events, tasks, states, etc., are grouped
4814 together into a 'Policy Model'. An organization might
4815 define many Policy Models, each containing a different
4818 .. container:: paragraph
4820 So the first step is to create a new empty Policy Model
4821 called ``MyFirstPolicyModel``. Using the APEX Policy
4822 Editor, click on the 'File' menus and select 'New'. Then
4823 define our new policy model called
4824 ``MyFirstPolicyModel``. Use the 'Generate UUID' button to
4825 create a new unique ID for the policy model, and fill in
4826 a description for the policy model. Press the ``Submit``
4827 button to save your changes.
4829 .. container:: imageblock
4831 .. container:: content
4833 |File > New to create a new Policy Model|
4835 .. container:: title
4837 Figure 4. Create a new Policy Model 1/2
4839 .. container:: imageblock
4841 .. container:: content
4843 |Create a new Policy Model|
4845 .. container:: title
4847 Figure 5. Create a new Policy Model 2/2
4849 Create the input event ``SALE_INPUT`` and the output event ``SALE_AUTH``
4850 ########################################################################
4852 .. container:: paragraph
4854 Using the APEX Policy Editor, click on the 'Events' tab.
4855 In the 'Events' pane, right click and select 'New':
4857 .. container:: imageblock
4859 .. container:: content
4861 |Right click to create a new event|
4863 .. container:: title
4865 Figure 6. Create a new Event type
4867 .. container:: paragraph
4869 Create a new event type called ``SALE_INPUT``. Use the
4870 'Generate UUID' button to create a new unique ID for the
4871 event type, and fill in a description for the event. Add
4872 a namespace, e.g. ``com.hyperm``. We can add hard-coded
4873 strings for the ``Source`` and ``Target``, e.g. ``POS``
4874 and ``APEX``. At this stage we will not add any parameter
4875 fields, we will leave this until later. Use the
4876 ``Submit`` button to create the event.
4878 .. container:: imageblock
4880 .. container:: content
4882 |Fill in the necessary information for the
4883 'SALE_INPUT' event and click 'Submit'|
4885 .. container:: title
4887 Figure 7. Populate the ``SALE_INPUT`` event
4889 .. container:: paragraph
4891 Repeat the same steps for a new event type called
4892 ``SALE_AUTH``. Just use ``APEX`` as source and ``POS`` as
4893 target, since this is the output event coming from APEX
4894 going to the sales point.
4896 .. container:: paragraph
4898 Before we can add parameter fields to an event we must
4899 first define APEX Context Item Schemas that can be used
4902 .. container:: paragraph
4904 To create new item schemas, click on the 'Context Item
4905 Schemas' tab. In that 'Context Item Schemas' pane, right
4906 click and select 'Create new ContextSchema'.
4908 .. container:: imageblock
4910 .. container:: content
4912 |Right click to create a new Item Schema|
4914 .. container:: title
4916 Figure 8. Create new Data Types
4918 .. container:: paragraph
4920 Create item schemas with the following characteristics,
4921 each with its own unique UUID:
4923 .. table:: Table 6. Item Schemas
4925 +-------------------+-----------------+-----------------+----------------------+
4926 | Name | Schema Flavour | Schema | Description |
4927 | | | Definition | |
4928 +===================+=================+=================+======================+
4929 | timestamp_type | Java | java.lang.Long | A type for |
4930 | | | | ``time`` values |
4931 +-------------------+-----------------+-----------------+----------------------+
4932 | sale_ID_type | Java | java.lang.Long | A type for |
4933 | | | | ``sale_ID`` |
4935 +-------------------+-----------------+-----------------+----------------------+
4936 | price_type | Java | java.lang.Long | A type for |
4937 | | | | ``amount``/``price`` |
4939 +-------------------+-----------------+-----------------+----------------------+
4940 | item_ID_type | Java | java.lang.Long | A type for |
4941 | | | | ``item_ID`` |
4943 +-------------------+-----------------+-----------------+----------------------+
4944 | assistant_ID_type | Java | java.lang.Long | A type for |
4945 | | | | ``assistant_ID`` |
4947 +-------------------+-----------------+-----------------+----------------------+
4948 | quantity_type | Java | java.lang.Integ | A type for |
4949 | | | er | ``quantity`` |
4951 +-------------------+-----------------+-----------------+----------------------+
4952 | branch_ID_type | Java | java.lang.Long | A type for |
4953 | | | | ``branch_ID`` |
4955 +-------------------+-----------------+-----------------+----------------------+
4956 | notes_type | Java | java.lang.Strin | A type for |
4957 | | | g | ``notes`` |
4959 +-------------------+-----------------+-----------------+----------------------+
4960 | authorised_type | Java | java.lang.Boole | A type for |
4961 | | | an | ``authorised`` |
4963 +-------------------+-----------------+-----------------+----------------------+
4964 | message_type | Java | java.lang.Strin | A type for |
4965 | | | g | ``message`` |
4967 +-------------------+-----------------+-----------------+----------------------+
4969 .. container:: imageblock
4971 .. container:: content
4973 |Create a new Item Schema|
4975 .. container:: title
4977 Figure 9. Create new Item Schemas
4979 .. container:: paragraph
4981 The item schemas can now be seen on the 'Context Item
4982 Schemas' tab, and can be updated at any time by
4983 right-clicking on the item schemas on the 'Context Item
4984 Schemas' tab. Now we can go back to the event definitions
4985 for ``SALE_INPUT`` and ``SALE_AUTH`` and add some
4990 .. container:: title
4994 .. container:: paragraph
4996 APEX natively supports schema definitions in ``Java`` and ``Avro``.
4998 .. container:: paragraph
5000 ``Java`` schema definitions are simply the name of a Java Class. There are some restrictions:
5002 .. container:: ulist
5004 - the class must be instantiatable, i.e. not an Java interface or abstract class
5006 - primitive types are not supported, i.e. use ``java.lang.Integer`` instead of ``int``, etc.
5008 - it must be possible to find the class, i.e. the class must be contained in the Java classpath.
5010 .. container:: paragraph
5012 ``Avro`` schema definitions can be any valid `Avro <https://avro.apache.org/docs/current/spec.html>`__
5013 schema. For events using fields defined with ``Avro`` schemas, any incoming event containing that field must
5014 contain a value that conforms to the Avro schema.
5016 .. container:: paragraph
5018 Click on the 'Events' tab, then right click the
5019 ``SALE_INPUT`` row and select 'Edit Event
5020 :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`
5021 event add the following event parameters:
5023 .. table:: Table 7. Event Parameter Fields for the ``SALE_INPUT`` Event
5025 +----------------------+----------------------+-----------------------+
5026 | Parameter Name | Parameter Type | Optional |
5027 +======================+======================+=======================+
5028 | time | timestamp_type | no |
5029 +----------------------+----------------------+-----------------------+
5030 | sale_ID | sale_ID_type | no |
5031 +----------------------+----------------------+-----------------------+
5032 | amount | price_type | no |
5033 +----------------------+----------------------+-----------------------+
5034 | item_ID | item_ID_type | no |
5035 +----------------------+----------------------+-----------------------+
5036 | quantity | quantity_type | no |
5037 +----------------------+----------------------+-----------------------+
5038 | assistant_ID | assistant_ID_type | no |
5039 +----------------------+----------------------+-----------------------+
5040 | branch_ID | branch_ID_type | no |
5041 +----------------------+----------------------+-----------------------+
5042 | notes | notes_type | *yes* |
5043 +----------------------+----------------------+-----------------------+
5045 .. container:: paragraph
5047 Remember to click the 'Submit' button at the bottom of
5048 the event definition pane.
5051 Optional Fields in APEX Events
5052 Parameter fields can be *optional* in events. If a parameter is not marked as *optional* then by default it
5053 is *mandatory*, so it must appear in any input event passed to APEX. If an *optional* field is not set
5054 for an output event then value will be set to ``null``.
5056 .. container:: imageblock
5058 .. container:: content
5060 |Add new event parameters to an event|
5062 .. container:: title
5064 Figure 10. Add typed parameter fields to an event
5066 .. container:: paragraph
5068 Select the ``SALE_AUTH`` event and add the following
5071 .. table:: Table 8. Event Parameter Fields for the ``SALE_AUTH`` Event
5073 +----------------------+----------------------+-----------------------+
5074 | Parameter Name | Parameter Type | no |
5075 +======================+======================+=======================+
5076 | sale_ID | sale_ID_type | no |
5077 +----------------------+----------------------+-----------------------+
5078 | time | timestamp_type | no |
5079 +----------------------+----------------------+-----------------------+
5080 | authorised | authorised_type | no |
5081 +----------------------+----------------------+-----------------------+
5082 | message | message_type | *yes* |
5083 +----------------------+----------------------+-----------------------+
5084 | amount | price_type | no |
5085 +----------------------+----------------------+-----------------------+
5086 | item_ID | item_ID_type | no |
5087 +----------------------+----------------------+-----------------------+
5088 | assistant_ID | assistant_ID_type | no |
5089 +----------------------+----------------------+-----------------------+
5090 | quantity | quantity_type | no |
5091 +----------------------+----------------------+-----------------------+
5092 | branch_ID | branch_ID_type | no |
5093 +----------------------+----------------------+-----------------------+
5094 | notes | notes_type | *yes* |
5095 +----------------------+----------------------+-----------------------+
5097 .. container:: paragraph
5099 Remember to click the 'Submit' button at the bottom of
5100 the event definition pane.
5102 .. container:: paragraph
5104 The events for our policy are now defined.
5106 Create a new Policy and add the *"No Booze before 11:30"* check
5107 ###############################################################
5109 .. container:: paragraph
5111 APEX policies are defined using a state-machine model.
5112 Each policy comprises one or more *states* that can be
5113 individually executed. Where there is more than one
5114 *state* the states are chained together to form a
5115 `Directed Acyclic Graph
5116 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__
5117 of states. A *state* is triggered by passing it a single
5118 input (or 'trigger') event and once executed each state
5119 then emits an output event. For each *state* the logic
5120 for the *state* is embedded in one or more *tasks*. Each
5121 *task* contains specific *task logic* that is executed by
5122 the APEX execution environment each time the *task* is
5123 invoked. Where there is more than one *task* in a *state*
5124 then the *state* also defines some *task selection logic*
5125 to select an appropriate task each time the *state* is
5128 .. container:: paragraph
5130 Therefore, to create a new policy we must first define
5133 .. container:: paragraph
5135 To create a new Task click on the 'Tasks' tab. In the
5136 'Tasks' pane, right click and select 'Create new Task'.
5137 Create a new Task called ``MorningBoozeCheck``. Use the
5138 'Generate UUID' button to create a new unique ID for the
5139 task, and fill in a description for the task.
5141 .. container:: imageblock
5143 .. container:: content
5145 |Right click to create a new task|
5147 .. container:: title
5149 Figure 11. Create a new Task
5151 .. container:: paragraph
5153 Tasks are configured with a set of *input fields* and a
5154 set of *output fields*. To add new input/output fields
5155 for a task use the 'Add Task Input Field' and 'Add Task
5156 Output Field' button. The list of input and out fields to
5157 add for the ``MorningBoozeCheck`` task are given below.
5158 The input fields are drawn from the parameters in the
5159 state’s input event, and the task’s output fields are
5160 used to populate the state’s output event. The task’s
5161 input and output fields must be a subset of the event
5162 parameters defined for the input and output events for
5163 any state that uses that task. (You may have noticed that
5164 the input and output fields for the ``MorningBoozeCheck``
5165 task have the exact same names and reuse the item schemas
5166 that we used for the parameters in the ``SALE_INPUT`` and
5167 ``SALE_AUTH`` events respectively).
5169 .. table:: Table 9. Input fields for ``MorningBoozeCheck`` task
5171 +-----------------------------------+-----------------------------------+
5172 | Parameter Name | Parameter Type |
5173 +===================================+===================================+
5174 | time | timestamp_type |
5175 +-----------------------------------+-----------------------------------+
5176 | sale_ID | sale_ID_type |
5177 +-----------------------------------+-----------------------------------+
5178 | amount | price_type |
5179 +-----------------------------------+-----------------------------------+
5180 | item_ID | item_ID_type |
5181 +-----------------------------------+-----------------------------------+
5182 | quantity | quantity_type |
5183 +-----------------------------------+-----------------------------------+
5184 | assistant_ID | assistant_ID_type |
5185 +-----------------------------------+-----------------------------------+
5186 | branch_ID | branch_ID_type |
5187 +-----------------------------------+-----------------------------------+
5188 | notes | notes_type |
5189 +-----------------------------------+-----------------------------------+
5191 .. table:: Table 10. Output fields for ``MorningBoozeCheck`` task
5193 +-----------------------------------+-----------------------------------+
5194 | Parameter Name | Parameter Type |
5195 +===================================+===================================+
5196 | sale_ID | sale_ID_type |
5197 +-----------------------------------+-----------------------------------+
5198 | time | timestamp_type |
5199 +-----------------------------------+-----------------------------------+
5200 | authorised | authorised_type |
5201 +-----------------------------------+-----------------------------------+
5202 | message | message_type |
5203 +-----------------------------------+-----------------------------------+
5204 | amount | price_type |
5205 +-----------------------------------+-----------------------------------+
5206 | item_ID | item_ID_type |
5207 +-----------------------------------+-----------------------------------+
5208 | assistant_ID | assistant_ID_type |
5209 +-----------------------------------+-----------------------------------+
5210 | quantity | quantity_type |
5211 +-----------------------------------+-----------------------------------+
5212 | branch_ID | branch_ID_type |
5213 +-----------------------------------+-----------------------------------+
5214 | notes | notes_type |
5215 +-----------------------------------+-----------------------------------+
5217 .. container:: imageblock
5219 .. container:: content
5221 |Add input and out fields for the task|
5223 .. container:: title
5225 Figure 12. Add input and out fields for the Task
5227 .. container:: paragraph
5229 Each task must include some 'Task Logic' that implements
5230 the behaviour for the task. Task logic can be defined in
5231 a number of different ways using a choice of languages.
5232 For this task we will author the logic using the
5233 Java-like scripting language called
5234 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__.
5236 .. container:: paragraph
5238 For simplicity use the following code for the task logic.
5239 Paste the script text into the 'Task Logic' box, and use
5240 "MVEL" as the 'Task Logic Type / Flavour'.
5242 .. container:: paragraph
5244 This logic assumes that all items with ``item_ID``
5245 between 1000 and 2000 contain alcohol, which is not very
5246 realistic, but we will see a better approach for this
5247 later. It also uses the standard ``Java`` time utilities
5248 to check if the current time is between ``00:00:00 GMT``
5249 and ``11:30:00 GMT``. For a detailed guide to how to
5250 write your own logic in
5251 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
5252 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
5253 of the other supported languages please refer to APEX
5256 .. container:: listingblock
5258 .. container:: title
5260 MVEL code for the ``MorningBoozeCheck`` task
5262 .. container:: content
5267 * ============LICENSE_START=======================================================
5268 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5269 * ================================================================================
5270 * Licensed under the Apache License, Version 2.0 (the "License");
5271 * you may not use this file except in compliance with the License.
5272 * You may obtain a copy of the License at
5274 * http://www.apache.org/licenses/LICENSE-2.0
5276 * Unless required by applicable law or agreed to in writing, software
5277 * distributed under the License is distributed on an "AS IS" BASIS,
5278 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5279 * See the License for the specific language governing permissions and
5280 * limitations under the License.
5282 * SPDX-License-Identifier: Apache-2.0
5283 * ============LICENSE_END=========================================================
5285 import java.util.Date;
5286 import java.util.Calendar;
5287 import java.util.TimeZone;
5288 import java.text.SimpleDateFormat;
5290 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
5292 outFields.put("amount" , inFields.get("amount"));
5293 outFields.put("assistant_ID", inFields.get("assistant_ID"));
5294 outFields.put("notes" , inFields.get("notes"));
5295 outFields.put("quantity" , inFields.get("quantity"));
5296 outFields.put("branch_ID" , inFields.get("branch_ID"));
5297 outFields.put("item_ID" , inFields.get("item_ID"));
5298 outFields.put("time" , inFields.get("time"));
5299 outFields.put("sale_ID" , inFields.get("sale_ID"));
5301 item_id = inFields.get("item_ID");
5303 //The events used later to test this task use GMT timezone!
5304 gmt = TimeZone.getTimeZone("GMT");
5305 timenow = Calendar.getInstance(gmt);
5306 df = new SimpleDateFormat("HH:mm:ss z");
5307 df.setTimeZone(gmt);
5308 timenow.setTimeInMillis(inFields.get("time"));
5310 midnight = timenow.clone();
5312 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5313 timenow.get(Calendar.DATE),0,0,0);
5314 eleven30 = timenow.clone();
5316 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5317 timenow.get(Calendar.DATE),11,30,0);
5319 itemisalcohol = false;
5320 if(item_id != null && item_id >=1000 && item_id < 2000)
5321 itemisalcohol = true;
5324 && timenow.after(midnight) && timenow.before(eleven30)){
5325 outFields.put("authorised", false);
5326 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
5327 " for time "+df.format(timenow.getTime())+
5328 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
5329 " and "+df.format(eleven30.getTime()));
5333 outFields.put("authorised", true);
5334 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
5335 " for time "+df.format(timenow.getTime()));
5340 This task checks if a sale request is for an item that is an alcoholic drink.
5341 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5342 authorised. Otherwise the sale is authorised.
5343 In this implementation we assume that items with item_ID value between 1000 and
5344 2000 are all alcoholic drinks :-)
5347 .. container:: imageblock
5349 .. container:: content
5351 |Add task logic the task|
5353 .. container:: title
5355 Figure 13. Add Task Logic the Task
5357 .. container:: paragraph
5359 An alternative version of the same logic is available in
5360 JavaScript. Just use "JAVASCRIPT" as the 'Task Logic Type
5363 .. container:: listingblock
5365 .. container:: title
5367 Javascript alternative for the ``MorningBoozeCheck``
5370 .. container:: content
5375 * ============LICENSE_START=======================================================
5376 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5377 * ================================================================================
5378 * Licensed under the Apache License, Version 2.0 (the "License");
5379 * you may not use this file except in compliance with the License.
5380 * You may obtain a copy of the License at
5382 * http://www.apache.org/licenses/LICENSE-2.0
5384 * Unless required by applicable law or agreed to in writing, software
5385 * distributed under the License is distributed on an "AS IS" BASIS,
5386 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5387 * See the License for the specific language governing permissions and
5388 * limitations under the License.
5390 * SPDX-License-Identifier: Apache-2.0
5391 * ============LICENSE_END=========================================================
5394 var returnValueType = Java.type("java.lang.Boolean");
5395 var returnValue = new returnValueType(true);
5397 // Load compatibility script for imports etc
5398 load("nashorn:mozilla_compat.js");
5399 importPackage(java.text);
5400 importClass(java.text.SimpleDateFormat);
5402 executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'");
5404 executor.outFields.put("amount" , executor.inFields.get("amount"));
5405 executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID"));
5406 executor.outFields.put("notes" , executor.inFields.get("notes"));
5407 executor.outFields.put("quantity" , executor.inFields.get("quantity"));
5408 executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID"));
5409 executor.outFields.put("item_ID" , executor.inFields.get("item_ID"));
5410 executor.outFields.put("time" , executor.inFields.get("time"));
5411 executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID"));
5413 item_id = executor.inFields.get("item_ID");
5415 //All times in this script are in GMT/UTC since the policy and events assume time is in GMT.
5416 var timenow_gmt = new Date(Number(executor.inFields.get("time")));
5418 var midnight_gmt = new Date(Number(executor.inFields.get("time")));
5419 midnight_gmt.setUTCHours(0,0,0,0);
5421 var eleven30_gmt = new Date(Number(executor.inFields.get("time")));
5422 eleven30_gmt.setUTCHours(11,30,0,0);
5424 var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z");
5426 var itemisalcohol = false;
5427 if(item_id != null && item_id >=1000 && item_id < 2000)
5428 itemisalcohol = true;
5431 && timenow_gmt.getTime() >= midnight_gmt.getTime()
5432 && timenow_gmt.getTime() < eleven30_gmt.getTime()) {
5434 executor.outFields.put("authorised", false);
5435 executor.outFields.put("message", "Sale not authorised by policy task " +
5436 executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) +
5437 ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) +
5438 " and " + timeformatter.format(eleven30_gmt.getTime()));
5441 executor.outFields.put("authorised", true);
5442 executor.outFields.put("message", "Sale authorised by policy task " +
5443 executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime()));
5447 This task checks if a sale request is for an item that is an alcoholic drink.
5448 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5449 authorised. Otherwise the sale is authorised.
5450 In this implementation we assume that items with item_ID value between 1000 and
5451 2000 are all alcoholic drinks :-)
5454 .. container:: paragraph
5456 The task definition is now complete so click the 'Submit'
5457 button to save the task. The task can now be seen on the
5458 'Tasks' tab, and can be updated at any time by
5459 right-clicking on the task on the 'Task' tab. Now that we
5460 have created our task, we can can create a policy that
5463 .. container:: paragraph
5465 To create a new Policy click on the 'Policies' tab. In
5466 the 'Policies' pane, right click and select 'Create new
5469 .. container:: paragraph
5471 Create a new Policy called ``MyFirstPolicy``. Use the
5472 'Generate UUID' button to create a new unique ID for the
5473 policy, and fill in a description for the policy. Use
5474 'FREEFORM' as the 'Policy Flavour'.
5476 .. container:: paragraph
5478 Each policy must have at least one state. Since this is
5479 'freeform' policy we can add as many states as we wish.
5480 Let’s start with one state. Add a new state called
5481 ``BoozeAuthDecide`` to this ``MyFirstPolicy`` policy
5482 using the 'Add new State' button after filling in the
5483 name of our new state.
5485 .. container:: imageblock
5487 .. container:: content
5489 |Create a new policy|
5491 .. container:: title
5493 Figure 14. Create a new Policy
5495 .. container:: paragraph
5497 Each state must uses one input event type. For this new
5498 state select the ``SALE_INPUT`` event as the input event.
5500 .. container:: paragraph
5502 Each policy must define a 'First State' and a 'Policy
5503 Trigger Event'. The 'Policy Trigger Event' is the input
5504 event for the policy as a whole. This event is then
5505 passed to the first state in the chain of states in the
5506 policy, therefore the 'Policy Trigger Event' will be the
5507 input event for the first state. Each policy can only
5508 have one 'First State'. For our ``MyFirstPolicy`` policy,
5509 select ``BoozeAuthDecide`` as the 'First State'. This
5510 will automatically select ``SALE_INPUT`` as the 'Policy
5511 Trigger Event' for our policy.
5513 .. container:: imageblock
5515 .. container:: content
5519 .. container:: title
5521 Figure 15. Create a new State
5523 .. container:: paragraph
5525 In this case we will create a reference the pre-existing
5526 ``MorningBoozeCheck`` task that we defined above using
5527 the 'Add New Task' button. Select the
5528 ``MorningBoozeCheck`` task, and use the name of the task
5529 as the 'Local Name' for the task.
5531 .. container:: paragraph
5533 in the case where a state references more than one task,
5534 a 'Default Task' must be selected for the state and some
5535 logic ('Task Selection Logic') must be specified to
5536 select the appropriate task at execution time. Since our
5537 new state ``BoozeAuthDecide`` only has one task the
5538 default task is automatically selected and no 'Task
5539 Selection Logic' is required.
5542 .. container:: title
5544 State Output Mappings
5546 .. container:: paragraph
5548 In a 'Policy' 'State' a 'State Output Mapping' has 3 roles:
5549 1) Select which 'State' should be executed next, 2) Select
5550 the type of the state’s 'Outgoing Event', and 3)
5551 Populate the state’s 'Outgoing Event'. This is how states are
5552 chained together to form a (`Directed Acyclic Graph
5553 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__ )
5554 of states. The final state(s) of a policy are those that do
5555 not select any 'next' state. Since a 'State' can only
5556 accept a single type of event, the type of the event emitted
5557 by a previous 'State' must be match the incoming event type
5558 of the next 'State'. This is also how the last state(s) in
5559 a policy can emit events of different types. The 'State
5560 Output Mapping' is also responsible for taking the
5561 fields that are output by the task executed in the state and
5562 populating the state’s output event before it is emitted.
5564 .. container:: paragraph
5566 Each 'Task' referenced in 'State' must have a defined
5567 'Output Mapping' to take the output of the task, select an
5568 'Outgoing Event' type for the state, populate the state’s
5569 outgoing event, and then select the next state to be
5572 .. container:: paragraph
5574 There are 2 basic types of output mappings:
5576 .. container:: olist arabic
5578 #. **Direct Output Mappings** have a single value for
5579 'Next State' and a single value for 'State Output
5580 Event'. The outgoing event for the state is
5581 automatically created, any outgoing event parameters
5582 that were present in the incoming event are copied
5583 into the outgoing event, then any task output fields
5584 that have the same name and type as parameters in the
5585 outgoing event are automatically copied into
5588 #. **Logic-based State Output Mappings / Finalizers**
5589 have some logic defined that dynamically selects
5590 and creates the 'State Outgoing Event', manages
5591 the population of the outgoing event parameters
5592 (perhaps changing or adding to the outputs from the
5593 task), and then dynamically selects the next state to
5594 be executed (if any).
5596 .. container:: paragraph
5598 Each task reference must also have an associated 'Output
5599 State Mapping' so we need an 'Output State Mapping' for
5600 the ``BoozeAuthDecide`` state to use when the
5601 ``MorningBoozeCheck`` task is executed. The simplest type
5602 of output mapping is a 'Direct Output Mapping'.
5604 .. container:: paragraph
5606 Create a new 'Direct Output Mapping' for the state called
5607 ``MorningBoozeCheck_Output_Direct`` using the 'Add New
5608 Direct State Output Mapping' button. Select ``SALE_AUTH``
5609 as the output event and select ``None`` for the next
5610 state value. We can then select this output mapping for
5611 use when the the ``MorningBoozeCheck`` task is executed.
5612 Since there is only state, and only one task for that
5613 state, this output mapping ensures that the
5614 ``BoozeAuthDecide`` state is the only state executed and
5615 the state (and the policy) can only emit events of type
5616 ``SALE_AUTH``. (You may remember that the output fields
5617 for the ``MorningBoozeCheck`` task have the exact same
5618 names and reuse the item schemas that we used for the
5619 parameters in ``SALE_AUTH`` event. The
5620 ``MorningBoozeCheck_Output_Direct`` direct output mapping
5621 can now automatically copy the values from the
5622 ``MorningBoozeCheck`` task directly into outgoing
5623 ``SALE_AUTH`` events.)
5625 .. container:: imageblock
5627 .. container:: content
5629 |Add a Task and Output Mapping|
5631 .. container:: title
5633 Figure 16. Add a Task and Output Mapping
5635 .. container:: paragraph
5637 Click the 'Submit' button to complete the definition of
5638 our ``MyFirstPolicy`` policy. The policy
5639 ``MyFirstPolicy`` can now be seen in the list of policies
5640 on the 'Policies' tab, and can be updated at any time by
5641 right-clicking on the policy on the 'Policies' tab.
5643 .. container:: paragraph
5645 The ``MyFirstPolicyModel``, including our
5646 ``MyFirstPolicy`` policy can now be checked for errors.
5647 Click on the 'Model' menu and select 'Validate'. The
5648 model should validate without any 'Warning' or 'Error'
5649 messages. If you see any 'Error' or 'Warning' messages,
5650 carefully read the message as a hint to find where you
5651 might have made a mistake when defining some aspect of
5654 .. container:: imageblock
5656 .. container:: content
5658 |Validate the policy model for error using the 'Model'
5659 > 'Validate' menu item|
5661 .. container:: title
5663 Figure 17. Validate a Policy Model
5665 .. container:: paragraph
5667 Congratulations, you have now completed your first APEX
5668 policy. The policy model containing our new policy can
5669 now be exported from the editor and saved. Click on the
5670 'File' menu and select 'Download' to save the policy
5671 model in JSON format. The exported policy model is then
5672 available in the directory you selected, for instance
5673 ``$APEX_HOME/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json``.
5674 The exported policy can now be loaded into the APEX
5675 Policy Engine, or can be re-loaded and edited by the APEX
5678 .. container:: imageblock
5680 .. container:: content
5682 |Download the completed policy model using the 'File'
5683 > 'Download' menu item|
5685 .. container:: title
5687 Figure 18. Export a Policy Model
5692 .. container:: paragraph
5694 To start a new APEX Engine you can use the following
5695 configuration. In a full APEX installation you can find
5696 this configuration in
5697 ``$APEX_HOME/examples/config/MyFirstPolicy/1/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
5698 This configuration expects incoming events to be in
5699 ``JSON`` format and to be passed into the APEX Engine
5700 from ``stdin``, and result events will be printed in
5701 ``JSON`` format to ``stdout``. This configuration loads
5702 the policy model stored in the file
5703 'MyFirstPolicyModel_0.0.1.json' as exported from the APEX
5704 Editor. Note, you may need to edit this file to provide
5705 the full path to wherever you stored the exported policy
5708 .. container:: listingblock
5710 .. container:: title
5712 JSON to load and execute *My First Policy*, read input
5713 JSON events from ``stdin``, and emit output events to
5716 .. container:: content
5721 "engineServiceParameters" : {
5722 "name" : "MyFirstPolicyApexEngine",
5723 "version" : "0.0.1",
5725 "instanceCount" : 4,
5726 "deploymentPort" : 12345,
5727 "policyModelFileName" : "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json",
5728 "engineParameters" : {
5729 "executorParameters" : {
5731 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
5734 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
5739 "eventOutputParameters": {
5741 "carrierTechnologyParameters" : {
5742 "carrierTechnology" : "FILE",
5747 "eventProtocolParameters" : {
5748 "eventProtocol" : "JSON"
5752 "eventInputParameters": {
5754 "carrierTechnologyParameters" : {
5755 "carrierTechnology" : "FILE",
5760 "eventProtocolParameters" : {
5761 "eventProtocol" : "JSON"
5767 .. container:: paragraph
5769 To test the policy try paste the following events into
5770 the console as the APEX engine executes:
5772 .. table:: Table 11. Inputs and Outputs when testing *My First Policy*
5774 +------------------------------------------+-------------------------------------------+-----------+
5775 | Input Event (JSON) | Output Event (JSON) | comment |
5776 +==========================================+===========================================+===========+
5777 | .. container:: | .. container:: | Request |
5779 | .. container:: listingblock | .. container:: listingblock | non-alcoh |
5781 | | .. container:: content | item |
5782 | .. container:: content | | (``item_I |
5783 | | .. code:: | D=5123``) |
5785 | .. code:: | { | *10:13:09 |
5786 | | "name": "SALE_AUTH", | * |
5788 | { | "version": "0.0.1", | *Tuesday, |
5789 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | 10 |
5790 | "name" : "SALE_INPUT", | "source": "", | January |
5791 | "version": "0.0.1", | "target": "", | 2017*. |
5792 | "time" : 1483351989000, | "amount": 299, | Sale is |
5793 | "sale_ID": 99999991, | "assistant_ID": 23, | authorize |
5794 | "amount": 299, | "authorised": true, | d. |
5795 | "item_ID": 5123, | "branch_ID": 1, | |
5796 | "quantity": 1, | "item_ID": 5123, | |
5797 | "assistant_ID": 23, | "message": "Sale authorised | |
5798 | "branch_ID": 1, | by policy task MorningBo | |
5799 | "notes": "Special Offer!!" | ozeCheck for time 10:13:09 | |
5801 | | "notes": "Special Offer!!", | |
5802 | | "quantity": 1, | |
5803 | | "sale_ID": 99999991, | |
5804 | | "time": 1483351989000 | |
5809 +------------------------------------------+-------------------------------------------+-----------+
5810 | .. container:: | .. container:: | Request |
5812 | .. container:: listingblock | .. container:: listingblock | alcohol |
5814 | .. container:: content | .. container:: content | (``item_I |
5816 | .. code:: | .. code:: | at |
5819 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | on |
5820 | "name": "SALE_INPUT", | "name": "SALE_AUTH", | *Monday, |
5821 | "version": "0.0.1", | "source": "", | 02 |
5822 | "time": 1483346466000, | "target": "", | January |
5823 | "sale_ID": 99999992, | "amount": 1249, | 2017*. |
5824 | "version": "0.0.1", | "assistant_ID": 12, | |
5825 | "amount": 1249, | "authorised": false, | Sale is |
5826 | "item_ID": 1012, | "branch_ID": 2, | not |
5827 | "quantity": 1, | "item_ID": 1012, | authorize |
5828 | "assistant_ID": 12, | "message": "Sale not | d. |
5829 | "branch_ID": 2 | authorised by policy task | |
5830 | } | MorningBoozeCheck for time | |
5831 | | 08:41:06 GMT. Alcohol can | |
5832 | | not be sold between | |
5833 | | 00:00:00 GMT and 11:30:00 | |
5835 | | "notes": null, | |
5836 | | "quantity": 1, | |
5837 | | "sale_ID": 99999992, | |
5838 | | "time": 1483346466000 | |
5840 +------------------------------------------+-------------------------------------------+-----------+
5841 | .. container:: | .. container:: | Request |
5843 | .. container:: listingblock | .. container:: listingblock | alcohol |
5845 | | .. container:: content | D=1943``) |
5846 | .. container:: content | | at |
5847 | | .. code:: | *20:17:13 |
5849 | .. code:: | { | on |
5850 | | "name": "SALE_AUTH", | *Tuesday, |
5851 | { | "version": "0.0.1", | 20 |
5852 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | December |
5853 | "name" : "SALE_INPUT", | "source": "", | 2016*. |
5854 | "version": "0.0.1", | "target": "", | |
5855 | "time" : 1482265033000, | "amount": 4799, | Sale is |
5856 | "sale_ID": 99999993, | "assistant_ID": 9, | authorize |
5857 | "amount": 4799, | "authorised": true, | d. |
5858 | "item_ID": 1943, | "branch_ID": 3, | |
5859 | "quantity": 2, | "item_ID": 1943, | |
5860 | "assistant_ID": 9, | "message": "Sale authorised | |
5861 | "branch_ID": 3 | by policy task MorningBo | |
5862 | } | ozeCheck for time 20:17:13 | |
5864 | | "notes": null, | |
5865 | | "quantity": 2, | |
5866 | | "sale_ID": 99999993, | |
5867 | | "time": 1482265033000 | |
5869 +------------------------------------------+-------------------------------------------+-----------+
5871 4.3.6. Policy 1 in CLI Editor
5872 #############################
5874 .. container:: paragraph
5876 An equivalent version of the ``MyFirstPolicyModel``
5877 policy model can again be generated using the APEX CLI
5878 editor. A sample APEX CLI script is shown below:
5880 .. container:: listingblock
5882 .. container:: title
5884 APEX CLI Editor code for Policy 1
5886 .. container:: content
5890 #-------------------------------------------------------------------------------
5891 # ============LICENSE_START=======================================================
5892 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
5893 # ================================================================================
5894 # Licensed under the Apache License, Version 2.0 (the "License");
5895 # you may not use this file except in compliance with the License.
5896 # You may obtain a copy of the License at
5898 # http://www.apache.org/licenses/LICENSE-2.0
5900 # Unless required by applicable law or agreed to in writing, software
5901 # distributed under the License is distributed on an "AS IS" BASIS,
5902 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5903 # See the License for the specific language governing permissions and
5904 # limitations under the License.
5906 # SPDX-License-Identifier: Apache-2.0
5907 # ============LICENSE_END=========================================================
5908 #-------------------------------------------------------------------------------
5910 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
5912 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
5914 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
5916 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
5918 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
5920 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
5922 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
5924 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
5926 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
5928 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
5930 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
5932 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
5933 This task checks if the sales request is for an item that contains alcohol.
5934 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
5935 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
5937 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
5938 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
5939 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
5940 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
5941 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
5942 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
5943 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
5944 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
5945 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
5946 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
5947 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
5948 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
5949 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
5950 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
5951 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
5952 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
5953 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
5954 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
5955 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
5957 * ============LICENSE_START=======================================================
5958 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5959 * ================================================================================
5960 * Licensed under the Apache License, Version 2.0 (the "License");
5961 * you may not use this file except in compliance with the License.
5962 * You may obtain a copy of the License at
5964 * http://www.apache.org/licenses/LICENSE-2.0
5966 * Unless required by applicable law or agreed to in writing, software
5967 * distributed under the License is distributed on an "AS IS" BASIS,
5968 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5969 * See the License for the specific language governing permissions and
5970 * limitations under the License.
5972 * SPDX-License-Identifier: Apache-2.0
5973 * ============LICENSE_END=========================================================
5975 import java.util.Date;
5976 import java.util.Calendar;
5977 import java.util.TimeZone;
5978 import java.text.SimpleDateFormat;
5980 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
5982 outFields.put("amount" , inFields.get("amount"));
5983 outFields.put("assistant_ID", inFields.get("assistant_ID"));
5984 outFields.put("notes" , inFields.get("notes"));
5985 outFields.put("quantity" , inFields.get("quantity"));
5986 outFields.put("branch_ID" , inFields.get("branch_ID"));
5987 outFields.put("item_ID" , inFields.get("item_ID"));
5988 outFields.put("time" , inFields.get("time"));
5989 outFields.put("sale_ID" , inFields.get("sale_ID"));
5991 item_id = inFields.get("item_ID");
5993 //The events used later to test this task use GMT timezone!
5994 gmt = TimeZone.getTimeZone("GMT");
5995 timenow = Calendar.getInstance(gmt);
5996 df = new SimpleDateFormat("HH:mm:ss z");
5997 df.setTimeZone(gmt);
5998 timenow.setTimeInMillis(inFields.get("time"));
6000 midnight = timenow.clone();
6002 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6003 timenow.get(Calendar.DATE),0,0,0);
6004 eleven30 = timenow.clone();
6006 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6007 timenow.get(Calendar.DATE),11,30,0);
6009 itemisalcohol = false;
6010 if(item_id != null && item_id >=1000 && item_id < 2000)
6011 itemisalcohol = true;
6014 && timenow.after(midnight) && timenow.before(eleven30)){
6015 outFields.put("authorised", false);
6016 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6017 " for time "+df.format(timenow.getTime())+
6018 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6019 " and "+df.format(eleven30.getTime()));
6023 outFields.put("authorised", true);
6024 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6025 " for time "+df.format(timenow.getTime()));
6030 This task checks if a sale request is for an item that is an alcoholic drink.
6031 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6032 authorised. Otherwise the sale is authorised.
6033 In this implementation we assume that items with item_ID value between 1000 and
6034 2000 are all alcoholic drinks :-)
6038 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"
6039 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6040 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6041 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
6042 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6043 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6044 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6045 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6046 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6047 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6048 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6050 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"
6051 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6052 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6053 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6054 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6055 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6056 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6057 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6058 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6061 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
6062 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
6063 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
6064 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
6071 .. container:: paragraph
6073 *HyperM* have just opened a new branch in a different
6074 country, but that country has different rules about when
6075 alcohol can be sold! In this section we will go through
6076 the necessary steps to extend our policy to enforce this
6079 .. container:: ulist
6081 - In some branches alcohol cannot be sold before 1pm,
6082 and not at all on Sundays.
6084 .. container:: paragraph
6086 Although there are a number of ways to accomplish this
6087 the easiest approach for us is to define another task and
6088 then select which task is appropriate at runtime
6089 depending on the branch identifier in the incoming event.
6091 Extend the Policy with the new Scenario
6092 #######################################
6094 .. container:: paragraph
6096 To create a new Task click on the 'Tasks' tab. In the
6097 'Tasks' pane, right click and select 'Create new Task':
6099 .. container:: paragraph
6101 Create a new Task called ``MorningBoozeCheckAlt1``. Use
6102 the 'Generate UUID' button to create a new unique ID for
6103 the task, and fill in a description for the task. Select
6104 the same input and output fields that we used earlier
6105 when we defined the ``MorningBoozeCheck`` task earlier.
6107 .. table:: Table 12. Input fields for ``MorningBoozeCheckAlt1`` task
6109 +-----------------------------------+-----------------------------------+
6110 | Parameter Name | Parameter Type |
6111 +===================================+===================================+
6112 | time | timestamp_type |
6113 +-----------------------------------+-----------------------------------+
6114 | sale_ID | sale_ID_type |
6115 +-----------------------------------+-----------------------------------+
6116 | amount | price_type |
6117 +-----------------------------------+-----------------------------------+
6118 | item_ID | item_ID_type |
6119 +-----------------------------------+-----------------------------------+
6120 | quantity | quantity_type |
6121 +-----------------------------------+-----------------------------------+
6122 | assistant_ID | assistant_ID_type |
6123 +-----------------------------------+-----------------------------------+
6124 | branch_ID | branch_ID_type |
6125 +-----------------------------------+-----------------------------------+
6126 | notes | notes_type |
6127 +-----------------------------------+-----------------------------------+
6129 .. table:: Table 13. Output fields for ``MorningBoozeCheckAlt1`` task
6131 +-----------------------------------+-----------------------------------+
6132 | Parameter Name | Parameter Type |
6133 +===================================+===================================+
6134 | sale_ID | sale_ID_type |
6135 +-----------------------------------+-----------------------------------+
6136 | time | timestamp_type |
6137 +-----------------------------------+-----------------------------------+
6138 | authorised | authorised_type |
6139 +-----------------------------------+-----------------------------------+
6140 | message | message_type |
6141 +-----------------------------------+-----------------------------------+
6142 | amount | price_type |
6143 +-----------------------------------+-----------------------------------+
6144 | item_ID | item_ID_type |
6145 +-----------------------------------+-----------------------------------+
6146 | assistant_ID | assistant_ID_type |
6147 +-----------------------------------+-----------------------------------+
6148 | quantity | quantity_type |
6149 +-----------------------------------+-----------------------------------+
6150 | branch_ID | branch_ID_type |
6151 +-----------------------------------+-----------------------------------+
6152 | notes | notes_type |
6153 +-----------------------------------+-----------------------------------+
6155 .. container:: paragraph
6157 This task also requires some 'Task Logic' to implement
6158 the new behaviour for this task.
6160 .. container:: paragraph
6162 For simplicity use the following code for the task logic.
6163 It again assumes that all items with ``item_ID`` between
6164 1000 and 2000 contain alcohol. We again use the standard
6165 ``Java`` time utilities to check if the current time is
6166 between ``00:00:00 CET`` and ``13:00:00 CET`` or if it is
6169 .. container:: paragraph
6171 For this task we will again author the logic using the
6172 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__
6173 scripting language. Sample task logic code (specified in
6174 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__) is
6175 given below. For a detailed guide to how to write your
6177 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
6178 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
6179 of the other supported languages please refer to APEX
6182 .. container:: listingblock
6184 .. container:: title
6186 MVEL code for the ``MorningBoozeCheckAlt1`` task
6188 .. container:: content
6193 * ============LICENSE_START=======================================================
6194 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6195 * ================================================================================
6196 * Licensed under the Apache License, Version 2.0 (the "License");
6197 * you may not use this file except in compliance with the License.
6198 * You may obtain a copy of the License at
6200 * http://www.apache.org/licenses/LICENSE-2.0
6202 * Unless required by applicable law or agreed to in writing, software
6203 * distributed under the License is distributed on an "AS IS" BASIS,
6204 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6205 * See the License for the specific language governing permissions and
6206 * limitations under the License.
6208 * SPDX-License-Identifier: Apache-2.0
6209 * ============LICENSE_END=========================================================
6211 import java.util.Date;
6212 import java.util.Calendar;
6213 import java.util.TimeZone;
6214 import java.text.SimpleDateFormat;
6216 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6218 outFields.put("amount" , inFields.get("amount"));
6219 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6220 outFields.put("notes" , inFields.get("notes"));
6221 outFields.put("quantity" , inFields.get("quantity"));
6222 outFields.put("branch_ID" , inFields.get("branch_ID"));
6223 outFields.put("item_ID" , inFields.get("item_ID"));
6224 outFields.put("time" , inFields.get("time"));
6225 outFields.put("sale_ID" , inFields.get("sale_ID"));
6227 item_id = inFields.get("item_ID");
6229 //The events used later to test this task use CET timezone!
6230 cet = TimeZone.getTimeZone("CET");
6231 timenow = Calendar.getInstance(cet);
6232 df = new SimpleDateFormat("HH:mm:ss z");
6233 df.setTimeZone(cet);
6234 timenow.setTimeInMillis(inFields.get("time"));
6236 midnight = timenow.clone();
6238 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6239 timenow.get(Calendar.DATE),0,0,0);
6240 onepm = timenow.clone();
6242 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6243 timenow.get(Calendar.DATE),13,0,0);
6245 itemisalcohol = false;
6246 if(item_id != null && item_id >=1000 && item_id < 2000)
6247 itemisalcohol = true;
6249 if( itemisalcohol &&
6250 ( (timenow.after(midnight) && timenow.before(onepm))
6252 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
6254 outFields.put("authorised", false);
6255 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6256 " for time "+df.format(timenow.getTime())+
6257 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6258 " and "+df.format(onepm.getTime()) +" or on Sunday");
6262 outFields.put("authorised", true);
6263 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6264 " for time "+df.format(timenow.getTime()));
6269 This task checks if a sale request is for an item that is an alcoholic drink.
6270 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6271 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6272 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
6275 .. container:: imageblock
6277 .. container:: content
6279 |Create a new alternative task MorningBoozeCheckAlt1|
6281 .. container:: title
6283 Figure 19. Create a new Task
6285 .. container:: paragraph
6287 The task definition is now complete so click the 'Submit'
6288 button to save the task. Now that we have created our
6289 task, we can can add this task to the single pre-existing
6290 state (``BoozeAuthDecide``) in our policy.
6292 .. container:: paragraph
6294 To edit the ``BoozeAuthDecide`` state in our policy click
6295 on the 'Policies' tab. In the 'Policies' pane, right
6296 click on our ``MyFirstPolicy`` policy and select 'Edit'.
6297 Navigate to the ``BoozeAuthDecide`` state in the 'states'
6298 section at the bottom of the policy definition pane.
6300 .. container:: imageblock
6302 .. container:: content
6304 |Right click to edit a policy|
6306 .. container:: title
6308 Figure 20. Edit a Policy
6310 .. container:: paragraph
6312 To add our new task ``MorningBoozeCheckAlt1``, scroll
6313 down to the ``BoozeAuthDecide`` state in the 'States'
6314 section. In the 'State Tasks' section for
6315 ``BoozeAuthDecide`` use the 'Add new task' button. Select
6316 our new ``MorningBoozeCheckAlt1`` task, and use the name
6317 of the task as the 'Local Name' for the task. The
6318 ``MorningBoozeCheckAlt1`` task can reuse the same
6319 ``MorningBoozeCheck_Output_Direct`` 'Direct State Output
6320 Mapping' that we used for the ``MorningBoozeCheck`` task.
6321 (Recall that the role of the 'State Output Mapping' is to
6322 select the output event for the state, and select the
6323 next state to be executed. These both remain the same as
6326 .. container:: paragraph
6328 Since our state has more than one task we must define
6329 some logic to determine which task should be used each
6330 time the state is executed. This *task selection logic*
6331 is defined in the state definition. For our
6332 ``BoozeAuthDecide`` state we want the choice of which
6333 task to use to be based on the ``branch_ID`` from which
6334 the ``SALE_INPUT`` event originated. For simplicity sake
6335 let us assume that branches with ``branch_ID`` between
6336 ``0`` and ``999`` should use the ``MorningBoozeCheck``
6337 task, and the branches with with ``branch_ID`` between
6338 ``1000`` and ``1999`` should use the
6339 ``MorningBoozeCheckAlt1`` task.
6341 .. container:: paragraph
6343 This time, for variety, we will author the task selection
6345 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__
6346 scripting language. Sample task selection logic code
6348 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__)
6349 is given below. Paste the script text into the 'Task
6350 Selection Logic' box, and use "JAVASCRIPT" as the 'Task
6351 Selection Logic Type / Flavour'. It is necessary to mark
6352 one of the tasks as the 'Default Task' so that the task
6353 selection logic always has a fallback default option in
6354 cases where a particular task cannot be selected. In this
6355 case the ``MorningBoozeCheck`` task can be the default
6358 .. container:: listingblock
6360 .. container:: title
6362 JavaScript code for the ``BoozeAuthDecide`` task
6365 .. container:: content
6370 * ============LICENSE_START=======================================================
6371 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6372 * ================================================================================
6373 * Licensed under the Apache License, Version 2.0 (the "License");
6374 * you may not use this file except in compliance with the License.
6375 * You may obtain a copy of the License at
6377 * http://www.apache.org/licenses/LICENSE-2.0
6379 * Unless required by applicable law or agreed to in writing, software
6380 * distributed under the License is distributed on an "AS IS" BASIS,
6381 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6382 * See the License for the specific language governing permissions and
6383 * limitations under the License.
6385 * SPDX-License-Identifier: Apache-2.0
6386 * ============LICENSE_END=========================================================
6390 var returnValueType = Java.type("java.lang.Boolean");
6391 var returnValue = new returnValueType(true);
6393 executor.logger.info("Task Selection Execution: '"+executor.subject.id+
6394 "'. Input Event: '"+executor.inFields+"'");
6396 branchid = executor.inFields.get("branch_ID");
6397 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
6398 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
6399 taskdef = executor.subject.getDefaultTaskKey();
6401 if(branchid >=0 && branchid <1000){
6402 taskorig.copyTo(executor.selectedTask);
6404 else if (branchid >=1000 && branchid <2000){
6405 taskalt.copyTo(executor.selectedTask);
6408 taskdef.copyTo(executor.selectedTask);
6412 This task selection logic selects task "MorningBoozeCheck" for branches with
6413 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with
6414 1000<=branch_ID<2000. Otherwise the default task is selected.
6415 In this case the default task is also "MorningBoozeCheck"
6418 .. container:: imageblock
6420 .. container:: content
6422 |State definition with 2 Tasks and Task Selection
6425 .. container:: title
6427 Figure 21. State definition with 2 Tasks and Task
6430 .. container:: paragraph
6432 When complete don’t forget to click the 'Submit' button
6433 at the bottom of 'Policies' pane for our
6434 ``MyFirstPolicy`` policy after updating the
6435 ``BoozeAuthDecide`` state.
6437 .. container:: paragraph
6439 Congratulations, you have now completed the second step
6440 towards your first APEX policy. The policy model
6441 containing our new policy can again be validated and
6442 exported from the editor and saved as shown in Step 1.
6444 .. container:: paragraph
6446 The exported policy model is then available in the
6447 directory you selected, as
6448 `MyFirstPolicyModel_0.0.1.json <files/mfp-files/2/MyFirstPolicyModel_0.0.1.json>`__.
6449 The exported policy can now be loaded into the APEX
6450 Policy Engine, or can be re-loaded and edited by the APEX
6456 .. container:: paragraph
6458 To start a new APEX Engine you can use the following
6459 configuration. In a full APEX installation you can find
6460 this configuration in
6461 ``$APEX_HOME/examples/config/MyFirstPolicy/2/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
6462 Note, this has changed from the configuration file in
6463 Step 1 to enable the ``JAVASCRIPT`` executor for our new
6464 'Task Selection Logic'.
6466 .. container:: listingblock
6468 .. container:: title
6470 JSON to load and execute *My First Policy*, read input
6471 JSON events from ``stdin``, and emit output events to
6474 .. container:: content
6479 "engineServiceParameters" : {
6480 "name" : "MyFirstPolicyApexEngine",
6481 "version" : "0.0.1",
6483 "instanceCount" : 4,
6484 "deploymentPort" : 12345,
6485 "policyModelFileName" : "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json",
6486 "engineParameters" : {
6487 "executorParameters" : {
6489 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
6492 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
6497 "eventOutputParameters": {
6499 "carrierTechnologyParameters" : {
6500 "carrierTechnology" : "FILE",
6505 "eventProtocolParameters" : {
6506 "eventProtocol" : "JSON"
6510 "eventInputParameters": {
6512 "carrierTechnologyParameters" : {
6513 "carrierTechnology" : "FILE",
6518 "eventProtocolParameters" : {
6519 "eventProtocol" : "JSON"
6525 .. container:: paragraph
6527 To test the policy try paste the following events into
6528 the console as the APEX engine executes. Note, all tests
6529 from Step 1 will still work perfectly since none of those
6530 events originate from a branch with ``branch_ID`` between
6531 ``1000`` and ``2000``. The 'Task Selection Logic' will
6532 therefore pick the ``MorningBoozeCheck`` task as
6533 expected, and will therefore give the same results.
6535 .. table:: Table 14. Inputs and Outputs when testing *My First Policy*
6537 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6538 | Input Event (JSON) | Output Event (JSON) | comment |
6539 +==============================================+============================================================+===========================+
6540 | .. container:: | .. container:: | Request to buy |
6541 | | | alcohol item |
6542 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1249``) |
6544 | | | at *08:41:06 |
6545 | | .. container:: content | GMT* on *Monday, |
6546 | .. container:: content | | 02 January |
6547 | | .. code:: | 2017*. |
6549 | | { | Sale is not |
6550 | .. code:: | "nameSpace": "com.hyperm", | authorized. Uses |
6551 | | "name": "SALE_AUTH", | the |
6552 | | "version": "0.0.1", | ``MorningBoozeCheck`` |
6553 | { | "source": "", | |
6554 | "nameSpace": "com.hyperm", | "target": "", | task. |
6555 | "name": "SALE_INPUT", | "amount": 1249, | |
6556 | "version": "0.0.1", | "assistant_ID":12, | Note this test |
6557 | "time": 1483346466000, | "authorised": false, | is copied from |
6558 | "sale_ID": 99999992, | "branch_ID": 2, | Step 1 above, |
6559 | "amount": 1249, | "item_ID": 1012, | and demonstrates |
6560 | "item_ID": 1012, | "message": "Sale not authorised by policy ta | that the |
6561 | "quantity": 1, | sk MorningBoozeCheck for time 08:41:06 GMT.| original |
6562 | "assistant_ID": 12, | Alcohol can not be sold between 00:00:00 | ``MorningBoozeCheck`` |
6563 | "branch_ID": 2 | GMT and 11:30:00 GMT", | |
6564 | } | "notes": null, | task is |
6565 | | "quantity": 1, | executed. |
6566 | | "sale_ID": 99999992, | |
6567 | | "time": 1483346466000 | |
6569 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6570 | .. container:: | .. container:: | Request to buy |
6572 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1047``) |
6574 | | | at *10:14:33* on |
6575 | | .. container:: content | *Thursday, 22 |
6576 | .. container:: content | | December 2016*. |
6579 | | { | authorized. Uses |
6580 | .. code:: | "nameSpace" : "com.hyperm", | the |
6581 | | "name" : "SALE_AUTH", | ``MorningBoozeCheckAlt1`` |
6582 | | "version" : "0.0.1", | task. |
6583 | { | "source" : "", | |
6584 | | "target" : "", | |
6585 | "nameSpace": "com.hyperm", | "sale_ID" : 99999981, | |
6586 | "name": "SALE_INPUT", | "amount" : 299, | |
6587 | "version": "0.0.1", | "assistant_ID": 1212, | |
6588 | "time": 1482398073000, | "notes" : null, | |
6589 | "sale_ID": 99999981, | "quantity" : 1, | |
6590 | "amount": 299, | "branch_ID" : 1002, | |
6591 | "item_ID": 1047, | "item_ID" : 1047, | |
6592 | "quantity": 1, | "authorised" : false, | |
6593 | "assistant_ID": 1212, | "time" : 1482398073000, | |
6594 | "branch_ID": 1002 | "message" : "Sale not authorised by policy t | |
6595 | } | ask MorningBoozeCheckAlt1 fortime | |
6596 | | 10:14:33 CET. Alcohol can not be sold | |
6597 | | between 00:00:00 CET and 13:00:00 CET or on | |
6600 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6601 | .. container:: | .. container:: | Request to buy |
6603 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1443``) |
6605 | | | at *17:19:37* on |
6606 | | .. container:: content | *Sunday, 18 |
6607 | .. container:: content | | December 2016*. |
6610 | | { | authorized. Uses |
6611 | .. code:: | "nameSpace" : "com.hyperm", | the |
6612 | | | ``MorningBoozeCheckAlt1`` |
6613 | | "name" : "SALE_AUTH", | task. |
6615 | "nameSpace": "com.hyperm", | "version" : "0.0.1", | |
6616 | "name": "SALE_INPUT", | "source" : "", | |
6617 | "version": "0.0.1", | "target" : "", | |
6618 | "time": 1482077977000, | "sale_ID" : 99999982, | |
6619 | "sale_ID": 99999982, | "amount" : 2199, | |
6620 | "amount": 2199, | "assistant_ID" : 94, | |
6621 | "item_ID": 1443, | "notes" : "Buy 3, get 1 free!!", | |
6622 | "quantity": 12, | "quantity" : 12, | |
6623 | "assistant_ID": 94, | "branch_ID" : 1003, | |
6624 | "branch_ID": 1003, | "item_ID" : 1443, | |
6625 | "notes": "Buy 3, get 1 free!!" | "authorised" : false, | |
6626 | } | "time" : 1482077977000, | |
6627 | | "message" : "Sale not authorised by policy t | |
6628 | | ask MorningBoozeCheckAlt1 for | |
6629 | | time 17:19:37 CET. Alcohol c | |
6630 | | an not be sold between 00:00: | |
6631 | | 00 CET and 13:00:00 CET or on | |
6633 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6634 | .. container:: | .. container:: | Request to buy |
6635 | | | non-alcoholic |
6636 | .. container:: listingblock | .. container:: listingblock | item |
6637 | | | (``item_ID=5321``) |
6639 | | .. container:: content | at *11:13:09* on |
6640 | .. container:: content | | *Monday, 2 |
6641 | | .. code:: | January 2017*. |
6644 | .. code:: | "nameSpace" : "com.hyperm", | authorized. Uses |
6645 | | "name" : "SALE_AUTH", | the |
6646 | { | "version" : "0.0.1", | ``MorningBoozeCheckAlt1`` |
6647 | "nameSpace": "com.hyperm", | "source" : "", | task. |
6648 | "name": "SALE_INPUT", | "target" : "", | |
6649 | "version": "0.0.1", | "sale_ID" : 99999983, | |
6650 | "time": 1483351989000, | "amount" : 699, | |
6651 | "sale_ID": 99999983, | "assistant_ID" : 2323, | |
6652 | "amount": 699, | "notes" : "", | |
6653 | "item_ID": 5321, | "quantity" : 1, | |
6654 | "quantity": 1, | "branch_ID" : 1001, | |
6655 | "assistant_ID": 2323, | "item_ID" : 5321, | |
6656 | "branch_ID": 1001, | "authorised" : true, | |
6657 | "notes": "" | "time" : 1483351989000, | |
6658 | } | "message" : "Sale authorised by policy task | |
6659 | | MorningBoozeCheckAlt1 for time 11:13:09 CET"| |
6661 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6663 Policy 2 in CLI Editor
6664 ######################
6666 .. container:: paragraph
6668 An equivalent version of the ``MyFirstPolicyModel``
6669 policy model can again be generated using the APEX CLI
6670 editor. A sample APEX CLI script is shown below:
6672 .. container:: listingblock
6674 .. container:: title
6676 APEX CLI Editor code for Policy 2
6678 .. container:: content
6682 #-------------------------------------------------------------------------------
6683 # ============LICENSE_START=======================================================
6684 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
6685 # ================================================================================
6686 # Licensed under the Apache License, Version 2.0 (the "License");
6687 # you may not use this file except in compliance with the License.
6688 # You may obtain a copy of the License at
6690 # http://www.apache.org/licenses/LICENSE-2.0
6692 # Unless required by applicable law or agreed to in writing, software
6693 # distributed under the License is distributed on an "AS IS" BASIS,
6694 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6695 # See the License for the specific language governing permissions and
6696 # limitations under the License.
6698 # SPDX-License-Identifier: Apache-2.0
6699 # ============LICENSE_END=========================================================
6700 #-------------------------------------------------------------------------------
6702 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6704 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
6706 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
6708 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
6710 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
6712 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
6714 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
6716 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
6718 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
6720 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
6722 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
6724 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6725 This task checks if the sales request is for an item that contains alcohol.
6726 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6727 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6729 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6730 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6731 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6732 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6733 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6734 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6735 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6736 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6737 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6738 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6739 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6740 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6741 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6742 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6743 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6744 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6745 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6746 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6747 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6749 * ============LICENSE_START=======================================================
6750 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6751 * ================================================================================
6752 * Licensed under the Apache License, Version 2.0 (the "License");
6753 * you may not use this file except in compliance with the License.
6754 * You may obtain a copy of the License at
6756 * http://www.apache.org/licenses/LICENSE-2.0
6758 * Unless required by applicable law or agreed to in writing, software
6759 * distributed under the License is distributed on an "AS IS" BASIS,
6760 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6761 * See the License for the specific language governing permissions and
6762 * limitations under the License.
6764 * SPDX-License-Identifier: Apache-2.0
6765 * ============LICENSE_END=========================================================
6767 import java.util.Date;
6768 import java.util.Calendar;
6769 import java.util.TimeZone;
6770 import java.text.SimpleDateFormat;
6772 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6774 outFields.put("amount" , inFields.get("amount"));
6775 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6776 outFields.put("notes" , inFields.get("notes"));
6777 outFields.put("quantity" , inFields.get("quantity"));
6778 outFields.put("branch_ID" , inFields.get("branch_ID"));
6779 outFields.put("item_ID" , inFields.get("item_ID"));
6780 outFields.put("time" , inFields.get("time"));
6781 outFields.put("sale_ID" , inFields.get("sale_ID"));
6783 item_id = inFields.get("item_ID");
6785 //The events used later to test this task use GMT timezone!
6786 gmt = TimeZone.getTimeZone("GMT");
6787 timenow = Calendar.getInstance(gmt);
6788 df = new SimpleDateFormat("HH:mm:ss z");
6789 df.setTimeZone(gmt);
6790 timenow.setTimeInMillis(inFields.get("time"));
6792 midnight = timenow.clone();
6794 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6795 timenow.get(Calendar.DATE),0,0,0);
6796 eleven30 = timenow.clone();
6798 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6799 timenow.get(Calendar.DATE),11,30,0);
6801 itemisalcohol = false;
6802 if(item_id != null && item_id >=1000 && item_id < 2000)
6803 itemisalcohol = true;
6806 && timenow.after(midnight) && timenow.before(eleven30)){
6807 outFields.put("authorised", false);
6808 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6809 " for time "+df.format(timenow.getTime())+
6810 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6811 " and "+df.format(eleven30.getTime()));
6815 outFields.put("authorised", true);
6816 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6817 " for time "+df.format(timenow.getTime()));
6822 This task checks if a sale request is for an item that is an alcoholic drink.
6823 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6824 authorised. Otherwise the sale is authorised.
6825 In this implementation we assume that items with item_ID value between 1000 and
6826 2000 are all alcoholic drinks :-)
6830 task create name=MorningBoozeCheckAlt1 version=0.0.1 uuid=bc6d90c9-c902-4686-afd3-925b30e39990 description=LS
6831 This task checks if a sale request is for an item that is an alcoholic drink.
6832 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6833 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6834 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks
6836 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6837 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6838 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6839 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6840 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6841 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6842 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6843 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6844 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6845 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6846 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6847 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6848 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6849 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6850 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6851 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6852 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6853 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6854 task logic create name=MorningBoozeCheckAlt1 version=0.0.1 logicFlavour=MVEL logic=LS
6856 * ============LICENSE_START=======================================================
6857 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6858 * ================================================================================
6859 * Licensed under the Apache License, Version 2.0 (the "License");
6860 * you may not use this file except in compliance with the License.
6861 * You may obtain a copy of the License at
6863 * http://www.apache.org/licenses/LICENSE-2.0
6865 * Unless required by applicable law or agreed to in writing, software
6866 * distributed under the License is distributed on an "AS IS" BASIS,
6867 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6868 * See the License for the specific language governing permissions and
6869 * limitations under the License.
6871 * SPDX-License-Identifier: Apache-2.0
6872 * ============LICENSE_END=========================================================
6874 import java.util.Date;
6875 import java.util.Calendar;
6876 import java.util.TimeZone;
6877 import java.text.SimpleDateFormat;
6879 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6881 outFields.put("amount" , inFields.get("amount"));
6882 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6883 outFields.put("notes" , inFields.get("notes"));
6884 outFields.put("quantity" , inFields.get("quantity"));
6885 outFields.put("branch_ID" , inFields.get("branch_ID"));
6886 outFields.put("item_ID" , inFields.get("item_ID"));
6887 outFields.put("time" , inFields.get("time"));
6888 outFields.put("sale_ID" , inFields.get("sale_ID"));
6890 item_id = inFields.get("item_ID");
6892 //The events used later to test this task use CET timezone!
6893 cet = TimeZone.getTimeZone("CET");
6894 timenow = Calendar.getInstance(cet);
6895 df = new SimpleDateFormat("HH:mm:ss z");
6896 df.setTimeZone(cet);
6897 timenow.setTimeInMillis(inFields.get("time"));
6899 midnight = timenow.clone();
6901 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6902 timenow.get(Calendar.DATE),0,0,0);
6903 onepm = timenow.clone();
6905 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6906 timenow.get(Calendar.DATE),13,0,0);
6908 itemisalcohol = false;
6909 if(item_id != null && item_id >=1000 && item_id < 2000)
6910 itemisalcohol = true;
6912 if( itemisalcohol &&
6913 ( (timenow.after(midnight) && timenow.before(onepm))
6915 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
6917 outFields.put("authorised", false);
6918 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6919 " for time "+df.format(timenow.getTime())+
6920 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6921 " and "+df.format(onepm.getTime()) +" or on Sunday");
6925 outFields.put("authorised", true);
6926 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6927 " for time "+df.format(timenow.getTime()));
6932 This task checks if a sale request is for an item that is an alcoholic drink.
6933 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6934 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6935 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
6939 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"
6940 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6941 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6942 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
6943 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6944 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6945 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6946 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6947 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6948 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6949 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6951 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"
6952 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6953 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6954 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6955 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6956 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6957 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6958 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6959 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6962 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
6963 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
6964 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
6965 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
6966 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
6967 policy state selecttasklogic create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide logicFlavour=JAVASCRIPT logic=LS
6969 * ============LICENSE_START=======================================================
6970 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6971 * ================================================================================
6972 * Licensed under the Apache License, Version 2.0 (the "License");
6973 * you may not use this file except in compliance with the License.
6974 * You may obtain a copy of the License at
6976 * http://www.apache.org/licenses/LICENSE-2.0
6978 * Unless required by applicable law or agreed to in writing, software
6979 * distributed under the License is distributed on an "AS IS" BASIS,
6980 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6981 * See the License for the specific language governing permissions and
6982 * limitations under the License.
6984 * SPDX-License-Identifier: Apache-2.0
6985 * ============LICENSE_END=========================================================
6988 var returnValueType = Java.type("java.lang.Boolean");
6989 var returnValue = new returnValueType(true);
6991 executor.logger.info("Task Selection Execution: '"+executor.subject.id+"'. Input Event: '"+executor.inFields+"'");
6993 branchid = executor.inFields.get("branch_ID");
6994 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
6995 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
6996 taskdef = executor.subject.getDefaultTaskKey();
6998 if(branchid >=0 && branchid <1000){
6999 taskorig.copyTo(executor.selectedTask);
7001 else if (branchid >=1000 && branchid <2000){
7002 taskalt.copyTo(executor.selectedTask);
7005 taskdef.copyTo(executor.selectedTask);
7009 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"
7016 Introduction to APEX Logging
7017 ----------------------------
7019 .. container:: paragraph
7021 All APEX components make extensive use of logging using the
7022 logging façade `SLF4J <https://www.slf4j.org/>`__ with the
7023 backend `Logback <https://logback.qos.ch/>`__. Both are used
7024 off-the-shelve, so the standard documentation and
7025 configuration apply to APEX logging. For details on how to
7026 work with logback please see the `logback
7027 manual <https://logback.qos.ch/manual/index.html>`__.
7029 .. container:: paragraph
7031 The APEX applications is the logback configuration file
7032 ``$APEX_HOME/etc/logback.xml`` (Windows:
7033 ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
7034 to no debug, i.e. logs from the logging framework should be
7037 .. container:: paragraph
7039 The configurable log levels work as expected:
7041 .. container:: ulist
7043 - *error* (or *ERROR*) is used for serious errors in the
7046 - *warn* (or *WARN*) is used for warnings, which in general
7047 can be ignored but might indicate some deeper problems
7049 - *info* (or *INFO*) is used to provide generally
7050 interesting messages for startup and policy execution
7052 - *debug* (or *DEBUG*) provides more details on startup and
7055 - *trace* (or *TRACE*) gives full details on every aspect
7056 of the APEX engine from start to end
7058 .. container:: paragraph
7060 The loggers can also be configured as expected. The standard
7061 configuration (after installing APEX) uses log level *info*
7062 on all APEX classes (components).
7064 .. container:: paragraph
7066 The applications and scripts in ``$APEX_HOME/bin`` (Windows:
7067 ``%APEX_HOME\bin``) are configured to use the logback
7068 configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
7069 ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
7070 use different logback configurations, for instance:
7072 .. container:: ulist
7074 - Maintain multiple configurations in ``etc``, for instance
7075 a ``logback-debug.xml`` for deep debugging and a
7076 ``logback-production.xml`` for APEX in production mode,
7077 then copy the required configuration file to the used
7078 ``logback.xml`` prior starting APEX
7080 - Edit the scripts in ``bin`` to use a different logback
7081 configuration file (only recommended if you are familiar
7082 with editing bash scripts or windows batch files)
7084 Standard Logging Configuration
7085 ------------------------------
7087 .. container:: paragraph
7089 The standard logging configuration defines a context *APEX*,
7090 which is used in the standard output pattern. The location
7091 for log files is defined in the property ``VAR_LOG`` and set
7092 to ``/var/log/onap/policy/apex-pdp``. The standard status
7093 listener is set to *NOP* and the overall logback
7094 configuration is set to no debug.
7096 .. container:: listingblock
7098 .. container:: content
7103 <configuration debug="false">
7104 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7106 <contextName>Apex</contextName>
7107 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7113 .. container:: paragraph
7115 The first appender defined is called ``STDOUT`` for logs to standard
7118 .. container:: listingblock
7120 .. container:: content
7125 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7127 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7131 .. container:: paragraph
7133 The root level logger then is set to the level *info* using the
7134 standard out appender.
7136 .. container:: listingblock
7138 .. container:: content
7144 <appender-ref ref="STDOUT" />
7147 .. container:: paragraph
7149 The second appender is called ``FILE``. It writes logs to a file
7152 .. container:: listingblock
7154 .. container:: content
7159 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7160 <file>${VAR_LOG}/apex.log</file>
7162 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7166 .. container:: paragraph
7168 The third appender is called ``CTXT_FILE``. It writes logs to a file
7171 .. container:: listingblock
7173 .. container:: content
7178 <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
7179 <file>${VAR_LOG}/apex_ctxt.log</file>
7181 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7185 .. container:: paragraph
7187 The last definitions are for specific loggers. The first logger
7188 captures all standard APEX classes. It is configured for log level
7189 *info* and uses the standard output and file appenders. The second
7190 logger captures APEX context classes responsible for context
7191 monitoring. It is configured for log level *trace* and uses the
7192 context file appender.
7194 .. container:: listingblock
7196 .. container:: content
7202 <logger name="org.onap.policy.apex" level="info" additivity="false">
7203 <appender-ref ref="STDOUT" />
7204 <appender-ref ref="FILE" />
7207 <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
7208 <appender-ref ref="CTXT_FILE" />
7211 Adding Logback Status and Debug
7212 -------------------------------
7214 .. container:: paragraph
7216 To activate logback status messages change the status listener
7217 from 'NOP' to for instance console.
7219 .. container:: listingblock
7221 .. container:: content
7225 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
7227 .. container:: paragraph
7229 To activate all logback debugging, for instance to debug a new
7230 logback configuration, activate the debug attribute in the
7233 .. container:: listingblock
7235 .. container:: content
7239 <configuration debug="true">
7243 Logging External Components
7244 ---------------------------
7246 .. container:: paragraph
7248 Logback can also be configured to log any other, external
7249 components APEX is using, if they are using the common logging
7252 .. container:: paragraph
7254 For instance, the context component of APEX is using *Infinispan*
7255 and one can add a logger for this external component. The
7256 following example adds a logger for *Infinispan* using the
7257 standard output appender.
7259 .. container:: listingblock
7261 .. container:: content
7265 <logger name="org.infinispan" level="INFO" additivity="false">
7266 <appender-ref ref="STDOUT" />
7269 .. container:: paragraph
7271 Another example is Apache Zookeeper. The following example adds a
7272 logger for Zookeeper using the standard outout appender.
7274 .. container:: listingblock
7276 .. container:: content
7280 <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
7281 <appender-ref ref="STDOUT" />
7284 Configuring loggers for Policy Logic
7285 ------------------------------------
7287 .. container:: paragraph
7289 The logging for the logic inside a policy (task logic, task
7290 selection logic, state finalizer logic) can be configured separate
7291 from standard logging. The logger for policy logic is
7292 ``org.onap.policy.apex.executionlogging``. The following example
7295 .. container:: ulist
7297 - a new appender for standard out using a very simple pattern
7298 (simply the actual message)
7300 - a logger for policy logic to standard out using the new
7301 appender and the already described file appender.
7303 .. container:: listingblock
7305 .. container:: content
7309 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7311 <pattern>policy: %msg\n</pattern>
7315 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7316 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7317 <appender-ref ref="FILE" />
7320 .. container:: paragraph
7322 It is also possible to use specific logging for parts of policy
7323 logic. The following example defines a logger for task logic.
7325 .. container:: listingblock
7327 .. container:: content
7331 <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
7332 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7335 Rolling File Appenders
7336 ----------------------
7338 .. container:: paragraph
7340 Rolling file appenders are a good option for more complex logging
7341 of a production or complex testing APEX installation. The standard
7342 logback configuration can be used for these use cases. This
7343 section gives two examples for the standard logging and for
7346 .. container:: paragraph
7348 First the standard logging. The following example defines a
7349 rolling file appender. The appender rolls over on a daily basis.
7350 It allows for a file size of 100 MB.
7352 .. container:: listingblock
7354 .. container:: content
7358 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
7359 <file>${VAR_LOG}/apex.log</file>
7360 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7361 <!-- rollover daily -->
7362 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
7363 <fileNamePattern>${VAR_LOG}/apex_%d{yyyy-MM-dd}.%i.log.gz
7365 <maxHistory>4</maxHistory>
7366 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7367 <!-- or whenever the file size reaches 100MB -->
7368 <maxFileSize>100MB</maxFileSize>
7369 </timeBasedFileNamingAndTriggeringPolicy>
7373 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7378 .. container:: paragraph
7380 A very similar configuration can be used for a rolling file
7381 appender logging APEX context.
7383 .. container:: listingblock
7385 .. container:: content
7389 <appender name="CTXT-FILE"
7390 class="ch.qos.logback.core.rolling.RollingFileAppender">
7391 <file>${VAR_LOG}/apex_ctxt.log</file>
7392 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7393 <fileNamePattern>${VAR_LOG}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
7395 <maxHistory>4</maxHistory>
7396 <timeBasedFileNamingAndTriggeringPolicy
7397 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7398 <maxFileSize>100MB</maxFileSize>
7399 </timeBasedFileNamingAndTriggeringPolicy>
7403 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7408 Example Configuration for Logging Logic
7409 ---------------------------------------
7411 .. container:: paragraph
7413 The following example shows a configuration that logs policy logic
7414 to standard out and a file (*info*). All other APEX components are
7415 logging to a file (*debug*).. This configuration an be used in a
7416 pre-production phase with the APEX engine still running in a
7417 separate terminal to monitor policy execution. This logback
7418 configuration is in the APEX installation as
7419 ``etc/logback-logic.xml``.
7421 .. container:: listingblock
7423 .. container:: content
7427 <configuration debug="false">
7428 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7430 <contextName>Apex</contextName>
7431 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7433 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7435 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7439 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7440 <file>${VAR_LOG}/apex.log</file>
7443 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7448 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7450 <pattern>policy: %msg\n</pattern>
7454 <root level="error">
7455 <appender-ref ref="STDOUT" />
7458 <logger name="org.onap.policy.apex" level="debug" additivity="false">
7459 <appender-ref ref="FILE" />
7462 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7463 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7464 <appender-ref ref="FILE" />
7468 Example Configuration for a Production Server
7469 ---------------------------------------------
7471 .. container:: paragraph
7473 The following example shows a configuration that logs all APEX
7474 components, including policy logic, to a file (*debug*). This
7475 configuration an be used in a production phase with the APEX
7476 engine being executed as a service on a system without console
7477 output. This logback configuration is in the APEX installation as
7478 ``logback-server.xml``
7480 .. container:: listingblock
7482 .. container:: content
7486 <configuration debug="false">
7487 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7489 <contextName>Apex</contextName>
7490 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7492 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7493 <file>${VAR_LOG}/apex.log</file>
7496 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7501 <root level="debug">
7502 <appender-ref ref="FILE" />
7505 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
7506 <appender-ref ref="FILE" />
7510 Building a System with Websocket Backend
7511 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7516 .. container:: paragraph
7518 Websocket is a protocol to run sockets of HTTP. Since it in
7519 essence a socket, the connection is realized between a
7520 server (waiting for connections) and a client (connecting to
7521 a server). Server/client separation is only important for
7522 connection establishment, once connected, everyone can
7523 send/receive on the same socket (as any standard socket
7526 .. container:: paragraph
7528 Standard Websocket implementations are simple, no
7529 publish/subscribe and no special event handling. Most
7530 servers simply send all incoming messages to all
7531 connections. There is a PubSub definition on top of
7532 Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
7533 does not support WAMP at the moment.
7538 .. container:: paragraph
7541 356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7542 defines the standard Websocket API. This JSR is part of Jave
7543 EE 7 standard. For Java SE, several implementations exist in
7544 open source. Since Websockets are a stable standard and
7545 simple, most implementations are stable and ready to use. A
7546 lot of products support Websockets, like Spring, JBoss,
7547 Netty, … there are also Kafka extensions for Websockets.
7549 Websocket Example Code for Websocket clients (FOSS)
7550 ---------------------------------------------------
7552 .. container:: paragraph
7554 There are a lot of implementations and examples available on
7555 Github for Websocket clients. If one is using Java EE 7,
7556 then one can also use the native Websocket implementation.
7557 Good examples for clients using simply Java SE are here:
7559 .. container:: ulist
7562 implementation <https://github.com/TooTallNate/Java-WebSocket>`__
7564 - `Websocket sending client example, using
7565 AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
7567 - `Websocket receiving client example (simple echo
7568 client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
7570 .. container:: paragraph
7572 For Java EE, the native Websocket API is explained here:
7574 .. container:: ulist
7577 docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7580 example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
7582 BCP: Websocket Configuration
7583 ----------------------------
7585 .. container:: paragraph
7587 The probably best is to configure APEX for Websocket servers
7588 for input (ingress, consume) and output (egress, produce)
7589 interfaces. This means that APEX will start Websocket
7590 servers on named ports and wait for clients to connect.
7591 Advantage: once APEX is running all connectivity
7592 infrastructure is running as well. Consequence: if APEX is
7593 not running, everyone else is in the dark, too.
7595 .. container:: paragraph
7597 The best protocol to be used is JSON string. Each event on
7598 any interface is then a string with a JSON encoding. JSON
7599 string is a little bit slower than byte code, but we doubt
7600 that this will be noticeable. A further advantage of JSON
7601 strings over Websockets with APEX starting the servers: it
7602 is very easy to connect web browsers to such a system.
7603 Simple connect the web browser to the APEX sockets and
7604 send/read JSON strings.
7606 .. container:: paragraph
7608 Once APEX is started you simply connect Websocket clients to
7609 it, and send/receive event. When APEX is terminated, the
7610 Websocket servers go down, and the clients will be
7611 disconnected. APEX does not (yet) support auto-client
7612 reconnect nor WAMP, so clients might need to be restarted or
7613 reconnected manually after an APEX boot.
7615 Demo with VPN Policy Model
7616 --------------------------
7618 .. container:: paragraph
7620 We assume that you have an APEX installation using the full
7621 package, i.e. APEX with all examples, of version ``0.5.6``
7622 or higher. We will use the VPN policy from the APEX examples
7625 .. container:: paragraph
7627 Now, have the following ready to start the demo:
7629 .. container:: ulist
7631 - 3 terminals on the host where APEX is running (we need 1
7632 for APEX and 1 for each client)
7634 - the events in the file
7635 ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
7636 in an editor (we need to send those events to APEX)
7638 - the events in the file
7639 ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
7640 in an editor (we need to send those events to APEX)
7642 A Websocket Configuration for the VPN Domain
7643 ############################################
7645 .. container:: paragraph
7647 Create a new APEX configuration using the VPN policy
7648 model and configuring APEX as discussed above for
7649 Websockets. Copy the following configuration into
7650 ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
7652 ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
7654 .. container:: listingblock
7656 .. container:: content
7662 "engineServiceParameters" : {
7663 "name" : "VPNApexEngine",
7664 "version" : "0.0.1",
7666 "instanceCount" : 1,
7667 "deploymentPort" : 12345,
7668 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
7669 "engineParameters" : {
7670 "executorParameters" : {
7672 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
7675 "contextParameters" : {
7676 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
7677 "schemaParameters":{
7679 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
7685 "producerCarrierTechnologyParameters" : {
7686 "carrierTechnology" : "WEBSOCKET",
7687 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7693 "producerEventProtocolParameters" : {
7694 "eventProtocol" : "JSON"
7696 "consumerCarrierTechnologyParameters" : {
7697 "carrierTechnology" : "WEBSOCKET",
7698 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7704 "consumerEventProtocolParameters" : {
7705 "eventProtocol" : "JSON"
7712 .. container:: paragraph
7714 In a new terminal, start APEX with the new configuration for
7715 Websocket-Server ingress/egress:
7717 .. container:: listingblock
7719 .. container:: content
7724 #: $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
7726 .. container:: listingblock
7728 .. container:: content
7733 #: %APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
7735 .. container:: paragraph
7737 Wait for APEX to start, it takes a while to create all Websocket
7738 servers (about 8 seconds on a standard laptop without cached
7739 binaries). depending on your log messages, you will see no (some, a
7740 lot) log messages. If APEX starts correctly, the last few messages
7743 .. container:: listingblock
7745 .. container:: content
7750 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)
7751 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 ...
7752 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
7753 Started Apex service
7755 .. container:: paragraph
7757 APEX is running in the new terminal and will produce output when the
7758 policy is triggered/executed.
7760 Run the Websocket Echo Client
7761 #############################
7763 .. container:: paragraph
7765 The echo client is included in an APEX full installation. To run
7766 the client, open a new shell (Unix, Cygwin) or command prompt
7767 (``cmd`` on Windows). Then use the APEX application launcher to
7771 APEX engine needs to run first
7772 The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
7774 +---------------------------------------------------------+-----------------------------------------------------------+
7775 | Unix, Cygwin | Windows |
7776 +=========================================================+===========================================================+
7777 | .. container:: | .. container:: |
7779 | .. container:: listingblock | .. container:: listingblock |
7781 | .. container:: content | .. container:: content |
7783 | .. code:: | .. code:: |
7785 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
7786 +---------------------------------------------------------+-----------------------------------------------------------+
7788 .. container:: paragraph
7790 Use the following command line arguments for server and port of
7791 the Websocket server. The port should be the same as configured in
7792 the APEX engine. The server host should be the host on which the
7793 APEX engine is running
7795 .. container:: ulist
7797 - ``-p`` defines the Websocket port to connect to (defaults to
7800 - ``-s`` defines the host on which a Websocket server is running
7801 (defaults to ``localhost``)
7803 .. container:: paragraph
7805 Let’s assume that there is an APEX engine running, configured for
7806 produce Websocket carrier technology, as server, for port 42452,
7807 with produce event protocol JSON,. If we start the console client
7808 on the same host, we can omit the ``-s`` options. We start the
7811 .. container:: listingblock
7813 .. container:: content
7817 # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
7818 > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
7820 .. container:: colist arabic
7822 +-------+--------------------------------+
7823 | **1** | Start client on Unix or Cygwin |
7824 +-------+--------------------------------+
7825 | **2** | Start client on Windows |
7826 +-------+--------------------------------+
7828 .. container:: paragraph
7830 Once started successfully, the client will produce the following
7831 messages (assuming we used ``-p 42452`` and an APEX engine is
7832 running on ``localhost`` with the same port:
7834 .. container:: listingblock
7836 .. container:: content
7840 ws-simple-echo: starting simple event echo
7841 --> server: localhost
7844 Once started, the application will simply print out all received events to standard out.
7845 Each received event will be prefixed by '---' and suffixed by '===='
7848 ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
7850 Run the Websocket Console Client
7851 ################################
7853 .. container:: paragraph
7855 The console client is included in an APEX full installation. To
7856 run the client, open a new shell (Unix, Cygwin) or command prompt
7857 (``cmd`` on Windows). Then use the APEX application launcher to
7861 APEX engine needs to run first
7862 The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
7863 protocol is executed first.
7865 +------------------------------------------------------------+--------------------------------------------------------------+
7866 | Unix, Cygwin | Windows |
7867 +============================================================+==============================================================+
7868 | .. container:: | .. container:: |
7870 | .. container:: listingblock | .. container:: listingblock |
7872 | .. container:: content | .. container:: content |
7874 | .. code:: | .. code:: |
7876 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
7877 +------------------------------------------------------------+--------------------------------------------------------------+
7879 .. container:: paragraph
7881 Use the following command line arguments for server and port of
7882 the Websocket server. The port should be the same as configured in
7883 the APEX engine. The server host should be the host on which the
7884 APEX engine is running
7886 .. container:: ulist
7888 - ``-p`` defines the Websocket port to connect to (defaults to
7891 - ``-s`` defines the host on which a Websocket server is running
7892 (defaults to ``localhost``)
7894 .. container:: paragraph
7896 Let’s assume that there is an APEX engine running, configured for
7897 consume Websocket carrier technology, as server, for port 42450,
7898 with consume event protocol JSON,. If we start the console client
7899 on the same host, we can omit the ``-s`` options. We start the
7902 .. container:: listingblock
7904 .. container:: content
7908 # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
7909 > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
7911 .. container:: colist arabic
7913 +-------+--------------------------------+
7914 | **1** | Start client on Unix or Cygwin |
7915 +-------+--------------------------------+
7916 | **2** | Start client on Windows |
7917 +-------+--------------------------------+
7919 .. container:: paragraph
7921 Once started successfully, the client will produce the following
7922 messages (assuming we used ``-p 42450`` and an APEX engine is
7923 running on ``localhost`` with the same port:
7925 .. container:: listingblock
7927 .. container:: content
7931 ws-simple-console: starting simple event console
7932 --> server: localhost
7935 - terminate the application typing 'exit<enter>' or using 'CTRL+C'
7936 - events are created by a non-blank starting line and terminated by a blank line
7939 ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
7944 .. container:: paragraph
7946 Now you have the full system up and running:
7948 .. container:: ulist
7950 - Terminal 1: APEX ready and loaded
7952 - Terminal 2: an echo client, printing received messages produced
7955 - Terminal 2: a console client, waiting for input on the console
7956 (standard in) and sending text to APEX
7958 .. container:: paragraph
7960 We started the engine with the VPN policy example. So all the
7961 events we are using now are located in files in the following
7964 .. container:: listingblock
7966 .. container:: content
7971 #: $APEX_HOME/examples/events/VPN
7972 > %APEX_HOME%\examples\events\VPN
7974 .. container:: paragraph
7976 To sends events, simply copy the content of the event files into
7977 Terminal 3 (the console client). It will read multi-line JSON text
7978 and send the events. So copy the content of ``SetupEvents.json`` into
7979 the client. APEX will trigger a policy and produce some output, the
7980 echo client will also print some events created in the policy. In
7981 Terminal 1 (APEX) you’ll see some status messages from the policy as:
7983 .. container:: listingblock
7985 .. container:: content
7990 {Link=L09, LinkUp=true}
7992 outFields: {Link=L09, LinkUp=true}
7993 {Link=L10, LinkUp=true}
7996 outFields: {Link=L10, LinkUp=true}
7997 {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
7999 C 300 300 [L09, L10]
8000 outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8001 {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8004 C 300 300 [L09, L10]
8005 outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8006 {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8009 C 300 300 [L09, L10]
8010 D 300 400 [L09, L10]
8011 outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8012 {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8015 B 300 299 [L09, L10]
8016 C 300 300 [L09, L10]
8017 D 300 400 [L09, L10]
8018 outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8020 .. container:: paragraph
8022 In Terminal 2 (echo-client) you see the received events, the last two
8025 .. container:: listingblock
8027 .. container:: content
8032 ws-simple-echo: received
8033 ---------------------------------
8035 "name": "VPNCustomerCtxtActEvent",
8037 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8040 "CustomerName": "C",
8041 "LinkList": "L09 L10",
8045 =================================
8047 ws-simple-echo: received
8048 ---------------------------------
8050 "name": "VPNCustomerCtxtActEvent",
8052 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8055 "CustomerName": "D",
8056 "LinkList": "L09 L10",
8060 =================================
8062 .. container:: paragraph
8064 Congratulations, you have triggered a policy in APEX using
8065 Websockets, the policy did run through, created events, picked up by
8068 .. container:: paragraph
8070 Now you can send the Link 09 and Link 10 events, they will trigger
8071 the actual VPN policy and some calculations are made. Let’s take the
8072 Link 09 events from ``Link09Events.json``, copy them all into
8073 Terminal 3 (the console). APEX will run the policy (with some status
8074 output), and the echo client will receive and print events.
8076 .. container:: paragraph
8078 To terminate the applications, simply press ``CTRL+C`` in Terminal 1
8079 (APEX). This will also terminate the echo-client in Terminal 2. Then
8080 type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
8090 Last updated 2018-09-10 15:38:16 IST
8092 .. |Extract the TAR archive| image:: images/install-guide/win-extract-tar-gz.png
8093 .. |Extract the APEX distribution| image:: images/install-guide/win-extract-tar.png
8094 .. |REST Editor Start Screen| image:: images/install-guide/rest-start.png
8095 .. |REST Editor with loaded SampleDomain Policy Model| image:: images/install-guide/rest-loaded.png
8096 .. |APEX Configuration Matrix| image:: images/apex-intro/ApexEngineConfig.png
8097 .. |File > New to create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel1.png
8098 .. |Create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel2.png
8099 .. |Right click to create a new event| image:: images/mfp/MyFirstPolicy_P1_newEvent1.png
8100 .. |Fill in the necessary information for the 'SALE_INPUT' event and click 'Submit'| image:: images/mfp/MyFirstPolicy_P1_newEvent2.png
8101 .. |Right click to create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema1.png
8102 .. |Create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema2.png
8103 .. |Add new event parameters to an event| image:: images/mfp/MyFirstPolicy_P1_newEvent3.png
8104 .. |Right click to create a new task| image:: images/mfp/MyFirstPolicy_P1_newTask1.png
8105 .. |Add input and out fields for the task| image:: images/mfp/MyFirstPolicy_P1_newTask2.png
8106 .. |Add task logic the task| image:: images/mfp/MyFirstPolicy_P1_newTask3.png
8107 .. |Create a new policy| image:: images/mfp/MyFirstPolicy_P1_newPolicy1.png
8108 .. |Create a state| image:: images/mfp/MyFirstPolicy_P1_newState1.png
8109 .. |Add a Task and Output Mapping| image:: images/mfp/MyFirstPolicy_P1_newState2.png
8110 .. |Validate the policy model for error using the 'Model' > 'Validate' menu item| image:: images/mfp/MyFirstPolicy_P1_validatePolicyModel.png
8111 .. |Download the completed policy model using the 'File' > 'Download' menu item| image:: images/mfp/MyFirstPolicy_P1_exportPolicyModel1.png
8112 .. |Create a new alternative task MorningBoozeCheckAlt1| image:: images/mfp/MyFirstPolicy_P2_newTask1.png
8113 .. |Right click to edit a policy| image:: images/mfp/MyFirstPolicy_P2_editPolicy1.png
8114 .. |State definition with 2 Tasks and Task Selection Logic| image:: images/mfp/MyFirstPolicy_P2_editState1.png