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 -Pdocker -DskipTests | >cd \dev\apex |
196 | | >mvn clean install -Pdocker -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 -Pdocker -DskipTests | >cd \dev\apex |
524 | | >mvn clean install -Pdocker -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="logDir" value="/var/log/onap/policy/apex-pdp/" />``
915 .. container:: paragraph
919 .. container:: paragraph
921 ``<property name="logDir" 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="logDir" 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 | sudo mkdir -p /var/log/onap/policy/apex-pdp | >mkdir C:\apex\apex-full-2.0.0-SNAPSHOT\logs |
956 | sudo 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:: paragraph
1022 On Unix/Linux flavoured platforms, give the commands below:
1024 .. container:: listingblock
1026 .. container:: content
1032 export APEX_HOME <path to apex installation>
1033 export APEX_USER apexuser
1035 .. container:: paragraph
1037 You can now try to run apex.
1039 .. container:: listingblock
1041 .. container:: content
1046 # $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/SampleDomain/Stdin2StdoutJsonEventJava.json (1)
1047 # $APEX_HOME/bin/apexEngine.sh -c C:/apex/apex-full-2.0.0-SNAPSHOT/examples/config/SampleDomain/Stdin2StdoutJsonEventJava.json (2)
1048 >%APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\SampleDomain\Stdin2StdoutJsonEventJava.json :: (3)
1050 .. container:: colist arabic
1060 .. container:: paragraph
1062 The engine should start successfully. Assuming the logging levels are set to ``info`` in the built system, the output
1063 should look similar to this (last few lines)
1065 .. container:: listingblock
1067 .. container:: content
1072 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] . . .
1073 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 .
1074 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 .
1075 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 .
1076 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 .
1077 2018-09-05 15:16:42,805 Apex [main] INFO o.o.p.a.s.e.r.impl.EngineServiceImpl - APEX service created.
1078 2018-09-05 15:16:43,962 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging starting . . .
1079 2018-09-05 15:16:43,963 Apex [main] INFO o.o.p.a.s.e.e.EngDepMessagingService - engine<-->deployment messaging started
1080 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
1081 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
1082 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
1083 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
1084 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
1085 Started Apex service
1087 .. container:: paragraph
1089 Important are the last two line, stating that APEX has added the
1090 final action listener to the engine and that the engine is started.
1092 .. container:: paragraph
1094 The engine is configured to read events from standard input and write
1095 produced events to standard output. The policy model is a very simple
1098 .. container:: paragraph
1100 The following table shows an input event in the left column and an
1101 output event in the right column. Past the input event into the
1102 console where APEX is running, and the output event should appear in
1103 the console. Pasting the input event multiple times will produce
1104 output events with different values.
1106 +-------------------------------------------------------------+-------------------------------------------------------------+
1107 | Input Event | Example Output Event |
1108 +=============================================================+=============================================================+
1109 | .. container:: | .. container:: |
1111 | .. container:: content | .. container:: content |
1113 | .. code:: | .. code:: |
1114 | :number-lines: | :number-lines: |
1117 | "nameSpace": "org.onap.policy.apex.sample.events", | "name": "Event0004", |
1118 | "name": "Event0000", | "version": "0.0.1", |
1119 | "version": "0.0.1", | "nameSpace": "org.onap.policy.apex.sample.events", |
1120 | "source": "test", | "source": "Act", |
1121 | "target": "apex", | "target": "Outside", |
1122 | "TestSlogan": "Test slogan for External Event0", | "TestActCaseSelected": 2, |
1123 | "TestMatchCase": 0, | "TestActStateTime": 1536157104627, |
1124 | "TestTimestamp": 1469781869269, | "TestDecideCaseSelected": 0, |
1125 | "TestTemperature": 9080.866 | "TestDecideStateTime": 1536157104625, |
1126 | } | "TestEstablishCaseSelected": 0, |
1127 | | "TestEstablishStateTime": 1536157104623, |
1128 | | "TestMatchCase": 0, |
1129 | | "TestMatchCaseSelected": 1, |
1130 | | "TestMatchStateTime": 1536157104620, |
1131 | | "TestSlogan": "Test slogan for External Event0", |
1132 | | "TestTemperature": 9080.866, |
1133 | | "TestTimestamp": 1469781869269 |
1135 +-------------------------------------------------------------+-------------------------------------------------------------+
1137 .. container:: paragraph
1139 Terminate APEX by simply using ``CTRL+C`` in the console.
1141 Verify a Full Installation - REST Editor
1142 ########################################
1144 .. container:: paragraph
1146 APEX has a REST application for viewing policy models. The
1147 application can also be used to create new policy models close to
1148 the engine native policy language. Start the REST editor as
1151 .. container:: listingblock
1153 .. container:: content
1158 # $APEX_HOME/bin/apexApps.sh rest-editor
1160 .. container:: listingblock
1162 .. container:: content
1167 >%APEX_HOME%\bin\apexApps.bat rest-editor
1169 .. container:: paragraph
1171 The script will start a simple web server
1172 (`Grizzly <https://javaee.github.io/grizzly/>`__) and deploy a
1173 ``war`` web archive in it. Once the editor is started, it will be
1174 available on ``localhost:18989``. The last few line of the messages
1177 .. container:: listingblock
1179 .. container:: content
1184 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
1185 Sep 05, 2018 10:35:57 PM org.glassfish.grizzly.http.server.NetworkListener start
1186 INFO: Started listener bound to [localhost:18989]
1187 Sep 05, 2018 10:35:57 PM org.glassfish.grizzly.http.server.HttpServer start
1188 INFO: [HttpServer] Started.
1189 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
1191 .. container:: paragraph
1193 Now open a browser (Firefox, Chrome, Opera, Internet Explorer) and
1194 use the URL ``http://localhost:18989/``. This will connect the
1195 browser to the started REST editor. The start screen should be as
1198 .. container:: imageblock
1200 .. container:: content
1202 |REST Editor Start Screen|
1204 .. container:: title
1206 Figure 1. REST Editor Start Screen
1208 .. container:: paragraph
1210 Now load a policy model by clicking the menu ``File`` and then
1211 ``Open``. In the opened dialog, go to the directory where APEX is
1212 installed, then ``examples``, ``models``, ``SampleDomain``, and there
1213 select the file ``SamplePolicyModelJAVA.json``. This will load the
1214 policy model used to verify the policy engine (see above). Once
1215 loaded, the screen should look as follows.
1217 .. container:: imageblock
1219 .. container:: content
1221 |REST Editor with loaded SampleDomain Policy Model|
1223 .. container:: title
1225 Figure 2. REST Editor with loaded SampleDomain Policy Model
1227 .. container:: paragraph
1229 Now you can use the REST editor. To finish this verification, simply
1230 terminate your browser (or the tab), and then use ``CTRL+C`` in the
1231 console where you started the REST editor.
1233 Installing WAR Applications
1234 ---------------------------
1236 .. container:: paragraph
1238 APEX comes with a set of WAR files. These are complete
1239 applications that can be installed and run in an application
1240 server. All of these applications are realized as servlets. You
1241 can find the WAR applications in ``$APEX_HOME/war`` (UNIX, Cygwin)
1242 or ``%APEX_HOME%\war`` (Windows).
1244 .. container:: paragraph
1246 Installing and using the WAR applications requires a web server
1247 that can execute ``war`` web archives. We recommend to use `Apache
1248 Tomcat <https://tomcat.apache.org/>`__, however other web servers
1249 can be used as well.
1251 .. container:: paragraph
1253 Install Apache Tomcat including the ``Manager App``, see `V9.0
1254 Docs <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html#Configuring_Manager_Application_Access>`__
1255 for details. Start the Tomcat service, or make sure that Tomcat is
1258 .. container:: paragraph
1260 There are multiple ways to install the APEX WAR applications:
1262 .. container:: ulist
1264 - copy the ``.war`` file into the Tomcat ``webapps`` folder
1266 - use the Tomcat ``Manager App`` to deploy via the web interface
1268 - deploy using a REST call to Tomcat
1270 .. container:: paragraph
1272 For details on how to install ``war`` files please consult the
1274 Documentation <https://tomcat.apache.org/tomcat-9.0-doc/index.html>`__
1276 HOW-TO <https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html>`__.
1277 Once you installed an APEX WAR application (and wait for
1278 sufficient time for Tomcat to finalize the installation), open the
1279 ``Manager App`` in Tomcat. You should see the APEX WAR application
1280 being installed and running.
1282 .. container:: paragraph
1284 In case of errors, examine the log files in the Tomcat log
1285 directory. In a conventional install, those log files are in the
1286 logs directory where Tomcat is installed.
1288 .. container:: paragraph
1290 The current APEX version provides the following WAR applications:
1292 .. container:: ulist
1294 - client-deployment-2.0.0-SNAPSHOT.war - a client to deploy new
1295 policy models to a running engine
1297 - client-editor-2.0.0-SNAPSHOT.war - the standard policy REST
1300 - client-monitoring-2.0.0-SNAPSHOT.war - a client for monitoring
1301 a running APEX engine
1303 - client-full-2.0.0-SNAPSHOT.war - a full client with a
1304 one-stop-access to deployment, monitoring, and REST editor
1306 - examples-servlet-2.0.0-SNAPSHOT.war - an example APEX servlet
1308 Running APEX in Docker
1309 ----------------------
1311 .. container:: paragraph
1313 Since APEX is in ONAP, we provide a full virtualization
1314 environment for the engine.
1319 .. container:: paragraph
1321 Running APEX from the ONAP docker repository only requires 2
1324 .. container:: olist arabic
1326 #. Log into the ONAP docker repo
1328 .. container:: listingblock
1330 .. container:: content
1334 docker login -u docker -p docker nexus3.onap.org:10003
1336 .. container:: olist arabic
1338 #. Run the APEX docker image
1340 .. container:: listingblock
1342 .. container:: content
1346 docker run -it --rm nexus3.onap.org:10003/onap/policy-apex-pdp:latest
1348 Build a Docker Image
1349 ####################
1351 .. container:: paragraph
1353 Alternatively, one can use the Dockerfile defined in the Docker
1354 package to build an image.
1356 .. container:: listingblock
1358 .. container:: title
1362 .. container:: content
1368 # Docker file to build an image that runs APEX on Java 8 in Ubuntu
1372 RUN apt-get update && \
1373 apt-get upgrade -y && \
1374 apt-get install -y software-properties-common && \
1375 add-apt-repository ppa:openjdk-r/ppa -y && \
1377 apt-get install -y openjdk-8-jdk
1379 # Create apex user and group
1380 RUN groupadd apexuser
1381 RUN useradd --create-home -g apexuser apexuser
1383 # Add Apex-specific directories and set ownership as the Apex admin user
1384 RUN mkdir -p /opt/app/policy/apex-pdp
1385 RUN mkdir -p /var/log/onap/policy/apex-pdp
1386 RUN chown -R apexuser:apexuser /var/log/onap/policy/apex-pdp
1388 # Unpack the tarball
1390 COPY apex-pdp-package-full.tar.gz /packages
1391 RUN tar xvfz /packages/apex-pdp-package-full.tar.gz --directory /opt/app/policy/apex-pdp
1392 RUN rm /packages/apex-pdp-package-full.tar.gz
1394 # Ensure everything has the correct permissions
1395 RUN find /opt/app -type d -perm 755
1396 RUN find /opt/app -type f -perm 644
1397 RUN chmod a+x /opt/app/policy/apex-pdp/bin/*
1399 # Copy examples to Apex user area
1400 RUN cp -pr /opt/app/policy/apex-pdp/examples /home/apexuser
1404 RUN chown -R apexuser:apexuser /home/apexuser/*
1407 ENV PATH /opt/app/policy/apex-pdp/bin:$PATH
1408 WORKDIR /home/apexuser
1410 APEX Configurations Explained
1411 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1413 Introduction to APEX Configuration
1414 ----------------------------------
1416 .. container:: paragraph
1418 An APEX engine can be configured to use various combinations
1419 of event input handlers, event output handlers, event
1420 protocols, context handlers, and logic executors. The system
1421 is build using a plugin architecture. Each configuration
1422 option is realized by a plugin, which can be loaded and
1423 configured when the engine is started. New plugins can be
1424 added to the system at any time, though to benefit from a
1425 new plugin an engine will need to be restarted.
1427 .. container:: imageblock
1429 .. container:: content
1431 |APEX Configuration Matrix|
1433 .. container:: title
1435 Figure 3. APEX Configuration Matrix
1437 .. container:: paragraph
1439 The APEX distribution already comes with a number of
1440 plugins. The figure above shows the provided plugins. Any
1441 combination of input, output, event protocol, context
1442 handlers, and executors is possible.
1444 General Configuration Format
1445 ----------------------------
1447 .. container:: paragraph
1449 The APEX configuration file is a JSON file containing a few
1450 main blocks for different parts of the configuration. Each
1451 block then holds the configuration details. The following
1452 code shows the main blocks:
1454 .. container:: listingblock
1456 .. container:: content
1461 "engineServiceParameters":{
1463 "engineParameters":{ (2)
1464 "executorParameters":{...}, (3)
1465 "contextParameters":{...} (4)
1466 "taskParameters":[...] (5)
1469 "eventInputParameters":{ (6)
1471 "carrierTechnologyParameters":{...},
1472 "eventProtocolParameters":{...}
1475 "carrierTechnologyParameters":{...},
1476 "eventProtocolParameters":{...}
1480 "eventOutputParameters":{ (10)
1482 "carrierTechnologyParameters":{...},
1483 "eventProtocolParameters":{...}
1486 "carrierTechnologyParameters":{...},
1487 "eventProtocolParameters":{...}
1493 .. container:: colist arabic
1495 +-----------------------------------+-----------------------------------+
1496 | **1** | main engine configuration |
1497 +-----------------------------------+-----------------------------------+
1498 | **2** | engine parameters for plugin |
1499 | | configurations (execution |
1500 | | environments and context |
1502 +-----------------------------------+-----------------------------------+
1503 | **3** | engine specific parameters, |
1504 | | mainly for executor plugins |
1505 +-----------------------------------+-----------------------------------+
1506 | **4** | context specific parameters, e.g. |
1507 | | for context schemas, persistence, |
1509 +-----------------------------------+-----------------------------------+
1510 | **5** | list of task parameters that |
1511 | | should be made available in task |
1512 | | logic (optional). |
1513 +-----------------------------------+-----------------------------------+
1514 | **6** | configuration of the input |
1516 +-----------------------------------+-----------------------------------+
1517 | **7** | an example input called |
1518 | | ``input1`` with carrier |
1519 | | technology and event protocol |
1520 +-----------------------------------+-----------------------------------+
1521 | **8** | an example input called |
1522 | | ``input2`` with carrier |
1523 | | technology and event protocol |
1524 +-----------------------------------+-----------------------------------+
1525 | **9** | any further input configuration |
1526 +-----------------------------------+-----------------------------------+
1527 | **10** | configuration of the output |
1529 +-----------------------------------+-----------------------------------+
1530 | **11** | an example output called |
1531 | | ``output1`` with carrier |
1532 | | technology and event protocol |
1533 +-----------------------------------+-----------------------------------+
1534 | **12** | an example output called |
1535 | | ``output2`` with carrier |
1536 | | technology and event protocol |
1537 +-----------------------------------+-----------------------------------+
1538 | **13** | any further output configuration |
1539 +-----------------------------------+-----------------------------------+
1541 Engine Service Parameters
1542 -------------------------
1544 .. container:: paragraph
1546 The configuration provides a number of parameters to
1547 configure the engine. An example configuration with
1548 explanations of all options is shown below.
1550 .. container:: listingblock
1552 .. container:: content
1556 "engineServiceParameters" : {
1557 "name" : "AADMApexEngine", (1)
1558 "version" : "0.0.1", (2)
1560 "instanceCount" : 4, (4)
1561 "deploymentPort" : 12345, (5)
1562 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelJava.json", (6)
1563 "periodicEventPeriod": 1000, (7)
1564 "engineParameters":{ (8)
1565 "executorParameters":{...}, (9)
1566 "contextParameters":{...}, (10)
1567 "taskParameters":[...] (11)
1571 .. container:: colist arabic
1573 +-----------------------------------+-----------------------------------+
1574 | **1** | a name for the engine. The engine |
1575 | | name is used to create a key in a |
1576 | | runtime engine. An name matching |
1577 | | the following regular expression |
1578 | | can be used here: |
1579 | | ``[A-Za-z0-9\\-_\\.]+`` |
1580 +-----------------------------------+-----------------------------------+
1581 | **2** | a version of the engine, use |
1582 | | semantic versioning as explained |
1583 | | here: `Semantic |
1584 | | Versioning <http://semver.org/>`_ |
1586 | | This version is used in a runtime |
1587 | | engine to create a version of the |
1588 | | engine. For that reason, the |
1589 | | version must match the following |
1590 | | regular expression ``[A-Z0-9.]+`` |
1591 +-----------------------------------+-----------------------------------+
1592 | **3** | a numeric identifier for the |
1594 +-----------------------------------+-----------------------------------+
1595 | **4** | the number of threads (policy |
1596 | | instances executed in parallel) |
1597 | | the engine should use, use ``1`` |
1598 | | for single threaded engines |
1599 +-----------------------------------+-----------------------------------+
1600 | **5** | the port for the deployment |
1601 | | Websocket connection to the |
1603 +-----------------------------------+-----------------------------------+
1604 | **6** | the model file to load into the |
1605 | | engine on startup (optional) |
1606 +-----------------------------------+-----------------------------------+
1607 | **7** | an optional timer for periodic |
1608 | | policies, in milliseconds (a |
1609 | | defined periodic policy will be |
1610 | | executed every ``X`` |
1611 | | milliseconds), not used of not |
1613 +-----------------------------------+-----------------------------------+
1614 | **8** | engine parameters for plugin |
1615 | | configurations (execution |
1616 | | environments and context |
1618 +-----------------------------------+-----------------------------------+
1619 | **9** | engine specific parameters, |
1620 | | mainly for executor plugins |
1621 +-----------------------------------+-----------------------------------+
1622 | **10** | context specific parameters, e.g. |
1623 | | for context schemas, persistence, |
1625 +-----------------------------------+-----------------------------------+
1626 | **11** | list of task parameters that |
1627 | | should be made available in task |
1628 | | logic (optional). |
1629 +-----------------------------------+-----------------------------------+
1631 .. container:: paragraph
1633 The model file is optional, it can also be specified via
1634 command line. In any case, make sure all execution and other
1635 required plug-ins for the loaded model are loaded as
1638 Input and Output Interfaces
1639 ---------------------------
1641 .. container:: paragraph
1643 An APEX engine has two main interfaces:
1645 .. container:: ulist
1647 - An *input* interface to receive events: also known as
1648 ingress interface or consumer, receiving (consuming)
1649 events commonly named triggers, and
1651 - An *output* interface to publish produced events: also
1652 known as egress interface or producer, sending
1653 (publishing) events commonly named actions or action
1656 .. container:: paragraph
1658 The input and output interface is configured in terms of
1659 inputs and outputs, respectively. Each input and output is a
1660 combination of a carrier technology and an event protocol.
1661 Carrier technologies and event protocols are provided by
1662 plugins, each with its own specific configuration. Most
1663 carrier technologies can be configured for input as well as
1664 output. Most event protocols can be used for all carrier
1665 technologies. One exception is the JMS object event
1666 protocol, which can only be used for the JMS carrier
1667 technology. Some further restrictions apply (for instance
1668 for carrier technologies using bi- or uni-directional
1671 .. container:: paragraph
1673 Input and output interface can be configured separately, in
1674 isolation, with any number of carrier technologies. The
1675 resulting general configuration options are:
1677 .. container:: ulist
1679 - Input interface with one or more inputs
1681 .. container:: ulist
1683 - each input with a carrier technology and an event
1686 - some inputs with optional synchronous mode
1688 - some event protocols with additional parameters
1690 - Output interface with one or more outputs
1692 .. container:: ulist
1694 - each output with a carrier technology and an event
1697 - some outputs with optional synchronous mode
1699 - some event protocols with additional parameters
1701 .. container:: paragraph
1703 The configuration for input and output is contained in
1704 ``eventInputParameters`` and ``eventOutputParameters``,
1705 respectively. Inside here, one can configure any number of
1706 inputs and outputs. Each of them needs to have a unique
1707 identifier (name), the content of the name is free form. The
1708 example below shows a configuration for two inputs and two
1711 .. container:: listingblock
1713 .. container:: content
1717 "eventInputParameters": { (1)
1718 "FirstConsumer": { (2)
1719 "carrierTechnologyParameters" : {...}, (3)
1720 "eventProtocolParameters":{...}, (4)
1723 "SecondConsumer": { (6)
1724 "carrierTechnologyParameters" : {...}, (7)
1725 "eventProtocolParameters":{...}, (8)
1729 "eventOutputParameters": { (10)
1730 "FirstProducer": { (11)
1731 "carrierTechnologyParameters":{...}, (12)
1732 "eventProtocolParameters":{...}, (13)
1735 "SecondProducer": { (15)
1736 "carrierTechnologyParameters":{...}, (16)
1737 "eventProtocolParameters":{...}, (17)
1742 .. container:: colist arabic
1744 +--------+--------------------------------------------------------------------+
1745 | **1** | input interface configuration, APEX input plugins |
1746 +--------+--------------------------------------------------------------------+
1747 | **2** | first input called ``FirstConsumer`` |
1748 +--------+--------------------------------------------------------------------+
1749 | **3** | carrier technology for plugin |
1750 +--------+--------------------------------------------------------------------+
1751 | **4** | event protocol for plugin |
1752 +--------+--------------------------------------------------------------------+
1753 | **5** | any other input configuration (e.g. event name filter, see below) |
1754 +--------+--------------------------------------------------------------------+
1755 | **6** | second input called ``SecondConsumer`` |
1756 +--------+--------------------------------------------------------------------+
1757 | **7** | carrier technology for plugin |
1758 +--------+--------------------------------------------------------------------+
1759 | **8** | event protocol for plugin |
1760 +--------+--------------------------------------------------------------------+
1761 | **9** | any other plugin configuration |
1762 +--------+--------------------------------------------------------------------+
1763 | **10** | output interface configuration, APEX output plugins |
1764 +--------+--------------------------------------------------------------------+
1765 | **11** | first output called ``FirstProducer`` |
1766 +--------+--------------------------------------------------------------------+
1767 | **12** | carrier technology for plugin |
1768 +--------+--------------------------------------------------------------------+
1769 | **13** | event protocol for plugin |
1770 +--------+--------------------------------------------------------------------+
1771 | **14** | any other plugin configuration |
1772 +--------+--------------------------------------------------------------------+
1773 | **15** | second output called ``SecondProducer`` |
1774 +--------+--------------------------------------------------------------------+
1775 | **16** | carrier technology for plugin |
1776 +--------+--------------------------------------------------------------------+
1777 | **17** | event protocol for plugin |
1778 +--------+--------------------------------------------------------------------+
1779 | **18** | any other output configuration (e.g. event name filter, see below) |
1780 +--------+--------------------------------------------------------------------+
1785 .. container:: paragraph
1787 APEX will always send an event after a policy execution
1788 is finished. For a successful execution, the event sent
1789 is the output event created by the policy. In case the
1790 policy does not create an output event, APEX will create
1791 a new event with all input event fields plus an
1792 additional field ``exceptionMessage`` with an exception
1795 .. container:: paragraph
1797 There are situations in which this auto-generated error
1798 event might not be required or wanted:
1800 .. container:: ulist
1802 - when a policy failing should not result in an event
1803 send out via an output interface
1805 - when the auto-generated event goes back in an APEX
1806 engine (or the same APEX engine), this can create
1809 - the auto-generated event should go to a special output
1810 interface or channel
1812 .. container:: paragraph
1814 All of these situations are supported by a filter option
1815 using a wildecard (regular expression) configuration on
1816 APEX I/O interfaces. The parameter is called
1817 ``eventNameFilter`` and the value are `Java regular
1818 expressions <https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html>`__
1820 `tutorial <http://www.vogella.com/tutorials/JavaRegularExpressions/article.html>`__).
1821 The following code shows some examples:
1823 .. container:: listingblock
1825 .. container:: content
1829 "eventInputParameters": {
1831 "carrierTechnologyParameters" : {...},
1832 "eventProtocolParameters":{...},
1833 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]004$" (1)
1836 "eventOutputParameters": {
1838 "carrierTechnologyParameters":{...},
1839 "eventProtocolParameters":{...},
1840 "eventNameFilter" : "^E[Vv][Ee][Nn][Tt][0-9]104$" (2)
1847 .. container:: paragraph
1849 Executors are plugins that realize the execution of logic
1850 contained in a policy model. Logic can be in a task
1851 selector, a task, and a state finalizer. Using plugins for
1852 execution environments makes APEX very flexible to support
1853 virtually any executable logic expressions.
1855 .. container:: paragraph
1857 APEX 2.0.0-SNAPSHOT supports the following executors:
1859 .. container:: ulist
1861 - Java, for Java implemented logic
1863 .. container:: ulist
1865 - This executor requires logic implemented using the
1866 APEX Java interfaces.
1868 - Generated JAR files must be in the classpath of the
1869 APEX engine at start time.
1879 .. container:: ulist
1881 - This executor uses the latest version of the MVEL
1882 engine, which can be very hard to debug and can
1883 produce unwanted side effects during execution
1885 Configure the Javascript Executor
1886 #################################
1888 .. container:: paragraph
1890 The Javascript executor is added to the configuration as
1893 .. container:: listingblock
1895 .. container:: content
1899 "engineServiceParameters":{
1900 "engineParameters":{
1901 "executorParameters":{
1903 "parameterClassName" :
1904 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
1910 Configure the Jython Executor
1911 #############################
1913 .. container:: paragraph
1915 The Jython executor is added to the configuration as
1918 .. container:: listingblock
1920 .. container:: content
1924 "engineServiceParameters":{
1925 "engineParameters":{
1926 "executorParameters":{
1928 "parameterClassName" :
1929 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
1935 Configure the JRuby Executor
1936 ############################
1938 .. container:: paragraph
1940 The JRuby executor is added to the configuration as
1943 .. container:: listingblock
1945 .. container:: content
1949 "engineServiceParameters":{
1950 "engineParameters":{
1951 "executorParameters":{
1953 "parameterClassName" :
1954 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
1960 Configure the Java Executor
1961 ###########################
1963 .. container:: paragraph
1965 The Java executor is added to the configuration as
1968 .. container:: listingblock
1970 .. container:: content
1974 "engineServiceParameters":{
1975 "engineParameters":{
1976 "executorParameters":{
1978 "parameterClassName" :
1979 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
1985 Configure the MVEL Executor
1986 ###########################
1988 .. container:: paragraph
1990 The MVEL executor is added to the configuration as
1993 .. container:: listingblock
1995 .. container:: content
1999 "engineServiceParameters":{
2000 "engineParameters":{
2001 "executorParameters":{
2003 "parameterClassName" :
2004 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
2013 .. container:: paragraph
2015 Context handlers are responsible for all context processing.
2016 There are the following main areas:
2018 .. container:: ulist
2020 - Context schema: use schema handlers other than Java class
2021 (supported by default without configuration)
2023 - Context distribution: distribute context across multiple
2026 - Context locking: mechanisms to lock context elements for
2029 - Context persistence: mechanisms to persist context
2031 .. container:: paragraph
2033 APEX provides plugins for each of the main areas.
2035 Configure AVRO Schema Handler
2036 #############################
2038 .. container:: paragraph
2040 The AVRO schema handler is added to the configuration as
2043 .. container:: listingblock
2045 .. container:: content
2049 "engineServiceParameters":{
2050 "engineParameters":{
2051 "contextParameters":{
2052 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
2053 "schemaParameters":{
2055 "parameterClassName" :
2056 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
2063 .. container:: paragraph
2065 Using the AVRO schema handler has one limitation: AVRO
2066 only supports field names that represent valid Java class
2067 names. This means only letters and the character ``_``
2068 are supported. Characters commonly used in field names,
2069 such as ``.`` and ``-``, are not supported by AVRO. for
2070 more information see `Avro Spec:
2071 Names <https://avro.apache.org/docs/1.8.1/spec.html#names>`__.
2073 .. container:: paragraph
2075 To work with this limitation, the APEX Avro plugin will
2076 parse a given AVRO definition and replace *all*
2077 occurrences of ``.`` and ``-`` with a ``_``. This means
2080 .. container:: ulist
2082 - In a policy model, if the AVRO schema defined a field
2083 as ``my-name`` the policy logic should access it as
2086 - In a policy model, if the AVRO schema defined a field
2087 as ``my.name`` the policy logic should access it as
2090 - There should be no field names that convert to the
2093 .. container:: ulist
2095 - For instance the simultaneous use of
2096 ``my_name``, ``my.name``, and ``my-name`` should
2099 - If not avoided, the event processing might
2100 create unwanted side effects
2102 - If field names use any other not-supported character,
2103 the AVRO plugin will reject it
2105 .. container:: ulist
2107 - Since AVRO uses lazy initialization, this
2108 rejection might only become visible at runtime
2110 Configure Task Parameters
2111 #########################
2113 .. container:: paragraph
2115 The Task Parameters are added to the configuration as
2118 .. container:: listingblock
2120 .. container:: content
2124 "engineServiceParameters": {
2125 "engineParameters": {
2128 "key": "ParameterKey1",
2129 "value": "ParameterValue1"
2132 "taskId": "Task_Act0",
2133 "key": "ParameterKey2",
2134 "value": "ParameterValue2"
2140 .. container:: paragraph
2142 TaskParameters can be used to pass parameters from ApexConfig
2143 to the policy logic. In the config, these are optional.
2144 The list of task parameters provided in the config may be added
2145 to the tasks or existing task parameters in the task will be overriden.
2147 .. container:: paragraph
2149 If taskId is provided in ApexConfig for an entry, then that
2150 parameter is updated only for that particular task. Otherwise,
2151 the task parameter is added to all tasks.
2153 Carrier Technologies
2154 --------------------
2156 .. container:: paragraph
2158 Carrier technologies define how APEX receives (input) and
2159 sends (output) events. They can be used in any combination,
2160 using asynchronous or synchronous mode. There can also be
2161 any number of carrier technologies for the input (consume)
2162 and the output (produce) interface.
2164 .. container:: paragraph
2166 Supported *input* technologies are:
2168 .. container:: ulist
2170 - Standard input, read events from the standard input
2171 (console), not suitable for APEX background servers
2173 - File input, read events from a file
2175 - Kafka, read events from a Kafka system
2177 - Websockets, read events from a Websocket
2181 - REST (synchronous and asynchronous), additionally as
2184 - Event Requestor, allows reading of events that have been
2185 looped back into APEX
2187 .. container:: paragraph
2189 Supported *output* technologies are:
2191 .. container:: ulist
2193 - Standard output, write events to the standard output
2194 (console), not suitable for APEX background servers
2196 - File output, write events to a file
2198 - Kafka, write events to a Kafka system
2200 - Websockets, write events to a Websocket
2204 - REST (synchronous and asynchronous), additionally as
2207 - Event Requestor, allows events to be looped back into
2210 .. container:: paragraph
2212 New carrier technologies can be added as plugins to APEX or
2213 developed outside APEX and added to an APEX deployment.
2218 .. container:: paragraph
2220 Standard IO does not require a specific plugin, it is
2221 supported be default.
2225 .. container:: paragraph
2227 APEX will take events from its standard input. This
2228 carrier is good for testing, but certainly not for a
2229 use case where APEX runs as a server. The
2230 configuration is as follows:
2232 .. container:: listingblock
2234 .. container:: content
2238 "carrierTechnologyParameters" : {
2239 "carrierTechnology" : "FILE", (1)
2241 "standardIO" : true (2)
2245 .. container:: colist arabic
2247 +-------+---------------------------------------+
2248 | **1** | standard input is considered a file |
2249 +-------+---------------------------------------+
2250 | **2** | file descriptor set to standard input |
2251 +-------+---------------------------------------+
2256 .. container:: paragraph
2258 APEX will send events to its standard output. This
2259 carrier is good for testing, but certainly not for a
2260 use case where APEX runs as a server. The
2261 configuration is as follows:
2263 .. container:: listingblock
2265 .. container:: content
2269 "carrierTechnologyParameters" : {
2270 "carrierTechnology" : "FILE", (1)
2272 "standardIO" : true (2)
2276 .. container:: colist arabic
2278 +-------+----------------------------------------+
2279 | **1** | standard output is considered a file |
2280 +-------+----------------------------------------+
2281 | **2** | file descriptor set to standard output |
2282 +-------+----------------------------------------+
2287 .. container:: paragraph
2289 File IO does not require a specific plugin, it is
2290 supported be default.
2295 .. container:: paragraph
2297 APEX will take events from a file. The same file
2298 should not be used as an output. The configuration is
2301 .. container:: listingblock
2303 .. container:: content
2307 "carrierTechnologyParameters" : {
2308 "carrierTechnology" : "FILE", (1)
2310 "fileName" : "examples/events/SampleDomain/EventsIn.xmlfile" (2)
2314 .. container:: colist arabic
2316 +-------+------------------------------------------+
2317 | **1** | set file input |
2318 +-------+------------------------------------------+
2319 | **2** | the name of the file to read events from |
2320 +-------+------------------------------------------+
2324 .. container:: paragraph
2326 APEX will write events to a file. The same file should
2327 not be used as an input. The configuration is as
2330 .. container:: listingblock
2332 .. container:: content
2336 "carrierTechnologyParameters" : {
2337 "carrierTechnology" : "FILE", (1)
2339 "fileName" : "examples/events/SampleDomain/EventsOut.xmlfile" (2)
2343 .. container:: colist arabic
2345 +-------+-----------------------------------------+
2346 | **1** | set file output |
2347 +-------+-----------------------------------------+
2348 | **2** | the name of the file to write events to |
2349 +-------+-----------------------------------------+
2354 .. container:: paragraph
2356 Event Requestor IO does not require a specific plugin, it
2357 is supported be default. It should only be used with the
2358 APEX event protocol.
2360 Event Requestor Input
2361 =====================
2363 .. container:: paragraph
2365 APEX will take events from APEX.
2367 .. container:: listingblock
2369 .. container:: content
2373 "carrierTechnologyParameters" : {
2374 "carrierTechnology": "EVENT_REQUESTOR" (1)
2377 .. container:: colist arabic
2379 +-------+---------------------------+
2380 | **1** | set event requestor input |
2381 +-------+---------------------------+
2383 Event Requestor Output
2384 ======================
2386 .. container:: paragraph
2388 APEX will write events to APEX.
2390 .. container:: listingblock
2392 .. container:: content
2396 "carrierTechnologyParameters" : {
2397 "carrierTechnology": "EVENT_REQUESTOR" (1)
2400 Peering Event Requestors
2401 ========================
2403 .. container:: paragraph
2405 When using event requestors, they need to be peered.
2406 This means an event requestor output needs to be
2407 peered (associated) with an event requestor input. The
2408 following example shows the use of an event requestor
2409 with the APEX event protocol and the peering of output
2412 .. container:: listingblock
2414 .. container:: content
2418 "eventInputParameters": {
2419 "EventRequestorConsumer": {
2420 "carrierTechnologyParameters": {
2421 "carrierTechnology": "EVENT_REQUESTOR" (1)
2423 "eventProtocolParameters": {
2424 "eventProtocol": "APEX" (2)
2426 "eventNameFilter": "InputEvent", (3)
2427 "requestorMode": true, (4)
2428 "requestorPeer": "EventRequestorProducer", (5)
2429 "requestorTimeout": 500 (6)
2432 "eventOutputParameters": {
2433 "EventRequestorProducer": {
2434 "carrierTechnologyParameters": {
2435 "carrierTechnology": "EVENT_REQUESTOR" (7)
2437 "eventProtocolParameters": {
2438 "eventProtocol": "APEX" (8)
2440 "eventNameFilter": "EventListEvent", (9)
2441 "requestorMode": true, (10)
2442 "requestorPeer": "EventRequestorConsumer", (11)
2443 "requestorTimeout": 500 (12)
2447 .. container:: colist arabic
2449 +-----------------------------------+-----------------------------------+
2450 | **1** | event requestor on a consumer |
2451 +-----------------------------------+-----------------------------------+
2452 | **2** | with APEX event protocol |
2453 +-----------------------------------+-----------------------------------+
2454 | **3** | optional filter (best to use a |
2455 | | filter to prevent unwanted events |
2456 | | on the consumer side) |
2457 +-----------------------------------+-----------------------------------+
2458 | **4** | activate requestor mode |
2459 +-----------------------------------+-----------------------------------+
2460 | **5** | the peer to the output (must |
2461 | | match the output carrier) |
2462 +-----------------------------------+-----------------------------------+
2463 | **6** | an optional timeout in |
2465 +-----------------------------------+-----------------------------------+
2466 | **7** | event requestor on a producer |
2467 +-----------------------------------+-----------------------------------+
2468 | **8** | with APEX event protocol |
2469 +-----------------------------------+-----------------------------------+
2470 | **9** | optional filter (best to use a |
2471 | | filter to prevent unwanted events |
2472 | | on the consumer side) |
2473 +-----------------------------------+-----------------------------------+
2474 | **10** | activate requestor mode |
2475 +-----------------------------------+-----------------------------------+
2476 | **11** | the peer to the output (must |
2477 | | match the input carrier) |
2478 +-----------------------------------+-----------------------------------+
2479 | **12** | an optional timeout in |
2481 +-----------------------------------+-----------------------------------+
2486 .. container:: paragraph
2488 Kafka IO is supported by the APEX Kafka plugin. The
2489 configurations below are examples. APEX will take any
2490 configuration inside the parameter object and forward it
2491 to Kafka. More information on Kafka specific
2492 configuration parameters can be found in the Kafka
2495 .. container:: ulist
2498 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html>`__
2501 Class <https://kafka.apache.org/090/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html>`__
2505 .. container:: paragraph
2507 APEX will receive events from the Apache Kafka
2508 messaging system. The input is uni-directional, an
2509 engine will only receive events from the input but not
2510 send any event to the input.
2512 .. container:: listingblock
2514 .. container:: content
2518 "carrierTechnologyParameters" : {
2519 "carrierTechnology" : "KAFKA", (1)
2520 "parameterClassName" :
2521 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2523 "bootstrapServers" : "localhost:49092", (2)
2524 "groupId" : "apex-group-id", (3)
2525 "enableAutoCommit" : true, (4)
2526 "autoCommitTime" : 1000, (5)
2527 "sessionTimeout" : 30000, (6)
2528 "consumerPollTime" : 100, (7)
2529 "consumerTopicList" : ["apex-in-0", "apex-in-1"], (8)
2531 "org.apache.kafka.common.serialization.StringDeserializer", (9)
2532 "valueDeserializer" :
2533 "org.apache.kafka.common.serialization.StringDeserializer" (10)
2537 .. container:: colist arabic
2539 +--------+-------------------------------------+
2540 | **1** | set Kafka as carrier technology |
2541 +--------+-------------------------------------+
2542 | **2** | bootstrap server and port |
2543 +--------+-------------------------------------+
2544 | **3** | a group identifier |
2545 +--------+-------------------------------------+
2546 | **4** | flag for auto-commit |
2547 +--------+-------------------------------------+
2548 | **5** | auto-commit timeout in milliseconds |
2549 +--------+-------------------------------------+
2550 | **6** | session timeout in milliseconds |
2551 +--------+-------------------------------------+
2552 | **7** | consumer poll time in milliseconds |
2553 +--------+-------------------------------------+
2554 | **8** | consumer topic list |
2555 +--------+-------------------------------------+
2556 | **9** | key for the Kafka de-serializer |
2557 +--------+-------------------------------------+
2558 | **10** | value for the Kafka de-serializer |
2559 +--------+-------------------------------------+
2563 .. container:: paragraph
2565 APEX will send events to the Apache Kafka messaging
2566 system. The output is uni-directional, an engine will
2567 send events to the output but not receive any event
2570 .. container:: listingblock
2572 .. container:: content
2576 "carrierTechnologyParameters" : {
2577 "carrierTechnology" : "KAFKA", (1)
2578 "parameterClassName" :
2579 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
2581 "bootstrapServers" : "localhost:49092", (2)
2584 "batchSize" : 16384, (5)
2585 "lingerTime" : 1, (6)
2586 "bufferMemory" : 33554432, (7)
2587 "producerTopic" : "apex-out", (8)
2589 "org.apache.kafka.common.serialization.StringSerializer", (9)
2591 "org.apache.kafka.common.serialization.StringSerializer" (10)
2595 .. container:: colist arabic
2597 +--------+---------------------------------+
2598 | **1** | set Kafka as carrier technology |
2599 +--------+---------------------------------+
2600 | **2** | bootstrap server and port |
2601 +--------+---------------------------------+
2602 | **3** | acknowledgement strategy |
2603 +--------+---------------------------------+
2604 | **4** | number of retries |
2605 +--------+---------------------------------+
2606 | **5** | batch size |
2607 +--------+---------------------------------+
2608 | **6** | time to linger in milliseconds |
2609 +--------+---------------------------------+
2610 | **7** | buffer memory in byte |
2611 +--------+---------------------------------+
2612 | **8** | producer topic |
2613 +--------+---------------------------------+
2614 | **9** | key for the Kafka serializer |
2615 +--------+---------------------------------+
2616 | **10** | value for the Kafka serializer |
2617 +--------+---------------------------------+
2622 .. container:: paragraph
2624 APEX supports the Java Messaging Service (JMS) as input
2625 as well as output. JMS IO is supported by the APEX JMS
2626 plugin. Input and output support an event encoding as
2627 text (JSON string) or object (serialized object). The
2628 input configuration is the same for both encodings, the
2629 output configuration differs.
2633 .. container:: paragraph
2635 APEX will receive events from a JMS messaging system.
2636 The input is uni-directional, an engine will only
2637 receive events from the input but not send any event
2640 .. container:: listingblock
2642 .. container:: content
2646 "carrierTechnologyParameters" : {
2647 "carrierTechnology" : "JMS", (1)
2648 "parameterClassName" :
2649 "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2650 "parameters" : { (2)
2651 "initialContextFactory" :
2652 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2653 "connectionFactory" : "ConnectionFactory", (4)
2654 "providerURL" : "remote://localhost:5445", (5)
2655 "securityPrincipal" : "guest", (6)
2656 "securityCredentials" : "IAmAGuest", (7)
2657 "consumerTopic" : "jms/topic/apexIn" (8)
2661 .. container:: colist arabic
2663 +-----------------------------------+-----------------------------------+
2664 | **1** | set JMS as carrier technology |
2665 +-----------------------------------+-----------------------------------+
2666 | **2** | set all JMS specific parameters |
2667 +-----------------------------------+-----------------------------------+
2668 | **3** | the context factory, in this case |
2669 | | from JBOSS (it requires the |
2671 | | org.jboss:jboss-remote-naming:2.0 |
2673 | | or a different version to be in |
2674 | | the directory ``$APEX_HOME/lib`` |
2675 | | or ``%APEX_HOME%\lib`` |
2676 +-----------------------------------+-----------------------------------+
2677 | **4** | a connection factory for the JMS |
2679 +-----------------------------------+-----------------------------------+
2680 | **5** | URL with host and port of the JMS |
2682 +-----------------------------------+-----------------------------------+
2683 | **6** | access credentials, user name |
2684 +-----------------------------------+-----------------------------------+
2685 | **7** | access credentials, user password |
2686 +-----------------------------------+-----------------------------------+
2687 | **8** | the JMS topic to listen to |
2688 +-----------------------------------+-----------------------------------+
2690 JMS Output with Text
2691 ====================
2693 .. container:: paragraph
2695 APEX engine send events to a JMS messaging system. The
2696 output is uni-directional, an engine will send events
2697 to the output but not receive any event from output.
2699 .. container:: listingblock
2701 .. container:: content
2705 "carrierTechnologyParameters" : {
2706 "carrierTechnology" : "JMS", (1)
2707 "parameterClassName" :
2708 "org.onap.policy.apex.plugins.event.carrier.jms.JMSCarrierTechnologyParameters",
2709 "parameters" : { (2)
2710 "initialContextFactory" :
2711 "org.jboss.naming.remote.client.InitialContextFactory", (3)
2712 "connectionFactory" : "ConnectionFactory", (4)
2713 "providerURL" : "remote://localhost:5445", (5)
2714 "securityPrincipal" : "guest", (6)
2715 "securityCredentials" : "IAmAGuest", (7)
2716 "producerTopic" : "jms/topic/apexOut", (8)
2717 "objectMessageSending": "false" (9)
2721 .. container:: colist arabic
2723 +-----------------------------------+-----------------------------------+
2724 | **1** | set JMS as carrier technology |
2725 +-----------------------------------+-----------------------------------+
2726 | **2** | set all JMS specific parameters |
2727 +-----------------------------------+-----------------------------------+
2728 | **3** | the context factory, in this case |
2729 | | from JBOSS (it requires the |
2731 | | org.jboss:jboss-remote-naming:2.0 |
2733 | | or a different version to be in |
2734 | | the directory ``$APEX_HOME/lib`` |
2735 | | or ``%APEX_HOME%\lib`` |
2736 +-----------------------------------+-----------------------------------+
2737 | **4** | a connection factory for the JMS |
2739 +-----------------------------------+-----------------------------------+
2740 | **5** | URL with host and port of the JMS |
2742 +-----------------------------------+-----------------------------------+
2743 | **6** | access credentials, user name |
2744 +-----------------------------------+-----------------------------------+
2745 | **7** | access credentials, user password |
2746 +-----------------------------------+-----------------------------------+
2747 | **8** | the JMS topic to write to |
2748 +-----------------------------------+-----------------------------------+
2749 | **9** | set object messaging to ``false`` |
2750 | | means it sends JSON text |
2751 +-----------------------------------+-----------------------------------+
2753 JMS Output with Object
2754 ======================
2756 .. container:: paragraph
2758 To configure APEX for JMS objects on the output
2759 interface use the same configuration as above (for
2760 output). Simply change the ``objectMessageSending``
2761 parameter to ``true``.
2764 ########################
2766 .. container:: paragraph
2768 APEX supports the Websockets as input as well as output.
2769 WS IO is supported by the APEX Websocket plugin. This
2770 carrier technology does only support uni-directional
2771 communication. APEX will not send events to a Websocket
2772 input and any event sent to a Websocket output will
2773 result in an error log.
2775 .. container:: paragraph
2777 The input can be configured as client (APEX connects to
2778 an existing Websocket server) or server (APEX starts a
2779 Websocket server). The same applies to the output. Input
2780 and output can both use a client or a server
2781 configuration, or separate configurations (input as
2782 client and output as server, input as server and output
2783 as client). Each configuration should use its own
2784 dedicated port to avoid any communication loops. The
2785 configuration of a Websocket client is the same for input
2786 and output. The configuration of a Websocket server is
2787 the same for input and output.
2792 .. container:: paragraph
2794 APEX will connect to a given Websocket server. As
2795 input, it will receive events from the server but not
2796 send any events. As output, it will send events to the
2797 server and any event received from the server will
2798 result in an error log.
2800 .. container:: listingblock
2802 .. container:: content
2806 "carrierTechnologyParameters" : {
2807 "carrierTechnology" : "WEBSOCKET", (1)
2808 "parameterClassName" :
2809 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2811 "host" : "localhost", (2)
2816 .. container:: colist arabic
2818 +-------+------------------------------------------------------+
2819 | **1** | set Websocket as carrier technology |
2820 +-------+------------------------------------------------------+
2821 | **2** | the host name on which a Websocket server is running |
2822 +-------+------------------------------------------------------+
2823 | **3** | the port of that Websocket server |
2824 +-------+------------------------------------------------------+
2829 .. container:: paragraph
2831 APEX will start a Websocket server, which will accept
2832 any Websocket clients to connect. As input, it will
2833 receive events from the server but not send any
2834 events. As output, it will send events to the server
2835 and any event received from the server will result in
2838 .. container:: listingblock
2840 .. container:: content
2844 "carrierTechnologyParameters" : {
2845 "carrierTechnology" : "WEBSOCKET", (1)
2846 "parameterClassName" :
2847 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
2849 "wsClient" : false, (2)
2854 .. container:: colist arabic
2856 +-------+------------------------------------------------------------+
2857 | **1** | set Websocket as carrier technology |
2858 +-------+------------------------------------------------------------+
2859 | **2** | disable client, so that APEX will start a Websocket server |
2860 +-------+------------------------------------------------------------+
2861 | **3** | the port for the Websocket server APEX will start |
2862 +-------+------------------------------------------------------------+
2867 .. container:: paragraph
2869 APEX can act as REST client on the input as well as on
2870 the output interface. The media type is
2871 ``application/json``, so this plugin only works with
2872 the JSON Event protocol.
2877 .. container:: paragraph
2879 APEX will connect to a given URL to receive events,
2880 but not send any events. The server is polled, i.e.
2881 APEX will do an HTTP GET, take the result, and then do
2882 the next GET. Any required timing needs to be handled
2883 by the server configured via the URL. For instance,
2884 the server could support a wait timeout via the URL as
2886 The httpCodeFilter is used for filtering the status
2887 code, and it can be configured as a regular expression
2888 string. The default httpCodeFilter is "[2][0-9][0-9]"
2889 - for successful response codes.
2890 The response with HTTP status code that matches the
2891 given regular expression is forwarded to the task,
2892 otherwise it is logged as a failure.
2894 .. container:: listingblock
2896 .. container:: content
2900 "carrierTechnologyParameters" : {
2901 "carrierTechnology" : "RESTCLIENT", (1)
2902 "parameterClassName" :
2903 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2905 "url" : "http://example.org:8080/triggers/events", (2)
2906 "httpCodeFilter" : "[2][0-9][0-9]" (3)
2910 .. container:: colist arabic
2912 +-------+--------------------------------------------------+
2913 | **1** | set REST client as carrier technology |
2914 +-------+--------------------------------------------------+
2915 | **2** | the URL of the HTTP server for events |
2916 +-------+--------------------------------------------------+
2917 | **3** | use HTTP CODE FILTER for filtering status code |
2918 +-------+--------------------------------------------------+
2923 .. container:: paragraph
2925 APEX will connect to a given URL to send events, but
2926 not receive any events. The default HTTP operation is
2927 POST (no configuration required). To change it to PUT
2928 simply add the configuration parameter (as shown in
2930 The URL can be configured statically or tagged
2931 as ``?example.{site}.org:8080/{trig}/events``,
2932 all tags such as ``site`` and ``trig`` in the URL
2933 need to be set in the properties object available to
2934 the tasks. In addition, the keys should exactly match
2935 with the tags defined in url. The scope of the properties
2936 object is per HTTP call. Hence, key/value pairs set
2937 in the properties object by task are only available
2938 for that specific HTTP call.
2940 .. container:: listingblock
2942 .. container:: content
2946 "carrierTechnologyParameters" : {
2947 "carrierTechnology" : "RESTCLIENT", (1)
2948 "parameterClassName" :
2949 "org.onap.policy.apex.plugins.event.carrier.restclient.RESTClientCarrierTechnologyParameters",
2951 "url" : "http://example.com:8888/actions/events", (2)
2952 "url" : "http://example.{site}.com:8888/{trig}/events", (2')
2953 "httpMethod" : "PUT" (3)
2957 .. container:: colist arabic
2959 +-------+--------------------------------------------------+
2960 | **1** | set REST client as carrier technology |
2961 +-------+--------------------------------------------------+
2962 | **2** | the static URL of the HTTP server for events |
2963 +-------+--------------------------------------------------+
2964 | **2'**| the tagged URL of the HTTP server for events |
2965 +-------+--------------------------------------------------+
2966 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
2967 +-------+--------------------------------------------------+
2972 .. container:: paragraph
2974 APEX supports a REST server for input and output.
2976 .. container:: paragraph
2978 The REST server plugin always uses a synchronous mode. A
2979 client does a HTTP GET on the APEX REST server with the
2980 input event and receives the generated output event in
2981 the server reply. This means that for the REST server
2982 there has to always to be an input with an associated
2983 output. Input or output only are not permitted.
2985 .. container:: paragraph
2987 The plugin will start a Grizzly server as REST server for
2988 a normal APEX engine. If the APEX engine is executed as a
2989 servlet, for instance inside Tomcat, then Tomcat will be
2990 used as REST server (this case requires configuration on
2993 .. container:: paragraph
2995 Some configuration restrictions apply for all scenarios:
2997 .. container:: ulist
2999 - Minimum port: 1024
3001 - Maximum port: 65535
3003 - The media type is ``application/json``, so this plugin
3004 only works with the JSON Event protocol.
3006 .. container:: paragraph
3008 The URL the client calls is created using
3010 .. container:: ulist
3012 - the configured host and port, e.g.
3013 ``http://localhost:12345``
3015 - the standard path, e.g. ``/apex/``
3017 - the name of the input/output, e.g. ``FirstConsumer/``
3019 - the input or output name, e.g. ``EventIn``.
3021 .. container:: paragraph
3023 The examples above lead to the URL
3024 ``http://localhost:12345/apex/FirstConsumer/EventIn``.
3026 .. container:: paragraph
3028 A client can also get status information of the REST
3029 server using ``/Status``, e.g.
3030 ``http://localhost:12345/apex/FirstConsumer/Status``.
3032 REST Server Stand-alone
3033 =======================
3035 .. container:: paragraph
3037 We need to configure a REST server input and a REST
3038 server output. Input and output are associated with
3039 each other via there name.
3041 .. container:: paragraph
3043 Timeouts for REST calls need to be set carefully. If
3044 they are too short, the call might timeout before a
3045 policy finished creating an event.
3047 .. container:: paragraph
3049 The following example configures the input named as
3050 ``MyConsumer`` and associates an output named
3051 ``MyProducer`` with it.
3053 .. container:: listingblock
3055 .. container:: content
3059 "eventInputParameters": {
3061 "carrierTechnologyParameters" : {
3062 "carrierTechnology" : "RESTSERVER", (1)
3063 "parameterClassName" :
3064 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters",
3066 "standalone" : true, (2)
3067 "host" : "localhost", (3)
3071 "eventProtocolParameters":{
3072 "eventProtocol" : "JSON" (5)
3074 "synchronousMode" : true, (6)
3075 "synchronousPeer" : "MyProducer", (7)
3076 "synchronousTimeout" : 500 (8)
3080 .. container:: colist arabic
3082 +-------+---------------------------------------+
3083 | **1** | set REST server as carrier technology |
3084 +-------+---------------------------------------+
3085 | **2** | set the server as stand-alone |
3086 +-------+---------------------------------------+
3087 | **3** | set the server host |
3088 +-------+---------------------------------------+
3089 | **4** | set the server listen port |
3090 +-------+---------------------------------------+
3091 | **5** | use JSON event protocol |
3092 +-------+---------------------------------------+
3093 | **6** | activate synchronous mode |
3094 +-------+---------------------------------------+
3095 | **7** | associate an output ``MyProducer`` |
3096 +-------+---------------------------------------+
3097 | **8** | set a timeout of 500 milliseconds |
3098 +-------+---------------------------------------+
3100 .. container:: paragraph
3102 The following example configures the output named as
3103 ``MyProducer`` and associates the input ``MyConsumer``
3104 with it. Note that for the output there are no more
3105 paramters (such as host or port), since they are
3106 already configured in the associated input
3108 .. container:: listingblock
3110 .. container:: content
3114 "eventOutputParameters": {
3116 "carrierTechnologyParameters":{
3117 "carrierTechnology" : "RESTSERVER",
3118 "parameterClassName" :
3119 "org.onap.policy.apex.plugins.event.carrier.restserver.RESTServerCarrierTechnologyParameters"
3121 "eventProtocolParameters":{
3122 "eventProtocol" : "JSON"
3124 "synchronousMode" : true,
3125 "synchronousPeer" : "MyConsumer",
3126 "synchronousTimeout" : 500
3130 REST Server Stand-alone, multi input
3131 ====================================
3133 .. container:: paragraph
3135 Any number of input/output pairs for REST servers can
3136 be configured. For instance, we can configure an input
3137 ``FirstConsumer`` with output ``FirstProducer`` and an
3138 input ``SecondConsumer`` with output
3139 ``SecondProducer``. Important is that there is always
3140 one pair of input/output.
3142 REST Server Stand-alone in Servlet
3143 ==================================
3145 .. container:: paragraph
3147 If APEX is executed as a servlet, e.g. inside Tomcat,
3148 the configuration becomes easier since the plugin can
3149 now use Tomcat as the REST server. In this scenario,
3150 there are not parameters (port, host, etc.) and the
3151 key ``standalone`` must not be used (or set to false).
3153 .. container:: paragraph
3155 For the Tomcat configuration, we need to add the REST
3158 .. container:: listingblock
3160 .. container:: content
3168 <param-value>org.onap.policy.apex.plugins.event.carrier.restserver</param-value>
3176 .. container:: paragraph
3178 APEX can act as REST requestor on the input as well as on
3179 the output interface. The media type is
3180 ``application/json``, so this plugin only works with
3181 the JSON Event protocol.
3183 REST Requestor Input
3184 ====================
3186 .. container:: paragraph
3188 APEX will connect to a given URL to request an input.
3189 The URL can be configured statically or tagged
3190 as ``?example.{site}.org:8080/{trig}/events``,
3191 all tags such as ``site`` and ``trig`` in the URL
3192 need to be set in the properties object available to
3193 the tasks. In addition, the keys should exactly match
3194 with the tags defined in url. The scope of the properties
3195 object is per HTTP call. Hence, key/value pairs set
3196 in the properties object by task are only available
3197 for that specific HTTP call.
3198 The httpCodeFilter is used for filtering the status
3199 code, and it can be configured as a regular expression
3200 string. The default httpCodeFilter is "[2][0-9][0-9]"
3201 - for successful response codes.
3202 The response with HTTP status code that matches the
3203 given regular expression is forwarded to the task,
3204 otherwise it is logged as a failure.
3206 .. container:: listingblock
3208 .. container:: content
3212 "carrierTechnologyParameters": {
3213 "carrierTechnology": "RESTREQUESTOR", (1)
3214 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters",
3216 "url": "http://localhost:54321/some/path/to/rest/resource", (2)
3217 "url": "http://localhost:54321/{site}/path/to/rest/{resValue}", (2')
3218 "httpMethod": "POST", (3)
3219 "restRequestTimeout": 2000, (4)
3220 "httpCodeFilter" : "[2][0-9][0-9]" (5)
3224 .. container:: colist arabic
3226 +-------+--------------------------------------------------+
3227 | **1** | set REST requestor as carrier technology |
3228 +-------+--------------------------------------------------+
3229 | **2** | the static URL of the HTTP server for events |
3230 +-------+--------------------------------------------------+
3231 | **2'**| the tagged URL of the HTTP server for events |
3232 +-------+--------------------------------------------------+
3233 | **3** | use HTTP PUT (remove this line to use HTTP POST) |
3234 +-------+--------------------------------------------------+
3235 | **4** | request timeout in milliseconds |
3236 +-------+--------------------------------------------------+
3237 | **5** | use HTTP CODE FILTER for filtering status code |
3238 +-------+--------------------------------------------------+
3240 .. container:: paragraph
3242 Further settings are required on the consumer to
3243 define the event that is requested, for example:
3245 .. container:: listingblock
3247 .. container:: content
3251 "eventName": "GuardResponseEvent", (1)
3252 "eventNameFilter": "GuardResponseEvent", (2)
3253 "requestorMode": true, (3)
3254 "requestorPeer": "GuardRequestorProducer", (4)
3255 "requestorTimeout": 500 (5)
3257 .. container:: colist arabic
3259 +-------+---------------------------+
3260 | **1** | the event name |
3261 +-------+---------------------------+
3262 | **2** | a filter on the event |
3263 +-------+---------------------------+
3264 | **3** | the mode of the requestor |
3265 +-------+---------------------------+
3266 | **4** | a peer for the requestor |
3267 +-------+---------------------------+
3268 | **5** | a general request timeout |
3269 +-------+---------------------------+
3271 REST Requestor Output
3272 =====================
3274 .. container:: paragraph
3276 APEX will connect to a given URL to send events, but
3277 not receive any events.
3279 .. container:: listingblock
3281 .. container:: content
3285 "carrierTechnologyParameters": {
3286 "carrierTechnology": "RESTREQUESTOR", (1)
3287 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters"
3290 .. container:: colist arabic
3292 +-------+------------------------------------------+
3293 | **1** | set REST requestor as carrier technology |
3294 +-------+------------------------------------------+
3296 .. container:: paragraph
3298 Further settings are required on the consumer to
3299 define the event that is requested, for example:
3301 .. container:: listingblock
3303 .. container:: content
3307 "eventNameFilter": "GuardRequestEvent", (1)
3308 "requestorMode": true, (2)
3309 "requestorPeer": "GuardRequestorConsumer", (3)
3310 "requestorTimeout": 500 (4)
3312 .. container:: colist arabic
3314 +-------+---------------------------+
3315 | **1** | a filter on the event |
3316 +-------+---------------------------+
3317 | **2** | the mode of the requestor |
3318 +-------+---------------------------+
3319 | **3** | a peer for the requestor |
3320 +-------+---------------------------+
3321 | **4** | a general request timeout |
3322 +-------+---------------------------+
3327 .. container:: paragraph
3329 APEX can send requests over gRPC at the output side, and get back
3330 response at the input side. This can be used to send requests to CDS
3331 over gRPC. The media type is ``application/json``, so this plugin
3332 only works with the JSON Event protocol.
3337 .. container:: paragraph
3339 APEX will connect to a given host to send a request over
3342 .. container:: listingblock
3344 .. container:: content
3348 "carrierTechnologyParameters": {
3349 "carrierTechnology": "GRPC", (1)
3350 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters",
3352 "host": "cds-blueprints-processor-grpc", (2)
3354 "username": "ccsdkapps", (3)
3355 "password": ccsdkapps, (4)
3360 .. container:: colist arabic
3362 +-------+--------------------------------------------------+
3363 | **1** | set GRPC as carrier technology |
3364 +-------+--------------------------------------------------+
3365 | **2** | the host to which request is sent |
3366 +-------+--------------------------------------------------+
3367 | **2'**| the value for port |
3368 +-------+--------------------------------------------------+
3369 | **3** | username required to initiate connection |
3370 +-------+--------------------------------------------------+
3371 | **4** | password required to initiate connection |
3372 +-------+--------------------------------------------------+
3373 | **5** | the timeout value for completing the request |
3374 +-------+--------------------------------------------------+
3376 .. container:: paragraph
3378 Further settings are required on the producer to
3379 define the event that is requested, for example:
3381 .. container:: listingblock
3383 .. container:: content
3387 "eventName": "GRPCRequestEvent", (1)
3388 "eventNameFilter": "GRPCRequestEvent", (2)
3389 "requestorMode": true, (3)
3390 "requestorPeer": "GRPCRequestConsumer", (4)
3391 "requestorTimeout": 500 (5)
3393 .. container:: colist arabic
3395 +-------+---------------------------+
3396 | **1** | the event name |
3397 +-------+---------------------------+
3398 | **2** | a filter on the event |
3399 +-------+---------------------------+
3400 | **3** | the mode of the requestor |
3401 +-------+---------------------------+
3402 | **4** | a peer for the requestor |
3403 +-------+---------------------------+
3404 | **5** | a general request timeout |
3405 +-------+---------------------------+
3410 .. container:: paragraph
3412 APEX will connect to the host specified in the producer
3413 side, anad take in response back at the consumer side.
3415 .. container:: listingblock
3417 .. container:: content
3421 "carrierTechnologyParameters": {
3422 "carrierTechnology": "GRPC", (1)
3423 "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters"
3426 .. container:: colist arabic
3428 +-------+------------------------------------------+
3429 | **1** | set GRPC as carrier technology |
3430 +-------+------------------------------------------+
3432 .. container:: paragraph
3434 Further settings are required on the consumer to
3435 define the event that is requested, for example:
3437 .. container:: listingblock
3439 .. container:: content
3443 "eventNameFilter": "GRPCResponseEvent", (1)
3444 "requestorMode": true, (2)
3445 "requestorPeer": "GRPCRequestProducer", (3)
3446 "requestorTimeout": 500 (4)
3448 .. container:: colist arabic
3450 +-------+---------------------------+
3451 | **1** | a filter on the event |
3452 +-------+---------------------------+
3453 | **2** | the mode of the requestor |
3454 +-------+---------------------------+
3455 | **3** | a peer for the requestor |
3456 +-------+---------------------------+
3457 | **4** | a general request timeout |
3458 +-------+---------------------------+
3460 Event Protocols, Format and Encoding
3461 ------------------------------------
3463 .. container:: paragraph
3465 Event protocols define what event formats APEX can receive
3466 (input) and should send (output). They can be used in any
3467 combination for input and output, unless further restricted
3468 by a carrier technology plugin (for instance for JMS
3469 output). There can only be 1 event protocol per event
3472 .. container:: paragraph
3474 Supported *input* event protocols are:
3476 .. container:: ulist
3478 - JSON, the event as a JSON string
3480 - APEX, an APEX event
3482 - JMS object, the event as a JMS object,
3484 - JMS text, the event as a JMS text,
3486 - XML, the event as an XML string,
3488 - YAML, the event as YAML text
3490 .. container:: paragraph
3492 Supported *output* event protocols are:
3494 .. container:: ulist
3496 - JSON, the event as a JSON string
3498 - APEX, an APEX event
3500 - JMS object, the event as a JMS object,
3502 - JMS text, the event as a JMS text,
3504 - XML, the event as an XML string,
3506 - YAML, the event as YAML text
3508 .. container:: paragraph
3510 New event protocols can be added as plugins to APEX or
3511 developed outside APEX and added to an APEX deployment.
3516 .. container:: paragraph
3518 The event protocol for JSON encoding does not require a
3519 specific plugin, it is supported by default. Furthermore,
3520 there is no difference in the configuration for the input
3521 and output interface.
3523 .. container:: paragraph
3525 For an input, APEX requires a well-formed JSON string.
3526 Well-formed here means according to the definitions of a
3527 policy. Any JSON string that is not defined as a trigger
3528 event (consume) will not be consumed (errors will be
3529 thrown). For output JSON events, APEX will always produce
3530 valid JSON strings according to the definition in the
3533 .. container:: paragraph
3535 The following JSON shows the configuration.
3537 .. container:: listingblock
3539 .. container:: content
3543 "eventProtocolParameters":{
3544 "eventProtocol" : "JSON"
3547 .. container:: paragraph
3549 For JSON events, there are a few more optional
3550 parameters, which allow to define a mapping for standard
3551 event fields. An APEX event must have the fields
3552 ``name``, ``version``, ``source``, and ``target``
3553 defined. Sometimes it is not possible to configure a
3554 trigger or actioning system to use those fields. However,
3555 they might be in an event generated outside APEX (or used
3556 outside APEX) just with different names. To configure
3557 APEX to map between the different event names, simply add
3558 the following parameters to a JSON event:
3560 .. container:: listingblock
3562 .. container:: content
3566 "eventProtocolParameters":{
3567 "eventProtocol" : "JSON",
3568 "nameAlias" : "policyName", (1)
3569 "versionAlias" : "policyVersion", (2)
3570 "sourceAlias" : "from", (3)
3571 "targetAlias" : "to", (4)
3572 "nameSpaceAlias": "my.name.space" (5)
3575 .. container:: colist arabic
3577 +-----------------------------------+-----------------------------------+
3578 | **1** | mapping for the ``name`` field, |
3579 | | here from a field called |
3580 | | ``policyName`` |
3581 +-----------------------------------+-----------------------------------+
3582 | **2** | mapping for the ``version`` |
3583 | | field, here from a field called |
3584 | | ``policyVersion`` |
3585 +-----------------------------------+-----------------------------------+
3586 | **3** | mapping for the ``source`` field, |
3587 | | here from a field called ``from`` |
3588 | | (only for an input event) |
3589 +-----------------------------------+-----------------------------------+
3590 | **4** | mapping for the ``target`` field, |
3591 | | here from a field called ``to`` |
3592 | | (only for an output event) |
3593 +-----------------------------------+-----------------------------------+
3594 | **5** | mapping for the ``nameSpace`` |
3595 | | field, here from a field called |
3596 | | ``my.name.space`` |
3597 +-----------------------------------+-----------------------------------+
3601 .. container:: paragraph
3603 The event protocol for APEX events does not require a
3604 specific plugin, it is supported by default. Furthermore,
3605 there is no difference in the configuration for the input
3606 and output interface.
3608 .. container:: paragraph
3610 For input and output APEX uses APEX events.
3612 .. container:: paragraph
3614 The following JSON shows the configuration.
3616 .. container:: listingblock
3618 .. container:: content
3622 "eventProtocolParameters":{
3623 "eventProtocol" : "APEX"
3629 .. container:: paragraph
3631 The event protocol for JMS is provided by the APEX JMS
3632 plugin. The plugin supports encoding as JSON text or as
3633 object. There is no difference in the configuration for
3634 the input and output interface.
3638 .. container:: paragraph
3640 If used as input, APEX will take a JMS message and
3641 extract a JSON string, then proceed as if a JSON event
3642 was received. If used as output, APEX will take the
3643 event produced by a policy, create a JSON string, and
3644 then wrap it into a JMS message.
3646 .. container:: paragraph
3648 The configuration for JMS text is as follows:
3650 .. container:: listingblock
3652 .. container:: content
3656 "eventProtocolParameters":{
3657 "eventProtocol" : "JMSTEXT",
3658 "parameterClassName" :
3659 "org.onap.policy.apex.plugins.event.protocol.jms.JMSTextEventProtocolParameters"
3664 .. container:: paragraph
3666 If used as input, APEX will will take a JMS message,
3667 extract a Java Bean from the ``ObjectMessage``
3668 message, construct an APEX event and put the bean on
3669 the APEX event as a parameter. If used as output, APEX
3670 will take the event produced by a policy, create a
3671 Java Bean and send it as a JMS message.
3673 .. container:: paragraph
3675 The configuration for JMS object is as follows:
3677 .. container:: listingblock
3679 .. container:: content
3683 "eventProtocolParameters":{
3684 "eventProtocol" : "JMSOBJECT",
3685 "parameterClassName" :
3686 "org.onap.policy.apex.plugins.event.protocol.jms.JMSObjectEventProtocolParameters"
3692 .. container:: paragraph
3694 The event protocol for YAML is provided by the APEX YAML
3695 plugin. There is no difference in the configuration for
3696 the input and output interface.
3698 .. container:: paragraph
3700 If used as input, APEX will consume events as YAML and
3701 map them to policy trigger events. Not well-formed YAML
3702 and not understood trigger events will be rejected. If
3703 used as output, APEX produce YAML encoded events from the
3704 event a policy produces. Those events will always be
3705 well-formed according to the definition in the policy
3708 .. container:: paragraph
3710 The following code shows the configuration.
3712 .. container:: listingblock
3714 .. container:: content
3718 "eventProtocolParameters":{
3719 "eventProtocol" : "XML",
3720 "parameterClassName" :
3721 "org.onap.policy.apex.plugins.event.protocol.yaml.YamlEventProtocolParameters"
3726 .. container:: paragraph
3728 The event protocol for XML is provided by the APEX XML
3729 plugin. There is no difference in the configuration for
3730 the input and output interface.
3732 .. container:: paragraph
3734 If used as input, APEX will consume events as XML and map
3735 them to policy trigger events. Not well-formed XML and
3736 not understood trigger events will be rejected. If used
3737 as output, APEX produce XML encoded events from the event
3738 a policy produces. Those events will always be
3739 well-formed according to the definition in the policy
3742 .. container:: paragraph
3744 The following code shows the configuration.
3746 .. container:: listingblock
3748 .. container:: content
3752 "eventProtocolParameters":{
3753 "eventProtocol" : "XML",
3754 "parameterClassName" :
3755 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3758 A configuration example
3759 -----------------------
3761 .. container:: paragraph
3763 The following example loads all available plug-ins.
3765 .. container:: paragraph
3767 Events are consumed from a Websocket, APEX as client.
3768 Consumed event format is JSON.
3770 .. container:: paragraph
3772 Events are produced to Kafka. Produced event format is XML.
3774 .. container:: listingblock
3776 .. container:: content
3781 "engineServiceParameters" : {
3782 "name" : "MyApexEngine",
3783 "version" : "0.0.1",
3785 "instanceCount" : 4,
3786 "deploymentPort" : 12345,
3787 "policyModelFileName" : "examples/models/some-model.json",
3788 "engineParameters" : {
3789 "executorParameters" : {
3791 "parameterClassName" :
3792 "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
3795 "parameterClassName" :
3796 "org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters"
3799 "parameterClassName" :
3800 "org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters"
3803 "parameterClassName" :
3804 "org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters"
3807 "parameterClassName" :
3808 "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
3811 "contextParameters" : {
3812 "parameterClassName" :
3813 "org.onap.policy.apex.context.parameters.ContextParameters",
3814 "schemaParameters" : {
3816 "parameterClassName" :
3817 "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
3823 "producerCarrierTechnologyParameters" : {
3824 "carrierTechnology" : "KAFKA",
3825 "parameterClassName" :
3826 "org.onap.policy.apex.plugins.event.carrier.kafka.KAFKACarrierTechnologyParameters",
3828 "bootstrapServers" : "localhost:49092",
3831 "batchSize" : 16384,
3833 "bufferMemory" : 33554432,
3834 "producerTopic" : "apex-out",
3835 "keySerializer" : "org.apache.kafka.common.serialization.StringSerializer",
3836 "valueSerializer" : "org.apache.kafka.common.serialization.StringSerializer"
3839 "producerEventProtocolParameters" : {
3840 "eventProtocol" : "XML",
3841 "parameterClassName" :
3842 "org.onap.policy.apex.plugins.event.protocol.xml.XMLEventProtocolParameters"
3844 "consumerCarrierTechnologyParameters" : {
3845 "carrierTechnology" : "WEBSOCKET",
3846 "parameterClassName" :
3847 "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
3849 "host" : "localhost",
3853 "consumerEventProtocolParameters" : {
3854 "eventProtocol" : "JSON"
3858 Engine and Applications of the APEX System
3859 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3861 Introduction to APEX Engine and Applications
3862 --------------------------------------------
3864 .. container:: paragraph
3866 The core of APEX is the APEX Engine, also known as the APEX
3867 Policy Engine or the APEX PDP (since it is in fact a Policy
3868 Decision Point). Beside this engine, an APEX system comes
3869 with a few applications intended to help with policy
3870 authoring, deployment, and execution.
3872 .. container:: paragraph
3874 The engine itself and most applications are started from the
3875 command line with command line arguments. This is called a
3876 Command Line Interface (CLI). Some applications require an
3877 installation on a webserver, as for instance the REST
3878 Editor. Those applications can be accessed via a web
3881 .. container:: paragraph
3883 You can also use the available APEX APIs and applications to
3884 develop other applications as required. This includes policy
3885 languages (and associated parsers and compilers /
3886 interpreters), GUIs to access APEX or to define policies,
3887 clients to connect to APEX, etc.
3889 .. container:: paragraph
3891 For this documentation, we assume an installation of APEX as
3892 a full system based on a current ONAP release.
3894 CLI on Unix, Windows, and Cygwin
3895 --------------------------------
3897 .. container:: paragraph
3899 A note on APEX CLI applications: all applications and the
3900 engine itself have been deployed and tested on different
3901 operating systems: Red Hat, Ubuntu, Debian, Mac OSX,
3902 Windows, Cygwin. Each operating system comes with its own
3903 way of configuring and executing Java. The main items here
3906 .. container:: ulist
3908 - For UNIX systems (RHL, Ubuntu, Debian, Mac OSX), the
3909 provided bash scripts work as expected with absolute
3911 ``/opt/app/policy/apex-pdp/apex-pdp-2.0.0-SNAPSHOT/examples``),
3912 indirect and linked paths (e.g. ``../apex/apex``), and
3913 path substitutions using environment settings (e.g.
3914 ``$APEX_HOME/bin/``)
3916 - For Windows systems, the provided batch files (``.bat``)
3917 work as expected with with absolute paths (e.g.
3918 ``C:\apex\apex-2.0.0-SNAPSHOT\examples``), and path
3919 substitutions using environment settings (e.g.
3920 ``%APEX_HOME%\bin\``)
3922 - For Cygwin system we assume a standard Cygwin
3923 installation with standard tools (mainly bash) using a
3924 Windows Java installation. This means that the bash
3925 scripts can be used as in UNIX, however any argument
3926 pointing to files and directories need to use either a
3928 ``C:\apex\apex-2.0.0-SNAPSHOT\examples\config...``) or
3929 the command ``cygpath`` with a mixed option. The reason
3930 for that is: Cygwin executes Java using UNIX paths but
3931 then runs Java as a DOS/WINDOWS process, which requires
3932 DOS paths for file access.
3937 .. container:: paragraph
3939 The APEX engine can be started in different ways, depending
3940 your requirements. All scripts are located in the APEX *bin*
3943 .. container:: paragraph
3945 On UNIX and Cygwin systems use:
3947 .. container:: ulist
3949 - ``apexEngine.sh`` - this script will
3951 .. container:: ulist
3953 - Test if ``$APEX_USER`` is set and if the user
3954 exists, terminate with an error otherwise
3956 - Test if ``$APEX_HOME`` is set. If not set, it will
3957 use the default setting as
3958 ``/opt/app/policy/apex-pdp/apex-pdp``. Then the set
3959 directory is tested to exist, the script will
3962 - When all tests are passed successfully, the script
3963 will call ``apexApps.sh`` with arguments to start
3966 - ``apexApps.sh engine`` - this is the general APEX
3967 application launcher, which will
3969 .. container:: ulist
3971 - Start the engine with the argument ``engine``
3973 - Test if ``$APEX_HOME`` is set and points to an
3974 existing directory. If not set or directory does
3975 not exist, script terminates.
3977 - Not test for any settings of ``$APEX_USER``.
3979 .. container:: paragraph
3981 On Windows systems use ``apexEngine.bat`` and
3982 ``apexApps.bat engine`` respectively. Note: none of the
3983 windows batch files will test for ``%APEX_USER%``.
3985 .. container:: paragraph
3987 Summary of alternatives to start the APEX Engine:
3989 +--------------------------------------------------------+----------------------------------------------------------+
3990 | Unix, Cygwin | Windows |
3991 +========================================================+==========================================================+
3992 | .. container:: | .. container:: |
3994 | .. container:: listingblock | .. container:: listingblock |
3996 | .. container:: content | .. container:: content |
3998 | .. code:: | .. code:: |
4000 | # $APEX_HOME/bin/apexEngine.sh [args] | > %APEX_HOME%\bin\apexEngine.bat [args] |
4001 | # $APEX_HOME/bin/apexApps.sh engine [args] | > %APEX_HOME%\bin\apexApps.bat engine [args] |
4002 +--------------------------------------------------------+----------------------------------------------------------+
4004 .. container:: paragraph
4006 The APEX engine comes with a few CLI arguments for setting
4007 configuration and policy model. The configuration file is
4008 always required. The policy model file is only required if
4009 no model file is specified in the configuration, or if the
4010 specified model file should be over written. The option
4011 ``-h`` prints a help screen.
4013 .. container:: listingblock
4015 .. container:: content
4019 usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]
4021 -c,--config-file <CONFIG_FILE> the full path to the configuration file to use, the configuration file must be a Json file
4022 containing the Apex configuration parameters
4023 -h,--help outputs the usage of this command
4024 -m,--model-file <MODEL_FILE> the full path to the model file to use, if set it overrides the model file set in the
4026 -v,--version outputs the version of Apex
4031 .. container:: paragraph
4033 The CLI Editor allows to define policies from the command
4034 line. The application uses a simple language and supports
4035 all elements of an APEX policy. It can be used in to
4038 .. container:: ulist
4040 - non-interactive, specifying a file with the commands to
4043 - interactive, using the editors CLI to create a policy
4045 .. container:: paragraph
4047 When a policy is fully specified, the editor will generate
4048 the APEX core policy specification in JSON. This core
4049 specification is called the policy model in the APEX engine
4050 and can be used directly with the APEX engine.
4052 .. container:: paragraph
4054 On UNIX and Cygwin systems use:
4056 .. container:: ulist
4058 - ``apexCLIEditor.sh`` - simply starts the CLI editor,
4059 arguments to the script determine the mode of the editor
4061 - ``apexApps.sh cli-editor`` - simply starts the CLI
4062 editor, arguments to the script determine the mode of the
4065 .. container:: paragraph
4067 On Windows systems use:
4069 .. container:: ulist
4071 - ``apexCLIEditor.bat`` - simply starts the CLI editor,
4072 arguments to the script determine the mode of the editor
4074 - ``apexApps.bat cli-editor`` - simply starts the CLI
4075 editor, arguments to the script determine the mode of the
4078 .. container:: paragraph
4080 Summary of alternatives to start the APEX CLI Editor:
4082 +------------------------------------------------------------+--------------------------------------------------------------+
4083 | Unix, Cygwin | Windows |
4084 +============================================================+==============================================================+
4085 | .. container:: | .. container:: |
4087 | .. container:: listingblock | .. container:: listingblock |
4089 | .. container:: content | .. container:: content |
4091 | .. code:: | .. code:: |
4093 | # $APEX_HOME/bin/apexCLIEditor.sh.sh [args] | > %APEX_HOME%\bin\apexCLIEditor.bat [args] |
4094 | # $APEX_HOME/bin/apexApps.sh cli-editor [args] | > %APEX_HOME%\bin\apexApps.bat cli-editor [args] |
4095 +------------------------------------------------------------+--------------------------------------------------------------+
4097 .. container:: paragraph
4099 The option ``-h`` provides a help screen with all command
4102 .. container:: listingblock
4104 .. container:: content
4108 usage: org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain [options...]
4110 -a,--model-props-file <MODEL_PROPS_FILE> name of the apex model properties file to use
4111 -c,--command-file <COMMAND_FILE> name of a file containing editor commands to run into the editor
4112 -h,--help outputs the usage of this command
4113 -i,--input-model-file <INPUT_MODEL_FILE> name of a file that contains an input model for the editor
4114 -if,--ignore-failures <IGNORE_FAILURES_FLAG> true or false, ignore failures of commands in command files and continue
4115 executing the command file
4116 -l,--log-file <LOG_FILE> name of a file that will contain command logs from the editor, will log
4117 to standard output if not specified or suppressed with "-nl" flag
4118 -m,--metadata-file <CMD_METADATA_FILE> name of the command metadata file to use
4119 -nl,--no-log if specified, no logging or output of commands to standard output or log
4121 -nm,--no-model-output if specified, no output of a model to standard output or model output
4122 file is carried out, the user can use the "save" command in a script to
4124 -o,--output-model-file <OUTPUT_MODEL_FILE> name of a file that will contain the output model for the editor, will
4125 output model to standard output if not specified or suppressed with
4127 -wd,--working-directory <WORKING_DIRECTORY> the working directory that is the root for the CLI editor and is the
4128 root from which to look for included macro files
4130 The APEX CLI Tosca Editor
4131 -------------------------
4133 .. container:: paragraph
4135 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.
4137 .. container:: paragraph
4139 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.
4141 .. container:: paragraph
4143 On UNIX and Cygwin systems use:
4145 .. container:: ulist
4147 - ``apexCLIToscaEditor.sh`` - starts the CLI Tosca editor,
4148 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4150 - ``apexApps.sh cli-tosca-editor`` - starts the CLI Tosca editor,
4151 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4153 .. container:: paragraph
4155 On Windows systems use:
4157 .. container:: ulist
4159 - ``apexCLIToscaEditor.bat`` - starts the CLI Tosca editor,
4160 all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4162 - ``apexApps.bat cli-tosca-editor`` - starts the CLI Tosca
4163 editor, all the arguments supported by the basic CLI Editor are supported in addition to the mandatory arguments needed to generate ToscaServiceTemplate.
4165 .. container:: paragraph
4167 Summary of alternatives to start the APEX CLI Tosca Editor:
4169 +-----------------------------------------------------------------+--------------------------------------------------------------------+
4170 | Unix, Cygwin | Windows |
4171 +=================================================================+====================================================================+
4172 | .. container:: | .. container:: |
4174 | .. container:: listingblock | .. container:: listingblock |
4176 | .. container:: content | .. container:: content |
4178 | .. code:: | .. code:: |
4180 | # $APEX_HOME/bin/apexCLIToscaEditor.sh.sh [args] | > %APEX_HOME%\bin\apexCLIToscaEditor.bat [args] |
4181 | # $APEX_HOME/bin/apexApps.sh cli-tosca-editor [args]| > %APEX_HOME%\bin\apexApps.bat cli-tosca-editor [args] |
4182 +-----------------------------------------------------------------+--------------------------------------------------------------------+
4184 .. container:: paragraph
4186 The option ``-h`` provides a help screen with all command
4189 .. container:: listingblock
4191 .. container:: content
4195 usage: org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain [options...]
4197 -a,--model-props-file <MODEL_PROPS_FILE> name of the apex model properties file to use
4198 -ac,--apex-config-file <APEX_CONFIG_FILE> name of the file containing apex configuration details
4199 -c,--command-file <COMMAND_FILE> name of a file containing editor commands to run into the editor
4200 -h,--help outputs the usage of this command
4201 -i,--input-model-file <INPUT_MODEL_FILE> name of a file that contains an input model for the editor
4202 -if,--ignore-failures <IGNORE_FAILURES_FLAG> true or false, ignore failures of commands in command files and
4203 continue executing the command file
4204 -l,--log-file <LOG_FILE> name of a file that will contain command logs from the editor, will
4205 log to standard output if not specified or suppressed with "-nl" flag
4206 -m,--metadata-file <CMD_METADATA_FILE> name of the command metadata file to use
4207 -nl,--no-log if specified, no logging or output of commands to standard output or
4208 log file is carried out
4209 -ot,--output-tosca-file <OUTPUT_TOSCA_FILE> name of a file that will contain the output ToscaServiceTemplate
4210 -t,--tosca-template-file <TOSCA_TEMPLATE_FILE> name of the input file containing tosca template which needs to be
4212 -wd,--working-directory <WORKING_DIRECTORY> the working directory that is the root for the CLI editor and is the
4213 root from which to look for included macro files
4215 .. container:: paragraph
4217 An example command to run the APEX CLI Tosca editor on windows machine is given below.
4219 .. container:: listingblock
4221 .. container:: content
4225 %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
4227 The APEX REST Editor
4228 --------------------
4230 .. container:: paragraph
4232 The standard way to use the APEX REST Editor is via an
4233 installation of the *war* file on a webserver. However, the
4234 REST editor can also be started via command line. This will
4235 start a Grizzly webserver with the *war* deployed. Access to
4236 the REST Editor is then via the provided URL
4238 .. container:: paragraph
4240 On UNIX and Cygwin systems use:
4242 .. container:: ulist
4244 - ``apexRESTEditor.sh`` - simply starts the webserver with
4247 - ``apexApps.sh rest-editor`` - simply starts the webserver
4248 with the REST editor
4250 .. container:: paragraph
4252 On Windows systems use:
4254 .. container:: ulist
4256 - ``apexRESTEditor.bat`` - simply starts the webserver with
4259 - ``apexApps.bat rest-editor`` - simply starts the
4260 webserver with the REST editor
4262 .. container:: paragraph
4264 Summary of alternatives to start the APEX REST Editor:
4266 +-------------------------------------------------------------+---------------------------------------------------------------+
4267 | Unix, Cygwin | Windows |
4268 +=============================================================+===============================================================+
4269 | .. container:: | .. container:: |
4271 | .. container:: listingblock | .. container:: listingblock |
4273 | .. container:: content | .. container:: content |
4275 | .. code:: | .. code:: |
4277 | # $APEX_HOME/bin/apexRESTEditor.sh.sh [args] | > %APEX_HOME%\bin\apexRESTEditor.bat [args] |
4278 | # $APEX_HOME/bin/apexApps.sh rest-editor [args] | > %APEX_HOME%\bin\apexApps.bat rest-editor [args] |
4279 +-------------------------------------------------------------+---------------------------------------------------------------+
4281 .. container:: paragraph
4283 The option ``-h`` provides a help screen with all command
4286 .. container:: listingblock
4288 .. container:: content
4292 usage: org.onap.policy.apex.client.editor.rest.ApexEditorMain [options...]
4293 -h,--help outputs the usage of this command
4294 -l,--listen <ADDRESS> the IP address to listen on. Default value is localhost to restrict access to the
4296 -p,--port <PORT> port to use for the Apex RESTful editor REST calls.
4297 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating. Default
4298 value is -1 to run indefinitely.
4300 .. container:: paragraph
4302 If the REST Editor is started without any arguments the
4303 final messages will look similar to this:
4305 .. container:: listingblock
4307 .. container:: content
4311 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4312 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.NetworkListener start
4313 INFO: Started listener bound to [localhost:18989]
4314 Sep 05, 2018 11:24:30 PM org.glassfish.grizzly.http.server.HttpServer start
4315 INFO: [HttpServer] Started.
4316 Apex Editor REST endpoint (ApexEditorMain: Config=[ApexEditorParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4318 .. container:: paragraph
4320 The last line states the URL on which the REST Editor can be
4321 accessed. The example above stated
4322 ``http://0.0.0.0:18989/apex/``. In a web browser use the URL
4323 ``http://localhost:18989`` and the REST Editor will start.
4325 The APEX Monitoring Client
4326 --------------------------
4328 .. container:: paragraph
4330 The standard way to use the APEX Monitoring Client is via an
4331 installation of the *war* file on a webserver. However, the
4332 Monitoring Client can also be started via command line. This
4333 will start a Grizzly webserver with the *war* deployed.
4334 Access to the Monitoring Client is then via the provided URL
4336 .. container:: paragraph
4338 On UNIX and Cygwin systems use:
4340 .. container:: ulist
4342 - ``apexApps.sh eng-monitoring`` - simply starts the
4343 webserver with the Monitoring Client
4345 .. container:: paragraph
4347 On Windows systems use:
4349 .. container:: ulist
4351 - ``apexApps.bat eng-monitoring`` - simply starts the
4352 webserver with the Monitoring Client
4354 .. container:: paragraph
4356 The option ``-h`` provides a help screen with all command
4359 .. container:: listingblock
4361 .. container:: content
4365 usage: org.onap.policy.apex.client.monitoring.rest.ApexMonitoringRestMain [options...]
4366 -h,--help outputs the usage of this command
4367 -p,--port <PORT> port to use for the Apex Services REST calls
4368 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4370 .. container:: paragraph
4372 If the Monitoring Client is started without any arguments
4373 the final messages will look similar to this:
4375 .. container:: listingblock
4377 .. container:: content
4381 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4382 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.NetworkListener start
4383 INFO: Started listener bound to [localhost:18989]
4384 Sep 05, 2018 11:26:20 PM org.glassfish.grizzly.http.server.HttpServer start
4385 INFO: [HttpServer] Started.
4386 Apex Services REST endpoint (ApexMonitoringRestMain: Config=[ApexMonitoringRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4388 .. container:: paragraph
4390 The last line states the URL on which the Monitoring Client
4391 can be accessed. The example above stated
4392 ``http://localhost:18989/apexservices``. In a web browser
4393 use the URL ``http://localhost:18989``.
4395 The APEX Deployment Client
4396 --------------------------
4398 .. container:: paragraph
4400 The standard way to use the APEX Deployment Client is via an
4401 installation of the *war* file on a webserver. However, the
4402 Deployment Client can also be started via command line. This
4403 will start a Grizzly webserver with the *war* deployed.
4404 Access to the Deployment Client is then via the provided URL
4406 .. container:: paragraph
4408 On UNIX and Cygwin systems use:
4410 .. container:: ulist
4412 - ``apexApps.sh eng-deployment`` - simply starts the
4413 webserver with the Deployment Client
4415 .. container:: paragraph
4417 On Windows systems use:
4419 .. container:: ulist
4421 - ``apexApps.bat eng-deployment`` - simply starts the
4422 webserver with the Deployment Client
4424 .. container:: paragraph
4426 The option ``-h`` provides a help screen with all command
4429 .. container:: listingblock
4431 .. container:: content
4435 usage: org.onap.policy.apex.client.deployment.rest.ApexDeploymentRestMain [options...]
4436 -h,--help outputs the usage of this command
4437 -p,--port <PORT> port to use for the Apex Services REST calls
4438 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4440 .. container:: paragraph
4442 If the Deployment Client is started without any arguments
4443 the final messages will look similar to this:
4445 .. container:: listingblock
4447 .. container:: content
4451 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4452 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.NetworkListener start
4453 INFO: Started listener bound to [localhost:18989]
4454 Sep 05, 2018 11:27:09 PM org.glassfish.grizzly.http.server.HttpServer start
4455 INFO: [HttpServer] Started.
4456 Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4458 .. container:: paragraph
4460 The last line states the URL on which the Deployment Client
4461 can be accessed. The example above stated
4462 ``http://localhost:18989/apexservices``. In a web browser
4463 use the URL ``http://localhost:18989``.
4465 The APEX Full Client
4466 --------------------
4468 .. container:: paragraph
4470 The APEX Full Client combines the REST Editor, the
4471 Monitoring Client, and the Deployment Client into a single
4472 application. The standard way to use the APEX Full Client is
4473 via an installation of the *war* file on a webserver.
4474 However, the Full Client can also be started via command
4475 line. This will start a Grizzly webserver with the *war*
4476 deployed. Access to the Full Client is then via the provided
4479 .. container:: paragraph
4481 On UNIX and Cygwin systems use:
4483 .. container:: ulist
4485 - ``apexApps.sh full-client`` - simply starts the webserver
4486 with the Full Client
4488 .. container:: paragraph
4490 On Windows systems use:
4492 .. container:: ulist
4494 - ``apexApps.bat full-client`` - simply starts the
4495 webserver with the Full Client
4497 .. container:: paragraph
4499 The option ``-h`` provides a help screen with all command
4502 .. container:: listingblock
4504 .. container:: content
4508 usage: org.onap.policy.apex.client.full.rest.ApexServicesRestMain [options...]
4509 -h,--help outputs the usage of this command
4510 -p,--port <PORT> port to use for the Apex Services REST calls
4511 -t,--time-to-live <TIME_TO_LIVE> the amount of time in seconds that the server will run for before terminating
4513 .. container:: paragraph
4515 If the Full Client is started without any arguments the
4516 final messages will look similar to this:
4518 .. container:: listingblock
4520 .. container:: content
4524 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=READY) starting at http://localhost:18989/apexservices/ . . .
4525 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.NetworkListener start
4526 INFO: Started listener bound to [localhost:18989]
4527 Sep 05, 2018 11:28:28 PM org.glassfish.grizzly.http.server.HttpServer start
4528 INFO: [HttpServer] Started.
4529 Apex Editor REST endpoint (ApexServicesRestMain: Config=[ApexServicesRestParameters: URI=http://localhost:18989/apexservices/, TTL=-1sec], State=RUNNING) started at http://localhost:18989/apexservices/
4531 .. container:: paragraph
4533 The last line states the URL on which the Monitoring Client
4534 can be accessed. The example above stated
4535 ``http://localhost:18989/apexservices``. In a web browser
4536 use the URL ``http://localhost:18989``.
4538 The APEX Application Launcher
4539 ------------------------------
4541 .. container:: paragraph
4543 The standard applications (Engine, CLI Editor, REST Editor)
4544 come with dedicated start scripts. For all other APEX
4545 applications, we provide an application launcher.
4547 .. container:: paragraph
4549 On UNIX and Cygwin systems use:
4551 .. container:: ulist
4553 - apexApps.sh\` - simply starts the application launcher
4555 .. container:: paragraph
4557 On Windows systems use:
4559 .. container:: ulist
4561 - ``apexApps.bat`` - simply starts the application launcher
4563 .. container:: paragraph
4565 Summary of alternatives to start the APEX application
4568 +-------------------------------------------------+---------------------------------------------------+
4569 | Unix, Cygwin | Windows |
4570 +=================================================+===================================================+
4571 | .. container:: | .. container:: |
4573 | .. container:: listingblock | .. container:: listingblock |
4575 | .. container:: content | .. container:: content |
4577 | .. code:: | .. code:: |
4579 | # $APEX_HOME/bin/apexApps.sh [args] | > %APEX_HOME%\bin\apexApps.bat [args] |
4580 +-------------------------------------------------+---------------------------------------------------+
4582 .. container:: paragraph
4584 The option ``-h`` provides a help screen with all launcher
4585 command line arguments.
4587 .. container:: listingblock
4589 .. container:: content
4593 apexApps.sh - runs APEX applications
4595 Usage: apexApps.sh [options] | [<application> [<application options>]]
4598 -d <app> - describes an application
4599 -l - lists all applications supported by this script
4600 -h - this help screen
4602 .. container:: paragraph
4604 Using ``-l`` lists all known application the launcher can
4607 .. container:: listingblock
4609 .. container:: content
4613 apexApps.sh: supported applications:
4614 --> ws-echo engine eng-monitoring full-client eng-deployment tpl-event-json model-2-cli rest-editor cli-editor ws-console
4616 .. container:: paragraph
4618 Using the ``-d <name>`` option describes the named
4619 application, for instance for the ``ws-console``:
4621 .. container:: listingblock
4623 .. container:: content
4627 apexApps.sh: application 'ws-console'
4628 --> a simple console sending events to APEX, connect to APEX consumer port
4630 .. container:: paragraph
4632 Launching an application is done by calling the script with
4633 only the application name and any CLI arguments for the
4634 application. For instance, starting the ``ws-echo``
4635 application with port ``8888``:
4637 .. container:: listingblock
4639 .. container:: content
4643 apexApps.sh ws-echo -p 8888
4645 Application: Create Event Templates
4646 -----------------------------------
4648 .. container:: paragraph
4650 **Status: Experimental**
4652 .. container:: paragraph
4654 This application takes a policy model (JSON or XML encoded)
4655 and generates templates for events in JSON format. This can
4656 help when a policy defines rather complex trigger or action
4657 events or complex events between states. The application can
4658 produce events for the types: stimuli (policy trigger
4659 events), internal (events between policy states), and
4660 response (action events).
4662 +----------------------------------------------------------------+------------------------------------------------------------------+
4663 | Unix, Cygwin | Windows |
4664 +================================================================+==================================================================+
4665 | .. container:: | .. container:: |
4667 | .. container:: listingblock | .. container:: listingblock |
4669 | .. container:: content | .. container:: content |
4671 | .. code:: | .. code:: |
4673 | # $APEX_HOME/bin/apexApps.sh tpl-event-json [args] | > %APEX_HOME%\bin\apexApps.bat tpl-event-json [args] |
4674 +----------------------------------------------------------------+------------------------------------------------------------------+
4676 .. container:: paragraph
4678 The option ``-h`` provides a help screen.
4680 .. container:: listingblock
4682 .. container:: content
4686 gen-model2event v{release-version} - generates JSON templates for events generated from a policy model
4687 usage: gen-model2event
4688 -h,--help prints this help and usage screen
4689 -m,--model <MODEL-FILE> set the input policy model file
4690 -t,--type <TYPE> set the event type for generation, one of:
4691 stimuli (trigger events), response (action
4692 events), internal (events between states)
4693 -v,--version prints the application version
4695 .. container:: paragraph
4697 The created templates are not valid events, instead they use
4698 some markup for values one will need to change to actual
4699 values. For instance, running the tool with the *Sample
4700 Domain* policy model as:
4702 .. container:: listingblock
4704 .. container:: content
4708 apexApps.sh tpl-event-json -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json -t stimuli
4710 .. container:: paragraph
4712 will produce the following status messages:
4714 .. container:: listingblock
4716 .. container:: content
4720 gen-model2event: starting Event generator
4721 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4724 .. container:: paragraph
4726 and then run the generator application producing two event
4727 templates. The first template is called ``Event0000``.
4729 .. container:: listingblock
4731 .. container:: content
4736 "name" : "Event0000",
4737 "nameSpace" : "org.onap.policy.apex.sample.events",
4738 "version" : "0.0.1",
4739 "source" : "Outside",
4741 "TestTemperature" : ###double: 0.0###,
4742 "TestTimestamp" : ###long: 0###,
4743 "TestMatchCase" : ###integer: 0###,
4744 "TestSlogan" : "###string###"
4747 .. container:: paragraph
4749 The values for the keys are marked with ``#`` and the
4750 expected type of the value. To create an actual stimuli
4751 event, all these markers need to be change to actual values,
4754 .. container:: listingblock
4756 .. container:: content
4761 "name" : "Event0000",
4762 "nameSpace" : "org.onap.policy.apex.sample.events",
4763 "version" : "0.0.1",
4764 "source" : "Outside",
4766 "TestTemperature" : 25,
4767 "TestTimestamp" : 123456789123456789,
4768 "TestMatchCase" : 1,
4769 "TestSlogan" : "Testing the Match Case with Temperature 25"
4772 Application: Convert a Policy Model to CLI Editor Commands
4773 ----------------------------------------------------------
4775 .. container:: paragraph
4777 **Status: Experimental**
4779 .. container:: paragraph
4781 This application takes a policy model (JSON or XML encoded)
4782 and generates commands for the APEX CLI Editor. This
4783 effectively reverses a policy specification realized with
4786 +-------------------------------------------------------------+---------------------------------------------------------------+
4787 | Unix, Cygwin | Windows |
4788 +=============================================================+===============================================================+
4789 | .. container:: | .. container:: |
4791 | .. container:: listingblock | .. container:: listingblock |
4793 | .. container:: content | .. container:: content |
4795 | .. code:: | .. code:: |
4797 | # $APEX_HOME/bin/apexApps.sh model-2-cli [args] | > %APEX_HOME%\bin\apexApps.bat model-2-cli [args] |
4798 +-------------------------------------------------------------+---------------------------------------------------------------+
4800 .. container:: paragraph
4802 The option ``-h`` provides a help screen.
4804 .. container:: listingblock
4806 .. container:: content
4810 usage: gen-model2cli
4811 -h,--help prints this help and usage screen
4812 -m,--model <MODEL-FILE> set the input policy model file
4813 -sv,--skip-validation switch of validation of the input file
4814 -v,--version prints the application version
4816 .. container:: paragraph
4818 For instance, running the tool with the *Sample Domain*
4821 .. container:: listingblock
4823 .. container:: content
4827 apexApps.sh model-2-cli -m $APEX_HOME/examples/models/SampleDomain/SamplePolicyModelJAVA.json
4829 .. container:: paragraph
4831 will produce the following status messages:
4833 .. container:: listingblock
4835 .. container:: content
4839 gen-model2cli: starting CLI generator
4840 --> model file: examples/models/SampleDomain/SamplePolicyModelJAVA.json
4842 .. container:: paragraph
4844 and then run the generator application producing all CLI
4845 Editor commands and printing them to standard out.
4847 Application: Websocket Clients (Echo and Console)
4848 -------------------------------------------------
4850 .. container:: paragraph
4852 **Status: Production**
4854 .. container:: paragraph
4856 The application launcher also provides a Websocket echo
4857 client and a Websocket console client. The echo client
4858 connects to APEX and prints all events it receives from
4859 APEX. The console client connects to APEX, reads input from
4860 the command line, and sends this input as events to APEX.
4862 +------------------------------------------------------------+--------------------------------------------------------------+
4863 | Unix, Cygwin | Windows |
4864 +============================================================+==============================================================+
4865 | .. container:: | .. container:: |
4867 | .. container:: listingblock | .. container:: listingblock |
4869 | .. container:: content | .. container:: content |
4871 | .. code:: | .. code:: |
4873 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
4874 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
4875 +------------------------------------------------------------+--------------------------------------------------------------+
4877 .. container:: paragraph
4879 The arguments are the same for both applications:
4881 .. container:: ulist
4883 - ``-p`` defines the Websocket port to connect to (defaults
4886 - ``-s`` defines the host on which a Websocket server is
4887 running (defaults to ``localhost``)
4889 .. container:: paragraph
4891 A discussion on how to use these two applications to build
4892 an APEX system is detailed HowTo-Websockets.
4899 .. container:: paragraph
4901 Consider a scenario where a supermarket chain called
4902 *HyperM* controls how it sells items in a policy-based
4903 manner. Each time an item is processed by *HyperM*'s
4904 point-of-sale (PoS) system an event is generated and
4905 published about that item of stock being sold. This event
4906 can then be used to update stock levels, etc..
4908 .. container:: paragraph
4910 *HyperM* want to extend this approach to allow some checks
4911 to be performed before the sale can be completed. This can
4912 be achieved by requesting a policy-controlled decision as
4913 each item is processed by for sale by each PoS system. The
4914 decision process is integrated with *HyperM*'s other IT
4915 systems that manage stock control, sourcing and purchasing,
4916 personnel systems, etc.
4918 .. container:: paragraph
4920 In this document we will show how APEX and APEX Policies can
4921 be used to achieve this, starting with a simple policy,
4922 building up to more complicated policy that demonstrates the
4931 .. container:: paragraph
4933 Each time a PoS system processes a sales item an event
4934 with the following format is emitted:
4936 .. table:: Table 1. Sale Input Event
4938 +----------------------+----------------------+-----------------------+
4939 | Event | Fields | Description |
4940 +======================+======================+=======================+
4941 | SALE_INPUT | time, sale_ID, | Event indicating a |
4942 | | amount, item_ID, | sale of an item is |
4943 | | quantity, | occurring |
4944 | | assistant_ID, | |
4945 | | branch_ID, notes, … | |
4946 +----------------------+----------------------+-----------------------+
4948 .. container:: paragraph
4950 In each ``SALE_INPUT`` event the ``sale_ID`` field is a
4951 unique ID generated by the PoS system. A timestamp for
4952 the event is stored in the ``time`` field. The ``amount``
4953 field refers to the value of the item(s) to be sold (in
4954 cents). The ``item_ID`` field is a unique identifier for
4955 each item type, and can be used to retrieve more
4956 information about the item from *HyperM*'s stock control
4957 system. The ``quantity`` field refers to the quantity of
4958 the item to be sold. The ``assistant_ID`` field is a
4959 unique identifier for the PoS operator, and can be used
4960 to retrieve more information about the operator from the
4961 *HyperM*'s personnel system. Since *HyperM* has many
4962 branches the ``branch_ID`` identifies the shop. The
4963 ``notes`` field contains arbitrary notes about the sale.
4965 Sales Decision Event
4966 ####################
4968 .. container:: paragraph
4970 After a ``SALE_INPUT`` event is emitted by the PoS system
4971 *HyperM*'s policy-based controlled sales checking system
4972 emits a Sale Authorization Event indicating whether the
4973 sale is authorized or denied. The PoS system can then
4974 listen for this event before continuing with the sale.
4976 .. table:: Table 2. Sale Authorisation Event
4978 +----------------------+----------------------+-----------------------+
4979 | Event | Fields | Description |
4980 +======================+======================+=======================+
4981 | SALE_AUTH | sale_ID, time, | Event indicating a |
4982 | | authorized, amount, | sale of an item is |
4983 | | item_ID, quantity, | authorized or denied |
4984 | | assistant_ID, | |
4985 | | branch_ID, notes, | |
4987 +----------------------+----------------------+-----------------------+
4989 .. container:: paragraph
4991 In each ``SALE_AUTH`` event the ``sale_ID`` field is
4992 copied from the ``SALE_INPUT`` event that trigger the
4993 decision request. The ``SALE_AUTH`` event is also
4994 timestamped using the ``time`` field, and a field called
4995 ``authorised`` is set to ``true`` or ``false`` depending
4996 on whether the sale is authorized or denied. The
4997 ``message`` field carries an optional message about why a
4998 sale was not authorized. The other fields from the
4999 ``SALE_INPUT`` event are also included for completeness.
5001 Stock Control: Items
5002 ####################
5004 .. container:: paragraph
5006 *HyperM* maintains information about each item for sale
5007 in a database table called ``ITEMS``.
5009 .. table:: Table 3. Items Database
5011 +----------------------+----------------------+-----------------------+
5012 | Table | Fields | Description |
5013 +======================+======================+=======================+
5014 | ITEMS | item_ID, | Database table |
5015 | | description, | describing each item |
5016 | | cost_price, barcode, | for sale |
5017 | | supplier_ID, | |
5018 | | category, … | |
5019 +----------------------+----------------------+-----------------------+
5021 .. container:: paragraph
5023 The database table ``ITEMS`` has a row for each items
5024 that *HyperM* sells. Each item is identified by an
5025 ``item_ID`` value. The ``description`` field stores a
5026 description of the item. The cost price of the item is
5027 given in ``cost_price``. The barcode of the item is
5028 encoded in ``barcode``, while the item supplier is
5029 identified by ``supplier_ID``. Items may also be
5030 classified into categories using the ``category`` field.
5031 Useful categories might include: ``soft drinks``,
5032 ``alcoholic drinks``, ``cigarettes``, ``knives``,
5033 ``confectionery``, ``bakery``, ``fruit&vegetables``,
5036 Personnel System: Assistants
5037 ############################
5039 .. table:: Table 4. Assistants Database
5041 +----------------------+----------------------+-----------------------+
5042 | Table | Fields | Description |
5043 +======================+======================+=======================+
5044 | ASSISTANTS | assistant_ID, | Database table |
5045 | | surname, firstname, | describing each |
5046 | | middlename, age, | *HyperM* sales |
5047 | | grade, phone_number, | assistant |
5049 +----------------------+----------------------+-----------------------+
5051 .. container:: paragraph
5053 The database table ``ASSISTANTS`` has a row for each
5054 sales assistant employed by *HyperM*. Each assistant is
5055 identified by an ``assistant_ID`` value, with their name
5056 given in the ``firstname``, ``middlename`` and
5057 ``surname`` fields. The assistant’s age in years is given
5058 in ``age``, while their phone number is contained in the
5059 ``phone_number`` field. The assistant’s grade is encoded
5060 in ``grade``. Useful values for ``grade`` might include:
5061 ``trainee``, ``operator``, ``supervisor``, etc..
5064 ####################
5066 .. table:: Table 5. Branches Database
5068 +----------------------+----------------------+-----------------------+
5069 | Table | Fields | Description |
5070 +======================+======================+=======================+
5071 | BRANCHES | branch_ID, | Database table |
5072 | | branch_Name, | describing each |
5073 | | category, street, | *HyperM* branch |
5074 | | city, country, | |
5075 | | postcode, … | |
5076 +----------------------+----------------------+-----------------------+
5078 .. container:: paragraph
5080 *HyperM* operates a number of branches. Each branch is
5081 described in the ``BRANCHES`` database table. Each branch
5082 is identified by a ``branch_ID``, with a branch name
5083 given in ``branch_Name``. The address for the branch is
5084 encoded in ``street``, ``city``, ``country`` and
5085 ``postcode``. The branch category is given in the
5086 ``category`` field. Useful values for ``category`` might
5087 include: ``Small``, ``Large``, ``Super``, ``Hyper``,
5095 .. container:: paragraph
5097 For the first version of our policy, let’s start with
5098 something simple. Let us assume that there exists some
5099 restriction that alcohol products cannot be sold before
5100 11:30am. In this section we will go through the necessary
5101 steps to define a policy that can enforce this for
5104 .. container:: ulist
5106 - Alcohol cannot be sold before 11:30am.
5108 Create the an new empty Policy Model ``MyFirstPolicyModel``
5109 ###########################################################
5111 .. container:: paragraph
5113 Since an organisation like *HyperM* may have many
5114 policies covering many different domains, policies should
5115 be grouped into policy sets. In order to edit or deploy a
5116 policy, or policy set, the definition of the policy(ies)
5117 and all required events, tasks, states, etc., are grouped
5118 together into a 'Policy Model'. An organization might
5119 define many Policy Models, each containing a different
5122 .. container:: paragraph
5124 So the first step is to create a new empty Policy Model
5125 called ``MyFirstPolicyModel``. Using the APEX Policy
5126 Editor, click on the 'File' menus and select 'New'. Then
5127 define our new policy model called
5128 ``MyFirstPolicyModel``. Use the 'Generate UUID' button to
5129 create a new unique ID for the policy model, and fill in
5130 a description for the policy model. Press the ``Submit``
5131 button to save your changes.
5133 .. container:: imageblock
5135 .. container:: content
5137 |File > New to create a new Policy Model|
5139 .. container:: title
5141 Figure 4. Create a new Policy Model 1/2
5143 .. container:: imageblock
5145 .. container:: content
5147 |Create a new Policy Model|
5149 .. container:: title
5151 Figure 5. Create a new Policy Model 2/2
5153 Create the input event ``SALE_INPUT`` and the output event ``SALE_AUTH``
5154 ########################################################################
5156 .. container:: paragraph
5158 Using the APEX Policy Editor, click on the 'Events' tab.
5159 In the 'Events' pane, right click and select 'New':
5161 .. container:: imageblock
5163 .. container:: content
5165 |Right click to create a new event|
5167 .. container:: title
5169 Figure 6. Create a new Event type
5171 .. container:: paragraph
5173 Create a new event type called ``SALE_INPUT``. Use the
5174 'Generate UUID' button to create a new unique ID for the
5175 event type, and fill in a description for the event. Add
5176 a namespace, e.g. ``com.hyperm``. We can add hard-coded
5177 strings for the ``Source`` and ``Target``, e.g. ``POS``
5178 and ``APEX``. At this stage we will not add any parameter
5179 fields, we will leave this until later. Use the
5180 ``Submit`` button to create the event.
5182 .. container:: imageblock
5184 .. container:: content
5186 |Fill in the necessary information for the
5187 'SALE_INPUT' event and click 'Submit'|
5189 .. container:: title
5191 Figure 7. Populate the ``SALE_INPUT`` event
5193 .. container:: paragraph
5195 Repeat the same steps for a new event type called
5196 ``SALE_AUTH``. Just use ``APEX`` as source and ``POS`` as
5197 target, since this is the output event coming from APEX
5198 going to the sales point.
5200 .. container:: paragraph
5202 Before we can add parameter fields to an event we must
5203 first define APEX Context Item Schemas that can be used
5206 .. container:: paragraph
5208 To create new item schemas, click on the 'Context Item
5209 Schemas' tab. In that 'Context Item Schemas' pane, right
5210 click and select 'Create new ContextSchema'.
5212 .. container:: imageblock
5214 .. container:: content
5216 |Right click to create a new Item Schema|
5218 .. container:: title
5220 Figure 8. Create new Data Types
5222 .. container:: paragraph
5224 Create item schemas with the following characteristics,
5225 each with its own unique UUID:
5227 .. table:: Table 6. Item Schemas
5229 +-------------------+-----------------+-----------------+----------------------+
5230 | Name | Schema Flavour | Schema | Description |
5231 | | | Definition | |
5232 +===================+=================+=================+======================+
5233 | timestamp_type | Java | java.lang.Long | A type for |
5234 | | | | ``time`` values |
5235 +-------------------+-----------------+-----------------+----------------------+
5236 | sale_ID_type | Java | java.lang.Long | A type for |
5237 | | | | ``sale_ID`` |
5239 +-------------------+-----------------+-----------------+----------------------+
5240 | price_type | Java | java.lang.Long | A type for |
5241 | | | | ``amount``/``price`` |
5243 +-------------------+-----------------+-----------------+----------------------+
5244 | item_ID_type | Java | java.lang.Long | A type for |
5245 | | | | ``item_ID`` |
5247 +-------------------+-----------------+-----------------+----------------------+
5248 | assistant_ID_type | Java | java.lang.Long | A type for |
5249 | | | | ``assistant_ID`` |
5251 +-------------------+-----------------+-----------------+----------------------+
5252 | quantity_type | Java | java.lang.Integ | A type for |
5253 | | | er | ``quantity`` |
5255 +-------------------+-----------------+-----------------+----------------------+
5256 | branch_ID_type | Java | java.lang.Long | A type for |
5257 | | | | ``branch_ID`` |
5259 +-------------------+-----------------+-----------------+----------------------+
5260 | notes_type | Java | java.lang.Strin | A type for |
5261 | | | g | ``notes`` |
5263 +-------------------+-----------------+-----------------+----------------------+
5264 | authorised_type | Java | java.lang.Boole | A type for |
5265 | | | an | ``authorised`` |
5267 +-------------------+-----------------+-----------------+----------------------+
5268 | message_type | Java | java.lang.Strin | A type for |
5269 | | | g | ``message`` |
5271 +-------------------+-----------------+-----------------+----------------------+
5273 .. container:: imageblock
5275 .. container:: content
5277 |Create a new Item Schema|
5279 .. container:: title
5281 Figure 9. Create new Item Schemas
5283 .. container:: paragraph
5285 The item schemas can now be seen on the 'Context Item
5286 Schemas' tab, and can be updated at any time by
5287 right-clicking on the item schemas on the 'Context Item
5288 Schemas' tab. Now we can go back to the event definitions
5289 for ``SALE_INPUT`` and ``SALE_AUTH`` and add some
5294 .. container:: title
5298 .. container:: paragraph
5300 APEX natively supports schema definitions in ``Java`` and ``Avro``.
5302 .. container:: paragraph
5304 ``Java`` schema definitions are simply the name of a Java Class. There are some restrictions:
5306 .. container:: ulist
5308 - the class must be instantiatable, i.e. not an Java interface or abstract class
5310 - primitive types are not supported, i.e. use ``java.lang.Integer`` instead of ``int``, etc.
5312 - it must be possible to find the class, i.e. the class must be contained in the Java classpath.
5314 .. container:: paragraph
5316 ``Avro`` schema definitions can be any valid `Avro <https://avro.apache.org/docs/current/spec.html>`__
5317 schema. For events using fields defined with ``Avro`` schemas, any incoming event containing that field must
5318 contain a value that conforms to the Avro schema.
5320 .. container:: paragraph
5322 Click on the 'Events' tab, then right click the
5323 ``SALE_INPUT`` row and select 'Edit Event
5324 :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`
5325 event add the following event parameters:
5327 .. table:: Table 7. Event Parameter Fields for the ``SALE_INPUT`` Event
5329 +----------------------+----------------------+-----------------------+
5330 | Parameter Name | Parameter Type | Optional |
5331 +======================+======================+=======================+
5332 | time | timestamp_type | no |
5333 +----------------------+----------------------+-----------------------+
5334 | sale_ID | sale_ID_type | no |
5335 +----------------------+----------------------+-----------------------+
5336 | amount | price_type | no |
5337 +----------------------+----------------------+-----------------------+
5338 | item_ID | item_ID_type | no |
5339 +----------------------+----------------------+-----------------------+
5340 | quantity | quantity_type | no |
5341 +----------------------+----------------------+-----------------------+
5342 | assistant_ID | assistant_ID_type | no |
5343 +----------------------+----------------------+-----------------------+
5344 | branch_ID | branch_ID_type | no |
5345 +----------------------+----------------------+-----------------------+
5346 | notes | notes_type | *yes* |
5347 +----------------------+----------------------+-----------------------+
5349 .. container:: paragraph
5351 Remember to click the 'Submit' button at the bottom of
5352 the event definition pane.
5355 Optional Fields in APEX Events
5356 Parameter fields can be *optional* in events. If a parameter is not marked as *optional* then by default it
5357 is *mandatory*, so it must appear in any input event passed to APEX. If an *optional* field is not set
5358 for an output event then value will be set to ``null``.
5360 .. container:: imageblock
5362 .. container:: content
5364 |Add new event parameters to an event|
5366 .. container:: title
5368 Figure 10. Add typed parameter fields to an event
5370 .. container:: paragraph
5372 Select the ``SALE_AUTH`` event and add the following
5375 .. table:: Table 8. Event Parameter Fields for the ``SALE_AUTH`` Event
5377 +----------------------+----------------------+-----------------------+
5378 | Parameter Name | Parameter Type | no |
5379 +======================+======================+=======================+
5380 | sale_ID | sale_ID_type | no |
5381 +----------------------+----------------------+-----------------------+
5382 | time | timestamp_type | no |
5383 +----------------------+----------------------+-----------------------+
5384 | authorised | authorised_type | no |
5385 +----------------------+----------------------+-----------------------+
5386 | message | message_type | *yes* |
5387 +----------------------+----------------------+-----------------------+
5388 | amount | price_type | no |
5389 +----------------------+----------------------+-----------------------+
5390 | item_ID | item_ID_type | no |
5391 +----------------------+----------------------+-----------------------+
5392 | assistant_ID | assistant_ID_type | no |
5393 +----------------------+----------------------+-----------------------+
5394 | quantity | quantity_type | no |
5395 +----------------------+----------------------+-----------------------+
5396 | branch_ID | branch_ID_type | no |
5397 +----------------------+----------------------+-----------------------+
5398 | notes | notes_type | *yes* |
5399 +----------------------+----------------------+-----------------------+
5401 .. container:: paragraph
5403 Remember to click the 'Submit' button at the bottom of
5404 the event definition pane.
5406 .. container:: paragraph
5408 The events for our policy are now defined.
5410 Create a new Policy and add the *"No Booze before 11:30"* check
5411 ###############################################################
5413 .. container:: paragraph
5415 APEX policies are defined using a state-machine model.
5416 Each policy comprises one or more *states* that can be
5417 individually executed. Where there is more than one
5418 *state* the states are chained together to form a
5419 `Directed Acyclic Graph
5420 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__
5421 of states. A *state* is triggered by passing it a single
5422 input (or 'trigger') event and once executed each state
5423 then emits an output event. For each *state* the logic
5424 for the *state* is embedded in one or more *tasks*. Each
5425 *task* contains specific *task logic* that is executed by
5426 the APEX execution environment each time the *task* is
5427 invoked. Where there is more than one *task* in a *state*
5428 then the *state* also defines some *task selection logic*
5429 to select an appropriate task each time the *state* is
5432 .. container:: paragraph
5434 Therefore, to create a new policy we must first define
5437 .. container:: paragraph
5439 To create a new Task click on the 'Tasks' tab. In the
5440 'Tasks' pane, right click and select 'Create new Task'.
5441 Create a new Task called ``MorningBoozeCheck``. Use the
5442 'Generate UUID' button to create a new unique ID for the
5443 task, and fill in a description for the task.
5445 .. container:: imageblock
5447 .. container:: content
5449 |Right click to create a new task|
5451 .. container:: title
5453 Figure 11. Create a new Task
5455 .. container:: paragraph
5457 Tasks are configured with a set of *input fields* and a
5458 set of *output fields*. To add new input/output fields
5459 for a task use the 'Add Task Input Field' and 'Add Task
5460 Output Field' button. The list of input and out fields to
5461 add for the ``MorningBoozeCheck`` task are given below.
5462 The input fields are drawn from the parameters in the
5463 state’s input event, and the task’s output fields are
5464 used to populate the state’s output event. The task’s
5465 input and output fields must be a subset of the event
5466 parameters defined for the input and output events for
5467 any state that uses that task. (You may have noticed that
5468 the input and output fields for the ``MorningBoozeCheck``
5469 task have the exact same names and reuse the item schemas
5470 that we used for the parameters in the ``SALE_INPUT`` and
5471 ``SALE_AUTH`` events respectively).
5473 .. table:: Table 9. Input fields for ``MorningBoozeCheck`` task
5475 +-----------------------------------+-----------------------------------+
5476 | Parameter Name | Parameter Type |
5477 +===================================+===================================+
5478 | time | timestamp_type |
5479 +-----------------------------------+-----------------------------------+
5480 | sale_ID | sale_ID_type |
5481 +-----------------------------------+-----------------------------------+
5482 | amount | price_type |
5483 +-----------------------------------+-----------------------------------+
5484 | item_ID | item_ID_type |
5485 +-----------------------------------+-----------------------------------+
5486 | quantity | quantity_type |
5487 +-----------------------------------+-----------------------------------+
5488 | assistant_ID | assistant_ID_type |
5489 +-----------------------------------+-----------------------------------+
5490 | branch_ID | branch_ID_type |
5491 +-----------------------------------+-----------------------------------+
5492 | notes | notes_type |
5493 +-----------------------------------+-----------------------------------+
5495 .. table:: Table 10. Output fields for ``MorningBoozeCheck`` task
5497 +-----------------------------------+-----------------------------------+
5498 | Parameter Name | Parameter Type |
5499 +===================================+===================================+
5500 | sale_ID | sale_ID_type |
5501 +-----------------------------------+-----------------------------------+
5502 | time | timestamp_type |
5503 +-----------------------------------+-----------------------------------+
5504 | authorised | authorised_type |
5505 +-----------------------------------+-----------------------------------+
5506 | message | message_type |
5507 +-----------------------------------+-----------------------------------+
5508 | amount | price_type |
5509 +-----------------------------------+-----------------------------------+
5510 | item_ID | item_ID_type |
5511 +-----------------------------------+-----------------------------------+
5512 | assistant_ID | assistant_ID_type |
5513 +-----------------------------------+-----------------------------------+
5514 | quantity | quantity_type |
5515 +-----------------------------------+-----------------------------------+
5516 | branch_ID | branch_ID_type |
5517 +-----------------------------------+-----------------------------------+
5518 | notes | notes_type |
5519 +-----------------------------------+-----------------------------------+
5521 .. container:: imageblock
5523 .. container:: content
5525 |Add input and out fields for the task|
5527 .. container:: title
5529 Figure 12. Add input and out fields for the Task
5531 .. container:: paragraph
5533 Each task must include some 'Task Logic' that implements
5534 the behaviour for the task. Task logic can be defined in
5535 a number of different ways using a choice of languages.
5536 For this task we will author the logic using the
5537 Java-like scripting language called
5538 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__.
5540 .. container:: paragraph
5542 For simplicity use the following code for the task logic.
5543 Paste the script text into the 'Task Logic' box, and use
5544 "MVEL" as the 'Task Logic Type / Flavour'.
5546 .. container:: paragraph
5548 This logic assumes that all items with ``item_ID``
5549 between 1000 and 2000 contain alcohol, which is not very
5550 realistic, but we will see a better approach for this
5551 later. It also uses the standard ``Java`` time utilities
5552 to check if the current time is between ``00:00:00 GMT``
5553 and ``11:30:00 GMT``. For a detailed guide to how to
5554 write your own logic in
5555 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
5556 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
5557 of the other supported languages please refer to APEX
5560 .. container:: listingblock
5562 .. container:: title
5564 MVEL code for the ``MorningBoozeCheck`` task
5566 .. container:: content
5571 * ============LICENSE_START=======================================================
5572 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5573 * ================================================================================
5574 * Licensed under the Apache License, Version 2.0 (the "License");
5575 * you may not use this file except in compliance with the License.
5576 * You may obtain a copy of the License at
5578 * http://www.apache.org/licenses/LICENSE-2.0
5580 * Unless required by applicable law or agreed to in writing, software
5581 * distributed under the License is distributed on an "AS IS" BASIS,
5582 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5583 * See the License for the specific language governing permissions and
5584 * limitations under the License.
5586 * SPDX-License-Identifier: Apache-2.0
5587 * ============LICENSE_END=========================================================
5589 import java.util.Date;
5590 import java.util.Calendar;
5591 import java.util.TimeZone;
5592 import java.text.SimpleDateFormat;
5594 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
5596 outFields.put("amount" , inFields.get("amount"));
5597 outFields.put("assistant_ID", inFields.get("assistant_ID"));
5598 outFields.put("notes" , inFields.get("notes"));
5599 outFields.put("quantity" , inFields.get("quantity"));
5600 outFields.put("branch_ID" , inFields.get("branch_ID"));
5601 outFields.put("item_ID" , inFields.get("item_ID"));
5602 outFields.put("time" , inFields.get("time"));
5603 outFields.put("sale_ID" , inFields.get("sale_ID"));
5605 item_id = inFields.get("item_ID");
5607 //The events used later to test this task use GMT timezone!
5608 gmt = TimeZone.getTimeZone("GMT");
5609 timenow = Calendar.getInstance(gmt);
5610 df = new SimpleDateFormat("HH:mm:ss z");
5611 df.setTimeZone(gmt);
5612 timenow.setTimeInMillis(inFields.get("time"));
5614 midnight = timenow.clone();
5616 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5617 timenow.get(Calendar.DATE),0,0,0);
5618 eleven30 = timenow.clone();
5620 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
5621 timenow.get(Calendar.DATE),11,30,0);
5623 itemisalcohol = false;
5624 if(item_id != null && item_id >=1000 && item_id < 2000)
5625 itemisalcohol = true;
5628 && timenow.after(midnight) && timenow.before(eleven30)){
5629 outFields.put("authorised", false);
5630 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
5631 " for time "+df.format(timenow.getTime())+
5632 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
5633 " and "+df.format(eleven30.getTime()));
5637 outFields.put("authorised", true);
5638 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
5639 " for time "+df.format(timenow.getTime()));
5644 This task checks if a sale request is for an item that is an alcoholic drink.
5645 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5646 authorised. Otherwise the sale is authorised.
5647 In this implementation we assume that items with item_ID value between 1000 and
5648 2000 are all alcoholic drinks :-)
5651 .. container:: imageblock
5653 .. container:: content
5655 |Add task logic the task|
5657 .. container:: title
5659 Figure 13. Add Task Logic the Task
5661 .. container:: paragraph
5663 An alternative version of the same logic is available in
5664 JavaScript. Just use "JAVASCRIPT" as the 'Task Logic Type
5667 .. container:: listingblock
5669 .. container:: title
5671 Javascript alternative for the ``MorningBoozeCheck``
5674 .. container:: content
5679 * ============LICENSE_START=======================================================
5680 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
5681 * ================================================================================
5682 * Licensed under the Apache License, Version 2.0 (the "License");
5683 * you may not use this file except in compliance with the License.
5684 * You may obtain a copy of the License at
5686 * http://www.apache.org/licenses/LICENSE-2.0
5688 * Unless required by applicable law or agreed to in writing, software
5689 * distributed under the License is distributed on an "AS IS" BASIS,
5690 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5691 * See the License for the specific language governing permissions and
5692 * limitations under the License.
5694 * SPDX-License-Identifier: Apache-2.0
5695 * ============LICENSE_END=========================================================
5698 var returnValueType = Java.type("java.lang.Boolean");
5699 var returnValue = new returnValueType(true);
5701 // Load compatibility script for imports etc
5702 load("nashorn:mozilla_compat.js");
5703 importPackage(java.text);
5704 importClass(java.text.SimpleDateFormat);
5706 executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'");
5708 executor.outFields.put("amount" , executor.inFields.get("amount"));
5709 executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID"));
5710 executor.outFields.put("notes" , executor.inFields.get("notes"));
5711 executor.outFields.put("quantity" , executor.inFields.get("quantity"));
5712 executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID"));
5713 executor.outFields.put("item_ID" , executor.inFields.get("item_ID"));
5714 executor.outFields.put("time" , executor.inFields.get("time"));
5715 executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID"));
5717 item_id = executor.inFields.get("item_ID");
5719 //All times in this script are in GMT/UTC since the policy and events assume time is in GMT.
5720 var timenow_gmt = new Date(Number(executor.inFields.get("time")));
5722 var midnight_gmt = new Date(Number(executor.inFields.get("time")));
5723 midnight_gmt.setUTCHours(0,0,0,0);
5725 var eleven30_gmt = new Date(Number(executor.inFields.get("time")));
5726 eleven30_gmt.setUTCHours(11,30,0,0);
5728 var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z");
5730 var itemisalcohol = false;
5731 if(item_id != null && item_id >=1000 && item_id < 2000)
5732 itemisalcohol = true;
5735 && timenow_gmt.getTime() >= midnight_gmt.getTime()
5736 && timenow_gmt.getTime() < eleven30_gmt.getTime()) {
5738 executor.outFields.put("authorised", false);
5739 executor.outFields.put("message", "Sale not authorised by policy task " +
5740 executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) +
5741 ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) +
5742 " and " + timeformatter.format(eleven30_gmt.getTime()));
5745 executor.outFields.put("authorised", true);
5746 executor.outFields.put("message", "Sale authorised by policy task " +
5747 executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime()));
5751 This task checks if a sale request is for an item that is an alcoholic drink.
5752 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
5753 authorised. Otherwise the sale is authorised.
5754 In this implementation we assume that items with item_ID value between 1000 and
5755 2000 are all alcoholic drinks :-)
5758 .. container:: paragraph
5760 The task definition is now complete so click the 'Submit'
5761 button to save the task. The task can now be seen on the
5762 'Tasks' tab, and can be updated at any time by
5763 right-clicking on the task on the 'Task' tab. Now that we
5764 have created our task, we can can create a policy that
5767 .. container:: paragraph
5769 To create a new Policy click on the 'Policies' tab. In
5770 the 'Policies' pane, right click and select 'Create new
5773 .. container:: paragraph
5775 Create a new Policy called ``MyFirstPolicy``. Use the
5776 'Generate UUID' button to create a new unique ID for the
5777 policy, and fill in a description for the policy. Use
5778 'FREEFORM' as the 'Policy Flavour'.
5780 .. container:: paragraph
5782 Each policy must have at least one state. Since this is
5783 'freeform' policy we can add as many states as we wish.
5784 Let’s start with one state. Add a new state called
5785 ``BoozeAuthDecide`` to this ``MyFirstPolicy`` policy
5786 using the 'Add new State' button after filling in the
5787 name of our new state.
5789 .. container:: imageblock
5791 .. container:: content
5793 |Create a new policy|
5795 .. container:: title
5797 Figure 14. Create a new Policy
5799 .. container:: paragraph
5801 Each state must uses one input event type. For this new
5802 state select the ``SALE_INPUT`` event as the input event.
5804 .. container:: paragraph
5806 Each policy must define a 'First State' and a 'Policy
5807 Trigger Event'. The 'Policy Trigger Event' is the input
5808 event for the policy as a whole. This event is then
5809 passed to the first state in the chain of states in the
5810 policy, therefore the 'Policy Trigger Event' will be the
5811 input event for the first state. Each policy can only
5812 have one 'First State'. For our ``MyFirstPolicy`` policy,
5813 select ``BoozeAuthDecide`` as the 'First State'. This
5814 will automatically select ``SALE_INPUT`` as the 'Policy
5815 Trigger Event' for our policy.
5817 .. container:: imageblock
5819 .. container:: content
5823 .. container:: title
5825 Figure 15. Create a new State
5827 .. container:: paragraph
5829 In this case we will create a reference the pre-existing
5830 ``MorningBoozeCheck`` task that we defined above using
5831 the 'Add New Task' button. Select the
5832 ``MorningBoozeCheck`` task, and use the name of the task
5833 as the 'Local Name' for the task.
5835 .. container:: paragraph
5837 in the case where a state references more than one task,
5838 a 'Default Task' must be selected for the state and some
5839 logic ('Task Selection Logic') must be specified to
5840 select the appropriate task at execution time. Since our
5841 new state ``BoozeAuthDecide`` only has one task the
5842 default task is automatically selected and no 'Task
5843 Selection Logic' is required.
5846 .. container:: title
5848 State Output Mappings
5850 .. container:: paragraph
5852 In a 'Policy' 'State' a 'State Output Mapping' has 3 roles:
5853 1) Select which 'State' should be executed next, 2) Select
5854 the type of the state’s 'Outgoing Event', and 3)
5855 Populate the state’s 'Outgoing Event'. This is how states are
5856 chained together to form a (`Directed Acyclic Graph
5857 (DAG) <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`__ )
5858 of states. The final state(s) of a policy are those that do
5859 not select any 'next' state. Since a 'State' can only
5860 accept a single type of event, the type of the event emitted
5861 by a previous 'State' must be match the incoming event type
5862 of the next 'State'. This is also how the last state(s) in
5863 a policy can emit events of different types. The 'State
5864 Output Mapping' is also responsible for taking the
5865 fields that are output by the task executed in the state and
5866 populating the state’s output event before it is emitted.
5868 .. container:: paragraph
5870 Each 'Task' referenced in 'State' must have a defined
5871 'Output Mapping' to take the output of the task, select an
5872 'Outgoing Event' type for the state, populate the state’s
5873 outgoing event, and then select the next state to be
5876 .. container:: paragraph
5878 There are 2 basic types of output mappings:
5880 .. container:: olist arabic
5882 #. **Direct Output Mappings** have a single value for
5883 'Next State' and a single value for 'State Output
5884 Event'. The outgoing event for the state is
5885 automatically created, any outgoing event parameters
5886 that were present in the incoming event are copied
5887 into the outgoing event, then any task output fields
5888 that have the same name and type as parameters in the
5889 outgoing event are automatically copied into
5892 #. **Logic-based State Output Mappings / Finalizers**
5893 have some logic defined that dynamically selects
5894 and creates the 'State Outgoing Event', manages
5895 the population of the outgoing event parameters
5896 (perhaps changing or adding to the outputs from the
5897 task), and then dynamically selects the next state to
5898 be executed (if any).
5900 .. container:: paragraph
5902 Each task reference must also have an associated 'Output
5903 State Mapping' so we need an 'Output State Mapping' for
5904 the ``BoozeAuthDecide`` state to use when the
5905 ``MorningBoozeCheck`` task is executed. The simplest type
5906 of output mapping is a 'Direct Output Mapping'.
5908 .. container:: paragraph
5910 Create a new 'Direct Output Mapping' for the state called
5911 ``MorningBoozeCheck_Output_Direct`` using the 'Add New
5912 Direct State Output Mapping' button. Select ``SALE_AUTH``
5913 as the output event and select ``None`` for the next
5914 state value. We can then select this output mapping for
5915 use when the the ``MorningBoozeCheck`` task is executed.
5916 Since there is only state, and only one task for that
5917 state, this output mapping ensures that the
5918 ``BoozeAuthDecide`` state is the only state executed and
5919 the state (and the policy) can only emit events of type
5920 ``SALE_AUTH``. (You may remember that the output fields
5921 for the ``MorningBoozeCheck`` task have the exact same
5922 names and reuse the item schemas that we used for the
5923 parameters in ``SALE_AUTH`` event. The
5924 ``MorningBoozeCheck_Output_Direct`` direct output mapping
5925 can now automatically copy the values from the
5926 ``MorningBoozeCheck`` task directly into outgoing
5927 ``SALE_AUTH`` events.)
5929 .. container:: imageblock
5931 .. container:: content
5933 |Add a Task and Output Mapping|
5935 .. container:: title
5937 Figure 16. Add a Task and Output Mapping
5939 .. container:: paragraph
5941 Click the 'Submit' button to complete the definition of
5942 our ``MyFirstPolicy`` policy. The policy
5943 ``MyFirstPolicy`` can now be seen in the list of policies
5944 on the 'Policies' tab, and can be updated at any time by
5945 right-clicking on the policy on the 'Policies' tab.
5947 .. container:: paragraph
5949 The ``MyFirstPolicyModel``, including our
5950 ``MyFirstPolicy`` policy can now be checked for errors.
5951 Click on the 'Model' menu and select 'Validate'. The
5952 model should validate without any 'Warning' or 'Error'
5953 messages. If you see any 'Error' or 'Warning' messages,
5954 carefully read the message as a hint to find where you
5955 might have made a mistake when defining some aspect of
5958 .. container:: imageblock
5960 .. container:: content
5962 |Validate the policy model for error using the 'Model'
5963 > 'Validate' menu item|
5965 .. container:: title
5967 Figure 17. Validate a Policy Model
5969 .. container:: paragraph
5971 Congratulations, you have now completed your first APEX
5972 policy. The policy model containing our new policy can
5973 now be exported from the editor and saved. Click on the
5974 'File' menu and select 'Download' to save the policy
5975 model in JSON format. The exported policy model is then
5976 available in the directory you selected, for instance
5977 ``$APEX_HOME/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json``.
5978 The exported policy can now be loaded into the APEX
5979 Policy Engine, or can be re-loaded and edited by the APEX
5982 .. container:: imageblock
5984 .. container:: content
5986 |Download the completed policy model using the 'File'
5987 > 'Download' menu item|
5989 .. container:: title
5991 Figure 18. Export a Policy Model
5996 .. container:: paragraph
5998 To start a new APEX Engine you can use the following
5999 configuration. In a full APEX installation you can find
6000 this configuration in
6001 ``$APEX_HOME/examples/config/MyFirstPolicy/1/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
6002 This configuration expects incoming events to be in
6003 ``JSON`` format and to be passed into the APEX Engine
6004 from ``stdin``, and result events will be printed in
6005 ``JSON`` format to ``stdout``. This configuration loads
6006 the policy model stored in the file
6007 'MyFirstPolicyModel_0.0.1.json' as exported from the APEX
6008 Editor. Note, you may need to edit this file to provide
6009 the full path to wherever you stored the exported policy
6012 .. container:: listingblock
6014 .. container:: title
6016 JSON to load and execute *My First Policy*, read input
6017 JSON events from ``stdin``, and emit output events to
6020 .. container:: content
6025 "engineServiceParameters" : {
6026 "name" : "MyFirstPolicyApexEngine",
6027 "version" : "0.0.1",
6029 "instanceCount" : 4,
6030 "deploymentPort" : 12345,
6031 "policyModelFileName" : "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json",
6032 "engineParameters" : {
6033 "executorParameters" : {
6035 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
6038 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
6043 "eventOutputParameters": {
6045 "carrierTechnologyParameters" : {
6046 "carrierTechnology" : "FILE",
6051 "eventProtocolParameters" : {
6052 "eventProtocol" : "JSON"
6056 "eventInputParameters": {
6058 "carrierTechnologyParameters" : {
6059 "carrierTechnology" : "FILE",
6064 "eventProtocolParameters" : {
6065 "eventProtocol" : "JSON"
6071 .. container:: paragraph
6073 To test the policy try paste the following events into
6074 the console as the APEX engine executes:
6076 .. table:: Table 11. Inputs and Outputs when testing *My First Policy*
6078 +------------------------------------------+-------------------------------------------+-----------+
6079 | Input Event (JSON) | Output Event (JSON) | comment |
6080 +==========================================+===========================================+===========+
6081 | .. container:: | .. container:: | Request |
6083 | .. container:: listingblock | .. container:: listingblock | non-alcoh |
6085 | | .. container:: content | item |
6086 | .. container:: content | | (``item_I |
6087 | | .. code:: | D=5123``) |
6089 | .. code:: | { | *10:13:09 |
6090 | | "name": "SALE_AUTH", | * |
6092 | { | "version": "0.0.1", | *Tuesday, |
6093 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | 10 |
6094 | "name" : "SALE_INPUT", | "source": "", | January |
6095 | "version": "0.0.1", | "target": "", | 2017*. |
6096 | "time" : 1483351989000, | "amount": 299, | Sale is |
6097 | "sale_ID": 99999991, | "assistant_ID": 23, | authorize |
6098 | "amount": 299, | "authorised": true, | d. |
6099 | "item_ID": 5123, | "branch_ID": 1, | |
6100 | "quantity": 1, | "item_ID": 5123, | |
6101 | "assistant_ID": 23, | "message": "Sale authorised | |
6102 | "branch_ID": 1, | by policy task MorningBo | |
6103 | "notes": "Special Offer!!" | ozeCheck for time 10:13:09 | |
6105 | | "notes": "Special Offer!!", | |
6106 | | "quantity": 1, | |
6107 | | "sale_ID": 99999991, | |
6108 | | "time": 1483351989000 | |
6113 +------------------------------------------+-------------------------------------------+-----------+
6114 | .. container:: | .. container:: | Request |
6116 | .. container:: listingblock | .. container:: listingblock | alcohol |
6118 | .. container:: content | .. container:: content | (``item_I |
6120 | .. code:: | .. code:: | at |
6123 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | on |
6124 | "name": "SALE_INPUT", | "name": "SALE_AUTH", | *Monday, |
6125 | "version": "0.0.1", | "source": "", | 02 |
6126 | "time": 1483346466000, | "target": "", | January |
6127 | "sale_ID": 99999992, | "amount": 1249, | 2017*. |
6128 | "version": "0.0.1", | "assistant_ID": 12, | |
6129 | "amount": 1249, | "authorised": false, | Sale is |
6130 | "item_ID": 1012, | "branch_ID": 2, | not |
6131 | "quantity": 1, | "item_ID": 1012, | authorize |
6132 | "assistant_ID": 12, | "message": "Sale not | d. |
6133 | "branch_ID": 2 | authorised by policy task | |
6134 | } | MorningBoozeCheck for time | |
6135 | | 08:41:06 GMT. Alcohol can | |
6136 | | not be sold between | |
6137 | | 00:00:00 GMT and 11:30:00 | |
6139 | | "notes": null, | |
6140 | | "quantity": 1, | |
6141 | | "sale_ID": 99999992, | |
6142 | | "time": 1483346466000 | |
6144 +------------------------------------------+-------------------------------------------+-----------+
6145 | .. container:: | .. container:: | Request |
6147 | .. container:: listingblock | .. container:: listingblock | alcohol |
6149 | | .. container:: content | D=1943``) |
6150 | .. container:: content | | at |
6151 | | .. code:: | *20:17:13 |
6153 | .. code:: | { | on |
6154 | | "name": "SALE_AUTH", | *Tuesday, |
6155 | { | "version": "0.0.1", | 20 |
6156 | "nameSpace": "com.hyperm", | "nameSpace": "com.hyperm", | December |
6157 | "name" : "SALE_INPUT", | "source": "", | 2016*. |
6158 | "version": "0.0.1", | "target": "", | |
6159 | "time" : 1482265033000, | "amount": 4799, | Sale is |
6160 | "sale_ID": 99999993, | "assistant_ID": 9, | authorize |
6161 | "amount": 4799, | "authorised": true, | d. |
6162 | "item_ID": 1943, | "branch_ID": 3, | |
6163 | "quantity": 2, | "item_ID": 1943, | |
6164 | "assistant_ID": 9, | "message": "Sale authorised | |
6165 | "branch_ID": 3 | by policy task MorningBo | |
6166 | } | ozeCheck for time 20:17:13 | |
6168 | | "notes": null, | |
6169 | | "quantity": 2, | |
6170 | | "sale_ID": 99999993, | |
6171 | | "time": 1482265033000 | |
6173 +------------------------------------------+-------------------------------------------+-----------+
6175 4.3.6. Policy 1 in CLI Editor
6176 #############################
6178 .. container:: paragraph
6180 An equivalent version of the ``MyFirstPolicyModel``
6181 policy model can again be generated using the APEX CLI
6182 editor. A sample APEX CLI script is shown below:
6184 .. container:: listingblock
6186 .. container:: title
6188 APEX CLI Editor code for Policy 1
6190 .. container:: content
6194 #-------------------------------------------------------------------------------
6195 # ============LICENSE_START=======================================================
6196 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
6197 # ================================================================================
6198 # Licensed under the Apache License, Version 2.0 (the "License");
6199 # you may not use this file except in compliance with the License.
6200 # You may obtain a copy of the License at
6202 # http://www.apache.org/licenses/LICENSE-2.0
6204 # Unless required by applicable law or agreed to in writing, software
6205 # distributed under the License is distributed on an "AS IS" BASIS,
6206 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6207 # See the License for the specific language governing permissions and
6208 # limitations under the License.
6210 # SPDX-License-Identifier: Apache-2.0
6211 # ============LICENSE_END=========================================================
6212 #-------------------------------------------------------------------------------
6214 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
6216 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
6218 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
6220 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
6222 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
6224 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
6226 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
6228 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
6230 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
6232 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
6234 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
6236 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
6237 This task checks if the sales request is for an item that contains alcohol.
6238 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
6239 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
6241 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6242 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6243 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6244 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6245 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6246 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6247 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6248 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6249 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6250 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
6251 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6252 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6253 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
6254 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6255 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6256 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
6257 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
6258 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6259 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
6261 * ============LICENSE_START=======================================================
6262 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6263 * ================================================================================
6264 * Licensed under the Apache License, Version 2.0 (the "License");
6265 * you may not use this file except in compliance with the License.
6266 * You may obtain a copy of the License at
6268 * http://www.apache.org/licenses/LICENSE-2.0
6270 * Unless required by applicable law or agreed to in writing, software
6271 * distributed under the License is distributed on an "AS IS" BASIS,
6272 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6273 * See the License for the specific language governing permissions and
6274 * limitations under the License.
6276 * SPDX-License-Identifier: Apache-2.0
6277 * ============LICENSE_END=========================================================
6279 import java.util.Date;
6280 import java.util.Calendar;
6281 import java.util.TimeZone;
6282 import java.text.SimpleDateFormat;
6284 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
6286 outFields.put("amount" , inFields.get("amount"));
6287 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6288 outFields.put("notes" , inFields.get("notes"));
6289 outFields.put("quantity" , inFields.get("quantity"));
6290 outFields.put("branch_ID" , inFields.get("branch_ID"));
6291 outFields.put("item_ID" , inFields.get("item_ID"));
6292 outFields.put("time" , inFields.get("time"));
6293 outFields.put("sale_ID" , inFields.get("sale_ID"));
6295 item_id = inFields.get("item_ID");
6297 //The events used later to test this task use GMT timezone!
6298 gmt = TimeZone.getTimeZone("GMT");
6299 timenow = Calendar.getInstance(gmt);
6300 df = new SimpleDateFormat("HH:mm:ss z");
6301 df.setTimeZone(gmt);
6302 timenow.setTimeInMillis(inFields.get("time"));
6304 midnight = timenow.clone();
6306 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6307 timenow.get(Calendar.DATE),0,0,0);
6308 eleven30 = timenow.clone();
6310 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6311 timenow.get(Calendar.DATE),11,30,0);
6313 itemisalcohol = false;
6314 if(item_id != null && item_id >=1000 && item_id < 2000)
6315 itemisalcohol = true;
6318 && timenow.after(midnight) && timenow.before(eleven30)){
6319 outFields.put("authorised", false);
6320 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6321 " for time "+df.format(timenow.getTime())+
6322 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6323 " and "+df.format(eleven30.getTime()));
6327 outFields.put("authorised", true);
6328 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6329 " for time "+df.format(timenow.getTime()));
6334 This task checks if a sale request is for an item that is an alcoholic drink.
6335 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
6336 authorised. Otherwise the sale is authorised.
6337 In this implementation we assume that items with item_ID value between 1000 and
6338 2000 are all alcoholic drinks :-)
6342 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"
6343 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6344 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6345 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
6346 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6347 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6348 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
6349 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6350 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6351 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6352 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6354 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"
6355 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
6356 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
6357 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
6358 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
6359 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
6360 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
6361 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
6362 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
6365 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
6366 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
6367 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
6368 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
6375 .. container:: paragraph
6377 *HyperM* have just opened a new branch in a different
6378 country, but that country has different rules about when
6379 alcohol can be sold! In this section we will go through
6380 the necessary steps to extend our policy to enforce this
6383 .. container:: ulist
6385 - In some branches alcohol cannot be sold before 1pm,
6386 and not at all on Sundays.
6388 .. container:: paragraph
6390 Although there are a number of ways to accomplish this
6391 the easiest approach for us is to define another task and
6392 then select which task is appropriate at runtime
6393 depending on the branch identifier in the incoming event.
6395 Extend the Policy with the new Scenario
6396 #######################################
6398 .. container:: paragraph
6400 To create a new Task click on the 'Tasks' tab. In the
6401 'Tasks' pane, right click and select 'Create new Task':
6403 .. container:: paragraph
6405 Create a new Task called ``MorningBoozeCheckAlt1``. Use
6406 the 'Generate UUID' button to create a new unique ID for
6407 the task, and fill in a description for the task. Select
6408 the same input and output fields that we used earlier
6409 when we defined the ``MorningBoozeCheck`` task earlier.
6411 .. table:: Table 12. Input fields for ``MorningBoozeCheckAlt1`` task
6413 +-----------------------------------+-----------------------------------+
6414 | Parameter Name | Parameter Type |
6415 +===================================+===================================+
6416 | time | timestamp_type |
6417 +-----------------------------------+-----------------------------------+
6418 | sale_ID | sale_ID_type |
6419 +-----------------------------------+-----------------------------------+
6420 | amount | price_type |
6421 +-----------------------------------+-----------------------------------+
6422 | item_ID | item_ID_type |
6423 +-----------------------------------+-----------------------------------+
6424 | quantity | quantity_type |
6425 +-----------------------------------+-----------------------------------+
6426 | assistant_ID | assistant_ID_type |
6427 +-----------------------------------+-----------------------------------+
6428 | branch_ID | branch_ID_type |
6429 +-----------------------------------+-----------------------------------+
6430 | notes | notes_type |
6431 +-----------------------------------+-----------------------------------+
6433 .. table:: Table 13. Output fields for ``MorningBoozeCheckAlt1`` task
6435 +-----------------------------------+-----------------------------------+
6436 | Parameter Name | Parameter Type |
6437 +===================================+===================================+
6438 | sale_ID | sale_ID_type |
6439 +-----------------------------------+-----------------------------------+
6440 | time | timestamp_type |
6441 +-----------------------------------+-----------------------------------+
6442 | authorised | authorised_type |
6443 +-----------------------------------+-----------------------------------+
6444 | message | message_type |
6445 +-----------------------------------+-----------------------------------+
6446 | amount | price_type |
6447 +-----------------------------------+-----------------------------------+
6448 | item_ID | item_ID_type |
6449 +-----------------------------------+-----------------------------------+
6450 | assistant_ID | assistant_ID_type |
6451 +-----------------------------------+-----------------------------------+
6452 | quantity | quantity_type |
6453 +-----------------------------------+-----------------------------------+
6454 | branch_ID | branch_ID_type |
6455 +-----------------------------------+-----------------------------------+
6456 | notes | notes_type |
6457 +-----------------------------------+-----------------------------------+
6459 .. container:: paragraph
6461 This task also requires some 'Task Logic' to implement
6462 the new behaviour for this task.
6464 .. container:: paragraph
6466 For simplicity use the following code for the task logic.
6467 It again assumes that all items with ``item_ID`` between
6468 1000 and 2000 contain alcohol. We again use the standard
6469 ``Java`` time utilities to check if the current time is
6470 between ``00:00:00 CET`` and ``13:00:00 CET`` or if it is
6473 .. container:: paragraph
6475 For this task we will again author the logic using the
6476 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__
6477 scripting language. Sample task logic code (specified in
6478 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__) is
6479 given below. For a detailed guide to how to write your
6481 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
6482 ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__ or one
6483 of the other supported languages please refer to APEX
6486 .. container:: listingblock
6488 .. container:: title
6490 MVEL code for the ``MorningBoozeCheckAlt1`` task
6492 .. container:: content
6497 * ============LICENSE_START=======================================================
6498 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6499 * ================================================================================
6500 * Licensed under the Apache License, Version 2.0 (the "License");
6501 * you may not use this file except in compliance with the License.
6502 * You may obtain a copy of the License at
6504 * http://www.apache.org/licenses/LICENSE-2.0
6506 * Unless required by applicable law or agreed to in writing, software
6507 * distributed under the License is distributed on an "AS IS" BASIS,
6508 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6509 * See the License for the specific language governing permissions and
6510 * limitations under the License.
6512 * SPDX-License-Identifier: Apache-2.0
6513 * ============LICENSE_END=========================================================
6515 import java.util.Date;
6516 import java.util.Calendar;
6517 import java.util.TimeZone;
6518 import java.text.SimpleDateFormat;
6520 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
6522 outFields.put("amount" , inFields.get("amount"));
6523 outFields.put("assistant_ID", inFields.get("assistant_ID"));
6524 outFields.put("notes" , inFields.get("notes"));
6525 outFields.put("quantity" , inFields.get("quantity"));
6526 outFields.put("branch_ID" , inFields.get("branch_ID"));
6527 outFields.put("item_ID" , inFields.get("item_ID"));
6528 outFields.put("time" , inFields.get("time"));
6529 outFields.put("sale_ID" , inFields.get("sale_ID"));
6531 item_id = inFields.get("item_ID");
6533 //The events used later to test this task use CET timezone!
6534 cet = TimeZone.getTimeZone("CET");
6535 timenow = Calendar.getInstance(cet);
6536 df = new SimpleDateFormat("HH:mm:ss z");
6537 df.setTimeZone(cet);
6538 timenow.setTimeInMillis(inFields.get("time"));
6540 midnight = timenow.clone();
6542 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6543 timenow.get(Calendar.DATE),0,0,0);
6544 onepm = timenow.clone();
6546 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
6547 timenow.get(Calendar.DATE),13,0,0);
6549 itemisalcohol = false;
6550 if(item_id != null && item_id >=1000 && item_id < 2000)
6551 itemisalcohol = true;
6553 if( itemisalcohol &&
6554 ( (timenow.after(midnight) && timenow.before(onepm))
6556 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
6558 outFields.put("authorised", false);
6559 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
6560 " for time "+df.format(timenow.getTime())+
6561 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
6562 " and "+df.format(onepm.getTime()) +" or on Sunday");
6566 outFields.put("authorised", true);
6567 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
6568 " for time "+df.format(timenow.getTime()));
6573 This task checks if a sale request is for an item that is an alcoholic drink.
6574 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
6575 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
6576 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
6579 .. container:: imageblock
6581 .. container:: content
6583 |Create a new alternative task MorningBoozeCheckAlt1|
6585 .. container:: title
6587 Figure 19. Create a new Task
6589 .. container:: paragraph
6591 The task definition is now complete so click the 'Submit'
6592 button to save the task. Now that we have created our
6593 task, we can can add this task to the single pre-existing
6594 state (``BoozeAuthDecide``) in our policy.
6596 .. container:: paragraph
6598 To edit the ``BoozeAuthDecide`` state in our policy click
6599 on the 'Policies' tab. In the 'Policies' pane, right
6600 click on our ``MyFirstPolicy`` policy and select 'Edit'.
6601 Navigate to the ``BoozeAuthDecide`` state in the 'states'
6602 section at the bottom of the policy definition pane.
6604 .. container:: imageblock
6606 .. container:: content
6608 |Right click to edit a policy|
6610 .. container:: title
6612 Figure 20. Edit a Policy
6614 .. container:: paragraph
6616 To add our new task ``MorningBoozeCheckAlt1``, scroll
6617 down to the ``BoozeAuthDecide`` state in the 'States'
6618 section. In the 'State Tasks' section for
6619 ``BoozeAuthDecide`` use the 'Add new task' button. Select
6620 our new ``MorningBoozeCheckAlt1`` task, and use the name
6621 of the task as the 'Local Name' for the task. The
6622 ``MorningBoozeCheckAlt1`` task can reuse the same
6623 ``MorningBoozeCheck_Output_Direct`` 'Direct State Output
6624 Mapping' that we used for the ``MorningBoozeCheck`` task.
6625 (Recall that the role of the 'State Output Mapping' is to
6626 select the output event for the state, and select the
6627 next state to be executed. These both remain the same as
6630 .. container:: paragraph
6632 Since our state has more than one task we must define
6633 some logic to determine which task should be used each
6634 time the state is executed. This *task selection logic*
6635 is defined in the state definition. For our
6636 ``BoozeAuthDecide`` state we want the choice of which
6637 task to use to be based on the ``branch_ID`` from which
6638 the ``SALE_INPUT`` event originated. For simplicity sake
6639 let us assume that branches with ``branch_ID`` between
6640 ``0`` and ``999`` should use the ``MorningBoozeCheck``
6641 task, and the branches with with ``branch_ID`` between
6642 ``1000`` and ``1999`` should use the
6643 ``MorningBoozeCheckAlt1`` task.
6645 .. container:: paragraph
6647 This time, for variety, we will author the task selection
6649 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__
6650 scripting language. Sample task selection logic code
6652 ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__)
6653 is given below. Paste the script text into the 'Task
6654 Selection Logic' box, and use "JAVASCRIPT" as the 'Task
6655 Selection Logic Type / Flavour'. It is necessary to mark
6656 one of the tasks as the 'Default Task' so that the task
6657 selection logic always has a fallback default option in
6658 cases where a particular task cannot be selected. In this
6659 case the ``MorningBoozeCheck`` task can be the default
6662 .. container:: listingblock
6664 .. container:: title
6666 JavaScript code for the ``BoozeAuthDecide`` task
6669 .. container:: content
6674 * ============LICENSE_START=======================================================
6675 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
6676 * ================================================================================
6677 * Licensed under the Apache License, Version 2.0 (the "License");
6678 * you may not use this file except in compliance with the License.
6679 * You may obtain a copy of the License at
6681 * http://www.apache.org/licenses/LICENSE-2.0
6683 * Unless required by applicable law or agreed to in writing, software
6684 * distributed under the License is distributed on an "AS IS" BASIS,
6685 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6686 * See the License for the specific language governing permissions and
6687 * limitations under the License.
6689 * SPDX-License-Identifier: Apache-2.0
6690 * ============LICENSE_END=========================================================
6694 var returnValueType = Java.type("java.lang.Boolean");
6695 var returnValue = new returnValueType(true);
6697 executor.logger.info("Task Selection Execution: '"+executor.subject.id+
6698 "'. Input Event: '"+executor.inFields+"'");
6700 branchid = executor.inFields.get("branch_ID");
6701 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
6702 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
6703 taskdef = executor.subject.getDefaultTaskKey();
6705 if(branchid >=0 && branchid <1000){
6706 taskorig.copyTo(executor.selectedTask);
6708 else if (branchid >=1000 && branchid <2000){
6709 taskalt.copyTo(executor.selectedTask);
6712 taskdef.copyTo(executor.selectedTask);
6716 This task selection logic selects task "MorningBoozeCheck" for branches with
6717 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with
6718 1000<=branch_ID<2000. Otherwise the default task is selected.
6719 In this case the default task is also "MorningBoozeCheck"
6722 .. container:: imageblock
6724 .. container:: content
6726 |State definition with 2 Tasks and Task Selection
6729 .. container:: title
6731 Figure 21. State definition with 2 Tasks and Task
6734 .. container:: paragraph
6736 When complete don’t forget to click the 'Submit' button
6737 at the bottom of 'Policies' pane for our
6738 ``MyFirstPolicy`` policy after updating the
6739 ``BoozeAuthDecide`` state.
6741 .. container:: paragraph
6743 Congratulations, you have now completed the second step
6744 towards your first APEX policy. The policy model
6745 containing our new policy can again be validated and
6746 exported from the editor and saved as shown in Step 1.
6748 .. container:: paragraph
6750 The exported policy model is then available in the
6751 directory you selected, as
6752 `MyFirstPolicyModel_0.0.1.json <files/mfp-files/2/MyFirstPolicyModel_0.0.1.json>`__.
6753 The exported policy can now be loaded into the APEX
6754 Policy Engine, or can be re-loaded and edited by the APEX
6760 .. container:: paragraph
6762 To start a new APEX Engine you can use the following
6763 configuration. In a full APEX installation you can find
6764 this configuration in
6765 ``$APEX_HOME/examples/config/MyFirstPolicy/2/MyFirstPolicyConfigStdin2StdoutJsonEvent.json``.
6766 Note, this has changed from the configuration file in
6767 Step 1 to enable the ``JAVASCRIPT`` executor for our new
6768 'Task Selection Logic'.
6770 .. container:: listingblock
6772 .. container:: title
6774 JSON to load and execute *My First Policy*, read input
6775 JSON events from ``stdin``, and emit output events to
6778 .. container:: content
6783 "engineServiceParameters" : {
6784 "name" : "MyFirstPolicyApexEngine",
6785 "version" : "0.0.1",
6787 "instanceCount" : 4,
6788 "deploymentPort" : 12345,
6789 "policyModelFileName" : "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json",
6790 "engineParameters" : {
6791 "executorParameters" : {
6793 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
6796 "parameterClassName" : "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
6801 "eventOutputParameters": {
6803 "carrierTechnologyParameters" : {
6804 "carrierTechnology" : "FILE",
6809 "eventProtocolParameters" : {
6810 "eventProtocol" : "JSON"
6814 "eventInputParameters": {
6816 "carrierTechnologyParameters" : {
6817 "carrierTechnology" : "FILE",
6822 "eventProtocolParameters" : {
6823 "eventProtocol" : "JSON"
6829 .. container:: paragraph
6831 To test the policy try paste the following events into
6832 the console as the APEX engine executes. Note, all tests
6833 from Step 1 will still work perfectly since none of those
6834 events originate from a branch with ``branch_ID`` between
6835 ``1000`` and ``2000``. The 'Task Selection Logic' will
6836 therefore pick the ``MorningBoozeCheck`` task as
6837 expected, and will therefore give the same results.
6839 .. table:: Table 14. Inputs and Outputs when testing *My First Policy*
6841 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6842 | Input Event (JSON) | Output Event (JSON) | comment |
6843 +==============================================+============================================================+===========================+
6844 | .. container:: | .. container:: | Request to buy |
6845 | | | alcohol item |
6846 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1249``) |
6848 | | | at *08:41:06 |
6849 | | .. container:: content | GMT* on *Monday, |
6850 | .. container:: content | | 02 January |
6851 | | .. code:: | 2017*. |
6853 | | { | Sale is not |
6854 | .. code:: | "nameSpace": "com.hyperm", | authorized. Uses |
6855 | | "name": "SALE_AUTH", | the |
6856 | | "version": "0.0.1", | ``MorningBoozeCheck`` |
6857 | { | "source": "", | |
6858 | "nameSpace": "com.hyperm", | "target": "", | task. |
6859 | "name": "SALE_INPUT", | "amount": 1249, | |
6860 | "version": "0.0.1", | "assistant_ID":12, | Note this test |
6861 | "time": 1483346466000, | "authorised": false, | is copied from |
6862 | "sale_ID": 99999992, | "branch_ID": 2, | Step 1 above, |
6863 | "amount": 1249, | "item_ID": 1012, | and demonstrates |
6864 | "item_ID": 1012, | "message": "Sale not authorised by policy ta | that the |
6865 | "quantity": 1, | sk MorningBoozeCheck for time 08:41:06 GMT.| original |
6866 | "assistant_ID": 12, | Alcohol can not be sold between 00:00:00 | ``MorningBoozeCheck`` |
6867 | "branch_ID": 2 | GMT and 11:30:00 GMT", | |
6868 | } | "notes": null, | task is |
6869 | | "quantity": 1, | executed. |
6870 | | "sale_ID": 99999992, | |
6871 | | "time": 1483346466000 | |
6873 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6874 | .. container:: | .. container:: | Request to buy |
6876 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1047``) |
6878 | | | at *10:14:33* on |
6879 | | .. container:: content | *Thursday, 22 |
6880 | .. container:: content | | December 2016*. |
6883 | | { | authorized. Uses |
6884 | .. code:: | "nameSpace" : "com.hyperm", | the |
6885 | | "name" : "SALE_AUTH", | ``MorningBoozeCheckAlt1`` |
6886 | | "version" : "0.0.1", | task. |
6887 | { | "source" : "", | |
6888 | | "target" : "", | |
6889 | "nameSpace": "com.hyperm", | "sale_ID" : 99999981, | |
6890 | "name": "SALE_INPUT", | "amount" : 299, | |
6891 | "version": "0.0.1", | "assistant_ID": 1212, | |
6892 | "time": 1482398073000, | "notes" : null, | |
6893 | "sale_ID": 99999981, | "quantity" : 1, | |
6894 | "amount": 299, | "branch_ID" : 1002, | |
6895 | "item_ID": 1047, | "item_ID" : 1047, | |
6896 | "quantity": 1, | "authorised" : false, | |
6897 | "assistant_ID": 1212, | "time" : 1482398073000, | |
6898 | "branch_ID": 1002 | "message" : "Sale not authorised by policy t | |
6899 | } | ask MorningBoozeCheckAlt1 fortime | |
6900 | | 10:14:33 CET. Alcohol can not be sold | |
6901 | | between 00:00:00 CET and 13:00:00 CET or on | |
6904 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6905 | .. container:: | .. container:: | Request to buy |
6907 | .. container:: listingblock | .. container:: listingblock | (``item_ID=1443``) |
6909 | | | at *17:19:37* on |
6910 | | .. container:: content | *Sunday, 18 |
6911 | .. container:: content | | December 2016*. |
6914 | | { | authorized. Uses |
6915 | .. code:: | "nameSpace" : "com.hyperm", | the |
6916 | | | ``MorningBoozeCheckAlt1`` |
6917 | | "name" : "SALE_AUTH", | task. |
6919 | "nameSpace": "com.hyperm", | "version" : "0.0.1", | |
6920 | "name": "SALE_INPUT", | "source" : "", | |
6921 | "version": "0.0.1", | "target" : "", | |
6922 | "time": 1482077977000, | "sale_ID" : 99999982, | |
6923 | "sale_ID": 99999982, | "amount" : 2199, | |
6924 | "amount": 2199, | "assistant_ID" : 94, | |
6925 | "item_ID": 1443, | "notes" : "Buy 3, get 1 free!!", | |
6926 | "quantity": 12, | "quantity" : 12, | |
6927 | "assistant_ID": 94, | "branch_ID" : 1003, | |
6928 | "branch_ID": 1003, | "item_ID" : 1443, | |
6929 | "notes": "Buy 3, get 1 free!!" | "authorised" : false, | |
6930 | } | "time" : 1482077977000, | |
6931 | | "message" : "Sale not authorised by policy t | |
6932 | | ask MorningBoozeCheckAlt1 for | |
6933 | | time 17:19:37 CET. Alcohol c | |
6934 | | an not be sold between 00:00: | |
6935 | | 00 CET and 13:00:00 CET or on | |
6937 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6938 | .. container:: | .. container:: | Request to buy |
6939 | | | non-alcoholic |
6940 | .. container:: listingblock | .. container:: listingblock | item |
6941 | | | (``item_ID=5321``) |
6943 | | .. container:: content | at *11:13:09* on |
6944 | .. container:: content | | *Monday, 2 |
6945 | | .. code:: | January 2017*. |
6948 | .. code:: | "nameSpace" : "com.hyperm", | authorized. Uses |
6949 | | "name" : "SALE_AUTH", | the |
6950 | { | "version" : "0.0.1", | ``MorningBoozeCheckAlt1`` |
6951 | "nameSpace": "com.hyperm", | "source" : "", | task. |
6952 | "name": "SALE_INPUT", | "target" : "", | |
6953 | "version": "0.0.1", | "sale_ID" : 99999983, | |
6954 | "time": 1483351989000, | "amount" : 699, | |
6955 | "sale_ID": 99999983, | "assistant_ID" : 2323, | |
6956 | "amount": 699, | "notes" : "", | |
6957 | "item_ID": 5321, | "quantity" : 1, | |
6958 | "quantity": 1, | "branch_ID" : 1001, | |
6959 | "assistant_ID": 2323, | "item_ID" : 5321, | |
6960 | "branch_ID": 1001, | "authorised" : true, | |
6961 | "notes": "" | "time" : 1483351989000, | |
6962 | } | "message" : "Sale authorised by policy task | |
6963 | | MorningBoozeCheckAlt1 for time 11:13:09 CET"| |
6965 +----------------------------------------------+------------------------------------------------------------+---------------------------+
6967 Policy 2 in CLI Editor
6968 ######################
6970 .. container:: paragraph
6972 An equivalent version of the ``MyFirstPolicyModel``
6973 policy model can again be generated using the APEX CLI
6974 editor. A sample APEX CLI script is shown below:
6976 .. container:: listingblock
6978 .. container:: title
6980 APEX CLI Editor code for Policy 2
6982 .. container:: content
6986 #-------------------------------------------------------------------------------
6987 # ============LICENSE_START=======================================================
6988 # Copyright (C) 2016-2018 Ericsson. All rights reserved.
6989 # ================================================================================
6990 # Licensed under the Apache License, Version 2.0 (the "License");
6991 # you may not use this file except in compliance with the License.
6992 # You may obtain a copy of the License at
6994 # http://www.apache.org/licenses/LICENSE-2.0
6996 # Unless required by applicable law or agreed to in writing, software
6997 # distributed under the License is distributed on an "AS IS" BASIS,
6998 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6999 # See the License for the specific language governing permissions and
7000 # limitations under the License.
7002 # SPDX-License-Identifier: Apache-2.0
7003 # ============LICENSE_END=========================================================
7004 #-------------------------------------------------------------------------------
7006 model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
7008 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
7010 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
7012 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
7014 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
7016 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
7018 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
7020 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
7022 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
7024 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
7026 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
7028 task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
7029 This task checks if the sales request is for an item that contains alcohol.
7030 If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
7031 In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
7033 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7034 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
7035 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7036 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7037 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
7038 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7039 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7040 task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
7041 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7042 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
7043 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7044 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7045 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
7046 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7047 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7048 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
7049 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
7050 task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
7051 task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
7053 * ============LICENSE_START=======================================================
7054 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
7055 * ================================================================================
7056 * Licensed under the Apache License, Version 2.0 (the "License");
7057 * you may not use this file except in compliance with the License.
7058 * You may obtain a copy of the License at
7060 * http://www.apache.org/licenses/LICENSE-2.0
7062 * Unless required by applicable law or agreed to in writing, software
7063 * distributed under the License is distributed on an "AS IS" BASIS,
7064 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7065 * See the License for the specific language governing permissions and
7066 * limitations under the License.
7068 * SPDX-License-Identifier: Apache-2.0
7069 * ============LICENSE_END=========================================================
7071 import java.util.Date;
7072 import java.util.Calendar;
7073 import java.util.TimeZone;
7074 import java.text.SimpleDateFormat;
7076 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
7078 outFields.put("amount" , inFields.get("amount"));
7079 outFields.put("assistant_ID", inFields.get("assistant_ID"));
7080 outFields.put("notes" , inFields.get("notes"));
7081 outFields.put("quantity" , inFields.get("quantity"));
7082 outFields.put("branch_ID" , inFields.get("branch_ID"));
7083 outFields.put("item_ID" , inFields.get("item_ID"));
7084 outFields.put("time" , inFields.get("time"));
7085 outFields.put("sale_ID" , inFields.get("sale_ID"));
7087 item_id = inFields.get("item_ID");
7089 //The events used later to test this task use GMT timezone!
7090 gmt = TimeZone.getTimeZone("GMT");
7091 timenow = Calendar.getInstance(gmt);
7092 df = new SimpleDateFormat("HH:mm:ss z");
7093 df.setTimeZone(gmt);
7094 timenow.setTimeInMillis(inFields.get("time"));
7096 midnight = timenow.clone();
7098 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7099 timenow.get(Calendar.DATE),0,0,0);
7100 eleven30 = timenow.clone();
7102 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7103 timenow.get(Calendar.DATE),11,30,0);
7105 itemisalcohol = false;
7106 if(item_id != null && item_id >=1000 && item_id < 2000)
7107 itemisalcohol = true;
7110 && timenow.after(midnight) && timenow.before(eleven30)){
7111 outFields.put("authorised", false);
7112 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
7113 " for time "+df.format(timenow.getTime())+
7114 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
7115 " and "+df.format(eleven30.getTime()));
7119 outFields.put("authorised", true);
7120 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
7121 " for time "+df.format(timenow.getTime()));
7126 This task checks if a sale request is for an item that is an alcoholic drink.
7127 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
7128 authorised. Otherwise the sale is authorised.
7129 In this implementation we assume that items with item_ID value between 1000 and
7130 2000 are all alcoholic drinks :-)
7134 task create name=MorningBoozeCheckAlt1 version=0.0.1 uuid=bc6d90c9-c902-4686-afd3-925b30e39990 description=LS
7135 This task checks if a sale request is for an item that is an alcoholic drink.
7136 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
7137 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
7138 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks
7140 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7141 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
7142 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7143 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7144 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
7145 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7146 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7147 task inputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
7148 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7149 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
7150 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7151 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7152 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
7153 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7154 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7155 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
7156 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
7157 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
7158 task logic create name=MorningBoozeCheckAlt1 version=0.0.1 logicFlavour=MVEL logic=LS
7160 * ============LICENSE_START=======================================================
7161 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
7162 * ================================================================================
7163 * Licensed under the Apache License, Version 2.0 (the "License");
7164 * you may not use this file except in compliance with the License.
7165 * You may obtain a copy of the License at
7167 * http://www.apache.org/licenses/LICENSE-2.0
7169 * Unless required by applicable law or agreed to in writing, software
7170 * distributed under the License is distributed on an "AS IS" BASIS,
7171 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7172 * See the License for the specific language governing permissions and
7173 * limitations under the License.
7175 * SPDX-License-Identifier: Apache-2.0
7176 * ============LICENSE_END=========================================================
7178 import java.util.Date;
7179 import java.util.Calendar;
7180 import java.util.TimeZone;
7181 import java.text.SimpleDateFormat;
7183 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
7185 outFields.put("amount" , inFields.get("amount"));
7186 outFields.put("assistant_ID", inFields.get("assistant_ID"));
7187 outFields.put("notes" , inFields.get("notes"));
7188 outFields.put("quantity" , inFields.get("quantity"));
7189 outFields.put("branch_ID" , inFields.get("branch_ID"));
7190 outFields.put("item_ID" , inFields.get("item_ID"));
7191 outFields.put("time" , inFields.get("time"));
7192 outFields.put("sale_ID" , inFields.get("sale_ID"));
7194 item_id = inFields.get("item_ID");
7196 //The events used later to test this task use CET timezone!
7197 cet = TimeZone.getTimeZone("CET");
7198 timenow = Calendar.getInstance(cet);
7199 df = new SimpleDateFormat("HH:mm:ss z");
7200 df.setTimeZone(cet);
7201 timenow.setTimeInMillis(inFields.get("time"));
7203 midnight = timenow.clone();
7205 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7206 timenow.get(Calendar.DATE),0,0,0);
7207 onepm = timenow.clone();
7209 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
7210 timenow.get(Calendar.DATE),13,0,0);
7212 itemisalcohol = false;
7213 if(item_id != null && item_id >=1000 && item_id < 2000)
7214 itemisalcohol = true;
7216 if( itemisalcohol &&
7217 ( (timenow.after(midnight) && timenow.before(onepm))
7219 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
7221 outFields.put("authorised", false);
7222 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
7223 " for time "+df.format(timenow.getTime())+
7224 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
7225 " and "+df.format(onepm.getTime()) +" or on Sunday");
7229 outFields.put("authorised", true);
7230 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
7231 " for time "+df.format(timenow.getTime()));
7236 This task checks if a sale request is for an item that is an alcoholic drink.
7237 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
7238 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
7239 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)
7243 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"
7244 event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7245 event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7246 event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
7247 event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7248 event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7249 event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
7250 event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7251 event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7252 event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7253 event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7255 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"
7256 event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
7257 event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
7258 event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
7259 event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
7260 event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
7261 event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
7262 event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
7263 event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
7266 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
7267 policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
7268 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
7269 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
7270 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
7271 policy state selecttasklogic create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide logicFlavour=JAVASCRIPT logic=LS
7273 * ============LICENSE_START=======================================================
7274 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
7275 * ================================================================================
7276 * Licensed under the Apache License, Version 2.0 (the "License");
7277 * you may not use this file except in compliance with the License.
7278 * You may obtain a copy of the License at
7280 * http://www.apache.org/licenses/LICENSE-2.0
7282 * Unless required by applicable law or agreed to in writing, software
7283 * distributed under the License is distributed on an "AS IS" BASIS,
7284 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7285 * See the License for the specific language governing permissions and
7286 * limitations under the License.
7288 * SPDX-License-Identifier: Apache-2.0
7289 * ============LICENSE_END=========================================================
7292 var returnValueType = Java.type("java.lang.Boolean");
7293 var returnValue = new returnValueType(true);
7295 executor.logger.info("Task Selection Execution: '"+executor.subject.id+"'. Input Event: '"+executor.inFields+"'");
7297 branchid = executor.inFields.get("branch_ID");
7298 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
7299 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
7300 taskdef = executor.subject.getDefaultTaskKey();
7302 if(branchid >=0 && branchid <1000){
7303 taskorig.copyTo(executor.selectedTask);
7305 else if (branchid >=1000 && branchid <2000){
7306 taskalt.copyTo(executor.selectedTask);
7309 taskdef.copyTo(executor.selectedTask);
7313 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"
7320 Introduction to APEX Logging
7321 ----------------------------
7323 .. container:: paragraph
7325 All APEX components make extensive use of logging using the
7326 logging façade `SLF4J <https://www.slf4j.org/>`__ with the
7327 backend `Logback <https://logback.qos.ch/>`__. Both are used
7328 off-the-shelve, so the standard documentation and
7329 configuration apply to APEX logging. For details on how to
7330 work with logback please see the `logback
7331 manual <https://logback.qos.ch/manual/index.html>`__.
7333 .. container:: paragraph
7335 The APEX applications is the logback configuration file
7336 ``$APEX_HOME/etc/logback.xml`` (Windows:
7337 ``%APEX_HOME%\etc\logback.xml``). The logging backend is set
7338 to no debug, i.e. logs from the logging framework should be
7341 .. container:: paragraph
7343 The configurable log levels work as expected:
7345 .. container:: ulist
7347 - *error* (or *ERROR*) is used for serious errors in the
7350 - *warn* (or *WARN*) is used for warnings, which in general
7351 can be ignored but might indicate some deeper problems
7353 - *info* (or *INFO*) is used to provide generally
7354 interesting messages for startup and policy execution
7356 - *debug* (or *DEBUG*) provides more details on startup and
7359 - *trace* (or *TRACE*) gives full details on every aspect
7360 of the APEX engine from start to end
7362 .. container:: paragraph
7364 The loggers can also be configured as expected. The standard
7365 configuration (after installing APEX) uses log level *info*
7366 on all APEX classes (components).
7368 .. container:: paragraph
7370 The applications and scripts in ``$APEX_HOME/bin`` (Windows:
7371 ``%APEX_HOME\bin``) are configured to use the logback
7372 configuration ``$APEX_HOME/etc/logback.xml`` (Windows:
7373 ``%APEX_HOME\etc\logback.xml``). There are multiple ways to
7374 use different logback configurations, for instance:
7376 .. container:: ulist
7378 - Maintain multiple configurations in ``etc``, for instance
7379 a ``logback-debug.xml`` for deep debugging and a
7380 ``logback-production.xml`` for APEX in production mode,
7381 then copy the required configuration file to the used
7382 ``logback.xml`` prior starting APEX
7384 - Edit the scripts in ``bin`` to use a different logback
7385 configuration file (only recommended if you are familiar
7386 with editing bash scripts or windows batch files)
7388 Standard Logging Configuration
7389 ------------------------------
7391 .. container:: paragraph
7393 The standard logging configuration defines a context *APEX*,
7394 which is used in the standard output pattern. The location
7395 for log files is defined in the property ``logDir`` and set
7396 to ``/var/log/onap/policy/apex-pdp``. The standard status
7397 listener is set to *NOP* and the overall logback
7398 configuration is set to no debug.
7400 .. container:: listingblock
7402 .. container:: content
7407 <configuration debug="false">
7408 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7410 <contextName>Apex</contextName>
7411 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
7417 .. container:: paragraph
7419 The first appender defined is called ``STDOUT`` for logs to standard
7422 .. container:: listingblock
7424 .. container:: content
7429 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7431 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7435 .. container:: paragraph
7437 The root level logger then is set to the level *info* using the
7438 standard out appender.
7440 .. container:: listingblock
7442 .. container:: content
7448 <appender-ref ref="STDOUT" />
7451 .. container:: paragraph
7453 The second appender is called ``FILE``. It writes logs to a file
7456 .. container:: listingblock
7458 .. container:: content
7463 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7464 <file>${logDir}/apex.log</file>
7466 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7470 .. container:: paragraph
7472 The third appender is called ``CTXT_FILE``. It writes logs to a file
7475 .. container:: listingblock
7477 .. container:: content
7482 <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
7483 <file>${logDir}/apex_ctxt.log</file>
7485 <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %n %ex{full}</pattern>
7489 .. container:: paragraph
7491 The last definitions are for specific loggers. The first logger
7492 captures all standard APEX classes. It is configured for log level
7493 *info* and uses the standard output and file appenders. The second
7494 logger captures APEX context classes responsible for context
7495 monitoring. It is configured for log level *trace* and uses the
7496 context file appender.
7498 .. container:: listingblock
7500 .. container:: content
7506 <logger name="org.onap.policy.apex" level="info" additivity="false">
7507 <appender-ref ref="STDOUT" />
7508 <appender-ref ref="FILE" />
7511 <logger name="org.onap.policy.apex.core.context.monitoring" level="TRACE" additivity="false">
7512 <appender-ref ref="CTXT_FILE" />
7515 Adding Logback Status and Debug
7516 -------------------------------
7518 .. container:: paragraph
7520 To activate logback status messages change the status listener
7521 from 'NOP' to for instance console.
7523 .. container:: listingblock
7525 .. container:: content
7529 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
7531 .. container:: paragraph
7533 To activate all logback debugging, for instance to debug a new
7534 logback configuration, activate the debug attribute in the
7537 .. container:: listingblock
7539 .. container:: content
7543 <configuration debug="true">
7547 Logging External Components
7548 ---------------------------
7550 .. container:: paragraph
7552 Logback can also be configured to log any other, external
7553 components APEX is using, if they are using the common logging
7556 .. container:: paragraph
7558 For instance, the context component of APEX is using *Infinispan*
7559 and one can add a logger for this external component. The
7560 following example adds a logger for *Infinispan* using the
7561 standard output appender.
7563 .. container:: listingblock
7565 .. container:: content
7569 <logger name="org.infinispan" level="INFO" additivity="false">
7570 <appender-ref ref="STDOUT" />
7573 .. container:: paragraph
7575 Another example is Apache Zookeeper. The following example adds a
7576 logger for Zookeeper using the standard outout appender.
7578 .. container:: listingblock
7580 .. container:: content
7584 <logger name="org.apache.zookeeper.ClientCnxn" level="INFO" additivity="false">
7585 <appender-ref ref="STDOUT" />
7588 Configuring loggers for Policy Logic
7589 ------------------------------------
7591 .. container:: paragraph
7593 The logging for the logic inside a policy (task logic, task
7594 selection logic, state finalizer logic) can be configured separate
7595 from standard logging. The logger for policy logic is
7596 ``org.onap.policy.apex.executionlogging``. The following example
7599 .. container:: ulist
7601 - a new appender for standard out using a very simple pattern
7602 (simply the actual message)
7604 - a logger for policy logic to standard out using the new
7605 appender and the already described file appender.
7607 .. container:: listingblock
7609 .. container:: content
7613 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7615 <pattern>policy: %msg\n</pattern>
7619 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7620 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7621 <appender-ref ref="FILE" />
7624 .. container:: paragraph
7626 It is also possible to use specific logging for parts of policy
7627 logic. The following example defines a logger for task logic.
7629 .. container:: listingblock
7631 .. container:: content
7635 <logger name="org.onap.policy.apex.executionlogging.TaskExecutionLogging" level="TRACE" additivity="false">
7636 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7639 Rolling File Appenders
7640 ----------------------
7642 .. container:: paragraph
7644 Rolling file appenders are a good option for more complex logging
7645 of a production or complex testing APEX installation. The standard
7646 logback configuration can be used for these use cases. This
7647 section gives two examples for the standard logging and for
7650 .. container:: paragraph
7652 First the standard logging. The following example defines a
7653 rolling file appender. The appender rolls over on a daily basis.
7654 It allows for a file size of 100 MB.
7656 .. container:: listingblock
7658 .. container:: content
7662 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
7663 <file>${logDir}/apex.log</file>
7664 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7665 <!-- rollover daily -->
7666 <!-- <fileNamePattern>xstream-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> -->
7667 <fileNamePattern>${logDir}/apex_%d{yyyy-MM-dd}.%i.log.gz
7669 <maxHistory>4</maxHistory>
7670 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7671 <!-- or whenever the file size reaches 100MB -->
7672 <maxFileSize>100MB</maxFileSize>
7673 </timeBasedFileNamingAndTriggeringPolicy>
7677 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7682 .. container:: paragraph
7684 A very similar configuration can be used for a rolling file
7685 appender logging APEX context.
7687 .. container:: listingblock
7689 .. container:: content
7693 <appender name="CTXT-FILE"
7694 class="ch.qos.logback.core.rolling.RollingFileAppender">
7695 <file>${logDir}/apex_ctxt.log</file>
7696 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
7697 <fileNamePattern>${logDir}/apex_ctxt_%d{yyyy-MM-dd}.%i.log.gz
7699 <maxHistory>4</maxHistory>
7700 <timeBasedFileNamingAndTriggeringPolicy
7701 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
7702 <maxFileSize>100MB</maxFileSize>
7703 </timeBasedFileNamingAndTriggeringPolicy>
7707 %d %-5relative [procId=${processId}] [%thread] %-5level %logger{26} - %msg %ex{full} %n
7712 Example Configuration for Logging Logic
7713 ---------------------------------------
7715 .. container:: paragraph
7717 The following example shows a configuration that logs policy logic
7718 to standard out and a file (*info*). All other APEX components are
7719 logging to a file (*debug*).. This configuration an be used in a
7720 pre-production phase with the APEX engine still running in a
7721 separate terminal to monitor policy execution. This logback
7722 configuration is in the APEX installation as
7723 ``etc/logback-logic.xml``.
7725 .. container:: listingblock
7727 .. container:: content
7731 <configuration debug="false">
7732 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7734 <contextName>Apex</contextName>
7735 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
7737 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7739 <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
7743 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7744 <file>${logDir}/apex.log</file>
7747 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7752 <appender name="POLICY_APPENDER_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7754 <pattern>policy: %msg\n</pattern>
7758 <root level="error">
7759 <appender-ref ref="STDOUT" />
7762 <logger name="org.onap.policy.apex" level="debug" additivity="false">
7763 <appender-ref ref="FILE" />
7766 <logger name="org.onap.policy.apex.executionlogging" level="info" additivity="false">
7767 <appender-ref ref="POLICY_APPENDER_STDOUT" />
7768 <appender-ref ref="FILE" />
7772 Example Configuration for a Production Server
7773 ---------------------------------------------
7775 .. container:: paragraph
7777 The following example shows a configuration that logs all APEX
7778 components, including policy logic, to a file (*debug*). This
7779 configuration an be used in a production phase with the APEX
7780 engine being executed as a service on a system without console
7781 output. This logback configuration is in the APEX installation as
7782 ``logback-server.xml``
7784 .. container:: listingblock
7786 .. container:: content
7790 <configuration debug="false">
7791 <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
7793 <contextName>Apex</contextName>
7794 <property name="logDir" value="/var/log/onap/policy/apex-pdp/" />
7796 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
7797 <file>${logDir}/apex.log</file>
7800 %d %-5relative [procId=${processId}] [%thread] %-5level%logger{26} - %msg %n %ex{full}
7805 <root level="debug">
7806 <appender-ref ref="FILE" />
7809 <logger name="org.onap.policy.apex.executionlogging" level="debug" additivity="false">
7810 <appender-ref ref="FILE" />
7814 Building a System with Websocket Backend
7815 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7820 .. container:: paragraph
7822 Websocket is a protocol to run sockets of HTTP. Since it in
7823 essence a socket, the connection is realized between a
7824 server (waiting for connections) and a client (connecting to
7825 a server). Server/client separation is only important for
7826 connection establishment, once connected, everyone can
7827 send/receive on the same socket (as any standard socket
7830 .. container:: paragraph
7832 Standard Websocket implementations are simple, no
7833 publish/subscribe and no special event handling. Most
7834 servers simply send all incoming messages to all
7835 connections. There is a PubSub definition on top of
7836 Websocket called `WAMP <http://wamp-proto.org/>`__. APEX
7837 does not support WAMP at the moment.
7842 .. container:: paragraph
7845 356 <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7846 defines the standard Websocket API. This JSR is part of Jave
7847 EE 7 standard. For Java SE, several implementations exist in
7848 open source. Since Websockets are a stable standard and
7849 simple, most implementations are stable and ready to use. A
7850 lot of products support Websockets, like Spring, JBoss,
7851 Netty, … there are also Kafka extensions for Websockets.
7853 Websocket Example Code for Websocket clients (FOSS)
7854 ---------------------------------------------------
7856 .. container:: paragraph
7858 There are a lot of implementations and examples available on
7859 Github for Websocket clients. If one is using Java EE 7,
7860 then one can also use the native Websocket implementation.
7861 Good examples for clients using simply Java SE are here:
7863 .. container:: ulist
7866 implementation <https://github.com/TooTallNate/Java-WebSocket>`__
7868 - `Websocket sending client example, using
7869 AWT <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ChatClient.java>`__
7871 - `Websocket receiving client example (simple echo
7872 client) <https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/ExampleClient.java>`__
7874 .. container:: paragraph
7876 For Java EE, the native Websocket API is explained here:
7878 .. container:: ulist
7881 docs <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>`__
7884 example <http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html>`__
7886 BCP: Websocket Configuration
7887 ----------------------------
7889 .. container:: paragraph
7891 The probably best is to configure APEX for Websocket servers
7892 for input (ingress, consume) and output (egress, produce)
7893 interfaces. This means that APEX will start Websocket
7894 servers on named ports and wait for clients to connect.
7895 Advantage: once APEX is running all connectivity
7896 infrastructure is running as well. Consequence: if APEX is
7897 not running, everyone else is in the dark, too.
7899 .. container:: paragraph
7901 The best protocol to be used is JSON string. Each event on
7902 any interface is then a string with a JSON encoding. JSON
7903 string is a little bit slower than byte code, but we doubt
7904 that this will be noticeable. A further advantage of JSON
7905 strings over Websockets with APEX starting the servers: it
7906 is very easy to connect web browsers to such a system.
7907 Simple connect the web browser to the APEX sockets and
7908 send/read JSON strings.
7910 .. container:: paragraph
7912 Once APEX is started you simply connect Websocket clients to
7913 it, and send/receive event. When APEX is terminated, the
7914 Websocket servers go down, and the clients will be
7915 disconnected. APEX does not (yet) support auto-client
7916 reconnect nor WAMP, so clients might need to be restarted or
7917 reconnected manually after an APEX boot.
7919 Demo with VPN Policy Model
7920 --------------------------
7922 .. container:: paragraph
7924 We assume that you have an APEX installation using the full
7925 package, i.e. APEX with all examples, of version ``0.5.6``
7926 or higher. We will use the VPN policy from the APEX examples
7929 .. container:: paragraph
7931 Now, have the following ready to start the demo:
7933 .. container:: ulist
7935 - 3 terminals on the host where APEX is running (we need 1
7936 for APEX and 1 for each client)
7938 - the events in the file
7939 ``$APEX_HOME/examples/events/VPN/SetupEvents.json`` open
7940 in an editor (we need to send those events to APEX)
7942 - the events in the file
7943 ``$APEX_HOME/examples/events/VPN/Link09Events.json`` open
7944 in an editor (we need to send those events to APEX)
7946 A Websocket Configuration for the VPN Domain
7947 ############################################
7949 .. container:: paragraph
7951 Create a new APEX configuration using the VPN policy
7952 model and configuring APEX as discussed above for
7953 Websockets. Copy the following configuration into
7954 ``$APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json``
7956 ``%APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json``):
7958 .. container:: listingblock
7960 .. container:: content
7966 "engineServiceParameters" : {
7967 "name" : "VPNApexEngine",
7968 "version" : "0.0.1",
7970 "instanceCount" : 1,
7971 "deploymentPort" : 12345,
7972 "policyModelFileName" : "examples/models/VPN/VPNPolicyModelAvro.json",
7973 "engineParameters" : {
7974 "executorParameters" : {
7976 "parameterClassName" : "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters"
7979 "contextParameters" : {
7980 "parameterClassName" : "org.onap.policy.apex.context.parameters.ContextParameters",
7981 "schemaParameters":{
7983 "parameterClassName" : "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
7989 "producerCarrierTechnologyParameters" : {
7990 "carrierTechnology" : "WEBSOCKET",
7991 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
7997 "producerEventProtocolParameters" : {
7998 "eventProtocol" : "JSON"
8000 "consumerCarrierTechnologyParameters" : {
8001 "carrierTechnology" : "WEBSOCKET",
8002 "parameterClassName" : "org.onap.policy.apex.plugins.event.carrier.websocket.WEBSOCKETCarrierTechnologyParameters",
8008 "consumerEventProtocolParameters" : {
8009 "eventProtocol" : "JSON"
8016 .. container:: paragraph
8018 In a new terminal, start APEX with the new configuration for
8019 Websocket-Server ingress/egress:
8021 .. container:: listingblock
8023 .. container:: content
8028 #: $APEX_HOME/bin/apexEngine.sh -c $APEX_HOME/examples/config/VPN/Ws2WsServerAvroContextJsonEvent.json
8030 .. container:: listingblock
8032 .. container:: content
8037 #: %APEX_HOME%\bin\apexEngine.bat -c %APEX_HOME%\examples\config\VPN\Ws2WsServerAvroContextJsonEvent.json
8039 .. container:: paragraph
8041 Wait for APEX to start, it takes a while to create all Websocket
8042 servers (about 8 seconds on a standard laptop without cached
8043 binaries). depending on your log messages, you will see no (some, a
8044 lot) log messages. If APEX starts correctly, the last few messages
8047 .. container:: listingblock
8049 .. container:: content
8054 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)
8055 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 ...
8056 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
8057 Started Apex service
8059 .. container:: paragraph
8061 APEX is running in the new terminal and will produce output when the
8062 policy is triggered/executed.
8064 Run the Websocket Echo Client
8065 #############################
8067 .. container:: paragraph
8069 The echo client is included in an APEX full installation. To run
8070 the client, open a new shell (Unix, Cygwin) or command prompt
8071 (``cmd`` on Windows). Then use the APEX application launcher to
8075 APEX engine needs to run first
8076 The example assumes that an APEX engine configured for *produce* carrier technology Websocket and *JSON* event protocol is executed first.
8078 +---------------------------------------------------------+-----------------------------------------------------------+
8079 | Unix, Cygwin | Windows |
8080 +=========================================================+===========================================================+
8081 | .. container:: | .. container:: |
8083 | .. container:: listingblock | .. container:: listingblock |
8085 | .. container:: content | .. container:: content |
8087 | .. code:: | .. code:: |
8089 | # $APEX_HOME/bin/apexApps.sh ws-echo [args] | > %APEX_HOME%\bin\apexApps.bat ws-echo [args] |
8090 +---------------------------------------------------------+-----------------------------------------------------------+
8092 .. container:: paragraph
8094 Use the following command line arguments for server and port of
8095 the Websocket server. The port should be the same as configured in
8096 the APEX engine. The server host should be the host on which the
8097 APEX engine is running
8099 .. container:: ulist
8101 - ``-p`` defines the Websocket port to connect to (defaults to
8104 - ``-s`` defines the host on which a Websocket server is running
8105 (defaults to ``localhost``)
8107 .. container:: paragraph
8109 Let’s assume that there is an APEX engine running, configured for
8110 produce Websocket carrier technology, as server, for port 42452,
8111 with produce event protocol JSON,. If we start the console client
8112 on the same host, we can omit the ``-s`` options. We start the
8115 .. container:: listingblock
8117 .. container:: content
8121 # $APEX_HOME/bin/apexApps.sh ws-echo -p 42452 (1)
8122 > %APEX_HOME%\bin\apexApps.bat ws-echo -p 42452 (2)
8124 .. container:: colist arabic
8126 +-------+--------------------------------+
8127 | **1** | Start client on Unix or Cygwin |
8128 +-------+--------------------------------+
8129 | **2** | Start client on Windows |
8130 +-------+--------------------------------+
8132 .. container:: paragraph
8134 Once started successfully, the client will produce the following
8135 messages (assuming we used ``-p 42452`` and an APEX engine is
8136 running on ``localhost`` with the same port:
8138 .. container:: listingblock
8140 .. container:: content
8144 ws-simple-echo: starting simple event echo
8145 --> server: localhost
8148 Once started, the application will simply print out all received events to standard out.
8149 Each received event will be prefixed by '---' and suffixed by '===='
8152 ws-simple-echo: opened connection to APEX (Web Socket Protocol Handshake)
8154 Run the Websocket Console Client
8155 ################################
8157 .. container:: paragraph
8159 The console client is included in an APEX full installation. To
8160 run the client, open a new shell (Unix, Cygwin) or command prompt
8161 (``cmd`` on Windows). Then use the APEX application launcher to
8165 APEX engine needs to run first
8166 The example assumes that an APEX engine configured for *consume* carrier technology Websocket and *JSON* event
8167 protocol is executed first.
8169 +------------------------------------------------------------+--------------------------------------------------------------+
8170 | Unix, Cygwin | Windows |
8171 +============================================================+==============================================================+
8172 | .. container:: | .. container:: |
8174 | .. container:: listingblock | .. container:: listingblock |
8176 | .. container:: content | .. container:: content |
8178 | .. code:: | .. code:: |
8180 | # $APEX_HOME/bin/apexApps.sh ws-console [args] | > %APEX_HOME%\bin\apexApps.bat ws-console [args] |
8181 +------------------------------------------------------------+--------------------------------------------------------------+
8183 .. container:: paragraph
8185 Use the following command line arguments for server and port of
8186 the Websocket server. The port should be the same as configured in
8187 the APEX engine. The server host should be the host on which the
8188 APEX engine is running
8190 .. container:: ulist
8192 - ``-p`` defines the Websocket port to connect to (defaults to
8195 - ``-s`` defines the host on which a Websocket server is running
8196 (defaults to ``localhost``)
8198 .. container:: paragraph
8200 Let’s assume that there is an APEX engine running, configured for
8201 consume Websocket carrier technology, as server, for port 42450,
8202 with consume event protocol JSON,. If we start the console client
8203 on the same host, we can omit the ``-s`` options. We start the
8206 .. container:: listingblock
8208 .. container:: content
8212 # $APEX_HOME/bin/apexApps.sh ws-console -p 42450 (1)
8213 > %APEX_HOME%\bin\apexApps.sh ws-console -p 42450 (2)
8215 .. container:: colist arabic
8217 +-------+--------------------------------+
8218 | **1** | Start client on Unix or Cygwin |
8219 +-------+--------------------------------+
8220 | **2** | Start client on Windows |
8221 +-------+--------------------------------+
8223 .. container:: paragraph
8225 Once started successfully, the client will produce the following
8226 messages (assuming we used ``-p 42450`` and an APEX engine is
8227 running on ``localhost`` with the same port:
8229 .. container:: listingblock
8231 .. container:: content
8235 ws-simple-console: starting simple event console
8236 --> server: localhost
8239 - terminate the application typing 'exit<enter>' or using 'CTRL+C'
8240 - events are created by a non-blank starting line and terminated by a blank line
8243 ws-simple-console: opened connection to APEX (Web Socket Protocol Handshake)
8248 .. container:: paragraph
8250 Now you have the full system up and running:
8252 .. container:: ulist
8254 - Terminal 1: APEX ready and loaded
8256 - Terminal 2: an echo client, printing received messages produced
8259 - Terminal 2: a console client, waiting for input on the console
8260 (standard in) and sending text to APEX
8262 .. container:: paragraph
8264 We started the engine with the VPN policy example. So all the
8265 events we are using now are located in files in the following
8268 .. container:: listingblock
8270 .. container:: content
8275 #: $APEX_HOME/examples/events/VPN
8276 > %APEX_HOME%\examples\events\VPN
8278 .. container:: paragraph
8280 To sends events, simply copy the content of the event files into
8281 Terminal 3 (the console client). It will read multi-line JSON text
8282 and send the events. So copy the content of ``SetupEvents.json`` into
8283 the client. APEX will trigger a policy and produce some output, the
8284 echo client will also print some events created in the policy. In
8285 Terminal 1 (APEX) you’ll see some status messages from the policy as:
8287 .. container:: listingblock
8289 .. container:: content
8294 {Link=L09, LinkUp=true}
8296 outFields: {Link=L09, LinkUp=true}
8297 {Link=L10, LinkUp=true}
8300 outFields: {Link=L10, LinkUp=true}
8301 {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8303 C 300 300 [L09, L10]
8304 outFields: {CustomerName=C, LinkList=L09 L10, SlaDT=300, YtdDT=300}
8305 {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8308 C 300 300 [L09, L10]
8309 outFields: {CustomerName=A, LinkList=L09 L10, SlaDT=300, YtdDT=50}
8310 {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8313 C 300 300 [L09, L10]
8314 D 300 400 [L09, L10]
8315 outFields: {CustomerName=D, LinkList=L09 L10, SlaDT=300, YtdDT=400}
8316 {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8319 B 300 299 [L09, L10]
8320 C 300 300 [L09, L10]
8321 D 300 400 [L09, L10]
8322 outFields: {CustomerName=B, LinkList=L09 L10, SlaDT=300, YtdDT=299}
8324 .. container:: paragraph
8326 In Terminal 2 (echo-client) you see the received events, the last two
8329 .. container:: listingblock
8331 .. container:: content
8336 ws-simple-echo: received
8337 ---------------------------------
8339 "name": "VPNCustomerCtxtActEvent",
8341 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8344 "CustomerName": "C",
8345 "LinkList": "L09 L10",
8349 =================================
8351 ws-simple-echo: received
8352 ---------------------------------
8354 "name": "VPNCustomerCtxtActEvent",
8356 "nameSpace": "org.onap.policy.apex.domains.vpn.events",
8359 "CustomerName": "D",
8360 "LinkList": "L09 L10",
8364 =================================
8366 .. container:: paragraph
8368 Congratulations, you have triggered a policy in APEX using
8369 Websockets, the policy did run through, created events, picked up by
8372 .. container:: paragraph
8374 Now you can send the Link 09 and Link 10 events, they will trigger
8375 the actual VPN policy and some calculations are made. Let’s take the
8376 Link 09 events from ``Link09Events.json``, copy them all into
8377 Terminal 3 (the console). APEX will run the policy (with some status
8378 output), and the echo client will receive and print events.
8380 .. container:: paragraph
8382 To terminate the applications, simply press ``CTRL+C`` in Terminal 1
8383 (APEX). This will also terminate the echo-client in Terminal 2. Then
8384 type ``exit<enter>`` in Terminal 3 (or ``CTRL+C``) to terminate the
8394 Last updated 2018-09-10 15:38:16 IST
8396 .. |Extract the TAR archive| image:: images/install-guide/win-extract-tar-gz.png
8397 .. |Extract the APEX distribution| image:: images/install-guide/win-extract-tar.png
8398 .. |REST Editor Start Screen| image:: images/install-guide/rest-start.png
8399 .. |REST Editor with loaded SampleDomain Policy Model| image:: images/install-guide/rest-loaded.png
8400 .. |APEX Configuration Matrix| image:: images/apex-intro/ApexEngineConfig.png
8401 .. |File > New to create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel1.png
8402 .. |Create a new Policy Model| image:: images/mfp/MyFirstPolicy_P1_newPolicyModel2.png
8403 .. |Right click to create a new event| image:: images/mfp/MyFirstPolicy_P1_newEvent1.png
8404 .. |Fill in the necessary information for the 'SALE_INPUT' event and click 'Submit'| image:: images/mfp/MyFirstPolicy_P1_newEvent2.png
8405 .. |Right click to create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema1.png
8406 .. |Create a new Item Schema| image:: images/mfp/MyFirstPolicy_P1_newItemSchema2.png
8407 .. |Add new event parameters to an event| image:: images/mfp/MyFirstPolicy_P1_newEvent3.png
8408 .. |Right click to create a new task| image:: images/mfp/MyFirstPolicy_P1_newTask1.png
8409 .. |Add input and out fields for the task| image:: images/mfp/MyFirstPolicy_P1_newTask2.png
8410 .. |Add task logic the task| image:: images/mfp/MyFirstPolicy_P1_newTask3.png
8411 .. |Create a new policy| image:: images/mfp/MyFirstPolicy_P1_newPolicy1.png
8412 .. |Create a state| image:: images/mfp/MyFirstPolicy_P1_newState1.png
8413 .. |Add a Task and Output Mapping| image:: images/mfp/MyFirstPolicy_P1_newState2.png
8414 .. |Validate the policy model for error using the 'Model' > 'Validate' menu item| image:: images/mfp/MyFirstPolicy_P1_validatePolicyModel.png
8415 .. |Download the completed policy model using the 'File' > 'Download' menu item| image:: images/mfp/MyFirstPolicy_P1_exportPolicyModel1.png
8416 .. |Create a new alternative task MorningBoozeCheckAlt1| image:: images/mfp/MyFirstPolicy_P2_newTask1.png
8417 .. |Right click to edit a policy| image:: images/mfp/MyFirstPolicy_P2_editPolicy1.png
8418 .. |State definition with 2 Tasks and Task Selection Logic| image:: images/mfp/MyFirstPolicy_P2_editState1.png