blob: d990290481f8aa45f3a846f9a2c1192fa299c43c [file] [log] [blame]
jhh108dd8f2020-06-12 17:01:24 -05001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3
4.. _pdpd-engine-label:
5
6PDP-D Engine
7############
8
9.. contents::
10 :depth: 2
11
12Overview
13========
14
15The PDP-D Core Engine provides an infrastructure and services for `drools <https://www.drools.org/>`__ based applications
16in the context of Policies and ONAP.
17
18A PDP-D supports applications by means of *controllers*. A *controller* is a named
19grouping of resources. These typically include references to communication endpoints,
20maven artifact coordinates, and *coders* for message mapping.
21
22*Controllers* use *communication endpoints* to interact
23with remote networked entities typically using messaging (dmaap or ueb),
24or http.
25
26PDP-D Engine capabilities can be extended via *features*. Integration with other
27Policy Framework components (API, PAP, and PDP-X) is through one of them (*feature-lifecycle*).
28
29The PDP-D Engine infrastructure provides mechanisms for data migration, diagnostics, and application management.
30
31Software
32========
33
34Source Code repositories
35~~~~~~~~~~~~~~~~~~~~~~~~
36
37The PDP-D software is mainly located in the `policy/drools repository <https://git.onap.org/policy/drools-pdp>`__ with the *communication endpoints* software residing in the `policy/common repository <https://git.onap.org/policy/common>`__ and Tosca policy models in the `policy/models repository <https://git.onap.org/policy/models>`__.
38
39Docker Image
40~~~~~~~~~~~~
41
42Check the *drools-pdp* `released versions <https://wiki.onap.org/display/DW/Policy+Framework+Project%3A+Component+Versions>`__ page for the latest versions.
Ram Krishna Vermaf4009f02021-06-10 16:57:14 -040043At the time of this writing *1.8.2* is the latest version.
jhh108dd8f2020-06-12 17:01:24 -050044
45.. code-block:: bash
46
Ram Krishna Vermaf4009f02021-06-10 16:57:14 -040047 docker pull onap/policy-drools:1.8.2
jhh108dd8f2020-06-12 17:01:24 -050048
49A container instantiated from this image will run under the non-priviledged *policy* account.
50
51The PDP-D root directory is located at the */opt/app/policy* directory (or *$POLICY_HOME*), with the
52exception of the *$HOME/.m2* which contains the local maven repository.
53The PDP-D configuration resides in the following directories:
54
55- **/opt/app/policy/config**: (*$POLICY_HOME/config* or *$POLICY_CONFIG*) contains *engine*, *controllers*, and *endpoint* configuration.
56- **/home/policy/.m2**: (*$HOME/.m2*) maven repository configuration.
57- **/opt/app/policy/etc/**: (*$POLICY_HOME/etc*) miscellaneous configuration such as certificate stores.
58
59The following command can be used to explore the directory layout.
60
61.. code-block:: bash
62
Ram Krishna Vermaf4009f02021-06-10 16:57:14 -040063 docker run --rm -it nexus3.onap.org:10001/onap/policy-drools:1.8.2 -- bash
jhh108dd8f2020-06-12 17:01:24 -050064
65Communication Endpoints
66=======================
67
68PDP-D supports the following networked infrastructures. This is also referred to as
69*communication infrastructures* in the source code.
70
71- DMaaP
72- UEB
73- NOOP
74- Http Servers
75- Http Clients
76
77The source code is located at
78`the policy-endpoints module <https://git.onap.org/policy/common/tree/policy-endpoints>`__
79in the *policy/commons* repository.
80
81These network resources are *named* and typically have a *global* scope, therefore typically visible to
82the PDP-D engine (for administration purposes), application *controllers*,
83and *features*.
84
85DMaaP, UEB, and NOOP are message-based communication infrastructures, hence the terminology of
86source and sinks, to denote their directionality into or out of the *controller*, respectively.
87
88An endpoint can either be *managed* or *unmanaged*. The default for an endpoint is to be *managed*,
89meaning that they are globally accessible by name, and managed by the PDP-D engine.
90*Unmanaged* topics are used when neither global visibility, or centralized PDP-D management is desired.
91The software that uses *unmanaged* topics is responsible for their lifecycle management.
92
93DMaaP Endpoints
94~~~~~~~~~~~~~~~
95
96These are messaging enpoints that use DMaaP as the communication infrastructure.
97
98Typically, a *managed* endpoint configuration is stored in the *<topic-name>-topic.properties* files.
99
100For example, the
101`DCAE_TOPIC-topic.properties <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-management/src/main/feature/config/DCAE_TOPIC-topic.properties>`__ is defined as
102
103.. code-block:: bash
104
105 dmaap.source.topics=DCAE_TOPIC
106
107 dmaap.source.topics.DCAE_TOPIC.effectiveTopic=${env:DCAE_TOPIC}
108 dmaap.source.topics.DCAE_TOPIC.servers=${env:DMAAP_SERVERS}
109 dmaap.source.topics.DCAE_TOPIC.consumerGroup=${env:DCAE_CONSUMER_GROUP}
110 dmaap.source.topics.DCAE_TOPIC.https=true
111
112In this example, the generic name of the *source* endpoint
113is *DCAE_TOPIC*. This is known as the *canonical* name.
114The actual *topic* used in communication exchanges in a physical lab is contained
115in the *$DCAE_TOPIC* environment variable. This environment variable is usually
116set up by *devops* on a per installation basis to meet the needs of each
117lab spec.
118
119In the previous example, *DCAE_TOPIC* is a source-only topic.
120
121Sink topics are similarly specified but indicating that are sink endpoints
122from the perspective of the *controller*. For example, the *APPC-CL* topic
123is configured as
124
125.. code-block:: bash
126
127 dmaap.source.topics=APPC-CL
128 dmaap.sink.topics=APPC-CL
129
130 dmaap.source.topics.APPC-CL.servers=${env:DMAAP_SERVERS}
131 dmaap.source.topics.APPC-CL.https=true
132
133 dmaap.sink.topics.APPC-CL.servers=${env:DMAAP_SERVERS}
134 dmaap.sink.topics.APPC-CL.https=true
135
136Although not shown in these examples, additional configuration options are available such as *user name*,
137*password*, *security keys*, *consumer group* and *consumer instance*.
138
139UEB Endpoints
140~~~~~~~~~~~~~
141
142Similary, UEB endpoints are messaging endpoints, similar to the DMaaP ones.
143
144For example, the
145`DCAE_TOPIC-topic.properties <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-management/src/main/feature/config/DCAE_TOPIC-topic.properties>`__ can be converted to an *UEB* one, by replacing the
146*dmaap* prefix with *ueb*. For example:
147
148.. code-block:: bash
149
150 ueb.source.topics=DCAE_TOPIC
151
152 ueb.source.topics.DCAE_TOPIC.effectiveTopic=${env:DCAE_TOPIC}
153 ueb.source.topics.DCAE_TOPIC.servers=${env:DMAAP_SERVERS}
154 ueb.source.topics.DCAE_TOPIC.consumerGroup=${env:DCAE_CONSUMER_GROUP}
155 ueb.source.topics.DCAE_TOPIC.https=true
156
157NOOP Endpoints
158~~~~~~~~~~~~~~
159
160NOOP (no-operation) endpoints are messaging endpoints that don't have any network attachments.
161They are used for testing convenience.
162To convert the
163`DCAE_TOPIC-topic.properties <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-management/src/main/feature/config/DCAE_TOPIC-topic.properties>`__ to a *NOOP* endpoint, simply replace the *dmaap* prefix with *noop*:
164
165.. code-block:: bash
166
167 noop.source.topics=DCAE_TOPIC
168 noop.source.topics.DCAE_TOPIC.effectiveTopic=${env:DCAE_TOPIC}
169
170HTTP Clients
171~~~~~~~~~~~~
172
173HTTP Clients are typically stored in files following the naming convention: *<name>-http-client.properties* convention.
174One such example is
175the `AAI HTTP Client <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-management/src/main/feature/config/AAI-http-client.properties>`__:
176
177.. code-block:: bash
178
179 http.client.services=AAI
180
181 http.client.services.AAI.managed=true
182 http.client.services.AAI.https=true
183 http.client.services.AAI.host=${envd:AAI_HOST}
184 http.client.services.AAI.port=${envd:AAI_PORT}
185 http.client.services.AAI.userName=${envd:AAI_USERNAME}
186 http.client.services.AAI.password=${envd:AAI_PASSWORD}
187 http.client.services.AAI.contextUriPath=${envd:AAI_CONTEXT_URI}
188
189HTTP Servers
190~~~~~~~~~~~~
191
192HTTP Servers are stored in files that follow a similar naming convention *<name>-http-server.properties*.
193The following is an example of a server named *CONFIG*, getting most of its configuration from
194environment variables.
195
196.. code-block:: bash
197
198 http.server.services=CONFIG
199
200 http.server.services.CONFIG.host=${envd:TELEMETRY_HOST}
201 http.server.services.CONFIG.port=7777
202 http.server.services.CONFIG.userName=${envd:TELEMETRY_USER}
203 http.server.services.CONFIG.password=${envd:TELEMETRY_PASSWORD}
204 http.server.services.CONFIG.restPackages=org.onap.policy.drools.server.restful
205 http.server.services.CONFIG.managed=false
206 http.server.services.CONFIG.swagger=true
207 http.server.services.CONFIG.https=true
208 http.server.services.CONFIG.aaf=${envd:AAF:false}
209
210*Endpoints* configuration resides in the *$POLICY_HOME/config* (or *$POLICY_CONFIG*) directory in a container.
211
212Controllers
213===========
214
215*Controllers* are the means for the PDP-D to run *applications*. Controllers are
216defined in *<name>-controller.properties* files.
217
218For example, see the
Jim Hahnae9582c2020-11-02 14:36:25 -0500219`usecases controller configuration <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties>`__.
jhh108dd8f2020-06-12 17:01:24 -0500220
221This configuration file has two sections: *a)* application maven coordinates, and *b)* endpoint references and coders.
222
223Maven Coordinates
224~~~~~~~~~~~~~~~~~
225
Jim Hahnae9582c2020-11-02 14:36:25 -0500226The coordinates section (*rules*) points to the *controller-usecases* *kjar* artifact.
jhh108dd8f2020-06-12 17:01:24 -0500227It is the *brain* of the control loop application.
228
229.. code-block:: bash
230
Jim Hahnae9582c2020-11-02 14:36:25 -0500231 controller.name=usecases
jhh108dd8f2020-06-12 17:01:24 -0500232
233 rules.groupId=${project.groupId}
Jim Hahnae9582c2020-11-02 14:36:25 -0500234 rules.artifactId=controller-usecases
jhh108dd8f2020-06-12 17:01:24 -0500235 rules.version=${project.version}
236 .....
237
238This *kjar* contains the
Jim Hahnae9582c2020-11-02 14:36:25 -0500239`usecases DRL <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/src/main/resources/usecases.drl>`__ file (there may be more than one DRL file included).
jhh108dd8f2020-06-12 17:01:24 -0500240
241.. code-block:: bash
242
243 ...
244 rule "NEW.TOSCA.POLICY"
245 when
246 $policy : ToscaPolicy()
247 then
248
249 ...
250
251 ControlLoopParams params = ControlLoopUtils.toControlLoopParams($policy);
252 if (params != null) {
253 insert(params);
254 }
255 end
256 ...
257
258The DRL in conjuction with the dependent java libraries in the kjar
Jim Hahnae9582c2020-11-02 14:36:25 -0500259`pom <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/pom.xml>`__
jhh108dd8f2020-06-12 17:01:24 -0500260realizes the application's function. For intance, it realizes the
261vFirewall, vCPE, and vDNS use cases in ONAP.
262
263.. code-block:: bash
264
265 ..
266 <dependency>
267 <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
268 <artifactId>actor.appclcm</artifactId>
269 <version>${policy.models.version}</version>
270 <scope>provided</scope>
271 </dependency>
272 ...
273
274Endpoints References and Coders
275~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276
Jim Hahnae9582c2020-11-02 14:36:25 -0500277The *usecases-controller.properties* configuration also contains a mix of
jhh108dd8f2020-06-12 17:01:24 -0500278source (of incoming controller traffic) and sink (of outgoing controller traffic)
279configuration. This configuration also contains specific
280filtering and mapping rules for incoming and outgoing dmaap messages
281known as *coders*.
282
283.. code-block:: bash
284
285 ...
286 dmaap.source.topics=DCAE_TOPIC,APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP
287 dmaap.sink.topics=APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL,DCAE_CL_RSP
288
289
290 dmaap.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.AppcLcmDmaapWrapper
291 dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.AppcLcmDmaapWrapper.filter=[?($.type == 'response')]
292 dmaap.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson
293
294 dmaap.sink.topics.APPC-CL.events=org.onap.policy.appc.Request
295 dmaap.sink.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty
296 ...
297
298In this example, the *coders* specify that incoming messages over the DMaaP endpoint
299reference *APPC-LCM-WRITE*, that have a field called *type* under the root JSON object with
300value *response* are allowed into the *controller* application. In this case, the incoming
301message is converted into an object (fact) of type *org.onap.policy.appclcm.AppcLcmDmaapWrapper*.
302The *coder* has attached a custom implementation provided by the *application* with class
303*org.onap.policy.appclcm.util.Serialization*. Note that the *coder* filter is expressed in JSONPath notation.
304
305Note that not all the communication endpoint references need to be explicitly referenced within the
306*controller* configuration file. For example, *Http clients* do not.
307The reasons are historical, as the PDP-D was initially intended to only communicate
308through messaging-based protocols such as UEB or DMaaP in asynchronous unidirectional mode.
309The introduction of *Http* with synchronous bi-directional communication with remote endpoints made
310it more convenient for the application to manage each network exchange.
311
312*Controllers* configuration resides in the *$POLICY_HOME/config* (or *$POLICY_CONFIG*) directory in a container.
313
314Other Configuration Files
315~~~~~~~~~~~~~~~~~~~~~~~~~
316
317There are other types of configuration files that *controllers* can use, for example *.environment* files
318that provides a means to share data across applications. The
319`controlloop.properties.environment <https://git.onap.org/policy/drools-applications/tree/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment>`__ is one such example.
320
321
322Tosca Policies
323==============
324
325PDP-D supports Tosca Policies through the *feature-lifecycle*. The *PDP-D* receives its policy set
326from the *PAP*. A policy conforms to its Policy Type specification.
327Policy Types and policy creation is done by the *API* component.
328Policy deployments are orchestrated by the *PAP*.
329
330All communication between *PAP* and PDP-D is over the DMaaP *POLICY-PDP-PAP* topic.
331
332Native Policy Types
333~~~~~~~~~~~~~~~~~~~
334
335The PDP-D Engine supports two (native) Tosca policy types by means of the *lifecycle*
336feature:
337
338- *onap.policies.native.drools.Controller*
339- *onap.policies.native.drools.Artifact*
340
341These types can be used to dynamically deploy or undeploy application *controllers*,
342assign policy types, and upgrade or downgrade their attached maven artifact versions.
343
344For instance, an
345`example native controller <https://git.onap.org/policy/drools-pdp/tree/feature-lifecycle/src/test/resources/tosca-policy-native-controller-example.json>`__ policy is shown below.
346
347.. code-block:: bash
348
349 {
350 "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
351 "topology_template": {
352 "policies": [
353 {
354 "example.controller": {
355 "type": "onap.policies.native.drools.Controller",
356 "type_version": "1.0.0",
357 "version": "1.0.0",
358 "name": "example.controller",
359 "metadata": {
360 "policy-id": "example.controller"
361 },
362 "properties": {
363 "controllerName": "lifecycle",
364 "sourceTopics": [
365 {
366 "topicName": "DCAE_TOPIC",
367 "events": [
368 {
369 "eventClass": "java.util.HashMap",
370 "eventFilter": "[?($.closedLoopEventStatus == 'ONSET')]"
371 },
372 {
373 "eventClass": "java.util.HashMap",
374 "eventFilter": "[?($.closedLoopEventStatus == 'ABATED')]"
375 }
376 ]
377 }
378 ],
379 "sinkTopics": [
380 {
381 "topicName": "APPC-CL",
382 "events": [
383 {
384 "eventClass": "java.util.HashMap",
385 "eventFilter": "[?($.CommonHeader && $.Status)]"
386 }
387 ]
388 }
389 ],
390 "customConfig": {
391 "field1" : "value1"
392 }
393 }
394 }
395 }
396 ]
397 }
398 }
399
400The actual application coordinates are provided with a policy of type onap.policies.native.drools.Artifact,
401see the `example native artifact <https://git.onap.org/policy/drools-pdp/tree/feature-lifecycle/src/test/resources/tosca-policy-native-artifact-example.json>`__
402
403.. code-block:: bash
404
405 {
406 "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
407 "topology_template": {
408 "policies": [
409 {
410 "example.artifact": {
411 "type": "onap.policies.native.drools.Artifact",
412 "type_version": "1.0.0",
413 "version": "1.0.0",
414 "name": "example.artifact",
415 "metadata": {
416 "policy-id": "example.artifact"
417 },
418 "properties": {
419 "rulesArtifact": {
420 "groupId": "org.onap.policy.drools.test",
421 "artifactId": "lifecycle",
422 "version": "1.0.0"
423 },
424 "controller": {
425 "name": "lifecycle"
426 }
427 }
428 }
429 }
430 ]
431 }
432 }
433
434Operational Policy Types
435~~~~~~~~~~~~~~~~~~~~~~~~
436
437The PDP-D also recognizes Tosca Operational Policies, although it needs an
438application *controller* that understands them to execute them. These are:
439
440- *onap.policies.controlloop.operational.common.Drools*
jhh108dd8f2020-06-12 17:01:24 -0500441
442A minimum of one application *controller* that supports these capabilities
443must be installed in order to honor the *operational policy types*.
Jim Hahnae9582c2020-11-02 14:36:25 -0500444One such controller is the *usecases* controller residing in the
jhh108dd8f2020-06-12 17:01:24 -0500445`policy/drools-applications <https://git.onap.org/policy/drools-applications>`__
446repository.
447
448Controller Policy Type Support
449~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450
451Note that a *controller* may support other policy types. A controller may declare them
452explicitly in a native *onap.policies.native.drools.Controller* policy.
453
454.. code-block:: bash
455
456 "customConfig": {
457 "controller.policy.types" : "policy.type.A"
458 }
459
460The *controller* application could declare its supported policy types in the *kjar*.
Jim Hahnae9582c2020-11-02 14:36:25 -0500461For example, the *usecases controller* packages this information in the
462`kmodule.xml <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml>`__. One advantage of this approach is that the PDP-D would only
jhh108dd8f2020-06-12 17:01:24 -0500463commit to execute policies against these policy types if a supporting controller is up and running.
464
465.. code-block:: bash
466
467 <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
468 <kbase name="onap.policies.controlloop.operational.common.Drools" default="false" equalsBehavior="equality"/>
469 <kbase name="onap.policies.controlloop.Operational" equalsBehavior="equality"
470 packages="org.onap.policy.controlloop" includes="onap.policies.controlloop.operational.common.Drools">
Jim Hahnae9582c2020-11-02 14:36:25 -0500471 <ksession name="usecases"/>
jhh108dd8f2020-06-12 17:01:24 -0500472 </kbase>
473 </kmodule>
474
475Software Architecture
476======================
477
478PDP-D is divided into 2 layers:
479
480- core (`policy-core <https://git.onap.org/policy/drools-pdp/tree/policy-core>`__)
481- management (`policy-management <https://git.onap.org/policy/drools-pdp/tree/policy-management>`__)
482
483Core Layer
484~~~~~~~~~~
485
486The core layer directly interfaces with the *drools* libraries with 2 main abstractions:
487
488* `PolicyContainer <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java>`__, and
489* `PolicySession <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java>`__.
490
491Policy Container and Sessions
492"""""""""""""""""""""""""""""
493
494The *PolicyContainer* abstracts the drools *KieContainer*, while a *PolicySession* abstracts a drools *KieSession*.
495PDP-D uses stateful sessions in active mode (*fireUntilHalt*) (please visit the `drools <https://www.drools.org/>`__
496website for additional documentation).
497
498Management Layer
499~~~~~~~~~~~~~~~~
500
501The management layer manages the PDP-D and builds on top of the *core* capabilities.
502
503PolicyEngine
504""""""""""""
505
506The PDP-D `PolicyEngine <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java>`__ is the top abstraction and abstracts away the PDP-D and all the
507resources it holds. The reader looking at the source code can start looking at this component
508in a top-down fashion. Note that the *PolicyEngine* abstraction should not be confused with the
509sofware in the *policy/engine* repository, there is no relationship whatsoever other than in the naming.
510
511The *PolicyEngine* represents the PDP-D, holds all PDP-D resources, and orchestrates activities among those.
512
513The *PolicyEngine* manages applications via the `PolicyController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java>`__ abstractions in the base code. The
514relationship between the *PolicyEngine* and *PolicyController* is one to many.
515
516The *PolicyEngine* holds other global resources such as a *thread pool*, *policies validator*, *telemetry* server,
517and *unmanaged* topics for administration purposes.
518
519The *PolicyEngine* has interception points that allow
520`*features* <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java>`__
521to observe and alter the default *PolicyEngine* behavior.
522
523The *PolicyEngine* implements the `*Startable* <https://git.onap.org/policy/common/tree/capabilities/src/main/java/org/onap/policy/common/capabilities/Startable.java>`__ and `*Lockable* <https://git.onap.org/policy/common/tree/capabilities/src/main/java/org/onap/policy/common/capabilities/Lockable.java>`__ interfaces. These operations
524have a cascading effect on the resources the *PolicyEngine* holds, as it is the top level entity, thus
525affecting *controllers* and *endpoints*. These capabilities are intended to be used for extensions,
526for example active/standby multi-node capabilities. This programmability is
527exposed via the *telemetry* API, and *feature* hooks.
528
529Configuration
530^^^^^^^^^^^^^
531
532*PolicyEngine* related configuration is located in the
533`engine.properties <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server/config/engine.properties>`__,
534and `engine-system.properties <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server/config/engine.properties>`__.
535
536The *engine* configuration files reside in the *$POLICY_CONFIG* directory.
537
538PolicyController
539""""""""""""""""
540
541A *PolicyController* represents an application. Each *PolicyController* has an instance of a
542`DroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java>`__. The *PolicyController* provides the means to group application specific resources
543into a single unit. Such resources include the application's *maven coordinates*, *endpoint references*, and *coders*.
544
545A *PolicyController* uses a
546`DroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java>`__ to interface with the *core* layer (*PolicyContainer* and *PolicySession*).
547
548The relationship between the *PolicyController* and the *DroolsController* is one-to-one.
549The *DroolsController* currently supports 2 implementations, the
550`MavenDroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java>`__, and the
551`NullDroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java>`__.
552The *DroolsController*'s polymorphic behavior depends on whether a maven artifact is attached to the controller or not.
553
554Configuration
555^^^^^^^^^^^^^
556
557The *controllers* configuration resides in the *$POLICY_CONFIG* directory.
558
559Programmability
560~~~~~~~~~~~~~~~
561
562PDP-D is programmable through:
563
564- Features and Event Listeners.
565- Maven-Drools applications.
566
567Using Features and Listeners
568""""""""""""""""""""""""""""
569
570Features hook into the interception points provided by the the *PDP-D* main entities.
571
572*Endpoint Listeners*, see `here <https://git.onap.org/policy/common/tree/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicListener.java>`__
573and `here <https://git.onap.org/policy/common/tree/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/listeners>`__, can be used in conjuction with features for additional capabilities.
574
575Using Maven-Drools applications
576"""""""""""""""""""""""""""""""
577
578Maven-based drools applications can run any arbitrary functionality structured with rules and java logic.
579
580Recommended Flow
581""""""""""""""""
582
583Whenever possible it is suggested that PDP-D related operations flow through the
584*PolicyEngine* downwards in a top-down manner. This imposed order implies that
585all the feature hooks are always invoked in a deterministic fashion. It is also
586a good mechanism to safeguard against deadlocks.
587
588Telemetry Extensions
589""""""""""""""""""""
590
591It is recommended to *features* (extensions) to offer a diagnostics REST API
592to integrate with the telemetry API. This is done by placing JAX-RS files under
593the package *org.onap.policy.drools.server.restful*. The root context path
594for all the telemetry services is */policy/pdp/engine*.
595
596Features
597========
598
599*Features* is an extension mechanism for the PDP-D functionality.
600Features can be toggled on and off.
601A feature is composed of:
602
603- Java libraries.
604- Scripts and configuration files.
605
606Java Extensions
607~~~~~~~~~~~~~~~
608
609Additional functionality can be provided in the form of java libraries that hook into the
610*PolicyEngine*, *PolicyController*, *DroolsController*, and *PolicySession* interception
611points to observe or alter the PDP-D logic.
612
613See the Feature APIs available in the
614`management <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/features>`__
615and
616`core <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java>`__ layers.
617
618The convention used for naming these extension modules are *api-<name>* for interfaces,
619and *feature-<name>* for the actual java extensions.
620
621Configuration Items
622~~~~~~~~~~~~~~~~~~~
623
624Installation items such as scripts, SQL, maven artifacts, and configuration files.
625
626The reader can refer to the `policy/drools-pdp repository <https://git.onap.org/policy/drools-pdp>`__
627and the <https://git.onap.org/policy/drools-applications>`__ repository for miscellaneous feature
628implementations.
629
630Layout
631""""""
632
633A feature is packaged in a *feature-<name>.zip* and has this internal layout:
634
635.. code-block:: bash
636
637 # #######################################################################################
638 # Features Directory Layout:
639 #
640 # $POLICY_HOME/
641 # L─ features/
642 # L─ <feature-name>*/
643 #     L─ [config]/
644 #     |   L─ <config-file>+
645 #     L─ [bin]/
646 #     |   L─ <bin-file>+
647 #     L─ lib/
648 #     |  L─ [dependencies]/
649 #     |  | L─ <dependent-jar>+
650 #     │  L─ feature/
651 #     │  L─ <feature-jar>
652 #     L─ [db]/
653 #     │   L─ <db-name>/+
654 #     │  L─ sql/
655 #     │ L─ <sql-scripts>*
656 #     L─ [artifacts]/
657 #      L─ <artifact>+
658 #     L─ [install]
659 #      L─ [enable]
660 #      L─ [disable]
661 #      L─ [other-directories-or-files]
662 #
663 # notes: [] = optional , * = 0 or more , + = 1 or more
664 # <feature-name> directory without "feature-" prefix.
665 # [config] feature configuration directory that contains all configuration
666 # needed for this features
667 # [config]/<config-file> preferably named with "feature-<feature-name>" prefix to
668 # precisely match it against the exact features, source code, and
669 # associated wiki page for configuration details.
670 # [bin] feature bin directory that contains helper scripts for this feature
671 # [bin]/<executable-file> preferably named with "feature-<feature-name>" prefix.
672 # lib jar libraries needed by this features
673 # lib/[dependencies] 3rd party jar dependencies not provided by base installation
674 # of pdp-d that are necessary for <feature-name> to operate
675 # correctly.
676 # lib/feature the single feature jar that implements the feature.
677 # [db] database directory, if the feature contains sql.
678 # [db]/<db-name> database to which underlying sql scripts should be applied.
679 # ideally, <db-name> = <feature-name> so it is easily to associate
680 # the db data with a feature itself. In addition, since a feature is
681 # a somewhat independent isolated unit of functionality,the <db-name>
682 # database ideally isolates all its data.
683 # [db]/<db-name>/sql directory with all the sql scripts.
684 # [db]/<db-name>/sql/<sql-scripts> for this feature, sql
685 # upgrade scripts should be suffixed with ".upgrade.sql"
686 # and downgrade scripts should be suffixed with ".downgrade.sql"
687 # [artifacts] maven artifacts to be deployed in a maven repository.
688 # [artifacts]/<artifact> maven artifact with identifiable maven coordinates embedded
689 # in the artifact.
690 # [install] custom installation directory where custom enable or disable scripts
691 # and other free form data is included to be used for the enable and
692 # and disable scripts.
693 # [install]/[enable] enable script executed when the enable operation is invoked in
694 # the feature.
695 # [install]/[disable] disable script executed when the disable operation is invoked in
696 # the feature.
697 # [install]/[other-directories-or-files] other executables, or data that can be used
698 # by the feature for any of its operations. The content is determined
699 # by the feature designer.
700 # ########################################################################################
701
702The `features <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server-gen/bin/features>`__
703is the tool used for administration purposes:
704
705.. code-block:: bash
706
707 Usage: features status
708 Get enabled/disabled status on all features
709 features enable <feature> ...
710 Enable the specified feature
711 features disable <feature> ...
712 Disable the specified feature
713 features install [ <feature> | <file-name> ] ...
714 Install the specified feature
715 features uninstall <feature> ...
716 Uninstall the specified feature
717
718Features available in the Docker image
719~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
720
721The only enabled feature in the *onap/policy-drools* image is:
722
723- **lifecycle**: enables the lifecycle capability to integrate with the Policy Framework components.
724
725The following features are included in the image but disabled.
726
727- **distributed locking**: distributed resource locking.
728- **healthcheck**: basic PDP-D Engine healthcheck.
729
730Healthcheck
731"""""""""""
732
733The Healthcheck feature provides reports used to verify the health of *PolicyEngine.manager* in addition to the construction, operation, and deconstruction of HTTP server/client objects.
734
735When enabled, the feature takes as input a properties file named "*feature-healtcheck.properties*.
736This file should contain configuration properties necessary for the construction of HTTP client and server objects.
737
738Upon initialization, the feature first constructs HTTP server and client objects using the properties
739from its properties file. A healthCheck operation is then triggered. The logic of the healthCheck verifies
740that *PolicyEngine.manager* is alive, and iteratively tests each HTTP server object by sending HTTP GET
741requests using its respective client object. If a server returns a "200 OK" message, it is marked as "healthy"
742in its individual report. Any other return code results in an "unhealthy" report.
743
744After the testing of the server objects has completed, the feature returns a single consolidated report.
745
746Lifecycle
747"""""""""
748
749The "lifecycle" feature enables a PDP-D to work with the architectural framework introduced in the
750Dublin release.
751
752The lifecycle feature maintains three states: TERMINATED, PASSIVE, and ACTIVE.
753The PAP interacts with the lifecycle feature to put a PDP-D in PASSIVE or ACTIVE states.
754The PASSIVE state allows for Tosca Operational policies to be deployed.
755Policy execution is enabled when the PDP-D transitions to the ACTIVE state.
756
757This feature can coexist side by side with the legacy mode of operation that pre-dates the Dublin release.
758
759Distributed Locking
760"""""""""""""""""""
761
762The Distributed Locking Feature provides locking of resources across a pool of PDP-D hosts.
763The list of locks is maintained in a database, where each record includes a resource identifier,
764an owner identifier, and an expiration time. Typically, a drools application will unlock the resource
765when it's operation completes. However, if it fails to do so, then the resource will be automatically
766released when the lock expires, thus preventing a resource from becoming permanently locked.
767
768Other features
769~~~~~~~~~~~~~~
770
771The following features have been contributed to the *policy/drools-pdp* but are either
772unnecessary or have not been thoroughly tested:
773
774.. toctree::
775 :maxdepth: 1
776
777 feature_activestdbymgmt.rst
778 feature_controllerlogging.rst
779 feature_eelf.rst
780 feature_mdcfilters.rst
781 feature_pooling.rst
782 feature_sesspersist.rst
783 feature_statemgmt.rst
784 feature_testtransaction.rst
jhha61a2fe2021-03-25 14:08:45 -0500785 feature_nolocking.rst
jhh108dd8f2020-06-12 17:01:24 -0500786
787Data Migration
788==============
789
790PDP-D data is migrated across releases with the
791`db-migrator <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server-gen/bin/db-migrator>`__.
792
793The migration occurs when different release data is detected. *db-migrator* will look under the
794*$POLICY_HOME/etc/db/migration* for databases and SQL scripts to migrate.
795
796.. code-block:: bash
797
798 $POLICY_HOME/etc/db/migration/<schema-name>/sql/<sql-file>
799
800where *<sql-file>* is of the form:
801
802.. code-block:: bash
803
804 <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
805
806The db-migrator tool syntax is
807
808.. code-block:: bash
809
810 syntax: db-migrator
811 -s <schema-name>
812 [-b <migration-dir>]
813 [-f <from-version>]
814 [-t <target-version>]
815 -o <operations>
816
817 where <operations>=upgrade|downgrade|auto|version|erase|report
818
819 Configuration Options:
820 -s|--schema|--database: schema to operate on ('ALL' to apply on all)
821 -b|--basedir: overrides base DB migration directory
822 -f|--from: overrides current release version for operations
823 -t|--target: overrides target release to upgrade/downgrade
824
825 Operations:
826 upgrade: upgrade operation
827 downgrade: performs a downgrade operation
828 auto: autonomous operation, determines upgrade or downgrade
829 version: returns current version, and in conjunction if '-f' sets the current version
830 erase: erase all data related <schema> (use with care)
831 report: migration detailed report on an schema
832 ok: is the migration status valid
833
834See the
835`feature-distributed-locking sql directory <https://git.onap.org/policy/drools-pdp/tree/feature-distributed-locking/src/main/feature/db/pooling/sql>`__
836for an example of upgrade/downgrade scripts.
837
838The following command will provide a report on the upgrade or downgrade activies:
839
840.. code-block:: bash
841
842 db-migrator -s ALL -o report
843
Jim Hahnae9582c2020-11-02 14:36:25 -0500844For example in the official guilin delivery:
jhh108dd8f2020-06-12 17:01:24 -0500845
846.. code-block:: bash
847
848 policy@dev-drools-0:/tmp/policy-install$ db-migrator -s ALL -o report
849 +---------+---------+
850 | name | version |
851 +---------+---------+
852 | pooling | 1811 |
853 +---------+---------+
854 +-------------------------------------+-----------+---------+---------------------+
855 | script | operation | success | atTime |
856 +-------------------------------------+-----------+---------+---------------------+
857 | 1804-distributedlocking.upgrade.sql | upgrade | 1 | 2020-05-22 19:33:09 |
858 | 1811-distributedlocking.upgrade.sql | upgrade | 1 | 2020-05-22 19:33:09 |
859 +-------------------------------------+-----------+---------+---------------------+
860
861In order to use the *db-migrator* tool, the system must be configured with a database.
862
863.. code-block:: bash
864
865 SQL_HOST=mariadb
866
867Maven Repositories
868==================
869
870The drools libraries in the PDP-D uses maven to fetch rules artifacts and software dependencies.
871
872The default *settings.xml* file specifies the repositories to search. This configuration
873can be overriden with a custom copy that would sit in a mounted configuration
874directory. See an example of the OOM override
875`settings.xml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/configmaps/settings.xml>`__.
876
877The default ONAP installation of the *control loop* child image *onap/policy-pdpd-cl:1.6.4* is *OFFLINE*.
878In this configuration, the *rules* artifact and the *dependencies* retrieves all the artifacts from the local
879maven repository. Of course, this requires that the maven dependencies are preloaded in the local
880repository for it to work.
881
882An offline configuration requires two items:
883
884- *OFFLINE* environment variable set to true.
885- override *settings.xml* customization, see
886 `settings.xml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/configmaps/settings.xml>`__.
887
888The default mode in the *onap/policy-drools:1.6.3* is ONLINE instead.
889
890In *ONLINE* mode, the *controller* initialization can take a significant amount of time.
891
892The Policy ONAP installation includes a *nexus* repository component that can be used to host any arbitrary
893artifacts that an PDP-D application may require.
894The following environment variables configure its location:
895
896.. code-block:: bash
897
898 SNAPSHOT_REPOSITORY_ID=policy-nexus-snapshots
899 SNAPSHOT_REPOSITORY_URL=http://nexus:8080/nexus/content/repositories/snapshots/
900 RELEASE_REPOSITORY_ID=policy-nexus-releases
901 RELEASE_REPOSITORY_URL=http://nexus:8080/nexus/content/repositories/releases/
902 REPOSITORY_OFFLINE=false
903
904The *deploy-artifact* tool is used to deploy artifacts to the local or remote maven repositories.
905It also allows for dependencies to be installed locally. The *features* tool invokes it when artifacts are
906to be deployed as part of a feature. The tool can be useful for developers to test a new application
907in a container.
908
909.. code-block:: bash
910
911 syntax: deploy-artifact
912 [-f|-l|-d]
913 -s <custom-settings>
914 -a <artifact>
915
916 Options:
917 -f|--file-repo: deploy in the file repository
918 -l|--local-repo: install in the local repository
919 -d|--dependencies: install dependencies in the local repository
920 -s|--settings: custom settings.xml
921 -a|--artifact: file artifact (jar or pom) to deploy and/or install
922
923AAF
924===
925
926Policy can talk to AAF for authorization requests. To enable AAF set
927the following environment variables:
928
929.. code-block:: bash
930
931 AAF=true
932 AAF_NAMESPACE=org.onap.policy
933 AAF_HOST=aaf-locate.onap
934
935By default AAF is disabled.
936
937Policy Tool
938===========
939
940The *policy* tool can be used to stop, start, and provide status on the PDP-D.
941
942.. code-block:: bash
943
944 syntax: policy [--debug] status|start|stop
945
946The *status* option provides generic status of the system.
947
948.. code-block:: bash
949
950 [drools-pdp-controllers]
951 L []: Policy Management (pid 408) is running
952 0 cron jobs installed.
953
954 [features]
955 name version status
956 ---- ------- ------
957 healthcheck 1.6.3 enabled
958 distributed-locking 1.6.3 enabled
959 lifecycle 1.6.3 enabled
960 controlloop-management 1.6.4 enabled
961 controlloop-utils 1.6.4 enabled
962 controlloop-trans 1.6.4 enabled
Jim Hahnae9582c2020-11-02 14:36:25 -0500963 controlloop-usecases 1.6.4 enabled
jhh108dd8f2020-06-12 17:01:24 -0500964
965 [migration]
966 pooling: OK @ 1811
967
968It contains 3 sections:
969
970- *PDP-D* running status
971- *features* applied
972- Data migration status on a per database basis.
973
974The *start* and *stop* commands are useful for developers testing functionality on a docker container instance.
975
976Telemetry Shell
977===============
978
979*PDP-D* offers an ample set of REST APIs to debug, introspect, and change state on a running PDP-D. This is known as the
980*telemetry* API. The *telemetry* shell wraps these APIs for shell-like access using
981`http-prompt <http://http-prompt.com/>`__.
982
983.. code-block:: bash
984
985 policy@dev-drools-0:~$ telemetry
986 Version: 1.0.0
987 https://localhost:9696/policy/pdp/engine> get controllers
988 HTTP/1.1 200 OK
989 Content-Length: 13
990 Content-Type: application/json
991 Date: Thu, 04 Jun 2020 01:07:38 GMT
992 Server: Jetty(9.4.24.v20191120)
993
994 [
Jim Hahnae9582c2020-11-02 14:36:25 -0500995 "usecases"
jhh108dd8f2020-06-12 17:01:24 -0500996 ]
997
998 https://localhost:9696/policy/pdp/engine> exit
999 Goodbye!
1000 policy@dev-drools-0:~$
1001
1002
1003Other tools
1004===========
1005
1006Refer to the *$POLICY_HOME/bin/* directory for additional tooling.
1007
1008PDP-D Docker Container Configuration
1009====================================
1010
1011Both the PDP-D *onap/policy-drools* and *onap/policy-pdpd-cl* images can be used without other components.
1012
1013There are 2 types of configuration data provided to the container:
1014
10151. environment variables.
10162. configuration files and shell scripts.
1017
1018Environment variables
1019~~~~~~~~~~~~~~~~~~~~~
1020
1021As it was shown in the *controller* and *endpoint* sections, PDP-D configuration can rely
1022on environment variables. In a container environment, these variables are set up by the user
1023in the host environment.
1024
1025Configuration Files and Shell Scripts
1026~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1027
1028PDP-D is very flexible in its configuration.
1029
1030The following file types are recognized when mounted under */tmp/policy-install/config*.
1031
1032These are the configuration items that can reside externally and override the default configuration:
1033
1034- **settings.xml** if working with external nexus repositories.
1035- **standalone-settings.xml** if an external *policy* nexus repository is not available.
1036- ***.conf** files containing environment variables. This is an alternative to use environment variables,
1037 as these files will be sourced in before the PDP-D starts.
1038- **features*.zip** to load any arbitrary feature not present in the image.
1039- ***.pre.sh** scripts that will be executed before the PDP-D starts.
1040- ***.post.sh** scripts that will be executed after the PDP-D starts.
1041- **policy-keystore** to override the default PDP-D java keystore.
1042- **policy-truststore** to override the default PDP-D java truststore.
1043- **aaf-cadi.keyfile** to override the default AAF CADI Key generated by AAF.
1044- ***.properties** to override or add any properties file for the PDP-D, this includes *controller*, *endpoint*,
1045 *engine* or *system* configurations.
1046- **logback*.xml** to override the default logging configuration.
1047- ***.xml** to override other .xml configuration that may be used for example by an *application*.
1048- ***.json** *json* configuration that may be used by an *application*.
1049
1050
1051Running PDP-D with a single container
1052=====================================
1053
1054Environment File
1055~~~~~~~~~~~~~~~~
1056
1057First create an environment file (in this example *env.conf*) to configure the PDP-D.
1058
1059.. code-block:: bash
1060
1061 # SYSTEM software configuration
1062
1063 POLICY_HOME=/opt/app/policy
1064 POLICY_LOGS=/var/log/onap/policy/pdpd
1065 KEYSTORE_PASSWD=Pol1cy_0nap
1066 TRUSTSTORE_PASSWD=Pol1cy_0nap
1067
1068 # Telemetry credentials
1069
1070 TELEMETRY_PORT=9696
1071 TELEMETRY_HOST=0.0.0.0
1072 TELEMETRY_USER=demo@people.osaaf.org
1073 TELEMETRY_PASSWORD=demo123456!
1074
1075 # nexus repository
1076
1077 SNAPSHOT_REPOSITORY_ID=
1078 SNAPSHOT_REPOSITORY_URL=
1079 RELEASE_REPOSITORY_ID=
1080 RELEASE_REPOSITORY_URL=
1081 REPOSITORY_USERNAME=
1082 REPOSITORY_PASSWORD=
1083 REPOSITORY_OFFLINE=true
1084
1085 # Relational (SQL) DB access
1086
1087 SQL_HOST=
1088 SQL_USER=
1089 SQL_PASSWORD=
1090
1091 # AAF
1092
1093 AAF=false
1094 AAF_NAMESPACE=org.onap.policy
1095 AAF_HOST=aaf.api.simpledemo.onap.org
1096
1097 # PDP-D DMaaP configuration channel
1098
1099 PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
1100 PDPD_CONFIGURATION_API_KEY=
1101 PDPD_CONFIGURATION_API_SECRET=
1102 PDPD_CONFIGURATION_CONSUMER_GROUP=
1103 PDPD_CONFIGURATION_CONSUMER_INSTANCE=
1104 PDPD_CONFIGURATION_PARTITION_KEY=
1105
1106 # PAP-PDP configuration channel
1107
1108 POLICY_PDP_PAP_TOPIC=POLICY-PDP-PAP
1109 POLICY_PDP_PAP_API_KEY=
1110 POLICY_PDP_PAP_API_SECRET=
1111
1112 # DMaaP
1113
1114 DMAAP_SERVERS=localhost
1115
1116Note that *SQL_HOST*, and *REPOSITORY* are empty, so the PDP-D does not attempt
1117to integrate with those components.
1118
1119Configuration
1120~~~~~~~~~~~~~
1121
1122In order to avoid the noise in the logs that relate to dmaap configuration, a startup script (*noop.pre.sh*) is added
1123to convert *dmaap* endpoints to *noop* in the host directory to be mounted.
1124
1125noop.pre.sh
1126"""""""""""
1127
1128.. code-block:: bash
1129
1130 #!/bin/bash -x
1131
1132 sed -i "s/^dmaap/noop/g" $POLICY_HOME/config/*.properties
1133
1134
1135active.post.sh
1136""""""""""""""
1137
1138To put the controller directly in active mode at initialization, place an *active.post.sh* script under the
1139mounted host directory:
1140
1141.. code-block:: bash
1142
1143 #!/bin/bash -x
1144
1145 bash -c "http --verify=no -a ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} PUT https://localhost:9696/policy/pdp/engine/lifecycle/state/ACTIVE"
1146
1147Bring up the PDP-D
1148~~~~~~~~~~~~~~~~~~
1149
1150.. code-block:: bash
1151
1152 docker run --rm -p 9696:9696 -v ${PWD}/config:/tmp/policy-install/config --env-file ${PWD}/env/env.conf -it --name PDPD -h pdpd nexus3.onap.org:10001/onap/policy-drools:1.6.3
1153
1154To run the container in detached mode, add the *-d* flag.
1155
1156Note that in this command, we are opening the *9696* telemetry API port to the outside world, the config directory
1157(where the *noop.pre.sh* customization script resides) is mounted as /tmp/policy-install/config,
1158and the customization environment variables (*env/env.conf*) are passed into the container.
1159
1160To open a shell into the PDP-D:
1161
1162.. code-block:: bash
1163
1164 docker exec -it pdp-d bash
1165
1166Once in the container, run tools such as *telemetry*, *db-migrator*, *policy* to look at the system state:
1167
1168To run the *telemetry shell* and other tools from the host:
1169
1170.. code-block:: bash
1171
1172 docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
1173 docker exec -it PDPD bash -c "/opt/app/policy/bin/policy status"
1174 docker exec -it PDPD bash -c "/opt/app/policy/bin/db-migrator -s ALL -o report"
1175
1176Controlled instantiation of the PDP-D
1177~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1178
1179Sometimes a developer may want to start and stop the PDP-D manually:
1180
1181.. code-block:: bash
1182
1183 # start a bash
1184
1185 docker run --rm -p 9696:9696 -v ${PWD}/config:/tmp/policy-install/config --env-file ${PWD}/env/env.conf -it --name PDPD -h pdpd nexus3.onap.org:10001/onap/policy-drools:1.6.3 bash
1186
1187 # use this command to start policy applying host customizations from /tmp/policy-install/config
1188
1189 pdpd-entrypoint.sh vmboot
1190
1191 # or use this command to start policy without host customization
1192
1193 policy start
1194
1195 # at any time use the following command to stop the PDP-D
1196
1197 policy stop
1198
1199 # and this command to start the PDP-D back again
1200
1201 policy start
1202
1203Running PDP-D with nexus and mariadb
1204====================================
1205
1206*docker-compose* can be used to test the PDP-D with other components. This is an example configuration
1207that brings up *nexus*, *mariadb* and the PDP-D (*docker-compose-pdp.yml*)
1208
1209docker-compose-pdp.yml
1210~~~~~~~~~~~~~~~~~~~~~~
1211
1212.. code-block:: bash
1213
1214 version: '3'
1215 services:
1216 mariadb:
1217 image: mariadb:10.2.25
1218 container_name: mariadb
1219 hostname: mariadb
1220 command: ['--lower-case-table-names=1', '--wait_timeout=28800']
1221 env_file:
1222 - ${PWD}/db/db.conf
1223 volumes:
1224 - ${PWD}/db:/docker-entrypoint-initdb.d
1225 ports:
1226 - "3306:3306"
1227 nexus:
1228 image: sonatype/nexus:2.14.8-01
1229 container_name: nexus
1230 hostname: nexus
1231 ports:
1232 - "8081:8081"
1233 drools:
1234 image: nexus3.onap.org:10001/onap/policy-drools:1.6.3
1235 container_name: drools
1236 depends_on:
1237 - mariadb
1238 - nexus
1239 hostname: drools
1240 ports:
1241 - "9696:9696"
1242 volumes:
1243 - ${PWD}/config:/tmp/policy-install/config
1244 env_file:
1245 - ${PWD}/env/env.conf
1246
1247with *${PWD}/db/db.conf*:
1248
1249db.conf
1250~~~~~~~
1251
1252.. code-block:: bash
1253
1254 MYSQL_ROOT_PASSWORD=secret
1255 MYSQL_USER=policy_user
1256 MYSQL_PASSWORD=policy_user
1257
1258and *${PWD}/db/db.sh*:
1259
1260db.sh
1261~~~~~
1262
1263.. code-block:: bash
1264
1265 for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
1266 do
1267 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "CREATE DATABASE IF NOT EXISTS ${db};"
1268 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "GRANT ALL PRIVILEGES ON \`${db}\`.* TO '${MYSQL_USER}'@'%' ;"
1269 done
1270
1271 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "FLUSH PRIVILEGES;"
1272
1273env.conf
1274~~~~~~~~
1275
1276The environment file *env/env.conf* for *PDP-D* can be set up with appropriate variables to point to the *nexus* instance
1277and the *mariadb* database:
1278
1279.. code-block:: bash
1280
1281 # SYSTEM software configuration
1282
1283 POLICY_HOME=/opt/app/policy
1284 POLICY_LOGS=/var/log/onap/policy/pdpd
1285 KEYSTORE_PASSWD=Pol1cy_0nap
1286 TRUSTSTORE_PASSWD=Pol1cy_0nap
1287
1288 # Telemetry credentials
1289
1290 TELEMETRY_PORT=9696
1291 TELEMETRY_HOST=0.0.0.0
1292 TELEMETRY_USER=demo@people.osaaf.org
1293 TELEMETRY_PASSWORD=demo123456!
1294
1295 # nexus repository
1296
1297 SNAPSHOT_REPOSITORY_ID=policy-nexus-snapshots
1298 SNAPSHOT_REPOSITORY_URL=http://nexus:8081/nexus/content/repositories/snapshots/
1299 RELEASE_REPOSITORY_ID=policy-nexus-releases
1300 RELEASE_REPOSITORY_URL=http://nexus:8081/nexus/content/repositories/releases/
1301 REPOSITORY_USERNAME=admin
1302 REPOSITORY_PASSWORD=admin123
1303 REPOSITORY_OFFLINE=false
1304
1305 MVN_SNAPSHOT_REPO_URL=https://nexus.onap.org/content/repositories/snapshots/
1306 MVN_RELEASE_REPO_URL=https://nexus.onap.org/content/repositories/releases/
1307
1308 # Relational (SQL) DB access
1309
1310 SQL_HOST=mariadb
1311 SQL_USER=policy_user
1312 SQL_PASSWORD=policy_user
1313
1314 # AAF
1315
1316 AAF=false
1317 AAF_NAMESPACE=org.onap.policy
1318 AAF_HOST=aaf.api.simpledemo.onap.org
1319
1320 # PDP-D DMaaP configuration channel
1321
1322 PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
1323 PDPD_CONFIGURATION_API_KEY=
1324 PDPD_CONFIGURATION_API_SECRET=
1325 PDPD_CONFIGURATION_CONSUMER_GROUP=
1326 PDPD_CONFIGURATION_CONSUMER_INSTANCE=
1327 PDPD_CONFIGURATION_PARTITION_KEY=
1328
1329 # PAP-PDP configuration channel
1330
1331 POLICY_PDP_PAP_TOPIC=POLICY-PDP-PAP
1332 POLICY_PDP_PAP_API_KEY=
1333 POLICY_PDP_PAP_API_SECRET=
1334
1335 # DMaaP
1336
1337 DMAAP_SERVERS=localhost
1338
1339prepare.pre.sh
1340~~~~~~~~~~~~~~
1341
1342A pre-start script *config/prepare.pres.sh"can be added the custom config directory
1343to prepare the PDP-D to activate the distributed-locking feature (using the database)
1344and to use "noop" topics instead of *dmaap* topics:
1345
1346.. code-block:: bash
1347
1348 #!/bin/bash
1349
1350 bash -c "/opt/app/policy/bin/features enable distributed-locking"
1351 sed -i "s/^dmaap/noop/g" $POLICY_HOME/config/*.properties
1352
1353active.post.sh
1354~~~~~~~~~~~~~~
1355
1356A post-start script *config/active.post.sh* can place PDP-D in *active* mode at initialization:
1357
1358 .. code-block:: bash
1359
1360 bash -c "http --verify=no -a ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} PUT https://localhost:9696/policy/pdp/engine/lifecycle/state/ACTIVE"
1361
1362Bring up the PDP-D, nexus, and mariadb
1363~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1364
1365To bring up the containers:
1366
1367.. code-block:: bash
1368
1369 docker-compose -f docker-compose-pdpd.yaml up -d
1370
1371To take it down:
1372
1373.. code-block:: bash
1374
1375 docker-compose -f docker-compose-pdpd.yaml down -v
1376
1377Other examples
1378~~~~~~~~~~~~~~
1379
1380The reader can also look at the `integration/csit repository <https://git.onap.org/integration/csit>`__.
1381More specifically, these directories have examples of other PDP-D configurations:
1382
1383* `plans <https://git.onap.org/integration/csit/tree/plans/policy/drools-pdp>`__: startup scripts.
1384* `scripts <https://git.onap.org/integration/csit/tree/scripts/policy/docker-compose-drools.yml>`__: docker-compose related files.
1385* `plans <https://git.onap.org/integration/csit/tree/tests/policy/drools-pdp>`__: test plan.
1386
1387Configuring the PDP-D in an OOM Kubernetes installation
1388=======================================================
1389
1390The `PDP-D OOM chart <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools>`__ can be
1391customized at the following locations:
1392
1393* `values.yaml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/values.yaml>`__: custom values for your installation.
1394* `configmaps <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/configmaps>`__: place in this directory any configuration extensions or overrides to customize the PDP-D that does not contain sensitive information.
1395* `secrets <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/secrets>`__: place in this directory any configuration extensions or overrides to customize the PDP-D that does contain sensitive information.
1396
1397The same customization techniques described in the docker sections for PDP-D, fully apply here, by placing the corresponding
1398files or scripts in these two directories.
1399
1400Additional information
1401======================
1402
1403For additional information, please see the
1404`Drools PDP Development and Testing (In Depth) <https://wiki.onap.org/display/DW/2020+Frankfurt+Tutorials>`__ page.