blob: 4b11413fc082b0662566d572747699b112606c2c [file] [log] [blame]
liamfallonf3981072020-07-10 15:59:25 +01001 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
ramverma3b71c972019-07-10 11:25:37 +00003
liamfallonf3981072020-07-10 15:59:25 +01004#################
ramverma3b71c972019-07-10 11:25:37 +00005APEX Policy Guide
liamfallonf3981072020-07-10 15:59:25 +01006#################
7
ramverma3b71c972019-07-10 11:25:37 +00008
9.. contents::
liamfallonab5be042020-07-13 16:37:56 +010010 :depth: 5
ramverma3b71c972019-07-10 11:25:37 +000011
liamfallonf3981072020-07-10 15:59:25 +010012******************
ramverma3b71c972019-07-10 11:25:37 +000013APEX Policy Matrix
liamfallonf3981072020-07-10 15:59:25 +010014******************
ramverma3b71c972019-07-10 11:25:37 +000015
liamfallonf3981072020-07-10 15:59:25 +010016.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +000017
liamfallonf3981072020-07-10 15:59:25 +010018 APEX offers a lot of flexibility for defining, deploying, and executing policies. Based on a theoretic model, it
19 supports virtually any policy model and supports translation of legacy policies into the APEX execution format.
20 However, the most important aspect for using APEX is to decide what policy is needed, what underlying policy concepts
21 should be used, and how the decision logic should be realized. Once these aspects are decided, APEX can be used to
22 execute the policies. If the policy evolves, say from a simple decision table to a fully adaptable policy, only the
23 policy definition requires change. APEX supports all of that.
ramverma3b71c972019-07-10 11:25:37 +000024
liamfallonf3981072020-07-10 15:59:25 +010025.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +000026
liamfallonf3981072020-07-10 15:59:25 +010027 The figure below shows a (non-exhaustive) matrix, which will help to decide what policy is required to solve your
28 problem. Read the matrix from left to right choosing one cell in each column.
ramverma3b71c972019-07-10 11:25:37 +000029
liamfallonf3981072020-07-10 15:59:25 +010030.. container:: imageblock
ramverma3b71c972019-07-10 11:25:37 +000031
liamfallonf3981072020-07-10 15:59:25 +010032 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +000033
liamfallonf3981072020-07-10 15:59:25 +010034 |APEX Policy Matrix|
ramverma3b71c972019-07-10 11:25:37 +000035
liamfallonf3981072020-07-10 15:59:25 +010036 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +000037
liamfallonf3981072020-07-10 15:59:25 +010038 Figure 1. APEX Policy Matrix
ramverma3b71c972019-07-10 11:25:37 +000039
liamfallonf3981072020-07-10 15:59:25 +010040.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +000041
liamfallonf3981072020-07-10 15:59:25 +010042 The policy can support one of a number of stimuli with an associated purpose/model of the policy, for instance:
ramverma3b71c972019-07-10 11:25:37 +000043
liamfallonf3981072020-07-10 15:59:25 +010044.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +000045
liamfallonf3981072020-07-10 15:59:25 +010046 - Configuration, i.e. what should happen. An example is an event that states an intended network configuration
47 and the policy should provide the detailed actions for it. The policy can be realized for instance as an
48 obligation policy, a promise or an intent.
ramverma3b71c972019-07-10 11:25:37 +000049
liamfallonf3981072020-07-10 15:59:25 +010050 - Report, i.e. something did happen. An example is an event about an error or fault and the policy needs to
51 repair that problem. The policy would usually be an obligation, utility function, or goal policy.
ramverma3b71c972019-07-10 11:25:37 +000052
liamfallonf3981072020-07-10 15:59:25 +010053 - Monitoring, i.e. something does happen. An example is a notification about certain network conditions, to
54 which the policy might (or might not) react. The policy will mitigate the monitored events or permit (deny)
55 related actions as an obligation or authorization.
ramverma3b71c972019-07-10 11:25:37 +000056
liamfallonf3981072020-07-10 15:59:25 +010057 - Analysis, i.e. why did something happen. An example is an analytic component sends insights of a situation
58 requiring a policy to act on it. The policy can solve the problem, escalate it, or delegate it as a refrain or
59 delegation policy.
ramverma3b71c972019-07-10 11:25:37 +000060
liamfallonf3981072020-07-10 15:59:25 +010061 - Prediction, i.e. what will happen next. An example are events that a policy uses to predict a future network
62 condition. The policy can prevent or enforce the prediction as an adaptive policy, a utility function, or a goal.
ramverma3b71c972019-07-10 11:25:37 +000063
liamfallonf3981072020-07-10 15:59:25 +010064 - Feedback, i.e. why did something happen or not happen. Similar to analysis, but here the feedback will be in
65 the input event and the policy needs to something with that information. Feedback can be related to history or
66 experience, for instance a previous policy execution. The policy needs to be context-aware or be a meta-policy.
ramverma3b71c972019-07-10 11:25:37 +000067
liamfallonf3981072020-07-10 15:59:25 +010068.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +000069
liamfallonf3981072020-07-10 15:59:25 +010070 Once the purpose of the policy is decided, the next step is to look into what context information the policy will
71 require to do its job. This can range from very simple to a lot of different information, for instance:
ramverma3b71c972019-07-10 11:25:37 +000072
liamfallonf3981072020-07-10 15:59:25 +010073.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +000074
liamfallonf3981072020-07-10 15:59:25 +010075 - No context, nothing but a trigger event, e.g. a string or a number, is required
ramverma3b71c972019-07-10 11:25:37 +000076
liamfallonf3981072020-07-10 15:59:25 +010077 - Event context, the incoming event provides all information (more than a string or number) for the policy
ramverma3b71c972019-07-10 11:25:37 +000078
liamfallonf3981072020-07-10 15:59:25 +010079 - Policy context (read only), the policy has access to additional information related to its class but cannot
80 change/alter them
ramverma3b71c972019-07-10 11:25:37 +000081
liamfallonf3981072020-07-10 15:59:25 +010082 - Policy context (read and write), the policy has access to additional information related to its class and can
83 alter this information (for instance to record historic information)
ramverma3b71c972019-07-10 11:25:37 +000084
liamfallonf3981072020-07-10 15:59:25 +010085 - Global context (read only), the policy has access to additional information of any kind but cannot
86 change/alter them
ramverma3b71c972019-07-10 11:25:37 +000087
liamfallonf3981072020-07-10 15:59:25 +010088 - Global context (read and write), the policy the policy has access to additional information of any kind and
89 can alter this information (for instance to record historic information)
ramverma3b71c972019-07-10 11:25:37 +000090
liamfallonf3981072020-07-10 15:59:25 +010091.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +000092
liamfallonf3981072020-07-10 15:59:25 +010093 The next step is to decide how the policy should do its job, i.e. what flavor it has, how many states are needed,
94 and how many tasks. There are many possible combinations, for instance:
ramverma3b71c972019-07-10 11:25:37 +000095
liamfallonf3981072020-07-10 15:59:25 +010096.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +000097
liamfallonf3981072020-07-10 15:59:25 +010098 - Simple / God: a simple policy with 1 state and 1 task, which is doing everything for the decision-making. This
99 is the ideal policy for simple situation, e.g. deciding on configuration parameters or simple access control.
ramverma3b71c972019-07-10 11:25:37 +0000100
liamfallonf3981072020-07-10 15:59:25 +0100101 - Simple sequence: a simple policy with a number of states each having a single task. This is a very good policy
102 for simple decision-making with different steps. For instance, a classic action policy (ECA) would have 3 states
103 (E, C, and A) with some logic (1 task) in each state.
ramverma3b71c972019-07-10 11:25:37 +0000104
liamfallonf3981072020-07-10 15:59:25 +0100105 - Simple selective: a policy with 1 state but more than one task. Here, the appropriate task (and it’s logic)
106 will be selected at execution time. This policy is very good for dealing with similar (or the same) situation in
107 different contexts. For instance, the tasks can be related to available external software, or to current work load
108 on the compute node, or to time of day.
ramverma3b71c972019-07-10 11:25:37 +0000109
liamfallonf3981072020-07-10 15:59:25 +0100110 - Selective: any number of states having any number of tasks (usually more than 1 task). This is a combination
111 of the two policies above, for instance an ECA policy with more than one task in E, C, and A.
ramverma3b71c972019-07-10 11:25:37 +0000112
liamfallonf3981072020-07-10 15:59:25 +0100113 - Classic directed: a policy with more than one state, each having one task, but a non-sequential execution.
114 This means that the sequence of the states is not pre-defined in the policy (as would be for all cases above) but
115 calculated at runtime. This can be good to realize decision trees based on contextual information.
ramverma3b71c972019-07-10 11:25:37 +0000116
liamfallonf3981072020-07-10 15:59:25 +0100117 - Super Adaptive: using the full potential of the APEX policy model, states and tasks and state execution are
118 fully flexible and calculated at runtime (per policy execution). This policy is very close to a general
119 programming system (with only a few limitations), but can solve very hard problems.
ramverma3b71c972019-07-10 11:25:37 +0000120
liamfallonf3981072020-07-10 15:59:25 +0100121.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000122
liamfallonf3981072020-07-10 15:59:25 +0100123 The final step is to select a response that the policy creates. Possible responses have been discussed in the
124 literature for a very long time. A few examples are:
ramverma3b71c972019-07-10 11:25:37 +0000125
liamfallonf3981072020-07-10 15:59:25 +0100126.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000127
liamfallonf3981072020-07-10 15:59:25 +0100128 - Obligation (deontic for what should happen)
ramverma3b71c972019-07-10 11:25:37 +0000129
liamfallonf3981072020-07-10 15:59:25 +0100130 - Authorization (e.g. for rule-based or other access control or security systems)
ramverma3b71c972019-07-10 11:25:37 +0000131
liamfallonf3981072020-07-10 15:59:25 +0100132 - Intent (instead of providing detailed actions the response is an intent statement and a further system
133 processes that)
ramverma3b71c972019-07-10 11:25:37 +0000134
liamfallonf3981072020-07-10 15:59:25 +0100135 - Delegation (hand the problem over to someone else, possibly with some information or instructions)
ramverma3b71c972019-07-10 11:25:37 +0000136
liamfallonf3981072020-07-10 15:59:25 +0100137 - Fail / Error (the policy has encountered a problem, and reports it)
ramverma3b71c972019-07-10 11:25:37 +0000138
liamfallonf3981072020-07-10 15:59:25 +0100139 - Feedback (why did the policy make a certain decision)
ramverma3b71c972019-07-10 11:25:37 +0000140
liamfallonf3981072020-07-10 15:59:25 +0100141*****************
ramverma3b71c972019-07-10 11:25:37 +0000142APEX Policy Model
liamfallonf3981072020-07-10 15:59:25 +0100143*****************
ramverma3b71c972019-07-10 11:25:37 +0000144
liamfallonf3981072020-07-10 15:59:25 +0100145.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000146
liamfallonf3981072020-07-10 15:59:25 +0100147 The APEX policy model is shown in UML notation in the figure below. A policy model can be stored in JSON or XML
148 format in a file or can be held in a database. The APEX editor creates and modifies APEX policy models. APEX
149 deployment deploys policy models, and a policy model is loaded into APEX engines so that the engines can run the
150 policies in the policy model.
ramverma3b71c972019-07-10 11:25:37 +0000151
liamfallonf3981072020-07-10 15:59:25 +0100152.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000153
liamfallonf3981072020-07-10 15:59:25 +0100154 The figure shows four different views of the policy model:
ramverma3b71c972019-07-10 11:25:37 +0000155
liamfallonf3981072020-07-10 15:59:25 +0100156.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000157
liamfallonf3981072020-07-10 15:59:25 +0100158 - The general model view shows the main parts of a policy: state, state output, event, and task. A task can also
159 have parameters. Data types can be defined on a per-model basis using either standard atomic types (such as
160 character, string, numbers) or complex types from a policy domain.
ramverma3b71c972019-07-10 11:25:37 +0000161
liamfallonf3981072020-07-10 15:59:25 +0100162 - The logic model view emphasizes how decision-making logic is injected into a policy. There are essentially
163 three different types of logic: task logic (for decision making in a task), task selection logic (to select a task
164 if more than one is defined in a state), and state finalizer logic (to compute the final output event of a state
165 and select an appropriate next state from the policy model).
ramverma3b71c972019-07-10 11:25:37 +0000166
liamfallonf3981072020-07-10 15:59:25 +0100167 - The context model view shows how context is injected into a policy. States collect all context from their
168 tasks. A task can define what context it requires for the decision making, i.e. what context the task logic will
169 process. Context itself is a collection of items (individual context information) with data types. Context can be
170 templated.
ramverma3b71c972019-07-10 11:25:37 +0000171
liamfallonf3981072020-07-10 15:59:25 +0100172 - The event and field model view shows the events in the policy model. Tasks define what information they
173 consume (input) and produce (output). This information is modeled as fields, essentially a key/type tuple in the
174 model and a key/type/value triple at execution. Events then are collection of fields.
ramverma3b71c972019-07-10 11:25:37 +0000175
liamfallonf3981072020-07-10 15:59:25 +0100176.. container:: imageblock
ramverma3b71c972019-07-10 11:25:37 +0000177
liamfallonf3981072020-07-10 15:59:25 +0100178 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +0000179
liamfallonf3981072020-07-10 15:59:25 +0100180 |APEX Policy Model for Execution|
ramverma3b71c972019-07-10 11:25:37 +0000181
liamfallonf3981072020-07-10 15:59:25 +0100182 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +0000183
liamfallonf3981072020-07-10 15:59:25 +0100184 Figure 2. APEX Policy Model for Execution
ramverma3b71c972019-07-10 11:25:37 +0000185
186Concepts and Keys
liamfallonf3981072020-07-10 15:59:25 +0100187=================
ramverma3b71c972019-07-10 11:25:37 +0000188
liamfallonf3981072020-07-10 15:59:25 +0100189.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000190
liamfallonf3981072020-07-10 15:59:25 +0100191 Each element of the policy model is called a *concept*. Each *concept* is a subclass of the abstract *Concept*
192 class, as shown in the next figure. Every concept implements the following abstract methods:
ramverma3b71c972019-07-10 11:25:37 +0000193
liamfallonf3981072020-07-10 15:59:25 +0100194.. container:: imageblock
ramverma3b71c972019-07-10 11:25:37 +0000195
liamfallonf3981072020-07-10 15:59:25 +0100196 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +0000197
liamfallonf3981072020-07-10 15:59:25 +0100198 |Concepts and Keys|
ramverma3b71c972019-07-10 11:25:37 +0000199
liamfallonf3981072020-07-10 15:59:25 +0100200 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +0000201
liamfallonf3981072020-07-10 15:59:25 +0100202 Figure 3. Concepts and Keys
ramverma3b71c972019-07-10 11:25:37 +0000203
liamfallonf3981072020-07-10 15:59:25 +0100204.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000205
liamfallonf3981072020-07-10 15:59:25 +0100206 - ``getKey()`` - gets the unique key for this concept instance in the system
ramverma3b71c972019-07-10 11:25:37 +0000207
liamfallonf3981072020-07-10 15:59:25 +0100208 - ``validate()`` - validates the structure of this concept, its sub-concepts and its relationships
ramverma3b71c972019-07-10 11:25:37 +0000209
liamfallonf3981072020-07-10 15:59:25 +0100210 - ``clean()`` - carries out housekeeping on the concept such as trimming strings, remove any hanging references
ramverma3b71c972019-07-10 11:25:37 +0000211
liamfallonf3981072020-07-10 15:59:25 +0100212 - ``clone()`` - creates a deep copy of an instance of this concept
ramverma3b71c972019-07-10 11:25:37 +0000213
liamfallonf3981072020-07-10 15:59:25 +0100214 - ``equals()`` - checks if two instances of this concept are equal
ramverma3b71c972019-07-10 11:25:37 +0000215
liamfallonf3981072020-07-10 15:59:25 +0100216 - ``toString()`` - returns a string representation of the concept
ramverma3b71c972019-07-10 11:25:37 +0000217
liamfallonf3981072020-07-10 15:59:25 +0100218 - ``hashCode()`` - returns a hash code for the concept
ramverma3b71c972019-07-10 11:25:37 +0000219
liamfallonf3981072020-07-10 15:59:25 +0100220 - ``copyTo()`` - carries out a deep copy of one instance of the concept to another instance, overwriting the
221 target fields.
ramverma3b71c972019-07-10 11:25:37 +0000222
liamfallonf3981072020-07-10 15:59:25 +0100223.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000224
liamfallonf3981072020-07-10 15:59:25 +0100225 All concepts must have a *key*, which uniquely identifies a concept instance. The *key* of a subclass of an *Concept*
226 must either be an ``ArtifactKey`` or an ``ReferenceKey``. Concepts that have a stand-alone independent existence such
227 as *Policy*, *Task*, and *Event* must have an ``ArtifctKey`` key. Concepts that are contained in other concepts, that
228 do not exist as stand-alone concepts must have an ``ReferenceKey`` key. Examples of such concepts are *State* and
229 *EventParameter*.
ramverma3b71c972019-07-10 11:25:37 +0000230
liamfallonf3981072020-07-10 15:59:25 +0100231.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000232
liamfallonf3981072020-07-10 15:59:25 +0100233 An ``ArticactKey`` has two fields; the *Name* of the concept it is the key for and the concept’s *Version*. A
234 concept’s name must be unique in a given PolicyModel. A concept version is represented using the well known
235 *major.minor.path* scheme as used in semantic versioning.
ramverma3b71c972019-07-10 11:25:37 +0000236
liamfallonf3981072020-07-10 15:59:25 +0100237.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000238
liamfallonf3981072020-07-10 15:59:25 +0100239 A ``ReferenceKey`` has three fields. The *UserKeyName* and *UserKeyVersion* fields identify the ``ArtifactKey`` of
240 the concept in which the concept keyed by the ``ReferenceKey`` is contained. The *LocalName* field identifies the
241 contained concept instance. The *LocalName* must be unique in the concepts of a given type contained by a parent.
ramverma3b71c972019-07-10 11:25:37 +0000242
liamfallonf3981072020-07-10 15:59:25 +0100243.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000244
liamfallonf3981072020-07-10 15:59:25 +0100245 For example, a policy called ``SalesPolicy`` with a Version of ``1.12.4`` has a state called ``Decide``. The
246 ``Decide`` state is linked to the ``SalesPolicy`` with a ``ReferenceKey`` with fields *UserKeyName* of
247 ``SalesPolicy``, *UserKeyVersion* of ``1.12.4``, and *LocalName* of ``Decide``. There must not be another state
248 called ``Decide`` in the policy ``SalesPolicy``. However, there may well be a state called ``Decide`` in some other
249 policy called ``PurchasingPolicy``.
ramverma3b71c972019-07-10 11:25:37 +0000250
liamfallonf3981072020-07-10 15:59:25 +0100251.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000252
liamfallonf3981072020-07-10 15:59:25 +0100253 Each concept in the model is also a JPA
254 (`Java Persistence API <https://en.wikipedia.org/wiki/Java_Persistence_API>`__) Entity. This means that every concept
255 can be individually persisted or the entire model can be persisted en-bloc to any persistence mechanism using an JPA
256 framework such as `Hibernate <http://hibernate.org/>`__ or `EclipseLink <http://www.eclipse.org/eclipselink/>`__.
ramverma3b71c972019-07-10 11:25:37 +0000257
258Concept: PolicyModel
liamfallonf3981072020-07-10 15:59:25 +0100259====================
ramverma3b71c972019-07-10 11:25:37 +0000260
liamfallonf3981072020-07-10 15:59:25 +0100261.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000262
liamfallonf3981072020-07-10 15:59:25 +0100263 The *PolicyModel* concept is a container that holds the definition of a set of policies and their associated events,
264 context maps, and tasks. A *PolicyModel* is implemented as four maps for policies, events, context maps, and tasks.
265 Each map is indexed by the key of the policy, event, context map, or task. Any non-empty policy model must have at
266 least one entry in its policy, event, and task map because all policies must have at least one input and output event
267 and must execute at least one task.
ramverma3b71c972019-07-10 11:25:37 +0000268
liamfallonf3981072020-07-10 15:59:25 +0100269.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000270
liamfallonf3981072020-07-10 15:59:25 +0100271 A *PolicyModel* concept is keyed with an ``ArtifactKey key``. Because a *PolicyModel* is an ``AxConcept``, calling
272 the ``validate()`` method on a policy model validates the concepts, structure, and relationships of the entire policy
273 model.
ramverma3b71c972019-07-10 11:25:37 +0000274
275Concept: DataType
liamfallonf3981072020-07-10 15:59:25 +0100276=================
ramverma3b71c972019-07-10 11:25:37 +0000277
liamfallonf3981072020-07-10 15:59:25 +0100278.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000279
liamfallonf3981072020-07-10 15:59:25 +0100280 Data types are tightly controlled in APEX in order to provide a very high degree of consistency in policies and to
281 facilitate tracking of changes to context as policies execute. All context is modeled as a *DataType* concept. Each
282 DataType concept instance is keyed with an ``ArtifactKey`` key. The DataType field identifies the Java class of
283 objects that is used to represent concept instances that use this data type. All context has a *DataType*; incoming
284 and outgoing context is represented by *EventField* concepts and all other context is represented by *ContextItem*
285 concepts.
ramverma3b71c972019-07-10 11:25:37 +0000286
287Concept: Event
liamfallonf3981072020-07-10 15:59:25 +0100288==============
ramverma3b71c972019-07-10 11:25:37 +0000289
liamfallonf3981072020-07-10 15:59:25 +0100290.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000291
liamfallonf3981072020-07-10 15:59:25 +0100292 An *Event* defines the structure of a message that passes into or out of an APEX engine or that passes between two
293 states in an APEX engine. APEX supports message reception and sending in many formats and all messages are translated
294 into an *Event* prior to processing by an APEX engine. Event concepts are keyed with an ``ArtifactKey`` key. The
295 parameters of an event are held as a map of *EventField* concept instances with each parameter indexed by the
296 *LocalName* of its ``ReferenceKey``. An *Event* has three fields:
ramverma3b71c972019-07-10 11:25:37 +0000297
liamfallonf3981072020-07-10 15:59:25 +0100298.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000299
liamfallonf3981072020-07-10 15:59:25 +0100300 - The *NameSpace* identifies the domain of application of the event
ramverma3b71c972019-07-10 11:25:37 +0000301
liamfallonf3981072020-07-10 15:59:25 +0100302 - The *Source* of the event identifies the system that emitted the event
ramverma3b71c972019-07-10 11:25:37 +0000303
liamfallonf3981072020-07-10 15:59:25 +0100304 - The *Target* of the event identifies the system that the event was sent to
ramverma3b71c972019-07-10 11:25:37 +0000305
liamfallonf3981072020-07-10 15:59:25 +0100306.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000307
liamfallonf3981072020-07-10 15:59:25 +0100308 A *PolicyModel* contains a map of all the events known to a given policy model. Although an empty model may have no
309 events in its event map, any sane policy model must have at least one *Event* defined.
ramverma3b71c972019-07-10 11:25:37 +0000310
311Concept: EventField
liamfallonf3981072020-07-10 15:59:25 +0100312===================
ramverma3b71c972019-07-10 11:25:37 +0000313
liamfallonf3981072020-07-10 15:59:25 +0100314.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000315
liamfallonf3981072020-07-10 15:59:25 +0100316 The incoming context and outgoing context of an event are the fields of the event. Each field representing a single
317 piece of incoming or outgoing context. Each field of an *Event* is represented by an instance of the *EventField*
318 concept. Each *EventField* concept instance in an event is keyed with a ``ReferenceKey`` key, which references the
319 event. The *LocalName* field of the ``ReferenceKey`` holds the name of the field A reference to a *DataType* concept
320 defines the data type that values of this parameter have at run time.
ramverma3b71c972019-07-10 11:25:37 +0000321
322Concept: ContextMap
liamfallonf3981072020-07-10 15:59:25 +0100323===================
ramverma3b71c972019-07-10 11:25:37 +0000324
liamfallonf3981072020-07-10 15:59:25 +0100325.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000326
liamfallonf3981072020-07-10 15:59:25 +0100327 The set of context that is available for use by the policies of a *PolicyModel* is defined as *ContextMap* concept
328 instances. The *PolicyModel* holds a map of all the *ContextMap* definitions. A *ContextMap* is itself a container
329 for a group of related context items, each of which is represented by a *ContextItem* concept instance. *ContextMap*
330 concepts are keyed with an ``ArtifactKey`` key. A developer can use the APEX Policy Editor to create context maps for
331 their application domain.
ramverma3b71c972019-07-10 11:25:37 +0000332
liamfallonf3981072020-07-10 15:59:25 +0100333.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000334
liamfallonf3981072020-07-10 15:59:25 +0100335 A *ContextMap* uses a map to hold the context items. The ContextItem concept instances in the map are indexed by the
336 *LocalName* of their ``ReferenceKey``.
ramverma3b71c972019-07-10 11:25:37 +0000337
liamfallonf3981072020-07-10 15:59:25 +0100338.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000339
liamfallonf3981072020-07-10 15:59:25 +0100340 The *ContextMapType* field of a *ContextMap* defines the type of a context map. The type can have either of two
341 values:
ramverma3b71c972019-07-10 11:25:37 +0000342
liamfallonf3981072020-07-10 15:59:25 +0100343.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000344
liamfallonf3981072020-07-10 15:59:25 +0100345 - A *BAG* context map is a context map with fixed content. Each possible context item in the context map is
346 defined at design time and is held in the *ContextMap* context instance as *ContextItem* concept definitions and
347 only the values of the context items in the context map can be changed at run time. The context items in a *BAG*
348 context map have mixed types and distinct *ContextItem* concept instances of the same type can be defined. A *BAG*
349 context map is convenient for defining a group of context items that are diverse but are related by domain, such as
350 the characteristics of a device. A fully defined *BAG* context map has a fully populated *ContextItem* map but its
351 *ContextItemTemplate* reference is not defined.
ramverma3b71c972019-07-10 11:25:37 +0000352
liamfallonf3981072020-07-10 15:59:25 +0100353 - A *SAMETYPE* context map is used to represent a group of *ContextItem* instances of the same type. Unlike a
354 *BAG* context map, the *ContextItem* concept instances of a *SAMETYPE* context map can be added, modified, and
355 deleted at runtime. All *ContextItem* concept instances in a *SAMETYPE* context map must be of the same type, and
356 that context item is defined as a single *ContextItemTemplate* concept instances at design time. At run time, the
357 *ContextItemTemplate* definition is used to create new *ContextItem* concept instances for the context map on
358 demand. A fully defined *SAMETYPE context map has an empty ContextItem map and its ContextItemTemplate\_*
359 reference is defined.
ramverma3b71c972019-07-10 11:25:37 +0000360
liamfallonf3981072020-07-10 15:59:25 +0100361.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000362
liamfallonf3981072020-07-10 15:59:25 +0100363 The *Scope* of a *ContextMap* defines the range of applicability of a context map in APEX. The following scopes of
364 applicability are defined:
ramverma3b71c972019-07-10 11:25:37 +0000365
liamfallonf3981072020-07-10 15:59:25 +0100366.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000367
liamfallonf3981072020-07-10 15:59:25 +0100368 - *EPHEMERAL* scope means that the context map is owned, used, and modified by a single application but the
369 context map only exists while that application is running
ramverma3b71c972019-07-10 11:25:37 +0000370
liamfallonf3981072020-07-10 15:59:25 +0100371 - *APPLICATION* scope specifies that the context map is owned, used, and modified by a single application, the
372 context map is persistent
ramverma3b71c972019-07-10 11:25:37 +0000373
liamfallonf3981072020-07-10 15:59:25 +0100374 - *GLOBAL* scope specifies that the context map is globally owned and is used and modified by any application,
375 the context map is persistent
ramverma3b71c972019-07-10 11:25:37 +0000376
liamfallonf3981072020-07-10 15:59:25 +0100377 - *EXTERNAL* scope specifies that the context map is owned by an external system and may be used in a read-only
378 manner by any application, the context map is persistent
ramverma3b71c972019-07-10 11:25:37 +0000379
liamfallonf3981072020-07-10 15:59:25 +0100380.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000381
liamfallonf3981072020-07-10 15:59:25 +0100382 A much more sophisticated scoping mechanism for context maps is envisaged for Apex in future work. In such a
383 mechanism, the scope of a context map would work somewhat like the way roles work in security authentication systems.
ramverma3b71c972019-07-10 11:25:37 +0000384
385Concept: ContextItem
liamfallonf3981072020-07-10 15:59:25 +0100386====================
ramverma3b71c972019-07-10 11:25:37 +0000387
liamfallonf3981072020-07-10 15:59:25 +0100388.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000389
liamfallonf3981072020-07-10 15:59:25 +0100390 Each piece of context in a *ContextMap* is represented by an instance of the *ContextItem* concept. Each
391 *ContextItem* concept instance in a context map keyed with a ``ReferenceKey`` key, which references the context map
392 of the context item. The *LocalName* field of the ``ReferenceKey`` holds the name of the context item in the context
393 map A reference to a *DataType* concept defines the data type that values of this context item have at run time. The
394 *WritableFlag* indicates if the context item is read only or read-write at run time.
ramverma3b71c972019-07-10 11:25:37 +0000395
396Concept: ContextItemTemplate
liamfallonf3981072020-07-10 15:59:25 +0100397============================
ramverma3b71c972019-07-10 11:25:37 +0000398
liamfallonf3981072020-07-10 15:59:25 +0100399.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000400
liamfallonf3981072020-07-10 15:59:25 +0100401 In a *SAMETYPE* *ContextMap*, the *ContextItemTemplate* definition provides a template for the *ContextItem*
402 instances that will be created on the context map at run time. Each *ContextItem* concept instance in the context map
403 is created using the *ContextItemTemplate* template. It is keyed with a ``ReferenceKey`` key, which references the
404 context map of the context item. The *LocalName* field of the ``ReferenceKey``, supplied by the creator of the
405 context item at run time, holds the name of the context item in the context map. A reference to a *DataType* concept
406 defines the data type that values of this context item have at run time. The *WritableFlag* indicates if the context
407 item is read only or read-write at run time.
ramverma3b71c972019-07-10 11:25:37 +0000408
409Concept: Task
liamfallonf3981072020-07-10 15:59:25 +0100410=============
ramverma3b71c972019-07-10 11:25:37 +0000411
liamfallonf3981072020-07-10 15:59:25 +0100412.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000413
liamfallonf3981072020-07-10 15:59:25 +0100414 The smallest unit of logic in a policy is a *Task*. A task encapsulates a single atomic unit of logic, and is
415 designed to be a single indivisible unit of execution. A task may be invoked by a single policy or by many policies.
416 A task has a single trigger event, which is sent to the task when it is invoked. Tasks emit one or more outgoing
417 events, which carry the result of the task execution. Tasks may use or modify context as they execute.
ramverma3b71c972019-07-10 11:25:37 +0000418
liamfallonf3981072020-07-10 15:59:25 +0100419.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000420
liamfallonf3981072020-07-10 15:59:25 +0100421 The Task concept definition captures the definition of an APEX task. Task concepts are keyed with an ``ArtifactKey``
422 key. The Trigger of the task is a reference to the *Event* concept that triggers the task. The *OutgoingEvents* of a
423 task are a set of references to *Event* concepts that may be emitted by the task.
ramverma3b71c972019-07-10 11:25:37 +0000424
liamfallonf3981072020-07-10 15:59:25 +0100425.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000426
liamfallonf3981072020-07-10 15:59:25 +0100427 All tasks have logic, some code that is programmed to execute the work of the task. The *Logic* concept of the task
428 holds the definition of that logic.
ramverma3b71c972019-07-10 11:25:37 +0000429
liamfallonf3981072020-07-10 15:59:25 +0100430.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000431
liamfallonf3981072020-07-10 15:59:25 +0100432 The *Task* definition holds a set of *ContextItem* and *ContextItemTemplate* context items that the task is allow to
433 access, as defined by the task developer at design time. The type of access (read-only or read write) that a task has
434 is determined by the *WritableFlag* flag on the individual context item definitions. At run time, a task may only
435 access the context items specified in its context item set, the APEX engine makes only the context items in the task
436 context item set is available to the task.
ramverma3b71c972019-07-10 11:25:37 +0000437
liamfallonf3981072020-07-10 15:59:25 +0100438.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000439
liamfallonf3981072020-07-10 15:59:25 +0100440 A task can be configured with startup parameters. The set of parameters that can be configured on a task are defined
441 as a set of *TaskParameter* concept definitions.
ramverma3b71c972019-07-10 11:25:37 +0000442
443Concept: TaskParameter
liamfallonf3981072020-07-10 15:59:25 +0100444======================
ramverma3b71c972019-07-10 11:25:37 +0000445
liamfallonf3981072020-07-10 15:59:25 +0100446.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000447
liamfallonf3981072020-07-10 15:59:25 +0100448 Each configuration parameter of a task are represented as a *Taskparameter* concept keyed with a ``ReferenceKey``
449 key, which references the task. The *LocalName* field of the ``ReferenceKey`` holds the name of the parameter. The
450 *DefaultValue* field defines the default value that the task parameter is set to. The value of *TaskParameter*
451 instances can be overridden at deployment time by specifying their values in the configuration information passed to
452 APEX engines.
ramverma3b71c972019-07-10 11:25:37 +0000453
liamfallonf3981072020-07-10 15:59:25 +0100454.. container:: paragraph
a.sreekumarcc0e9172020-03-16 13:36:45 +0000455
liamfallonf3981072020-07-10 15:59:25 +0100456 The *taskParameters* field is specified under *engineParameters* in the ApexConfig. It can contain one or more task
457 parameters, where each item can contain the parameter key, value as well as the taskId to which it is associated. If
458 the taskId is not specified, then the parameters are added to all tasks.
a.sreekumarcc0e9172020-03-16 13:36:45 +0000459
ramverma3b71c972019-07-10 11:25:37 +0000460Concept: Logic
liamfallonf3981072020-07-10 15:59:25 +0100461==============
ramverma3b71c972019-07-10 11:25:37 +0000462
liamfallonf3981072020-07-10 15:59:25 +0100463.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000464
liamfallonf3981072020-07-10 15:59:25 +0100465 The *Logic* concept instance holds the actual programmed task logic for a task defined in a *Task* concept or the
466 programmed task selection logic for a state defined in a *State* concept. It is keyed with a ``ReferenceKey`` key,
467 which references the task or state that owns the logic. The *LocalName* field of the Logic concept is the name of the
468 logic.
ramverma3b71c972019-07-10 11:25:37 +0000469
liamfallonf3981072020-07-10 15:59:25 +0100470.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000471
liamfallonf3981072020-07-10 15:59:25 +0100472 The *LogicCode* field of a Logic concept definition is a string that holds the program code that is to be executed
473 at run time. The *LogicType* field defines the language of the code. The standard values are the logic languages
474 supported by APEX: `JAVASCRIPT <https://en.wikipedia.org/wiki/JavaScript>`__, `JAVA <https://java.com/en/>`__,
475 `JYTHON <http://www.jython.org/>`__, `JRUBY <http://jruby.org/>`__, or
476 `MVEL <https://en.wikibooks.org/wiki/Transwiki:MVEL_Language_Guide>`__.
ramverma3b71c972019-07-10 11:25:37 +0000477
liamfallonf3981072020-07-10 15:59:25 +0100478.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000479
liamfallonf3981072020-07-10 15:59:25 +0100480 The APEX engine uses the *LogicType* field value to decide which language interpreter to use for a task and then
481 sends the logic defined in the *LogicCode* field to that interpreter.
ramverma3b71c972019-07-10 11:25:37 +0000482
483Concept: Policy
liamfallonf3981072020-07-10 15:59:25 +0100484===============
ramverma3b71c972019-07-10 11:25:37 +0000485
liamfallonf3981072020-07-10 15:59:25 +0100486.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000487
liamfallonf3981072020-07-10 15:59:25 +0100488 The *Policy* concept defines a policy in APEX. The definition is rather straightforward. A policy is made up of a
489 set of states with the flavor of the policy determining the structure of the policy states and the first state
490 defining what state in the policy executes first. *Policy* concepts are keyed with an ``ArtifactKey`` key.
ramverma3b71c972019-07-10 11:25:37 +0000491
liamfallonf3981072020-07-10 15:59:25 +0100492.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000493
liamfallonf3981072020-07-10 15:59:25 +0100494 The *PolicyFlavour* of a *Policy* concept specifies the structure that will be used for the states in the policy. A
495 number of commonly used policy patterns are supported as APEX policy flavors. The standard policy flavors are:
ramverma3b71c972019-07-10 11:25:37 +0000496
liamfallonf3981072020-07-10 15:59:25 +0100497.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000498
liamfallonf3981072020-07-10 15:59:25 +0100499 - The *MEDA* flavor supports policies written to the
500 `MEDA policy pattern <https://www.researchgate.net/publication/282576518_Dynamically_Adaptive_Policies_for_Dynamically_Adaptive_Telecommunications_Networks>`__
501 and require a sequence of four states: namely *Match*, *Establish*, *Decide* and *Act*.
ramverma3b71c972019-07-10 11:25:37 +0000502
liamfallonf3981072020-07-10 15:59:25 +0100503 - The *OODA* flavor supports policies written to the
504 `OODA loop pattern <https://en.wikipedia.org/wiki/OODA_loop>`__ and require a sequence of four states: namely
505 *Observe*, *Orient*, *Decide* and *Act*.
ramverma3b71c972019-07-10 11:25:37 +0000506
liamfallonf3981072020-07-10 15:59:25 +0100507 - The *ECA* flavor supports policies written to the
508 `ECA active rule pattern <https://en.wikipedia.org/wiki/Event_condition_action>`__ and require a sequence of three
509 states: namely *Event*, *Condition* and *Action*
ramverma3b71c972019-07-10 11:25:37 +0000510
liamfallonf3981072020-07-10 15:59:25 +0100511 - The *XACML* flavor supports policies written in `XACML <https://en.wikipedia.org/wiki/XACML>`__ and require a
512 single state: namely *XACML*
ramverma3b71c972019-07-10 11:25:37 +0000513
liamfallonf3981072020-07-10 15:59:25 +0100514 - The *FREEFORM* flavor supports policies written in an arbitrary style. A user can define a *FREEFORM* policy
515 as an arbitrarily long chain of states.
ramverma3b71c972019-07-10 11:25:37 +0000516
liamfallonf3981072020-07-10 15:59:25 +0100517.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000518
liamfallonf3981072020-07-10 15:59:25 +0100519 The *FirstState* field of a *Policy* definition is the starting point for execution of a policy. Therefore, the
520 trigger event of the state referenced in the *FirstState* field is also the trigger event for the entire policy.
ramverma3b71c972019-07-10 11:25:37 +0000521
522Concept: State
liamfallonf3981072020-07-10 15:59:25 +0100523==============
ramverma3b71c972019-07-10 11:25:37 +0000524
liamfallonf3981072020-07-10 15:59:25 +0100525.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000526
liamfallonf3981072020-07-10 15:59:25 +0100527 The *State* concept represents a phase or a stage in a policy, with a policy being composed of a series of states.
528 Each state has at least one but may have many tasks and, on each run of execution, a state executes one and only one
529 of its tasks. If a state has more than one task, then its task selection logic is used to select which task to
530 execute. Task selection logic is programmable logic provided by the state designer. That logic can use incoming,
531 policy, global, and external context to select which task best accomplishes the purpose of the state in a give
532 situation if more than one task has been specified on a state. A state calls one and only one task when it is
533 executed.
ramverma3b71c972019-07-10 11:25:37 +0000534
liamfallonf3981072020-07-10 15:59:25 +0100535.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000536
liamfallonf3981072020-07-10 15:59:25 +0100537 Each state is triggered by an event, which means that all tasks of a state must also be triggered by that same
538 event. The set of output events for a state is the union of all output events from all tasks for that task. In
539 practice at the moment, because a state can only have a single input event, a state that is not the final state of a
540 policy may only output a single event and all tasks of that state may also only output that single event. In future
541 work, the concept of having a less restrictive trigger pattern will be examined.
ramverma3b71c972019-07-10 11:25:37 +0000542
liamfallonf3981072020-07-10 15:59:25 +0100543.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000544
liamfallonf3981072020-07-10 15:59:25 +0100545 A *State* concept is keyed with a ``ReferenceKey`` key, which references the *Policy* concept that owns the state.
546 The *LocalName* field of the ``ReferenceKey`` holds the name of the state. As a state is part of a chain of states,
547 the *NextState* field of a state holds the ``ReferenceKey`` key of the state in the policy to execute after this
548 state.
ramverma3b71c972019-07-10 11:25:37 +0000549
liamfallonf3981072020-07-10 15:59:25 +0100550.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000551
liamfallonf3981072020-07-10 15:59:25 +0100552 The *Trigger* field of a state holds the ``ArtifactKey`` of the event that triggers this state. The *OutgoingEvents*
553 field holds the ``ArtifactKey`` references of all possible events that may be output from the state. This is a set
554 that is the union of all output events of all tasks of the state.
ramverma3b71c972019-07-10 11:25:37 +0000555
liamfallonf3981072020-07-10 15:59:25 +0100556.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000557
liamfallonf3981072020-07-10 15:59:25 +0100558 The *Task* concepts that hold the definitions of the task for the state are held as a set of ``ArtifactKey``
559 references in the state. The *DefaultTask* field holds a reference to the default task for the state, a task that is
560 executed if no task selection logic is specified. If the state has only one task, that task is the default task.
ramverma3b71c972019-07-10 11:25:37 +0000561
liamfallonf3981072020-07-10 15:59:25 +0100562.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000563
liamfallonf3981072020-07-10 15:59:25 +0100564 The *Logic* concept referenced by a state holds the task selection logic for a state. The task selection logic uses
565 the incoming context (parameters of the incoming event) and other context to determine the best task to use to
566 execute its goals. The state holds a set of references to *ContextItem* and *ContextItemTemplate* definitions for the
567 context used by its task selection logic.
ramverma3b71c972019-07-10 11:25:37 +0000568
liamfallonf3981072020-07-10 15:59:25 +0100569*************
ramverma3b71c972019-07-10 11:25:37 +0000570Writing Logic
liamfallonf3981072020-07-10 15:59:25 +0100571*************
ramverma3b71c972019-07-10 11:25:37 +0000572
573Writing APEX Task Logic
liamfallonf3981072020-07-10 15:59:25 +0100574=======================
ramverma3b71c972019-07-10 11:25:37 +0000575
liamfallonf3981072020-07-10 15:59:25 +0100576.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000577
liamfallonf3981072020-07-10 15:59:25 +0100578 Task logic specifies the behavior of an Apex Task. This logic can be specified in a number of ways, exploiting
579 Apex’s plug-in architecture to support a range of logic executors. In Apex scripted Task Logic can be written in any
580 of these languages:
ramverma3b71c972019-07-10 11:25:37 +0000581
liamfallonf3981072020-07-10 15:59:25 +0100582.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000583
liamfallonf3981072020-07-10 15:59:25 +0100584 - ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__,
ramverma3b71c972019-07-10 11:25:37 +0000585
liamfallonf3981072020-07-10 15:59:25 +0100586 - ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
ramverma3b71c972019-07-10 11:25:37 +0000587
liamfallonf3981072020-07-10 15:59:25 +0100588 - ```JRuby`` <https://en.wikipedia.org/wiki/JRuby>`__ or
ramverma3b71c972019-07-10 11:25:37 +0000589
liamfallonf3981072020-07-10 15:59:25 +0100590 - ```Jython`` <https://en.wikipedia.org/wiki/Jython>`__.
ramverma3b71c972019-07-10 11:25:37 +0000591
liamfallonf3981072020-07-10 15:59:25 +0100592.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000593
liamfallonf3981072020-07-10 15:59:25 +0100594 These languages were chosen because the scripts can be compiled into Java bytecode at runtime and then efficiently
595 executed natively in the JVM. Task Logic an also be written directly in Java but needs to be compiled, with the
596 resulting classes added to the classpath. There are also a number of other Task Logic types (e.g. Fuzzy Logic), but
597 these are not supported as yet. This guide will focus on the scripted Task Logic approaches, with MVEL and JavaScript
598 being our favorite languages. In particular this guide will focus on the Apex aspects of the scripts. However, this
599 guide does not attempt to teach you about the scripting languages themselves …​ that is up to you!
ramverma3b71c972019-07-10 11:25:37 +0000600
liamfallonf3981072020-07-10 15:59:25 +0100601.. tip::
602 JVM-based scripting languages For more more information on scripting for the Java platform see:
603 https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
ramverma3b71c972019-07-10 11:25:37 +0000604
liamfallonf3981072020-07-10 15:59:25 +0100605.. note::
606 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
607 of the steps in an Apex Policy. Each task receives some *incoming fields*, executes some logic (e.g: make a decision
608 based on *shared state* or *context*, *incoming fields*, *external context*, etc.), perhaps set some *shared state*
609 or *context* and then emits *outgoing fields*. The state that uses the task is responsible for extracting the
610 *incoming fields* from the state input event. The state also has an *output mapper* associated with the task, and
611 this *output mapper* is responsible for mapping the *outgoing fields* from the task into an appropriate output event
612 for the state.
ramverma3b71c972019-07-10 11:25:37 +0000613
liamfallonf3981072020-07-10 15:59:25 +0100614.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000615
liamfallonf3981072020-07-10 15:59:25 +0100616 First lets start with a sample task, drawn from the "My First Apex Policy" example: The task "MorningBoozeCheck"
617 from the "My First Apex Policy" example is available in both MVEL and JavaScript:
ramverma3b71c972019-07-10 11:25:37 +0000618
liamfallonf3981072020-07-10 15:59:25 +0100619.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +0000620
liamfallonf3981072020-07-10 15:59:25 +0100621 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +0000622
liamfallonf3981072020-07-10 15:59:25 +0100623 Javascript code for the ``MorningBoozeCheck`` task
ramverma3b71c972019-07-10 11:25:37 +0000624
liamfallonf3981072020-07-10 15:59:25 +0100625 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +0000626
liamfallonf3981072020-07-10 15:59:25 +0100627 .. code:: javascript
628 :number-lines:
ramverma3b71c972019-07-10 11:25:37 +0000629
liamfallonf3981072020-07-10 15:59:25 +0100630 /*
631 * ============LICENSE_START=======================================================
632 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
633 * Modifications Copyright (C) 2020 Nordix Foundation.
634 * ================================================================================
635 * Licensed under the Apache License, Version 2.0 (the "License");
636 * you may not use this file except in compliance with the License.
637 * You may obtain a copy of the License at
638 *
639 * http://www.apache.org/licenses/LICENSE-2.0
640 *
641 * Unless required by applicable law or agreed to in writing, software
642 * distributed under the License is distributed on an "AS IS" BASIS,
643 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
644 * See the License for the specific language governing permissions and
645 * limitations under the License.
646 *
647 * SPDX-License-Identifier: Apache-2.0
648 * ============LICENSE_END=========================================================
649 */
ramverma3b71c972019-07-10 11:25:37 +0000650
liamfallonf3981072020-07-10 15:59:25 +0100651 executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'");
ramverma3b71c972019-07-10 11:25:37 +0000652
liamfallonf3981072020-07-10 15:59:25 +0100653 executor.outFields.put("amount" , executor.inFields.get("amount"));
654 executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID"));
655 executor.outFields.put("notes" , executor.inFields.get("notes"));
656 executor.outFields.put("quantity" , executor.inFields.get("quantity"));
657 executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID"));
658 executor.outFields.put("item_ID" , executor.inFields.get("item_ID"));
659 executor.outFields.put("time" , executor.inFields.get("time"));
660 executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID"));
ramverma3b71c972019-07-10 11:25:37 +0000661
liamfallonf3981072020-07-10 15:59:25 +0100662 item_id = executor.inFields.get("item_ID");
ramverma3b71c972019-07-10 11:25:37 +0000663
liamfallonf3981072020-07-10 15:59:25 +0100664 //All times in this script are in GMT/UTC since the policy and events assume time is in GMT.
665 var timenow_gmt = new Date(Number(executor.inFields.get("time")));
ramverma3b71c972019-07-10 11:25:37 +0000666
liamfallonf3981072020-07-10 15:59:25 +0100667 var midnight_gmt = new Date(Number(executor.inFields.get("time")));
668 midnight_gmt.setUTCHours(0,0,0,0);
ramverma3b71c972019-07-10 11:25:37 +0000669
liamfallonf3981072020-07-10 15:59:25 +0100670 var eleven30_gmt = new Date(Number(executor.inFields.get("time")));
671 eleven30_gmt.setUTCHours(11,30,0,0);
ramverma3b71c972019-07-10 11:25:37 +0000672
liamfallonf3981072020-07-10 15:59:25 +0100673 var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z");
ramverma3b71c972019-07-10 11:25:37 +0000674
liamfallonf3981072020-07-10 15:59:25 +0100675 var itemisalcohol = false;
676 if(item_id != null && item_id >=1000 && item_id < 2000)
677 itemisalcohol = true;
ramverma3b71c972019-07-10 11:25:37 +0000678
liamfallonf3981072020-07-10 15:59:25 +0100679 if( itemisalcohol
680 && timenow_gmt.getTime() >= midnight_gmt.getTime()
681 && timenow_gmt.getTime() < eleven30_gmt.getTime()) {
ramverma3b71c972019-07-10 11:25:37 +0000682
liamfallonf3981072020-07-10 15:59:25 +0100683 executor.outFields.put("authorised", false);
684 executor.outFields.put("message", "Sale not authorised by policy task " +
685 executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) +
686 ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) +
687 " and " + timeformatter.format(eleven30_gmt.getTime()));
688 }
689 else{
690 executor.outFields.put("authorised", true);
691 executor.outFields.put("message", "Sale authorised by policy task " +
692 executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime()));
693 }
ramverma3b71c972019-07-10 11:25:37 +0000694
liamfallonf3981072020-07-10 15:59:25 +0100695 /*
696 This task checks if a sale request is for an item that is an alcoholic drink.
697 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
698 authorised. Otherwise the sale is authorised.
699 In this implementation we assume that items with item_ID value between 1000 and
700 2000 are all alcoholic drinks :-)
701 */
ramverma3b71c972019-07-10 11:25:37 +0000702
liamfallonf3981072020-07-10 15:59:25 +0100703 true;
ramverma3b71c972019-07-10 11:25:37 +0000704
liamfallonf3981072020-07-10 15:59:25 +0100705.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +0000706
liamfallonf3981072020-07-10 15:59:25 +0100707 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +0000708
liamfallonf3981072020-07-10 15:59:25 +0100709 MVEL code for the ``MorningBoozeCheck`` task
ramverma3b71c972019-07-10 11:25:37 +0000710
liamfallonf3981072020-07-10 15:59:25 +0100711 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +0000712
liamfallonf3981072020-07-10 15:59:25 +0100713 .. code:: javascript
714 :number-lines:
ramverma3b71c972019-07-10 11:25:37 +0000715
liamfallonf3981072020-07-10 15:59:25 +0100716 /*
717 * ============LICENSE_START=======================================================
718 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
719 * Modifications Copyright (C) 2020 Nordix Foundation.
720 * ================================================================================
721 * Licensed under the Apache License, Version 2.0 (the "License");
722 * you may not use this file except in compliance with the License.
723 * You may obtain a copy of the License at
724 *
725 * http://www.apache.org/licenses/LICENSE-2.0
726 *
727 * Unless required by applicable law or agreed to in writing, software
728 * distributed under the License is distributed on an "AS IS" BASIS,
729 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
730 * See the License for the specific language governing permissions and
731 * limitations under the License.
732 *
733 * SPDX-License-Identifier: Apache-2.0
734 * ============LICENSE_END=========================================================
735 */
736 import java.util.Date;
737 import java.util.Calendar;
738 import java.util.TimeZone;
739 import java.text.SimpleDateFormat;
ramverma3b71c972019-07-10 11:25:37 +0000740
liamfallonf3981072020-07-10 15:59:25 +0100741 logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
ramverma3b71c972019-07-10 11:25:37 +0000742
liamfallonf3981072020-07-10 15:59:25 +0100743 outFields.put("amount" , inFields.get("amount"));
744 outFields.put("assistant_ID", inFields.get("assistant_ID"));
745 outFields.put("notes" , inFields.get("notes"));
746 outFields.put("quantity" , inFields.get("quantity"));
747 outFields.put("branch_ID" , inFields.get("branch_ID"));
748 outFields.put("item_ID" , inFields.get("item_ID"));
749 outFields.put("time" , inFields.get("time"));
750 outFields.put("sale_ID" , inFields.get("sale_ID"));
ramverma3b71c972019-07-10 11:25:37 +0000751
liamfallonf3981072020-07-10 15:59:25 +0100752 item_id = inFields.get("item_ID");
ramverma3b71c972019-07-10 11:25:37 +0000753
liamfallonf3981072020-07-10 15:59:25 +0100754 //The events used later to test this task use GMT timezone!
755 gmt = TimeZone.getTimeZone("GMT");
756 timenow = Calendar.getInstance(gmt);
757 df = new SimpleDateFormat("HH:mm:ss z");
758 df.setTimeZone(gmt);
759 timenow.setTimeInMillis(inFields.get("time"));
ramverma3b71c972019-07-10 11:25:37 +0000760
liamfallonf3981072020-07-10 15:59:25 +0100761 midnight = timenow.clone();
762 midnight.set(
763 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
764 timenow.get(Calendar.DATE),0,0,0);
765 eleven30 = timenow.clone();
766 eleven30.set(
767 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
768 timenow.get(Calendar.DATE),11,30,0);
ramverma3b71c972019-07-10 11:25:37 +0000769
liamfallonf3981072020-07-10 15:59:25 +0100770 itemisalcohol = false;
771 if(item_id != null && item_id >=1000 && item_id < 2000)
772 itemisalcohol = true;
ramverma3b71c972019-07-10 11:25:37 +0000773
liamfallonf3981072020-07-10 15:59:25 +0100774 if( itemisalcohol
775 && timenow.after(midnight) && timenow.before(eleven30)){
776 outFields.put("authorised", false);
777 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
778 " for time "+df.format(timenow.getTime())+
779 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
780 " and "+df.format(eleven30.getTime()));
781 return true;
782 }
783 else{
784 outFields.put("authorised", true);
785 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
786 " for time "+df.format(timenow.getTime()));
787 return true;
788 }
ramverma3b71c972019-07-10 11:25:37 +0000789
liamfallonf3981072020-07-10 15:59:25 +0100790 /*
791 This task checks if a sale request is for an item that is an alcoholic drink.
792 If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
793 authorised. Otherwise the sale is authorised.
794 In this implementation we assume that items with item_ID value between 1000 and
795 2000 are all alcoholic drinks :-)
796 */
ramverma3b71c972019-07-10 11:25:37 +0000797
liamfallonf3981072020-07-10 15:59:25 +0100798.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000799
liamfallonf3981072020-07-10 15:59:25 +0100800 The role of the task in this simple example is to copy the values in the incoming fields into the outgoing
801 fields, then examine the values in some incoming fields (``item_id`` and ``time``), then set the values in some
802 other outgoing fields (``authorised`` and ``message``).
ramverma3b71c972019-07-10 11:25:37 +0000803
liamfallonf3981072020-07-10 15:59:25 +0100804.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000805
liamfallonf3981072020-07-10 15:59:25 +0100806 Both MVEL and JavaScript like most JVM-based scripting languages can use standard Java libraries to perform
807 complex tasks. Towards the top of the scripts you will see how to import Java classes and packages to be used
808 directly in the logic. Another thing to notice is that Task Logic should return a ``java.lang.Boolean`` value
809 ``true`` if the logic executed correctly. If the logic fails for some reason then ``false`` can be returned, but
810 this will cause the policy invoking this task will fail and exit.
ramverma3b71c972019-07-10 11:25:37 +0000811
liamfallonf3981072020-07-10 15:59:25 +0100812.. note::
813 How to return a value from task logic
814 Some languages explicitly support returning values from the script (e.g. MVEL and JRuby) using an explicit
815 return statement (e.g. ``return true``), other languages do not (e.g. Jython). For
816 languages that do not support the ``return`` statement, a special field called ``returnValue`` must be
817 created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
818 value to the ``returnValue`` field before completing the task).
819 Also, in MVEL if there is no explicit return statement then the return value of the last executed statement will
820 return (e.g. the statement a=(1+2) will return the value 3).
ramverma3b71c972019-07-10 11:25:37 +0000821
liamfallonf3981072020-07-10 15:59:25 +0100822 For Javascript, the last statement of a script must be a statement that evaluates to *true* or *false*, indicating
823 whether the script executed correctly or not. In the case where the script always executes to compeletion
824 sucessfully, simply add a last line with the statement *true'*. In cases where success or failure is assessed in the
825 script, create a boolean
826 local variable with a name such as ``returnvalue``. In the execution of the script, set ``returnValue`` to be ``true``
827 or ``false`` as appropriate. The last line of the scritp tehn should simply be ``returnValue;``, which returns the
828 value of ``returnValue``.
ramverma3b71c972019-07-10 11:25:37 +0000829
liamfallonf3981072020-07-10 15:59:25 +0100830.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000831
liamfallonf3981072020-07-10 15:59:25 +0100832 Besides these imported classes and normal language features Apex provides some natively available parameters
833 and functions that can be used directly. At run-time these parameters are populated by the Apex execution
834 environment and made natively available to logic scripts each time the logic script is invoked. (These can be
835 accessed using the ``executor`` keyword for most languages, or can be accessed directly without the
836 ``executor`` keyword in MVEL):
ramverma3b71c972019-07-10 11:25:37 +0000837
liamfallonf3981072020-07-10 15:59:25 +0100838Table 1. The ``executor`` Fields / Methods
ramverma760cce92019-07-11 12:57:49 +0000839
liamfallonf3981072020-07-10 15:59:25 +0100840 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
841 | Name | Type | Java type | Description |
842 +=====================================================+==========================================================================+===============================+==================================================================================+
843 | inFields | Fields | java.util.Map <String,Object> |The incoming task fields, implemented as a standard Java (unmodifiable) Map |
844 | | | | |
845 | | | |**Example:** |
846 | | | | |
847 | | | |.. code:: javascript |
848 | | | | |
849 | | | | executor.logger.debug("Incoming fields: " +executor.inFields.entrySet()); |
850 | | | | var item_id = executor.incomingFields["item_ID"]; |
851 | | | | if (item_id >=1000) { ... } |
852 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
853 | outFields | Fields | java.util.Map <String,Object> |The outgoing task fields. This is implemented as a standard initially empty Java |
854 | | | |(modifiable) Map. To create a new schema-compliant instance of a field object |
855 | | | |see the utility method subject.getOutFieldSchemaHelper() below |
856 | | | | |
857 | | | |**Example:** |
858 | | | | |
859 | | | |.. code:: javascript |
860 | | | | |
861 | | | | executor.outFields["authorised"] = false; |
862 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
863 | logger | Logger | org.slf4j.ext.XLogger |A helpful logger |
864 | | | | |
865 | | | |**Example:** |
866 | | | | |
867 | | | |.. code:: javascript |
868 | | | | |
869 | | | | executor.logger.info("Executing task: " +executor.subject.id); |
870 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
871 | TRUE/FALSE | boolean | java.lang.Boolean |2 helpful constants. These are useful to retrieve correct return values for the |
872 | | | |task logic |
873 | | | | |
874 | | | |**Example:** |
875 | | | | |
876 | | | |.. code:: javascript |
877 | | | | |
878 | | | | var returnValue = executor.isTrue; |
879 | | | | var returnValueType = Java.type("java.lang.Boolean"); |
880 | | | | var returnValue = new returnValueType(true); |
881 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
882 | subject | Task | TaskFacade |This provides some useful information about the task that contains this task |
883 | | | |logic. This object has some useful fields and methods : |
884 | | | | |
885 | | | |.. container:: ulist |
886 | | | | |
887 | | | | - **AxTask task** to get access to the full task definition of the host task |
888 | | | | |
889 | | | | - **String getTaskName()** to get the name of the host task |
890 | | | | |
891 | | | | - **String getId()** to get the ID of the host task |
892 | | | | |
893 | | | | - **SchemaHelper getInFieldSchemaHelper( String fieldName )** to |
894 | | | | get a ``SchemaHelper`` helper object to manipulate incoming |
895 | | | | task fields in a schema-aware manner |
896 | | | | |
897 | | | | - **SchemaHelper getOutFieldSchemaHelper( String fieldName )** to |
898 | | | | get a ``SchemaHelper`` helper object to manipulate outgoing |
899 | | | | task fields in a schema-aware manner, e.g. to instantiate new |
900 | | | | schema-compliant field objects to populate the |
901 | | | | ``executor.outFields`` outgoing fields map |
902 | | | | |
903 | | | |**Example:** |
904 | | | | |
905 | | | |.. code:: javascript |
906 | | | | |
907 | | | | executor.logger.info("Task name: " + executor.subject.getTaskName()); |
908 | | | | executor.logger.info("Task id: " + executor.subject.getId()); |
909 | | | | executor.logger.info("Task inputs definitions: " |
910 | | | | + "executor.subject.task.getInputFieldSet()); |
911 | | | | executor.logger.info("Task outputs definitions: " |
912 | | | | + "executor.subject.task.getOutputFieldSet()); |
913 | | | | executor.outFields["authorised"] = executor.subject |
914 | | | | .getOutFieldSchemaHelper("authorised").createNewInstance("false"); |
915 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
916 | ContextAlbum getContextAlbum(String ctxtAlbumName ) |A utility method to retrieve a ``ContextAlbum`` for use in the task. | | |
917 | |This is how you access the context used by the task. The returned | | |
918 | |``ContextAlbum`` implements the ``java.util.Map <String,Object>`` | | |
919 | |interface to get and set context as appropriate. The returned | | |
920 | |``ContextAlbum`` also has methods to lock context albums, get | | |
921 | |information about the schema of the items to be stored in a context | | |
922 | |album, and get a ``SchemaHelper`` to manipulate context album items. How | | |
923 | |to define and use context in a task is described in the Apex | | |
924 | |Programmer’s Guide and in the My First Apex Policy guide. | | |
925 | | | | |
926 | |**Example:** | | |
927 | | | | |
928 | |.. code:: javascript | | |
929 | | | | |
930 | | var bkey = executor.inFields.get("branch_ID"); | | |
931 | | var cnts = executor.getContextMap("BranchCounts"); | | |
932 | | cnts.lockForWriting(bkey); | | |
933 | | cnts.put(bkey, cnts.get(bkey) + 1); | | |
934 | | cnts.unlockForWriting(bkey); | | |
935 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +0000936
937Writing APEX Task Selection Logic
liamfallonf3981072020-07-10 15:59:25 +0100938=================================
ramverma3b71c972019-07-10 11:25:37 +0000939
liamfallonf3981072020-07-10 15:59:25 +0100940.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000941
liamfallonf3981072020-07-10 15:59:25 +0100942 The function of Task Selection Logic is to choose which task should be executed for an Apex State as one of
943 the steps in an Apex Policy. Since each state must define a default task there is no need for Task Selection
944 Logic unless the state uses more than one task. This logic can be specified in a number of ways, exploiting
945 Apex’s plug-in architecture to support a range of logic executors. In Apex scripted Task Selection Logic can be
946 written in any of these languages:
ramverma3b71c972019-07-10 11:25:37 +0000947
liamfallonf3981072020-07-10 15:59:25 +0100948.. container:: ulist
ramverma3b71c972019-07-10 11:25:37 +0000949
liamfallonf3981072020-07-10 15:59:25 +0100950 - ```MVEL`` <https://en.wikipedia.org/wiki/MVEL>`__,
ramverma3b71c972019-07-10 11:25:37 +0000951
liamfallonf3981072020-07-10 15:59:25 +0100952 - ```JavaScript`` <https://en.wikipedia.org/wiki/JavaScript>`__,
ramverma3b71c972019-07-10 11:25:37 +0000953
liamfallonf3981072020-07-10 15:59:25 +0100954 - ```JRuby`` <https://en.wikipedia.org/wiki/JRuby>`__ or
ramverma3b71c972019-07-10 11:25:37 +0000955
liamfallonf3981072020-07-10 15:59:25 +0100956 - ```Jython`` <https://en.wikipedia.org/wiki/Jython>`__.
ramverma3b71c972019-07-10 11:25:37 +0000957
liamfallonf3981072020-07-10 15:59:25 +0100958.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000959
liamfallonf3981072020-07-10 15:59:25 +0100960 These languages were chosen because the scripts can be compiled into Java bytecode at runtime and then
961 efficiently executed natively in the JVM. Task Selection Logic an also be written directly in Java but needs to
962 be compiled, with the resulting classes added to the classpath. There are also a number of other Task Selection
963 Logic types but these are not supported as yet. This guide will focus on the scripted Task Selection Logic
964 approaches, with MVEL and JavaScript being our favorite languages. In particular this guide will focus on the
965 Apex aspects of the scripts. However, this guide does not attempt to teach you about the scripting languages
966 themselves …​ that is up to you!
ramverma3b71c972019-07-10 11:25:37 +0000967
liamfallonf3981072020-07-10 15:59:25 +0100968.. tip::
969 JVM-based scripting languages
970 For more more information on Scripting for the Java platform see:
971 https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/index.html
ramverma3b71c972019-07-10 11:25:37 +0000972
liamfallonf3981072020-07-10 15:59:25 +0100973.. note::
974 What does Task Selection Logic do?
975 When an Apex state references multiple tasks, there must be a way to dynamically decide
976 which task should be chosen and executed. This can depend on the many factors, e.g. the
977 *incoming event for the state*, *shared state* or *context*, *external context*,
978 etc.. This is the function of a state’s Task Selection Logic. Obviously, if there is
979 only one task then Task only one task then Task Selection Logic is not needed.
980 Each state must also select one of the tasks a the *default state*. If the Task
981 Selection Logic is unable to select an appropriate task, then it should select the
982 *default task*. Once the task has been selected the Apex Engine will then execute that task.
ramverma3b71c972019-07-10 11:25:37 +0000983
liamfallonf3981072020-07-10 15:59:25 +0100984.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +0000985
liamfallonf3981072020-07-10 15:59:25 +0100986 First lets start with some simple Task Selection Logic, drawn from the "My First Apex Policy" example: The Task
987 Selection Logic from the "My First Apex Policy" example is specified in JavaScript here:
ramverma3b71c972019-07-10 11:25:37 +0000988
liamfallonf3981072020-07-10 15:59:25 +0100989.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +0000990
liamfallonf3981072020-07-10 15:59:25 +0100991 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +0000992
liamfallonf3981072020-07-10 15:59:25 +0100993 Javascript code for the "My First Policy" Task Selection Logic
ramverma3b71c972019-07-10 11:25:37 +0000994
liamfallonf3981072020-07-10 15:59:25 +0100995 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +0000996
liamfallonf3981072020-07-10 15:59:25 +0100997 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +0000998
liamfallonf3981072020-07-10 15:59:25 +0100999 /*
1000 * ============LICENSE_START=======================================================
1001 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
1002 * Modifications Copyright (C) 2020 Nordix Foundation.
1003 * ================================================================================
1004 * Licensed under the Apache License, Version 2.0 (the "License");
1005 * you may not use this file except in compliance with the License.
1006 * You may obtain a copy of the License at
1007 *
1008 * http://www.apache.org/licenses/LICENSE-2.0
1009 *
1010 * Unless required by applicable law or agreed to in writing, software
1011 * distributed under the License is distributed on an "AS IS" BASIS,
1012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1013 * See the License for the specific language governing permissions and
1014 * limitations under the License.
1015 *
1016 * SPDX-License-Identifier: Apache-2.0
1017 * ============LICENSE_END=========================================================
1018 */
ramverma3b71c972019-07-10 11:25:37 +00001019
liamfallonf3981072020-07-10 15:59:25 +01001020 executor.logger.info("Task Selection Execution: '"+executor.subject.id+
1021 "'. Input Event: '"+executor.inFields+"'");
ramverma3b71c972019-07-10 11:25:37 +00001022
liamfallonf3981072020-07-10 15:59:25 +01001023 branchid = executor.inFields.get("branch_ID");
1024 taskorig = executor.subject.getTaskKey("MorningBoozeCheck");
1025 taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1");
1026 taskdef = executor.subject.getDefaultTaskKey();
ramverma3b71c972019-07-10 11:25:37 +00001027
liamfallonf3981072020-07-10 15:59:25 +01001028 if(branchid >=0 && branchid <1000){
1029 taskorig.copyTo(executor.selectedTask);
1030 }
1031 else if (branchid >=1000 && branchid <2000){
1032 taskalt.copyTo(executor.selectedTask);
1033 }
1034 else{
1035 taskdef.copyTo(executor.selectedTask);
1036 }
ramverma3b71c972019-07-10 11:25:37 +00001037
liamfallonf3981072020-07-10 15:59:25 +01001038 /*
1039 This task selection logic selects task "MorningBoozeCheck" for branches with
1040 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with
1041 1000<=branch_ID<2000. Otherwise the default task is selected.
1042 In this case the default task is also "MorningBoozeCheck"
1043 */
ramverma3b71c972019-07-10 11:25:37 +00001044
liamfallonf3981072020-07-10 15:59:25 +01001045 true;
ramverma3b71c972019-07-10 11:25:37 +00001046
liamfallonf3981072020-07-10 15:59:25 +01001047.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001048
liamfallonf3981072020-07-10 15:59:25 +01001049 The role of the Task Selection Logic in this simple example is to examine the value in one incoming field
1050 (``branchid``), then depending on that field’s value set the value for the selected task to the appropriate task
1051 (``MorningBoozeCheck``, ``MorningBoozeCheckAlt1``, or the default task).
ramverma3b71c972019-07-10 11:25:37 +00001052
liamfallonf3981072020-07-10 15:59:25 +01001053.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001054
liamfallonf3981072020-07-10 15:59:25 +01001055 Another thing to notice is that Task Selection Logic should return a ``java.lang.Boolean`` value ``true`` if
1056 the logic executed correctly. If the logic fails for some reason then ``false`` can be returned, but this will
1057 cause the policy invoking this task will fail and exit.
ramverma3b71c972019-07-10 11:25:37 +00001058
liamfallonf3981072020-07-10 15:59:25 +01001059.. note::
1060 How to return a value from Task Selection Logic
1061 Some languages explicitly support returning values from the script (e.g. MVEL and
1062 JRuby) using an explicit return statement (e.g. ``return true``), other languages do not (e.g.
1063 JavaScript and Jython). For languages that do not support the ``return`` statement, a special field called
1064 ``returnValue`` must be created to hold the result of the task logic operation (i.e. assign a ``java.lang.Boolean``
1065 value to the ``returnValue`` field before completing the task).
1066 Also, in MVEL if there is not explicit return statement then the return value of the last executed statement will
1067 return (e.g. the statement a=(1+2) will return the value 3).
ramverma3b71c972019-07-10 11:25:37 +00001068
liamfallonf3981072020-07-10 15:59:25 +01001069.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001070
liamfallonf3981072020-07-10 15:59:25 +01001071 Each of the scripting languages used in Apex can import and use standard Java libraries to perform complex tasks.
1072 Besides imported classes and normal language features Apex provides some natively available parameters and functions
1073 that can be used directly. At run-time these parameters are populated by the Apex execution environment and made
1074 natively available to logic scripts each time the logic script is invoked. (These can be accessed using the
1075 ``executor`` keyword for most languages, or can be accessed directly without the ``executor`` keyword in MVEL):
ramverma3b71c972019-07-10 11:25:37 +00001076
liamfallonf3981072020-07-10 15:59:25 +01001077Table 2. The ``executor`` Fields / Methods
1078 +-----------------------------------+------------------------------------+
1079 | Unix, Cygwin | Windows |
1080 +===================================+====================================+
1081 |.. container:: content |.. container:: content |
1082 | | |
1083 | .. code:: bash | .. code:: bash |
1084 | :number-lines: | :number-lines: |
1085 | | |
1086 | >c: | # cd /usr/local/src/apex-pdp |
1087 | >cd \dev\apex | # mvn clean install -DskipTests |
1088 | >mvn clean install -DskipTests | |
1089 +-----------------------------------+------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +00001090
liamfallonf3981072020-07-10 15:59:25 +01001091 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1092 | Name | Type | Java type | Description |
1093 +=====================================================+==========================================================================+===============================+==================================================================================+
1094 | inFields | Fields | java.util.Map <String,Object> | All fields in the state’s incoming event. This is implemented as a standard Java |
1095 | | | | Java (unmodifiable) Map |
1096 | | | | |
1097 | | | | **Example:** |
1098 | | | | |
1099 | | | | .. code:: javascript |
1100 | | | | |
1101 | | | | executor.logger.debug("Incoming fields: " + executor.inFields.entrySet()); |
1102 | | | | var item_id = executor.incomingFields["item_ID"]; |
1103 | | | | if (item_id >=1000) { ... } |
1104 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1105 | outFields | Fields | java.util.Map <String,Object> | The outgoing task fields. This is implemented as a standard initially empty Java |
1106 | | | | (modifiable) Map. To create a new schema-compliant instance of a field object |
1107 | | | | see the utility method subject.getOutFieldSchemaHelper() below |
1108 | | | | |
1109 | | | | **Example:** |
1110 | | | | |
1111 | | | | .. code:: javascript |
1112 | | | | |
1113 | | | | executor.outFields["authorised"] = false; |
1114 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1115 | logger | Logger | org.slf4j.ext.XLogger | A helpful logger |
1116 | | | | |
1117 | | | | **Example:** |
1118 | | | | |
1119 | | | | .. code:: javascript |
1120 | | | | |
1121 | | | | executor.logger.info("Executing task: " |
1122 | | | | +executor.subject.id); |
1123 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1124 | TRUE/FALSE | boolean | java.lang.Boolean | 2 helpful constants. These are useful to retrieve correct return values for the |
1125 | | | | task logic |
1126 | | | | |
1127 | | | | **Example:** |
1128 | | | | |
1129 | | | | .. code:: javascript |
1130 | | | | |
1131 | | | | var returnValue = executor.isTrue; |
1132 | | | | var returnValueType = Java.type("java.lang.Boolean"); |
1133 | | | | var returnValue = new returnValueType(true); |
1134 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1135 | subject | Task | TaskFacade | This provides some useful information about the task that contains this task |
1136 | | | | logic. This object has some useful fields and methods : |
1137 | | | | |
1138 | | | | .. container:: ulist |
1139 | | | | |
1140 | | | | - **AxTask task** to get access to the full task definition of the host task |
1141 | | | | |
1142 | | | | - **String getTaskName()** to get the name of the host task |
1143 | | | | |
1144 | | | | - **String getId()** to get the ID of the host task |
1145 | | | | |
1146 | | | | - **SchemaHelper getInFieldSchemaHelper( String fieldName )** to |
1147 | | | | get a ``SchemaHelper`` helper object to manipulate incoming |
1148 | | | | task fields in a schema-aware manner |
1149 | | | | |
1150 | | | | - **SchemaHelper getOutFieldSchemaHelper( String fieldName )** to |
1151 | | | | get a ``SchemaHelper`` helper object to manipulate outgoing |
1152 | | | | task fields in a schema-aware manner, e.g. to instantiate new |
1153 | | | | schema-compliant field objects to populate the |
1154 | | | | ``executor.outFields`` outgoing fields map |
1155 | | | | |
1156 | | | | **Example:** |
1157 | | | | |
1158 | | | | .. code:: javascript |
1159 | | | | |
1160 | | | | executor.logger.info("Task name: " + executor.subject.getTaskName()); |
1161 | | | | executor.logger.info("Task id: " + executor.subject.getId()); |
1162 | | | | executor.logger.info("Task inputs definitions: " |
1163 | | | | + "executor.subject.task.getInputFieldSet()); |
1164 | | | | executor.logger.info("Task outputs definitions: " |
1165 | | | | + "executor.subject.task.getOutputFieldSet()); |
1166 | | | | executor.outFields["authorised"] = executor.subject |
1167 | | | | .getOutFieldSchemaHelper("authorised") |
1168 | | | | .createNewInstance("false"); |
1169 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1170 | parameters | Fields | java.util.Map <String,String> | All parameters in the current task. This is implemented as a standard Java Map. |
1171 | | | | |
1172 | | | | **Example:** |
1173 | | | | |
1174 | | | | .. code:: javascript |
1175 | | | | |
1176 | | | | executor.parameters.get("ParameterKey1")) |
1177 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
1178 | ContextAlbum getContextAlbum(String ctxtAlbumName ) | A utility method to retrieve a ``ContextAlbum`` for use in the task. | | |
1179 | | This is how you access the context used by the task. The returned | | |
1180 | | ``ContextAlbum`` implements the ``java.util.Map <String,Object>`` | | |
1181 | | interface to get and set context as appropriate. The returned | | |
1182 | | ``ContextAlbum`` also has methods to lock context albums, get | | |
1183 | | information about the schema of the items to be stored in a context | | |
1184 | | album, and get a ``SchemaHelper`` to manipulate context album items. How | | |
1185 | | to define and use context in a task is described in the Apex | | |
1186 | | Programmer’s Guide and in the My First Apex Policy guide. | | |
1187 | | | | |
1188 | | **Example:** | | |
1189 | | | | |
1190 | | .. code:: javascript | | |
1191 | | | | |
1192 | | var bkey = executor.inFields.get("branch_ID"); | | |
1193 | | var cnts = executor.getContextMap("BranchCounts"); | | |
1194 | | cnts.lockForWriting(bkey); | | |
1195 | | cnts.put(bkey, cnts.get(bkey) + 1); | | |
1196 | | cnts.unlockForWriting(bkey); | | |
1197 +-----------------------------------------------------+--------------------------------------------------------------------------+-------------------------------+----------------------------------------------------------------------------------+
ramverma3b71c972019-07-10 11:25:37 +00001198
liamfallonf3981072020-07-10 15:59:25 +01001199Logic Cheat Sheet
1200=================
ramverma3b71c972019-07-10 11:25:37 +00001201
liamfallonf3981072020-07-10 15:59:25 +01001202.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001203
liamfallonf3981072020-07-10 15:59:25 +01001204 Examples given here use Javascript (if not stated otherwise), other execution environments will be similar.
ramverma3b71c972019-07-10 11:25:37 +00001205
ramverma3b71c972019-07-10 11:25:37 +00001206Finish Logic with Success or Error
liamfallonf3981072020-07-10 15:59:25 +01001207----------------------------------
ramverma3b71c972019-07-10 11:25:37 +00001208
liamfallonf3981072020-07-10 15:59:25 +01001209.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001210
liamfallonf3981072020-07-10 15:59:25 +01001211 To finish logic, i.e. return to APEX, with success use the following line close to the end of the logic.
ramverma3b71c972019-07-10 11:25:37 +00001212
liamfallonf3981072020-07-10 15:59:25 +01001213.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001214
liamfallonf3981072020-07-10 15:59:25 +01001215 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001216
liamfallonf3981072020-07-10 15:59:25 +01001217 JS Success
ramverma3b71c972019-07-10 11:25:37 +00001218
liamfallonf3981072020-07-10 15:59:25 +01001219 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001220
liamfallonf3981072020-07-10 15:59:25 +01001221 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001222
liamfallonf3981072020-07-10 15:59:25 +01001223 true;
ramverma3b71c972019-07-10 11:25:37 +00001224
liamfallonf3981072020-07-10 15:59:25 +01001225.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001226
liamfallonf3981072020-07-10 15:59:25 +01001227 To notify a problem, finish with an error.
ramverma3b71c972019-07-10 11:25:37 +00001228
liamfallonf3981072020-07-10 15:59:25 +01001229 .. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001230
liamfallonf3981072020-07-10 15:59:25 +01001231 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001232
liamfallonf3981072020-07-10 15:59:25 +01001233 JS Fail
ramverma3b71c972019-07-10 11:25:37 +00001234
liamfallonf3981072020-07-10 15:59:25 +01001235 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001236
liamfallonf3981072020-07-10 15:59:25 +01001237 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001238
liamfallonf3981072020-07-10 15:59:25 +01001239 false;
ramverma3b71c972019-07-10 11:25:37 +00001240
1241Logic Logging
liamfallonf3981072020-07-10 15:59:25 +01001242-------------
ramverma3b71c972019-07-10 11:25:37 +00001243
liamfallonf3981072020-07-10 15:59:25 +01001244.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001245
liamfallonf3981072020-07-10 15:59:25 +01001246 Logging can be made easy using a local variable for the logger. Line 1 below does that. Then we start
1247 with a trace log with the task (or task logic) identifier followed by the infields.
ramverma3b71c972019-07-10 11:25:37 +00001248
liamfallonf3981072020-07-10 15:59:25 +01001249.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001250
liamfallonf3981072020-07-10 15:59:25 +01001251 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001252
liamfallonf3981072020-07-10 15:59:25 +01001253 JS Logging
ramverma3b71c972019-07-10 11:25:37 +00001254
liamfallonf3981072020-07-10 15:59:25 +01001255 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001256
liamfallonf3981072020-07-10 15:59:25 +01001257 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001258
liamfallonf3981072020-07-10 15:59:25 +01001259 var logger = executor.logger;
1260 logger.trace("start: " + executor.subject.id);
1261 logger.trace("-- infields: " + executor.inFields);
ramverma3b71c972019-07-10 11:25:37 +00001262
liamfallonf3981072020-07-10 15:59:25 +01001263.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001264
liamfallonf3981072020-07-10 15:59:25 +01001265 For larger logging blocks you can use the standard logging API to detect log levels, for instance:
ramverma3b71c972019-07-10 11:25:37 +00001266
liamfallonf3981072020-07-10 15:59:25 +01001267 .. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001268
liamfallonf3981072020-07-10 15:59:25 +01001269 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001270
liamfallonf3981072020-07-10 15:59:25 +01001271 JS Logging Blocks
ramverma3b71c972019-07-10 11:25:37 +00001272
liamfallonf3981072020-07-10 15:59:25 +01001273 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001274
liamfallonf3981072020-07-10 15:59:25 +01001275 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001276
liamfallonf3981072020-07-10 15:59:25 +01001277 if(logger.isTraceEnabled()){
1278 // trace logging block here
1279 }
ramverma3b71c972019-07-10 11:25:37 +00001280
liamfallonf3981072020-07-10 15:59:25 +01001281.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001282
liamfallonf3981072020-07-10 15:59:25 +01001283 Note: the shown logger here logs to ``org.onap.policy.apex.executionlogging``. The behavior of the actual logging can
1284 be specified in the ``$APEX_HOME/etc/logback.xml``.
ramverma3b71c972019-07-10 11:25:37 +00001285
liamfallonf3981072020-07-10 15:59:25 +01001286.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001287
liamfallonf3981072020-07-10 15:59:25 +01001288 If you want to log into the APEX root logger (which is sometimes necessary to report serious logic errors to the top),
1289 then import the required class and use this logger.
ramverma3b71c972019-07-10 11:25:37 +00001290
liamfallonf3981072020-07-10 15:59:25 +01001291.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001292
liamfallonf3981072020-07-10 15:59:25 +01001293 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001294
liamfallonf3981072020-07-10 15:59:25 +01001295 JS Root Logger
ramverma3b71c972019-07-10 11:25:37 +00001296
liamfallonf3981072020-07-10 15:59:25 +01001297 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001298
liamfallonf3981072020-07-10 15:59:25 +01001299 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001300
liamfallonf3981072020-07-10 15:59:25 +01001301 var rootLogger = LoggerFactory.getLogger(logger.ROOT_LOGGER_NAME);
1302 rootLogger.error("Serious error in logic detected: " + executor.subject.id);
ramverma3b71c972019-07-10 11:25:37 +00001303
a.sreekumarcc0e9172020-03-16 13:36:45 +00001304Accessing TaskParameters
liamfallonf3981072020-07-10 15:59:25 +01001305------------------------
a.sreekumarcc0e9172020-03-16 13:36:45 +00001306
liamfallonf3981072020-07-10 15:59:25 +01001307.. container:: paragraph
a.sreekumarcc0e9172020-03-16 13:36:45 +00001308
liamfallonf3981072020-07-10 15:59:25 +01001309 TaskParameters available in a Task can be accessed in the logic. The parameters in each task are made
1310 available at the executor level. This example assumes a parameter with key ``ParameterKey1``.
a.sreekumarcc0e9172020-03-16 13:36:45 +00001311
liamfallonf3981072020-07-10 15:59:25 +01001312 .. container:: listingblock
a.sreekumarcc0e9172020-03-16 13:36:45 +00001313
liamfallonf3981072020-07-10 15:59:25 +01001314 .. container:: title
a.sreekumarcc0e9172020-03-16 13:36:45 +00001315
liamfallonf3981072020-07-10 15:59:25 +01001316 JS TaskParameter value
a.sreekumarcc0e9172020-03-16 13:36:45 +00001317
liamfallonf3981072020-07-10 15:59:25 +01001318 .. container:: content
a.sreekumarcc0e9172020-03-16 13:36:45 +00001319
liamfallonf3981072020-07-10 15:59:25 +01001320 .. code:: javascript
a.sreekumarcc0e9172020-03-16 13:36:45 +00001321
liamfallonf3981072020-07-10 15:59:25 +01001322 executor.parameters.get("ParameterKey1"))
a.sreekumarcc0e9172020-03-16 13:36:45 +00001323
liamfallonf3981072020-07-10 15:59:25 +01001324.. container:: paragraph
a.sreekumarcc0e9172020-03-16 13:36:45 +00001325
liamfallonf3981072020-07-10 15:59:25 +01001326 Alternatively, the task parameters can also be accessed from the task object.
a.sreekumarcc0e9172020-03-16 13:36:45 +00001327
liamfallonf3981072020-07-10 15:59:25 +01001328 .. container:: listingblock
a.sreekumarcc0e9172020-03-16 13:36:45 +00001329
liamfallonf3981072020-07-10 15:59:25 +01001330 .. container:: title
a.sreekumarcc0e9172020-03-16 13:36:45 +00001331
liamfallonf3981072020-07-10 15:59:25 +01001332 JS TaskParameter value using task object
a.sreekumarcc0e9172020-03-16 13:36:45 +00001333
liamfallonf3981072020-07-10 15:59:25 +01001334 .. container:: content
a.sreekumarcc0e9172020-03-16 13:36:45 +00001335
liamfallonf3981072020-07-10 15:59:25 +01001336 .. code:: javascript
a.sreekumarcc0e9172020-03-16 13:36:45 +00001337
liamfallonf3981072020-07-10 15:59:25 +01001338 executor.subject.task.getTaskParameters.get("ParameterKey1").getTaskParameterValue()
a.sreekumarcc0e9172020-03-16 13:36:45 +00001339
ramverma3b71c972019-07-10 11:25:37 +00001340Local Variable for Infields
liamfallonf3981072020-07-10 15:59:25 +01001341---------------------------
ramverma3b71c972019-07-10 11:25:37 +00001342
liamfallonf3981072020-07-10 15:59:25 +01001343.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001344
liamfallonf3981072020-07-10 15:59:25 +01001345 It is a good idea to use local variables for ``infields``. This avoids long code lines and policy
1346 evolution. The following example assumes infields named ``nodeName`` and ``nodeAlias``.
ramverma3b71c972019-07-10 11:25:37 +00001347
liamfallonf3981072020-07-10 15:59:25 +01001348 .. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001349
liamfallonf3981072020-07-10 15:59:25 +01001350 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001351
liamfallonf3981072020-07-10 15:59:25 +01001352 JS Infields Local Var
ramverma3b71c972019-07-10 11:25:37 +00001353
liamfallonf3981072020-07-10 15:59:25 +01001354 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001355
liamfallonf3981072020-07-10 15:59:25 +01001356 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001357
liamfallonf3981072020-07-10 15:59:25 +01001358 var ifNodeName = executor.inFields["nodeName"];
1359 var ifNodeAlias = executor.inFields["nodeAlias"];
ramverma3b71c972019-07-10 11:25:37 +00001360
1361Local Variable for Context Albums
liamfallonf3981072020-07-10 15:59:25 +01001362---------------------------------
ramverma3b71c972019-07-10 11:25:37 +00001363
liamfallonf3981072020-07-10 15:59:25 +01001364.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001365
liamfallonf3981072020-07-10 15:59:25 +01001366 Similar to the ``infields`` it is good practice to use local variables for context albums as well. The
1367 following example assumes that a task can access a context album ``albumTopoNodes``. The second line gets a
1368 particular node from this context album.
ramverma3b71c972019-07-10 11:25:37 +00001369
liamfallonf3981072020-07-10 15:59:25 +01001370.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001371
liamfallonf3981072020-07-10 15:59:25 +01001372 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001373
liamfallonf3981072020-07-10 15:59:25 +01001374 JS Infields Local Var
ramverma3b71c972019-07-10 11:25:37 +00001375
liamfallonf3981072020-07-10 15:59:25 +01001376 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001377
liamfallonf3981072020-07-10 15:59:25 +01001378 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001379
liamfallonf3981072020-07-10 15:59:25 +01001380 var albumTopoNodes = executor.getContextAlbum("albumTopoNodes");
1381 var ctxtNode = albumTopoNodes.get(ifNodeName);
ramverma3b71c972019-07-10 11:25:37 +00001382
1383Set Outfields in Logic
liamfallonf3981072020-07-10 15:59:25 +01001384----------------------
ramverma3b71c972019-07-10 11:25:37 +00001385
liamfallonf3981072020-07-10 15:59:25 +01001386.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001387
liamfallonf3981072020-07-10 15:59:25 +01001388 The task logic needs to set outfields with content generated. The exception are outfields that are a
1389 direct copy from an infield of the same name, APEX does that autmatically.
ramverma3b71c972019-07-10 11:25:37 +00001390
liamfallonf3981072020-07-10 15:59:25 +01001391.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001392
liamfallonf3981072020-07-10 15:59:25 +01001393 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001394
liamfallonf3981072020-07-10 15:59:25 +01001395 JS Set Outfields
ramverma3b71c972019-07-10 11:25:37 +00001396
liamfallonf3981072020-07-10 15:59:25 +01001397 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001398
liamfallonf3981072020-07-10 15:59:25 +01001399 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001400
liamfallonf3981072020-07-10 15:59:25 +01001401 executor.outFields["report"] = "node ctxt :: added node " + ifNodeName;
ramverma3b71c972019-07-10 11:25:37 +00001402
1403Create a instance of an Outfield using Schemas
liamfallonf3981072020-07-10 15:59:25 +01001404----------------------------------------------
ramverma3b71c972019-07-10 11:25:37 +00001405
liamfallonf3981072020-07-10 15:59:25 +01001406.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001407
liamfallonf3981072020-07-10 15:59:25 +01001408 If an outfield is not an atomic type (string, integer, etc.) but uses a complex schema (with a Java or
1409 Avro backend), APEX can help to create new instances. The ``executor`` provides a field called ``subject``,
1410 which provides a schem helper with an API for this. The complete API of the schema helper is documented here:
1411 `API Doc: SchemaHelper <https://ericsson.github.io/apex-docs/javadocs/index.html>`__.
ramverma3b71c972019-07-10 11:25:37 +00001412
liamfallonf3981072020-07-10 15:59:25 +01001413.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001414
liamfallonf3981072020-07-10 15:59:25 +01001415 If the backend is Java, then the Java class implementing the schema needs to be imported.
ramverma3b71c972019-07-10 11:25:37 +00001416
liamfallonf3981072020-07-10 15:59:25 +01001417.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001418
liamfallonf3981072020-07-10 15:59:25 +01001419 The following example assumes an outfield ``situation``. The ``subject`` method ``getOutFieldSchemaHelper()`` is used
1420 to create a new instance.
ramverma3b71c972019-07-10 11:25:37 +00001421
liamfallonf3981072020-07-10 15:59:25 +01001422.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001423
liamfallonf3981072020-07-10 15:59:25 +01001424 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001425
liamfallonf3981072020-07-10 15:59:25 +01001426 JS Outfield Instance with Schema
ramverma3b71c972019-07-10 11:25:37 +00001427
liamfallonf3981072020-07-10 15:59:25 +01001428 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001429
liamfallonf3981072020-07-10 15:59:25 +01001430 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001431
liamfallonf3981072020-07-10 15:59:25 +01001432 var situation = executor.subject.getOutFieldSchemaHelper("situation").createNewInstance();
ramverma3b71c972019-07-10 11:25:37 +00001433
liamfallonf3981072020-07-10 15:59:25 +01001434.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001435
liamfallonf3981072020-07-10 15:59:25 +01001436 If the schema backend is Java, the new instance will be as implemented in the Java class. If the schema backend is
1437 Avro, the new instance will have all fields from the Avro schema specification, but set to ``null``. So any entry here
1438 needs to be done separately. For instance, the ``situation`` schema has a field ``problemID`` which we set.
ramverma3b71c972019-07-10 11:25:37 +00001439
liamfallonf3981072020-07-10 15:59:25 +01001440.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001441
liamfallonf3981072020-07-10 15:59:25 +01001442 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001443
liamfallonf3981072020-07-10 15:59:25 +01001444 JS Outfield Instance with Schema, set
ramverma3b71c972019-07-10 11:25:37 +00001445
liamfallonf3981072020-07-10 15:59:25 +01001446 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001447
liamfallonf3981072020-07-10 15:59:25 +01001448 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001449
liamfallonf3981072020-07-10 15:59:25 +01001450 situation.put("problemID", "my-problem");
ramverma3b71c972019-07-10 11:25:37 +00001451
1452Create a instance of an Context Album entry using Schemas
liamfallonf3981072020-07-10 15:59:25 +01001453---------------------------------------------------------
ramverma3b71c972019-07-10 11:25:37 +00001454
liamfallonf3981072020-07-10 15:59:25 +01001455.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001456
liamfallonf3981072020-07-10 15:59:25 +01001457 Context album instances can be created using very similar to the outfields. Here, the schema helper
1458 comes from the context album directly. The API of the schema helper is the same as for outfields, see
1459 `API Doc: SchemaHelper <https://ericsson.github.io/apex-docs/javadocs/index.html>`__.
ramverma3b71c972019-07-10 11:25:37 +00001460
liamfallonf3981072020-07-10 15:59:25 +01001461.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001462
liamfallonf3981072020-07-10 15:59:25 +01001463 If the backend is Java, then the Java class implementing the schema needs to be imported.
ramverma3b71c972019-07-10 11:25:37 +00001464
liamfallonf3981072020-07-10 15:59:25 +01001465.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001466
liamfallonf3981072020-07-10 15:59:25 +01001467 The following example creates a new instance of a context album instance named ``albumProblemMap``.
ramverma3b71c972019-07-10 11:25:37 +00001468
liamfallonf3981072020-07-10 15:59:25 +01001469.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001470
liamfallonf3981072020-07-10 15:59:25 +01001471 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001472
liamfallonf3981072020-07-10 15:59:25 +01001473 JS Outfield Instance with Schema
ramverma3b71c972019-07-10 11:25:37 +00001474
liamfallonf3981072020-07-10 15:59:25 +01001475 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001476
liamfallonf3981072020-07-10 15:59:25 +01001477 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001478
liamfallonf3981072020-07-10 15:59:25 +01001479 var albumProblemMap = executor.getContextAlbum("albumProblemMap");
1480 var linkProblem = albumProblemMap.getSchemaHelper().createNewInstance();
ramverma3b71c972019-07-10 11:25:37 +00001481
liamfallonf3981072020-07-10 15:59:25 +01001482.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001483
liamfallonf3981072020-07-10 15:59:25 +01001484 This can of course be also done in a single call without the local variable for the context album.
ramverma3b71c972019-07-10 11:25:37 +00001485
liamfallonf3981072020-07-10 15:59:25 +01001486.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001487
liamfallonf3981072020-07-10 15:59:25 +01001488 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001489
liamfallonf3981072020-07-10 15:59:25 +01001490 JS Outfield Instance with Schema, one line
ramverma3b71c972019-07-10 11:25:37 +00001491
liamfallonf3981072020-07-10 15:59:25 +01001492 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001493
liamfallonf3981072020-07-10 15:59:25 +01001494 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001495
liamfallonf3981072020-07-10 15:59:25 +01001496 var linkProblem = executor.getContextAlbum("albumProblemMap").getSchemaHelper().createNewInstance();
ramverma3b71c972019-07-10 11:25:37 +00001497
liamfallonf3981072020-07-10 15:59:25 +01001498.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001499
liamfallonf3981072020-07-10 15:59:25 +01001500 If the schema backend is Java, the new instance will be as implemented in the Java class. If the schema backend is
1501 Avro, the new instance will have all fields from the Avro schema specification, but set to ``null``. So any entry here
1502 needs to be done separately (see above in outfields for an example).
ramverma3b71c972019-07-10 11:25:37 +00001503
1504Enumerates
liamfallonf3981072020-07-10 15:59:25 +01001505----------
ramverma3b71c972019-07-10 11:25:37 +00001506
liamfallonf3981072020-07-10 15:59:25 +01001507.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001508
liamfallonf3981072020-07-10 15:59:25 +01001509 When dealing with enumerates (Avro or Java defined), it is sometimes and in some execution
1510 environments necessary to convert them to a string. For example, assume an Avro enumerate schema as:
ramverma3b71c972019-07-10 11:25:37 +00001511
liamfallonf3981072020-07-10 15:59:25 +01001512.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001513
liamfallonf3981072020-07-10 15:59:25 +01001514 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001515
liamfallonf3981072020-07-10 15:59:25 +01001516 Avro Enumerate Schema
ramverma3b71c972019-07-10 11:25:37 +00001517
liamfallonf3981072020-07-10 15:59:25 +01001518 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001519
liamfallonf3981072020-07-10 15:59:25 +01001520 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001521
liamfallonf3981072020-07-10 15:59:25 +01001522 {
1523 "type": "enum", "name": "Status", "symbols" : [
1524 "UP", "DOWN"
1525 ]
1526 }
ramverma3b71c972019-07-10 11:25:37 +00001527
liamfallonf3981072020-07-10 15:59:25 +01001528.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001529
liamfallonf3981072020-07-10 15:59:25 +01001530 Using a switch over a field initialized with this enumerate in Javascript will fail. Instead, use the ``toString`` method, for example:
ramverma3b71c972019-07-10 11:25:37 +00001531
liamfallonf3981072020-07-10 15:59:25 +01001532.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001533
liamfallonf3981072020-07-10 15:59:25 +01001534 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001535
liamfallonf3981072020-07-10 15:59:25 +01001536 JS Outfield Instance with Schema, one line
ramverma3b71c972019-07-10 11:25:37 +00001537
liamfallonf3981072020-07-10 15:59:25 +01001538 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001539
liamfallonf3981072020-07-10 15:59:25 +01001540 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001541
liamfallonf3981072020-07-10 15:59:25 +01001542 var switchTest = executor.inFields["status"]; switch(switchTest.toString()){
1543 case "UP": ...; break; case "DOWN": ...; break; default: ...;
1544 }
ramverma3b71c972019-07-10 11:25:37 +00001545
1546MVEL Initialize Outfields First!
liamfallonf3981072020-07-10 15:59:25 +01001547--------------------------------
ramverma3b71c972019-07-10 11:25:37 +00001548
liamfallonf3981072020-07-10 15:59:25 +01001549.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001550
liamfallonf3981072020-07-10 15:59:25 +01001551 In MVEL, we observed a problem when accessing (setting) outfields without a prior access to them. So
1552 in any MVEL task logic, before setting any outfield, simply do a get (with any string), to load the outfields
1553 into the MVEL cache.
ramverma3b71c972019-07-10 11:25:37 +00001554
liamfallonf3981072020-07-10 15:59:25 +01001555.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001556
liamfallonf3981072020-07-10 15:59:25 +01001557 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001558
liamfallonf3981072020-07-10 15:59:25 +01001559 MVEL Outfield Initialization
ramverma3b71c972019-07-10 11:25:37 +00001560
liamfallonf3981072020-07-10 15:59:25 +01001561 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001562
liamfallonf3981072020-07-10 15:59:25 +01001563 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001564
liamfallonf3981072020-07-10 15:59:25 +01001565 outFields.get("initialize outfields");
ramverma3b71c972019-07-10 11:25:37 +00001566
1567Using Java in Scripting Logic
liamfallonf3981072020-07-10 15:59:25 +01001568-----------------------------
ramverma3b71c972019-07-10 11:25:37 +00001569
liamfallonf3981072020-07-10 15:59:25 +01001570.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001571
liamfallonf3981072020-07-10 15:59:25 +01001572 Since APEX executes the logic inside a JVM, most scripting languages provide access to all standard
1573 Java classes. Simply add an import for the required class and then use it as in actual Java.
ramverma3b71c972019-07-10 11:25:37 +00001574
liamfallonf3981072020-07-10 15:59:25 +01001575.. container:: paragraph
ramverma3b71c972019-07-10 11:25:37 +00001576
liamfallonf3981072020-07-10 15:59:25 +01001577 The following example imports ``java.util.arraylist`` into a Javascript logic, and then creates a new
1578 list.
ramverma3b71c972019-07-10 11:25:37 +00001579
liamfallonf3981072020-07-10 15:59:25 +01001580.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001581
liamfallonf3981072020-07-10 15:59:25 +01001582 .. container:: title
ramverma3b71c972019-07-10 11:25:37 +00001583
liamfallonf3981072020-07-10 15:59:25 +01001584 JS Import ArrayList
ramverma3b71c972019-07-10 11:25:37 +00001585
liamfallonf3981072020-07-10 15:59:25 +01001586 .. container:: content
ramverma3b71c972019-07-10 11:25:37 +00001587
liamfallonf3981072020-07-10 15:59:25 +01001588 .. code:: javascript
ramverma3b71c972019-07-10 11:25:37 +00001589
liamfallonf3981072020-07-10 15:59:25 +01001590 var myList = new ArrayList();
1591
1592Converting Javascript scripts from Nashorn to Rhino dialects
1593------------------------------------------------------------
1594
1595The Nashorn Javascript engine was removed from Java in the Java 11 release. Java 11 was introduced into
1596the Policy Framework in the Frankfurt release, so from Frankfurt on, APEX Javascript scripts use the Rhino
1597Javascript engine and scripts must be in the Rhino dialect.
1598
1599There are some minor but important differences between the dialects that users should be aware of so
1600that they can convert their scripts into the Rhino dialect.
1601
1602Return Values
1603^^^^^^^^^^^^^
1604
1605APEX scripts must always return a value of ``true`` indicating that the script executed correctly or ``false``
1606indicating that there was an error in script execution.
1607
1608*Pre Frankfurt*
1609
1610In Nashorn dialect scripts, the user had to create a special variable called ``returnValue`` and set the value of
1611that variable to be the return value for the script.
1612
1613*Frankfurt and Later*
1614
1615In Rhino dialect scripts, the return value of the script is the logical result of the last statement. Therefore the
1616last line of the script must evaluate to either ``true`` or ``false``.
1617
1618.. container:: listingblock
1619
1620 .. container:: title
1621
1622 JS Rhino script last executed line examples
1623
1624 .. container:: content
1625
1626 .. code:: javascript
1627
1628 true;
1629
1630 returnValue; // Where returnValue is assigned earlier in the script
1631
1632 someValue == 1; // Where the value of someValue is assigned earlier in the script
1633
1634return statement
1635^^^^^^^^^^^^^^^^
1636
1637The ``return`` statement is not supported from the main script called in the Rhino interpreter.
1638
1639*Pre Frankfurt*
1640
1641In Nashorn dialect scripts, the user could return a value of ``true`` or ``false`` at any point in their script.
1642
1643.. container:: listingblock
1644
1645 .. container:: title
1646
1647 JS Nashorn main script returning ``true`` and ``false``
1648
1649 .. container:: content
1650
1651 .. code:: javascript
1652
1653 var n;
1654
1655 // some code assigns n a value
1656
1657 if (n < 2) {
1658 return false;
1659 } else {
1660 return true;
1661 }
1662
1663*Frankfurt and Later*
1664
1665In Rhino dialect scripts, the ``return`` statement cannot be used in the main method, but it can still be used in
1666functions. If you want to have a ``return`` statement in your code prior to the last statement, encapsulate your code
1667in a function.
1668
1669.. container:: listingblock
1670
1671 .. container:: title
1672
1673 JS Rhino script with ``return`` statements in a function
1674
1675 .. container:: content
1676
1677 .. code:: javascript
1678
1679 someFunction();
1680
1681 function someFunction() {
1682 var n;
1683
1684 // some code assigns n a value
1685
1686 if (n < 2) {
1687 return false;
1688 } else {
1689 return true;
1690 }
1691 }
1692
1693Compatibility Script
1694^^^^^^^^^^^^^^^^^^^^
1695
1696For Nashorn, the user had to call a compatibility script at the beginning of their Javascript script. This is not
1697required in Rhino.
1698
1699*Pre Frankfurt*
1700
1701In Nashorn dialect scripts, the compatibility script must be loaded.
1702
1703.. container:: listingblock
1704
1705 .. container:: title
1706
1707 Nashorn compatability script loading
1708
1709 .. container:: content
1710
1711 .. code:: javascript
1712
1713 load("nashorn:mozilla_compat.js");
1714
1715*Frankfurt and Later*
1716
1717Not required.
1718
1719Import of Java classes
1720^^^^^^^^^^^^^^^^^^^^^^
1721
1722For Nashorn, the user had explicitly import all the Java packages and classes they wished to use in their Javascript
1723script. In Rhino, all Java classes on the classpath are available for use.
1724
1725*Pre Frankfurt*
1726
1727In Nashorn dialect scripts, Java classes must be imported.
1728
1729.. container:: listingblock
1730
1731 .. container:: title
1732
1733 Importation of Java packages and classes
1734
1735 .. container:: content
1736
1737 .. code:: javascript
1738
1739 importPackage(java.text);
1740 importClass(java.text.SimpleDateFormat);
1741
1742*Frankfurt and Later*
1743
1744Not required.
1745
1746Using Java Classes and Objects as Variables
1747^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1748
1749Setting a Javascript variable to hold a Java class or a Java object is more straightforward in Rhino than it is in
1750Nashorn. The examples below show how to instantiate a Javascript variable as a Java class and how to use that variable
1751to create an instance of the Java class in another Javascript variable in both dialects.
ramverma3b71c972019-07-10 11:25:37 +00001752
ramverma3b71c972019-07-10 11:25:37 +00001753
liamfallonf3981072020-07-10 15:59:25 +01001754*Pre Frankfurt*
ramverma3b71c972019-07-10 11:25:37 +00001755
liamfallonf3981072020-07-10 15:59:25 +01001756.. container:: listingblock
ramverma3b71c972019-07-10 11:25:37 +00001757
liamfallonf3981072020-07-10 15:59:25 +01001758 .. container:: title
1759
1760 Create Javascript variables to hold a Java class and instance
1761
1762 .. container:: content
1763
1764 .. code:: javascript
1765
1766 var webClientClass = Java.type("org.onap.policy.apex.examples.bbs.WebClient");
1767 var webClientObject = new webClientClass();
1768
1769*Frankfurt and Later*
1770
1771.. container:: listingblock
1772
1773 .. container:: title
1774
1775 Create Javascript variables to hold a Java class and instance
1776
1777 .. container:: content
1778
1779 .. code:: javascript
1780
1781 var webClientClass = org.onap.policy.apex.examples.bbs.WebClient;
1782 var webClientObject = new webClientClass();
1783
1784Equal Value and Equal Type operator ``===``
1785^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1786
1787The *Equal Value and Equal Type* operator ``===`` is not supported in Rhino. Developers must use the Equal To
1788operator ``==`` instead. To check types, they may need to explicitly find and check the type of the variables
1789they are using.
ramverma3b71c972019-07-10 11:25:37 +00001790
1791.. |APEX Policy Matrix| image:: images/apex-intro/ApexPolicyMatrix.png
1792.. |APEX Policy Model for Execution| image:: images/apex-policy-model/UmlPolicyModels.png
1793.. |Concepts and Keys| image:: images/apex-policy-model/ConceptsKeys.png
1794