[Asterisk-code-review] bridging: Add creation timestamps (...asterisk[master])
George Joseph
asteriskteam at digium.com
Fri Mar 8 11:11:36 CST 2019
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/10986 )
Change subject: bridging: Add creation timestamps
......................................................................
bridging: Add creation timestamps
This small feature will help to checking the bridge's status to
figure out which bridge is in old/zombie or not. Also added
detail items for the 'bridge show *' cli to provide more detail
info. And added creation item to the ARI as well.
ASTERISK-28279
Change-Id: I460238c488eca4d216b9176576211cb03286e040
---
M include/asterisk/bridge.h
M main/bridge.c
M main/stasis_bridges.c
M res/ari/ari_model_validators.c
M res/ari/ari_model_validators.h
M rest-api/api-docs/bridges.json
6 files changed, 49 insertions(+), 5 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/include/asterisk/bridge.h b/include/asterisk/bridge.h
index e4d11e8..621ed0d 100644
--- a/include/asterisk/bridge.h
+++ b/include/asterisk/bridge.h
@@ -331,6 +331,8 @@
unsigned int num_active;
/*! The video mode of the bridge */
enum ast_bridge_video_mode_type video_mode;
+ /*! The time of bridge creation */
+ struct timeval creationtime;
};
/*!
@@ -394,6 +396,8 @@
struct ast_vector_int media_types;
/*! Current bridge snapshot */
struct ast_bridge_snapshot *current_snapshot;
+ /*! The time of bridge creation */
+ struct timeval creationtime;
};
/*! \brief Bridge base class virtual method table. */
diff --git a/main/bridge.c b/main/bridge.c
index 1bee2e6..5752001 100644
--- a/main/bridge.c
+++ b/main/bridge.c
@@ -822,6 +822,8 @@
}
}
+ self->creationtime = ast_tvnow();
+
return self;
}
@@ -5051,8 +5053,8 @@
static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
-#define FORMAT_HDR "%-36s %5s %-15s %s\n"
-#define FORMAT_ROW "%-36s %5u %-15s %s\n"
+#define FORMAT_HDR "%-36s %5s %-15s %-15s %s\n"
+#define FORMAT_ROW "%-36s %5u %-15s %-15s %s\n"
struct ao2_iterator iter;
struct ast_bridge *bridge;
@@ -5068,18 +5070,22 @@
return NULL;
}
- ast_cli(a->fd, FORMAT_HDR, "Bridge-ID", "Chans", "Type", "Technology");
+ ast_cli(a->fd, FORMAT_HDR, "Bridge-ID", "Chans", "Type", "Technology", "Duration");
iter = ao2_iterator_init(bridges, 0);
for (; (bridge = ao2_iterator_next(&iter)); ao2_ref(bridge, -1)) {
struct ast_bridge_snapshot *snapshot = ast_bridge_get_snapshot(bridge);
+ char print_time[32];
+
+ ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, sizeof(print_time));
if (snapshot) {
ast_cli(a->fd, FORMAT_ROW,
snapshot->uniqueid,
snapshot->num_channels,
S_OR(snapshot->subclass, "<unknown>"),
- S_OR(snapshot->technology, "<unknown>"));
+ S_OR(snapshot->technology, "<unknown>"),
+ print_time);
ao2_ref(snapshot, -1);
}
}
@@ -5112,6 +5118,7 @@
static char *handle_bridge_show_specific(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_bridge_snapshot *snapshot;
+ char print_time[32];
switch (cmd) {
case CLI_INIT:
@@ -5136,10 +5143,19 @@
ast_cli(a->fd, "Bridge '%s' not found\n", a->argv[2]);
return CLI_SUCCESS;
}
+
+ ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, sizeof(print_time));
+
ast_cli(a->fd, "Id: %s\n", snapshot->uniqueid);
ast_cli(a->fd, "Type: %s\n", S_OR(snapshot->subclass, "<unknown>"));
ast_cli(a->fd, "Technology: %s\n", S_OR(snapshot->technology, "<unknown>"));
+ ast_cli(a->fd, "Subclass: %s\n", snapshot->subclass);
+ ast_cli(a->fd, "Creator: %s\n", snapshot->creator);
+ ast_cli(a->fd, "Name: %s\n", snapshot->name);
+ ast_cli(a->fd, "Video-Source-Id: %s\n", snapshot->video_source_id);
ast_cli(a->fd, "Num-Channels: %u\n", snapshot->num_channels);
+ ast_cli(a->fd, "Num-Active: %u\n", snapshot->num_active);
+ ast_cli(a->fd, "Duration: %s\n", print_time);
ao2_callback(snapshot->channels, OBJ_NODATA, bridge_show_specific_print_channel, a);
ao2_ref(snapshot, -1);
diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c
index bed28ba..cfdf117 100644
--- a/main/stasis_bridges.c
+++ b/main/stasis_bridges.c
@@ -246,6 +246,7 @@
snapshot->capabilities = bridge->technology->capabilities;
snapshot->num_channels = bridge->num_channels;
snapshot->num_active = bridge->num_active;
+ snapshot->creationtime = bridge->creationtime;
snapshot->video_mode = bridge->softmix.video_mode.mode;
if (snapshot->video_mode == AST_BRIDGE_VIDEO_MODE_SINGLE_SRC
&& bridge->softmix.video_mode.mode_data.single_src_data.chan_vsrc) {
@@ -679,7 +680,7 @@
return NULL;
}
- json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o, s: s}",
+ json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o, s: o, s: s}",
"id", snapshot->uniqueid,
"technology", snapshot->technology,
"bridge_type", capability2str(snapshot->capabilities),
@@ -687,6 +688,7 @@
"creator", snapshot->creator,
"name", snapshot->name,
"channels", json_channels,
+ "creationtime", ast_json_timeval(snapshot->creationtime, NULL),
"video_mode", ast_bridge_video_mode_to_string(snapshot->video_mode));
if (!json_bridge) {
return NULL;
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 44d9d77..0d629a8 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1360,6 +1360,7 @@
int has_bridge_class = 0;
int has_bridge_type = 0;
int has_channels = 0;
+ int has_creationtime = 0;
int has_creator = 0;
int has_id = 0;
int has_name = 0;
@@ -1397,6 +1398,16 @@
res = 0;
}
} else
+ if (strcmp("creationtime", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_creationtime = 1;
+ prop_is_valid = ast_ari_validate_date(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Bridge field creationtime failed validation\n");
+ res = 0;
+ }
+ } else
if (strcmp("creator", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
has_creator = 1;
@@ -1478,6 +1489,11 @@
res = 0;
}
+ if (!has_creationtime) {
+ ast_log(LOG_ERROR, "ARI Bridge missing required field creationtime\n");
+ res = 0;
+ }
+
if (!has_creator) {
ast_log(LOG_ERROR, "ARI Bridge missing required field creator\n");
res = 0;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 1ee74f4..343848b 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -1488,6 +1488,7 @@
* - bridge_class: string (required)
* - bridge_type: string (required)
* - channels: List[string] (required)
+ * - creationtime: Date (required)
* - creator: string (required)
* - id: string (required)
* - name: string (required)
diff --git a/rest-api/api-docs/bridges.json b/rest-api/api-docs/bridges.json
index 04416c1..22743c3 100644
--- a/rest-api/api-docs/bridges.json
+++ b/rest-api/api-docs/bridges.json
@@ -753,6 +753,11 @@
"type": "string",
"description": "The ID of the channel that is the source of video in this bridge, if one exists.",
"required": false
+ },
+ "creationtime": {
+ "required": true,
+ "type": "Date",
+ "description": "Timestamp when bridge was created"
}
}
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/10986
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I460238c488eca4d216b9176576211cb03286e040
Gerrit-Change-Number: 10986
Gerrit-PatchSet: 7
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190308/d202e760/attachment-0001.html>
More information about the asterisk-code-review
mailing list