<p>sungtae kim has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11080">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Added creation timestamp for the bridge<br><br>This small feature will help to checking the bridge's status to<br>figure out which bridge is in old/zombie or not. Also added<br>detail items for the 'bridge show *' cli to provide more detail<br>info. And added creation item to the ARI as well.<br><br>ASTERISK-28279<br><br>Change-Id: I460238c488eca4d216b9176576211cb03286e040<br>---<br>M include/asterisk/bridge.h<br>M include/asterisk/stasis_bridges.h<br>M main/bridge.c<br>M main/stasis_bridges.c<br>M res/ari/ari_model_validators.c<br>M res/ari/ari_model_validators.h<br>M rest-api/api-docs/bridges.json<br>7 files changed, 48 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/11080/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/bridge.h b/include/asterisk/bridge.h</span><br><span>index f4b1df8..dc8ebe5 100644</span><br><span>--- a/include/asterisk/bridge.h</span><br><span>+++ b/include/asterisk/bridge.h</span><br><span>@@ -358,6 +358,8 @@</span><br><span> </span><br><span>      /*! Type mapping used for media routing */</span><br><span>   struct ast_vector_int media_types;</span><br><span style="color: hsl(120, 100%, 40%);">+    /*! The time of bridge creation */</span><br><span style="color: hsl(120, 100%, 40%);">+    struct timeval creationtime;</span><br><span> };</span><br><span> </span><br><span> /*! \brief Bridge base class virtual method table. */</span><br><span>diff --git a/include/asterisk/stasis_bridges.h b/include/asterisk/stasis_bridges.h</span><br><span>index a455a5b..533c12e 100644</span><br><span>--- a/include/asterisk/stasis_bridges.h</span><br><span>+++ b/include/asterisk/stasis_bridges.h</span><br><span>@@ -62,6 +62,8 @@</span><br><span>         unsigned int num_active;</span><br><span>     /*! The video mode of the bridge */</span><br><span>  enum ast_bridge_video_mode_type video_mode;</span><br><span style="color: hsl(120, 100%, 40%);">+   /*! The time of bridge creation */</span><br><span style="color: hsl(120, 100%, 40%);">+    struct timeval creationtime;</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/main/bridge.c b/main/bridge.c</span><br><span>index d6e7a51..f3c34d1 100644</span><br><span>--- a/main/bridge.c</span><br><span>+++ b/main/bridge.c</span><br><span>@@ -847,6 +847,8 @@</span><br><span>                 }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ self->creationtime = ast_tvnow();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       return self;</span><br><span> }</span><br><span> </span><br><span>@@ -5102,8 +5104,8 @@</span><br><span> </span><br><span> static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-#define FORMAT_HDR "%-36s %5s %-15s %s\n"</span><br><span style="color: hsl(0, 100%, 40%);">-#define FORMAT_ROW "%-36s %5u %-15s %s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+#define FORMAT_HDR "%-36s %5s %-15s %-15s %s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+#define FORMAT_ROW "%-36s %5u %-15s %-15s %s\n"</span><br><span> </span><br><span>      RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup);</span><br><span>         struct ao2_iterator iter;</span><br><span>@@ -5126,17 +5128,21 @@</span><br><span>          return CLI_SUCCESS;</span><br><span>  }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   ast_cli(a->fd, FORMAT_HDR, "Bridge-ID", "Chans", "Type", "Technology");</span><br><span style="color: hsl(120, 100%, 40%);">+    ast_cli(a->fd, FORMAT_HDR, "Bridge-ID", "Chans", "Type", "Technology", "Duration");</span><br><span> </span><br><span>         iter = ao2_iterator_init(cached_bridges, 0);</span><br><span>         for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {</span><br><span>             struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+              char print_time[32];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, sizeof(print_time));</span><br><span> </span><br><span>             ast_cli(a->fd, FORMAT_ROW,</span><br><span>                        snapshot->uniqueid,</span><br><span>                       snapshot->num_channels,</span><br><span>                   S_OR(snapshot->subclass, "<unknown>"),</span><br><span style="color: hsl(0, 100%, 40%);">-                       S_OR(snapshot->technology, "<unknown>"));</span><br><span style="color: hsl(120, 100%, 40%);">+                  S_OR(snapshot->technology, "<unknown>"),</span><br><span style="color: hsl(120, 100%, 40%);">+                   print_time);</span><br><span>         }</span><br><span>    ao2_iterator_destroy(&iter);</span><br><span>     return CLI_SUCCESS;</span><br><span>@@ -5168,6 +5174,7 @@</span><br><span> {</span><br><span>     RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);</span><br><span>   struct ast_bridge_snapshot *snapshot;</span><br><span style="color: hsl(120, 100%, 40%);">+ char print_time[32];</span><br><span> </span><br><span>     switch (cmd) {</span><br><span>       case CLI_INIT:</span><br><span>@@ -5194,10 +5201,18 @@</span><br><span>     }</span><br><span> </span><br><span>        snapshot = stasis_message_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, sizeof(print_time));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       ast_cli(a->fd, "Id: %s\n", snapshot->uniqueid);</span><br><span>      ast_cli(a->fd, "Type: %s\n", S_OR(snapshot->subclass, "<unknown>"));</span><br><span>         ast_cli(a->fd, "Technology: %s\n", S_OR(snapshot->technology, "<unknown>"));</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_cli(a->fd, "Subclass: %s\n", snapshot->subclass);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Creator: %s\n", snapshot->creator);</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_cli(a->fd, "Name: %s\n", snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Video-Source-Id: %s\n", snapshot->video_source_id);</span><br><span>  ast_cli(a->fd, "Num-Channels: %u\n", snapshot->num_channels);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Num-Active: %u\n", snapshot->num_active);</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_cli(a->fd, "Duration: %s\n", print_time);</span><br><span>   ao2_callback(snapshot->channels, OBJ_NODATA, bridge_show_specific_print_channel, a);</span><br><span> </span><br><span>  return CLI_SUCCESS;</span><br><span>diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c</span><br><span>index 59b9685..af425c0 100644</span><br><span>--- a/main/stasis_bridges.c</span><br><span>+++ b/main/stasis_bridges.c</span><br><span>@@ -278,6 +278,7 @@</span><br><span>   snapshot->capabilities = bridge->technology->capabilities;</span><br><span>  snapshot->num_channels = bridge->num_channels;</span><br><span>         snapshot->num_active = bridge->num_active;</span><br><span style="color: hsl(120, 100%, 40%);">+      snapshot->creationtime = bridge->creationtime;</span><br><span>         snapshot->video_mode = bridge->softmix.video_mode.mode;</span><br><span>        if (snapshot->video_mode == AST_BRIDGE_VIDEO_MODE_SINGLE_SRC</span><br><span>              && bridge->softmix.video_mode.mode_data.single_src_data.chan_vsrc) {</span><br><span>@@ -620,7 +621,7 @@</span><br><span>                return NULL;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o, s: s}",</span><br><span style="color: hsl(120, 100%, 40%);">+     json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o, s: o, s: s}",</span><br><span>              "id", snapshot->uniqueid,</span><br><span>               "technology", snapshot->technology,</span><br><span>             "bridge_type", capability2str(snapshot->capabilities),</span><br><span>@@ -628,6 +629,7 @@</span><br><span>            "creator", snapshot->creator,</span><br><span>           "name", snapshot->name,</span><br><span>                 "channels", json_channels,</span><br><span style="color: hsl(120, 100%, 40%);">+          "creationtime", ast_json_timeval(snapshot->creationtime, NULL),</span><br><span>                 "video_mode", ast_bridge_video_mode_to_string(snapshot->video_mode));</span><br><span>   if (!json_bridge) {</span><br><span>          return NULL;</span><br><span>diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c</span><br><span>index 44d9d77..0d629a8 100644</span><br><span>--- a/res/ari/ari_model_validators.c</span><br><span>+++ b/res/ari/ari_model_validators.c</span><br><span>@@ -1360,6 +1360,7 @@</span><br><span>    int has_bridge_class = 0;</span><br><span>    int has_bridge_type = 0;</span><br><span>     int has_channels = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_creationtime = 0;</span><br><span>    int has_creator = 0;</span><br><span>         int has_id = 0;</span><br><span>      int has_name = 0;</span><br><span>@@ -1397,6 +1398,16 @@</span><br><span>                           res = 0;</span><br><span>                     }</span><br><span>            } else</span><br><span style="color: hsl(120, 100%, 40%);">+                if (strcmp("creationtime", ast_json_object_iter_key(iter)) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  int prop_is_valid;</span><br><span style="color: hsl(120, 100%, 40%);">+                    has_creationtime = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+                 prop_is_valid = ast_ari_validate_date(</span><br><span style="color: hsl(120, 100%, 40%);">+                                ast_json_object_iter_value(iter));</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (!prop_is_valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+                         ast_log(LOG_ERROR, "ARI Bridge field creationtime failed validation\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                            res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+                      }</span><br><span style="color: hsl(120, 100%, 40%);">+             } else</span><br><span>               if (strcmp("creator", ast_json_object_iter_key(iter)) == 0) {</span><br><span>                      int prop_is_valid;</span><br><span>                   has_creator = 1;</span><br><span>@@ -1478,6 +1489,11 @@</span><br><span>            res = 0;</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!has_creationtime) {</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_log(LOG_ERROR, "ARI Bridge missing required field creationtime\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (!has_creator) {</span><br><span>          ast_log(LOG_ERROR, "ARI Bridge missing required field creator\n");</span><br><span>                 res = 0;</span><br><span>diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h</span><br><span>index 1ee74f4..343848b 100644</span><br><span>--- a/res/ari/ari_model_validators.h</span><br><span>+++ b/res/ari/ari_model_validators.h</span><br><span>@@ -1488,6 +1488,7 @@</span><br><span>  * - bridge_class: string (required)</span><br><span>  * - bridge_type: string (required)</span><br><span>  * - channels: List[string] (required)</span><br><span style="color: hsl(120, 100%, 40%);">+ * - creationtime: Date (required)</span><br><span>  * - creator: string (required)</span><br><span>  * - id: string (required)</span><br><span>  * - name: string (required)</span><br><span>diff --git a/rest-api/api-docs/bridges.json b/rest-api/api-docs/bridges.json</span><br><span>index 04416c1..22743c3 100644</span><br><span>--- a/rest-api/api-docs/bridges.json</span><br><span>+++ b/rest-api/api-docs/bridges.json</span><br><span>@@ -753,6 +753,11 @@</span><br><span>                                      "type": "string",</span><br><span>                                        "description": "The ID of the channel that is the source of video in this bridge, if one exists.",</span><br><span>                                       "required": false</span><br><span style="color: hsl(120, 100%, 40%);">+                           },</span><br><span style="color: hsl(120, 100%, 40%);">+                            "creationtime": {</span><br><span style="color: hsl(120, 100%, 40%);">+                                   "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+                                   "type": "Date",</span><br><span style="color: hsl(120, 100%, 40%);">+                                   "description": "Timestamp when bridge was created"</span><br><span>                               }</span><br><span>                    }</span><br><span>            }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11080">change 11080</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/+/11080"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I460238c488eca4d216b9176576211cb03286e040 </div>
<div style="display:none"> Gerrit-Change-Number: 11080 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>