Commit 5e15f460 authored by Iustin Pop's avatar Iustin Pop
Browse files

hail: Implement non-mirrored instance allocation

This patch implements non-mirrored instance allocation, by allocating as
secondary node “noSecondary”.
parent f826c5e0
......@@ -34,7 +34,8 @@ module Ganeti.HTools.Cluster
, compCV
, printStats
-- * IAllocator functions
, allocateOn
, allocateOnSingle
, allocateOnPair
) where
import Data.List
......@@ -409,10 +410,19 @@ applyMove nl inst (FailoverAndReplace new_sdx) =
Container.addTwo old_sdx new_p old_pdx int_p nl
in (new_nl, Instance.setBoth inst old_sdx new_sdx, old_sdx, new_sdx)
allocateOn nl inst new_pdx new_sdx =
let
tgt_p = Container.find new_pdx nl
tgt_s = Container.find new_sdx nl
allocateOnSingle :: NodeList -> Instance.Instance -> Node.Node
-> (Maybe NodeList, Instance.Instance)
allocateOnSingle nl inst p =
let new_pdx = Node.idx p
new_nl = Node.addPri p inst >>= \new_p ->
return $ Container.add new_pdx new_p nl
in (new_nl, Instance.setBoth inst new_pdx Node.noSecondary)
allocateOnPair :: NodeList -> Instance.Instance -> Node.Node -> Node.Node
-> (Maybe NodeList, Instance.Instance)
allocateOnPair nl inst tgt_p tgt_s =
let new_pdx = Node.idx tgt_p
new_sdx = Node.idx tgt_s
new_nl = do -- Maybe monad
new_p <- Node.addPri tgt_p inst
new_s <- Node.addSec tgt_s inst new_pdx
......
......@@ -21,7 +21,6 @@ import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance
import qualified Ganeti.HTools.CLI as CLI
import Ganeti.HTools.IAlloc
import Ganeti.HTools.Utils
import Ganeti.HTools.Types
-- | Command line options structure.
......@@ -120,17 +119,20 @@ tryAlloc :: (Monad m) =>
-> Instance.Instance
-> Int
-> m [(Maybe NodeList, [Node.Node])]
tryAlloc nl il inst 2 =
tryAlloc nl _ inst 2 =
let all_nodes = Container.elems nl
all_pairs = liftM2 (,) all_nodes all_nodes
ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y) all_pairs
sols1 = map (\(p, s) -> let pdx = Node.idx p
sdx = Node.idx s
(mnl, _) = Cluster.allocateOn nl
inst pdx sdx
in (mnl, [p, s])
) ok_pairs
in return sols1
sols = map (\(p, s) ->
(fst $ Cluster.allocateOnPair nl inst p s, [p, s]))
ok_pairs
in return sols
tryAlloc nl _ inst 1 =
let all_nodes = Container.elems nl
sols = map (\p -> (fst $ Cluster.allocateOnSingle nl inst p, [p]))
all_nodes
in return sols
tryAlloc _ _ _ reqn = fail $ "Unsupported number of alllocation \
\destinations required (" ++ (show reqn) ++
......@@ -180,8 +182,8 @@ processResults sols =
sols'' = sortBy (compare `on` fst) sols'
(best, w) = head sols''
(worst, l) = last sols''
info = printf "Valid results: %d, best score: %.8f (nodes %s), \
\worst score: %.8f (nodes %s)" (length sols'')
info = printf "Valid results: %d, best score: %.8f for node(s) %s, \
\worst score: %.8f for node(s) %s" (length sols'')
best (intercalate "/" . map Node.name $ w)
worst (intercalate "/" . map Node.name $ l)
in return (info, w)
......
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