Extend ClusterData with the cluster instance policy
authorIustin Pop <iustin@google.com>
Fri, 23 Dec 2011 10:38:38 +0000 (11:38 +0100)
committerIustin Pop <iustin@google.com>
Fri, 13 Jan 2012 13:16:24 +0000 (14:16 +0100)
This attribute is always initialised to the default, and is not (yet)
read/saved in the various backends.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

htools/Ganeti/HTools/IAlloc.hs
htools/Ganeti/HTools/Loader.hs
htools/Ganeti/HTools/Luxi.hs
htools/Ganeti/HTools/Program/Hbal.hs
htools/Ganeti/HTools/Program/Hscan.hs
htools/Ganeti/HTools/Program/Hspace.hs
htools/Ganeti/HTools/QC.hs
htools/Ganeti/HTools/Rapi.hs
htools/Ganeti/HTools/Simu.hs
htools/Ganeti/HTools/Text.hs

index 26b7ea6..cbec6a9 100644 (file)
@@ -158,7 +158,7 @@ parseData body = do
   let (kti, il) = assignIndices iobj
   -- cluster tags
   ctags <- extrObj "cluster_tags"
-  cdata1 <- mergeData [] [] [] [] (ClusterData gl nl il ctags)
+  cdata1 <- mergeData [] [] [] [] (ClusterData gl nl il ctags defIPolicy)
   let (msgs, fix_nl) = checkData (cdNodes cdata1) (cdInstances cdata1)
       cdata = cdata1 { cdNodes = fix_nl }
       map_n = cdNodes cdata
@@ -307,7 +307,7 @@ formatRelocate (nl, il, ndxs) =
 -- | Process a request and return new node lists.
 processRequest :: Request -> Result IAllocResult
 processRequest request =
-  let Request rqtype (ClusterData gl nl il _) = request
+  let Request rqtype (ClusterData gl nl il _ _) = request
   in case rqtype of
        Allocate xi reqn ->
          Cluster.tryMGAlloc gl nl il xi reqn >>= formatAllocate il
index a9c9e0e..7d76038 100644 (file)
@@ -90,6 +90,7 @@ data ClusterData = ClusterData
   , cdNodes     :: Node.List     -- ^ The node list
   , cdInstances :: Instance.List -- ^ The instance list
   , cdTags      :: [String]      -- ^ The cluster tags
+  , cdIPolicy   :: IPolicy       -- ^ The cluster instance policy
   } deriving (Show, Read)
 
 -- | The priority of a match in a lookup result.
@@ -116,6 +117,7 @@ instance Ord LookupResult where
 -- | An empty cluster.
 emptyCluster :: ClusterData
 emptyCluster = ClusterData Container.empty Container.empty Container.empty []
+                 defIPolicy
 
 -- * Functions
 
@@ -267,7 +269,7 @@ mergeData :: [(String, DynUtil)]  -- ^ Instance utilisation data
           -> [String]             -- ^ Excluded instances
           -> ClusterData          -- ^ Data from backends
           -> Result ClusterData   -- ^ Fixed cluster data
-mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags) =
+mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags _) =
   let il = Container.elems il2
       il3 = foldl' (\im (name, n_util) ->
                         case Container.findByName im name of
index 744aa05..d360390 100644 (file)
@@ -249,7 +249,7 @@ parseData (groups, nodes, instances, cinfo) = do
   inst_data <- instances >>= getInstances node_names
   let (_, inst_idx) = assignIndices inst_data
   ctags <- cinfo >>= getClusterTags
-  return (ClusterData group_idx node_idx inst_idx ctags)
+  return (ClusterData group_idx node_idx inst_idx ctags defIPolicy)
 
 -- | Top level function for data loading.
 loadData :: String -- ^ Unix socket to use as source
index e702733..758b890 100644 (file)
@@ -351,7 +351,7 @@ main = do
       shownodes = optShowNodes opts
       showinsts = optShowInsts opts
 
-  ini_cdata@(ClusterData gl fixed_nl ilf ctags) <- loadExternalData opts
+  ini_cdata@(ClusterData gl fixed_nl ilf ctags _) <- loadExternalData opts
 
   when (verbose > 1) $
        putStrLn $ "Loaded cluster tags: " ++ intercalate "," ctags
@@ -412,7 +412,7 @@ main = do
        saveBalanceCommands opts $ Cluster.formatCmds cmd_jobs
 
   maybeSaveData (optSaveCluster opts) "balanced" "after balancing"
-                (ClusterData gl fin_nl fin_il ctags)
+                ini_cdata { cdNodes = fin_nl, cdInstances = fin_il }
 
   maybePrintInsts showinsts "Final" (Cluster.printInsts fin_nl fin_il)
 
index acdf7e8..cac708f 100644 (file)
@@ -82,7 +82,7 @@ fixSlash = map (\x -> if x == '/' then '_' else x)
 -- | Generates serialized data from loader input.
 processData :: ClusterData -> Result ClusterData
 processData input_data = do
-  cdata@(ClusterData _ nl il _) <- mergeData [] [] [] [] input_data
+  cdata@(ClusterData _ nl il _ _) <- mergeData [] [] [] [] input_data
   let (_, fix_nl) = checkData nl il
   return cdata { cdNodes = fix_nl }
 
@@ -111,7 +111,7 @@ writeDataInner :: Int
                -> ClusterData
                -> IO Bool
 writeDataInner nlen name opts cdata fixdata = do
-  let (ClusterData _ nl il _) = fixdata
+  let (ClusterData _ nl il _ _) = fixdata
   printf "%-*s " nlen name :: IO ()
   hFlush stdout
   let shownodes = optShowNodes opts
index 3248a98..81c8098 100644 (file)
@@ -397,12 +397,12 @@ main = do
       req_nodes = Instance.requiredNodes disk_template
       machine_r = optMachineReadable opts
 
-  (ClusterData gl fixed_nl il ctags) <- loadExternalData opts
+  orig_cdata@(ClusterData gl fixed_nl il _ _) <- loadExternalData opts
   nl <- setNodeStatus opts fixed_nl
 
   let num_instances = Container.size il
       all_nodes = Container.elems fixed_nl
-      cdata = ClusterData gl nl il ctags
+      cdata = orig_cdata { cdNodes = fixed_nl }
       csf = commonSuffix fixed_nl il
 
   when (not (null csf) && verbose > 1) $
index 4f749b6..f80ebd7 100644 (file)
@@ -1035,7 +1035,7 @@ prop_Loader_mergeData ns =
   in case Loader.mergeData [] [] [] []
          (Loader.emptyCluster {Loader.cdNodes = na}) of
     Types.Bad _ -> False
-    Types.Ok (Loader.ClusterData _ nl il _) ->
+    Types.Ok (Loader.ClusterData _ nl il _ _) ->
       let nodes = Container.elems nl
           instances = Container.elems il
       in (sum . map (length . Node.pList)) nodes == 0 &&
index 8031964..c6cb648 100644 (file)
@@ -183,7 +183,7 @@ parseData (group_body, node_body, inst_body, tags_body) = do
   inst_data <- inst_body >>= getInstances node_names
   let (_, inst_idx) = assignIndices inst_data
   tags_data <- tags_body >>= (fromJResult "Parsing tags data" . decodeStrict)
-  return (ClusterData group_idx node_idx inst_idx tags_data)
+  return (ClusterData group_idx node_idx inst_idx tags_data defIPolicy)
 
 -- | Top level function for data loading.
 loadData :: String -- ^ Cluster or URL to use as source
index dc488de..42f4625 100644 (file)
@@ -91,7 +91,7 @@ parseData ndata = do
             $ zip [1..] nodes'
       ktg = map (\g -> (Group.idx g, g)) groups
   return (ClusterData (Container.fromList ktg)
-                      (Container.fromList ktn) Container.empty [])
+                      (Container.fromList ktn) Container.empty [] defIPolicy)
 
 -- | Builds the cluster data from node\/instance files.
 loadData :: [String] -- ^ Cluster description in text format
index ab3d078..9a08c2e 100644 (file)
@@ -104,7 +104,7 @@ serializeInstances nl =
 
 -- | Generate complete cluster data from node and instance lists.
 serializeCluster :: ClusterData -> String
-serializeCluster (ClusterData gl nl il ctags) =
+serializeCluster (ClusterData gl nl il ctags _) =
   let gdata = serializeGroups gl
       ndata = serializeNodes gl nl
       idata = serializeInstances nl il
@@ -221,7 +221,7 @@ parseData fdata = do
   {- instance file: name mem disk status pnode snode -}
   (_, il) <- loadTabular ilines (loadInst ktn)
   {- the tags are simply line-based, no processing needed -}
-  return (ClusterData gl nl il ctags)
+  return (ClusterData gl nl il ctags defIPolicy)
 
 -- | Top level function for data loading.
 loadData :: String -- ^ Path to the text file