yumapro  20.10-12
YumaPro SDK
agt_yp_ha.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 - 2021, YumaWorks, Inc., All Rights Reserved.
3  *
4  * Unless required by applicable law or agreed to in writing,
5  * software distributed under the License is distributed on an
6  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7  * KIND, either express or implied. See the License for the
8  * specific language governing permissions and limitations
9  * under the License.
10  */
11 #ifdef WITH_YP_HA
12 #ifndef _H_agt_yp_ha
13 #define _H_agt_yp_ha
14 
15 /* FILE: agt_yp_ha.h
16 *********************************************************************
17 * *
18 * P U R P O S E *
19 * *
20 *********************************************************************/
21 
28 /*********************************************************************
29 * *
30 * C H A N G E H I S T O R Y *
31 * *
32 *********************************************************************
33 
34 date init comment
35 ----------------------------------------------------------------------
36 06-feb-16 abb Begun
37 */
38 
39 #include <xmlstring.h>
40 
41 #ifndef _H_agt
42 #include "agt.h"
43 #endif
44 
45 #ifndef _H_agt_cfg
46 #include "agt_cfg.h"
47 #endif
48 
49 #ifndef _H_status_enum
50 #include "status_enum.h"
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 
58 /* header only */
59 
60 
84 /********************************************************************
85 * *
86 * C O N S T A N T S *
87 * *
88 *********************************************************************/
89 
90 
91 /********************************************************************
92 * *
93 * T Y P E S *
94 * *
95 *********************************************************************/
96 
98 typedef enum yp_ha_state_t_ {
101 
104 
107 
110 
113 
116 
119 
122 
125 } yp_ha_state_t;
126 
127 
133 typedef struct yp_ha_server_t_ {
135  dlq_hdr_t qhdr;
136 
138  xmlChar *server_name;
139 
141  xmlChar *server_addr;
142 
144  uint16 server_port;
145 
147  struct yp_ha_subsys_t_ *subsys_cb;
148 
149 } yp_ha_server_t;
150 
151 
157 typedef struct yp_ha_service_t_ {
159  dlq_hdr_t ha_serverQ;
160 
162  yp_ha_server_t *my_server_cb;
163 
165  const xmlChar *ha_server_key;
166 
168  obj_template_t *yp_ha_obj;
169 
171  val_value_t *payload_val;
172 
174  yp_ha_state_t ha_state;
175 
177  boolean ha_enabled;
178 
180  boolean ha_init_done;
181 
183  struct yp_ha_active_t_ *active_cb;
184 
186  struct yp_ha_standby_t_ *standby_cb;
187 
188 } yp_ha_service_t;
189 
190 
191 /********************************************************************
192 * *
193 * F U N C T I O N S *
194 * *
195 *********************************************************************/
196 
205 extern void
206  agt_yp_ha_preinit (void);
207 
208 
214 extern status_t
215  agt_yp_ha_init (void);
216 
217 
226 extern status_t
227  agt_yp_ha_init2 (void);
228 
229 
235 extern void
236  agt_yp_ha_cleanup (void);
237 
238 
245 extern status_t
246  agt_yp_ha_add_server_cli (const xmlChar *valstr);
247 
248 
254 extern boolean
255  agt_yp_ha_mgmt_enabled (void);
256 
257 
263 extern status_t
264  agt_yp_ha_be_active (void);
265 
266 
272 extern status_t
273  agt_yp_ha_be_none (void);
274 
275 
282 extern status_t
283  agt_yp_ha_be_standby (const xmlChar *new_server_id);
284 
285 
291 extern agt_ha_role_t
292  agt_yp_ha_get_role (void);
293 
294 
300 extern const xmlChar *
302 
303 
309 extern yp_ha_service_t *
311 
312 
318 extern void
320 
321 
331 extern yp_ha_server_t *
332  agt_yp_ha_find_server (const xmlChar *server_name);
333 
334 
341 extern void
342  agt_yp_ha_config_update (rpc_msg_t *msg,
343  agt_cfg_transaction_t *txcb);
344 
345 
351 extern status_t
352  agt_yp_ha_nvstore (void);
353 
354 
361 extern boolean
362  agt_yp_ha_sil_disabled (void);
363 
364 
365 
376 extern void
377  agt_yp_ha_mod_event (const xmlChar *name,
378  const xmlChar *revision,
379  val_value_t *inputval,
380  boolean is_module,
381  boolean is_load);
382 
383 
393 extern status_t
395  const xmlChar **config_stamp);
396 
397 
401 #ifdef __cplusplus
402 } /* end extern 'C' */
403 #endif
404 
405 #endif /* _H_agt_yp_ha */
406 #endif // WITH_YP_HA
xml_strlen
uint32 xml_strlen(const xmlChar *str)
Get the String len for xmlChar.
Definition: xml_util.c:1406
HA_STATE_SHUTTING_DOWN
@ HA_STATE_SHUTTING_DOWN
shutting down HA service
Definition: agt_yp_ha.h:132
cfg.h
AGT_DEF_HA_PORT
#define AGT_DEF_HA_PORT
default –ha-port value
Definition: agt.h:337
agt_util.h
Utility Functions for NCX Server method routines.
tstamp.h
Timestamp utilities.
ncx_decode_num
status_t ncx_decode_num(const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum)
Handle some sort of number string.
Definition: ncx_num.c:1288
yp_ha_service_t_::active_cb
struct yp_ha_active_t_ * active_cb
active mode
Definition: agt_yp_ha.h:183
agt_yp_ha_be_active
status_t agt_yp_ha_be_active(void)
Put this server in YP-HA Active mode.
Definition: agt_yp_ha.c:567
yp_ha_server_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: agt_yp_ha.h:135
yp_ha_service_t_::my_server_cb
yp_ha_server_t * my_server_cb
HA control block.
Definition: agt_yp_ha.h:162
agt_yp_ha_preinit
void agt_yp_ha_preinit(void)
Pre-Initialize the YP-HA subsys handler.
Definition: agt_yp_ha.c:221
ERR_NCX_DEF_NOT_FOUND
@ ERR_NCX_DEF_NOT_FOUND
250
Definition: status_enum.h:289
log_error
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
AGT_YP_HA
#define AGT_YP_HA
YP-HA service name for YControl.
Definition: agt.h:418
val.h
Value Node Basic Support.
HA_STATE_BE_ACTIVE
@ HA_STATE_BE_ACTIVE
in process of becoming active server
Definition: agt_yp_ha.h:120
agt_yp_ha_find_server
yp_ha_server_t * agt_yp_ha_find_server(const xmlChar *server_name)
Find a server record.
Definition: agt_yp_ha.c:1070
status_enum.h
global error status code enumerations
HA_STATE_STANDBY
@ HA_STATE_STANDBY
standby server role
Definition: agt_yp_ha.h:129
agt_yp_ha_cleanup
void agt_yp_ha_cleanup(void)
Cleanup the YP-HA Module.
Definition: agt_yp_ha.c:443
log_debug3
void void void void void void void void void void void log_debug3(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG3 log entry.
ncx_num.h
NCX Module Library Number Utility Functions.
yp_ha_service_t_::payload_val
val_value_t * payload_val
payload_val for reuse and faster messages
Definition: agt_yp_ha.h:171
yp_ha_service_t_
YP-HA service instance.
Definition: agt_yp_ha.h:157
yp_ha_server_t_::server_port
uint16 server_port
peer TCP port number
Definition: agt_yp_ha.h:144
agt_yp_ha_mod_event
void agt_yp_ha_mod_event(const xmlChar *name, const xmlChar *revision, val_value_t *inputval, boolean is_module, boolean is_load)
Generate a module event.
Definition: agt_yp_ha.c:1254
agt_yp_ha_active_init
void agt_yp_ha_active_init(yp_ha_service_t *ha_serv)
Initialize the YP-HA Active module.
Definition: agt_yp_ha_active.c:2018
yp_ha_server_t_
For each CLI-configured ha-server there will be one entry entry the active and standby both need this...
Definition: agt_yp_ha.h:133
ncx_init_num
void ncx_init_num(ncx_num_t *num)
Init a ncx_num_t struct.
Definition: ncx_num.c:162
ERR_NCX_DUP_ENTRY
@ ERR_NCX_DUP_ENTRY
224
Definition: status_enum.h:263
op.h
NETCONF protocol operations.
ncxconst.h
Contains NCX constants.
agt_yp_ha_active_go
status_t agt_yp_ha_active_go(yp_ha_service_t *ha_serv)
Go into YP-HA Active server mode.
Definition: agt_yp_ha_active.c:1906
HA_STATE_BE_STANDBY
@ HA_STATE_BE_STANDBY
in process of becoming standby server
Definition: agt_yp_ha.h:126
HA_STATE_DISABLED
@ HA_STATE_DISABLED
HA disabled.
Definition: agt_yp_ha.h:111
AGT_HA_ROLE_ACTIVE
@ AGT_HA_ROLE_ACTIVE
HA active role.
Definition: agt.h:687
yp_ha_service_t_::ha_init_done
boolean ha_init_done
HA init done flag.
Definition: agt_yp_ha.h:180
log_debug2
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
AGT_HA_ROLE_STANDBY
@ AGT_HA_ROLE_STANDBY
HA standby role.
Definition: agt.h:686
agt_yp_ha_mgmt_enabled
boolean agt_yp_ha_mgmt_enabled(void)
Check if MGMT protocols disabled because YP-HA Standby mode.
Definition: agt_yp_ha.c:877
agt_yp_ha_nvstore
status_t agt_yp_ha_nvstore(void)
Do an <nvstore> in the active role.
Definition: agt_yp_ha.c:1184
val_any_whitespace
boolean val_any_whitespace(const xmlChar *str, uint32 len)
Check if a string has any whitespace chars.
Definition: val.c:11753
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
agt_yp_ha_standby_get_config_info
status_t agt_yp_ha_standby_get_config_info(yp_ha_service_t *ha_serv, ncx_transaction_id_t *config_id, const xmlChar **config_stamp)
Get the config ID and timestamp info.
Definition: agt_yp_ha_standby.c:1724
agt_yp_ha_init
status_t agt_yp_ha_init(void)
Initialize the YP-HA subsys handler (begin phase 2 init)
Definition: agt_yp_ha.c:247
agt_yp_ha_init2
status_t agt_yp_ha_init2(void)
Initialize the YP-HA shared state (phase 2 init, post external init).
Definition: agt_yp_ha.c:367
agt_yp_ha_standby.h
YumaPro High Availability module (YP-HA). HA Standby Mode.
xml_strndup
xmlChar * xml_strndup(const xmlChar *copyFrom, uint32 maxlen)
String duplicate for max N xmlChars.
Definition: xml_util.c:1663
log_debug4
void void void void void void void void void void void void void log_debug4(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG4 log entry.
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
yp_ha_service_t_::ha_state
yp_ha_state_t ha_state
current HA state
Definition: agt_yp_ha.h:174
agt_yp_ha_check_standby_io
void agt_yp_ha_check_standby_io(void)
Check if the YP-SA Standby mode needs to check for input.
Definition: agt_yp_ha.c:1023
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
ncx_valid_name
boolean ncx_valid_name(const xmlChar *str, uint32 len)
Check if an xmlChar string is a valid YANG identifier value.
Definition: ncx.c:7596
dlq_remove
void dlq_remove(void *nodeP)
remove the queue entry from its queue list entry MUST have been enqueued somehow before this function...
Definition: dlq.c:519
agt_yp_ha_standby_stop
void agt_yp_ha_standby_stop(yp_ha_service_t *ha_serv)
Exit YP-HA Standby server mode.
Definition: agt_yp_ha_standby.c:1583
val_util.h
Value Node Utilities.
agt_yp_ha_standby_setup
status_t agt_yp_ha_standby_setup(yp_ha_service_t *ha_serv, const xmlChar *new_server_id)
Setup the HA service standby_cb record for YP-HA Standby mode.
Definition: agt_yp_ha_standby.c:1616
ERR_NCX_INVALID_VALUE
@ ERR_NCX_INVALID_VALUE
258
Definition: status_enum.h:299
NCX_CFGID_STARTUP
@ NCX_CFGID_STARTUP
startup datastore
Definition: ncxtypes.h:386
NCX_BT_UINT16
@ NCX_BT_UINT16
uint16
Definition: ncxtypes.h:212
yp_ha_service_t_::ha_enabled
boolean ha_enabled
HA enabled flag.
Definition: agt_yp_ha.h:177
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
xml_strncmp
int xml_strncmp(const xmlChar *s1, const xmlChar *s2, uint32 maxlen)
String compare for xmlChar for at most 'maxlen' xmlChars.
Definition: xml_util.c:1824
yp_ha_state_t_
yp_ha_state_t_
YP-HA Shared State.
Definition: agt_yp_ha.h:98
ERR_INTERNAL_INIT_SEQ
@ ERR_INTERNAL_INIT_SEQ
007
Definition: status_enum.h:197
get_error_string
const char * get_error_string(status_t res)
Get the error message for a specific internal error.
Definition: status.c:239
agt_yp_ha_get_service_cb
yp_ha_service_t * agt_yp_ha_get_service_cb(void)
Get the YP-HA service control block for this server.
Definition: agt_yp_ha.c:1006
agt_yp_ha_standby_cleanup
void agt_yp_ha_standby_cleanup(yp_ha_service_t *ha_serv)
Cleanup the YP-HA Standby module.
Definition: agt_yp_ha_standby.c:1662
log_debug
void void void void void void void log_debug(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG log entry.
typ.h
Parameter Type Handler.
dlq_count
unsigned int dlq_count(const dlq_hdrT *listP)
get the number of queue entries in the listP queue list
Definition: dlq.c:994
NCX_CFGID_RUNNING
@ NCX_CFGID_RUNNING
running datastore (no value for not set!)
Definition: ncxtypes.h:384
yangconst.h
Contains YANG constants separated to prevent H file include loops.
yp_ha_service_t_::standby_cb
struct yp_ha_standby_t_ * standby_cb
standby mode
Definition: agt_yp_ha.h:186
agt_yp_ha_config_update
void agt_yp_ha_config_update(rpc_msg_t *msg, agt_cfg_transaction_t *txcb)
Do a config update in the active role.
Definition: agt_yp_ha.c:1095
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
agt.h
Multi-Protocol Network Management Server.
ERR_NCX_RESOURCE_DENIED
@ ERR_NCX_RESOURCE_DENIED
269
Definition: status_enum.h:310
agt_yp_ha_standby_init
void agt_yp_ha_standby_init(yp_ha_service_t *ha_serv)
Initialize the YP-HA Standby module.
Definition: agt_yp_ha_standby.c:1600
HA_STATE_WAIT_ROLE
@ HA_STATE_WAIT_ROLE
waiting for HA role
Definition: agt_yp_ha.h:117
agt_yp_ha_active_nvstore
status_t agt_yp_ha_active_nvstore(yp_ha_service_t *ha_serv)
Do an <nvstore> command to the standby servers.
Definition: agt_yp_ha_active.c:2096
yp_ha_service_t_::yp_ha_obj
obj_template_t * yp_ha_obj
YANG object template for service layer.
Definition: agt_yp_ha.h:168
agt_yp_ha_be_standby
status_t agt_yp_ha_be_standby(const xmlChar *new_server_id)
Put this server in YP-HA Standby mode.
Definition: agt_yp_ha.c:770
yp_ha_server_t_::server_name
xmlChar * server_name
service name
Definition: agt_yp_ha.h:138
agt_yp_ha_active_cleanup_server
void agt_yp_ha_active_cleanup_server(yp_ha_service_t *ha_serv, yp_ha_server_t *ha_server)
Cleanup the YP-HA Active Server subsystem record.
Definition: agt_yp_ha_active.c:2048
agt_yp_ha_get_role
agt_ha_role_t agt_yp_ha_get_role(void)
Get the YP-HA server role for this server.
Definition: agt_yp_ha.c:921
obj_find_child
obj_template_t * obj_find_child(obj_template_t *obj, const xmlChar *modname, const xmlChar *objname)
Find a child object with the specified Qname.
Definition: obj.c:6116
AGT_HA_ROLE_NONE
@ AGT_HA_ROLE_NONE
not set
Definition: agt.h:684
agt_yp_ha_add_server_cli
status_t agt_yp_ha_add_server_cli(const xmlChar *valstr)
Add an HA server entry from the –ha-server CLI parm.
Definition: agt_yp_ha.c:477
xml_strcmp
int xml_strcmp(const xmlChar *s1, const xmlChar *s2)
String compare for xmlChar.
Definition: xml_util.c:1746
ycontrol_msg_cmn.h
YControl Message Utilities.
LOGDEBUG4
#define LOGDEBUG4
Check if at least log-level=debug4.
Definition: log.h:302
log.h
NCX System Logging Manager.
AGT_HA_ROLE_NOT_SET
@ AGT_HA_ROLE_NOT_SET
HA role not set.
Definition: agt.h:685
LOGDEBUG
#define LOGDEBUG
Check if at least log-level=debug.
Definition: log.h:287
agt_yp_ha_active_setup
status_t agt_yp_ha_active_setup(yp_ha_service_t *ha_serv)
One time pre-init YP-HA Active mode.
Definition: agt_yp_ha_active.c:1880
rpc_err.h
NETCONF protocol standard error definitions.
ycontrol_check_io
status_t ycontrol_check_io(void)
Check for input/output.
Definition: ycontrol.c:820
agt_yp_ha_get_config_info
status_t agt_yp_ha_get_config_info(uint64 *config_id, const xmlChar **config_stamp)
Get the config ID and timestamp info.
Definition: agt_yp_ha.c:1294
agt_cfg.h
Manage Server configuration edit transactions.
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
agt_yp_ha_active_stop
void agt_yp_ha_active_stop(yp_ha_service_t *ha_serv)
Exit from YP-HA Active server mode.
Definition: agt_yp_ha_active.c:1981
agt_yp_ha_active_cleanup
void agt_yp_ha_active_cleanup(yp_ha_service_t *ha_serv)
Cleanup the YP-HA Active module.
Definition: agt_yp_ha_active.c:2032
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
agt_yp_ha_active_mod_event
void agt_yp_ha_active_mod_event(yp_ha_service_t *ha_serv, const xmlChar *name, const xmlChar *revision, val_value_t *inputval, boolean is_module, boolean is_load)
Generate a module event.
Definition: agt_yp_ha_active.c:2118
agt_get_profile
agt_profile_t * agt_get_profile(void)
Get the server profile struct.
Definition: agt.c:4118
agt_get_server_id
const xmlChar * agt_get_server_id(void)
Get the server-id string.
Definition: agt.c:4700
yp_ha_service_t_::ha_server_key
const xmlChar * ha_server_key
shared HA pool key
Definition: agt_yp_ha.h:165
agt_yp_ha_active.h
YumaPro High Availability module (YP-HA). HA Active Mode.
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
ncx.h
YANG module utility functions.
agt_yp_ha_active_config_update
status_t agt_yp_ha_active_config_update(yp_ha_service_t *ha_serv, rpc_msg_t *msg, agt_cfg_transaction_t *txcb)
Do a config update in the active role.
Definition: agt_yp_ha_active.c:2073
agt_yp_ha.h
YumaPro High Availability module (YP-HA)
obj.h
Data Object Support.
cfg_get_config_id
cfg_template_t * cfg_get_config_id(ncx_cfg_t cfgid)
Get the config struct from its ID.
Definition: cfg.c:1530
agt_yp_ha_get_role_state
const xmlChar * agt_yp_ha_get_role_state(void)
Get the YP-HA server role for this server as a string.
Definition: agt_yp_ha.c:961
ycontrol.h
YumaPro Subsystem Control Protocol.
agt_yp_ha_sil_disabled
boolean agt_yp_ha_sil_disabled(void)
Check if all hooks are enabled or disabled because of the YP-HA Standby mode.
Definition: agt_yp_ha.c:1221
agt_yp_ha_standby_check_cleanup
void agt_yp_ha_standby_check_cleanup(yp_ha_service_t *ha_serv)
Check if the cleanup of standby mode is needed.
Definition: agt_yp_ha_standby.c:1684
agt_ycontrol.h
Handle the YumaPro Control Protocol <ycontrol> (top-level) element.
agt_yp_ha_be_none
status_t agt_yp_ha_be_none(void)
Put this server in WAIT_ROLE state.
Definition: agt_yp_ha.c:671
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
yp_ha_server_t_::subsys_cb
struct yp_ha_subsys_t_ * subsys_cb
maintained only by the active server
Definition: agt_yp_ha.h:147
HA_STATE_NONE
@ HA_STATE_NONE
not set
Definition: agt_yp_ha.h:108
agt_timer.h
Handle timer services for the server.
agt_init2_done
boolean agt_init2_done(void)
Check if the init2 phase is complete.
Definition: agt.c:4983
yp_ha_service_t_::ha_serverQ
dlq_hdr_t ha_serverQ
common state is a Q of yp_ha_server_t
Definition: agt_yp_ha.h:159
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
HA_STATE_ERROR
@ HA_STATE_ERROR
HA error state.
Definition: agt_yp_ha.h:114
agt_ycontrol_get_obj
obj_template_t * agt_ycontrol_get_obj(void)
Get the ycontrol container object.
Definition: agt_ycontrol.c:1927
val_free_value
void val_free_value(val_value_t *val)
Scrub the memory in a val_value_t by freeing all the sub-fields and then freeing the entire struct it...
Definition: val.c:2842
status.h
Global error messages for status code enumerations.
dlq.h
dlq provides general double-linked list and queue support:
HA_STATE_ACTIVE
@ HA_STATE_ACTIVE
active server role
Definition: agt_yp_ha.h:123
yp_ha_server_t_::server_addr
xmlChar * server_addr
peer IP address or domain name
Definition: agt_yp_ha.h:141
agt_yp_ha_standby_go
status_t agt_yp_ha_standby_go(yp_ha_service_t *ha_serv)
Go into YP-HA Standby server mode.
Definition: agt_yp_ha_standby.c:1567
LOGDEBUG3
#define LOGDEBUG3
Check if at least log-level=debug3.
Definition: log.h:297
agt_yp_ha_active_get_config_info
status_t agt_yp_ha_active_get_config_info(yp_ha_service_t *ha_serv, ncx_transaction_id_t *config_id, const xmlChar **config_stamp)
Get the config ID and timestamp info.
Definition: agt_yp_ha_active.c:2164
ncx_transaction_id_t
uint64 ncx_transaction_id_t
transaction is scoped to single session write operation on a config
Definition: ncxtypes.h:548