Implements transactional host pools members add

This commit is contained in:
Simone Mainardi 2020-11-13 19:15:21 +01:00
parent 7f3b9a4a93
commit e7a6682aba
3 changed files with 55 additions and 6 deletions

View file

@ -38,6 +38,30 @@ end
-- ##############################################
-- @brief Start a pool transaction.
-- See pools:start_transaction() for additional comments
function host_pools:start_transaction()
-- OVERRIDE
self.transaction_started = true
end
-- ##############################################
-- @brief Ends a pool transaction.
function host_pools:end_transaction()
-- Perform end-of-transaction operations. Basically all the operations
-- that are needed when doing a _persist
-- Reload pools
ntop.reloadHostPools()
-- Reload periodic scripts
ntop.reloadPeriodicScripts()
self.transaction_started = nil
end
-- ##############################################
-- @brief Given a member key, returns a table of member details such as member name.
function host_pools:get_member_details(member)
local res = {}
@ -197,11 +221,16 @@ function host_pools:_persist(pool_id, name, members, configset_id, recipients)
-- Recipients
ntop.setHashCache(pool_details_key, "recipients", json.encode(recipients));
-- Reload pools
ntop.reloadHostPools()
-- Only reload if a transaction is not started. If a transaction is in progress
-- no reload is performed: it is UP TO THE CALLER to call end_transaction and
-- which will perform these operations
if not self.transaction_started then
-- Reload pools
ntop.reloadHostPools()
-- Reload periodic scripts
ntop.reloadPeriodicScripts()
-- Reload periodic scripts
ntop.reloadPeriodicScripts()
end
-- Return the assigned pool_id
return pool_id

View file

@ -78,6 +78,21 @@ end
-- ##############################################
-- @brief Start a pool transaction. Useful to do bulk imports or other operations that may require multiple steps
-- By default, all operations are non-transational, that is, every operation atomically changes the status of pools.
-- To perform multiple, non-atomic operations, a transaction can be started.
-- NOTE: currently, transactions are not supported, unless implemented in pools.lua subclasses
function pools:start_transaction()
end
-- ##############################################
-- @brief Ends a pool transaction.
function pools:end_transaction()
end
-- ##############################################
function pools:_initialize()
local locked = self:_lock()
@ -912,10 +927,10 @@ function pools:bind_member_if_not_already_bound(member, pool_id)
-- Member already existing
if assigned_members[member]["pool_id"] == pool_id then
-- Member is bound to the same pool as the parameter `pool_id`
ret, err = true, pools.ERRORS.NO_ERROR
ret, err = true, pools.ERRORS.NO_ERROR
else
-- Member is bound to another pool
ret, err = false, pools.ERRORS.ALREADY_BOUND
ret, err = false, pools.ERRORS.ALREADY_BOUND
end
else
-- Member isn't bound to any pool, safe to add it