Browse code

dmq: Add an RPC interface to query the nodes in the cluster

Alex Hermann authored on 01/09/2014 15:54:38
Showing 1 changed files
... ...
@@ -40,6 +40,7 @@
40 40
 #include "../../lib/kmi/mi.h"
41 41
 #include "../../hashes.h"
42 42
 #include "../../mod_fix.h"
43
+#include "../../rpc_lookup.h"
43 44
 
44 45
 #include "dmq.h"
45 46
 #include "dmq_funcs.h"
... ...
@@ -112,6 +113,8 @@ static mi_export_t mi_cmds[] = {
112 113
 	{0, 0, 0, 0, 0}
113 114
 };
114 115
 
116
+static rpc_export_t rpc_methods[];
117
+
115 118
 /** module exports */
116 119
 struct module_exports exports = {
117 120
 	"dmq",				/* module name */
... ...
@@ -195,6 +198,11 @@ static int mod_init(void)
195 198
 		return -1;
196 199
 	}
197 200
 
201
+	if (rpc_register_array(rpc_methods)!=0) {
202
+		LM_ERR("failed to register RPC commands\n");
203
+		return -1;
204
+	}
205
+
198 206
 	/* register worker processes - add one because of the ping process */
199 207
 	register_procs(num_workers);
200 208
 	
... ...
@@ -325,3 +333,33 @@ static int bcast_dmq_fixup(void** param, int param_no)
325 333
         return fixup_spve_null(param, 1);
326 334
 }
327 335
 
336
+static void dmq_rpc_list_nodes(rpc_t *rpc, void *c)
337
+{
338
+	void *h;
339
+	dmq_node_t* cur = node_list->nodes;
340
+
341
+	while(cur) {
342
+		if (rpc->add(c, "{", &h) < 0) goto error;
343
+		if (rpc->struct_add(h, "SSddd",
344
+			"host", &cur->uri.host,
345
+			"port", &cur->uri.port,
346
+			"status", cur->status,
347
+			"last_notification", cur->last_notification,
348
+			"local", cur->local) < 0) goto error;
349
+		cur = cur->next;
350
+	}
351
+	return;
352
+error:
353
+	LM_ERR("Failed to add item to RPC response\n");
354
+	return;
355
+
356
+}
357
+
358
+static const char *dmq_rpc_list_nodes_doc[2] = {
359
+	"Print all nodes", 0
360
+};
361
+
362
+static rpc_export_t rpc_methods[] = {
363
+	{"dmq.list_nodes", dmq_rpc_list_nodes, dmq_rpc_list_nodes_doc, RET_ARRAY},
364
+	{0, 0, 0, 0}
365
+};