#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "ais.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
Go to the source code of this file.
Functions | |
static char * | ais_clm_show_members (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
int | ast_ais_clm_load_module (void) |
int | ast_ais_clm_unload_module (void) |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 369001 $") | |
static void | clm_node_get_cb (SaInvocationT invocation, const SaClmClusterNodeT *cluster_node, SaAisErrorT error) |
static void | clm_track_cb (const SaClmClusterNotificationBufferT *notif_buffer, SaUint32T num_members, SaAisErrorT error) |
Variables | |
static struct ast_cli_entry | ais_cli [] |
static const SaClmCallbacksT | clm_callbacks |
SaClmHandleT | clm_handle |
static SaAisErrorT | clm_init_res |
Definition in file clm.c.
static char* ais_clm_show_members | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Definition at line 94 of file clm.c.
References ast_cli_args::argc, ast_cli_entry::args, ARRAY_LEN, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, clm_handle, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
00095 { 00096 int i; 00097 SaClmClusterNotificationBufferT buf; 00098 SaClmClusterNotificationT notif[64]; 00099 SaAisErrorT ais_res; 00100 00101 switch (cmd) { 00102 case CLI_INIT: 00103 e->command = "ais clm show members"; 00104 e->usage = 00105 "Usage: ais clm show members\n" 00106 " List members of the cluster using the CLM (Cluster Membership) service.\n"; 00107 return NULL; 00108 00109 case CLI_GENERATE: 00110 return NULL; /* no completion */ 00111 } 00112 00113 if (a->argc != e->args) 00114 return CLI_SHOWUSAGE; 00115 00116 buf.notification = notif; 00117 buf.numberOfItems = ARRAY_LEN(notif); 00118 00119 ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CURRENT, &buf); 00120 if (ais_res != SA_AIS_OK) { 00121 ast_cli(a->fd, "Error retrieving current cluster members.\n"); 00122 return CLI_FAILURE; 00123 } 00124 00125 ast_cli(a->fd, "\n" 00126 "=============================================================\n" 00127 "=== Cluster Members =========================================\n" 00128 "=============================================================\n" 00129 "===\n"); 00130 00131 for (i = 0; i < buf.numberOfItems; i++) { 00132 SaClmClusterNodeT *node = &buf.notification[i].clusterNode; 00133 00134 ast_cli(a->fd, "=== ---------------------------------------------------------\n" 00135 "=== Node Name: %s\n" 00136 "=== ==> ID: 0x%x\n" 00137 "=== ==> Address: %s\n" 00138 "=== ==> Member: %s\n", 00139 (char *) node->nodeName.value, (int) node->nodeId, 00140 (char *) node->nodeAddress.value, 00141 node->member ? "Yes" : "No"); 00142 00143 ast_cli(a->fd, "=== ---------------------------------------------------------\n" 00144 "===\n"); 00145 } 00146 00147 ast_cli(a->fd, "=============================================================\n" 00148 "\n"); 00149 00150 return CLI_SUCCESS; 00151 }
int ast_ais_clm_load_module | ( | void | ) |
Definition at line 157 of file clm.c.
References ais_cli, ais_err2str(), ais_version, ARRAY_LEN, ast_cli_register_multiple(), ast_log(), clm_callbacks, clm_handle, clm_init_res, and LOG_ERROR.
Referenced by load_module().
00158 { 00159 SaAisErrorT ais_res; 00160 00161 clm_init_res = saClmInitialize(&clm_handle, &clm_callbacks, &ais_version); 00162 if (clm_init_res != SA_AIS_OK) { 00163 ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n", 00164 ais_err2str(clm_init_res)); 00165 return -1; 00166 } 00167 00168 ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CHANGES, NULL); 00169 if (ais_res != SA_AIS_OK) { 00170 ast_log(LOG_ERROR, "Error starting tracking of cluster membership changes.\n"); 00171 } 00172 00173 ast_cli_register_multiple(ais_cli, ARRAY_LEN(ais_cli)); 00174 00175 return 0; 00176 }
int ast_ais_clm_unload_module | ( | void | ) |
Definition at line 178 of file clm.c.
References ais_cli, ais_err2str(), ARRAY_LEN, ast_cli_unregister_multiple(), ast_log(), clm_handle, clm_init_res, and LOG_ERROR.
Referenced by load_module(), and unload_module().
00179 { 00180 SaAisErrorT ais_res; 00181 00182 if (clm_init_res != SA_AIS_OK) { 00183 return 0; 00184 } 00185 00186 ast_cli_unregister_multiple(ais_cli, ARRAY_LEN(ais_cli)); 00187 00188 ais_res = saClmFinalize(clm_handle); 00189 if (ais_res != SA_AIS_OK) { 00190 ast_log(LOG_ERROR, "Problem stopping cluster membership service: %s\n", 00191 ais_err2str(ais_res)); 00192 return -1; 00193 } 00194 00195 return 0; 00196 }
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 369001 $" | ||||
) |
static void clm_node_get_cb | ( | SaInvocationT | invocation, | |
const SaClmClusterNodeT * | cluster_node, | |||
SaAisErrorT | error | |||
) | [static] |
static void clm_track_cb | ( | const SaClmClusterNotificationBufferT * | notif_buffer, | |
SaUint32T | num_members, | |||
SaAisErrorT | error | |||
) | [static] |
Definition at line 71 of file clm.c.
References ast_debug.
00073 { 00074 unsigned int i; 00075 unsigned int node_joined = 0; 00076 00077 ast_debug(1, "Cluster membership changed. Number of members: %u\n", num_members); 00078 00079 for (i = 0; i < notif_buffer->numberOfItems; i++) { 00080 SaClmClusterNotificationT *notif = notif_buffer->notification + i; 00081 00082 if (notif->clusterChange == SA_CLM_NODE_JOINED) { 00083 node_joined = 1; 00084 break; 00085 } 00086 } 00087 00088 if (node_joined) { 00089 ast_debug(1, "A node has joined the cluster, dumping event cache.\n"); 00090 ast_ais_cmd(AST_AIS_CMD_MEMBERSHIP_CHANGED); 00091 } 00092 }
struct ast_cli_entry ais_cli[] [static] |
Initial value:
{ { .handler = ais_clm_show_members , .summary = "List current members of the cluster" ,__VA_ARGS__ }, }
Definition at line 153 of file clm.c.
Referenced by ast_ais_clm_load_module(), ast_ais_clm_unload_module(), and ast_ais_evt_load_module().
const SaClmCallbacksT clm_callbacks [static] |
Initial value:
{ .saClmClusterNodeGetCallback = clm_node_get_cb, .saClmClusterTrackCallback = clm_track_cb, }
Definition at line 60 of file clm.c.
Referenced by ast_ais_clm_load_module().
SaClmHandleT clm_handle |
Definition at line 52 of file clm.c.
Referenced by ais_clm_show_members(), ast_ais_clm_load_module(), ast_ais_clm_unload_module(), ast_event_cb(), and dispatch_thread_handler().
SaAisErrorT clm_init_res [static] |
Definition at line 53 of file clm.c.
Referenced by ast_ais_clm_load_module(), and ast_ais_clm_unload_module().