Browse code

dmq: added dmq.remove rpc command

- make it possible to remove a node that still is reachable by old
address without having to shut dowm all nodes

Daniel-Constantin Mierla authored on 21/04/2021 17:09:21
Showing 3 changed files
... ...
@@ -430,8 +430,29 @@ error:
430 430
 
431 431
 static const char *dmq_rpc_list_nodes_doc[2] = {"Print all nodes", 0};
432 432
 
433
+void rpc_dmq_remove(rpc_t* rpc, void* ctx)
434
+{
435
+	str taddr = STR_NULL;
436
+
437
+	if (rpc->scan(ctx, ".S", &taddr) < 1) {
438
+		rpc->fault(ctx, 500, "Invalid Parameters");
439
+		return;
440
+	}
441
+	if(dmq_node_del_by_uri(dmq_node_list, &taddr)<0) {
442
+		rpc->fault(ctx, 500, "Failure");
443
+		return;
444
+	}
445
+}
446
+
447
+static const char* rpc_dmq_remove_doc[3] = {
448
+	"Remove a DMQ node",
449
+	"address - the DMQ node address",
450
+	0
451
+};
452
+
433 453
 static rpc_export_t rpc_methods[] = {
434 454
 	{"dmq.list_nodes", dmq_rpc_list_nodes, dmq_rpc_list_nodes_doc, RET_ARRAY},
455
+	{"dmq.remove",     rpc_dmq_remove,     rpc_dmq_remove_doc, 0},
435 456
 	{0, 0, 0, 0}
436 457
 };
437 458
 
... ...
@@ -350,6 +350,22 @@ int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
350 350
 	return 0;
351 351
 }
352 352
 
353
+/**
354
+ * @brief delete dmq node by uri
355
+ */
356
+int dmq_node_del_by_uri(dmq_node_list_t *list, str *suri)
357
+{
358
+	dmq_node_t dnode;
359
+
360
+	memset(&dnode, 0, sizeof(dmq_node_t));
361
+	if(parse_uri(suri->s, suri->len, &dnode.uri) < 0) {
362
+		LM_ERR("error parsing uri [%.*s]\n", suri->len, suri->s);
363
+		return -1;
364
+	}
365
+
366
+	return del_dmq_node(list, &dnode);
367
+}
368
+
353 369
 /**
354 370
  * @brief add dmq node
355 371
  */
... ...
@@ -69,6 +69,7 @@ dmq_node_t *find_dmq_node(dmq_node_list_t *list, dmq_node_t *node);
69 69
 dmq_node_t *find_dmq_node_uri(dmq_node_list_t *list, str *uri);
70 70
 dmq_node_t *find_dmq_node_uri2(str *uri);
71 71
 int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node);
72
+int dmq_node_del_by_uri(dmq_node_list_t *list, str *suri);
72 73
 int cmp_dmq_node(dmq_node_t *node, dmq_node_t *cmpnode);
73 74
 int update_dmq_node_status(dmq_node_list_t *list, dmq_node_t *node, int status);
74 75
 dmq_node_t *shm_dup_node(dmq_node_t *node);