@@ -28,7 +28,7 @@ import qualified Data.Graph as G
28
28
import qualified Data.Tree as T
29
29
import Data.Foldable (toList ,foldl' ,Foldable ,foldlM )
30
30
import Data.Traversable (mapM ,forM )
31
- import Debug.Trace ( traceEventIO )
31
+ import Control.Monad.Operational
32
32
33
33
-- helpers
34
34
vmapM :: (Monad m , Foldable t ) => (a -> m b ) -> t a -> m [b ]
@@ -40,25 +40,27 @@ vmapM f = mapM f . toList
40
40
-- (this last one might not be up to date and is only useful for code
41
41
-- coverage tests)) along with all messages that have been generated by the
42
42
-- compilation process.
43
- getCatalog :: ( TopLevelType -> T. Text -> IO (S. Either Doc Statement ) ) -- ^ get statements function
43
+ getCatalog :: Monad m
44
+ => (InterpreterReader -> InterpreterMonad (FinalCatalog , EdgeMap , FinalCatalog , [Resource ]) -> RSM m (FinalCatalog , EdgeMap , FinalCatalog , [Resource ])) -- ^ A function that will interpret the InterpreterMonad and will convert it to something else (for example, 'interpretIO')
45
+ -> ( TopLevelType -> T. Text -> IO (S. Either Doc Statement ) ) -- ^ get statements function
44
46
-> (Either T. Text T. Text -> T. Text -> Container ScopeInformation -> IO (S. Either Doc T. Text )) -- ^ compute template function
45
47
-> PuppetDBAPI
46
48
-> T. Text -- ^ Node name
47
49
-> Facts -- ^ Facts ...
48
50
-> Container PuppetTypeMethods -- ^ List of native types
49
51
-> Container ( [PValue ] -> InterpreterMonad PValue )
50
52
-> HieraQueryFunc -- ^ Hiera query function
51
- -> IO (Pair (S. Either Doc (FinalCatalog , EdgeMap , FinalCatalog , [Resource ])) [Pair Priority Doc ])
52
- getCatalog gtStatement gtTemplate pdbQuery ndename facts nTypes extfuncs hquery = do
53
- nameThread (" Catalog " <> T. unpack ndename)
53
+ -> m (Pair (S. Either Doc (FinalCatalog , EdgeMap , FinalCatalog , [Resource ])) [Pair Priority Doc ])
54
+ getCatalog convertMonad gtStatement gtTemplate pdbQuery ndename facts nTypes extfuncs hquery = do
55
+ -- nameThread ("Catalog " <> T.unpack ndename)
54
56
let rdr = InterpreterReader nTypes gtStatement gtTemplate pdbQuery extfuncs ndename hquery
55
57
dummypos = initialPPos " dummy"
56
58
initialclass = mempty & at " ::" ?~ (IncludeStandard :!: dummypos)
57
59
stt = InterpreterState baseVars initialclass mempty [ContRoot ] dummypos mempty [] []
58
60
factvars = facts & each %~ (\ x -> PString x :!: initialPPos " facts" :!: ContRoot )
59
61
callervars = ifromList [(" caller_module_name" , PString " ::" :!: dummypos :!: ContRoot ), (" module_name" , PString " ::" :!: dummypos :!: ContRoot )]
60
62
baseVars = isingleton " ::" (ScopeInformation (factvars <> callervars) mempty mempty (CurContainer ContRoot mempty ) mempty S. Nothing )
61
- (output, _, warnings) <- runRSST (runErrorT (computeCatalog ndename)) rdr stt
63
+ (output, _, warnings) <- runRSST (runErrorT (convertMonad rdr ( computeCatalog ndename) )) rdr stt
62
64
return (strictifyEither output :!: warnings)
63
65
64
66
isParent :: T. Text -> CurContainerDesc -> InterpreterMonad Bool
@@ -146,12 +148,7 @@ getstt topleveltype toplevelname = do
146
148
-- check if this is a known class (spurious or inner class)
147
149
use (nestedDeclarations . at (topleveltype, toplevelname)) >>= \ case
148
150
Just x -> return ([] , x) -- it is known !
149
- Nothing -> do
150
- -- load the file
151
- getStmtfunc <- view getStatement
152
- liftIO (getStmtfunc topleveltype toplevelname) >>= \ case
153
- S. Right x -> evalTopLevel x
154
- S. Left y -> throwPosError y
151
+ Nothing -> singleton (GetStatement topleveltype toplevelname) >>= evalTopLevel
155
152
156
153
computeCatalog :: T. Text -> InterpreterMonad (FinalCatalog , EdgeMap , FinalCatalog , [Resource ])
157
154
computeCatalog ndename = do
@@ -342,13 +339,12 @@ evaluateStatement r@(ResourceCollection e resType searchExp mods p) = do
342
339
if et == RealizeCollected
343
340
then do
344
341
let q = searchExpressionToPuppetDB resType rsearch
345
- pdb <- view pdbAPI
346
- fqdn <- view thisNodename
342
+ fqdn <- singleton GetNodeName
347
343
-- we must filter the resources that originated from this host
348
344
-- here ! They are also turned into "normal" resources
349
345
res <- ( map (rvirtuality .~ Normal )
350
346
. filter ((/= fqdn) . _rnode)
351
- ) `fmap` interpreterIO (getResources pdb q)
347
+ ) `fmap` singleton ( PDBGetResources q)
352
348
scpdesc <- ContImported `fmap` getScope
353
349
void $ enterScope SENormal scpdesc " importing" p
354
350
pushScope scpdesc
@@ -581,8 +577,8 @@ loadClass :: T.Text
581
577
-> InterpreterMonad [Resource ]
582
578
loadClass rclassname loadedfrom params cincludetype = do
583
579
let classname = dropInitialColons rclassname
584
- ndn <- view thisNodename
585
- liftIO (traceEventIO (' [' : T. unpack ndn ++ " ] loadClass " ++ T. unpack classname))
580
+ ndn <- singleton GetNodeName
581
+ singleton ( TraceEvent (' [' : T. unpack ndn ++ " ] loadClass " ++ T. unpack classname))
586
582
p <- use curPos
587
583
-- check if the class has already been loaded
588
584
-- http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#using-resource-like-declarations
@@ -618,7 +614,7 @@ loadClass rclassname loadedfrom params cincludetype = do
618
614
classresource <- if cincludetype == IncludeStandard
619
615
then do
620
616
scp <- use curScope
621
- fqdn <- view thisNodename
617
+ fqdn <- singleton GetNodeName
622
618
return [Resource (RIdentifier " class" classname) (HS. singleton classname) mempty mempty scp Normal mempty p fqdn]
623
619
else return []
624
620
pushScope scopedesc
@@ -690,7 +686,7 @@ registerResource rt rn arg vrt p = do
690
686
getClassTags (ContImported _ ) = []
691
687
getClassTags (ContImport _ _ ) = []
692
688
allScope <- use curScope
693
- fqdn <- view thisNodename
689
+ fqdn <- singleton GetNodeName
694
690
let baseresource = Resource (RIdentifier rt rn) (HS. singleton rn) mempty mempty allScope vrt defaulttags p fqdn
695
691
r <- foldM (addAttribute CantOverride ) baseresource (itoList arg)
696
692
let resid = RIdentifier rt rn
@@ -770,10 +766,7 @@ mainFunctionCall "hiera_include" _ = throwPosError "hiera_include(): This functi
770
766
mainFunctionCall fname args = do
771
767
p <- use curPos
772
768
let representation = MainFunctionCall fname mempty p
773
- external <- view externalFunctions
774
- rs <- case external ^. at fname of
775
- Just f -> f args
776
- Nothing -> throwPosError (" Unknown function:" <+> pretty representation)
769
+ rs <- singleton (ExternalFunction fname args)
777
770
unless (rs == PUndef ) $ throwPosError (" This function call should return" <+> pretty PUndef <+> " and not" <+> pretty rs <$> pretty representation)
778
771
return []
779
772
-- Method stuff
0 commit comments