<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17987">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_queue: load queues and members from Realtime when needed<br><br>There are a lot of Queue AMI actions and Queue applications<br>which do not load queue and queue members from Realtime.<br><br>AMI actions<br>QueuePause - if queue not in memory - response "Interface not found".<br>QueueStatus/QueueSummary - if queue not in memory - empty response.<br><br>Applications:<br>PauseQueueMember - if queue not in memory<br> Attempt to pause interface %s, not found<br>UnpauseQueueMember - if queue not in memory<br> Attempt to unpause interface xxxxx, not found<br><br>This patch adds a new function load_realtime_queues<br>which loads queue and queue members for desired queue<br>or all queues and all members if param 'queuename' is NULL or empty.<br>Calls the function load_realtime_queues when needed.<br><br>Also this patch fixes leak of ast_config in function set_member_value.<br><br>Also this patch fixes incorrect LOG_WARNING when pausing/unpausing<br>already paused/unpaused member.<br>The function ast_update_realtime returns 0 when no record modified.<br>So 0 is not an error to warn about.<br><br>ASTERISK-29873 #close<br>ASTERISK-18416 #close<br>ASTERISK-27597 #close<br><br>Change-Id: I554ee0eebde93bd8f49df7f84b74acb21edcb99c<br>---<br>M apps/app_queue.c<br>A doc/CHANGES-staging/load_realtime_queues.txt<br>2 files changed, 54 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_queue.c b/apps/app_queue.c</span><br><span>index 9bd0537..8ec98e2 100644</span><br><span>--- a/apps/app_queue.c</span><br><span>+++ b/apps/app_queue.c</span><br><span>@@ -3899,6 +3899,40 @@</span><br><span> return q;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Load queues and members from realtime.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param queuename - name of the desired queue to load or empty if need to load all queues</span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+static void load_realtime_queues(const char *queuename)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_config *cfg = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *category = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *name = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct call_queue *q = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_check_realtime("queues")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(queuename)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((category = ast_category_browse(cfg, category))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ name = ast_variable_retrieve(cfg, category, "name");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(name) && (q = find_load_queue_rt_friendly(name))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ queue_unref(q);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_config_destroy(cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((q = find_load_queue_rt_friendly(queuename))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ queue_unref(q);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int update_realtime_member_field(struct member *mem, const char *queue_name, const char *field, const char *value)</span><br><span> {</span><br><span> int ret = -1;</span><br><span>@@ -3907,7 +3941,7 @@</span><br><span> return ret;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) >= 0) {</span><br><span> ret = 0;</span><br><span> }</span><br><span> </span><br><span>@@ -7663,6 +7697,10 @@</span><br><span> struct call_queue *q;</span><br><span> struct ao2_iterator queue_iter;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_check_realtime("queues")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ load_realtime_queues(queuename);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> queue_iter = ao2_iterator_init(queues, 0);</span><br><span> while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) {</span><br><span> ao2_lock(q);</span><br><span>@@ -7834,6 +7872,8 @@</span><br><span> queue_unref(q);</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_config_destroy(queue_config);</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -10178,6 +10218,10 @@</span><br><span> struct ao2_iterator queue_iter;</span><br><span> struct ao2_iterator mem_iter;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_check_realtime("queues")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ load_realtime_queues(queuefilter);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> astman_send_listack(s, m, "Queue summary will follow", "start");</span><br><span> time(&now);</span><br><span> idText[0] = '\0';</span><br><span>@@ -10256,6 +10300,10 @@</span><br><span> struct ao2_iterator queue_iter;</span><br><span> struct ao2_iterator mem_iter;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_check_realtime("queues")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ load_realtime_queues(queuefilter);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> astman_send_listack(s, m, "Queue status will follow", "start");</span><br><span> time(&now);</span><br><span> idText[0] = '\0';</span><br><span>diff --git a/doc/CHANGES-staging/load_realtime_queues.txt b/doc/CHANGES-staging/load_realtime_queues.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..68a4a8b</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/load_realtime_queues.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: app_queue</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Load queues and members from Realtime for</span><br><span style="color: hsl(120, 100%, 40%);">+AMI actions: QueuePause, QueueStatus and QueueSummary,</span><br><span style="color: hsl(120, 100%, 40%);">+Applications: PauseQueueMember and UnpauseQueueMember.</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17987">change 17987</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17987"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I554ee0eebde93bd8f49df7f84b74acb21edcb99c </div>
<div style="display:none"> Gerrit-Change-Number: 17987 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>