blob: d19eac15948bf811dd91c0ced2a86c353aea67b0 [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.
43At the time of this writing *1.6.3* is the latest version.
44
45.. code-block:: bash
46
47 docker pull onap/policy-drools:1.6.3
48
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
63 docker run --rm -it nexus3.onap.org:10001/onap/policy-drools:1.6.3 -- bash
64
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*
441- *onap.policies.controlloop.Operational*
442
443A minimum of one application *controller* that supports these capabilities
444must be installed in order to honor the *operational policy types*.
Jim Hahnae9582c2020-11-02 14:36:25 -0500445One such controller is the *usecases* controller residing in the
jhh108dd8f2020-06-12 17:01:24 -0500446`policy/drools-applications <https://git.onap.org/policy/drools-applications>`__
447repository.
448
449Controller Policy Type Support
450~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451
452Note that a *controller* may support other policy types. A controller may declare them
453explicitly in a native *onap.policies.native.drools.Controller* policy.
454
455.. code-block:: bash
456
457 "customConfig": {
458 "controller.policy.types" : "policy.type.A"
459 }
460
461The *controller* application could declare its supported policy types in the *kjar*.
Jim Hahnae9582c2020-11-02 14:36:25 -0500462For example, the *usecases controller* packages this information in the
463`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 -0500464commit to execute policies against these policy types if a supporting controller is up and running.
465
466.. code-block:: bash
467
468 <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
469 <kbase name="onap.policies.controlloop.operational.common.Drools" default="false" equalsBehavior="equality"/>
470 <kbase name="onap.policies.controlloop.Operational" equalsBehavior="equality"
471 packages="org.onap.policy.controlloop" includes="onap.policies.controlloop.operational.common.Drools">
Jim Hahnae9582c2020-11-02 14:36:25 -0500472 <ksession name="usecases"/>
jhh108dd8f2020-06-12 17:01:24 -0500473 </kbase>
474 </kmodule>
475
476Software Architecture
477======================
478
479PDP-D is divided into 2 layers:
480
481- core (`policy-core <https://git.onap.org/policy/drools-pdp/tree/policy-core>`__)
482- management (`policy-management <https://git.onap.org/policy/drools-pdp/tree/policy-management>`__)
483
484Core Layer
485~~~~~~~~~~
486
487The core layer directly interfaces with the *drools* libraries with 2 main abstractions:
488
489* `PolicyContainer <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java>`__, and
490* `PolicySession <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java>`__.
491
492Policy Container and Sessions
493"""""""""""""""""""""""""""""
494
495The *PolicyContainer* abstracts the drools *KieContainer*, while a *PolicySession* abstracts a drools *KieSession*.
496PDP-D uses stateful sessions in active mode (*fireUntilHalt*) (please visit the `drools <https://www.drools.org/>`__
497website for additional documentation).
498
499Management Layer
500~~~~~~~~~~~~~~~~
501
502The management layer manages the PDP-D and builds on top of the *core* capabilities.
503
504PolicyEngine
505""""""""""""
506
507The 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
508resources it holds. The reader looking at the source code can start looking at this component
509in a top-down fashion. Note that the *PolicyEngine* abstraction should not be confused with the
510sofware in the *policy/engine* repository, there is no relationship whatsoever other than in the naming.
511
512The *PolicyEngine* represents the PDP-D, holds all PDP-D resources, and orchestrates activities among those.
513
514The *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
515relationship between the *PolicyEngine* and *PolicyController* is one to many.
516
517The *PolicyEngine* holds other global resources such as a *thread pool*, *policies validator*, *telemetry* server,
518and *unmanaged* topics for administration purposes.
519
520The *PolicyEngine* has interception points that allow
521`*features* <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java>`__
522to observe and alter the default *PolicyEngine* behavior.
523
524The *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
525have a cascading effect on the resources the *PolicyEngine* holds, as it is the top level entity, thus
526affecting *controllers* and *endpoints*. These capabilities are intended to be used for extensions,
527for example active/standby multi-node capabilities. This programmability is
528exposed via the *telemetry* API, and *feature* hooks.
529
530Configuration
531^^^^^^^^^^^^^
532
533*PolicyEngine* related configuration is located in the
534`engine.properties <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server/config/engine.properties>`__,
535and `engine-system.properties <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server/config/engine.properties>`__.
536
537The *engine* configuration files reside in the *$POLICY_CONFIG* directory.
538
539PolicyController
540""""""""""""""""
541
542A *PolicyController* represents an application. Each *PolicyController* has an instance of a
543`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
544into a single unit. Such resources include the application's *maven coordinates*, *endpoint references*, and *coders*.
545
546A *PolicyController* uses a
547`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*).
548
549The relationship between the *PolicyController* and the *DroolsController* is one-to-one.
550The *DroolsController* currently supports 2 implementations, the
551`MavenDroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java>`__, and the
552`NullDroolsController <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java>`__.
553The *DroolsController*'s polymorphic behavior depends on whether a maven artifact is attached to the controller or not.
554
555Configuration
556^^^^^^^^^^^^^
557
558The *controllers* configuration resides in the *$POLICY_CONFIG* directory.
559
560Programmability
561~~~~~~~~~~~~~~~
562
563PDP-D is programmable through:
564
565- Features and Event Listeners.
566- Maven-Drools applications.
567
568Using Features and Listeners
569""""""""""""""""""""""""""""
570
571Features hook into the interception points provided by the the *PDP-D* main entities.
572
573*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>`__
574and `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.
575
576Using Maven-Drools applications
577"""""""""""""""""""""""""""""""
578
579Maven-based drools applications can run any arbitrary functionality structured with rules and java logic.
580
581Recommended Flow
582""""""""""""""""
583
584Whenever possible it is suggested that PDP-D related operations flow through the
585*PolicyEngine* downwards in a top-down manner. This imposed order implies that
586all the feature hooks are always invoked in a deterministic fashion. It is also
587a good mechanism to safeguard against deadlocks.
588
589Telemetry Extensions
590""""""""""""""""""""
591
592It is recommended to *features* (extensions) to offer a diagnostics REST API
593to integrate with the telemetry API. This is done by placing JAX-RS files under
594the package *org.onap.policy.drools.server.restful*. The root context path
595for all the telemetry services is */policy/pdp/engine*.
596
597Features
598========
599
600*Features* is an extension mechanism for the PDP-D functionality.
601Features can be toggled on and off.
602A feature is composed of:
603
604- Java libraries.
605- Scripts and configuration files.
606
607Java Extensions
608~~~~~~~~~~~~~~~
609
610Additional functionality can be provided in the form of java libraries that hook into the
611*PolicyEngine*, *PolicyController*, *DroolsController*, and *PolicySession* interception
612points to observe or alter the PDP-D logic.
613
614See the Feature APIs available in the
615`management <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/java/org/onap/policy/drools/features>`__
616and
617`core <https://git.onap.org/policy/drools-pdp/tree/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java>`__ layers.
618
619The convention used for naming these extension modules are *api-<name>* for interfaces,
620and *feature-<name>* for the actual java extensions.
621
622Configuration Items
623~~~~~~~~~~~~~~~~~~~
624
625Installation items such as scripts, SQL, maven artifacts, and configuration files.
626
627The reader can refer to the `policy/drools-pdp repository <https://git.onap.org/policy/drools-pdp>`__
628and the <https://git.onap.org/policy/drools-applications>`__ repository for miscellaneous feature
629implementations.
630
631Layout
632""""""
633
634A feature is packaged in a *feature-<name>.zip* and has this internal layout:
635
636.. code-block:: bash
637
638 # #######################################################################################
639 # Features Directory Layout:
640 #
641 # $POLICY_HOME/
642 # L─ features/
643 # L─ <feature-name>*/
644 #     L─ [config]/
645 #     |   L─ <config-file>+
646 #     L─ [bin]/
647 #     |   L─ <bin-file>+
648 #     L─ lib/
649 #     |  L─ [dependencies]/
650 #     |  | L─ <dependent-jar>+
651 #     │  L─ feature/
652 #     │  L─ <feature-jar>
653 #     L─ [db]/
654 #     │   L─ <db-name>/+
655 #     │  L─ sql/
656 #     │ L─ <sql-scripts>*
657 #     L─ [artifacts]/
658 #      L─ <artifact>+
659 #     L─ [install]
660 #      L─ [enable]
661 #      L─ [disable]
662 #      L─ [other-directories-or-files]
663 #
664 # notes: [] = optional , * = 0 or more , + = 1 or more
665 # <feature-name> directory without "feature-" prefix.
666 # [config] feature configuration directory that contains all configuration
667 # needed for this features
668 # [config]/<config-file> preferably named with "feature-<feature-name>" prefix to
669 # precisely match it against the exact features, source code, and
670 # associated wiki page for configuration details.
671 # [bin] feature bin directory that contains helper scripts for this feature
672 # [bin]/<executable-file> preferably named with "feature-<feature-name>" prefix.
673 # lib jar libraries needed by this features
674 # lib/[dependencies] 3rd party jar dependencies not provided by base installation
675 # of pdp-d that are necessary for <feature-name> to operate
676 # correctly.
677 # lib/feature the single feature jar that implements the feature.
678 # [db] database directory, if the feature contains sql.
679 # [db]/<db-name> database to which underlying sql scripts should be applied.
680 # ideally, <db-name> = <feature-name> so it is easily to associate
681 # the db data with a feature itself. In addition, since a feature is
682 # a somewhat independent isolated unit of functionality,the <db-name>
683 # database ideally isolates all its data.
684 # [db]/<db-name>/sql directory with all the sql scripts.
685 # [db]/<db-name>/sql/<sql-scripts> for this feature, sql
686 # upgrade scripts should be suffixed with ".upgrade.sql"
687 # and downgrade scripts should be suffixed with ".downgrade.sql"
688 # [artifacts] maven artifacts to be deployed in a maven repository.
689 # [artifacts]/<artifact> maven artifact with identifiable maven coordinates embedded
690 # in the artifact.
691 # [install] custom installation directory where custom enable or disable scripts
692 # and other free form data is included to be used for the enable and
693 # and disable scripts.
694 # [install]/[enable] enable script executed when the enable operation is invoked in
695 # the feature.
696 # [install]/[disable] disable script executed when the disable operation is invoked in
697 # the feature.
698 # [install]/[other-directories-or-files] other executables, or data that can be used
699 # by the feature for any of its operations. The content is determined
700 # by the feature designer.
701 # ########################################################################################
702
703The `features <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server-gen/bin/features>`__
704is the tool used for administration purposes:
705
706.. code-block:: bash
707
708 Usage: features status
709 Get enabled/disabled status on all features
710 features enable <feature> ...
711 Enable the specified feature
712 features disable <feature> ...
713 Disable the specified feature
714 features install [ <feature> | <file-name> ] ...
715 Install the specified feature
716 features uninstall <feature> ...
717 Uninstall the specified feature
718
719Features available in the Docker image
720~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
721
722The only enabled feature in the *onap/policy-drools* image is:
723
724- **lifecycle**: enables the lifecycle capability to integrate with the Policy Framework components.
725
726The following features are included in the image but disabled.
727
728- **distributed locking**: distributed resource locking.
729- **healthcheck**: basic PDP-D Engine healthcheck.
730
731Healthcheck
732"""""""""""
733
734The 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.
735
736When enabled, the feature takes as input a properties file named "*feature-healtcheck.properties*.
737This file should contain configuration properties necessary for the construction of HTTP client and server objects.
738
739Upon initialization, the feature first constructs HTTP server and client objects using the properties
740from its properties file. A healthCheck operation is then triggered. The logic of the healthCheck verifies
741that *PolicyEngine.manager* is alive, and iteratively tests each HTTP server object by sending HTTP GET
742requests using its respective client object. If a server returns a "200 OK" message, it is marked as "healthy"
743in its individual report. Any other return code results in an "unhealthy" report.
744
745After the testing of the server objects has completed, the feature returns a single consolidated report.
746
747Lifecycle
748"""""""""
749
750The "lifecycle" feature enables a PDP-D to work with the architectural framework introduced in the
751Dublin release.
752
753The lifecycle feature maintains three states: TERMINATED, PASSIVE, and ACTIVE.
754The PAP interacts with the lifecycle feature to put a PDP-D in PASSIVE or ACTIVE states.
755The PASSIVE state allows for Tosca Operational policies to be deployed.
756Policy execution is enabled when the PDP-D transitions to the ACTIVE state.
757
758This feature can coexist side by side with the legacy mode of operation that pre-dates the Dublin release.
759
760Distributed Locking
761"""""""""""""""""""
762
763The Distributed Locking Feature provides locking of resources across a pool of PDP-D hosts.
764The list of locks is maintained in a database, where each record includes a resource identifier,
765an owner identifier, and an expiration time. Typically, a drools application will unlock the resource
766when it's operation completes. However, if it fails to do so, then the resource will be automatically
767released when the lock expires, thus preventing a resource from becoming permanently locked.
768
769Other features
770~~~~~~~~~~~~~~
771
772The following features have been contributed to the *policy/drools-pdp* but are either
773unnecessary or have not been thoroughly tested:
774
775.. toctree::
776 :maxdepth: 1
777
778 feature_activestdbymgmt.rst
779 feature_controllerlogging.rst
780 feature_eelf.rst
781 feature_mdcfilters.rst
782 feature_pooling.rst
783 feature_sesspersist.rst
784 feature_statemgmt.rst
785 feature_testtransaction.rst
jhha61a2fe2021-03-25 14:08:45 -0500786 feature_nolocking.rst
jhh108dd8f2020-06-12 17:01:24 -0500787
788Data Migration
789==============
790
791PDP-D data is migrated across releases with the
792`db-migrator <https://git.onap.org/policy/drools-pdp/tree/policy-management/src/main/server-gen/bin/db-migrator>`__.
793
794The migration occurs when different release data is detected. *db-migrator* will look under the
795*$POLICY_HOME/etc/db/migration* for databases and SQL scripts to migrate.
796
797.. code-block:: bash
798
799 $POLICY_HOME/etc/db/migration/<schema-name>/sql/<sql-file>
800
801where *<sql-file>* is of the form:
802
803.. code-block:: bash
804
805 <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
806
807The db-migrator tool syntax is
808
809.. code-block:: bash
810
811 syntax: db-migrator
812 -s <schema-name>
813 [-b <migration-dir>]
814 [-f <from-version>]
815 [-t <target-version>]
816 -o <operations>
817
818 where <operations>=upgrade|downgrade|auto|version|erase|report
819
820 Configuration Options:
821 -s|--schema|--database: schema to operate on ('ALL' to apply on all)
822 -b|--basedir: overrides base DB migration directory
823 -f|--from: overrides current release version for operations
824 -t|--target: overrides target release to upgrade/downgrade
825
826 Operations:
827 upgrade: upgrade operation
828 downgrade: performs a downgrade operation
829 auto: autonomous operation, determines upgrade or downgrade
830 version: returns current version, and in conjunction if '-f' sets the current version
831 erase: erase all data related <schema> (use with care)
832 report: migration detailed report on an schema
833 ok: is the migration status valid
834
835See the
836`feature-distributed-locking sql directory <https://git.onap.org/policy/drools-pdp/tree/feature-distributed-locking/src/main/feature/db/pooling/sql>`__
837for an example of upgrade/downgrade scripts.
838
839The following command will provide a report on the upgrade or downgrade activies:
840
841.. code-block:: bash
842
843 db-migrator -s ALL -o report
844
Jim Hahnae9582c2020-11-02 14:36:25 -0500845For example in the official guilin delivery:
jhh108dd8f2020-06-12 17:01:24 -0500846
847.. code-block:: bash
848
849 policy@dev-drools-0:/tmp/policy-install$ db-migrator -s ALL -o report
850 +---------+---------+
851 | name | version |
852 +---------+---------+
853 | pooling | 1811 |
854 +---------+---------+
855 +-------------------------------------+-----------+---------+---------------------+
856 | script | operation | success | atTime |
857 +-------------------------------------+-----------+---------+---------------------+
858 | 1804-distributedlocking.upgrade.sql | upgrade | 1 | 2020-05-22 19:33:09 |
859 | 1811-distributedlocking.upgrade.sql | upgrade | 1 | 2020-05-22 19:33:09 |
860 +-------------------------------------+-----------+---------+---------------------+
861
862In order to use the *db-migrator* tool, the system must be configured with a database.
863
864.. code-block:: bash
865
866 SQL_HOST=mariadb
867
868Maven Repositories
869==================
870
871The drools libraries in the PDP-D uses maven to fetch rules artifacts and software dependencies.
872
873The default *settings.xml* file specifies the repositories to search. This configuration
874can be overriden with a custom copy that would sit in a mounted configuration
875directory. See an example of the OOM override
876`settings.xml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/configmaps/settings.xml>`__.
877
878The default ONAP installation of the *control loop* child image *onap/policy-pdpd-cl:1.6.4* is *OFFLINE*.
879In this configuration, the *rules* artifact and the *dependencies* retrieves all the artifacts from the local
880maven repository. Of course, this requires that the maven dependencies are preloaded in the local
881repository for it to work.
882
883An offline configuration requires two items:
884
885- *OFFLINE* environment variable set to true.
886- override *settings.xml* customization, see
887 `settings.xml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/resources/configmaps/settings.xml>`__.
888
889The default mode in the *onap/policy-drools:1.6.3* is ONLINE instead.
890
891In *ONLINE* mode, the *controller* initialization can take a significant amount of time.
892
893The Policy ONAP installation includes a *nexus* repository component that can be used to host any arbitrary
894artifacts that an PDP-D application may require.
895The following environment variables configure its location:
896
897.. code-block:: bash
898
899 SNAPSHOT_REPOSITORY_ID=policy-nexus-snapshots
900 SNAPSHOT_REPOSITORY_URL=http://nexus:8080/nexus/content/repositories/snapshots/
901 RELEASE_REPOSITORY_ID=policy-nexus-releases
902 RELEASE_REPOSITORY_URL=http://nexus:8080/nexus/content/repositories/releases/
903 REPOSITORY_OFFLINE=false
904
905The *deploy-artifact* tool is used to deploy artifacts to the local or remote maven repositories.
906It also allows for dependencies to be installed locally. The *features* tool invokes it when artifacts are
907to be deployed as part of a feature. The tool can be useful for developers to test a new application
908in a container.
909
910.. code-block:: bash
911
912 syntax: deploy-artifact
913 [-f|-l|-d]
914 -s <custom-settings>
915 -a <artifact>
916
917 Options:
918 -f|--file-repo: deploy in the file repository
919 -l|--local-repo: install in the local repository
920 -d|--dependencies: install dependencies in the local repository
921 -s|--settings: custom settings.xml
922 -a|--artifact: file artifact (jar or pom) to deploy and/or install
923
924AAF
925===
926
927Policy can talk to AAF for authorization requests. To enable AAF set
928the following environment variables:
929
930.. code-block:: bash
931
932 AAF=true
933 AAF_NAMESPACE=org.onap.policy
934 AAF_HOST=aaf-locate.onap
935
936By default AAF is disabled.
937
938Policy Tool
939===========
940
941The *policy* tool can be used to stop, start, and provide status on the PDP-D.
942
943.. code-block:: bash
944
945 syntax: policy [--debug] status|start|stop
946
947The *status* option provides generic status of the system.
948
949.. code-block:: bash
950
951 [drools-pdp-controllers]
952 L []: Policy Management (pid 408) is running
953 0 cron jobs installed.
954
955 [features]
956 name version status
957 ---- ------- ------
958 healthcheck 1.6.3 enabled
959 distributed-locking 1.6.3 enabled
960 lifecycle 1.6.3 enabled
961 controlloop-management 1.6.4 enabled
962 controlloop-utils 1.6.4 enabled
963 controlloop-trans 1.6.4 enabled
Jim Hahnae9582c2020-11-02 14:36:25 -0500964 controlloop-usecases 1.6.4 enabled
jhh108dd8f2020-06-12 17:01:24 -0500965
966 [migration]
967 pooling: OK @ 1811
968
969It contains 3 sections:
970
971- *PDP-D* running status
972- *features* applied
973- Data migration status on a per database basis.
974
975The *start* and *stop* commands are useful for developers testing functionality on a docker container instance.
976
977Telemetry Shell
978===============
979
980*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
981*telemetry* API. The *telemetry* shell wraps these APIs for shell-like access using
982`http-prompt <http://http-prompt.com/>`__.
983
984.. code-block:: bash
985
986 policy@dev-drools-0:~$ telemetry
987 Version: 1.0.0
988 https://localhost:9696/policy/pdp/engine> get controllers
989 HTTP/1.1 200 OK
990 Content-Length: 13
991 Content-Type: application/json
992 Date: Thu, 04 Jun 2020 01:07:38 GMT
993 Server: Jetty(9.4.24.v20191120)
994
995 [
Jim Hahnae9582c2020-11-02 14:36:25 -0500996 "usecases"
jhh108dd8f2020-06-12 17:01:24 -0500997 ]
998
999 https://localhost:9696/policy/pdp/engine> exit
1000 Goodbye!
1001 policy@dev-drools-0:~$
1002
1003
1004Other tools
1005===========
1006
1007Refer to the *$POLICY_HOME/bin/* directory for additional tooling.
1008
1009PDP-D Docker Container Configuration
1010====================================
1011
1012Both the PDP-D *onap/policy-drools* and *onap/policy-pdpd-cl* images can be used without other components.
1013
1014There are 2 types of configuration data provided to the container:
1015
10161. environment variables.
10172. configuration files and shell scripts.
1018
1019Environment variables
1020~~~~~~~~~~~~~~~~~~~~~
1021
1022As it was shown in the *controller* and *endpoint* sections, PDP-D configuration can rely
1023on environment variables. In a container environment, these variables are set up by the user
1024in the host environment.
1025
1026Configuration Files and Shell Scripts
1027~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1028
1029PDP-D is very flexible in its configuration.
1030
1031The following file types are recognized when mounted under */tmp/policy-install/config*.
1032
1033These are the configuration items that can reside externally and override the default configuration:
1034
1035- **settings.xml** if working with external nexus repositories.
1036- **standalone-settings.xml** if an external *policy* nexus repository is not available.
1037- ***.conf** files containing environment variables. This is an alternative to use environment variables,
1038 as these files will be sourced in before the PDP-D starts.
1039- **features*.zip** to load any arbitrary feature not present in the image.
1040- ***.pre.sh** scripts that will be executed before the PDP-D starts.
1041- ***.post.sh** scripts that will be executed after the PDP-D starts.
1042- **policy-keystore** to override the default PDP-D java keystore.
1043- **policy-truststore** to override the default PDP-D java truststore.
1044- **aaf-cadi.keyfile** to override the default AAF CADI Key generated by AAF.
1045- ***.properties** to override or add any properties file for the PDP-D, this includes *controller*, *endpoint*,
1046 *engine* or *system* configurations.
1047- **logback*.xml** to override the default logging configuration.
1048- ***.xml** to override other .xml configuration that may be used for example by an *application*.
1049- ***.json** *json* configuration that may be used by an *application*.
1050
1051
1052Running PDP-D with a single container
1053=====================================
1054
1055Environment File
1056~~~~~~~~~~~~~~~~
1057
1058First create an environment file (in this example *env.conf*) to configure the PDP-D.
1059
1060.. code-block:: bash
1061
1062 # SYSTEM software configuration
1063
1064 POLICY_HOME=/opt/app/policy
1065 POLICY_LOGS=/var/log/onap/policy/pdpd
1066 KEYSTORE_PASSWD=Pol1cy_0nap
1067 TRUSTSTORE_PASSWD=Pol1cy_0nap
1068
1069 # Telemetry credentials
1070
1071 TELEMETRY_PORT=9696
1072 TELEMETRY_HOST=0.0.0.0
1073 TELEMETRY_USER=demo@people.osaaf.org
1074 TELEMETRY_PASSWORD=demo123456!
1075
1076 # nexus repository
1077
1078 SNAPSHOT_REPOSITORY_ID=
1079 SNAPSHOT_REPOSITORY_URL=
1080 RELEASE_REPOSITORY_ID=
1081 RELEASE_REPOSITORY_URL=
1082 REPOSITORY_USERNAME=
1083 REPOSITORY_PASSWORD=
1084 REPOSITORY_OFFLINE=true
1085
1086 # Relational (SQL) DB access
1087
1088 SQL_HOST=
1089 SQL_USER=
1090 SQL_PASSWORD=
1091
1092 # AAF
1093
1094 AAF=false
1095 AAF_NAMESPACE=org.onap.policy
1096 AAF_HOST=aaf.api.simpledemo.onap.org
1097
1098 # PDP-D DMaaP configuration channel
1099
1100 PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
1101 PDPD_CONFIGURATION_API_KEY=
1102 PDPD_CONFIGURATION_API_SECRET=
1103 PDPD_CONFIGURATION_CONSUMER_GROUP=
1104 PDPD_CONFIGURATION_CONSUMER_INSTANCE=
1105 PDPD_CONFIGURATION_PARTITION_KEY=
1106
1107 # PAP-PDP configuration channel
1108
1109 POLICY_PDP_PAP_TOPIC=POLICY-PDP-PAP
1110 POLICY_PDP_PAP_API_KEY=
1111 POLICY_PDP_PAP_API_SECRET=
1112
1113 # DMaaP
1114
1115 DMAAP_SERVERS=localhost
1116
1117Note that *SQL_HOST*, and *REPOSITORY* are empty, so the PDP-D does not attempt
1118to integrate with those components.
1119
1120Configuration
1121~~~~~~~~~~~~~
1122
1123In order to avoid the noise in the logs that relate to dmaap configuration, a startup script (*noop.pre.sh*) is added
1124to convert *dmaap* endpoints to *noop* in the host directory to be mounted.
1125
1126noop.pre.sh
1127"""""""""""
1128
1129.. code-block:: bash
1130
1131 #!/bin/bash -x
1132
1133 sed -i "s/^dmaap/noop/g" $POLICY_HOME/config/*.properties
1134
1135
1136active.post.sh
1137""""""""""""""
1138
1139To put the controller directly in active mode at initialization, place an *active.post.sh* script under the
1140mounted host directory:
1141
1142.. code-block:: bash
1143
1144 #!/bin/bash -x
1145
1146 bash -c "http --verify=no -a ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} PUT https://localhost:9696/policy/pdp/engine/lifecycle/state/ACTIVE"
1147
1148Bring up the PDP-D
1149~~~~~~~~~~~~~~~~~~
1150
1151.. code-block:: bash
1152
1153 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
1154
1155To run the container in detached mode, add the *-d* flag.
1156
1157Note that in this command, we are opening the *9696* telemetry API port to the outside world, the config directory
1158(where the *noop.pre.sh* customization script resides) is mounted as /tmp/policy-install/config,
1159and the customization environment variables (*env/env.conf*) are passed into the container.
1160
1161To open a shell into the PDP-D:
1162
1163.. code-block:: bash
1164
1165 docker exec -it pdp-d bash
1166
1167Once in the container, run tools such as *telemetry*, *db-migrator*, *policy* to look at the system state:
1168
1169To run the *telemetry shell* and other tools from the host:
1170
1171.. code-block:: bash
1172
1173 docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
1174 docker exec -it PDPD bash -c "/opt/app/policy/bin/policy status"
1175 docker exec -it PDPD bash -c "/opt/app/policy/bin/db-migrator -s ALL -o report"
1176
1177Controlled instantiation of the PDP-D
1178~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1179
1180Sometimes a developer may want to start and stop the PDP-D manually:
1181
1182.. code-block:: bash
1183
1184 # start a bash
1185
1186 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
1187
1188 # use this command to start policy applying host customizations from /tmp/policy-install/config
1189
1190 pdpd-entrypoint.sh vmboot
1191
1192 # or use this command to start policy without host customization
1193
1194 policy start
1195
1196 # at any time use the following command to stop the PDP-D
1197
1198 policy stop
1199
1200 # and this command to start the PDP-D back again
1201
1202 policy start
1203
1204Running PDP-D with nexus and mariadb
1205====================================
1206
1207*docker-compose* can be used to test the PDP-D with other components. This is an example configuration
1208that brings up *nexus*, *mariadb* and the PDP-D (*docker-compose-pdp.yml*)
1209
1210docker-compose-pdp.yml
1211~~~~~~~~~~~~~~~~~~~~~~
1212
1213.. code-block:: bash
1214
1215 version: '3'
1216 services:
1217 mariadb:
1218 image: mariadb:10.2.25
1219 container_name: mariadb
1220 hostname: mariadb
1221 command: ['--lower-case-table-names=1', '--wait_timeout=28800']
1222 env_file:
1223 - ${PWD}/db/db.conf
1224 volumes:
1225 - ${PWD}/db:/docker-entrypoint-initdb.d
1226 ports:
1227 - "3306:3306"
1228 nexus:
1229 image: sonatype/nexus:2.14.8-01
1230 container_name: nexus
1231 hostname: nexus
1232 ports:
1233 - "8081:8081"
1234 drools:
1235 image: nexus3.onap.org:10001/onap/policy-drools:1.6.3
1236 container_name: drools
1237 depends_on:
1238 - mariadb
1239 - nexus
1240 hostname: drools
1241 ports:
1242 - "9696:9696"
1243 volumes:
1244 - ${PWD}/config:/tmp/policy-install/config
1245 env_file:
1246 - ${PWD}/env/env.conf
1247
1248with *${PWD}/db/db.conf*:
1249
1250db.conf
1251~~~~~~~
1252
1253.. code-block:: bash
1254
1255 MYSQL_ROOT_PASSWORD=secret
1256 MYSQL_USER=policy_user
1257 MYSQL_PASSWORD=policy_user
1258
1259and *${PWD}/db/db.sh*:
1260
1261db.sh
1262~~~~~
1263
1264.. code-block:: bash
1265
1266 for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
1267 do
1268 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "CREATE DATABASE IF NOT EXISTS ${db};"
1269 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "GRANT ALL PRIVILEGES ON \`${db}\`.* TO '${MYSQL_USER}'@'%' ;"
1270 done
1271
1272 mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "FLUSH PRIVILEGES;"
1273
1274env.conf
1275~~~~~~~~
1276
1277The environment file *env/env.conf* for *PDP-D* can be set up with appropriate variables to point to the *nexus* instance
1278and the *mariadb* database:
1279
1280.. code-block:: bash
1281
1282 # SYSTEM software configuration
1283
1284 POLICY_HOME=/opt/app/policy
1285 POLICY_LOGS=/var/log/onap/policy/pdpd
1286 KEYSTORE_PASSWD=Pol1cy_0nap
1287 TRUSTSTORE_PASSWD=Pol1cy_0nap
1288
1289 # Telemetry credentials
1290
1291 TELEMETRY_PORT=9696
1292 TELEMETRY_HOST=0.0.0.0
1293 TELEMETRY_USER=demo@people.osaaf.org
1294 TELEMETRY_PASSWORD=demo123456!
1295
1296 # nexus repository
1297
1298 SNAPSHOT_REPOSITORY_ID=policy-nexus-snapshots
1299 SNAPSHOT_REPOSITORY_URL=http://nexus:8081/nexus/content/repositories/snapshots/
1300 RELEASE_REPOSITORY_ID=policy-nexus-releases
1301 RELEASE_REPOSITORY_URL=http://nexus:8081/nexus/content/repositories/releases/
1302 REPOSITORY_USERNAME=admin
1303 REPOSITORY_PASSWORD=admin123
1304 REPOSITORY_OFFLINE=false
1305
1306 MVN_SNAPSHOT_REPO_URL=https://nexus.onap.org/content/repositories/snapshots/
1307 MVN_RELEASE_REPO_URL=https://nexus.onap.org/content/repositories/releases/
1308
1309 # Relational (SQL) DB access
1310
1311 SQL_HOST=mariadb
1312 SQL_USER=policy_user
1313 SQL_PASSWORD=policy_user
1314
1315 # AAF
1316
1317 AAF=false
1318 AAF_NAMESPACE=org.onap.policy
1319 AAF_HOST=aaf.api.simpledemo.onap.org
1320
1321 # PDP-D DMaaP configuration channel
1322
1323 PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
1324 PDPD_CONFIGURATION_API_KEY=
1325 PDPD_CONFIGURATION_API_SECRET=
1326 PDPD_CONFIGURATION_CONSUMER_GROUP=
1327 PDPD_CONFIGURATION_CONSUMER_INSTANCE=
1328 PDPD_CONFIGURATION_PARTITION_KEY=
1329
1330 # PAP-PDP configuration channel
1331
1332 POLICY_PDP_PAP_TOPIC=POLICY-PDP-PAP
1333 POLICY_PDP_PAP_API_KEY=
1334 POLICY_PDP_PAP_API_SECRET=
1335
1336 # DMaaP
1337
1338 DMAAP_SERVERS=localhost
1339
1340prepare.pre.sh
1341~~~~~~~~~~~~~~
1342
1343A pre-start script *config/prepare.pres.sh"can be added the custom config directory
1344to prepare the PDP-D to activate the distributed-locking feature (using the database)
1345and to use "noop" topics instead of *dmaap* topics:
1346
1347.. code-block:: bash
1348
1349 #!/bin/bash
1350
1351 bash -c "/opt/app/policy/bin/features enable distributed-locking"
1352 sed -i "s/^dmaap/noop/g" $POLICY_HOME/config/*.properties
1353
1354active.post.sh
1355~~~~~~~~~~~~~~
1356
1357A post-start script *config/active.post.sh* can place PDP-D in *active* mode at initialization:
1358
1359 .. code-block:: bash
1360
1361 bash -c "http --verify=no -a ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} PUT https://localhost:9696/policy/pdp/engine/lifecycle/state/ACTIVE"
1362
1363Bring up the PDP-D, nexus, and mariadb
1364~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1365
1366To bring up the containers:
1367
1368.. code-block:: bash
1369
1370 docker-compose -f docker-compose-pdpd.yaml up -d
1371
1372To take it down:
1373
1374.. code-block:: bash
1375
1376 docker-compose -f docker-compose-pdpd.yaml down -v
1377
1378Other examples
1379~~~~~~~~~~~~~~
1380
1381The reader can also look at the `integration/csit repository <https://git.onap.org/integration/csit>`__.
1382More specifically, these directories have examples of other PDP-D configurations:
1383
1384* `plans <https://git.onap.org/integration/csit/tree/plans/policy/drools-pdp>`__: startup scripts.
1385* `scripts <https://git.onap.org/integration/csit/tree/scripts/policy/docker-compose-drools.yml>`__: docker-compose related files.
1386* `plans <https://git.onap.org/integration/csit/tree/tests/policy/drools-pdp>`__: test plan.
1387
1388Configuring the PDP-D in an OOM Kubernetes installation
1389=======================================================
1390
1391The `PDP-D OOM chart <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools>`__ can be
1392customized at the following locations:
1393
1394* `values.yaml <https://git.onap.org/oom/tree/kubernetes/policy/charts/drools/values.yaml>`__: custom values for your installation.
1395* `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.
1396* `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.
1397
1398The same customization techniques described in the docker sections for PDP-D, fully apply here, by placing the corresponding
1399files or scripts in these two directories.
1400
1401Additional information
1402======================
1403
1404For additional information, please see the
1405`Drools PDP Development and Testing (In Depth) <https://wiki.onap.org/display/DW/2020+Frankfurt+Tutorials>`__ page.