blob: 8bec1421032e1069c2c2565c0cecb9fd198afc26 [file] [log] [blame]
Saryu Shahf96ef832019-06-03 16:23:04 +00001
2.. This work is licensed under a Creative Commons Attribution 4.0 International License.
3.. http://creativecommons.org/licenses/by/4.0
4
jhh108dd8f2020-06-12 17:01:24 -05005.. _feature-tt-label:
6
Saryu Shahf96ef832019-06-03 16:23:04 +00007*************************
8Feature: Test Transaction
9*************************
10
11.. contents::
12 :depth: 3
13
Saryu Shahf96ef832019-06-03 16:23:04 +000014The Test Transaction feature provides a mechanism by which the health of drools policy controllers can be tested.
15
16When enabled, the feature functions by injecting an event object (identified by a UUID) into the drools session of each policy controller that is active in the system. Only an object with this UUID can trigger the Test Transaction-specific drools logic to execute.
17
18The injection of the event triggers the "TT" rule (see *TestTransactionTemplate.drl* below) to fire. The "TT" rule simply increments a ForwardProgress counter object, thereby confirming that the drools session for this particular controller is active and firing its rules accordingly. This cycle repeats at 20 second intervals.
19
20If it is ever the case that a drools controller does not have the "TT" rule present in its *.drl*, or that the forward progress counter is not incremented, the Test Transaction thread for that particular drools session (i.e. controller) is terminated and a message is logged to *error.log*.
21
Saryu Shahf96ef832019-06-03 16:23:04 +000022Prior to being enabled, the following drools rules need to be appended to the rules templates of any use-case that is to be monitored by the feature.
23
24 .. code-block:: java
25 :caption: TestTransactionTemplate.drl
26 :linenos:
27
jhh108dd8f2020-06-12 17:01:24 -050028 /*
Saryu Shahf96ef832019-06-03 16:23:04 +000029 * ============LICENSE_START=======================================================
30 * feature-test-transaction
31 * ================================================================================
32 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
33 * ================================================================================
34 * Licensed under the Apache License, Version 2.0 (the "License");
35 * you may not use this file except in compliance with the License.
36 * You may obtain a copy of the License at
jhh108dd8f2020-06-12 17:01:24 -050037 *
Saryu Shahf96ef832019-06-03 16:23:04 +000038 * http://www.apache.org/licenses/LICENSE-2.0
jhh108dd8f2020-06-12 17:01:24 -050039 *
Saryu Shahf96ef832019-06-03 16:23:04 +000040 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
45 * ============LICENSE_END=========================================================
46 */
jhh108dd8f2020-06-12 17:01:24 -050047
Saryu Shahf96ef832019-06-03 16:23:04 +000048 package org.onap.policy.drools.rules;
jhh108dd8f2020-06-12 17:01:24 -050049
Saryu Shahf96ef832019-06-03 16:23:04 +000050 import java.util.EventObject;
jhh108dd8f2020-06-12 17:01:24 -050051
Saryu Shahf96ef832019-06-03 16:23:04 +000052 declare ForwardProgress
53 counter : Long
54 end
jhh108dd8f2020-06-12 17:01:24 -050055
Saryu Shahf96ef832019-06-03 16:23:04 +000056 rule "TT.SETUP"
57 when
58 then
59 ForwardProgress fp = new ForwardProgress();
60 fp.setCounter(0L);
61 insert(fp);
62 end
jhh108dd8f2020-06-12 17:01:24 -050063
Saryu Shahf96ef832019-06-03 16:23:04 +000064 rule "TT"
jhh108dd8f2020-06-12 17:01:24 -050065 when
Saryu Shahf96ef832019-06-03 16:23:04 +000066 $fp : ForwardProgress()
67 $tt : EventObject(source == "43868e59-d1f3-43c2-bd6f-86f89a61eea5")
68 then
69 $fp.setCounter($fp.getCounter() + 1);
70 retract($tt);
71 end
72 query "TT.FPC"
73 ForwardProgress(counter >= 0, $ttc : counter)
74 end
75
76Once the proper artifacts are built and deployed with the addition of the TestTransactionTemplate rules, the feature can then be enabled by entering the following commands:
77
78 .. code-block:: bash
79 :caption: PDPD Features Command
80
81 policy@hyperion-4:/opt/app/policy$ policy stop
82 [drools-pdp-controllers]
83 L []: Stopping Policy Management... Policy Management (pid=354) is stopping... Policy Management has stopped.
84 policy@hyperion-4:/opt/app/policy$ features enable test-transaction
85 name version status
86 ---- ------- ------
87 controlloop-utils 1.1.0-SNAPSHOT disabled
88 healthcheck 1.1.0-SNAPSHOT disabled
89 test-transaction 1.1.0-SNAPSHOT enabled
90 eelf 1.1.0-SNAPSHOT disabled
91 state-management 1.1.0-SNAPSHOT disabled
92 active-standby-management 1.1.0-SNAPSHOT disabled
93 session-persistence 1.1.0-SNAPSHOT disabled
94
95The output of the enable command will indicate whether or not the feature was enabled successfully.
96
97Policy engine can then be started as usual.
98
99
100End of Document
101
102.. SSNote: Wiki page ref. https://wiki.onap.org/display/DW/Feature+Test+Transaction