Wed Jan 8 2020 09:50:10

Asterisk developer's documentation


clm.c File Reference

Usage of the SAForum AIS (Application Interface Specification) More...

#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
 

Detailed Description

Usage of the SAForum AIS (Application Interface Specification)

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

This file contains the code specific to the use of the CLM (Cluster Membership) Service.

Definition in file clm.c.

Function Documentation

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.

95 {
96  int i;
97  SaClmClusterNotificationBufferT buf;
98  SaClmClusterNotificationT notif[64];
99  SaAisErrorT ais_res;
100 
101  switch (cmd) {
102  case CLI_INIT:
103  e->command = "ais clm show members";
104  e->usage =
105  "Usage: ais clm show members\n"
106  " List members of the cluster using the CLM (Cluster Membership) service.\n";
107  return NULL;
108 
109  case CLI_GENERATE:
110  return NULL; /* no completion */
111  }
112 
113  if (a->argc != e->args)
114  return CLI_SHOWUSAGE;
115 
116  buf.notification = notif;
117  buf.numberOfItems = ARRAY_LEN(notif);
118 
119  ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CURRENT, &buf);
120  if (ais_res != SA_AIS_OK) {
121  ast_cli(a->fd, "Error retrieving current cluster members.\n");
122  return CLI_FAILURE;
123  }
124 
125  ast_cli(a->fd, "\n"
126  "=============================================================\n"
127  "=== Cluster Members =========================================\n"
128  "=============================================================\n"
129  "===\n");
130 
131  for (i = 0; i < buf.numberOfItems; i++) {
132  SaClmClusterNodeT *node = &buf.notification[i].clusterNode;
133 
134  ast_cli(a->fd, "=== ---------------------------------------------------------\n"
135  "=== Node Name: %s\n"
136  "=== ==> ID: 0x%x\n"
137  "=== ==> Address: %s\n"
138  "=== ==> Member: %s\n",
139  (char *) node->nodeName.value, (int) node->nodeId,
140  (char *) node->nodeAddress.value,
141  node->member ? "Yes" : "No");
142 
143  ast_cli(a->fd, "=== ---------------------------------------------------------\n"
144  "===\n");
145  }
146 
147  ast_cli(a->fd, "=============================================================\n"
148  "\n");
149 
150  return CLI_SUCCESS;
151 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
const int fd
Definition: cli.h:153
#define CLI_SHOWUSAGE
Definition: cli.h:44
SaClmHandleT clm_handle
Definition: clm.c:52
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
int ast_ais_clm_load_module ( void  )

Definition at line 157 of file clm.c.

References 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().

158 {
159  SaAisErrorT ais_res;
160 
161  clm_init_res = saClmInitialize(&clm_handle, &clm_callbacks, &ais_version);
162  if (clm_init_res != SA_AIS_OK) {
163  ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n",
165  return -1;
166  }
167 
168  ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CHANGES, NULL);
169  if (ais_res != SA_AIS_OK) {
170  ast_log(LOG_ERROR, "Error starting tracking of cluster membership changes.\n");
171  }
172 
174 
175  return 0;
176 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const SaClmCallbacksT clm_callbacks
Definition: clm.c:60
SaVersionT ais_version
Definition: res_ais.c:70
static SaAisErrorT clm_init_res
Definition: clm.c:53
#define LOG_ERROR
Definition: logger.h:155
SaClmHandleT clm_handle
Definition: clm.c:52
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
const char * ais_err2str(SaAisErrorT error)
Definition: res_ais.c:105
static struct ast_cli_entry ais_cli[]
Definition: clm.c:153
int ast_ais_clm_unload_module ( void  )

Definition at line 178 of file clm.c.

References 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().

179 {
180  SaAisErrorT ais_res;
181 
182  if (clm_init_res != SA_AIS_OK) {
183  return 0;
184  }
185 
187 
188  ais_res = saClmFinalize(clm_handle);
189  if (ais_res != SA_AIS_OK) {
190  ast_log(LOG_ERROR, "Problem stopping cluster membership service: %s\n",
191  ais_err2str(ais_res));
192  return -1;
193  }
194 
195  return 0;
196 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
static SaAisErrorT clm_init_res
Definition: clm.c:53
#define LOG_ERROR
Definition: logger.h:155
SaClmHandleT clm_handle
Definition: clm.c:52
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
const char * ais_err2str(SaAisErrorT error)
Definition: res_ais.c:105
static struct ast_cli_entry ais_cli[]
Definition: clm.c:153
ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 369001 $"   
)
static void clm_node_get_cb ( SaInvocationT  invocation,
const SaClmClusterNodeT *  cluster_node,
SaAisErrorT  error 
)
static

Definition at line 65 of file clm.c.

67 {
68 
69 }
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_AIS_CMD_MEMBERSHIP_CHANGED, and ast_debug.

73 {
74  unsigned int i;
75  unsigned int node_joined = 0;
76 
77  ast_debug(1, "Cluster membership changed. Number of members: %u\n", num_members);
78 
79  for (i = 0; i < notif_buffer->numberOfItems; i++) {
80  SaClmClusterNotificationT *notif = notif_buffer->notification + i;
81 
82  if (notif->clusterChange == SA_CLM_NODE_JOINED) {
83  node_joined = 1;
84  break;
85  }
86  }
87 
88  if (node_joined) {
89  ast_debug(1, "A node has joined the cluster, dumping event cache.\n");
91  }
92 }
ast_ais_cmd
Definition: ais.h:50
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236

Variable Documentation

struct ast_cli_entry ais_cli[]
static
Initial value:
= {
AST_CLI_DEFINE(ais_clm_show_members, "List current members of the cluster"),
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * ais_clm_show_members(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: clm.c:94

Definition at line 153 of file clm.c.

const SaClmCallbacksT clm_callbacks
static
Initial value:
= {
.saClmClusterNodeGetCallback = clm_node_get_cb,
.saClmClusterTrackCallback = clm_track_cb,
}
static void clm_track_cb(const SaClmClusterNotificationBufferT *notif_buffer, SaUint32T num_members, SaAisErrorT error)
Definition: clm.c:71
static void clm_node_get_cb(SaInvocationT invocation, const SaClmClusterNodeT *cluster_node, SaAisErrorT error)
Definition: clm.c:65

Definition at line 60 of file clm.c.

Referenced by ast_ais_clm_load_module().

SaClmHandleT clm_handle
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().