Doc Updates: Policy OOM; StateMgmt
[policy/engine.git] / docs / platform / feature_statemgmt.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 *************************
6 Feature: State Management 
7 *************************
8
9 .. contents::
10     :depth: 2
11
12 Summary
13 ^^^^^^^
14 The State Management Feature provides:
15
16 - Node-level health monitoring
17 - Monitoring the health of dependency nodes - nodes on which a particular node is dependent
18 - Ability to lock/unlock a node and suspend or resume all application processing
19 - Ability to suspend application processing on a node that is disabled or in a standby state
20 - Interworking/Coordination of state values
21 - Support for ITU X.731 states and state transitions for:
22         - Administrative State
23         - Operational State
24         - Availability Status
25         - Standby Status
26
27 Usage
28 ^^^^^
29
30 Enabling and Disabling Feature State Management
31 -----------------------------------------------
32
33 The State 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:
34
35 - > features status - Lists the status of features
36 - > features enable state-management - Enables the State Management Feature
37 - > features disable state-management - Disables the State Management Feature
38
39 The Drools PDP must be stopped prior to enabling/disabling features and then restarted after the features have been enabled/disabled.
40
41     .. code-block:: bash
42        :caption: Enabling State Management Feature
43
44         policy@hyperion-4:/opt/app/policy$ policy stop
45         [drools-pdp-controllers]
46          L []: Stopping Policy Management... Policy Management (pid=354) is stopping... Policy Management has stopped.
47         policy@hyperion-4:/opt/app/policy$ features enable state-management
48         name                      version         status
49         ----                      -------         ------
50         controlloop-utils         1.1.0-SNAPSHOT  disabled
51         healthcheck               1.1.0-SNAPSHOT  disabled
52         test-transaction          1.1.0-SNAPSHOT  disabled
53         eelf                      1.1.0-SNAPSHOT  disabled
54         state-management          1.1.0-SNAPSHOT  enabled
55         active-standby-management 1.1.0-SNAPSHOT  disabled
56         session-persistence       1.1.0-SNAPSHOT  disabled
57
58 Description Details
59 ^^^^^^^^^^^^^^^^^^^
60
61 State Model
62 -----------
63
64 The state model follows the ITU X.731 standard for state management.  The supported state values are:
65     **Administrative State:**
66         - Locked - All application transaction processing is prohibited
67         - Unlocked - Application transaction processing is allowed
68     
69     **Administrative State Transitions:**
70         - The transition from Unlocked to Locked state is triggered with a Lock operation
71         - The transition from the Locked to Unlocked state is triggered with an Unlock operation
72
73     **Operational State:**
74         - Enabled - The node is healthy and able to process application transactions
75         - Disabled - The node is not healthy and not able to process application transactions    
76
77     **Operational State Transitions:**
78         - The transition from Enabled to Disabled is triggered with a disableFailed or disableDependency operation
79         - The transition from Disabled to Enabled is triggered with an enableNotFailed and enableNoDependency operation
80     
81     **Availability Status:**
82         - Null - The Operational State is Enabled
83         - Failed - The Operational State is Disabled because the node is no longer healthy
84         - Dependency - The Operational State is Disabled because all members of a dependency group are disabled
85         - Dependency.Failed - The Operational State is Disabled because the node is no longer healthy and all members of a dependency group are disabled
86     
87     **Availability Status Transitions:**
88         - The transition from Null to Failed is triggered with a disableFailed operation
89         - The transtion from Null to Dependency is triggered with a disableDependency operation
90         - The transition from Failed to Dependency.Failed is triggered with a disableDependency operation
91         - The transition from Dependency to Dependency.Failed is triggered with a disableFailed operation
92         - The transition from Dependency.Failed to Failed is triggered with an enableNoDependency operation
93         - The transition from Dependency.Failed to Dependency is triggered with an enableNotFailed operation
94         - The transition from Failed to Null is triggered with an enableNotFailed operation
95         - The transition from Dependency to Null is triggered with an enableNoDependency operation
96     
97     **Standby Status:**
98         - Null - The node does not support active-standby behavior
99         - ProvidingService - The node is actively providing application transaction service
100         - HotStandby - The node is capable of providing application transaction service, but is currently waiting to be promoted
101         - ColdStandby - The node is not capable of providing application service because of a failure
102     
103     **Standby Status Transitions:**
104         - The transition from Null to HotStandby is triggered by a demote operation when the Operational State is Enabled
105         - The transition for Null to ColdStandby is triggered is a demote operation when the Operational State is Disabled
106         - The transition from ColdStandby to HotStandby is triggered by a transition of the Operational State from Disabled to Enabled
107         - The transition from HotStandby to ColdStandby is triggered by a transition of the Operational State from Enabled to Disabled
108         - The transition from ProvidingService to ColdStandby is triggered by a transition of the Operational State from Enabled to Disabled
109         - The transition from HotStandby to ProvidingService is triggered by a Promote operation
110         - The transition from ProvidingService to HotStandby is triggered by a Demote operation
111
112 Database
113 --------
114
115 The State Management feature creates a StateManagement database having three tables:
116
117     **StateManagementEntity** - This table has the following columns:
118         - **id** - Automatically created unique identifier
119         - **resourceName** - The unique identifier for a node
120         - **adminState** - The Administrative State
121         - **opState** - The Operational State
122         - **availStatus** - The Availability Status
123         - **standbyStatus** - The Standby Status
124         - **created_Date** - The timestamp the resource entry was created
125         - **modifiedDate** - The timestamp the resource entry was last modified
126
127     **ForwardProgressEntity** - This table has the following columns:
128         - **forwardProgressId** - Automatically created unique identifier
129         - **resourceName** - The unique identifier for a node
130         - **fpc_count** - A forward progress counter which is periodically incremented if the node is healthy
131         - **created_date** - The timestamp the resource entry was created
132         - **last_updated** - The timestamp the resource entry was last updated
133     
134     **ResourceRegistrationEntity** - This table has the following columns:
135         - **ResourceRegistrationId** - Automatically created unique identifier
136         - **resourceName** - The unique identifier for a node
137         - **resourceUrl** - The JMX URL used to check the health of a node
138         - **site** - The name of the site in which the resource resides
139         - **nodeType** - The type of the node (i.e, pdp_xacml, pdp_drools, pap, pap_admin, logparser, brms_gateway, astra_gateway, elk_server, pypdp)
140         - **created_date** - The timestamp the resource entry was created
141         - **last_updated** - The timestamp the resource entry was last updated
142
143 Node Health Monitoring
144 ----------------------
145
146 **Application Monitoring**
147     
148     Application monitoring can be implemented using the *startTransaction()* and *endTransaction()* methods.  Whenever a transaction is started, the *startTransaction()* method is called.  If the node is locked, disabled or in a hot/cold standby state, the method will throw an exception.  Otherwise, it resets the timer which triggers the default *testTransaction()* method. 
149     
150     When a transaction completes, calling *endTransaction()* increments the forward process counter in the *ForwardProgressEntity* DB table.  As long as this counter is updating, the integrity monitor will assume the node is healthy/sane.
151     
152     If the *startTransaction()* method is not called within a provisioned period of time, a timer will expire which calls the *testTransaction()* method.  The default implementation of this method simply increments the forward progress counter.  The *testTransaction()* method may be overwritten to perform a more meaningful test of system sanity, if desired.
153     
154     If the forward progress counter stops incrementing, the integrity monitoring routine will assume the node application has lost sanity and it will trigger a *statechange* (disableFailed) to cause the operational state to become disabled and the availability status attribute to become failed.  Once the forward progress counter again begins incrementing, the operational state will return to enabled.
155
156 **Application Monitoring with AllSeemsWell**
157
158     The IntegrityMonitor class provides a facility for applications to directly control updates of the forwardprogressentity table.  As previously described, *startTransaction()* and *endTransaction()* are provided to monitor the forward progress of transactions.  This, however, does not monitor things such as internal threads that may be blocked or die.  An example is the feature-state-management *DroolsPdpElectionHandler.run()* method. 
159
160     The *run()* method is monitored by a timer task, *checkWaitTimer()*.  If the *run()* method is stalled an extended period of time, the *checkWaitTimer()* method will call *StateManagementFeature.allSeemsWell(<className>, <AllSeemsWell State>, <String message>)* with the AllSeemsWell state of Boolean.FALSE.
161
162     The IntegrityMonitor instance owned by StateManagementFeature will then store an entry in the allSeemsWellMap and block updates of the forwardprogressentity table.  This in turn, will cause the Drools PDP operational state to be set to “disabled” and availability status to be set to “failed”.  
163
164     Once the blocking condition is cleared, the *checkWaiTimer()* will again call the *allSeemsWell()* method and include an AllSeemsWell state of Boolean.True. This will cause the IntegrityMonitor to remove the entry for that className from the allSeemsWellMap and allow updating of the forwardprogressentity table, so long as there are no other entries in the map.
165
166 **Dependency Monitoring**
167
168     When a Drools PDP (or other node using the *IntegrityMonitor* policy/common module) is dependent upon other nodes to perform its function, those other nodes can be defined as dependencies in the properties file. In order for the dependency algorithm to function, the other nodes must also be running the *IntegrityMonitor*.  Periodically the Drools PDP will check the state of dependencies.  If all of a node type have failed, the Drools PDP will declare that it can no longer function and change the operational state to disabled and the availability status to dependency.
169
170     In addition to other policy node types, there is a *subsystemTest()* method that is periodically called by the *IntegrityMonitor*.  In Drools PDP, *subsystemTest* has been overwritten to execute an audit of the Database and of the Maven Repository.  If the audit is unable to verify the function of either the DB or the Maven Repository, he Drools PDP will declare that it can no longer function and change the operational state to disabled and the availability status to dependency.
171
172     When a failed dependency returns to normal operation, the *IntegrityMontor* will change the operational state to enabled and availability status to null.
173
174 **External Health Monitoring Interface**
175
176     The Drools PDP has a http test interface which, when called, will return 200 if all seems well and 500 otherwise.  The test interface URL is defined in the properties file.
177
178
179 Site Manager
180 ------------
181
182 The Site Manager is not deployed with the Drools PDP, but it is available in the policy/common repository in the site-manager directory.   
183 The Site Manager provides a lock/unlock interface for nodes and a way to display node information and status.
184
185 The following is from the README file included with the Site Manager.
186
187     .. code-block:: bash
188        :caption: Site Manager README extract
189
190         Before using 'siteManager', the file 'siteManager.properties' needs to be 
191         edited to configure the parameters used to access the database:
192         
193             javax.persistence.jdbc.driver - typically 'org.mariadb.jdbc.Driver'
194         
195             javax.persistence.jdbc.url - URL referring to the database,
196                 which typically has the form: 'jdbc:mariadb://<host>:<port>/<db>'
197                 ('<db>' is probably 'xacml' in this case)
198         
199             javax.persistence.jdbc.user - the user id for accessing the database
200         
201             javax.persistence.jdbc.password - password for accessing the database
202         
203         Once the properties file has been updated, the 'siteManager' script can be
204         invoked as follows:
205         
206             siteManager show [ -s <site> | -r <resourceName> ] :
207                 display node information (Site, NodeType, ResourceName, AdminState, 
208                                           OpState, AvailStatus, StandbyStatus)
209         
210             siteManager setAdminState { -s <site> | -r <resourceName> } <new-state> :
211                 update admin state on selected nodes
212         
213             siteManager lock { -s <site> | -r <resourceName> } :
214                 lock selected nodes
215         
216             siteManager unlock { -s <site> | -r <resourceName> } :
217                 unlock selected nodes
218         
219 Note that the 'siteManager' script assumes that the script, 
220 'site-manager-${project.version}.jar' file and 'siteManager.properties' file
221 are all in the same directory. If the files are separated, the 'siteManager'
222 script will need to be modified so it can locate the jar and properties files.
223
224
225 Properties
226 ----------
227
228 The feature-state-mangement.properties file controls the function of the State Management Feature.  In general, the properties have adequate descriptions in the file. Parameters which must be replaced prior to usage are indicated thus: ${{parameter to be replaced}}.
229
230     .. code-block:: bash
231        :caption: feature-state-mangement.properties 
232
233         # DB properties
234         javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
235         javax.persistence.jdbc.url=jdbc:mariadb://${{SQL_HOST}}:3306/statemanagement
236         javax.persistence.jdbc.user=${{SQL_USER}}
237         javax.persistence.jdbc.password=${{SQL_PASSWORD}}
238         
239         # DroolsPDPIntegrityMonitor Properties
240         # Test interface host and port defaults may be overwritten here
241         http.server.services.TEST.host=0.0.0.0
242         http.server.services.TEST.port=9981
243         #These properties will default to the following if no other values are provided:
244         # http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
245         # http.server.services.TEST.managed=false
246         # http.server.services.TEST.swagger=true
247         
248         #IntegrityMonitor Properties
249         
250         # Must be unique across the system
251         resource.name=pdp1
252         # Name of the site in which this node is hosted 
253         site_name=site1
254         # Forward Progress Monitor update interval seconds
255         fp_monitor_interval=30
256         # Failed counter threshold before failover 
257         failed_counter_threshold=3
258         # Interval between test transactions when no traffic seconds
259         test_trans_interval=10
260         # Interval between writes of the FPC to the DB seconds 
261         write_fpc_interval=5
262         # Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error! 
263         node_type=pdp_drools
264         # Dependency groups are groups of resources upon which a node operational state is dependent upon. 
265         # Each group is a comma-separated list of resource names and groups are separated by a semicolon.  For example:
266         # dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
267         dependency_groups=
268         # When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
269         # The default false is to use state checks for health.
270         test_via_jmx=true
271         # This is the max number of seconds beyond which a non incrementing FPC is considered a failure
272         max_fpc_update_interval=120
273         # Run the state audit every 60 seconds (60000 ms).  The state audit finds stale DB entries in the 
274         # forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity 
275         # table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
276         # A value of <= 0 will turn off the state audit.
277         state_audit_interval_ms=60000
278         # The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the 
279         # DB statemanagemententity table. It only refreshes the DB state entry for the local node.  That is, it does not
280         # refresh the state of any other nodes.  A value <= 0 will turn the audit off. Any other value will override 
281         # the default of 600000 ms.
282         refresh_state_audit_interval_ms=600000
283         
284         
285         # Repository audit properties
286         # Assume it's the releaseRepository that needs to be audited,
287         # because that's the one BRMGW will publish to.
288         repository.audit.id=${{releaseRepositoryID}}
289         repository.audit.url=${{releaseRepositoryUrl}}
290         repository.audit.username=${{repositoryUsername}}
291         repository.audit.password=${{repositoryPassword}}
292         repository2.audit.id=${{releaseRepository2ID}}
293         repository2.audit.url=${{releaseRepository2Url}}
294         repository2.audit.username=${{repositoryUsername2}}
295         repository2.audit.password=${{repositoryPassword2}}
296         
297         # Repository Audit Properties
298         # Flag to control the execution of the subsystemTest for the Nexus Maven repository
299         repository.audit.is.active=false
300         repository.audit.ignore.errors=true
301         repository.audit.interval_sec=86400
302         repository.audit.failure.threshold=3
303         
304         # DB Audit Properties
305         # Flag to control the execution of the subsystemTest for the Database
306         db.audit.is.active=false
307
308
309 End of Document
310
311 .. SSNote: Wiki page ref. https://wiki.onap.org/display/DW/Feature+State+Management
312
313