Update drools-pdp documents
[policy/parent.git] / docs / drools / pdpdApps.rst
1
2 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
4
5 .. _pdpd-apps-label:
6
7 PDP-D Applications
8 ##################
9
10 .. contents::
11     :depth: 2
12
13 Overview
14 ========
15
16 PDP-D applications uses the PDP-D Engine middleware to provide domain specific services.
17 See :ref:`pdpd-engine-label` for the description of the PDP-D infrastructure.
18
19 At this time *Control Loops* are the only type of applications supported.
20
21 *Control Loop* applications must support the following *Policy Type*:
22
23 - **onap.policies.controlloop.operational.common.Drools** (Tosca Compliant Operational Policies)
24
25 Software
26 ========
27
28 Source Code repositories
29 ~~~~~~~~~~~~~~~~~~~~~~~~
30
31 The PDP-D Applications software resides on the `policy/drools-applications <https://git.onap.org/policy/drools-applications>`__ repository.    The actor libraries introduced in the *frankfurt* release reside in
32 the `policy/models repository <https://git.onap.org/policy/models>`__.
33
34 At this time, the *control loop* application is the only application supported in ONAP.
35 All the application projects reside under the
36 `controlloop directory <https://git.onap.org/policy/drools-applications/tree/controlloop>`__.
37
38 Docker Image
39 ~~~~~~~~~~~~
40
41 See the *drools-applications*
42 `released versions <https://wiki.onap.org/display/DW/Policy+Framework+Project%3A+Component+Versions>`__
43 for the latest images:
44
45 .. code-block:: bash
46
47     docker pull onap/policy-pdpd-cl:1.8.2
48
49 At the time of this writing *1.8.2* is the latest version.
50
51 The *onap/policy-pdpd-cl* image extends the *onap/policy-drools* image with
52 the *usecases* controller that realizes the *control loop* application.
53
54 Usecases Controller
55 ====================
56
57 The `usecases <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases>`__
58 controller is the *control loop* application in ONAP.
59
60 There are three parts in this controller:
61
62 * The `drl rules <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/src/main/resources/usecases.drl>`__.
63 * The `kmodule.xml <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml>`__.
64 * The `dependencies <https://git.onap.org/policy/drools-applications/tree/controlloop/common/controller-usecases/pom.xml>`__.
65
66 The `kmodule.xml` specifies only one session, and declares in the *kbase* section the two operational policy types that
67 it supports.
68
69 The Usecases controller relies on the new Actor framework to interact with remote
70 components, part of a control loop transaction.   The reader is referred to the
71 *Policy Platform Actor Development Guidelines* in the documentation for further information.
72
73 Operational Policy Types
74 ========================
75
76 The *usecases* controller supports the following policy type:
77
78 - *onap.policies.controlloop.operational.common.Drools*.
79
80 The *onap.policies.controlloop.operational.common.Drools*
81 is the Tosca compliant policy type introduced in *frankfurt*.
82
83 The Tosca Compliant Operational Policy Type is defined at the
84 `onap.policies.controlloop.operational.common.Drools <https://git.onap.org/policy/models/tree/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml>`__.
85
86 An example of a Tosca Compliant Operational Policy can be found
87 `here <https://git.onap.org/policy/models/tree/models-examples/src/main/resources/policies/vDNS.policy.operational.input.tosca.json>`__.
88
89 Features
90 ========
91
92 Since the PDP-D Control Loop Application image was created from the PDP-D Engine one (*onap/policy-drools*),
93 it inherits all features and functionality.
94
95 The enabled features in the *onap/policy-pdpd-cl* image are:
96
97 - **distributed locking**: distributed resource locking.
98 - **healthcheck**: healthcheck.
99 - **lifecycle**: enables the lifecycle APIs.
100 - **controlloop-trans**: control loop transaction tracking.
101 - **controlloop-management**: generic controller capabilities.
102 - **controlloop-usecases**: new *controller* introduced in the guilin release to realize the ONAP use cases.
103
104 The following features are installed but disabled:
105
106 - **controlloop-tdjam**: experimental java-only *controller* to be deprecated post guilin.
107 - **controlloop-utils**: *actor* simulators.
108
109 Control Loops Transaction (controlloop-trans)
110 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
112 It tracks Control Loop Transactions and Operations.   These are recorded in
113 the *$POLICY_LOGS/audit.log* and *$POLICY_LOGS/metrics.log*, and accessible
114 through the telemetry APIs.
115
116 Control Loops Management (controlloop-management)
117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119 It installs common control loop application resources, and provides
120 telemetry API extensions.   *Actor* configurations are packaged in this
121 feature.
122
123 Usecases Controller (controlloop-usecases)
124 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125
126 It is the *guilin* release implementation of the ONAP use cases.
127 It relies on the new *Actor* model framework to carry out a policy's
128 execution.
129
130 TDJAM Controller (controlloop-tdjam)
131 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133 This is an experimental, java-only controller that will be deprecated after the
134 guilin release.
135
136 Utilities (controlloop-utils)
137 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138
139 Enables *actor simulators* for testing purposes.
140
141 Offline Mode
142 ============
143
144 The default ONAP installation in *onap/policy-pdpd-cl:1.8.2* is *OFFLINE*.
145 In this configuration, the *rules* artifact and the *dependencies* are all in the local
146 maven repository.   This requires that the maven dependencies are preloaded in the local
147 repository.
148
149 An offline configuration requires two configuration items:
150
151 - *OFFLINE* environment variable set to true (see `values.yaml <https://git.onap.org/oom/tree/kubernetes/policy/values.yaml>`__.
152 - override of the default *settings.xml* (see
153   `settings.xml <https://git.onap.org/oom/tree/kubernetes/policy/components/policy-drools-pdp/resources/configmaps/settings.xml>`__) override.
154
155 Running the PDP-D Control Loop Application in a single container
156 ================================================================
157
158 Environment File
159 ~~~~~~~~~~~~~~~~
160
161 First create an environment file (in this example *env.conf*) to configure the PDP-D.
162
163 .. code-block:: bash
164
165     # SYSTEM software configuration
166
167     POLICY_HOME=/opt/app/policy
168     POLICY_LOGS=/var/log/onap/policy/pdpd
169     KEYSTORE_PASSWD=Pol1cy_0nap
170     TRUSTSTORE_PASSWD=Pol1cy_0nap
171
172     # Telemetry credentials
173
174     TELEMETRY_PORT=9696
175     TELEMETRY_HOST=0.0.0.0
176     TELEMETRY_USER=demo@people.osaaf.org
177     TELEMETRY_PASSWORD=demo123456!
178
179     # nexus repository
180
181     SNAPSHOT_REPOSITORY_ID=
182     SNAPSHOT_REPOSITORY_URL=
183     RELEASE_REPOSITORY_ID=
184     RELEASE_REPOSITORY_URL=
185     REPOSITORY_USERNAME=
186     REPOSITORY_PASSWORD=
187     REPOSITORY_OFFLINE=true
188
189     MVN_SNAPSHOT_REPO_URL=
190     MVN_RELEASE_REPO_URL=
191
192     # Relational (SQL) DB access
193
194     SQL_HOST=
195     SQL_USER=
196     SQL_PASSWORD=
197
198     # AAF
199
200     AAF=false
201     AAF_NAMESPACE=org.onap.policy
202     AAF_HOST=aaf.api.simpledemo.onap.org
203
204     # PDP-D DMaaP configuration channel
205
206     PDPD_CONFIGURATION_TOPIC=PDPD-CONFIGURATION
207     PDPD_CONFIGURATION_API_KEY=
208     PDPD_CONFIGURATION_API_SECRET=
209     PDPD_CONFIGURATION_CONSUMER_GROUP=
210     PDPD_CONFIGURATION_CONSUMER_INSTANCE=
211     PDPD_CONFIGURATION_PARTITION_KEY=
212
213     # PAP-PDP configuration channel
214
215     POLICY_PDP_PAP_TOPIC=POLICY-PDP-PAP
216     POLICY_PDP_PAP_GROUP=defaultGroup
217
218     # Symmetric Key for encoded sensitive data
219
220     SYMM_KEY=
221
222     # Healthcheck Feature
223
224     HEALTHCHECK_USER=demo@people.osaaf.org
225     HEALTHCHECK_PASSWORD=demo123456!
226
227     # Pooling Feature
228
229     POOLING_TOPIC=POOLING
230
231     # PAP
232
233     PAP_HOST=
234     PAP_USERNAME=
235     PAP_PASSWORD=
236
237     # PAP legacy
238
239     PAP_LEGACY_USERNAME=
240     PAP_LEGACY_PASSWORD=
241
242     # PDP-X
243
244     PDP_HOST=localhost
245     PDP_PORT=6669
246     PDP_CONTEXT_URI=pdp/api/getDecision
247     PDP_USERNAME=policy
248     PDP_PASSWORD=password
249     GUARD_DISABLED=true
250
251     # DCAE DMaaP
252
253     DCAE_TOPIC=unauthenticated.DCAE_CL_OUTPUT
254     DCAE_SERVERS=localhost
255     DCAE_CONSUMER_GROUP=dcae.policy.shared
256
257     # Open DMaaP
258
259     DMAAP_SERVERS=localhost
260
261     # AAI
262
263     AAI_HOST=localhost
264     AAI_PORT=6666
265     AAI_CONTEXT_URI=
266     AAI_USERNAME=policy
267     AAI_PASSWORD=policy
268
269     # SO
270
271     SO_HOST=localhost
272     SO_PORT=6667
273     SO_CONTEXT_URI=
274     SO_URL=https://localhost:6667/
275     SO_USERNAME=policy
276     SO_PASSWORD=policy
277
278     # VFC
279
280     VFC_HOST=localhost
281     VFC_PORT=6668
282     VFC_CONTEXT_URI=api/nslcm/v1/
283     VFC_USERNAME=policy
284     VFC_PASSWORD=policy
285
286     # SDNC
287
288     SDNC_HOST=localhost
289     SDNC_PORT=6670
290     SDNC_CONTEXT_URI=restconf/operations/
291
292 Configuration
293 ~~~~~~~~~~~~~
294
295 noop.pre.sh
296 """""""""""
297
298 In order to avoid the noise in the logs that relate to dmaap configuration, a startup script (*noop.pre.sh*) is added
299 to convert *dmaap* endpoints to *noop* in the host directory to be mounted.
300
301 .. code-block:: bash
302
303     #!/bin/bash -x
304
305     sed -i "s/^dmaap/noop/g" $POLICY_HOME/config/*.properties
306
307 features.pre.sh
308 """""""""""""""
309
310 We can enable the *controlloop-utils* and disable the *distributed-locking* feature to avoid using the database.
311
312 .. code-block:: bash
313
314     #!/bin/bash -x
315
316     bash -c "/opt/app/policy/bin/features disable distributed-locking"
317     bash -c "/opt/app/policy/bin/features enable controlloop-utils"
318
319 active.post.sh
320 """"""""""""""
321
322 The *active.post.sh* script makes the PDP-D active.
323
324 .. code-block:: bash
325
326     #!/bin/bash -x
327
328     bash -c "http --verify=no -a ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} PUT https://localhost:9696/policy/pdp/engine/lifecycle/state/ACTIVE"
329
330 Actor Properties
331 """"""""""""""""
332
333 In the *guilin* release, some *actors* configurations need to be overridden to support *http* for compatibility
334 with the *controlloop-utils* feature.
335
336 AAI-http-client.properties
337 """"""""""""""""""""""""""
338
339 .. code-block:: bash
340
341     http.client.services=AAI
342
343     http.client.services.AAI.managed=true
344     http.client.services.AAI.https=false
345     http.client.services.AAI.host=${envd:AAI_HOST}
346     http.client.services.AAI.port=${envd:AAI_PORT}
347     http.client.services.AAI.userName=${envd:AAI_USERNAME}
348     http.client.services.AAI.password=${envd:AAI_PASSWORD}
349     http.client.services.AAI.contextUriPath=${envd:AAI_CONTEXT_URI}
350
351 SDNC-http-client.properties
352 """""""""""""""""""""""""""
353
354 .. code-block:: bash
355
356     http.client.services=SDNC
357
358     http.client.services.SDNC.managed=true
359     http.client.services.SDNC.https=false
360     http.client.services.SDNC.host=${envd:SDNC_HOST}
361     http.client.services.SDNC.port=${envd:SDNC_PORT}
362     http.client.services.SDNC.userName=${envd:SDNC_USERNAME}
363     http.client.services.SDNC.password=${envd:SDNC_PASSWORD}
364     http.client.services.SDNC.contextUriPath=${envd:SDNC_CONTEXT_URI}
365
366 VFC-http-client.properties
367 """"""""""""""""""""""""""
368
369 .. code-block:: bash
370
371     http.client.services=VFC
372
373     http.client.services.VFC.managed=true
374     http.client.services.VFC.https=false
375     http.client.services.VFC.host=${envd:VFC_HOST}
376     http.client.services.VFC.port=${envd:VFC_PORT}
377     http.client.services.VFC.userName=${envd:VFC_USERNAME}
378     http.client.services.VFC.password=${envd:VFC_PASSWORD}
379     http.client.services.VFC.contextUriPath=${envd:VFC_CONTEXT_URI:api/nslcm/v1/}
380
381 settings.xml
382 """"""""""""
383
384 The *standalone-settings.xml* file is the default maven settings override in the container.
385
386 .. code-block:: bash
387
388     <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
389               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
390               xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
391
392         <offline>true</offline>
393
394         <profiles>
395             <profile>
396                 <id>policy-local</id>
397                 <repositories>
398                     <repository>
399                         <id>file-repository</id>
400                         <url>file:${user.home}/.m2/file-repository</url>
401                         <releases>
402                             <enabled>true</enabled>
403                             <updatePolicy>always</updatePolicy>
404                         </releases>
405                         <snapshots>
406                             <enabled>true</enabled>
407                             <updatePolicy>always</updatePolicy>
408                         </snapshots>
409                     </repository>
410                 </repositories>
411             </profile>
412         </profiles>
413
414         <activeProfiles>
415             <activeProfile>policy-local</activeProfile>
416         </activeProfiles>
417
418     </settings>
419
420 Bring up the PDP-D Control Loop Application
421 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
422
423 .. code-block:: bash
424
425     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-pdpd-cl:1.6.4
426
427 To run the container in detached mode, add the *-d* flag.
428
429 Note that we are opening the *9696* telemetry API port to the outside world, mounting the *config* host directory,
430 and setting environment variables.
431
432 To open a shell into the PDP-D:
433
434 .. code-block:: bash
435
436     docker exec -it pdp-d bash
437
438 Once in the container, run tools such as *telemetry*, *db-migrator*, *policy* to look at the system state:
439
440 .. code-block:: bash
441
442     docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
443     docker exec -it PDPD bash -c "/opt/app/policy/bin/policy status"
444     docker exec -it PDPD bash -c "/opt/app/policy/bin/db-migrator -s ALL -o report"
445
446 Controlled instantiation of the PDP-D Control Loop Appplication
447 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448
449 Sometimes a developer may want to start and stop the PDP-D manually:
450
451 .. code-block:: bash
452
453    # start a bash
454
455    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-pdpd-cl:1.6.4 bash
456
457    # use this command to start policy applying host customizations from /tmp/policy-install/config
458
459    pdpd-cl-entrypoint.sh vmboot
460
461    # or use this command to start policy without host customization
462
463    policy start
464
465    # at any time use the following command to stop the PDP-D
466
467    policy stop
468
469    # and this command to start the PDP-D back again
470
471    policy start
472
473 Scale-out use case testing
474 ==========================
475
476 First step is to create the *operational.scaleout* policy.
477
478 policy.vdns.json
479 ~~~~~~~~~~~~~~~~
480
481 .. code-block:: bash
482
483     {
484       "type": "onap.policies.controlloop.operational.common.Drools",
485       "type_version": "1.0.0",
486       "name": "operational.scaleout",
487       "version": "1.0.0",
488       "metadata": {
489         "policy-id": "operational.scaleout"
490       },
491       "properties": {
492         "id": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
493         "timeout": 60,
494         "abatement": false,
495         "trigger": "unique-policy-id-1-scale-up",
496         "operations": [
497           {
498             "id": "unique-policy-id-1-scale-up",
499             "description": "Create a new VF Module",
500             "operation": {
501               "actor": "SO",
502               "operation": "VF Module Create",
503               "target": {
504                 "targetType": "VFMODULE",
505                 "entityIds": {
506                   "modelInvariantId": "e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e",
507                   "modelVersionId": "94b18b1d-cc91-4f43-911a-e6348665f292",
508                   "modelName": "VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0",
509                   "modelVersion": 1,
510                   "modelCustomizationId": "47958575-138f-452a-8c8d-d89b595f8164"
511                 }
512               },
513               "payload": {
514                 "requestParameters": "{\"usePreload\":true,\"userParams\":[]}",
515                 "configurationParameters": "[{\"ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[9]\",\"oam-ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[16]\",\"enabled\":\"$.vf-module-topology.vf-module-parameters.param[23]\"}]"
516               }
517             },
518             "timeout": 20,
519             "retries": 0,
520             "success": "final_success",
521             "failure": "final_failure",
522             "failure_timeout": "final_failure_timeout",
523             "failure_retries": "final_failure_retries",
524             "failure_exception": "final_failure_exception",
525             "failure_guard": "final_failure_guard"
526           }
527         ]
528       }
529     }
530
531 To provision the *scale-out policy*, issue the following command:
532
533 .. code-block:: bash
534
535     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/policy/pdp/engine/lifecycle/policies @usecases/policy.vdns.json
536
537 Verify that the policy shows with the telemetry tools:
538
539 .. code-block:: bash
540
541     docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
542     > get /policy/pdp/engine/lifecycle/policies
543     > get /policy/pdp/engine/controllers/usecases/drools/facts/usecases/controlloops
544
545
546 dcae.vdns.onset.json
547 ~~~~~~~~~~~~~~~~~~~~
548
549 .. code-block:: bash
550
551     {
552       "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
553       "closedLoopAlarmStart": 1463679805324,
554       "closedLoopEventClient": "microservice.stringmatcher",
555       "closedLoopEventStatus": "ONSET",
556       "requestID": "c7c6a4aa-bb61-4a15-b831-ba1472dd4a65",
557       "target_type": "VNF",
558       "target": "vserver.vserver-name",
559       "AAI": {
560         "vserver.is-closed-loop-disabled": "false",
561         "vserver.prov-status": "ACTIVE",
562         "vserver.vserver-name": "OzVServer"
563       },
564       "from": "DCAE",
565       "version": "1.0.2"
566     }
567
568 To initiate a control loop transaction, simulate a DCAE ONSET to Policy:
569
570 .. code-block:: bash
571
572     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" PUT https://localhost:9696/policy/pdp/engine/topics/sources/noop/DCAE_TOPIC/events @dcae.vdns.onset.json Content-Type:'text/plain'
573
574 This will trigger the scale out control loop transaction that will interact with the *SO*
575 simulator to complete the transaction.
576
577 Verify in *$POLICY_LOGS/network.log* that a *FINAL: SUCCESS* notification is sent over the POLICY-CL-MGT channel.
578 An entry in the *$POLICY_LOGS/audit.log* should indicate successful completion as well.
579
580 vCPE use case testing
581 =====================
582
583 First step is to create the *operational.restart* policy.
584
585 policy.vcpe.json
586 ~~~~~~~~~~~~~~~~
587
588 .. code-block:: bash
589
590     {
591       "type": "onap.policies.controlloop.operational.common.Drools",
592       "type_version": "1.0.0",
593       "name": "operational.restart",
594       "version": "1.0.0",
595       "metadata": {
596         "policy-id": "operational.restart"
597       },
598       "properties": {
599         "id": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
600         "timeout": 300,
601         "abatement": false,
602         "trigger": "unique-policy-id-1-restart",
603         "operations": [
604           {
605             "id": "unique-policy-id-1-restart",
606             "description": "Restart the VM",
607             "operation": {
608               "actor": "APPC",
609               "operation": "Restart",
610               "target": {
611                 "targetType": "VNF"
612               }
613             },
614             "timeout": 240,
615             "retries": 0,
616             "success": "final_success",
617             "failure": "final_failure",
618             "failure_timeout": "final_failure_timeout",
619             "failure_retries": "final_failure_retries",
620             "failure_exception": "final_failure_exception",
621             "failure_guard": "final_failure_guard"
622           }
623         ]
624       }
625     }
626
627 To provision the *operational.restart policy* issue the following command:
628
629 .. code-block:: bash
630
631     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/policy/pdp/engine/lifecycle/policies @usecases/policy.vcpe.json
632
633 Verify that the policy shows with the telemetry tools:
634
635 .. code-block:: bash
636
637     docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
638     > get /policy/pdp/engine/lifecycle/policies
639     > get /policy/pdp/engine/controllers/usecases/drools/facts/usecases/controlloops
640
641
642 dcae.vcpe.onset.json
643 ~~~~~~~~~~~~~~~~~~~~
644
645 .. code-block:: bash
646
647     {
648       "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
649       "closedLoopAlarmStart": 1463679805324,
650       "closedLoopEventClient": "DCAE_INSTANCE_ID.dcae-tca",
651       "closedLoopEventStatus": "ONSET",
652       "requestID": "664be3d2-6c12-4f4b-a3e7-c349acced200",
653       "target_type": "VNF",
654       "target": "generic-vnf.vnf-id",
655       "AAI": {
656         "vserver.is-closed-loop-disabled": "false",
657         "vserver.prov-status": "ACTIVE",
658         "generic-vnf.vnf-id": "vCPE_Infrastructure_vGMUX_demo_app"
659       },
660       "from": "DCAE",
661       "version": "1.0.2"
662     }
663
664 To initiate a control loop transaction, simulate a DCAE ONSET to Policy:
665
666 .. code-block:: bash
667
668     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" PUT https://localhost:9696/policy/pdp/engine/topics/sources/noop/DCAE_TOPIC/events @dcae.vcpe.onset.json Content-Type:'text/plain'
669
670 This will spawn a vCPE control loop transaction in the PDP-D.  Policy will send a *restart* message over the
671 *APPC-LCM-READ* channel to APPC and wait for a response.
672
673 Verify that you see this message in the network.log by looking for *APPC-LCM-READ* messages.
674
675 Note the *sub-request-id* value from the restart message in the *APPC-LCM-READ* channel.
676
677 Replace *REPLACEME* in the *appc.vcpe.success.json* with this sub-request-id.
678
679 appc.vcpe.success.json
680 ~~~~~~~~~~~~~~~~~~~~~~
681
682 .. code-block:: bash
683
684     {
685       "body": {
686         "output": {
687           "common-header": {
688             "timestamp": "2017-08-25T21:06:23.037Z",
689             "api-ver": "5.00",
690             "originator-id": "664be3d2-6c12-4f4b-a3e7-c349acced200",
691             "request-id": "664be3d2-6c12-4f4b-a3e7-c349acced200",
692             "sub-request-id": "REPLACEME",
693             "flags": {}
694           },
695           "status": {
696             "code": 400,
697             "message": "Restart Successful"
698           }
699         }
700       },
701       "version": "2.0",
702       "rpc-name": "restart",
703       "correlation-id": "664be3d2-6c12-4f4b-a3e7-c349acced200-1",
704       "type": "response"
705     }
706
707
708 Send a simulated APPC response back to the PDP-D over the *APPC-LCM-WRITE* channel.
709
710 .. code-block:: bash
711
712     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" PUT https://localhost:9696/policy/pdp/engine/topics/sources/noop/APPC-LCM-WRITE/events @appc.vcpe.success.json  Content-Type:'text/plain'
713
714 Verify in *$POLICY_LOGS/network.log* that a *FINAL: SUCCESS* notification is sent over the *POLICY-CL-MGT* channel,
715 and an entry is added to the *$POLICY_LOGS/audit.log* indicating successful completion.
716
717 vFirewall use case testing
718 ===========================
719
720 First step is to create the *operational.modifyconfig* policy.
721
722 policy.vfw.json
723 ~~~~~~~~~~~~~~~
724
725 .. code-block:: bash
726
727     {
728       "type": "onap.policies.controlloop.operational.common.Drools",
729       "type_version": "1.0.0",
730       "name": "operational.modifyconfig",
731       "version": "1.0.0",
732       "metadata": {
733         "policy-id": "operational.modifyconfig"
734       },
735       "properties": {
736         "id": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
737         "timeout": 300,
738         "abatement": false,
739         "trigger": "unique-policy-id-1-modifyConfig",
740         "operations": [
741           {
742             "id": "unique-policy-id-1-modifyConfig",
743             "description": "Modify the packet generator",
744             "operation": {
745               "actor": "APPC",
746               "operation": "ModifyConfig",
747               "target": {
748                 "targetType": "VNF",
749                 "entityIds": {
750                   "resourceID": "bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"
751                 }
752               },
753               "payload": {
754                 "streams": "{\"active-streams\": 5 }"
755               }
756             },
757             "timeout": 240,
758             "retries": 0,
759             "success": "final_success",
760             "failure": "final_failure",
761             "failure_timeout": "final_failure_timeout",
762             "failure_retries": "final_failure_retries",
763             "failure_exception": "final_failure_exception",
764             "failure_guard": "final_failure_guard"
765           }
766         ]
767       }
768     }
769
770
771 To provision the *operational.modifyconfig policy*, issue the following command:
772
773 .. code-block:: bash
774
775     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/policy/pdp/engine/lifecycle/policies @usecases/policy.vfw.json
776
777 Verify that the policy shows with the telemetry tools:
778
779 .. code-block:: bash
780
781     docker exec -it PDPD bash -c "/opt/app/policy/bin/telemetry"
782     > get /policy/pdp/engine/lifecycle/policies
783     > get /policy/pdp/engine/controllers/usecases/drools/facts/usecases/controlloops
784
785
786 dcae.vfw.onset.json
787 ~~~~~~~~~~~~~~~~~~~~
788
789 .. code-block:: bash
790
791     {
792       "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
793       "closedLoopAlarmStart": 1463679805324,
794       "closedLoopEventClient": "microservice.stringmatcher",
795       "closedLoopEventStatus": "ONSET",
796       "requestID": "c7c6a4aa-bb61-4a15-b831-ba1472dd4a65",
797       "target_type": "VNF",
798       "target": "generic-vnf.vnf-name",
799       "AAI": {
800         "vserver.is-closed-loop-disabled": "false",
801         "vserver.prov-status": "ACTIVE",
802         "generic-vnf.vnf-name": "fw0002vm002fw002",
803         "vserver.vserver-name": "OzVServer"
804       },
805       "from": "DCAE",
806       "version": "1.0.2"
807     }
808
809
810 To initiate a control loop transaction, simulate a DCAE ONSET to Policy:
811
812 .. code-block:: bash
813
814     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" PUT https://localhost:9696/policy/pdp/engine/topics/sources/noop/DCAE_TOPIC/events @dcae.vfw.onset.json Content-Type:'text/plain'
815
816 This will spawn a vFW control loop transaction in the PDP-D.  Policy will send a *ModifyConfig* message over the
817 *APPC-CL* channel to APPC and wait for a response.  This can be seen by searching the network.log for *APPC-CL*.
818
819 Note the *SubRequestId* field in the *ModifyConfig* message in the *APPC-CL* topic in the network.log
820
821 Send a simulated APPC response back to the PDP-D over the *APPC-CL* channel.
822 To do this, change the *REPLACEME* text in the *appc.vcpe.success.json* with this *SubRequestId*.
823
824 appc.vcpe.success.json
825 ~~~~~~~~~~~~~~~~~~~~~~
826
827 .. code-block:: bash
828
829     {
830       "CommonHeader": {
831         "TimeStamp": 1506051879001,
832         "APIver": "1.01",
833         "RequestID": "c7c6a4aa-bb61-4a15-b831-ba1472dd4a65",
834         "SubRequestID": "REPLACEME",
835         "RequestTrack": [],
836         "Flags": []
837       },
838       "Status": {
839         "Code": 400,
840         "Value": "SUCCESS"
841       },
842       "Payload": {
843         "generic-vnf.vnf-id": "f17face5-69cb-4c88-9e0b-7426db7edddd"
844       }
845     }
846
847 .. code-block:: bash
848
849     http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" PUT https://localhost:9696/policy/pdp/engine/topics/sources/noop/APPC-CL/events @appc.vcpe.success.json Content-Type:'text/plain'
850
851 Verify in *$POLICY_LOGS/network.log* that a *FINAL: SUCCESS* notification is sent over the POLICY-CL-MGT channel,
852 and an entry is added to the *$POLICY_LOGS/audit.log* indicating successful completion.
853
854
855 Running PDP-D Control Loop Application with other components
856 ============================================================
857
858 The reader can also look at the `policy/docker repository <https://github.com/onap/policy-docker/tree/master/csit>`__.
859 More specifically, these directories have examples of other PDP-D Control Loop configurations:
860
861 * `plans <https://github.com/onap/policy-docker/tree/master/csit/drools-pdp/plans>`__: startup scripts.
862 * `tests <https://github.com/onap/policy-docker/tree/master/csit/drools-pdp/tests>`__: test plan.
863
864 Additional information
865 ======================
866
867 For additional information, please see the
868 `Drools PDP Development and Testing (In Depth) <https://wiki.onap.org/display/DW/2020+Frankfurt+Tutorials>`__ page.
869
870