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 CLI Tosca Editor
3924 -------------------------
3926 .. container:: paragraph
3928 As per the new Policy LifeCycle API, the policies are expected to be defined as ToscaServiceTemplate. The CLI Tosca Editor is an extended version of the APEX CLI Editor which can generate the policies in ToscaServiceTemplate way.
3930 .. container:: paragraph
3932 The APEX config file(.json), command file(.apex) and the tosca template skeleton(.json) file paths need to be passed as input arguments to the CLI Tosca Editor. Policy in ToscaServiceTemplate format is generated as the output. This can be used as the input to Policy API for creating policies.
3934 .. container:: paragraph
3936 On UNIX and Cygwin systems use:
3938 .. container:: ulist
3940 - ``apexCLIToscaEditor.sh`` - starts the CLI Tosca editor,
3941 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3943 - ``apexApps.sh cli-tosca-editor`` - starts the CLI Tosca editor,
3944 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3946 .. container:: paragraph
3948 On Windows systems use:
3950 .. container:: ulist
3952 - ``apexCLIToscaEditor.bat`` - starts the CLI Tosca editor,
3953 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3955 - ``apexApps.bat cli-tosca-editor`` - starts the CLI Tosca
3956 editor, all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
3958 .. container:: paragraph
3960 Summary of alternatives to start the APEX CLI Tosca 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/apexCLIToscaEditor.sh.sh [args] | > %APEX_HOME%\bin\apexCLIToscaEditor.bat [args] |
3974 | # $APEX_HOME/bin/apexApps.sh cli-tosca-editor [args]| > %APEX_HOME%\bin\apexApps.bat cli-tosca-editor [args] |
3975 +-----------------------------------------------------------------+--------------------------------------------------------------------+
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.auth.clieditor.tosca.ApexCliToscaEditorMain [options...]
3990 -a,--model-props-file <MODEL_PROPS_FILE> name of the apex model properties file to use
3991 -ac,--apex-config-file <APEX_CONFIG_FILE> name of the file containing apex configuration details
3992 -c,--command-file <COMMAND_FILE> name of a file containing editor commands to run into the editor
3993 -h,--help outputs the usage of this command
3994 -i,--input-model-file <INPUT_MODEL_FILE> name of a file that contains an input model for the editor
3995 -if,--ignore-failures <IGNORE_FAILURES_FLAG> true or false, ignore failures of commands in command files and
3996 continue executing the command file
3997 -l,--log-file <LOG_FILE> name of a file that will contain command logs from the editor, will
3998 log to standard output if not specified or suppressed with "-nl" flag
3999 -m,--metadata-file <CMD_METADATA_FILE> name of the command metadata file to use
4000 -nl,--no-log if specified, no logging or output of commands to standard output or
4001 log file is carried out
4002 -ot,--output-tosca-file <OUTPUT_TOSCA_FILE> name of a file that will contain the output ToscaServiceTemplate
4003 -t,--tosca-template-file <TOSCA_TEMPLATE_FILE> name of the input file containing tosca template which needs to be
4005 -wd,--working-directory <WORKING_DIRECTORY> the working directory that is the root for the CLI editor and is the
4006 root from which to look for included macro files
4008 .. container:: paragraph
4010 An example command to run the APEX CLI Tosca editor on windows machine is given below.
4012 .. container:: listingblock
4014 .. container:: content
4018 %APEX_HOME%/\bin/\apexCLIToscaEditor.bat -c %APEX_HOME%\examples\PolicyModel.apex -ot %APEX_HOME%\examples\test.json -l %APEX_HOME%\examples\test.log -ac %APEX_HOME%\examples\RESTServerStandaloneJsonEvent.json -t %APEX_HOME%\examples\ToscaTemplate.json
4020 The APEX REST Editor
4021 --------------------
4023 .. container:: paragraph
4025 The standard way to use the APEX REST Editor is via an
4026 installation of the *war* file on a webserver. However, the
4027 REST editor can also be started via command line. This will
4028 start a Grizzly webserver with the *war* deployed. Access to
4029 the REST Editor is then via the provided URL
4031 .. container:: paragraph
4033 On UNIX and Cygwin systems use:
4035 .. container:: ulist
4037 - ``apexRESTEditor.sh`` - simply starts the webserver with
4040 - ``apexApps.sh rest-editor`` - simply starts the webserver
4041 with the REST editor
4043 .. container:: paragraph
4045 On Windows systems use:
4047 .. container:: ulist
4049 - ``apexRESTEditor.bat`` - simply starts the webserver with
4052 - ``apexApps.bat rest-editor`` - simply starts the
4053 webserver with the REST editor
4055 .. container:: paragraph
4057 Summary of alternatives to start the APEX REST Editor:
4059 +-------------------------------------------------------------+---------------------------------------------------------------+
4060 | Unix, Cygwin | Windows |
4061 +=============================================================+===============================================================+
4062 | .. container:: | .. container:: |
4064 | .. container:: listingblock | .. container:: listingblock |
4066 | .. container:: content | .. container:: content |
4068 | .. code:: | .. code:: |
4070 | # $APEX_HOME/bin/apexRESTEditor.sh.sh [args] | > %APEX_HOME%\bin\apexRESTEditor.bat [args] |
4071 | # $APEX_HOME/bin/apexApps.sh rest-editor [args] | > %APEX_HOME%\bin\apexApps.bat rest-editor [args] |
4072 +-------------------------------------------------------------+---------------------------------------------------------------+
4074 .. container:: paragraph
4076 The option ``-h`` provides a help screen with all command
4079 .. container:: listingblock
4081 .. container:: content
4085 usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]
4086 -h,--help outputs the usage of this command
4087 -l,--listen <ADDRESS> the IP address to listen on. Default value is localhost to restrict access to the
4089 -p,--port <PORT> port to use for the Apex RESTful editor REST calls.
4090 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating. Default
4091 value is -1 to run indefinitely.
4093 .. container:: paragraph
4095 If the REST Editor is started without any arguments the
4096 final messages will look similar to this:
4098 .. container:: listingblock
4100 .. container:: content
4104 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4105 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.NetworkListener start
4106 INFO: Started listener bound to [localhost:18989]
4107 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.HttpServer start
4108 INFO: [HttpServer] Started.
4109 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4111 .. container:: paragraph
4113 The last line states the URL on which the REST Editor can be
4114 accessed. The example above stated
4115 ``http://0.0.0.0:18989/apex/``. In a web browser use the URL
4116 ``http://localhost:18989`` and the REST Editor will start.
4118 The APEX Monitoring Client
4119 --------------------------
4121 .. container:: paragraph
4123 The standard way to use the APEX Monitoring Client is via an
4124 installation of the *war* file on a webserver. However, the
4125 Monitoring Client can also be started via command line. This
4126 will start a Grizzly webserver with the *war* deployed.
4127 Access to the Monitoring Client is then via the provided URL
4129 .. container:: paragraph
4131 On UNIX and Cygwin systems use:
4133 .. container:: ulist
4135 - ``apexApps.sh eng-monitoring`` - simply starts the
4136 webserver with the Monitoring Client
4138 .. container:: paragraph
4140 On Windows systems use:
4142 .. container:: ulist
4144 - ``apexApps.bat eng-monitoring`` - simply starts the
4145 webserver with the Monitoring Client
4147 .. container:: paragraph
4149 The option ``-h`` provides a help screen with all command
4152 .. container:: listingblock
4154 .. container:: content
4158 usage: org.onap.policy.apex.client.monitoring.rest.ApexMonitoringRestMain [options...]
4159 -h,--help outputs the usage of this command
4160 -p,--port <PORT> port to use for the Apex Services REST calls
4161 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4163 .. container:: paragraph
4165 If the Monitoring Client is started without any arguments
4166 the final messages will look similar to this:
4168 .. container:: listingblock
4170 .. container:: content
4174 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4175 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.NetworkListener start
4176 INFO: Started listener bound to [localhost:18989]
4177 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.HttpServer start
4178 INFO: [HttpServer] Started.
4179 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4181 .. container:: paragraph
4183 The last line states the URL on which the Monitoring Client
4184 can be accessed. The example above stated
4185 ``http://localhost:18989/apexservices``. In a web browser
4186 use the URL ``http://localhost:18989``.
4188 The APEX Deployment Client
4189 --------------------------
4191 .. container:: paragraph
4193 The standard way to use the APEX Deployment Client is via an
4194 installation of the *war* file on a webserver. However, the
4195 Deployment Client can also be started via command line. This
4196 will start a Grizzly webserver with the *war* deployed.
4197 Access to the Deployment Client is then via the provided URL
4199 .. container:: paragraph
4201 On UNIX and Cygwin systems use:
4203 .. container:: ulist
4205 - ``apexApps.sh eng-deployment`` - simply starts the
4206 webserver with the Deployment Client
4208 .. container:: paragraph
4210 On Windows systems use:
4212 .. container:: ulist
4214 - ``apexApps.bat eng-deployment`` - simply starts the
4215 webserver with the Deployment Client
4217 .. container:: paragraph
4219 The option ``-h`` provides a help screen with all command
4222 .. container:: listingblock
4224 .. container:: content
4228 usage: org.onap.policy.apex.client.deployment.rest.ApexDeploymentRestMain [options...]
4229 -h,--help outputs the usage of this command
4230 -p,--port <PORT> port to use for the Apex Services REST calls
4231 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4233 .. container:: paragraph
4235 If the Deployment Client is started without any arguments
4236 the final messages will look similar to this:
4238 .. container:: listingblock
4240 .. container:: content
4244 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4245 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.NetworkListener start
4246 INFO: Started listener bound to [localhost:18989]
4247 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.HttpServer start
4248 INFO: [HttpServer] Started.
4249 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4251 .. container:: paragraph
4253 The last line states the URL on which the Deployment Client
4254 can be accessed. The example above stated
4255 ``http://localhost:18989/apexservices``. In a web browser
4256 use the URL ``http://localhost:18989``.
4258 The APEX Full Client
4259 --------------------
4261 .. container:: paragraph
4263 The APEX Full Client combines the REST Editor, the
4264 Monitoring Client, and the Deployment Client into a single
4265 application. The standard way to use the APEX Full Client is
4266 via an installation of the *war* file on a webserver.
4267 However, the Full Client can also be started via command
4268 line. This will start a Grizzly webserver with the *war*
4269 deployed. Access to the Full Client is then via the provided
4272 .. container:: paragraph
4274 On UNIX and Cygwin systems use:
4276 .. container:: ulist
4278 - ``apexApps.sh full-client`` - simply starts the webserver
4279 with the Full Client
4281 .. container:: paragraph
4283 On Windows systems use:
4285 .. container:: ulist
4287 - ``apexApps.bat full-client`` - simply starts the
4288 webserver with the Full Client
4290 .. container:: paragraph
4292 The option ``-h`` provides a help screen with all command
4295 .. container:: listingblock
4297 .. container:: content
4301 usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4302 -h,--help outputs the usage of this command
4303 -p,--port <PORT> port to use for the Apex Services REST calls
4304 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4306 .. container:: paragraph
4308 If the Full Client is started without any arguments the
4309 final messages will look similar to this:
4311 .. container:: listingblock
4313 .. container:: content
4317 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4318 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4319 INFO: Started listener bound to [localhost:18989]
4320 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4321 INFO: [HttpServer] Started.
4322 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4324 .. container:: paragraph
4326 The last line states the URL on which the Monitoring Client
4327 can be accessed. The example above stated
4328 ``http://localhost:18989/apexservices``. In a web browser
4329 use the URL ``http://localhost:18989``.
4331 The APEX Application Launcher
4332 ------------------------------
4334 .. container:: paragraph
4336 The standard applications (Engine, CLI Editor, REST Editor)
4337 come with dedicated start scripts. For all other APEX
4338 applications, we provide an application launcher.
4340 .. container:: paragraph
4342 On UNIX and Cygwin systems use:
4344 .. container:: ulist
4346 - apexApps.sh\` - simply starts the application launcher
4348 .. container:: paragraph
4350 On Windows systems use:
4352 .. container:: ulist
4354 - ``apexApps.bat`` - simply starts the application launcher
4356 .. container:: paragraph
4358 Summary of alternatives to start the APEX application
4361 +-------------------------------------------------+---------------------------------------------------+
4362 | Unix, Cygwin | Windows |
4363 +=================================================+===================================================+
4364 | .. container:: | .. container:: |
4366 | .. container:: listingblock | .. container:: listingblock |
4368 | .. container:: content | .. container:: content |
4370 | .. code:: | .. code:: |
4372 | # $APEX_HOME/bin/apexApps.sh [args] | > %APEX_HOME%\bin\apexApps.bat [args] |
4373 +-------------------------------------------------+---------------------------------------------------+
4375 .. container:: paragraph
4377 The option ``-h`` provides a help screen with all launcher
4378 command line arguments.
4380 .. container:: listingblock
4382 .. container:: content
4386 apexApps.sh - runs APEX applications
4388 Usage: apexApps.sh [options] | [<application> [<application options>]]
4391 -d <app> - describes an application
4392 -l - lists all applications supported by this script
4393 -h - this help screen
4395 .. container:: paragraph
4397 Using ``-l`` lists all known application the launcher can
4400 .. container:: listingblock
4402 .. container:: content
4406 apexApps.sh: supported applications:
4407 --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4409 .. container:: paragraph
4411 Using the ``-d <name>`` option describes the named
4412 application, for instance for the ``ws-console``:
4414 .. container:: listingblock
4416 .. container:: content
4420 apexApps.sh: application 'ws-console'
4421 --> a simple console sending events to APEX, connect to APEX consumer port
4423 .. container:: paragraph
4425 Launching an application is done by calling the script with
4426 only the application name and any CLI arguments for the
4427 application. For instance, starting the ``ws-echo``
4428 application with port ``8888``:
4430 .. container:: listingblock
4432 .. container:: content
4436 apexApps.sh ws-echo -p 8888
4438 Application: Create Event Templates
4439 -----------------------------------
4441 .. container:: paragraph
4443 **Status: Experimental**
4445 .. container:: paragraph
4447 This application takes a policy model (JSON or XML encoded)
4448 and generates templates for events in JSON format. This can
4449 help when a policy defines rather complex trigger or action
4450 events or complex events between states. The application can
4451 produce events for the types: stimuli (policy trigger
4452 events), internal (events between policy states), and
4453 response (action events).
4455 +----------------------------------------------------------------+------------------------------------------------------------------+
4456 | Unix, Cygwin | Windows |
4457 +================================================================+==================================================================+
4458 | .. container:: | .. container:: |
4460 | .. container:: listingblock | .. container:: listingblock |
4462 | .. container:: content | .. container:: content |
4464 | .. code:: | .. code:: |
4466 | # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] | > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4467 +----------------------------------------------------------------+------------------------------------------------------------------+
4469 .. container:: paragraph
4471 The option ``-h`` provides a help screen.
4473 .. container:: listingblock
4475 .. container:: content
4479 gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4480 usage: gen-model2event
4481 -h,--help prints this help and usage screen
4482 -m,--model <MODEL-FILE> set the input policy model file
4483 -t,--type <TYPE> set the event type for generation, one of:
4484 stimuli (trigger events), response (action
4485 events), internal (events between states)
4486 -v,--version prints the application version
4488 .. container:: paragraph
4490 The created templates are not valid events, instead they use
4491 some markup for values one will need to change to actual
4492 values. For instance, running the tool with the *Sample
4493 Domain* policy model as:
4495 .. container:: listingblock
4497 .. container:: content
4501 apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4503 .. container:: paragraph
4505 will produce the following status messages:
4507 .. container:: listingblock
4509 .. container:: content
4513 gen-model2event: starting Event generator
4514 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4517 .. container:: paragraph
4519 and then run the generator application producing two event
4520 templates. The first template is called ``Event0000``.
4522 .. container:: listingblock
4524 .. container:: content
4529 "name" : "Event0000",
4530 "nameSpace" : "org.onap.policy.apex.sample.events",
4531 "version" : "0.0.1",
4532 "source" : "Outside",
4534 "TestTemperature" : ###double: 0.0###,
4535 "TestTimestamp" : ###long: 0###,
4536 "TestMatchCase" : ###integer: 0###,
4537 "TestSlogan" : "###string###"
4540 .. container:: paragraph
4542 The values for the keys are marked with ``#`` and the
4543 expected type of the value. To create an actual stimuli
4544 event, all these markers need to be change to actual values,
4547 .. container:: listingblock
4549 .. container:: content
4554 "name" : "Event0000",
4555 "nameSpace" : "org.onap.policy.apex.sample.events",
4556 "version" : "0.0.1",
4557 "source" : "Outside",
4559 "TestTemperature" : 25,
4560 "TestTimestamp" : 123456789123456789,
4561 "TestMatchCase" : 1,
4562 "TestSlogan" : "Testing the Match Case with Temperature 25"
4565 Application: Convert a Policy Model to CLI Editor Commands
4566 ----------------------------------------------------------
4568 .. container:: paragraph
4570 **Status: Experimental**
4572 .. container:: paragraph
4574 This application takes a policy model (JSON or XML encoded)
4575 and generates commands for the APEX CLI Editor. This
4576 effectively reverses a policy specification realized with
4579 +-------------------------------------------------------------+---------------------------------------------------------------+
4580 | Unix, Cygwin | Windows |
4581 +=============================================================+===============================================================+
4582 | .. container:: | .. container:: |
4584 | .. container:: listingblock | .. container:: listingblock |
4586 | .. container:: content | .. container:: content |
4588 | .. code:: | .. code:: |
4590 | # $APEX_HOME/bin/apexApps.sh model-2-cli [args] | > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4591 +-------------------------------------------------------------+---------------------------------------------------------------+
4593 .. container:: paragraph
4595 The option ``-h`` provides a help screen.
4597 .. container:: listingblock
4599 .. container:: content
4603 usage: gen-model2cli
4604 -h,--help prints this help and usage screen
4605 -m,--model <MODEL-FILE> set the input policy model file
4606 -sv,--skip-validation switch of validation of the input file
4607 -v,--version prints the application version
4609 .. container:: paragraph
4611 For instance, running the tool with the *Sample Domain*
4614 .. container:: listingblock
4616 .. container:: content
4620 apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4622 .. container:: paragraph
4624 will produce the following status messages:
4626 .. container:: listingblock
4628 .. container:: content
4632 gen-model2cli: starting CLI generator
4633 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4635 .. container:: paragraph
4637 and then run the generator application producing all CLI
4638 Editor commands and printing them to standard out.
4640 Application: Websocket Clients (Echo and Console)
4641 -------------------------------------------------
4643 .. container:: paragraph
4645 **Status: Production**
4647 .. container:: paragraph
4649 The application launcher also provides a Websocket echo
4650 client and a Websocket console client. The echo client
4651 connects to APEX and prints all events it receives from
4652 APEX. The console client connects to APEX, reads input from
4653 the command line, and sends this input as events to APEX.
4655 +------------------------------------------------------------+--------------------------------------------------------------+
4656 | Unix, Cygwin | Windows |
4657 +============================================================+==============================================================+
4658 | .. container:: | .. container:: |
4660 | .. container:: listingblock | .. container:: listingblock |
4662 | .. container:: content | .. container:: content |
4664 | .. code:: | .. code:: |
4666 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
4667 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4668 +------------------------------------------------------------+--------------------------------------------------------------+
4670 .. container:: paragraph
4672 The arguments are the same for both applications:
4674 .. container:: ulist
4676 - ``-p`` defines the Websocket port to connect to (defaults
4679 - ``-s`` defines the host on which a Websocket server is
4680 running (defaults to ``localhost``)
4682 .. container:: paragraph
4684 A discussion on how to use these two applications to build
4685 an APEX system is detailed HowTo-Websockets.
4692 .. container:: paragraph
4694 Consider a scenario where a supermarket chain called
4695 *HyperM* controls how it sells items in a policy-based
4696 manner. Each time an item is processed by *HyperM*'s
4697 point-of-sale (PoS) system an event is generated and
4698 published about that item of stock being sold. This event
4699 can then be used to update stock levels, etc..
4701 .. container:: paragraph
4703 *HyperM* want to extend this approach to allow some checks
4704 to be performed before the sale can be completed. This can
4705 be achieved by requesting a policy-controlled decision as
4706 each item is processed by for sale by each PoS system. The
4707 decision process is integrated with *HyperM*'s other IT
4708 systems that manage stock control, sourcing and purchasing,
4709 personnel systems, etc.
4711 .. container:: paragraph
4713 In this document we will show how APEX and APEX Policies can
4714 be used to achieve this, starting with a simple policy,
4715 building up to more complicated policy that demonstrates the
4724 .. container:: paragraph
4726 Each time a PoS system processes a sales item an event
4727 with the following format is emitted:
4729 .. table:: Table 1. Sale Input Event
4731 +----------------------+----------------------+-----------------------+
4732 | Event | Fields | Description |
4733 +======================+======================+=======================+
4734 | SALE_INPUT | time, sale_ID, | Event indicating a |
4735 | | amount, item_ID, | sale of an item is |
4736 | | quantity, | occurring |
4737 | | assistant_ID, | |
4738 | | branch_ID, notes, … | |
4739 +----------------------+----------------------+-----------------------+
4741 .. container:: paragraph
4743 In each ``SALE_INPUT`` event the ``sale_ID`` field is a
4744 unique ID generated by the PoS system. A timestamp for
4745 the event is stored in the ``time`` field. The ``amount``
4746 field refers to the value of the item(s) to be sold (in
4747 cents). The ``item_ID`` field is a unique identifier for
4748 each item type, and can be used to retrieve more
4749 information about the item from *HyperM*'s stock control
4750 system. The ``quantity`` field refers to the quantity of
4751 the item to be sold. The ``assistant_ID`` field is a
4752 unique identifier for the PoS operator, and can be used
4753 to retrieve more information about the operator from the
4754 *HyperM*'s personnel system. Since *HyperM* has many
4755 branches the ``branch_ID`` identifies the shop. The
4756 ``notes`` field contains arbitrary notes about the sale.
4758 Sales Decision Event
4759 ####################
4761 .. container:: paragraph
4763 After a ``SALE_INPUT`` event is emitted by the PoS system
4764 *HyperM*'s policy-based controlled sales checking system
4765 emits a Sale Authorization Event indicating whether the
4766 sale is authorized or denied. The PoS system can then
4767 listen for this event before continuing with the sale.
4769 .. table:: Table 2. Sale Authorisation Event
4771 +----------------------+----------------------+-----------------------+
4772 | Event | Fields | Description |
4773 +======================+======================+=======================+
4774 | SALE_AUTH | sale_ID, time, | Event indicating a |
4775 | | authorized, amount, | sale of an item is |
4776 | | item_ID, quantity, | authorized or denied |
4777 | | assistant_ID, | |
4778 | | branch_ID, notes, | |
4780 +----------------------+----------------------+-----------------------+
4782 .. container:: paragraph
4784 In each ``SALE_AUTH`` event the ``sale_ID`` field is
4785 copied from the ``SALE_INPUT`` event that trigger the
4786 decision request. The ``SALE_AUTH`` event is also
4787 timestamped using the ``time`` field, and a field called
4788 ``authorised`` is set to ``true`` or ``false`` depending
4789 on whether the sale is authorized or denied. The
4790 ``message`` field carries an optional message about why a
4791 sale was not authorized. The other fields from the
4792 ``SALE_INPUT`` event are also included for completeness.
4794 Stock Control: Items
4795 ####################
4797 .. container:: paragraph
4799 *HyperM* maintains information about each item for sale
4800 in a database table called ``ITEMS``.
4802 .. table:: Table 3. Items Database
4804 +----------------------+----------------------+-----------------------+
4805 | Table | Fields | Description |
4806 +======================+======================+=======================+
4807 | ITEMS | item_ID, | Database table |
4808 | | description, | describing each item |
4809 | | cost_price, barcode, | for sale |
4810 | | supplier_ID, | |
4811 | | category, … | |
4812 +----------------------+----------------------+-----------------------+
4814 .. container:: paragraph
4816 The database table ``ITEMS`` has a row for each items
4817 that *HyperM* sells. Each item is identified by an
4818 ``item_ID`` value. The ``description`` field stores a
4819 description of the item. The cost price of the item is
4820 given in ``cost_price``. The barcode of the item is
4821 encoded in ``barcode``, while the item supplier is
4822 identified by ``supplier_ID``. Items may also be
4823 classified into categories using the ``category`` field.
4824 Useful categories might include: ``soft drinks``,
4825 ``alcoholic drinks``, ``cigarettes``, ``knives``,
4826 ``confectionery``, ``bakery``, ``fruit&vegetables``,
4829 Personnel System: Assistants
4830 ############################
4832 .. table:: Table 4. Assistants Database
4834 +----------------------+----------------------+-----------------------+
4835 | Table | Fields | Description |
4836 +======================+======================+=======================+
4837 | ASSISTANTS | assistant_ID, | Database table |
4838 | | surname, firstname, | describing each |
4839 | | middlename, age, | *HyperM* sales |
4840 | | grade, phone_number, | assistant |
4842 +----------------------+----------------------+-----------------------+
4844 .. container:: paragraph
4846 The database table ``ASSISTANTS`` has a row for each
4847 sales assistant employed by *HyperM*. Each assistant is
4848 identified by an ``assistant_ID`` value, with their name
4849 given in the ``firstname``, ``middlename`` and
4850 ``surname`` fields. The assistant’s age in years is given
4851 in ``age``, while their phone number is contained in the
4852 ``phone_number`` field. The assistant’s grade is encoded
4853 in ``grade``. Useful values for ``grade`` might include:
4854 ``trainee``, ``operator``, ``supervisor``, etc..
4857 ####################
4859 .. table:: Table 5. Branches Database
4861 +----------------------+----------------------+-----------------------+
4862 | Table | Fields | Description |
4863 +======================+======================+=======================+
4864 | BRANCHES | branch_ID, | Database table |
4865 | | branch_Name, | describing each |
4866 | | category, street, | *HyperM* branch |
4867 | | city, country, | |
4868 | | postcode, … | |
4869 +----------------------+----------------------+-----------------------+
4871 .. container:: paragraph
4873 *HyperM* operates a number of branches. Each branch is
4874 described in the ``BRANCHES`` database table. Each branch
4875 is identified by a ``branch_ID``, with a branch name
4876 given in ``branch_Name``. The address for the branch is
4877 encoded in ``street``, ``city``, ``country`` and
4878 ``postcode``. The branch category is given in the
4879 ``category`` field. Useful values for ``category`` might
4880 include: ``Small``, ``Large``, ``Super``, ``Hyper``,
4888 .. container:: paragraph
4890 For the first version of our policy, let’s start with
4891 something simple. Let us assume that there exists some
4892 restriction that alcohol products cannot be sold before
4893 11:30am. In this section we will go through the necessary
4894 steps to define a policy that can enforce this for
4897 .. container:: ulist
4899 - Alcohol cannot be sold before 11:30am.
4901 Create the an new empty Policy Model ``MyFirstPolicyModel``
4902 ###########################################################
4904 .. container:: paragraph
4906 Since an organisation like *HyperM* may have many
4907 policies covering many different domains, policies should
4908 be grouped into policy sets. In order to edit or deploy a
4909 policy, or policy set, the definition of the policy(ies)
4910 and all required events, tasks, states, etc., are grouped
4911 together into a 'Policy Model'. An organization might
4912 define many Policy Models, each containing a different
4915 .. container:: paragraph
4917 So the first step is to create a new empty Policy Model
4918 called ``MyFirstPolicyModel``. Using the APEX Policy
4919 Editor, click on the 'File' menus and select 'New'. Then
4920 define our new policy model called
4921 ``MyFirstPolicyModel``. Use the 'Generate UUID' button to
4922 create a new unique ID for the policy model, and fill in
4923 a description for the policy model. Press the ``Submit``
4924 button to save your changes.
4926 .. container:: imageblock
4928 .. container:: content
4930 |File > New to create a new Policy Model|
4932 .. container:: title
4934 Figure 4. Create a new Policy Model 1/2
4936 .. container:: imageblock
4938 .. container:: content
4940 |Create a new Policy Model|
4942 .. container:: title
4944 Figure 5. Create a new Policy Model 2/2
4946 Create the input event ``SALE_INPUT`` and the output event ``SALE_AUTH``
4947 ########################################################################
4949 .. container:: paragraph
4951 Using the APEX Policy Editor, click on the 'Events' tab.
4952 In the 'Events' pane, right click and select 'New':
4954 .. container:: imageblock
4956 .. container:: content
4958 |Right click to create a new event|
4960 .. container:: title
4962 Figure 6. Create a new Event type
4964 .. container:: paragraph
4966 Create a new event type called ``SALE_INPUT``. Use the
4967 'Generate UUID' button to create a new unique ID for the
4968 event type, and fill in a description for the event. Add
4969 a namespace, e.g. ``com.hyperm``. We can add hard-coded
4970 strings for the ``Source`` and ``Target``, e.g. ``POS``
4971 and ``APEX``. At this stage we will not add any parameter
4972 fields, we will leave this until later. Use the
4973 ``Submit`` button to create the event.
4975 .. container:: imageblock
4977 .. container:: content
4979 |Fill in the necessary information for the
4980 'SALE_INPUT' event and click 'Submit'|
4982 .. container:: title
4984 Figure 7. Populate the ``SALE_INPUT`` event
4986 .. container:: paragraph
4988 Repeat the same steps for a new event type called
4989 ``SALE_AUTH``. Just use ``APEX`` as source and ``POS`` as
4990 target, since this is the output event coming from APEX
4991 going to the sales point.
4993 .. container:: paragraph
4995 Before we can add parameter fields to an event we must
4996 first define APEX Context Item Schemas that can be used
4999 .. container:: paragraph
5001 To create new item schemas, click on the 'Context Item
5002 Schemas' tab. In that 'Context Item Schemas' pane, right
5003 click and select 'Create new ContextSchema'.
5005 .. container:: imageblock
5007 .. container:: content
5009 |Right click to create a new Item Schema|
5011 .. container:: title
5013 Figure 8. Create new Data Types
5015 .. container:: paragraph
5017 Create item schemas with the following characteristics,
5018 each with its own unique UUID:
5020 .. table:: Table 6. Item Schemas
5022 +-------------------+-----------------+-----------------+----------------------+
5023 | Name | Schema Flavour | Schema | Description |
5024 | | | Definition | |
5025 +===================+=================+=================+======================+
5026 | timestamp_type | Java | java.lang.Long | A type for |
5027 | | | | ``time`` values |
5028 +-------------------+-----------------+-----------------+----------------------+
5029 | sale_ID_type | Java | java.lang.Long | A type for |
5030 | | | | ``sale_ID`` |
5032 +-------------------+-----------------+-----------------+----------------------+
5033 | price_type | Java | java.lang.Long | A type for |
5034 | | | | ``amount``/``price`` |
5036 +-------------------+-----------------+-----------------+----------------------+
5037 | item_ID_type | Java | java.lang.Long | A type for |
5038 | | | | ``item_ID`` |
5040 +-------------------+-----------------+-----------------+----------------------+
5041 | assistant_ID_type | Java | java.lang.Long | A type for |
5042 | | | | ``assistant_ID`` |
5044 +-------------------+-----------------+-----------------+----------------------+
5045 | quantity_type | Java | java.lang.Integ | A type for |
5046 | | | er | ``quantity`` |
5048 +-------------------+-----------------+-----------------+----------------------+
5049 | branch_ID_type | Java | java.lang.Long | A type for |
5050 | | | | ``branch_ID`` |
5052 +-------------------+-----------------+-----------------+----------------------+
5053 | notes_type | Java | java.lang.Strin | A type for |
5054 | | | g | ``notes`` |
5056 +-------------------+-----------------+-----------------+----------------------+
5057 | authorised_type | Java | java.lang.Boole | A type for |
5058 | | | an | ``authorised`` |
5060 +-------------------+-----------------+-----------------+----------------------+
5061 | message_type | Java | java.lang.Strin | A type for |
5062 | | | g | ``message`` |
5064 +-------------------+-----------------+-----------------+----------------------+
5066 .. container:: imageblock
5068 .. container:: content
5070 |Create a new Item Schema|
5072 .. container:: title
5074 Figure 9. Create new Item Schemas
5076 .. container:: paragraph
5078 The item schemas can now be seen on the 'Context Item
5079 Schemas' tab, and can be updated at any time by
5080 right-clicking on the item schemas on the 'Context Item
5081 Schemas' tab. Now we can go back to the event definitions
5082 for ``SALE_INPUT`` and ``SALE_AUTH`` and add some
5087 .. container:: title
5091 .. container:: paragraph
5093 APEX natively supports schema definitions in ``Java`` and ``Avro``.
5095 .. container:: paragraph
5097 ``Java`` schema definitions are simply the name of a Java Class. There are some restrictions:
5099 .. container:: ulist
5101 - the class must be instantiatable, i.e. not an Java interface or abstract class
5103 - primitive types are not supported, i.e. use ``java.lang.Integer`` instead of ``int``, etc.
5105 - it must be possible to find the class, i.e. the class must be contained in the Java classpath.
5107 .. container:: paragraph
5109 ``Avro`` schema definitions can be any valid `Avro <https://avro.apache.org/docs/current/spec.html>`__
5110 schema. For events using fields defined with ``Avro`` schemas, any incoming event containing that field must
5111 contain a value that conforms to the Avro schema.
5113 .. container:: paragraph
5115 Click on the 'Events' tab, then right click the
5116 ``SALE_INPUT`` row and select 'Edit Event
5117 :literal:`SALE_INPUT’. To add a new event parameter use the 'Add Event Parameter' button at the bottom of the screen. For the `SALE_INPUT`
5118 event add the following event parameters:
5120 .. table:: Table 7. Event Parameter Fields for the ``SALE_INPUT`` Event
5122 +----------------------+----------------------+-----------------------+
5123 | Parameter Name | Parameter Type | Optional |
5124 +======================+======================+=======================+
5125 | time | timestamp_type | no |
5126 +----------------------+----------------------+-----------------------+
5127 | sale_ID | sale_ID_type | no |
5128 +----------------------+----------------------+-----------------------+
5129 | amount | price_type | no |
5130 +----------------------+----------------------+-----------------------+
5131 | item_ID | item_ID_type | no |
5132 +----------------------+----------------------+-----------------------+
5133 | quantity | quantity_type | no |
5134 +----------------------+----------------------+-----------------------+
5135 | assistant_ID | assistant_ID_type | no |
5136 +----------------------+----------------------+-----------------------+
5137 | branch_ID | branch_ID_type | no |
5138 +----------------------+----------------------+-----------------------+
5139 | notes | notes_type | *yes* |
5140 +----------------------+----------------------+-----------------------+
5142 .. container:: paragraph
5144 Remember to click the 'Submit' button at the bottom of
5145 the event definition pane.
5148 Optional Fields in APEX Events
5149 Parameter fields can be *optional* in events. If a parameter is not marked as *optional* then by default it
5150 is *mandatory*, so it must appear in any input event passed to APEX. If an *optional* field is not set
5151 for an output event then value will be set to ``null``.
5153 .. container:: imageblock
5155 .. container:: content
5157 |Add new event parameters to an event|
5159 .. container:: title
5161 Figure 10. Add typed parameter fields to an event
5163 .. container:: paragraph
5165 Select the ``SALE_AUTH`` event and add the following
5168 .. table:: Table 8. Event Parameter Fields for the ``SALE_AUTH`` Event
5170 +----------------------+----------------------+-----------------------+
5171 | Parameter Name | Parameter Type | no |
5172 +======================+======================+=======================+
5173 | sale_ID | sale_ID_type | no |
5174 +----------------------+----------------------+-----------------------+
5175 | time | timestamp_type | no |
5176 +----------------------+----------------------+-----------------------+
5177 | authorised | authorised_type | no |
5178 +----------------------+----------------------+-----------------------+
5179 | message | message_type | *yes* |
5180 +----------------------+----------------------+-----------------------+
5181 | amount | price_type | no |
5182 +----------------------+----------------------+-----------------------+
5183 | item_ID | item_ID_type | no |
5184 +----------------------+----------------------+-----------------------+
5185 | assistant_ID | assistant_ID_type | no |
5186 +----------------------+----------------------+-----------------------+
5187 | quantity | quantity_type | no |
5188 +----------------------+----------------------+-----------------------+
5189 | branch_ID | branch_ID_type | no |
5190 +----------------------+----------------------+-----------------------+
5191 | notes | notes_type | *yes* |
5192 +----------------------+----------------------+-----------------------+
5194 .. container:: paragraph
5196 Remember to click the 'Submit' button at the bottom of
5197 the event definition pane.
5199 .. container:: paragraph
5201 The events for our policy are now defined.
5203 Create a new Policy and add the *"No Booze before 11:30"* check
5204 ###############################################################
5206 .. container:: paragraph
5208 APEX policies are defined using a state-machine model.
5209 Each policy comprises one or more *states* that can be
5210 individually executed. Where there is more than one
5211 *state* the states are chained together to form a
5212 `Directed Acyclic Graph
5213 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__
5214 of states. A *state* is triggered by passing it a single
5215 input (or 'trigger') event and once executed each state
5216 then emits an output event. For each *state* the logic
5217 for the *state* is embedded in one or more *tasks*. Each
5218 *task* contains specific *task logic* that is executed by
5219 the APEX execution environment each time the *task* is
5220 invoked. Where there is more than one *task* in a *state*
5221 then the *state* also defines some *task selection logic*
5222 to select an appropriate task each time the *state* is
5225 .. container:: paragraph
5227 Therefore, to create a new policy we must first define
5230 .. container:: paragraph
5232 To create a new Task click on the 'Tasks' tab. In the
5233 'Tasks' pane, right click and select 'Create new Task'.
5234 Create a new Task called ``MorningBoozeCheck``. Use the
5235 'Generate UUID' button to create a new unique ID for the
5236 task, and fill in a description for the task.
5238 .. container:: imageblock
5240 .. container:: content
5242 |Right click to create a new task|
5244 .. container:: title
5246 Figure 11. Create a new Task
5248 .. container:: paragraph
5250 Tasks are configured with a set of *input fields* and a
5251 set of *output fields*. To add new input/output fields
5252 for a task use the 'Add Task Input Field' and 'Add Task
5253 Output Field' button. The list of input and out fields to
5254 add for the ``MorningBoozeCheck`` task are given below.
5255 The input fields are drawn from the parameters in the
5256 state’s input event, and the task’s output fields are
5257 used to populate the state’s output event. The task’s
5258 input and output fields must be a subset of the event
5259 parameters defined for the input and output events for
5260 any state that uses that task. (You may have noticed that
5261 the input and output fields for the ``MorningBoozeCheck``
5262 task have the exact same names and reuse the item schemas
5263 that we used for the parameters in the ``SALE_INPUT`` and
5264 ``SALE_AUTH`` events respectively).
5266 .. table:: Table 9. Input fields for ``MorningBoozeCheck`` task
5268 +-----------------------------------+-----------------------------------+
5269 | Parameter Name | Parameter Type |
5270 +===================================+===================================+
5271 | time | timestamp_type |
5272 +-----------------------------------+-----------------------------------+
5273 | sale_ID | sale_ID_type |
5274 +-----------------------------------+-----------------------------------+
5275 | amount | price_type |
5276 +-----------------------------------+-----------------------------------+
5277 | item_ID | item_ID_type |
5278 +-----------------------------------+-----------------------------------+
5279 | quantity | quantity_type |
5280 +-----------------------------------+-----------------------------------+
5281 | assistant_ID | assistant_ID_type |
5282 +-----------------------------------+-----------------------------------+
5283 | branch_ID | branch_ID_type |
5284 +-----------------------------------+-----------------------------------+
5285 | notes | notes_type |
5286 +-----------------------------------+-----------------------------------+
5288 .. table:: Table 10. Output fields for ``MorningBoozeCheck`` task
5290 +-----------------------------------+-----------------------------------+
5291 | Parameter Name | Parameter Type |
5292 +===================================+===================================+
5293 | sale_ID | sale_ID_type |
5294 +-----------------------------------+-----------------------------------+
5295 | time | timestamp_type |
5296 +-----------------------------------+-----------------------------------+
5297 | authorised | authorised_type |
5298 +-----------------------------------+-----------------------------------+
5299 | message | message_type |
5300 +-----------------------------------+-----------------------------------+
5301 | amount | price_type |
5302 +-----------------------------------+-----------------------------------+
5303 | item_ID | item_ID_type |
5304 +-----------------------------------+-----------------------------------+
5305 | assistant_ID | assistant_ID_type |
5306 +-----------------------------------+-----------------------------------+
5307 | quantity | quantity_type |
5308 +-----------------------------------+-----------------------------------+
5309 | branch_ID | branch_ID_type |
5310 +-----------------------------------+-----------------------------------+
5311 | notes | notes_type |
5312 +-----------------------------------+-----------------------------------+
5314 .. container:: imageblock
5316 .. container:: content
5318 |Add input and out fields for the task|
5320 .. container:: title
5322 Figure 12. Add input and out fields for the Task
5324 .. container:: paragraph
5326 Each task must include some 'Task Logic' that implements
5327 the behaviour for the task. Task logic can be defined in
5328 a number of different ways using a choice of languages.
5329 For this task we will author the logic using the
5330 Java-like scripting language called
5331 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__.
5333 .. container:: paragraph
5335 For simplicity use the following code for the task logic.
5336 Paste the script text into the 'Task Logic' box, and use
5337 "MVEL" as the 'Task Logic Type / Flavour'.
5339 .. container:: paragraph
5341 This logic assumes that all items with ``item_ID``
5342 between 1000 and 2000 contain alcohol, which is not very
5343 realistic, but we will see a better approach for this
5344 later. It also uses the standard ``Java`` time utilities
5345 to check if the current time is between ``00:00:00 GMT``
5346 and ``11:30:00 GMT``. For a detailed guide to how to
5347 write your own logic in
5348 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
5349 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
5350 of the other supported languages please refer to APEX
5353 .. container:: listingblock
5355 .. container:: title
5357 MVEL code for the ``MorningBoozeCheck`` task
5359 .. container:: content
5364 * ============LICENSE_START=======================================================
5365 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5366 * ================================================================================
5367 * Licensed under the Apache License, Version 2.0 (the "License");
5368 * you may not use this file except in compliance with the License.
5369 * You may obtain a copy of the License at
5371 * http://www.apache.org/licenses/LICENSE-2.0
5373 * Unless required by applicable law or agreed to in writing, software
5374 * distributed under the License is distributed on an "AS IS" BASIS,
5375 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5376 * See the License for the specific language governing permissions and
5377 * limitations under the License.
5379 * SPDX-License-Identifier: Apache-2.0
5380 * ============LICENSE_END=========================================================
5382 import java.util.Date;
5383 import java.util.Calendar;
5384 import java.util.TimeZone;
5385 import java.text.SimpleDateFormat;
5387 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
5389 outFields.put("amount" , inFields.get("amount"));
5390 outFields.put("assistant_ID", inFields.get("assistant_ID"));
5391 outFields.put("notes" , inFields.get("notes"));
5392 outFields.put("quantity" , inFields.get("quantity"));
5393 outFields.put("branch_ID" , inFields.get("branch_ID"));
5394 outFields.put("item_ID" , inFields.get("item_ID"));
5395 outFields.put("time" , inFields.get("time"));
5396 outFields.put("sale_ID" , inFields.get("sale_ID"));
5398 item_id = inFields.get("item_ID");
5400 //The events used later to test this task use GMT timezone!
5401 gmt = TimeZone.getTimeZone("GMT");
5402 timenow = Calendar.getInstance(gmt);
5403 df = new SimpleDateFormat("HH:mm:ss z");
5404 df.setTimeZone(gmt);
5405 timenow.setTimeInMillis(inFields.get("time"));
5407 midnight = timenow.clone();
5409 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5410 timenow.get(Calendar.DATE),0,0,0);
5411 eleven30 = timenow.clone();
5413 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5414 timenow.get(Calendar.DATE),11,30,0);
5416 itemisalcohol = false;
5417 if(item_id != null && item_id >=1000 && item_id < 2000)
5418 itemisalcohol = true;
5421 && timenow.after(midnight) && timenow.before(eleven30)){
5422 outFields.put("authorised", false);
5423 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
5424 " for time "+df.format(timenow.getTime())+
5425 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
5426 " and "+df.format(eleven30.getTime()));
5430 outFields.put("authorised", true);
5431 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
5432 " for time "+df.format(timenow.getTime()));
5437 This task checks if a sale request is for an item that is an alcoholic drink.
5438 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5439 authorised. Otherwise the sale is authorised.
5440 In this implementation we assume that items with item_ID value between 1000 and
5441 2000 are all alcoholic drinks :-)
5444 .. container:: imageblock
5446 .. container:: content
5448 |Add task logic the task|
5450 .. container:: title
5452 Figure 13. Add Task Logic the Task
5454 .. container:: paragraph
5456 An alternative version of the same logic is available in
5457 JavaScript. Just use "JAVASCRIPT" as the 'Task Logic Type
5460 .. container:: listingblock
5462 .. container:: title
5464 Javascript alternative for the ``MorningBoozeCheck``
5467 .. container:: content
5472 * ============LICENSE_START=======================================================
5473 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5474 * ================================================================================
5475 * Licensed under the Apache License, Version 2.0 (the "License");
5476 * you may not use this file except in compliance with the License.
5477 * You may obtain a copy of the License at
5479 * http://www.apache.org/licenses/LICENSE-2.0
5481 * Unless required by applicable law or agreed to in writing, software
5482 * distributed under the License is distributed on an "AS IS" BASIS,
5483 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5484 * See the License for the specific language governing permissions and
5485 * limitations under the License.
5487 * SPDX-License-Identifier: Apache-2.0
5488 * ============LICENSE_END=========================================================
5491 var returnValueType = Java.type("java.lang.Boolean");
5492 var returnValue = new returnValueType(true);
5494 // Load compatibility script for imports etc
5495 load("nashorn:mozilla_compat.js");
5496 importPackage(java.text);
5497 importClass(java.text.SimpleDateFormat);
5499 executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'");
5501 executor.outFields.put("amount" , executor.inFields.get("amount"));
5502 executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID"));
5503 executor.outFields.put("notes" , executor.inFields.get("notes"));
5504 executor.outFields.put("quantity" , executor.inFields.get("quantity"));
5505 executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID"));
5506 executor.outFields.put("item_ID" , executor.inFields.get("item_ID"));
5507 executor.outFields.put("time" , executor.inFields.get("time"));
5508 executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID"));
5510 item_id = executor.inFields.get("item_ID");
5512 //All times in this script are in GMT/UTC since the policy and events assume time is in GMT.
5513 var timenow_gmt = new Date(Number(executor.inFields.get("time")));
5515 var midnight_gmt = new Date(Number(executor.inFields.get("time")));
5516 midnight_gmt.setUTCHours(0,0,0,0);
5518 var eleven30_gmt = new Date(Number(executor.inFields.get("time")));
5519 eleven30_gmt.setUTCHours(11,30,0,0);
5521 var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z");
5523 var itemisalcohol = false;
5524 if(item_id != null && item_id >=1000 && item_id < 2000)
5525 itemisalcohol = true;
5528 && timenow_gmt.getTime() >= midnight_gmt.getTime()
5529 && timenow_gmt.getTime() < eleven30_gmt.getTime()) {
5531 executor.outFields.put("authorised", false);
5532 executor.outFields.put("message", "Sale not authorised by policy task " +
5533 executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) +
5534 ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) +
5535 " and " + timeformatter.format(eleven30_gmt.getTime()));
5538 executor.outFields.put("authorised", true);
5539 executor.outFields.put("message", "Sale authorised by policy task " +
5540 executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime()));
5544 This task checks if a sale request is for an item that is an alcoholic drink.
5545 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5546 authorised. Otherwise the sale is authorised.
5547 In this implementation we assume that items with item_ID value between 1000 and
5548 2000 are all alcoholic drinks :-)
5551 .. container:: paragraph
5553 The task definition is now complete so click the 'Submit'
5554 button to save the task. The task can now be seen on the
5555 'Tasks' tab, and can be updated at any time by
5556 right-clicking on the task on the 'Task' tab. Now that we
5557 have created our task, we can can create a policy that
5560 .. container:: paragraph
5562 To create a new Policy click on the 'Policies' tab. In
5563 the 'Policies' pane, right click and select 'Create new
5566 .. container:: paragraph
5568 Create a new Policy called ``MyFirstPolicy``. Use the
5569 'Generate UUID' button to create a new unique ID for the
5570 policy, and fill in a description for the policy. Use
5571 'FREEFORM' as the 'Policy Flavour'.
5573 .. container:: paragraph
5575 Each policy must have at least one state. Since this is
5576 'freeform' policy we can add as many states as we wish.
5577 Let’s start with one state. Add a new state called
5578 ``BoozeAuthDecide`` to this ``MyFirstPolicy`` policy
5579 using the 'Add new State' button after filling in the
5580 name of our new state.
5582 .. container:: imageblock
5584 .. container:: content
5586 |Create a new policy|
5588 .. container:: title
5590 Figure 14. Create a new Policy
5592 .. container:: paragraph
5594 Each state must uses one input event type. For this new
5595 state select the ``SALE_INPUT`` event as the input event.
5597 .. container:: paragraph
5599 Each policy must define a 'First State' and a 'Policy
5600 Trigger Event'. The 'Policy Trigger Event' is the input
5601 event for the policy as a whole. This event is then
5602 passed to the first state in the chain of states in the
5603 policy, therefore the 'Policy Trigger Event' will be the
5604 input event for the first state. Each policy can only
5605 have one 'First State'. For our ``MyFirstPolicy`` policy,
5606 select ``BoozeAuthDecide`` as the 'First State'. This
5607 will automatically select ``SALE_INPUT`` as the 'Policy
5608 Trigger Event' for our policy.
5610 .. container:: imageblock
5612 .. container:: content
5616 .. container:: title
5618 Figure 15. Create a new State
5620 .. container:: paragraph
5622 In this case we will create a reference the pre-existing
5623 ``MorningBoozeCheck`` task that we defined above using
5624 the 'Add New Task' button. Select the
5625 ``MorningBoozeCheck`` task, and use the name of the task
5626 as the 'Local Name' for the task.
5628 .. container:: paragraph
5630 in the case where a state references more than one task,
5631 a 'Default Task' must be selected for the state and some
5632 logic ('Task Selection Logic') must be specified to
5633 select the appropriate task at execution time. Since our
5634 new state ``BoozeAuthDecide`` only has one task the
5635 default task is automatically selected and no 'Task
5636 Selection Logic' is required.
5639 .. container:: title
5641 State Output Mappings
5643 .. container:: paragraph
5645 In a 'Policy' 'State' a 'State Output Mapping' has 3 roles:
5646 1) Select which 'State' should be executed next, 2) Select
5647 the type of the state’s 'Outgoing Event', and 3)
5648 Populate the state’s 'Outgoing Event'. This is how states are
5649 chained together to form a (`Directed Acyclic Graph
5650 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__ )
5651 of states. The final state(s) of a policy are those that do
5652 not select any 'next' state. Since a 'State' can only
5653 accept a single type of event, the type of the event emitted
5654 by a previous 'State' must be match the incoming event type
5655 of the next 'State'. This is also how the last state(s) in
5656 a policy can emit events of different types. The 'State
5657 Output Mapping' is also responsible for taking the
5658 fields that are output by the task executed in the state and
5659 populating the state’s output event before it is emitted.
5661 .. container:: paragraph
5663 Each 'Task' referenced in 'State' must have a defined
5664 'Output Mapping' to take the output of the task, select an
5665 'Outgoing Event' type for the state, populate the state’s
5666 outgoing event, and then select the next state to be
5669 .. container:: paragraph
5671 There are 2 basic types of output mappings:
5673 .. container:: olist arabic
5675 #. **Direct Output Mappings** have a single value for
5676 'Next State' and a single value for 'State Output
5677 Event'. The outgoing event for the state is
5678 automatically created, any outgoing event parameters
5679 that were present in the incoming event are copied
5680 into the outgoing event, then any task output fields
5681 that have the same name and type as parameters in the
5682 outgoing event are automatically copied into
5685 #. **Logic-based State Output Mappings / Finalizers**
5686 have some logic defined that dynamically selects
5687 and creates the 'State Outgoing Event', manages
5688 the population of the outgoing event parameters
5689 (perhaps changing or adding to the outputs from the
5690 task), and then dynamically selects the next state to
5691 be executed (if any).
5693 .. container:: paragraph
5695 Each task reference must also have an associated 'Output
5696 State Mapping' so we need an 'Output State Mapping' for
5697 the ``BoozeAuthDecide`` state to use when the
5698 ``MorningBoozeCheck`` task is executed. The simplest type
5699 of output mapping is a 'Direct Output Mapping'.
5701 .. container:: paragraph
5703 Create a new 'Direct Output Mapping' for the state called
5704 ``MorningBoozeCheck_Output_Direct`` using the 'Add New
5705 Direct State Output Mapping' button. Select ``SALE_AUTH``
5706 as the output event and select ``None`` for the next
5707 state value. We can then select this output mapping for
5708 use when the the ``MorningBoozeCheck`` task is executed.
5709 Since there is only state, and only one task for that
5710 state, this output mapping ensures that the
5711 ``BoozeAuthDecide`` state is the only state executed and
5712 the state (and the policy) can only emit events of type
5713 ``SALE_AUTH``. (You may remember that the output fields
5714 for the ``MorningBoozeCheck`` task have the exact same
5715 names and reuse the item schemas that we used for the
5716 parameters in ``SALE_AUTH`` event. The
5717 ``MorningBoozeCheck_Output_Direct`` direct output mapping
5718 can now automatically copy the values from the
5719 ``MorningBoozeCheck`` task directly into outgoing
5720 ``SALE_AUTH`` events.)
5722 .. container:: imageblock
5724 .. container:: content
5726 |Add a Task and Output Mapping|
5728 .. container:: title
5730 Figure 16. Add a Task and Output Mapping
5732 .. container:: paragraph
5734 Click the 'Submit' button to complete the definition of
5735 our ``MyFirstPolicy`` policy. The policy
5736 ``MyFirstPolicy`` can now be seen in the list of policies
5737 on the 'Policies' tab, and can be updated at any time by
5738 right-clicking on the policy on the 'Policies' tab.
5740 .. container:: paragraph
5742 The ``MyFirstPolicyModel``, including our
5743 ``MyFirstPolicy`` policy can now be checked for errors.
5744 Click on the 'Model' menu and select 'Validate'. The
5745 model should validate without any 'Warning' or 'Error'
5746 messages. If you see any 'Error' or 'Warning' messages,
5747 carefully read the message as a hint to find where you
5748 might have made a mistake when defining some aspect of
5751 .. container:: imageblock
5753 .. container:: content
5755 |Validate the policy model for error using the 'Model'
5756 > 'Validate' menu item|
5758 .. container:: title
5760 Figure 17. Validate a Policy Model
5762 .. container:: paragraph
5764 Congratulations, you have now completed your first APEX
5765 policy. The policy model containing our new policy can
5766 now be exported from the editor and saved. Click on the
5767 'File' menu and select 'Download' to save the policy
5768 model in JSON format. The exported policy model is then
5769 available in the directory you selected, for instance
5770 ``$APEX_HOME/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json``.
5771 The exported policy can now be loaded into the APEX
5772 Policy Engine, or can be re-loaded and edited by the APEX
5775 .. container:: imageblock
5777 .. container:: content
5779 |Download the completed policy model using the 'File'
5780 > 'Download' menu item|
5782 .. container:: title
5784 Figure 18. Export a Policy Model
5789 .. container:: paragraph
5791 To start a new APEX Engine you can use the following
5792 configuration. In a full APEX installation you can find
5793 this configuration in
5794 ``$APEX_HOME/examples/config/MyFirstPolicy/1/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
5795 This configuration expects incoming events to be in
5796 ``JSON`` format and to be passed into the APEX Engine
5797 from ``stdin``, and result events will be printed in
5798 ``JSON`` format to ``stdout``. This configuration loads
5799 the policy model stored in the file
5800 'MyFirstPolicyModel_0.0.1.json' as exported from the APEX
5801 Editor. Note, you may need to edit this file to provide
5802 the full path to wherever you stored the exported policy
5805 .. container:: listingblock
5807 .. container:: title
5809 JSON to load and execute *My First Policy*, read input
5810 JSON events from ``stdin``, and emit output events to
5813 .. container:: content
5818 "engineServiceParameters" : {
5819 "name" : "MyFirstPolicyApexEngine",
5820 "version" : "0.0.1",
5822 "instanceCount" : 4,
5823 "deploymentPort" : 12345,
5824 "policyModelFileName" : "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json",
5825 "engineParameters" : {
5826 "executorParameters" : {
5828 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
5831 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
5836 "eventOutputParameters": {
5838 "carrierTechnologyParameters" : {
5839 "carrierTechnology" : "FILE",
5844 "eventProtocolParameters" : {
5845 "eventProtocol" : "JSON"
5849 "eventInputParameters": {
5851 "carrierTechnologyParameters" : {
5852 "carrierTechnology" : "FILE",
5857 "eventProtocolParameters" : {
5858 "eventProtocol" : "JSON"
5864 .. container:: paragraph
5866 To test the policy try paste the following events into
5867 the console as the APEX engine executes:
5869 .. table:: Table 11. Inputs and Outputs when testing *My First Policy*
5871 +------------------------------------------+-------------------------------------------+-----------+
5872 | Input Event (JSON) | Output Event (JSON) | comment |
5873 +==========================================+===========================================+===========+
5874 | .. container:: | .. container:: | Request |
5876 | .. container:: listingblock | .. container:: listingblock | non-alcoh |
5878 | | .. container:: content | item |
5879 | .. container:: content | | (``item_I |
5880 | | .. code:: | D=5123``) |
5882 | .. code:: | { | *10:13:09 |
5883 | | "name": "SALE_AUTH", | * |
5885 | { | "version": "0.0.1", | *Tuesday, |
5886 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | 10 |
5887 | "name" : "SALE_INPUT", | "source": "", | January |
5888 | "version": "0.0.1", | "target": "", | 2017*. |
5889 | "time" : 1483351989000, | "amount": 299, | Sale is |
5890 | "sale_ID": 99999991, | "assistant_ID": 23, | authorize |
5891 | "amount": 299, | "authorised": true, | d. |
5892 | "item_ID": 5123, | "branch_ID": 1, | |
5893 | "quantity": 1, | "item_ID": 5123, | |
5894 | "assistant_ID": 23, | "message": "Sale authorised | |
5895 | "branch_ID": 1, | by policy task MorningBo | |
5896 | "notes": "Special Offer!!" | ozeCheck for time 10:13:09 | |
5898 | | "notes": "Special Offer!!", | |
5899 | | "quantity": 1, | |
5900 | | "sale_ID": 99999991, | |
5901 | | "time": 1483351989000 | |
5906 +------------------------------------------+-------------------------------------------+-----------+
5907 | .. container:: | .. container:: | Request |
5909 | .. container:: listingblock | .. container:: listingblock | alcohol |
5911 | .. container:: content | .. container:: content | (``item_I |
5913 | .. code:: | .. code:: | at |
5916 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | on |
5917 | "name": "SALE_INPUT", | "name": "SALE_AUTH", | *Monday, |
5918 | "version": "0.0.1", | "source": "", | 02 |
5919 | "time": 1483346466000, | "target": "", | January |
5920 | "sale_ID": 99999992, | "amount": 1249, | 2017*. |
5921 | "version": "0.0.1", | "assistant_ID": 12, | |
5922 | "amount": 1249, | "authorised": false, | Sale is |
5923 | "item_ID": 1012, | "branch_ID": 2, | not |
5924 | "quantity": 1, | "item_ID": 1012, | authorize |
5925 | "assistant_ID": 12, | "message": "Sale not | d. |
5926 | "branch_ID": 2 | authorised by policy task | |
5927 | } | MorningBoozeCheck for time | |
5928 | | 08:41:06 GMT. Alcohol can | |
5929 | | not be sold between | |
5930 | | 00:00:00 GMT and 11:30:00 | |
5932 | | "notes": null, | |
5933 | | "quantity": 1, | |
5934 | | "sale_ID": 99999992, | |
5935 | | "time": 1483346466000 | |
5937 +------------------------------------------+-------------------------------------------+-----------+
5938 | .. container:: | .. container:: | Request |
5940 | .. container:: listingblock | .. container:: listingblock | alcohol |
5942 | | .. container:: content | D=1943``) |
5943 | .. container:: content | | at |
5944 | | .. code:: | *20:17:13 |
5946 | .. code:: | { | on |
5947 | | "name": "SALE_AUTH", | *Tuesday, |
5948 | { | "version": "0.0.1", | 20 |
5949 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | December |
5950 | "name" : "SALE_INPUT", | "source": "", | 2016*. |
5951 | "version": "0.0.1", | "target": "", | |
5952 | "time" : 1482265033000, | "amount": 4799, | Sale is |
5953 | "sale_ID": 99999993, | "assistant_ID": 9, | authorize |
5954 | "amount": 4799, | "authorised": true, | d. |
5955 | "item_ID": 1943, | "branch_ID": 3, | |
5956 | "quantity": 2, | "item_ID": 1943, | |
5957 | "assistant_ID": 9, | "message": "Sale authorised | |
5958 | "branch_ID": 3 | by policy task MorningBo | |
5959 | } | ozeCheck for time 20:17:13 | |
5961 | | "notes": null, | |
5962 | | "quantity": 2, | |
5963 | | "sale_ID": 99999993, | |
5964 | | "time": 1482265033000 | |
5966 +------------------------------------------+-------------------------------------------+-----------+
5968 4.3.6. Policy 1 in CLI Editor
5969 #############################
5971 .. container:: paragraph
5973 An equivalent version of the ``MyFirstPolicyModel``
5974 policy model can again be generated using the APEX CLI
5975 editor. A sample APEX CLI script is shown below:
5977 .. container:: listingblock
5979 .. container:: title
5981 APEX CLI Editor code for Policy 1
5983 .. container:: content
5987 #-------------------------------------------------------------------------------
5988 # ============LICENSE_START=======================================================
5989 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
5990 # ================================================================================
5991 # Licensed under the Apache License, Version 2.0 (the "License");
5992 # you may not use this file except in compliance with the License.
5993 # You may obtain a copy of the License at
5995 # http://www.apache.org/licenses/LICENSE-2.0
5997 # Unless required by applicable law or agreed to in writing, software
5998 # distributed under the License is distributed on an "AS IS" BASIS,
5999 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6000 # See the License for the specific language governing permissions and
6001 # limitations under the License.
6003 # SPDX-License-Identifier: Apache-2.0
6004 # ============LICENSE_END=========================================================
6005 #-------------------------------------------------------------------------------
6007 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6009 schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long
6011 schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean
6013 schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long
6015 schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long
6017 schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String
6019 schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String
6021 schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long
6023 schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer
6025 schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long
6027 schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long
6029 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6030 This task checks if the sales request is for an item that contains alcohol.
6031 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6032 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6034 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6035 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6036 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6037 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6038 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6039 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6040 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6041 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6042 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6043 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6044 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6045 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6046 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6047 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6048 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6049 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6050 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6051 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6052 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6054 * ============LICENSE_START=======================================================
6055 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6056 * ================================================================================
6057 * Licensed under the Apache License, Version 2.0 (the "License");
6058 * you may not use this file except in compliance with the License.
6059 * You may obtain a copy of the License at
6061 * http://www.apache.org/licenses/LICENSE-2.0
6063 * Unless required by applicable law or agreed to in writing, software
6064 * distributed under the License is distributed on an "AS IS" BASIS,
6065 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6066 * See the License for the specific language governing permissions and
6067 * limitations under the License.
6069 * SPDX-License-Identifier: Apache-2.0
6070 * ============LICENSE_END=========================================================
6072 import java.util.Date;
6073 import java.util.Calendar;
6074 import java.util.TimeZone;
6075 import java.text.SimpleDateFormat;
6077 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6079 outFields.put("amount" , inFields.get("amount"));
6080 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6081 outFields.put("notes" , inFields.get("notes"));
6082 outFields.put("quantity" , inFields.get("quantity"));
6083 outFields.put("branch_ID" , inFields.get("branch_ID"));
6084 outFields.put("item_ID" , inFields.get("item_ID"));
6085 outFields.put("time" , inFields.get("time"));
6086 outFields.put("sale_ID" , inFields.get("sale_ID"));
6088 item_id = inFields.get("item_ID");
6090 //The events used later to test this task use GMT timezone!
6091 gmt = TimeZone.getTimeZone("GMT");
6092 timenow = Calendar.getInstance(gmt);
6093 df = new SimpleDateFormat("HH:mm:ss z");
6094 df.setTimeZone(gmt);
6095 timenow.setTimeInMillis(inFields.get("time"));
6097 midnight = timenow.clone();
6099 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6100 timenow.get(Calendar.DATE),0,0,0);
6101 eleven30 = timenow.clone();
6103 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6104 timenow.get(Calendar.DATE),11,30,0);
6106 itemisalcohol = false;
6107 if(item_id != null && item_id >=1000 && item_id < 2000)
6108 itemisalcohol = true;
6111 && timenow.after(midnight) && timenow.before(eleven30)){
6112 outFields.put("authorised", false);
6113 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6114 " for time "+df.format(timenow.getTime())+
6115 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6116 " and "+df.format(eleven30.getTime()));
6120 outFields.put("authorised", true);
6121 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6122 " for time "+df.format(timenow.getTime()));
6127 This task checks if a sale request is for an item that is an alcoholic drink.
6128 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6129 authorised. Otherwise the sale is authorised.
6130 In this implementation we assume that items with item_ID value between 1000 and
6131 2000 are all alcoholic drinks :-)
6135 event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS"
6136 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6137 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6138 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
6139 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6140 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6141 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6142 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6143 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6144 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6145 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6147 event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX"
6148 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6149 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6150 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6151 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6152 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6153 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6154 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6155 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6158 policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide
6159 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
6160 policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL
6161 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
6168 .. container:: paragraph
6170 *HyperM* have just opened a new branch in a different
6171 country, but that country has different rules about when
6172 alcohol can be sold! In this section we will go through
6173 the necessary steps to extend our policy to enforce this
6176 .. container:: ulist
6178 - In some branches alcohol cannot be sold before 1pm,
6179 and not at all on Sundays.
6181 .. container:: paragraph
6183 Although there are a number of ways to accomplish this
6184 the easiest approach for us is to define another task and
6185 then select which task is appropriate at runtime
6186 depending on the branch identifier in the incoming event.
6188 Extend the Policy with the new Scenario
6189 #######################################
6191 .. container:: paragraph
6193 To create a new Task click on the 'Tasks' tab. In the
6194 'Tasks' pane, right click and select 'Create new Task':
6196 .. container:: paragraph
6198 Create a new Task called ``MorningBoozeCheckAlt1``. Use
6199 the 'Generate UUID' button to create a new unique ID for
6200 the task, and fill in a description for the task. Select
6201 the same input and output fields that we used earlier
6202 when we defined the ``MorningBoozeCheck`` task earlier.
6204 .. table:: Table 12. Input fields for ``MorningBoozeCheckAlt1`` task
6206 +-----------------------------------+-----------------------------------+
6207 | Parameter Name | Parameter Type |
6208 +===================================+===================================+
6209 | time | timestamp_type |
6210 +-----------------------------------+-----------------------------------+
6211 | sale_ID | sale_ID_type |
6212 +-----------------------------------+-----------------------------------+
6213 | amount | price_type |
6214 +-----------------------------------+-----------------------------------+
6215 | item_ID | item_ID_type |
6216 +-----------------------------------+-----------------------------------+
6217 | quantity | quantity_type |
6218 +-----------------------------------+-----------------------------------+
6219 | assistant_ID | assistant_ID_type |
6220 +-----------------------------------+-----------------------------------+
6221 | branch_ID | branch_ID_type |
6222 +-----------------------------------+-----------------------------------+
6223 | notes | notes_type |
6224 +-----------------------------------+-----------------------------------+
6226 .. table:: Table 13. Output fields for ``MorningBoozeCheckAlt1`` task
6228 +-----------------------------------+-----------------------------------+
6229 | Parameter Name | Parameter Type |
6230 +===================================+===================================+
6231 | sale_ID | sale_ID_type |
6232 +-----------------------------------+-----------------------------------+
6233 | time | timestamp_type |
6234 +-----------------------------------+-----------------------------------+
6235 | authorised | authorised_type |
6236 +-----------------------------------+-----------------------------------+
6237 | message | message_type |
6238 +-----------------------------------+-----------------------------------+
6239 | amount | price_type |
6240 +-----------------------------------+-----------------------------------+
6241 | item_ID | item_ID_type |
6242 +-----------------------------------+-----------------------------------+
6243 | assistant_ID | assistant_ID_type |
6244 +-----------------------------------+-----------------------------------+
6245 | quantity | quantity_type |
6246 +-----------------------------------+-----------------------------------+
6247 | branch_ID | branch_ID_type |
6248 +-----------------------------------+-----------------------------------+
6249 | notes | notes_type |
6250 +-----------------------------------+-----------------------------------+
6252 .. container:: paragraph
6254 This task also requires some 'Task Logic' to implement
6255 the new behaviour for this task.
6257 .. container:: paragraph
6259 For simplicity use the following code for the task logic.
6260 It again assumes that all items with ``item_ID`` between
6261 1000 and 2000 contain alcohol. We again use the standard
6262 ``Java`` time utilities to check if the current time is
6263 between ``00:00:00 CET`` and ``13:00:00 CET`` or if it is
6266 .. container:: paragraph
6268 For this task we will again author the logic using the
6269 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__
6270 scripting language. Sample task logic code (specified in
6271 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__) is
6272 given below. For a detailed guide to how to write your
6274 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
6275 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
6276 of the other supported languages please refer to APEX
6279 .. container:: listingblock
6281 .. container:: title
6283 MVEL code for the ``MorningBoozeCheckAlt1`` task
6285 .. container:: content
6290 * ============LICENSE_START=======================================================
6291 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6292 * ================================================================================
6293 * Licensed under the Apache License, Version 2.0 (the "License");
6294 * you may not use this file except in compliance with the License.
6295 * You may obtain a copy of the License at
6297 * http://www.apache.org/licenses/LICENSE-2.0
6299 * Unless required by applicable law or agreed to in writing, software
6300 * distributed under the License is distributed on an "AS IS" BASIS,
6301 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6302 * See the License for the specific language governing permissions and
6303 * limitations under the License.
6305 * SPDX-License-Identifier: Apache-2.0
6306 * ============LICENSE_END=========================================================
6308 import java.util.Date;
6309 import java.util.Calendar;
6310 import java.util.TimeZone;
6311 import java.text.SimpleDateFormat;
6313 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6315 outFields.put("amount" , inFields.get("amount"));
6316 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6317 outFields.put("notes" , inFields.get("notes"));
6318 outFields.put("quantity" , inFields.get("quantity"));
6319 outFields.put("branch_ID" , inFields.get("branch_ID"));
6320 outFields.put("item_ID" , inFields.get("item_ID"));
6321 outFields.put("time" , inFields.get("time"));
6322 outFields.put("sale_ID" , inFields.get("sale_ID"));
6324 item_id = inFields.get("item_ID");
6326 //The events used later to test this task use CET timezone!
6327 cet = TimeZone.getTimeZone("CET");
6328 timenow = Calendar.getInstance(cet);
6329 df = new SimpleDateFormat("HH:mm:ss z");
6330 df.setTimeZone(cet);
6331 timenow.setTimeInMillis(inFields.get("time"));
6333 midnight = timenow.clone();
6335 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6336 timenow.get(Calendar.DATE),0,0,0);
6337 onepm = timenow.clone();
6339 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6340 timenow.get(Calendar.DATE),13,0,0);
6342 itemisalcohol = false;
6343 if(item_id != null && item_id >=1000 && item_id < 2000)
6344 itemisalcohol = true;
6346 if( itemisalcohol &&
6347 ( (timenow.after(midnight) && timenow.before(onepm))
6349 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
6351 outFields.put("authorised", false);
6352 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6353 " for time "+df.format(timenow.getTime())+
6354 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6355 " and "+df.format(onepm.getTime()) +" or on Sunday");
6359 outFields.put("authorised", true);
6360 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6361 " for time "+df.format(timenow.getTime()));
6366 This task checks if a sale request is for an item that is an alcoholic drink.
6367 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6368 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6369 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
6372 .. container:: imageblock
6374 .. container:: content
6376 |Create a new alternative task MorningBoozeCheckAlt1|
6378 .. container:: title
6380 Figure 19. Create a new Task
6382 .. container:: paragraph
6384 The task definition is now complete so click the 'Submit'
6385 button to save the task. Now that we have created our
6386 task, we can can add this task to the single pre-existing
6387 state (``BoozeAuthDecide``) in our policy.
6389 .. container:: paragraph
6391 To edit the ``BoozeAuthDecide`` state in our policy click
6392 on the 'Policies' tab. In the 'Policies' pane, right
6393 click on our ``MyFirstPolicy`` policy and select 'Edit'.
6394 Navigate to the ``BoozeAuthDecide`` state in the 'states'
6395 section at the bottom of the policy definition pane.
6397 .. container:: imageblock
6399 .. container:: content
6401 |Right click to edit a policy|
6403 .. container:: title
6405 Figure 20. Edit a Policy
6407 .. container:: paragraph
6409 To add our new task ``MorningBoozeCheckAlt1``, scroll
6410 down to the ``BoozeAuthDecide`` state in the 'States'
6411 section. In the 'State Tasks' section for
6412 ``BoozeAuthDecide`` use the 'Add new task' button. Select
6413 our new ``MorningBoozeCheckAlt1`` task, and use the name
6414 of the task as the 'Local Name' for the task. The
6415 ``MorningBoozeCheckAlt1`` task can reuse the same
6416 ``MorningBoozeCheck_Output_Direct`` 'Direct State Output
6417 Mapping' that we used for the ``MorningBoozeCheck`` task.
6418 (Recall that the role of the 'State Output Mapping' is to
6419 select the output event for the state, and select the
6420 next state to be executed. These both remain the same as
6423 .. container:: paragraph
6425 Since our state has more than one task we must define
6426 some logic to determine which task should be used each
6427 time the state is executed. This *task selection logic*
6428 is defined in the state definition. For our
6429 ``BoozeAuthDecide`` state we want the choice of which
6430 task to use to be based on the ``branch_ID`` from which
6431 the ``SALE_INPUT`` event originated. For simplicity sake
6432 let us assume that branches with ``branch_ID`` between
6433 ``0`` and ``999`` should use the ``MorningBoozeCheck``
6434 task, and the branches with with ``branch_ID`` between
6435 ``1000`` and ``1999`` should use the
6436 ``MorningBoozeCheckAlt1`` task.
6438 .. container:: paragraph
6440 This time, for variety, we will author the task selection
6442 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__
6443 scripting language. Sample task selection logic code
6445 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__)
6446 is given below. Paste the script text into the 'Task
6447 Selection Logic' box, and use "JAVASCRIPT" as the 'Task
6448 Selection Logic Type / Flavour'. It is necessary to mark
6449 one of the tasks as the 'Default Task' so that the task
6450 selection logic always has a fallback default option in
6451 cases where a particular task cannot be selected. In this
6452 case the ``MorningBoozeCheck`` task can be the default
6455 .. container:: listingblock
6457 .. container:: title
6459 JavaScript code for the ``BoozeAuthDecide`` task
6462 .. container:: content
6467 * ============LICENSE_START=======================================================
6468 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6469 * ================================================================================
6470 * Licensed under the Apache License, Version 2.0 (the "License");
6471 * you may not use this file except in compliance with the License.
6472 * You may obtain a copy of the License at
6474 * http://www.apache.org/licenses/LICENSE-2.0
6476 * Unless required by applicable law or agreed to in writing, software
6477 * distributed under the License is distributed on an "AS IS" BASIS,
6478 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6479 * See the License for the specific language governing permissions and
6480 * limitations under the License.
6482 * SPDX-License-Identifier: Apache-2.0
6483 * ============LICENSE_END=========================================================
6487 var returnValueType = Java.type("java.lang.Boolean");
6488 var returnValue = new returnValueType(true);
6490 executor.logger.info("Task Selection Execution: '"+executor.subject.id+
6491 "'. Input Event: '"+executor.inFields+"'");
6493 branchid = executor.inFields.get("branch_ID");
6494 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
6495 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
6496 taskdef = executor.subject.getDefaultTaskKey();
6498 if(branchid >=0 && branchid <1000){
6499 taskorig.copyTo(executor.selectedTask);
6501 else if (branchid >=1000 && branchid <2000){
6502 taskalt.copyTo(executor.selectedTask);
6505 taskdef.copyTo(executor.selectedTask);
6509 This task selection logic selects task "MorningBoozeCheck" for branches with
6510 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with
6511 1000<=branch_ID<2000. Otherwise the default task is selected.
6512 In this case the default task is also "MorningBoozeCheck"
6515 .. container:: imageblock
6517 .. container:: content
6519 |State definition with 2 Tasks and Task Selection
6522 .. container:: title
6524 Figure 21. State definition with 2 Tasks and Task
6527 .. container:: paragraph
6529 When complete don’t forget to click the 'Submit' button
6530 at the bottom of 'Policies' pane for our
6531 ``MyFirstPolicy`` policy after updating the
6532 ``BoozeAuthDecide`` state.
6534 .. container:: paragraph
6536 Congratulations, you have now completed the second step
6537 towards your first APEX policy. The policy model
6538 containing our new policy can again be validated and
6539 exported from the editor and saved as shown in Step 1.
6541 .. container:: paragraph
6543 The exported policy model is then available in the
6544 directory you selected, as
6545 `MyFirstPolicyModel_0.0.1.json <files/mfp-files/2/MyFirstPolicyModel_0.0.1.json>`__.
6546 The exported policy can now be loaded into the APEX
6547 Policy Engine, or can be re-loaded and edited by the APEX
6553 .. container:: paragraph
6555 To start a new APEX Engine you can use the following
6556 configuration. In a full APEX installation you can find
6557 this configuration in
6558 ``$APEX_HOME/examples/config/MyFirstPolicy/2/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
6559 Note, this has changed from the configuration file in
6560 Step 1 to enable the ``JAVASCRIPT`` executor for our new
6561 'Task Selection Logic'.
6563 .. container:: listingblock
6565 .. container:: title
6567 JSON to load and execute *My First Policy*, read input
6568 JSON events from ``stdin``, and emit output events to
6571 .. container:: content
6576 "engineServiceParameters" : {
6577 "name" : "MyFirstPolicyApexEngine",
6578 "version" : "0.0.1",
6580 "instanceCount" : 4,
6581 "deploymentPort" : 12345,
6582 "policyModelFileName" : "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json",
6583 "engineParameters" : {
6584 "executorParameters" : {
6586 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
6589 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
6594 "eventOutputParameters": {
6596 "carrierTechnologyParameters" : {
6597 "carrierTechnology" : "FILE",
6602 "eventProtocolParameters" : {
6603 "eventProtocol" : "JSON"
6607 "eventInputParameters": {
6609 "carrierTechnologyParameters" : {
6610 "carrierTechnology" : "FILE",
6615 "eventProtocolParameters" : {
6616 "eventProtocol" : "JSON"
6622 .. container:: paragraph
6624 To test the policy try paste the following events into
6625 the console as the APEX engine executes. Note, all tests
6626 from Step 1 will still work perfectly since none of those
6627 events originate from a branch with ``branch_ID`` between
6628 ``1000`` and ``2000``. The 'Task Selection Logic' will
6629 therefore pick the ``MorningBoozeCheck`` task as
6630 expected, and will therefore give the same results.
6632 .. table:: Table 14. Inputs and Outputs when testing *My First Policy*
6634 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6635 | Input Event (JSON) | Output Event (JSON) | comment |
6636 +==============================================+============================================================+===========================+
6637 | .. container:: | .. container:: | Request to buy |
6638 | | | alcohol item |
6639 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1249``) |
6641 | | | at *08:41:06 |
6642 | | .. container:: content | GMT* on *Monday, |
6643 | .. container:: content | | 02 January |
6644 | | .. code:: | 2017*. |
6646 | | { | Sale is not |
6647 | .. code:: | "nameSpace": "com.hyperm", | authorized. Uses |
6648 | | "name": "SALE_AUTH", | the |
6649 | | "version": "0.0.1", | ``MorningBoozeCheck`` |
6650 | { | "source": "", | |
6651 | "nameSpace": "com.hyperm", | "target": "", | task. |
6652 | "name": "SALE_INPUT", | "amount": 1249, | |
6653 | "version": "0.0.1", | "assistant_ID":12, | Note this test |
6654 | "time": 1483346466000, | "authorised": false, | is copied from |
6655 | "sale_ID": 99999992, | "branch_ID": 2, | Step 1 above, |
6656 | "amount": 1249, | "item_ID": 1012, | and demonstrates |
6657 | "item_ID": 1012, | "message": "Sale not authorised by policy ta | that the |
6658 | "quantity": 1, | sk MorningBoozeCheck for time 08:41:06 GMT.| original |
6659 | "assistant_ID": 12, | Alcohol can not be sold between 00:00:00 | ``MorningBoozeCheck`` |
6660 | "branch_ID": 2 | GMT and 11:30:00 GMT", | |
6661 | } | "notes": null, | task is |
6662 | | "quantity": 1, | executed. |
6663 | | "sale_ID": 99999992, | |
6664 | | "time": 1483346466000 | |
6666 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6667 | .. container:: | .. container:: | Request to buy |
6669 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1047``) |
6671 | | | at *10:14:33* on |
6672 | | .. container:: content | *Thursday, 22 |
6673 | .. container:: content | | December 2016*. |
6676 | | { | authorized. Uses |
6677 | .. code:: | "nameSpace" : "com.hyperm", | the |
6678 | | "name" : "SALE_AUTH", | ``MorningBoozeCheckAlt1`` |
6679 | | "version" : "0.0.1", | task. |
6680 | { | "source" : "", | |
6681 | | "target" : "", | |
6682 | "nameSpace": "com.hyperm", | "sale_ID" : 99999981, | |
6683 | "name": "SALE_INPUT", | "amount" : 299, | |
6684 | "version": "0.0.1", | "assistant_ID": 1212, | |
6685 | "time": 1482398073000, | "notes" : null, | |
6686 | "sale_ID": 99999981, | "quantity" : 1, | |
6687 | "amount": 299, | "branch_ID" : 1002, | |
6688 | "item_ID": 1047, | "item_ID" : 1047, | |
6689 | "quantity": 1, | "authorised" : false, | |
6690 | "assistant_ID": 1212, | "time" : 1482398073000, | |
6691 | "branch_ID": 1002 | "message" : "Sale not authorised by policy t | |
6692 | } | ask MorningBoozeCheckAlt1 fortime | |
6693 | | 10:14:33 CET. Alcohol can not be sold | |
6694 | | between 00:00:00 CET and 13:00:00 CET or on | |
6697 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6698 | .. container:: | .. container:: | Request to buy |
6700 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1443``) |
6702 | | | at *17:19:37* on |
6703 | | .. container:: content | *Sunday, 18 |
6704 | .. container:: content | | December 2016*. |
6707 | | { | authorized. Uses |
6708 | .. code:: | "nameSpace" : "com.hyperm", | the |
6709 | | | ``MorningBoozeCheckAlt1`` |
6710 | | "name" : "SALE_AUTH", | task. |
6712 | "nameSpace": "com.hyperm", | "version" : "0.0.1", | |
6713 | "name": "SALE_INPUT", | "source" : "", | |
6714 | "version": "0.0.1", | "target" : "", | |
6715 | "time": 1482077977000, | "sale_ID" : 99999982, | |
6716 | "sale_ID": 99999982, | "amount" : 2199, | |
6717 | "amount": 2199, | "assistant_ID" : 94, | |
6718 | "item_ID": 1443, | "notes" : "Buy 3, get 1 free!!", | |
6719 | "quantity": 12, | "quantity" : 12, | |
6720 | "assistant_ID": 94, | "branch_ID" : 1003, | |
6721 | "branch_ID": 1003, | "item_ID" : 1443, | |
6722 | "notes": "Buy 3, get 1 free!!" | "authorised" : false, | |
6723 | } | "time" : 1482077977000, | |
6724 | | "message" : "Sale not authorised by policy t | |
6725 | | ask MorningBoozeCheckAlt1 for | |
6726 | | time 17:19:37 CET. Alcohol c | |
6727 | | an not be sold between 00:00: | |
6728 | | 00 CET and 13:00:00 CET or on | |
6730 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6731 | .. container:: | .. container:: | Request to buy |
6732 | | | non-alcoholic |
6733 | .. container:: listingblock | .. container:: listingblock | item |
6734 | | | (``item_ID=5321``) |
6736 | | .. container:: content | at *11:13:09* on |
6737 | .. container:: content | | *Monday, 2 |
6738 | | .. code:: | January 2017*. |
6741 | .. code:: | "nameSpace" : "com.hyperm", | authorized. Uses |
6742 | | "name" : "SALE_AUTH", | the |
6743 | { | "version" : "0.0.1", | ``MorningBoozeCheckAlt1`` |
6744 | "nameSpace": "com.hyperm", | "source" : "", | task. |
6745 | "name": "SALE_INPUT", | "target" : "", | |
6746 | "version": "0.0.1", | "sale_ID" : 99999983, | |
6747 | "time": 1483351989000, | "amount" : 699, | |
6748 | "sale_ID": 99999983, | "assistant_ID" : 2323, | |
6749 | "amount": 699, | "notes" : "", | |
6750 | "item_ID": 5321, | "quantity" : 1, | |
6751 | "quantity": 1, | "branch_ID" : 1001, | |
6752 | "assistant_ID": 2323, | "item_ID" : 5321, | |
6753 | "branch_ID": 1001, | "authorised" : true, | |
6754 | "notes": "" | "time" : 1483351989000, | |
6755 | } | "message" : "Sale authorised by policy task | |
6756 | | MorningBoozeCheckAlt1 for time 11:13:09 CET"| |
6758 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6760 Policy 2 in CLI Editor
6761 ######################
6763 .. container:: paragraph
6765 An equivalent version of the ``MyFirstPolicyModel``
6766 policy model can again be generated using the APEX CLI
6767 editor. A sample APEX CLI script is shown below:
6769 .. container:: listingblock
6771 .. container:: title
6773 APEX CLI Editor code for Policy 2
6775 .. container:: content
6779 #-------------------------------------------------------------------------------
6780 # ============LICENSE_START=======================================================
6781 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
6782 # ================================================================================
6783 # Licensed under the Apache License, Version 2.0 (the "License");
6784 # you may not use this file except in compliance with the License.
6785 # You may obtain a copy of the License at
6787 # http://www.apache.org/licenses/LICENSE-2.0
6789 # Unless required by applicable law or agreed to in writing, software
6790 # distributed under the License is distributed on an "AS IS" BASIS,
6791 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6792 # See the License for the specific language governing permissions and
6793 # limitations under the License.
6795 # SPDX-License-Identifier: Apache-2.0
6796 # ============LICENSE_END=========================================================
6797 #-------------------------------------------------------------------------------
6799 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6801 schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long
6803 schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean
6805 schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long
6807 schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long
6809 schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String
6811 schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String
6813 schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long
6815 schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer
6817 schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long
6819 schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long
6821 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6822 This task checks if the sales request is for an item that contains alcohol.
6823 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6824 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6826 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6827 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6828 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6829 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6830 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6831 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6832 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6833 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6834 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6835 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6836 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6837 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6838 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6839 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6840 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6841 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6842 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6843 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6844 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6846 * ============LICENSE_START=======================================================
6847 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6848 * ================================================================================
6849 * Licensed under the Apache License, Version 2.0 (the "License");
6850 * you may not use this file except in compliance with the License.
6851 * You may obtain a copy of the License at
6853 * http://www.apache.org/licenses/LICENSE-2.0
6855 * Unless required by applicable law or agreed to in writing, software
6856 * distributed under the License is distributed on an "AS IS" BASIS,
6857 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6858 * See the License for the specific language governing permissions and
6859 * limitations under the License.
6861 * SPDX-License-Identifier: Apache-2.0
6862 * ============LICENSE_END=========================================================
6864 import java.util.Date;
6865 import java.util.Calendar;
6866 import java.util.TimeZone;
6867 import java.text.SimpleDateFormat;
6869 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6871 outFields.put("amount" , inFields.get("amount"));
6872 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6873 outFields.put("notes" , inFields.get("notes"));
6874 outFields.put("quantity" , inFields.get("quantity"));
6875 outFields.put("branch_ID" , inFields.get("branch_ID"));
6876 outFields.put("item_ID" , inFields.get("item_ID"));
6877 outFields.put("time" , inFields.get("time"));
6878 outFields.put("sale_ID" , inFields.get("sale_ID"));
6880 item_id = inFields.get("item_ID");
6882 //The events used later to test this task use GMT timezone!
6883 gmt = TimeZone.getTimeZone("GMT");
6884 timenow = Calendar.getInstance(gmt);
6885 df = new SimpleDateFormat("HH:mm:ss z");
6886 df.setTimeZone(gmt);
6887 timenow.setTimeInMillis(inFields.get("time"));
6889 midnight = timenow.clone();
6891 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6892 timenow.get(Calendar.DATE),0,0,0);
6893 eleven30 = timenow.clone();
6895 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6896 timenow.get(Calendar.DATE),11,30,0);
6898 itemisalcohol = false;
6899 if(item_id != null && item_id >=1000 && item_id < 2000)
6900 itemisalcohol = true;
6903 && timenow.after(midnight) && timenow.before(eleven30)){
6904 outFields.put("authorised", false);
6905 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6906 " for time "+df.format(timenow.getTime())+
6907 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6908 " and "+df.format(eleven30.getTime()));
6912 outFields.put("authorised", true);
6913 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6914 " for time "+df.format(timenow.getTime()));
6919 This task checks if a sale request is for an item that is an alcoholic drink.
6920 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6921 authorised. Otherwise the sale is authorised.
6922 In this implementation we assume that items with item_ID value between 1000 and
6923 2000 are all alcoholic drinks :-)
6927 task create name=MorningBoozeCheckAlt1 version=0.0.1 uuid=bc6d90c9-c902-4686-afd3-925b30e39990 description=LS
6928 This task checks if a sale request is for an item that is an alcoholic drink.
6929 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6930 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6931 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks
6933 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6934 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6935 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6936 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6937 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6938 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6939 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6940 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6941 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6942 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6943 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6944 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6945 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6946 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6947 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6948 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6949 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6950 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6951 task logic create name=MorningBoozeCheckAlt1 version=0.0.1 logicFlavour=MVEL logic=LS
6953 * ============LICENSE_START=======================================================
6954 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6955 * ================================================================================
6956 * Licensed under the Apache License, Version 2.0 (the "License");
6957 * you may not use this file except in compliance with the License.
6958 * You may obtain a copy of the License at
6960 * http://www.apache.org/licenses/LICENSE-2.0
6962 * Unless required by applicable law or agreed to in writing, software
6963 * distributed under the License is distributed on an "AS IS" BASIS,
6964 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6965 * See the License for the specific language governing permissions and
6966 * limitations under the License.
6968 * SPDX-License-Identifier: Apache-2.0
6969 * ============LICENSE_END=========================================================
6971 import java.util.Date;
6972 import java.util.Calendar;
6973 import java.util.TimeZone;
6974 import java.text.SimpleDateFormat;
6976 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6978 outFields.put("amount" , inFields.get("amount"));
6979 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6980 outFields.put("notes" , inFields.get("notes"));
6981 outFields.put("quantity" , inFields.get("quantity"));
6982 outFields.put("branch_ID" , inFields.get("branch_ID"));
6983 outFields.put("item_ID" , inFields.get("item_ID"));
6984 outFields.put("time" , inFields.get("time"));
6985 outFields.put("sale_ID" , inFields.get("sale_ID"));
6987 item_id = inFields.get("item_ID");
6989 //The events used later to test this task use CET timezone!
6990 cet = TimeZone.getTimeZone("CET");
6991 timenow = Calendar.getInstance(cet);
6992 df = new SimpleDateFormat("HH:mm:ss z");
6993 df.setTimeZone(cet);
6994 timenow.setTimeInMillis(inFields.get("time"));
6996 midnight = timenow.clone();
6998 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6999 timenow.get(Calendar.DATE),0,0,0);
7000 onepm = timenow.clone();
7002 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7003 timenow.get(Calendar.DATE),13,0,0);
7005 itemisalcohol = false;
7006 if(item_id != null && item_id >=1000 && item_id < 2000)
7007 itemisalcohol = true;
7009 if( itemisalcohol &&
7010 ( (timenow.after(midnight) && timenow.before(onepm))
7012 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
7014 outFields.put("authorised", false);
7015 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
7016 " for time "+df.format(timenow.getTime())+
7017 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
7018 " and "+df.format(onepm.getTime()) +" or on Sunday");
7022 outFields.put("authorised", true);
7023 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
7024 " for time "+df.format(timenow.getTime()));
7029 This task checks if a sale request is for an item that is an alcoholic drink.
7030 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
7031 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
7032 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
7036 event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS"
7037 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7038 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7039 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
7040 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7041 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7042 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
7043 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7044 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7045 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7046 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7048 event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX"
7049 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7050 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7051 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7052 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7053 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7054 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7055 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7056 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7059 policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide
7060 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
7061 policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL
7062 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheckAlt1 taskName=MorningBoozeCheckAlt1 taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
7063 policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
7064 policy state selecttasklogic create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide logicFlavour=JAVASCRIPT logic=LS
7066 * ============LICENSE_START=======================================================
7067 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
7068 * ================================================================================
7069 * Licensed under the Apache License, Version 2.0 (the "License");
7070 * you may not use this file except in compliance with the License.
7071 * You may obtain a copy of the License at
7073 * http://www.apache.org/licenses/LICENSE-2.0
7075 * Unless required by applicable law or agreed to in writing, software
7076 * distributed under the License is distributed on an "AS IS" BASIS,
7077 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7078 * See the License for the specific language governing permissions and
7079 * limitations under the License.
7081 * SPDX-License-Identifier: Apache-2.0
7082 * ============LICENSE_END=========================================================
7085 var returnValueType = Java.type("java.lang.Boolean");
7086 var returnValue = new returnValueType(true);
7088 executor.logger.info("Task Selection Execution: '"+executor.subject.id+"'. Input Event: '"+executor.inFields+"'");
7090 branchid = executor.inFields.get("branch_ID");
7091 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
7092 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
7093 taskdef = executor.subject.getDefaultTaskKey();
7095 if(branchid >=0 && branchid <1000){
7096 taskorig.copyTo(executor.selectedTask);
7098 else if (branchid >=1000 && branchid <2000){
7099 taskalt.copyTo(executor.selectedTask);
7102 taskdef.copyTo(executor.selectedTask);
7106 This task selection logic selects task "MorningBoozeCheck" for branches with 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with 1000<=branch_ID<2000. Otherwise the default task is selected. In this case the default task is also "MorningBoozeCheck"
7113 Introduction to APEX Logging
7114 ----------------------------
7116 .. container:: paragraph
7118 All APEX components make extensive use of logging using the
7119 logging façade `SLF4J <https://www.slf4j.org/>`__ with the
7120 backend `Logback <https://logback.qos.ch/>`__. Both are used
7121 off-the-shelve, so the standard documentation and
7122 configuration apply to APEX logging. For details on how to
7123 work with logback please see the `logback
7124 manual <https://logback.qos.ch/manual/index.html>`__.
7126 .. container:: paragraph
7128 The APEX applications is the logback configuration file
7129 ``$APEX_HOME/etc/logback.xml`` (Windows:
7130 ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
7131 to no debug, i.e. logs from the logging framework should be
7134 .. container:: paragraph
7136 The configurable log levels work as expected:
7138 .. container:: ulist
7140 - *error* (or *ERROR*) is used for serious errors in the
7143 - *warn* (or *WARN*) is used for warnings, which in general
7144 can be ignored but might indicate some deeper problems
7146 - *info* (or *INFO*) is used to provide generally
7147 interesting messages for startup and policy execution
7149 - *debug* (or *DEBUG*) provides more details on startup and
7152 - *trace* (or *TRACE*) gives full details on every aspect
7153 of the APEX engine from start to end
7155 .. container:: paragraph
7157 The loggers can also be configured as expected. The standard
7158 configuration (after installing APEX) uses log level *info*
7159 on all APEX classes (components).
7161 .. container:: paragraph
7163 The applications and scripts in ``$APEX_HOME/bin`` (Windows:
7164 ``%APEX_HOME\bin``) are configured to use the logback
7165 configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
7166 ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
7167 use different logback configurations, for instance:
7169 .. container:: ulist
7171 - Maintain multiple configurations in ``etc``, for instance
7172 a ``logback-debug.xml`` for deep debugging and a
7173 ``logback-production.xml`` for APEX in production mode,
7174 then copy the required configuration file to the used
7175 ``logback.xml`` prior starting APEX
7177 - Edit the scripts in ``bin`` to use a different logback
7178 configuration file (only recommended if you are familiar
7179 with editing bash scripts or windows batch files)
7181 Standard Logging Configuration
7182 ------------------------------
7184 .. container:: paragraph
7186 The standard logging configuration defines a context *APEX*,
7187 which is used in the standard output pattern. The location
7188 for log files is defined in the property ``VAR_LOG`` and set
7189 to ``/var/log/onap/policy/apex-pdp``. The standard status
7190 listener is set to *NOP* and the overall logback
7191 configuration is set to no debug.
7193 .. container:: listingblock
7195 .. container:: content
7200 <configuration debug="false">
7201 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7203 <contextName>Apex</contextName>
7204 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7210 .. container:: paragraph
7212 The first appender defined is called ``STDOUT`` for logs to standard
7215 .. container:: listingblock
7217 .. container:: content
7222 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7224 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7228 .. container:: paragraph
7230 The root level logger then is set to the level *info* using the
7231 standard out appender.
7233 .. container:: listingblock
7235 .. container:: content
7241 <appender-ref ref="STDOUT" />
7244 .. container:: paragraph
7246 The second appender is called ``FILE``. It writes logs to a file
7249 .. container:: listingblock
7251 .. container:: content
7256 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7257 <file>${VAR_LOG}/apex.log</file>
7259 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7263 .. container:: paragraph
7265 The third appender is called ``CTXT_FILE``. It writes logs to a file
7268 .. container:: listingblock
7270 .. container:: content
7275 <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
7276 <file>${VAR_LOG}/apex_ctxt.log</file>
7278 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7282 .. container:: paragraph
7284 The last definitions are for specific loggers. The first logger
7285 captures all standard APEX classes. It is configured for log level
7286 *info* and uses the standard output and file appenders. The second
7287 logger captures APEX context classes responsible for context
7288 monitoring. It is configured for log level *trace* and uses the
7289 context file appender.
7291 .. container:: listingblock
7293 .. container:: content
7299 <logger name="org.onap.policy.apex" level="info" additivity="false">
7300 <appender-ref ref="STDOUT" />
7301 <appender-ref ref="FILE" />
7304 <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
7305 <appender-ref ref="CTXT_FILE" />
7308 Adding Logback Status and Debug
7309 -------------------------------
7311 .. container:: paragraph
7313 To activate logback status messages change the status listener
7314 from 'NOP' to for instance console.
7316 .. container:: listingblock
7318 .. container:: content
7322 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
7324 .. container:: paragraph
7326 To activate all logback debugging, for instance to debug a new
7327 logback configuration, activate the debug attribute in the
7330 .. container:: listingblock
7332 .. container:: content
7336 <configuration debug="true">
7340 Logging External Components
7341 ---------------------------
7343 .. container:: paragraph
7345 Logback can also be configured to log any other, external
7346 components APEX is using, if they are using the common logging
7349 .. container:: paragraph
7351 For instance, the context component of APEX is using *Infinispan*
7352 and one can add a logger for this external component. The
7353 following example adds a logger for *Infinispan* using the
7354 standard output appender.
7356 .. container:: listingblock
7358 .. container:: content
7362 <logger name="org.infinispan" level="INFO" additivity="false">
7363 <appender-ref ref="STDOUT" />
7366 .. container:: paragraph
7368 Another example is Apache Zookeeper. The following example adds a
7369 logger for Zookeeper using the standard outout appender.
7371 .. container:: listingblock
7373 .. container:: content
7377 <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
7378 <appender-ref ref="STDOUT" />
7381 Configuring loggers for Policy Logic
7382 ------------------------------------
7384 .. container:: paragraph
7386 The logging for the logic inside a policy (task logic, task
7387 selection logic, state finalizer logic) can be configured separate
7388 from standard logging. The logger for policy logic is
7389 ``org.onap.policy.apex.executionlogging``. The following example
7392 .. container:: ulist
7394 - a new appender for standard out using a very simple pattern
7395 (simply the actual message)
7397 - a logger for policy logic to standard out using the new
7398 appender and the already described file appender.
7400 .. container:: listingblock
7402 .. container:: content
7406 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7408 <pattern>policy: %msg\n</pattern>
7412 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7413 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7414 <appender-ref ref="FILE" />
7417 .. container:: paragraph
7419 It is also possible to use specific logging for parts of policy
7420 logic. The following example defines a logger for task logic.
7422 .. container:: listingblock
7424 .. container:: content
7428 <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
7429 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7432 Rolling File Appenders
7433 ----------------------
7435 .. container:: paragraph
7437 Rolling file appenders are a good option for more complex logging
7438 of a production or complex testing APEX installation. The standard
7439 logback configuration can be used for these use cases. This
7440 section gives two examples for the standard logging and for
7443 .. container:: paragraph
7445 First the standard logging. The following example defines a
7446 rolling file appender. The appender rolls over on a daily basis.
7447 It allows for a file size of 100 MB.
7449 .. container:: listingblock
7451 .. container:: content
7455 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
7456 <file>${VAR_LOG}/apex.log</file>
7457 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7458 <!-- rollover daily -->
7459 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
7460 <fileNamePattern>${VAR_LOG}/apex_%d{yyyy-MM-dd}.%i.log.gz
7462 <maxHistory>4</maxHistory>
7463 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7464 <!-- or whenever the file size reaches 100MB -->
7465 <maxFileSize>100MB</maxFileSize>
7466 </timeBasedFileNamingAndTriggeringPolicy>
7470 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7475 .. container:: paragraph
7477 A very similar configuration can be used for a rolling file
7478 appender logging APEX context.
7480 .. container:: listingblock
7482 .. container:: content
7486 <appender name="CTXT-FILE"
7487 class="ch.qos.logback.core.rolling.RollingFileAppender">
7488 <file>${VAR_LOG}/apex_ctxt.log</file>
7489 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7490 <fileNamePattern>${VAR_LOG}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
7492 <maxHistory>4</maxHistory>
7493 <timeBasedFileNamingAndTriggeringPolicy
7494 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7495 <maxFileSize>100MB</maxFileSize>
7496 </timeBasedFileNamingAndTriggeringPolicy>
7500 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7505 Example Configuration for Logging Logic
7506 ---------------------------------------
7508 .. container:: paragraph
7510 The following example shows a configuration that logs policy logic
7511 to standard out and a file (*info*). All other APEX components are
7512 logging to a file (*debug*).. This configuration an be used in a
7513 pre-production phase with the APEX engine still running in a
7514 separate terminal to monitor policy execution. This logback
7515 configuration is in the APEX installation as
7516 ``etc/logback-logic.xml``.
7518 .. container:: listingblock
7520 .. container:: content
7524 <configuration debug="false">
7525 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7527 <contextName>Apex</contextName>
7528 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7530 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7532 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7536 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7537 <file>${VAR_LOG}/apex.log</file>
7540 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7545 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7547 <pattern>policy: %msg\n</pattern>
7551 <root level="error">
7552 <appender-ref ref="STDOUT" />
7555 <logger name="org.onap.policy.apex" level="debug" additivity="false">
7556 <appender-ref ref="FILE" />
7559 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7560 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7561 <appender-ref ref="FILE" />
7565 Example Configuration for a Production Server
7566 ---------------------------------------------
7568 .. container:: paragraph
7570 The following example shows a configuration that logs all APEX
7571 components, including policy logic, to a file (*debug*). This
7572 configuration an be used in a production phase with the APEX
7573 engine being executed as a service on a system without console
7574 output. This logback configuration is in the APEX installation as
7575 ``logback-server.xml``
7577 .. container:: listingblock
7579 .. container:: content
7583 <configuration debug="false">
7584 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7586 <contextName>Apex</contextName>
7587 <property name="VAR_LOG" value="/var/log/onap/policy/apex-pdp/" />
7589 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7590 <file>${VAR_LOG}/apex.log</file>
7593 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7598 <root level="debug">
7599 <appender-ref ref="FILE" />
7602 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
7603 <appender-ref ref="FILE" />
7607 Building a System with Websocket Backend
7608 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7613 .. container:: paragraph
7615 Websocket is a protocol to run sockets of HTTP. Since it in
7616 essence a socket, the connection is realized between a
7617 server (waiting for connections) and a client (connecting to
7618 a server). Server/client separation is only important for
7619 connection establishment, once connected, everyone can
7620 send/receive on the same socket (as any standard socket
7623 .. container:: paragraph
7625 Standard Websocket implementations are simple, no
7626 publish/subscribe and no special event handling. Most
7627 servers simply send all incoming messages to all
7628 connections. There is a PubSub definition on top of
7629 Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
7630 does not support WAMP at the moment.
7635 .. container:: paragraph
7638 356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7639 defines the standard Websocket API. This JSR is part of Jave
7640 EE 7 standard. For Java SE, several implementations exist in
7641 open source. Since Websockets are a stable standard and
7642 simple, most implementations are stable and ready to use. A
7643 lot of products support Websockets, like Spring, JBoss,
7644 Netty, … there are also Kafka extensions for Websockets.
7646 Websocket Example Code for Websocket clients (FOSS)
7647 ---------------------------------------------------
7649 .. container:: paragraph
7651 There are a lot of implementations and examples available on
7652 Github for Websocket clients. If one is using Java EE 7,
7653 then one can also use the native Websocket implementation.
7654 Good examples for clients using simply Java SE are here:
7656 .. container:: ulist
7659 implementation <https://github.com/TooTallNate/Java-WebSocket>`__
7661 - `Websocket sending client example, using
7662 AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
7664 - `Websocket receiving client example (simple echo
7665 client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
7667 .. container:: paragraph
7669 For Java EE, the native Websocket API is explained here:
7671 .. container:: ulist
7674 docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7677 example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
7679 BCP: Websocket Configuration
7680 ----------------------------
7682 .. container:: paragraph
7684 The probably best is to configure APEX for Websocket servers
7685 for input (ingress, consume) and output (egress, produce)
7686 interfaces. This means that APEX will start Websocket
7687 servers on named ports and wait for clients to connect.
7688 Advantage: once APEX is running all connectivity
7689 infrastructure is running as well. Consequence: if APEX is
7690 not running, everyone else is in the dark, too.
7692 .. container:: paragraph
7694 The best protocol to be used is JSON string. Each event on
7695 any interface is then a string with a JSON encoding. JSON
7696 string is a little bit slower than byte code, but we doubt
7697 that this will be noticeable. A further advantage of JSON
7698 strings over Websockets with APEX starting the servers: it
7699 is very easy to connect web browsers to such a system.
7700 Simple connect the web browser to the APEX sockets and
7701 send/read JSON strings.
7703 .. container:: paragraph
7705 Once APEX is started you simply connect Websocket clients to
7706 it, and send/receive event. When APEX is terminated, the
7707 Websocket servers go down, and the clients will be
7708 disconnected. APEX does not (yet) support auto-client
7709 reconnect nor WAMP, so clients might need to be restarted or
7710 reconnected manually after an APEX boot.
7712 Demo with VPN Policy Model
7713 --------------------------
7715 .. container:: paragraph
7717 We assume that you have an APEX installation using the full
7718 package, i.e. APEX with all examples, of version ``0.5.6``
7719 or higher. We will use the VPN policy from the APEX examples
7722 .. container:: paragraph
7724 Now, have the following ready to start the demo:
7726 .. container:: ulist
7728 - 3 terminals on the host where APEX is running (we need 1
7729 for APEX and 1 for each client)
7731 - the events in the file
7732 ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
7733 in an editor (we need to send those events to APEX)
7735 - the events in the file
7736 ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
7737 in an editor (we need to send those events to APEX)
7739 A Websocket Configuration for the VPN Domain
7740 ############################################
7742 .. container:: paragraph
7744 Create a new APEX configuration using the VPN policy
7745 model and configuring APEX as discussed above for
7746 Websockets. Copy the following configuration into
7747 ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
7749 ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
7751 .. container:: listingblock
7753 .. container:: content
7759 "engineServiceParameters" : {
7760 "name" : "VPNApexEngine",
7761 "version" : "0.0.1",
7763 "instanceCount" : 1,
7764 "deploymentPort" : 12345,
7765 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
7766 "engineParameters" : {
7767 "executorParameters" : {
7769 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
7772 "contextParameters" : {
7773 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
7774 "schemaParameters":{
7776 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
7782 "producerCarrierTechnologyParameters" : {
7783 "carrierTechnology" : "WEBSOCKET",
7784 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7790 "producerEventProtocolParameters" : {
7791 "eventProtocol" : "JSON"
7793 "consumerCarrierTechnologyParameters" : {
7794 "carrierTechnology" : "WEBSOCKET",
7795 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7801 "consumerEventProtocolParameters" : {
7802 "eventProtocol" : "JSON"
7809 .. container:: paragraph
7811 In a new terminal, start APEX with the new configuration for
7812 Websocket-Server ingress/egress:
7814 .. container:: listingblock
7816 .. container:: content
7821 #: $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
7823 .. container:: listingblock
7825 .. container:: content
7830 #: %APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
7832 .. container:: paragraph
7834 Wait for APEX to start, it takes a while to create all Websocket
7835 servers (about 8 seconds on a standard laptop without cached
7836 binaries). depending on your log messages, you will see no (some, a
7837 lot) log messages. If APEX starts correctly, the last few messages
7840 .. container:: listingblock
7842 .. container:: content
7847 2017-07-28 13:17:20,834 Apex [main] INFO c.e.a.s.engine.runtime.EngineService - engine model VPNPolicyModelAvro:0.0.1 added to the engine-AxArtifactKey:(name=VPNApexEngine-0,version=0.0.1)
7848 2017-07-28 13:17:21,057 Apex [Apex-apex-engine-service-0:0] INFO c.e.a.s.engine.runtime.EngineService - Engine AxArtifactKey:(name=VPNApexEngine-0,version=0.0.1) processing ...
7849 2017-07-28 13:17:21,296 Apex [main] INFO c.e.a.s.e.r.impl.EngineServiceImpl - Added the action listener to the engine
7850 Started Apex service
7852 .. container:: paragraph
7854 APEX is running in the new terminal and will produce output when the
7855 policy is triggered/executed.
7857 Run the Websocket Echo Client
7858 #############################
7860 .. container:: paragraph
7862 The echo client is included in an APEX full installation. To run
7863 the client, open a new shell (Unix, Cygwin) or command prompt
7864 (``cmd`` on Windows). Then use the APEX application launcher to
7868 APEX engine needs to run first
7869 The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
7871 +---------------------------------------------------------+-----------------------------------------------------------+
7872 | Unix, Cygwin | Windows |
7873 +=========================================================+===========================================================+
7874 | .. container:: | .. container:: |
7876 | .. container:: listingblock | .. container:: listingblock |
7878 | .. container:: content | .. container:: content |
7880 | .. code:: | .. code:: |
7882 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
7883 +---------------------------------------------------------+-----------------------------------------------------------+
7885 .. container:: paragraph
7887 Use the following command line arguments for server and port of
7888 the Websocket server. The port should be the same as configured in
7889 the APEX engine. The server host should be the host on which the
7890 APEX engine is running
7892 .. container:: ulist
7894 - ``-p`` defines the Websocket port to connect to (defaults to
7897 - ``-s`` defines the host on which a Websocket server is running
7898 (defaults to ``localhost``)
7900 .. container:: paragraph
7902 Let’s assume that there is an APEX engine running, configured for
7903 produce Websocket carrier technology, as server, for port 42452,
7904 with produce event protocol JSON,. If we start the console client
7905 on the same host, we can omit the ``-s`` options. We start the
7908 .. container:: listingblock
7910 .. container:: content
7914 # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
7915 > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
7917 .. container:: colist arabic
7919 +-------+--------------------------------+
7920 | **1** | Start client on Unix or Cygwin |
7921 +-------+--------------------------------+
7922 | **2** | Start client on Windows |
7923 +-------+--------------------------------+
7925 .. container:: paragraph
7927 Once started successfully, the client will produce the following
7928 messages (assuming we used ``-p 42452`` and an APEX engine is
7929 running on ``localhost`` with the same port:
7931 .. container:: listingblock
7933 .. container:: content
7937 ws-simple-echo: starting simple event echo
7938 --> server: localhost
7941 Once started, the application will simply print out all received events to standard out.
7942 Each received event will be prefixed by '---' and suffixed by '===='
7945 ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
7947 Run the Websocket Console Client
7948 ################################
7950 .. container:: paragraph
7952 The console client is included in an APEX full installation. To
7953 run the client, open a new shell (Unix, Cygwin) or command prompt
7954 (``cmd`` on Windows). Then use the APEX application launcher to
7958 APEX engine needs to run first
7959 The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
7960 protocol is executed first.
7962 +------------------------------------------------------------+--------------------------------------------------------------+
7963 | Unix, Cygwin | Windows |
7964 +============================================================+==============================================================+
7965 | .. container:: | .. container:: |
7967 | .. container:: listingblock | .. container:: listingblock |
7969 | .. container:: content | .. container:: content |
7971 | .. code:: | .. code:: |
7973 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
7974 +------------------------------------------------------------+--------------------------------------------------------------+
7976 .. container:: paragraph
7978 Use the following command line arguments for server and port of
7979 the Websocket server. The port should be the same as configured in
7980 the APEX engine. The server host should be the host on which the
7981 APEX engine is running
7983 .. container:: ulist
7985 - ``-p`` defines the Websocket port to connect to (defaults to
7988 - ``-s`` defines the host on which a Websocket server is running
7989 (defaults to ``localhost``)
7991 .. container:: paragraph
7993 Let’s assume that there is an APEX engine running, configured for
7994 consume Websocket carrier technology, as server, for port 42450,
7995 with consume event protocol JSON,. If we start the console client
7996 on the same host, we can omit the ``-s`` options. We start the
7999 .. container:: listingblock
8001 .. container:: content
8005 # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
8006 > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
8008 .. container:: colist arabic
8010 +-------+--------------------------------+
8011 | **1** | Start client on Unix or Cygwin |
8012 +-------+--------------------------------+
8013 | **2** | Start client on Windows |
8014 +-------+--------------------------------+
8016 .. container:: paragraph
8018 Once started successfully, the client will produce the following
8019 messages (assuming we used ``-p 42450`` and an APEX engine is
8020 running on ``localhost`` with the same port:
8022 .. container:: listingblock
8024 .. container:: content
8028 ws-simple-console: starting simple event console
8029 --> server: localhost
8032 - terminate the application typing 'exit<enter>' or using 'CTRL+C'
8033 - events are created by a non-blank starting line and terminated by a blank line
8036 ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
8041 .. container:: paragraph
8043 Now you have the full system up and running:
8045 .. container:: ulist
8047 - Terminal 1: APEX ready and loaded
8049 - Terminal 2: an echo client, printing received messages produced
8052 - Terminal 2: a console client, waiting for input on the console
8053 (standard in) and sending text to APEX
8055 .. container:: paragraph
8057 We started the engine with the VPN policy example. So all the
8058 events we are using now are located in files in the following
8061 .. container:: listingblock
8063 .. container:: content
8068 #: $APEX_HOME/examples/events/VPN
8069 > %APEX_HOME%\examples\events\VPN
8071 .. container:: paragraph
8073 To sends events, simply copy the content of the event files into
8074 Terminal 3 (the console client). It will read multi-line JSON text
8075 and send the events. So copy the content of ``SetupEvents.json`` into
8076 the client. APEX will trigger a policy and produce some output, the
8077 echo client will also print some events created in the policy. In
8078 Terminal 1 (APEX) you’ll see some status messages from the policy as:
8080 .. container:: listingblock
8082 .. container:: content
8087 {Link=L09, LinkUp=true}
8089 outFields: {Link=L09, LinkUp=true}
8090 {Link=L10, LinkUp=true}
8093 outFields: {Link=L10, LinkUp=true}
8094 {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8096 C 300 300 [L09, L10]
8097 outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8098 {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8101 C 300 300 [L09, L10]
8102 outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8103 {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8106 C 300 300 [L09, L10]
8107 D 300 400 [L09, L10]
8108 outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8109 {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8112 B 300 299 [L09, L10]
8113 C 300 300 [L09, L10]
8114 D 300 400 [L09, L10]
8115 outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8117 .. container:: paragraph
8119 In Terminal 2 (echo-client) you see the received events, the last two
8122 .. container:: listingblock
8124 .. container:: content
8129 ws-simple-echo: received
8130 ---------------------------------
8132 "name": "VPNCustomerCtxtActEvent",
8134 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8137 "CustomerName": "C",
8138 "LinkList": "L09 L10",
8142 =================================
8144 ws-simple-echo: received
8145 ---------------------------------
8147 "name": "VPNCustomerCtxtActEvent",
8149 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8152 "CustomerName": "D",
8153 "LinkList": "L09 L10",
8157 =================================
8159 .. container:: paragraph
8161 Congratulations, you have triggered a policy in APEX using
8162 Websockets, the policy did run through, created events, picked up by
8165 .. container:: paragraph
8167 Now you can send the Link 09 and Link 10 events, they will trigger
8168 the actual VPN policy and some calculations are made. Let’s take the
8169 Link 09 events from ``Link09Events.json``, copy them all into
8170 Terminal 3 (the console). APEX will run the policy (with some status
8171 output), and the echo client will receive and print events.
8173 .. container:: paragraph
8175 To terminate the applications, simply press ``CTRL+C`` in Terminal 1
8176 (APEX). This will also terminate the echo-client in Terminal 2. Then
8177 type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
8187 Last updated 2018-09-10 15:38:16 IST
8189 .. |Extract the TAR archive| image:: images/install-guide/win-extract-tar-gz.png
8190 .. |Extract the APEX distribution| image:: images/install-guide/win-extract-tar.png
8191 .. |REST Editor Start Screen| image:: images/install-guide/rest-start.png
8192 .. |REST Editor with loaded SampleDomain Policy Model| image:: images/install-guide/rest-loaded.png
8193 .. |APEX Configuration Matrix| image:: images/apex-intro/ApexEngineConfig.png
8194 .. |File > New to create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel1.png
8195 .. |Create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel2.png
8196 .. |Right click to create a new event| image:: images/mfp/MyFirstPolicy_P1_newEvent1.png
8197 .. |Fill in the necessary information for the 'SALE_INPUT' event and click 'Submit'| image:: images/mfp/MyFirstPolicy_P1_newEvent2.png
8198 .. |Right click to create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema1.png
8199 .. |Create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema2.png
8200 .. |Add new event parameters to an event| image:: images/mfp/MyFirstPolicy_P1_newEvent3.png
8201 .. |Right click to create a new task| image:: images/mfp/MyFirstPolicy_P1_newTask1.png
8202 .. |Add input and out fields for the task| image:: images/mfp/MyFirstPolicy_P1_newTask2.png
8203 .. |Add task logic the task| image:: images/mfp/MyFirstPolicy_P1_newTask3.png
8204 .. |Create a new policy| image:: images/mfp/MyFirstPolicy_P1_newPolicy1.png
8205 .. |Create a state| image:: images/mfp/MyFirstPolicy_P1_newState1.png
8206 .. |Add a Task and Output Mapping| image:: images/mfp/MyFirstPolicy_P1_newState2.png
8207 .. |Validate the policy model for error using the 'Model' > 'Validate' menu item| image:: images/mfp/MyFirstPolicy_P1_validatePolicyModel.png
8208 .. |Download the completed policy model using the 'File' > 'Download' menu item| image:: images/mfp/MyFirstPolicy_P1_exportPolicyModel1.png
8209 .. |Create a new alternative task MorningBoozeCheckAlt1| image:: images/mfp/MyFirstPolicy_P2_newTask1.png
8210 .. |Right click to edit a policy| image:: images/mfp/MyFirstPolicy_P2_editPolicy1.png
8211 .. |State definition with 2 Tasks and Task Selection Logic| image:: images/mfp/MyFirstPolicy_P2_editState1.png