Querying collectors might fail and for some collectors
the information might be incomplete. In this case, it might
be useful to continue with he information available, but this
is not necessarily the case. Therefore, provide the information
if the dynamic data collection was successful.

Signed-off-by: Klaus Aehlig <[email protected]>
---
 src/Ganeti/HTools/Backend/MonD.hs | 22 ++++++++++++++--------
 src/Ganeti/HTools/ExtLoader.hs    |  7 ++++---
 src/Ganeti/HTools/Program/Hail.hs |  6 ++++--
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/Ganeti/HTools/Backend/MonD.hs 
b/src/Ganeti/HTools/Backend/MonD.hs
index bc85ff4..744d52d 100644
--- a/src/Ganeti/HTools/Backend/MonD.hs
+++ b/src/Ganeti/HTools/Backend/MonD.hs
@@ -44,6 +44,7 @@ module Ganeti.HTools.Backend.MonD
   ) where
 
 import Control.Monad
+import Control.Monad.Writer
 import qualified Data.List as L
 import qualified Data.IntMap as IntMap
 import qualified Data.Map as Map
@@ -67,7 +68,7 @@ import Ganeti.HTools.Loader (ClusterData(..))
 import Ganeti.HTools.Types
 import Ganeti.HTools.CLI
 import Ganeti.JSON
-import Ganeti.Logging (logWarning)
+import Ganeti.Logging.Lifted (logWarning)
 import Ganeti.Utils (exitIfBad)
 
 -- * General definitions
@@ -265,11 +266,12 @@ queryAMonD m dc node =
       Nothing -> fromCurl dc node
       Just m' -> return $ fromFile dc node m'
 
--- | Query all MonDs for a single Data Collector.
+-- | Query all MonDs for a single Data Collector. Return the updated
+-- cluster, as well as a bit inidicating wether the collector succeeded.
 queryAllMonDs :: Maybe MapMonDData -> (Node.List, Instance.List)
-                 -> DataCollector -> IO (Node.List, Instance.List)
+                 -> DataCollector -> WriterT All IO (Node.List, Instance.List)
 queryAllMonDs m (nl, il) dc = do
-  elems <- mapM (queryAMonD m dc) (Container.elems nl)
+  elems <- liftIO $ mapM (queryAMonD m dc) (Container.elems nl)
   let elems' = catMaybes elems
   if length elems == length elems'
     then
@@ -278,21 +280,25 @@ queryAllMonDs m (nl, il) dc = do
         Ok (nl', il') -> return (nl', il')
         Bad s -> do
           logWarning s
+          tell $ All False
           return (nl, il)
     else do
       logWarning $ "Didn't receive an answer by all MonDs, " ++ dName dc
                    ++ "'s data will be ignored."
+      tell $ All False
       return (nl,il)
 
--- | Query all MonDs for all Data Collector.
-queryAllMonDDCs :: ClusterData -> Options -> IO ClusterData
+-- | Query all MonDs for all Data Collector. Return the cluster enriched
+-- by dynamic data, as well as a bit indicating wether all collectors
+-- could be queried successfully.
+queryAllMonDDCs :: ClusterData -> Options -> WriterT All IO ClusterData
 queryAllMonDDCs cdata opts = do
   map_mDD <-
     case optMonDFile opts of
       Nothing -> return Nothing
       Just fp -> do
-        monDData_contents <- readFile fp
-        monDData <- exitIfBad "can't parse MonD data"
+        monDData_contents <- liftIO $ readFile fp
+        monDData <- liftIO . exitIfBad "can't parse MonD data"
                     . pMonDData $ monDData_contents
         return . Just $ Map.fromList monDData
   let (ClusterData _ nl il _ _) = cdata
diff --git a/src/Ganeti/HTools/ExtLoader.hs b/src/Ganeti/HTools/ExtLoader.hs
index cdc81eb..aebaeb3 100644
--- a/src/Ganeti/HTools/ExtLoader.hs
+++ b/src/Ganeti/HTools/ExtLoader.hs
@@ -43,6 +43,7 @@ module Ganeti.HTools.ExtLoader
   ) where
 
 import Control.Monad
+import Control.Monad.Writer (runWriterT)
 import Control.Exception
 import Data.Maybe (isJust, fromJust)
 import System.FilePath
@@ -124,9 +125,9 @@ loadExternalData opts = do
       ldresult = input_data >>= (if ignoreDynU then clearDynU else return)
                             >>= mergeData eff_u exTags selInsts exInsts now
   cdata <- exitIfBad "failed to load data, aborting" ldresult
-  cdata' <- if optMonD opts
-              then MonD.queryAllMonDDCs cdata opts
-              else return cdata
+  (cdata', _) <- runWriterT $ if optMonD opts
+                                then MonD.queryAllMonDDCs cdata opts
+                                else return cdata
   let (fix_msgs, nl) = checkData (cdNodes cdata') (cdInstances cdata')
 
   unless (optVerbose opts == 0) $ maybeShowWarnings fix_msgs
diff --git a/src/Ganeti/HTools/Program/Hail.hs 
b/src/Ganeti/HTools/Program/Hail.hs
index 2a398ad..db1be29 100644
--- a/src/Ganeti/HTools/Program/Hail.hs
+++ b/src/Ganeti/HTools/Program/Hail.hs
@@ -39,6 +39,7 @@ module Ganeti.HTools.Program.Hail
   ) where
 
 import Control.Monad
+import Control.Monad.Writer (runWriterT)
 import Data.Maybe (fromMaybe, isJust)
 import System.IO
 
@@ -87,8 +88,9 @@ wrapReadRequest opts args = do
       return $ Request rqt cdata
     else do
       let Request rqt cdata = r1
-      cdata' <-
-        if optMonD opts then MonD.queryAllMonDDCs cdata opts else return cdata
+      (cdata', _) <- runWriterT $ if optMonD opts
+                                    then MonD.queryAllMonDDCs cdata opts
+                                    else return cdata
       return $ Request rqt cdata'
 
 -- | Main function.
-- 
2.2.0.rc0.207.ga3a616c

Reply via email to