Saryu Shah | 1dbf351 | 2017-11-09 02:13:25 +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 | |
| 5 | ************************* |
| 6 | Feature: Test Transaction |
| 7 | ************************* |
| 8 | |
| 9 | .. contents:: |
| 10 | :depth: 3 |
| 11 | |
| 12 | Summary |
| 13 | ^^^^^^^ |
| 14 | |
| 15 | The Test Transaction feature provides a mechanism by which the health of drools policy controllers can be tested. |
| 16 | |
| 17 | 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. |
| 18 | |
| 19 | 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. |
| 20 | |
| 21 | 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*. |
| 22 | |
| 23 | Usage |
| 24 | ^^^^^ |
| 25 | |
| 26 | 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. |
| 27 | |
| 28 | .. code-block:: java |
| 29 | :caption: TestTransactionTemplate.drl |
| 30 | :linenos: |
| 31 | |
| 32 | /* |
| 33 | * ============LICENSE_START======================================================= |
| 34 | * feature-test-transaction |
| 35 | * ================================================================================ |
| 36 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 37 | * ================================================================================ |
| 38 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 39 | * you may not use this file except in compliance with the License. |
| 40 | * You may obtain a copy of the License at |
| 41 | * |
| 42 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 43 | * |
| 44 | * Unless required by applicable law or agreed to in writing, software |
| 45 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 46 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 47 | * See the License for the specific language governing permissions and |
| 48 | * limitations under the License. |
| 49 | * ============LICENSE_END========================================================= |
| 50 | */ |
| 51 | |
| 52 | package org.onap.policy.drools.rules; |
| 53 | |
| 54 | import java.util.EventObject; |
| 55 | |
| 56 | declare ForwardProgress |
| 57 | counter : Long |
| 58 | end |
| 59 | |
| 60 | rule "TT.SETUP" |
| 61 | when |
| 62 | then |
| 63 | ForwardProgress fp = new ForwardProgress(); |
| 64 | fp.setCounter(0L); |
| 65 | insert(fp); |
| 66 | end |
| 67 | |
| 68 | rule "TT" |
| 69 | when |
| 70 | $fp : ForwardProgress() |
| 71 | $tt : EventObject(source == "43868e59-d1f3-43c2-bd6f-86f89a61eea5") |
| 72 | then |
| 73 | $fp.setCounter($fp.getCounter() + 1); |
| 74 | retract($tt); |
| 75 | end |
| 76 | query "TT.FPC" |
| 77 | ForwardProgress(counter >= 0, $ttc : counter) |
| 78 | end |
| 79 | |
| 80 | 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: |
| 81 | |
| 82 | .. code-block:: bash |
| 83 | :caption: PDPD Features Command |
| 84 | |
| 85 | policy@hyperion-4:/opt/app/policy$ policy stop |
| 86 | [drools-pdp-controllers] |
| 87 | L []: Stopping Policy Management... Policy Management (pid=354) is stopping... Policy Management has stopped. |
| 88 | policy@hyperion-4:/opt/app/policy$ features enable test-transaction |
| 89 | name version status |
| 90 | ---- ------- ------ |
| 91 | controlloop-utils 1.1.0-SNAPSHOT disabled |
| 92 | healthcheck 1.1.0-SNAPSHOT disabled |
| 93 | test-transaction 1.1.0-SNAPSHOT enabled |
| 94 | eelf 1.1.0-SNAPSHOT disabled |
| 95 | state-management 1.1.0-SNAPSHOT disabled |
| 96 | active-standby-management 1.1.0-SNAPSHOT disabled |
| 97 | session-persistence 1.1.0-SNAPSHOT disabled |
| 98 | |
| 99 | The output of the enable command will indicate whether or not the feature was enabled successfully. |
| 100 | |
| 101 | Policy engine can then be started as usual. |
| 102 | |
| 103 | |
| 104 | End of Document |
| 105 | |
| 106 | .. SSNote: Wiki page ref. https://wiki.onap.org/display/DW/Feature+Test+Transaction |