Commit 71375ef7 authored by Iustin Pop's avatar Iustin Pop
Browse files

Extend ClusterData with the cluster instance policy



This attribute is always initialised to the default, and is not (yet)
read/saved in the various backends.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent d02f941e
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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) $
......
......@@ -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 &&
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment