@@ -28,7 +28,7 @@ import qualified Data.Graph as G
2828import qualified Data.Tree as T
2929import Data.Foldable (toList ,foldl' ,Foldable ,foldlM )
3030import Data.Traversable (mapM ,forM )
31- import Debug.Trace ( traceEventIO )
31+ import Control.Monad.Operational
3232
3333-- helpers
3434vmapM :: (Monad m , Foldable t ) => (a -> m b ) -> t a -> m [b ]
@@ -40,25 +40,27 @@ vmapM f = mapM f . toList
4040-- (this last one might not be up to date and is only useful for code
4141-- coverage tests)) along with all messages that have been generated by the
4242-- 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
4446 -> (Either T. Text T. Text -> T. Text -> Container ScopeInformation -> IO (S. Either Doc T. Text )) -- ^ compute template function
4547 -> PuppetDBAPI
4648 -> T. Text -- ^ Node name
4749 -> Facts -- ^ Facts ...
4850 -> Container PuppetTypeMethods -- ^ List of native types
4951 -> Container ( [PValue ] -> InterpreterMonad PValue )
5052 -> 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)
5456 let rdr = InterpreterReader nTypes gtStatement gtTemplate pdbQuery extfuncs ndename hquery
5557 dummypos = initialPPos " dummy"
5658 initialclass = mempty & at " ::" ?~ (IncludeStandard :!: dummypos)
5759 stt = InterpreterState baseVars initialclass mempty [ContRoot ] dummypos mempty [] []
5860 factvars = facts & each %~ (\ x -> PString x :!: initialPPos " facts" :!: ContRoot )
5961 callervars = ifromList [(" caller_module_name" , PString " ::" :!: dummypos :!: ContRoot ), (" module_name" , PString " ::" :!: dummypos :!: ContRoot )]
6062 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
6264 return (strictifyEither output :!: warnings)
6365
6466isParent :: T. Text -> CurContainerDesc -> InterpreterMonad Bool
@@ -146,12 +148,7 @@ getstt topleveltype toplevelname = do
146148 -- check if this is a known class (spurious or inner class)
147149 use (nestedDeclarations . at (topleveltype, toplevelname)) >>= \ case
148150 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
155152
156153computeCatalog :: T. Text -> InterpreterMonad (FinalCatalog , EdgeMap , FinalCatalog , [Resource ])
157154computeCatalog ndename = do
@@ -342,13 +339,12 @@ evaluateStatement r@(ResourceCollection e resType searchExp mods p) = do
342339 if et == RealizeCollected
343340 then do
344341 let q = searchExpressionToPuppetDB resType rsearch
345- pdb <- view pdbAPI
346- fqdn <- view thisNodename
342+ fqdn <- singleton GetNodeName
347343 -- we must filter the resources that originated from this host
348344 -- here ! They are also turned into "normal" resources
349345 res <- ( map (rvirtuality .~ Normal )
350346 . filter ((/= fqdn) . _rnode)
351- ) `fmap` interpreterIO (getResources pdb q)
347+ ) `fmap` singleton ( PDBGetResources q)
352348 scpdesc <- ContImported `fmap` getScope
353349 void $ enterScope SENormal scpdesc " importing" p
354350 pushScope scpdesc
@@ -581,8 +577,8 @@ loadClass :: T.Text
581577 -> InterpreterMonad [Resource ]
582578loadClass rclassname loadedfrom params cincludetype = do
583579 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))
586582 p <- use curPos
587583 -- check if the class has already been loaded
588584 -- http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#using-resource-like-declarations
@@ -618,7 +614,7 @@ loadClass rclassname loadedfrom params cincludetype = do
618614 classresource <- if cincludetype == IncludeStandard
619615 then do
620616 scp <- use curScope
621- fqdn <- view thisNodename
617+ fqdn <- singleton GetNodeName
622618 return [Resource (RIdentifier " class" classname) (HS. singleton classname) mempty mempty scp Normal mempty p fqdn]
623619 else return []
624620 pushScope scopedesc
@@ -690,7 +686,7 @@ registerResource rt rn arg vrt p = do
690686 getClassTags (ContImported _ ) = []
691687 getClassTags (ContImport _ _ ) = []
692688 allScope <- use curScope
693- fqdn <- view thisNodename
689+ fqdn <- singleton GetNodeName
694690 let baseresource = Resource (RIdentifier rt rn) (HS. singleton rn) mempty mempty allScope vrt defaulttags p fqdn
695691 r <- foldM (addAttribute CantOverride ) baseresource (itoList arg)
696692 let resid = RIdentifier rt rn
@@ -770,10 +766,7 @@ mainFunctionCall "hiera_include" _ = throwPosError "hiera_include(): This functi
770766mainFunctionCall fname args = do
771767 p <- use curPos
772768 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)
777770 unless (rs == PUndef ) $ throwPosError (" This function call should return" <+> pretty PUndef <+> " and not" <+> pretty rs <$> pretty representation)
778771 return []
779772-- Method stuff
0 commit comments