Merge "Updated documentation for Frankfurt changes to api and xacml-pdp"
[policy/parent.git] / docs / apex / APEX-Policy-Guide.rst
index 392f31c..c7e8ad5 100644 (file)
@@ -18,8 +18,8 @@ APEX Policy Matrix
 
                APEX offers a lot of flexibility for defining, deploying,
                and executing policies. Based on a theoretic model, it
-               supports virtually any policy model and allows to
-               translate legacy policies into the APEX execution format.
+               supports virtually any policy model and supports
+               translation of legacy policies into the APEX execution format.
                However, the most important aspect for using APEX is to
                decide what policy is needed, what underlying policy
                concepts should be used, and how the decision logic
@@ -664,6 +664,13 @@ Concept: TaskParameter
                   values in the configuration information passed to APEX
                   engines.
 
+               .. container:: paragraph
+
+                  The *taskParameters* field is specified under *engineParameters*
+                  in the ApexConfig. It can contain one or more task parameters, where each
+                  item can contain the parameter key, value as well as the taskId to which it is associated.
+                  If the taskId is not specified, then the parameters are added to all tasks.
+
 Concept: Logic
 ##############
 
@@ -868,19 +875,19 @@ Writing APEX Task Logic
                attempt to teach you about the scripting languages
                themselves …​ that is up to you!
 
-            .. tip::  
-                          JVM-based scripting languages
-                          For more more information on scripting for the Java platform see: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
+            .. tip::
+               JVM-based scripting languages
+               For more more information on scripting for the Java platform see: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
 
-            .. note:: 
-                          What do Tasks do?
-                          The function of an Apex Task is to provide the logic that can be executed for an Apex State as one of the steps in
-                          an Apex Policy. Each task receives some *incoming fields*, executes some logic (e.g: make a decision based on
-                          *shared state* or *context*, *incoming fields*, *external context*, etc.), perhaps set some *shared state* or 
-                          *context* and then emits *outgoing fields*. The state that uses the task is responsible for extracting the
-                          *incoming fields* from the state input event. The state also has an *output mapper* associated with the task, and
-                          this *output mapper* is responsible for mapping the *outgoing fields* from the task into an appropriate
-                          output event for the state.
+            .. note::
+               What do Tasks do?
+               The function of an Apex Task is to provide the logic that can be executed for an Apex State as one of the steps in
+               an Apex Policy. Each task receives some *incoming fields*, executes some logic (e.g: make a decision based on
+               *shared state* or *context*, *incoming fields*, *external context*, etc.), perhaps set some *shared state* or
+               *context* and then emits *outgoing fields*. The state that uses the task is responsible for extracting the
+               *incoming fields* from the state input event. The state also has an *output mapper* associated with the task, and
+               this *output mapper* is responsible for mapping the *outgoing fields* from the task into an appropriate
+               output event for the state.
 
             .. container:: paragraph
 
@@ -988,7 +995,7 @@ Writing APEX Task Logic
 
                .. container:: content
 
-                  .. code:: javascript 
+                  .. code:: javascript
                      :number-lines:
 
                      /*
@@ -1094,14 +1101,14 @@ Writing APEX Task Logic
                and exit.
 
             .. note::
-                          How to return a value from task logic 
-                          Some languages explicitly support returning values from the script (e.g. MVEL and JRuby) using an explicit 
-                          return statement (e.g. ``return true``), other languages do not (e.g. JavaScript and Jython). For
-                          languages that do not support the ``return`` statement, a special field called ``returnValue`` must be
-                          created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
-                          value to the ``returnValue`` field before completing the task).
-                          Also, in MVEL if there is no explicit return statement then the return value of the last executed statement will return
-                          (e.g. the statement a=(1+2) will return the value 3).
+               How to return a value from task logic
+               Some languages explicitly support returning values from the script (e.g. MVEL and JRuby) using an explicit
+               return statement (e.g. ``return true``), other languages do not (e.g. JavaScript and Jython). For
+               languages that do not support the ``return`` statement, a special field called ``returnValue`` must be
+               created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
+               value to the ``returnValue`` field before completing the task).
+               Also, in MVEL if there is no explicit return statement then the return value of the last executed statement will return
+               (e.g. the statement a=(1+2) will return the value 3).
 
             .. container:: paragraph
 
@@ -1116,7 +1123,7 @@ Writing APEX Task Logic
                ``executor`` keyword in MVEL):
 
             Table 1. The ``executor`` Fields / Methods
-         
+
 +------------+-------------+--------------------------------+-------------------------------------------------------------------------------------+
 | Name       | Type        | Java type                      | Description                                                                         |
 +============+=============+================================+=====================================================================================+
@@ -1308,21 +1315,21 @@ Writing APEX Task Selection Logic
       the scripting languages themselves …​ that is up to you!
 
    .. tip::
-      JVM-based scripting languages 
-         For more more information on Scripting for the Java platform see:
-         https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
-
-   .. note::  
-      What does Task Selection Logic do? 
-         When an Apex state references multiple tasks, there must be a way to dynamically decide
-         which task should be chosen and executed. This can depend on the many factors, e.g. the
-         *incoming event for the state*, *shared state* or *context*, *external context*,
-         etc.. This is the function of a state’s Task Selection Logic. Obviously, if there is 
-         only one task then Task only one task then Task Selection Logic is not needed. 
-         Each state must also select one of the tasks a the *default state*. If the Task 
-         Selection Logic is unable to select an appropriate task, then it should select the 
-         *default task*. Once the task has been selected the Apex Engine will then execute that
-         task.
+      JVM-based scripting languages
+      For more more information on Scripting for the Java platform see:
+      https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
+
+   .. note::
+      What does Task Selection Logic do?
+      When an Apex state references multiple tasks, there must be a way to dynamically decide
+      which task should be chosen and executed. This can depend on the many factors, e.g. the
+      *incoming event for the state*, *shared state* or *context*, *external context*,
+      etc.. This is the function of a state’s Task Selection Logic. Obviously, if there is
+      only one task then Task only one task then Task Selection Logic is not needed.
+      Each state must also select one of the tasks a the *default state*. If the Task
+      Selection Logic is unable to select an appropriate task, then it should select the
+      *default task*. Once the task has been selected the Apex Engine will then execute that
+      task.
 
    .. container:: paragraph
 
@@ -1406,15 +1413,15 @@ Writing APEX Task Selection Logic
       be returned, but this will cause the policy invoking this task
       will fail and exit.
 
-   .. note:: 
+   .. note::
       How to return a value from Task Selection Logic
-         Some languages explicitly support returning values from the script (e.g. MVEL and 
-         JRuby) using an explicit return statement (e.g. ``return true``), other languages do not (e.g.
-         JavaScript and Jython). For languages that do not support the ``return`` statement, a special field called 
-         ``returnValue`` must be created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
-         value to the ``returnValue`` field before completing the task). 
-         Also, in MVEL if there is not explicit return statement then the return value of the last executed statement will
-         return (e.g. the statement a=(1+2) will return the value 3).   
+      Some languages explicitly support returning values from the script (e.g. MVEL and
+      JRuby) using an explicit return statement (e.g. ``return true``), other languages do not (e.g.
+      JavaScript and Jython). For languages that do not support the ``return`` statement, a special field called
+      ``returnValue`` must be created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
+      value to the ``returnValue`` field before completing the task).
+      Also, in MVEL if there is not explicit return statement then the return value of the last executed statement will
+      return (e.g. the statement a=(1+2) will return the value 3).
 
    .. container:: paragraph
 
@@ -1440,7 +1447,7 @@ Writing APEX Task Selection Logic
       |         :number-lines:                                |         :number-lines:                                 |
       |                                                       |                                                        |
       |         >c:                                           |         # cd /usr/local/src/apex-pdp                   |
-      |         >cd \dev\apex                                 |         # mvn clean install -DskipTest                 |
+      |         >cd \dev\apex                                 |         # mvn clean install -DskipTests                |
       |         >mvn clean install -DskipTests                |                                                        |
       +-------------------------------------------------------+--------------------------------------------------------+
 
@@ -1567,6 +1574,22 @@ Writing APEX Task Selection Logic
 |            |             |                                |                .getOutFieldSchemaHelper("authorised")                               |
 |            |             |                                |               .createNewInstance("false");                                          |
 +------------+-------------+--------------------------------+-------------------------------------------------------------------------------------+
+| parameters | Fields      | java.util.Map <String,String>  | .. container:: paragraph                                                            |
+|            |             |                                |                                                                                     |
+|            |             |                                |    All parameters in the current task. This is implemented as a standard Java Map.  |
+|            |             |                                |                                                                                     |
+|            |             |                                | .. container::                                                                      |
+|            |             |                                |                                                                                     |
+|            |             |                                |    .. container:: content                                                           |
+|            |             |                                |                                                                                     |
+|            |             |                                |       .. container:: paragraph                                                      |
+|            |             |                                |                                                                                     |
+|            |             |                                |          **Example:**                                                               |
+|            |             |                                |                                                                                     |
+|            |             |                                |       .. code:: javascript                                                          |
+|            |             |                                |                                                                                     |
+|            |             |                                |          executor.parameters.get("ParameterKey1"))                                  |
++------------+-------------+--------------------------------+-------------------------------------------------------------------------------------+
 | ContextAlbum getContextAlbum(String ctxtAlbumName )       | .. container:: paragraph                                                            |
 |                                                           |                                                                                     |
 |                                                           |    A utility method to retrieve a ``ContextAlbum`` for use in the task.             |
@@ -1604,32 +1627,13 @@ Logic Cheatsheet
       Examples given here use Javascript (if not stated otherwise),
       other execution environments will be similar.
 
-Add Nashorn
-###########
-
-      .. container:: paragraph
-
-         First line in the logic use this import.
-
-      .. container:: listingblock
-
-         .. container:: title
-
-            JS Nashorn
-
-         .. container:: content
-
-            .. code:: javascript
-
-               load("nashorn:mozilla_compat.js");
-
 Finish Logic with Success or Error
 ##################################
 
       .. container:: paragraph
 
          To finish logic, i.e. return to APEX, with success use the
-         following lines close to the end of the logic.
+         following line close to the end of the logic.
 
       .. container:: listingblock
 
@@ -1641,8 +1645,7 @@ Finish Logic with Success or Error
 
             .. code:: javascript
 
-               var returnValueType = Java.type("java.lang.Boolean");
-               var returnValue = new returnValueType(true);
+               true;
 
       .. container:: paragraph
 
@@ -1658,8 +1661,7 @@ Finish Logic with Success or Error
 
             .. code:: javascript
 
-               var returnValueType = Java.type("java.lang.Boolean");
-               var returnValue = new returnValueType(false);
+               false;
 
 Logic Logging
 #############
@@ -1731,6 +1733,43 @@ Logic Logging
 
                rootLogger.error("Serious error in logic detected: " + executor.subject.id);
 
+Accessing TaskParameters
+########################
+
+      .. container:: paragraph
+
+         TaskParameters available in a Task can be accessed in the logic.
+         The parameters in each task are made available at the executor level.
+         This example assumes a parameter with key ``ParameterKey1``.
+
+      .. container:: listingblock
+
+         .. container:: title
+
+            JS TaskParameter value
+
+         .. container:: content
+
+            .. code:: javascript
+
+               executor.parameters.get("ParameterKey1"))
+
+      .. container:: paragraph
+
+         Alternatively, the task parameters can also be accessed from the task object.
+
+      .. container:: listingblock
+
+         .. container:: title
+
+            JS TaskParameter value using task object
+
+         .. container:: content
+
+            .. code:: javascript
+
+               executor.subject.task.getTaskParameters.get("ParameterKey1").getTaskParameterValue()
+
 Local Variable for Infields
 ###########################
 
@@ -1922,7 +1961,7 @@ Create a instance of an Context Album entry using Schemas
 
          .. container:: content
 
-            .. code:: javascript 
+            .. code:: javascript
 
                var albumProblemMap = executor.getContextAlbum("albumProblemMap");
                var linkProblem = albumProblemMap.getSchemaHelper().createNewInstance();
@@ -1940,7 +1979,7 @@ Create a instance of an Context Album entry using Schemas
 
          .. container:: content
 
-            .. code:: javascript 
+            .. code:: javascript
 
                var linkProblem = executor.getContextAlbum("albumProblemMap").getSchemaHelper().createNewInstance();
 
@@ -2057,6 +2096,19 @@ Using Java in Scripting Logic
 Policy Examples
 ^^^^^^^^^^^^^^^
 
+Sample APEX Policy in TOSCA format
+----------------------------------
+
+         .. container:: paragraph
+
+            An example APEX policy in TOSCA format for the vCPE
+            use case can be found here:
+
+         .. container:: ulist
+
+            -  `APEX TOSCA Policy
+               vCPE <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.apex.policy.operational.input.tosca.json>`__
+
 My First Policy
 ---------------
 
@@ -2124,8 +2176,8 @@ Decision Maker
    .. container::
       :name: footer-text
 
-      2.0.0-SNAPSHOT
-      Last updated 2018-09-04 16:04:24 IST
+      2.3.0-SNAPSHOT
+      Last updated 2020-03-16 16:04:24 GMT
 
 .. |APEX Policy Matrix| image:: images/apex-intro/ApexPolicyMatrix.png
 .. |APEX Policy Model for Execution| image:: images/apex-policy-model/UmlPolicyModels.png