X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=docs%2Fapex%2FAPEX-Policy-Guide.rst;h=cb2388e01b3e9b40e283a0bbd21d907396831a7b;hb=935358b4bfcf551ec780a4f6342032ac2a00376d;hp=dc4f2bbefb550dceefaa0a0d63a37ad7a589b286;hpb=760cce91689a00a52de363c96745323fb95a91b0;p=policy%2Fparent.git diff --git a/docs/apex/APEX-Policy-Guide.rst b/docs/apex/APEX-Policy-Guide.rst index dc4f2bbe..cb2388e0 100644 --- a/docs/apex/APEX-Policy-Guide.rst +++ b/docs/apex/APEX-Policy-Guide.rst @@ -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 ############## @@ -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 | .. 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 ########################### @@ -2054,69 +2093,6 @@ Using Java in Scripting Logic importClass(java.util.ArrayList); var myList = new ArrayList(); -Policy Examples -^^^^^^^^^^^^^^^ - -My First Policy ---------------- - - .. container:: paragraph - - A good starting point is the ``My First Policy`` example. It - describes a sales problem, to which policy can be applied. - The example details the policy background, shows how to use - the REST Editor to create a policy, and provides details for - running the policies. The documentation can be found: - - .. container:: ulist - - - `My-First-Policy on the APEX - site `__ - - - `Stand-alone - HTML `__ - - - `Stand-alone - PDF `__ - -VPN SLA -------- - - .. container:: paragraph - - The domain Policy-controlled Video Streaming (PCVS) contains - a policy for controlling video streams with different - strategies. It also provides details for installing an - actual testbed with off-the-shelve software (Mininet, - Floodlight, Kafka, Zookeeper). The policy model here - demonstrates virtually all APEX features: local context and - policies controlling it, task selection logic and multiple - tasks in a single state, AVRO schemas for context, AVOR - schemas for events (trigger and local), and a CLI editor - specification of the policy. The documentation can be found: - - .. container:: ulist - - - `VPN SLA Policy on the APEX - site `__ - -Decision Maker --------------- - - .. container:: paragraph - - The domain Decision Maker shows a very simple policy for - decisions. Interesting here is that the it creates a Docker - image to run the policy and that it uses the APEX REST - applications to update the policy on the-fly. It also has - local context to remember past decisions, and shows how to - use that to no make the same decision twice in a row. The - documentation can be found: - - .. container:: ulist - - - `Decision Maker on APEX - site `__ .. container:: :name: footer @@ -2124,8 +2100,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