drools documentation redo
[policy/parent.git] / docs / drools / feature_activestdbymgmt.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 .. _feature-asm-label:
6
7 **********************************
8 Feature: Active/Standby Management
9 **********************************
10
11 .. contents::
12     :depth: 3
13
14 When the Feature Session Persistence is enabled, there can only be one active/providing service Drools PDP due to the behavior of Drools persistence. The Active/Standby Management Feature controls the selection of the Drools PDP that is providing service. It utilizes its own database and the State Management Feature database in the election algorithm.  All Drools PDP nodes periodically run the election algorithm and, since they all use the same data, all nodes come to the same conclusion with the "elected" node assuming an active/providingservice state.  Thus, the algorithm is distributed and has no single point of failure - assuming the database is configured for high availability.
15
16 When the algorithm selects a Drools PDP to be active/providing service the controllers and topic endpoints are unlocked and allowed to process transactions. When a Drools PDP transitions to a hotstandby or coldstandby state, the controllers and topic endpoints are locked, preventing the Drools PDP from handling transactions.
17
18
19 Enabling and Disabling Feature State Management
20 ===============================================
21
22 The Active/Standby Management Feature is enabled from the command line when logged in as policy after configuring the feature properties file (see Description Details section).  From the command line:
23
24 - > features status - Lists the status of features
25 - > features enable active-standby-management - Enables the Active-Standby Management Feature
26 - > features disable active-standby-management - Disables the Active-Standby Management Feature
27
28 The Drools PDP must be stopped prior to enabling/disabling features and then restarted after the features have been enabled/disabled.
29
30     .. code-block:: bash
31        :caption: Enabling Active/Standby Management Feature
32
33         policy@hyperion-4:/opt/app/policy$ policy stop
34         [drools-pdp-controllers]
35          L []: Stopping Policy Management... Policy Management (pid=354) is stopping... Policy Management has stopped.
36         policy@hyperion-4:/opt/app/policy$ features enable active-standby-management
37         name                      version         status
38         ----                      -------         ------
39         controlloop-utils         1.1.0-SNAPSHOT  disabled
40         healthcheck               1.1.0-SNAPSHOT  disabled
41         test-transaction          1.1.0-SNAPSHOT  disabled
42         eelf                      1.1.0-SNAPSHOT  disabled
43         state-management          1.1.0-SNAPSHOT  disabled
44         active-standby-management 1.1.0-SNAPSHOT  enabled
45         session-persistence       1.1.0-SNAPSHOT  disabled
46
47
48 Description Details
49 ~~~~~~~~~~~~~~~~~~~
50
51 Election Algorithm
52 ------------------
53
54 The election algorithm selects the active/providingservice Drools PDP. The algorithm on each node reads the *standbystatus* from the *StateManagementEntity* table for all other nodes to determine if they are providingservice or in a hotstandby state and able to assume an active status. It uses the *DroolsPdpEntity* table to verify that other node election algorithms are currently functioning and when the other nodes were last designated as the active Drools PDP.
55
56 In general terms, the election algorithm periodically gathers the standbystatus and designation status for all the Drools PDPs. If the node which is currently designated as providingservice is "current" in updating its status, no action is required.  If the designated node is either not current or has a standbystatus other than providingservice, it is time to choose another designated *DroolsPDP*.  The algorithm will build a list of all DroolsPDPs that are current and have a *standbystatus* of *hotstandby*.  It will then give preference to DroolsPDPs within the same site, choosing the DroolsPDP with the lowest lexicographic value to the droolsPdpId (resourceName).  If the chosen DroolsPDP is itself, it will promote its standbystatus from hotstandby to providingservice.  If the chosen DroolsPDP is other than itself, it will do nothing.
57
58 When the DroolsPDP promotes its *standbystatus* from hotstandby to providing service, a state change notification will occur and the Standby State Change Handler will take appropriate action.
59
60
61 Standby State Change Handler
62 ----------------------------
63
64 The Standby State Change Handler (*PMStandbyStateChangeHandler* class) extends the IntegrityMonitor StateChangeNotifier class which implements the Observer class.  When the DroolsPDP is constructed, an instance of the handler is constructed and registered with StateManagement.  Whenever StateManagement implements a state transition, it calls the *handleStateChange()* method of the handler.  If the StandbyStatus transitions to hot or cold standby, the handler makes a call into the lower level management layer to lock the application controllers and topic endpoints, preventing it from handling transactions.  If the StandbyStatus transitions to providingservice, the handler makes a call into the lower level management layer to unlock the application controllers and topic endpoints, allowing it to handle transactions.
65
66
67 Database
68 --------
69
70 The Active/Standby Feature creates a database named activestandbymanagement with a single table, **droolspdpentity**.  The election handler uses that table to determine which DroolsPDP was/is designated as the active DroolsPDP and which DroolsPDP election handlers are healthy enough to periodically update their status.
71
72 The **droolspdpentity** table has the following columns:
73     - **pdpId** - The unique indentifier for the DroolsPDP.  It is the same as the resourceName
74     - **designated** - Has a value of 1 if the DroolsPDP is designated as active/providingservice.  It has a value of 0 otherwise
75     - **priority** - Indicates the priority level of the DroolsPDP for the election handler.  In general, this is ignore and all have the same priority.
76     - **updatedDate** - This is the timestamp for the most recent update of the record.
77     - **designatedDate** - This is the timestamp that indicates when the designated column was most recently set to a value of 1
78     - **site** - This is the name of the site
79
80 Properties
81 ----------
82
83 The properties are found in the feature-active-standby-management.properties file. In general, the properties are adequately described in the properties file. Parameters which must be replaced prior to usage are indicated thus: ${{parameter to be replaced}}
84
85     .. code-block:: bash
86        :caption: feature-active-standby-mangement.properties
87
88         # DB properties
89         javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
90         javax.persistence.jdbc.url=jdbc:mariadb://${{SQL_HOST}}:3306/activestandbymanagement
91         javax.persistence.jdbc.user=${{SQL_USER}}
92         javax.persistence.jdbc.password=${{SQL_PASSWORD}}
93
94         # Must be unique across the system
95         resource.name=pdp1
96         # Name of the site in which this node is hosted
97         site_name=site1
98
99         # Needed by DroolsPdpsElectionHandler
100         pdp.checkInterval=1500 # The interval in ms between updates of the updatedDate
101         pdp.updateInterval=1000 # The interval in ms between executions of the election handler
102         #pdp.timeout=3000
103         # Need long timeout, because testTransaction is only run every 10 seconds.
104         pdp.timeout=15000
105         #how long do we wait for the pdp table to populate on initial startup
106         pdp.initialWait=20000
107
108
109 End of Document
110
111 .. SSNote: Wiki page ref. https://wiki.onap.org/pages/viewpage.action?pageId=16005790
112
113