Merge "Update installation for R4"
[dcaegen2.git] / docs / sections / services / heartbeat-ms / design.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.\r
2 .. http://creativecommons.org/licenses/by/4.0\r
3 \r
4 Design\r
5 ======\r
6 \r
7 There are 4 processes created as below\r
8 \r
9 Main process\r
10 ------------\r
11  \r
12 This is the initial process which does the following.\r
13 \r
14 - Download CBS configuration and update the vnf_table_1\r
15 - Spawns HB worker process, DB Monitoring process and CBS polling\r
16   process (if required)\r
17 - Periodically update the hb_common table\r
18 \r
19 HB worker process\r
20 -----------------\r
21 \r
22 This process is created by main process and does the following.\r
23 \r
24 - It waits on the HB Json event message from DMaaP message router\r
25 - It receives the HB Json message and retrieves sourceName,\r
26   lastEpochTime, eventName in the incoming message\r
27 - It checks for the received eventName against the eventName in\r
28   vnf_table_1. If eventName is not matched, then it discards the\r
29   message.\r
30 - It checks for the received sourceName in the vnf_table_2. If the\r
31   sourceName is already there in vnf_table_2, then it updates the\r
32   received HB Json message in vnf_table_2 against that sourceName. If\r
33   the sourceName is not there in vnf_table_2, then it adds an entry in\r
34   vnf_table_2 for that eventName and increments the sourceName count in\r
35   vnf_table_1\r
36 \r
37 DB Monitoring process\r
38 ---------------------\r
39 \r
40 This process is created by main process and does the following.\r
41 \r
42 - The DB monitoring process scans through each entry of vnf_table_1 and\r
43   looks at the corresponding vnf_table_2 and checks the condition for\r
44   Control Loop event is met or not\r
45 - If it finds that the multiple consecutive HB are missed, it raises\r
46   the Control Loop event.\r
47 - It also clears the control loop event by looking at recently received\r
48   HB message.\r
49 - Because of reconfiguration procedure, some of the existing entries in\r
50   vnf_table_1 may become invalid. DB Monitoring process would clean the\r
51   DB by looking at validity flag maintained in each vnf_table_1 table\r
52   entry. If not valid, it removes the entry in vnf_table_1 and also\r
53   removes the corresponding entries of vnf_table_2.\r
54 \r
55 CBS polling process\r
56 -------------------\r
57 \r
58 If the local configuration file (config/hbproperties.yaml) indicates\r
59 that CBS polling is required, then main process would create the CBS \r
60 polling process. It does the following.\r
61 \r
62 - It takes the CBS polling interval from the configuration file.\r
63 \r
64 - For every CBS polling interval, it sets the hb_common with state as\r
65   reconfiguration to indicate the main process to download CBS\r
66   configuration\r
67 \r
68 CBS configuration download support\r
69 ----------------------------------\r
70 \r
71 Apart from the above, a function/method is provided to Docker container\r
72 that would download the CBS configuration whenever the configuration\r
73 changes. This method/function would read hb_common state and change the\r
74 state to reconfiguration.\r
75 \r
76 Heartbeat Microserice Multi instance support\r
77 --------------------------------------------\r
78 \r
79 In order to work smoothly in an environment having multiple HB micro\r
80 services instances, processes would work differently as mentioned below.\r
81 \r
82 **Main Process:**\r
83 \r
84     Active Instance:\r
85      - Download CBS configuration and process it\r
86      - Spawns processes\r
87      - Periodically update hb_common with last accessed time to indicate that active instance is Alive.\r
88          \r
89     Inactive Instance:\r
90         - Spawns processes\r
91         - Constantly check hb_common entry for last accessed time\r
92         - If the last accessed time is more than a minute or so, then it assumes the role of active instance \r
93     \r
94 **HB worker process:** Both active and inactive instance behaves the sames as metnioned in the Design section.\r
95 \r
96 **DB Monitoring process:** Both active periodically checks its process ID/hostname with hb_common data to know whether it is an active instance or not. If inactive instance it does nothing. If active instance, it behaves as mentioned in design section.\r
97 \r
98 **CBS Polling process:** Periodically checks its process ID/hostname with hb_common data to know whether it is an active instance or not. If inactive instance it does nothing. If active instance, it behaves as mentioned in design section.\r
99 \r
100 Handling of some of the failure scenarios\r
101 -----------------------------------------\r
102 \r
103 Failure to download the configuration from CBS – In this case, local\r
104 configuration file etc/config.json is considered as the configuration\r
105 file and vnf_table_1 is updated accordingly.\r
106 \r
107 The Reconfiguration procedure is as below\r
108 -----------------------------------------\r
109 \r
110 - If the state is Reconfiguration, then HB worker process, DB\r
111   monitoring process and CBS polling process would wait for\r
112   reconfiguration to complete.\r
113 - Set each entry as invalid by using validity flag in vnf_table_1\r
114 - Download the json file from CBS.\r
115 - Set the validity flag to indicate to valid when an entry is updated.\r
116 \r
117 Postgres Database\r
118 -----------------\r
119 \r
120 There are 3 tables maintained.\r
121 \r
122 **Vnf_table_1 table:** \r
123 This is table is indexed by eventName. Each entry\r
124 has following parameters in it.\r
125 \r
126 - eventName\r
127 - Configured heartbeat Missed Count\r
128 - Configured Heartbeat Interval\r
129 - Number of SourceName having same eventName\r
130 - Validity flag that indicates VNF entry is valid or not\r
131 - It also has following parameter related to Control loop event\r
132    - policyVersion\r
133    - policyName\r
134    - policyScope\r
135    - target_type\r
136    - target\r
137    - closedLoopControlName\r
138    - version\r
139 \r
140 **Vnf_table_2 table:** \r
141 For each sourceName there would be an entry in vnf_table_2. \r
142 This is indexed by eventName and SourceName. Each entry has\r
143 below parameters\r
144 \r
145 - SourceName\r
146 - Last received heartbeat epoch time\r
147 - Control loop event raised flag. 0 indicates not raised, 1 indicates\r
148   CL event raised\r
149 \r
150 **hb_common table:** \r
151 This is a single entry table.\r
152 \r
153 - The configuration status which would have one of the below.\r
154    - **RECONFIGURATION** – indicates CBS configuration processing is in\r
155       progress.\r
156    - **RUNNING** – CBS configuration is completed and ready to process HB\r
157       event and send CL event.\r
158 - The process ID – This indicates the main process ID of the active HB\r
159   instance which is responsible to take care of reconfiguration\r
160 - The source Name – It has 2 parts, hostname and service name. The\r
161   hostname is the Docker container ID. The service name is the\r
162   environment variable set for SERVICE_NAME\r
163 - The last accessed time – The time last accessed by the main process\r
164   having the above process ID.\r