From c119f0bd446350fc7094a7dbedb26bffd80db4ce Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 14 Jul 2015 14:06:41 +0200 Subject: [PATCH] Add routines to manipulate the jobs list for maintd In this way, the maintenance daemon can update the jobs part of its state, while complying with the requirement that all its state be stored in the configuration (and hence, also sufficiently replicated). Signed-off-by: Klaus Aehlig Reviewed-by: Petr Pudlak --- src/Ganeti/WConfd/ConfigModifications.hs | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Ganeti/WConfd/ConfigModifications.hs b/src/Ganeti/WConfd/ConfigModifications.hs index f643fc300..30bd86dd9 100644 --- a/src/Ganeti/WConfd/ConfigModifications.hs +++ b/src/Ganeti/WConfd/ConfigModifications.hs @@ -67,7 +67,8 @@ import Ganeti.Locking.Locks (ClientId, ciIdentifier) import Ganeti.Logging.Lifted (logDebug, logInfo) import Ganeti.Objects import Ganeti.Objects.Lens -import Ganeti.Types (AdminState, AdminStateSource) +import Ganeti.Types (AdminState, AdminStateSource, JobId) +import Ganeti.Utils (ordNub) import Ganeti.WConfd.ConfigState (ConfigState, csConfigData, csConfigDataL) import Ganeti.WConfd.Monad (WConfdMonad, modifyConfigWithLock , modifyConfigAndReturnWithLock) @@ -664,6 +665,28 @@ setMaintdRoundDelay delay = do (\_ cs -> return . setDelay $ cs) (return ()) +-- | Clear the list of current maintenance jobs. +clearMaintdJobs :: WConfdMonad Bool +clearMaintdJobs = do + now <- liftIO getClockTime + let clear = over (csConfigDataL . configMaintenanceL) + $ (serialL +~ 1) . (mTimeL .~ now) . (maintJobsL .~ []) + liftM isJust $ modifyConfigWithLock + (\_ cs -> return . clear $ cs) + (return ()) + +-- | Append new jobs to the list of current maintenace jobs, if +-- not alread present. +appendMaintdJobs :: [JobId] -> WConfdMonad Bool +appendMaintdJobs jobs = do + now <- liftIO getClockTime + let addJobs = over (csConfigDataL . configMaintenanceL) + $ (serialL +~ 1) . (mTimeL .~ now) + . over maintJobsL (ordNub . (++ jobs)) + liftM isJust $ modifyConfigWithLock + (\_ cs -> return . addJobs $ cs) + (return ()) + -- * The list of functions exported to RPC. exportedFunctions :: [Name] @@ -684,4 +707,6 @@ exportedFunctions = [ 'addInstance , 'updateNode , 'updateNodeGroup , 'setMaintdRoundDelay + , 'clearMaintdJobs + , 'appendMaintdJobs ] -- GitLab