Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #993 from seagate-ssg/dev/halon-457
Browse files Browse the repository at this point in the history
[HALON-457] Implement new job interface.
  • Loading branch information
nc6 authored Sep 29, 2016
2 parents bfdfa86 + a57eda6 commit fe96510
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 193 deletions.
1 change: 1 addition & 0 deletions cep/cep/src/Network/CEP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Network.CEP
, start
, start_
, startFork
, startForks
, get
, gets
, put
Expand Down
13 changes: 9 additions & 4 deletions cep/cep/src/Network/CEP/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,25 @@ start h l = singleton $ Start h l
start_ :: Jump PhaseHandle -> RuleM g () (Started g ())
start_ h = start h ()

-- | Start a rule with an implicit fork
-- | Start a rule with an implicit fork.
startFork :: Jump PhaseHandle -> l -> RuleM g l (Started g l)
startFork rule state = do
startFork rule = startForks [rule]

-- | Start a rule with an implicit fork. Rule may started from
-- different phases.
startForks :: [Jump PhaseHandle] -> l -> RuleM g l (Started g l)
startForks rules state = do
winit <- initWrapper
start winit state
where
initWrapper = do
wrapper_init <- phaseHandle "wrapper_init"
wrapper_clear <- phaseHandle "wrapper_clear"
wrapper_end <- phaseHandle "wrapper_end"
directly wrapper_init $ Network.CEP.Types.switch [rule, wrapper_clear]
directly wrapper_init $ Network.CEP.Types.switch (rules ++ [wrapper_clear])

directly wrapper_clear $ do
fork NoBuffer $ continue rule
fork NoBuffer $ Network.CEP.Types.switch rules
continue wrapper_end

directly wrapper_end stop
Expand Down
4 changes: 3 additions & 1 deletion mero-halon/mero-halon.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ Library
HA.RecoveryCoordinator.Actions.Hardware
HA.RecoveryCoordinator.Actions.Service
HA.RecoveryCoordinator.Actions.Test
HA.RecoveryCoordinator.Actions.Job
HA.RecoveryCoordinator.Job.Actions
HA.RecoveryCoordinator.Job.Events
HA.RecoveryCoordinator.Rules.Castor
HA.RecoveryCoordinator.Rules.Debug
HA.RecoveryCoordinator.Rules.Service
Expand All @@ -124,6 +125,7 @@ Library
HA.Services.SSPL.HL.StatusHandler
HA.Services.SSPL.HL.CEP
HA.Services.SSPL.LL.RC.Actions
HA.RecoveryCoordinator.Job.Internal

Build-Depends: base,
aeson,
Expand Down
35 changes: 34 additions & 1 deletion mero-halon/src/lib/HA/RecoveryCoordinator/Actions/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ module HA.RecoveryCoordinator.Actions.Core
, putStorageRC
, getStorageRC
, deleteStorageRC
-- ** Helpers for Set
, insertStorageSetRC
, memberStorageSetRC
, deleteStorageSetRC
-- ** Helpers for Map
, insertWithStorageMapRC
, memberStorageMapRC
, deleteStorageMapRC
, lookupStorageMapRC
-- * Communication with the EQ
, messageProcessed
, mkMessageProcessed
Expand Down Expand Up @@ -86,14 +92,15 @@ import Control.Distributed.Process
, spawnLocal
, link
)
import Control.Monad (when, unless)
import Control.Monad (when, unless, (<=<))
import Control.Distributed.Process.Serializable

import Data.Typeable (Typeable)
import Data.Functor (void)
import Data.Proxy
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Maybe (fromMaybe)

import Network.CEP

Expand Down Expand Up @@ -135,6 +142,32 @@ deleteStorageSetRC x = modify Global $ \g -> do
Nothing -> g
Just z -> g{lsStorage = Storage.put (Set.delete x z) $ lsStorage g}

-- | Helper that wraps. 'Data.Map.member' for map kept in Storage.
memberStorageMapRC :: forall proxy k v l . (Typeable k, Typeable v, Ord k)
=> proxy v -> k -> PhaseM LoopState l Bool
memberStorageMapRC _ x =
maybe False (\m -> Map.member x (m :: Map.Map k v))
. Storage.get . lsStorage <$> get Global

insertWithStorageMapRC :: (Typeable k, Typeable v, Ord k)
=> (v -> v -> v) -> k -> v -> PhaseM LoopState l ()
insertWithStorageMapRC f k v = modify Global $ \g -> do
let z = fromMaybe Map.empty $ Storage.get (lsStorage g)
g{lsStorage = Storage.put (Map.insertWith f k v z) $ lsStorage g}

deleteStorageMapRC :: forall proxy k v l . (Typeable k, Typeable v, Ord k)
=> proxy v -> k -> PhaseM LoopState l ()
deleteStorageMapRC _ x = modify Global $ \g -> do
case Storage.get (lsStorage g) of
Nothing -> g
Just (z::Map.Map k v) -> g{lsStorage = Storage.put (Map.delete x z) $ lsStorage g}

lookupStorageMapRC :: forall proxy k v l . (Typeable k, Typeable v, Ord k)
=> k -> PhaseM LoopState l (Maybe v)
lookupStorageMapRC x =
((\m -> Map.lookup x (m :: Map.Map k v))
<=< Storage.get . lsStorage) <$> get Global

-- | Is a given resource existent in the RG?
knownResource :: G.Resource a => a -> PhaseM LoopState l Bool
knownResource res = fmap (G.memberResource res) getLocalGraph
Expand Down
103 changes: 0 additions & 103 deletions mero-halon/src/lib/HA/RecoveryCoordinator/Actions/Job.hs

This file was deleted.

2 changes: 1 addition & 1 deletion mero-halon/src/lib/HA/RecoveryCoordinator/CEP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import HA.RecoveryCoordinator.Events.Cluster
import HA.RecoveryCoordinator.Rules.Castor
import qualified HA.RecoveryCoordinator.Rules.Service
import qualified HA.RecoveryCoordinator.Rules.Debug as Debug (rules)
import HA.RecoveryCoordinator.Actions.Job
import HA.RecoveryCoordinator.Job.Actions
import qualified HA.ResourceGraph as G
import HA.Resources
import HA.Resources.Castor
Expand Down
Loading

0 comments on commit fe96510

Please sign in to comment.