ganeti
Safe HaskellNone

Ganeti.WConfd.Monad

Description

All RPC calls are run within this monad.

It encapsulates:

  • IO operations,
  • failures,
  • working with the daemon state.

Code that is specific either to the configuration or the lock management, should go into their corresponding dedicated modules.

Synopsis

Monoid of the locations to flush the configuration to

data DistributionTarget Source #

Data type describing where the configuration has to be distributed to.

Constructors

Everywhere 
ToGroups (Set String) 

Pure data types used in the monad

data DaemonState Source #

The state of the daemon, capturing both the configuration state and the locking state.

data DaemonHandle Source #

Constructors

DaemonHandle 

Fields

mkDaemonHandle Source #

Arguments

:: FilePath 
-> ConfigState 
-> GanetiLockWaiting 
-> TempResState 
-> (IO ConfigState -> [AsyncWorker DistributionTarget ()] -> ResultG (AsyncWorker (Any, DistributionTarget) ()))

A function that creates a worker that asynchronously saves the configuration to the master file.

-> (IO ConfigState -> ResultG (AsyncWorker DistributionTarget ()))

A function that creates a worker that asynchronously distributes the configuration to master candidates

-> (IO ConfigState -> ResultG (AsyncWorker DistributionTarget ()))

A function that creates a worker that asynchronously distributes SSConf to nodes

-> (IO GanetiLockWaiting -> ResultG (AsyncWorker () ()))

A function that creates a worker that asynchronously saves the lock allocation state.

-> (IO TempResState -> ResultG (AsyncWorker () ()))

A function that creates a worker that asynchronously saves the temporary reservations state.

-> Livelock 
-> ResultG DaemonHandle 

The monad and its instances

type WConfdMonadIntType = ReaderT DaemonHandle IO Source #

A type alias for easier referring to the actual content of the monad when implementing its instances.

newtype WConfdMonadInt a Source #

The internal part of the monad without error handling.

Instances

Instances details
Monad WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Functor WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Methods

fmap :: (a -> b) -> WConfdMonadInt a -> WConfdMonadInt b

(<$) :: a -> WConfdMonadInt b -> WConfdMonadInt a

Applicative WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

MonadIO WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Methods

liftIO :: IO a -> WConfdMonadInt a

MonadLog WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Methods

logAt :: Priority -> String -> WConfdMonadInt () Source #

MonadBase IO WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Methods

liftBase :: IO α -> WConfdMonadInt α

MonadBaseControl IO WConfdMonadInt # 
Instance details

Defined in Ganeti.WConfd.Monad

Associated Types

type StM WConfdMonadInt a

Methods

liftBaseWith :: (RunInBase WConfdMonadInt IO -> IO a) -> WConfdMonadInt a

restoreM :: StM WConfdMonadInt a -> WConfdMonadInt a

type StM WConfdMonadInt b # 
Instance details

Defined in Ganeti.WConfd.Monad

type StM WConfdMonadInt b

runWConfdMonadInt :: WConfdMonadInt a -> DaemonHandle -> IO a Source #

Runs the internal part of the WConfdMonad monad on a given daemon handle.

type WConfdMonad = ResultT GanetiException WConfdMonadInt Source #

The complete monad with error handling.

type AtomicModifyMonad a = ResultT GanetiException WriterLog a Source #

A pure monad that logs and reports errors used for atomic modifications.

Basic functions in the monad

daemonHandle :: WConfdMonad DaemonHandle Source #

Returns the daemon handle.

readConfigState :: WConfdMonad ConfigState Source #

Returns the current configuration, given a handle

unpackConfigResult :: ClockTime -> ConfigState -> (a, ConfigState) -> ((a, Bool, Bool), ConfigState) Source #

From a result of a configuration change, determine if the configuration was changed and if full distribution is needed. If so, also bump the serial number.

modifyConfigStateErrWithImmediate :: (TempResState -> ConfigState -> AtomicModifyMonad (a, ConfigState)) -> WConfdMonad () -> WConfdMonad a Source #

Atomically modifies the configuration state in the WConfdMonad with a computation that can possibly fail; immediately afterwards, while config write is still going on, do the followup action. Return only after replication is finished.

modifyConfigStateErr :: (TempResState -> ConfigState -> AtomicModifyMonad (a, ConfigState)) -> WConfdMonad a Source #

Atomically modifies the configuration state in the WConfdMonad with a computation that can possibly fail.

modifyConfigStateErr_ :: (TempResState -> ConfigState -> AtomicModifyMonad ConfigState) -> WConfdMonad () Source #

Atomically modifies the configuration state in the WConfdMonad with a computation that can possibly fail.

modifyConfigState :: (ConfigState -> (a, ConfigState)) -> WConfdMonad a Source #

Atomically modifies the configuration state in the WConfdMonad.

modifyConfigStateWithImmediate :: (ConfigState -> (a, ConfigState)) -> WConfdMonad () -> WConfdMonad a Source #

Atomically modifies the configuration state in WConfdMonad; immediately afterwards (while the config write-out is not necessarily finished) do another acation.

forceConfigStateDistribution :: DistributionTarget -> WConfdMonad () Source #

Force the distribution of configuration without actually modifying it.

We need a separate call for this operation, because modifyConfigState only triggers the distribution when the configuration changes.

modifyConfigDataErr_ :: (TempResState -> ConfigData -> AtomicModifyMonad ConfigData) -> WConfdMonad () Source #

Atomically modifies the configuration data in the WConfdMonad with a computation that can possibly fail.

modifyTempResStateErr :: (ConfigData -> StateT TempResState ErrorResult a) -> WConfdMonad a Source #

Atomically modifies the state of temporary reservations in WConfdMonad in the presence of possible errors.

modifyTempResState :: (ConfigData -> State TempResState a) -> WConfdMonad a Source #

Atomically modifies the state of temporary reservations in WConfdMonad.

readTempResState :: WConfdMonad (ConfigData, TempResState) Source #

Reads the state of of the configuration and temporary reservations in WConfdMonad.

modifyLockWaiting :: (GanetiLockWaiting -> (GanetiLockWaiting, (a, Set ClientId))) -> WConfdMonad a Source #

Atomically modifies the lock waiting state in WConfdMonad.

modifyLockWaiting_ :: (GanetiLockWaiting -> (GanetiLockWaiting, Set ClientId)) -> WConfdMonad () Source #

Atomically modifies the lock allocation state in WConfdMonad, not producing any result

readLockWaiting :: WConfdMonad GanetiLockWaiting Source #

Read the lock waiting state in WConfdMonad.

readLockAllocation :: WConfdMonad (LockAllocation GanetiLocks ClientId) Source #

Read the underlying lock allocation.

modifyConfigAndReturnWithLock :: (TempResState -> ConfigState -> AtomicModifyMonad (a, ConfigState)) -> State TempResState () -> WConfdMonad (Maybe a) Source #

Modify the configuration while temporarily acquiring the configuration lock. If the configuration lock is held by someone else, nothing is changed and Nothing is returned.