Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 1 | |
| 2 | .. This work is licensed under a Creative Commons Attribution 4.0 International License. |
| 3 | .. http://creativecommons.org/licenses/by/4.0 |
| 4 | |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 5 | .. _feature-tt-label: |
| 6 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 7 | ************************* |
| 8 | Feature: Test Transaction |
| 9 | ************************* |
| 10 | |
| 11 | .. contents:: |
| 12 | :depth: 3 |
| 13 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 14 | The Test Transaction feature provides a mechanism by which the health of drools policy controllers can be tested. |
| 15 | |
| 16 | When 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 | |
| 18 | The 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 | |
| 20 | If 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 Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 22 | Prior 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 | |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 28 | /* |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 29 | * ============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 |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 37 | * |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 38 | * http://www.apache.org/licenses/LICENSE-2.0 |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 39 | * |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 40 | * 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 | */ |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 47 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 48 | package org.onap.policy.drools.rules; |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 49 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 50 | import java.util.EventObject; |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 51 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 52 | declare ForwardProgress |
| 53 | counter : Long |
| 54 | end |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 55 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 56 | rule "TT.SETUP" |
| 57 | when |
| 58 | then |
| 59 | ForwardProgress fp = new ForwardProgress(); |
| 60 | fp.setCounter(0L); |
| 61 | insert(fp); |
| 62 | end |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 63 | |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 64 | rule "TT" |
jhh | 108dd8f | 2020-06-12 17:01:24 -0500 | [diff] [blame] | 65 | when |
Saryu Shah | f96ef83 | 2019-06-03 16:23:04 +0000 | [diff] [blame] | 66 | $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 | |
| 76 | Once 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 | |
| 95 | The output of the enable command will indicate whether or not the feature was enabled successfully. |
| 96 | |
| 97 | Policy engine can then be started as usual. |
| 98 | |
| 99 | |
| 100 | End of Document |
| 101 | |
| 102 | .. SSNote: Wiki page ref. https://wiki.onap.org/display/DW/Feature+Test+Transaction |