diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 142fc236a..d2c5fa074 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,10 @@ Added - new issue when ``box.info.election.leader_idle`` is too high. +- Lua API ``get_uris`` to get all instances uris. + +- Filter param to Lua API ``get_servers`` to filter instances. + ------------------------------------------------------------------------------- [2.8.4] - 2023-10-31 ------------------------------------------------------------------------------- diff --git a/cartridge.lua b/cartridge.lua index 2d8e2d6ed..ff5730d72 100644 --- a/cartridge.lua +++ b/cartridge.lua @@ -1010,6 +1010,11 @@ return { -- @function admin_get_replicasets admin_get_replicasets = lua_api_topology.get_replicasets, + --- . + -- @refer cartridge.lua-api.get-topology.get_uris + -- @function admin_get_uris + admin_get_uris = lua_api_topology.get_uris, + --- . -- @refer cartridge.lua-api.topology.probe_server -- @function admin_probe_server diff --git a/cartridge/admin.lua b/cartridge/admin.lua index 02eb8e7ee..d87c9c4df 100755 --- a/cartridge/admin.lua +++ b/cartridge/admin.lua @@ -23,6 +23,7 @@ return { get_servers = lua_api_topology.get_servers, get_replicasets = lua_api_topology.get_replicasets, get_topology = lua_api_topology.get_topology, + get_uris = lua_api_topology.get_uris, edit_topology = lua_api_topology.edit_topology, probe_server = lua_api_topology.probe_server, diff --git a/cartridge/lua-api/get-topology.lua b/cartridge/lua-api/get-topology.lua index f382914f1..691502fc3 100644 --- a/cartridge/lua-api/get-topology.lua +++ b/cartridge/lua-api/get-topology.lua @@ -253,7 +253,15 @@ local function get_topology() } end -local function get_servers() + +--- Get servers list. +-- @function get_servers +-- @local +-- @tparam ?function filter +-- function(x: ServerInfo) -> boolean +-- @return table {ServerInfo, ...} +local function get_servers(filter) + filter = filter or function() return true end local servers = {} local topology, err = get_topology() if topology == nil then @@ -265,11 +273,25 @@ local function get_servers() server.replicaset_uuid = server.replicaset.uuid end server.replicaset = nil - table.insert(servers, server) + if filter(server) then + table.insert(servers, server) + end end return servers end +--- Get servers uri list. +-- @function get_uris +-- @local +-- @tparam ?function filter +-- function(x: ServerInfo) -> boolean +-- @return table {uri1, uri2, ...} +local function get_uris(filter) + return fun.iter(get_servers(filter)):map(function(server) + return server.uri + end):totable() +end + local function get_replicasets() local replicasets = {} local topology, err = get_topology() @@ -314,4 +336,5 @@ return { get_servers = get_servers, get_replicasets = get_replicasets, get_enabled_roles_without_deps = get_enabled_roles_without_deps, + get_uris = get_uris, } diff --git a/cartridge/lua-api/topology.lua b/cartridge/lua-api/topology.lua index b16232d46..d3da9fe17 100644 --- a/cartridge/lua-api/topology.lua +++ b/cartridge/lua-api/topology.lua @@ -249,6 +249,7 @@ return { get_servers = get_servers, get_replicasets = get_replicasets, get_topology = lua_api_get_topology.get_topology, + get_uris = lua_api_get_topology.get_uris, edit_topology = lua_api_edit_topology.edit_topology, probe_server = probe_server,