Skip to content

Commit

Permalink
Add get_uris and extend get_servers
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Nov 21, 2023
1 parent b5c946c commit fe0e73b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions cartridge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cartridge/admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 25 additions & 2 deletions cartridge/lua-api/get-topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions cartridge/lua-api/topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fe0e73b

Please sign in to comment.