Feature: Test Transaction
Contents
The Test Transaction feature provides a mechanism by which the health of drools policy controllers can be tested.
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.
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.
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.
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.
1 /* 2 * ============LICENSE_START======================================================= 3 * feature-test-transaction 4 * ================================================================================ 5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 6 * ================================================================================ 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * ============LICENSE_END========================================================= 19 */ 20 21 package org.onap.policy.drools.rules; 22 23 import java.util.EventObject; 24 25 declare ForwardProgress 26 counter : Long 27 end 28 29 rule "TT.SETUP" 30 when 31 then 32 ForwardProgress fp = new ForwardProgress(); 33 fp.setCounter(0L); 34 insert(fp); 35 end 36 37 rule "TT" 38 when 39 $fp : ForwardProgress() 40 $tt : EventObject(source == "43868e59-d1f3-43c2-bd6f-86f89a61eea5") 41 then 42 $fp.setCounter($fp.getCounter() + 1); 43 retract($tt); 44 end 45 query "TT.FPC" 46 ForwardProgress(counter >= 0, $ttc : counter) 47 end
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:
policy@hyperion-4:/opt/app/policy$ policy stop [drools-pdp-controllers] L []: Stopping Policy Management... Policy Management (pid=354) is stopping... Policy Management has stopped. policy@hyperion-4:/opt/app/policy$ features enable test-transaction name version status ---- ------- ------ controlloop-utils 1.1.0-SNAPSHOT disabled healthcheck 1.1.0-SNAPSHOT disabled test-transaction 1.1.0-SNAPSHOT enabled eelf 1.1.0-SNAPSHOT disabled state-management 1.1.0-SNAPSHOT disabled active-standby-management 1.1.0-SNAPSHOT disabled session-persistence 1.1.0-SNAPSHOT disabled
The output of the enable command will indicate whether or not the feature was enabled successfully.
Policy engine can then be started as usual.
End of Document