bridges: Remove reliance on stasis caching

* The bridging core no longer uses the stasis cache for bridge
  snapshots.  The latest bridge snapshot is now stored on the
  ast_bridge structure itself.

* The following APIs are no longer available since the stasis cache
  is no longer used:
    ast_bridge_topic_cached()
    ast_bridge_topic_all_cached()

* A topic pool is now used for individual bridge topics.

* The ast_bridge_cache() function was removed since there's no
  longer a separate container of snapshots.

* A new function "ast_bridges()" was created to retrieve the
  container of all bridges.  Users formerly calling
  ast_bridge_cache() can use the new function to iterate over
  bridges and retrieve the latest snapshot directly from the
  bridge.

* The ast_bridge_snapshot_get_latest() function was renamed to
  ast_bridge_get_snapshot_by_uniqueid().

* A new function "ast_bridge_get_snapshot()" was created to retrieve
  the bridge snapshot directly from the bridge structure.

* The ast_bridge_topic_all() function now returns a normal topic
  not a cached one so you can't use stasis cache functions on it
  either.

* The ast_bridge_snapshot_type() stasis message now has the
  ast_bridge_snapshot_update structure as it's data.  It contains
  the last snapshot and the new one.

* cdr, cel, manager and ari have been updated to use the new
  arrangement.

Change-Id: I7049b80efa88676ce5c4666f818fa18ad1985369
This commit is contained in:
George Joseph
2018-09-19 13:34:41 -06:00
parent 4ca709768d
commit 3667c5e1d2
15 changed files with 397 additions and 340 deletions

View File

@@ -65,7 +65,7 @@ static struct ast_bridge *find_bridge(
bridge = stasis_app_bridge_find_by_id(bridge_id);
if (bridge == NULL) {
RAII_VAR(struct ast_bridge_snapshot *, snapshot,
ast_bridge_snapshot_get_latest(bridge_id), ao2_cleanup);
ast_bridge_get_snapshot_by_uniqueid(bridge_id), ao2_cleanup);
if (!snapshot) {
ast_ari_response_error(response, 404, "Not found",
"Bridge not found");
@@ -856,7 +856,7 @@ void ast_ari_bridges_get(struct ast_variable *headers,
struct ast_ari_bridges_get_args *args,
struct ast_ari_response *response)
{
RAII_VAR(struct ast_bridge_snapshot *, snapshot, ast_bridge_snapshot_get_latest(args->bridge_id), ao2_cleanup);
RAII_VAR(struct ast_bridge_snapshot *, snapshot, ast_bridge_get_snapshot_by_uniqueid(args->bridge_id), ao2_cleanup);
if (!snapshot) {
ast_ari_response_error(
response, 404, "Not Found",
@@ -885,23 +885,13 @@ void ast_ari_bridges_list(struct ast_variable *headers,
struct ast_ari_bridges_list_args *args,
struct ast_ari_response *response)
{
RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
RAII_VAR(struct ao2_container *, bridges, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
struct ao2_iterator i;
void *obj;
struct ast_bridge *bridge;
cache = ast_bridge_cache();
if (!cache) {
ast_ari_response_error(
response, 500, "Internal Server Error",
"Message bus not initialized");
return;
}
ao2_ref(cache, +1);
snapshots = stasis_cache_dump(cache, ast_bridge_snapshot_type());
if (!snapshots) {
bridges = ast_bridges();
if (!bridges) {
ast_ari_response_alloc_failed(response);
return;
}
@@ -912,12 +902,14 @@ void ast_ari_bridges_list(struct ast_variable *headers,
return;
}
i = ao2_iterator_init(snapshots, 0);
while ((obj = ao2_iterator_next(&i))) {
RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
i = ao2_iterator_init(bridges, 0);
while ((bridge = ao2_iterator_next(&i))) {
struct ast_bridge_snapshot *snapshot = ast_bridge_get_snapshot(bridge);
/* ast_bridge_snapshot_to_json will return NULL if snapshot is NULL */
struct ast_json *json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
ao2_ref(bridge, -1);
ao2_cleanup(snapshot);
if (!json_bridge || ast_json_array_append(json, json_bridge)) {
ao2_iterator_destroy(&i);
ast_ari_response_alloc_failed(response);