Commit 23f9ab76 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change an internal type from Maybe to list



In preparation for multiple responses, we change from Maybe to List
(both used in the container sense).

This allows us to keep the same workflow for all kind of requests.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
parent 20c891d0
......@@ -73,7 +73,7 @@ import qualified Ganeti.OpCodes as OpCodes
-- * Types
-- | Allocation\/relocation solution.
type AllocSolution = ([FailMode], Int, Maybe (Score, AllocElement))
type AllocSolution = ([FailMode], Int, [(Score, AllocElement)])
-- | Allocation\/relocation element.
type AllocElement = (Node.List, Instance.Instance, [Node.Node])
......@@ -499,11 +499,15 @@ concatAllocs (flst, cntok, osols) (OpGood ns@(nl, _, _)) =
let nscore = compCV nl
-- Choose the old or new solution, based on the cluster score
nsols = case osols of
Nothing -> Just (nscore, ns)
Just (oscore, _) ->
[] -> [(nscore, ns)]
(oscore, _):[] ->
if oscore < nscore
then osols
else Just (nscore, ns)
else [(nscore, ns)]
-- FIXME: here we simply concat to lists with more
-- than one element; we should instead abort, since
-- this is not a valid usage of this function
xs -> (nscore, ns):xs
nsuc = cntok + 1
-- Note: we force evaluation of nsols here in order to keep the
-- memory profile low - we know that we will need nsols for sure
......@@ -525,14 +529,14 @@ tryAlloc nl _ inst 2 =
ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y) all_pairs
sols = foldl' (\cstate (p, s) ->
concatAllocs cstate $ allocateOnPair nl inst p s
) ([], 0, Nothing) ok_pairs
) ([], 0, []) ok_pairs
in return sols
tryAlloc nl _ inst 1 =
let all_nodes = getOnline nl
sols = foldl' (\cstate ->
concatAllocs cstate . allocateOnSingle nl inst
) ([], 0, Nothing) all_nodes
) ([], 0, []) all_nodes
in return sols
tryAlloc _ _ _ reqn = fail $ "Unsupported number of allocation \
......@@ -559,7 +563,7 @@ tryReloc nl il xid 1 ex_idx =
applyMove nl inst (ReplaceSecondary x)
return (mnl, i, [Container.find x mnl])
in concatAllocs cstate em
) ([], 0, Nothing) valid_idxes
) ([], 0, []) valid_idxes
in return sols1
tryReloc _ _ _ reqn _ = fail $ "Unsupported number of relocation \
......
......@@ -50,14 +50,15 @@ options = [oPrintNodes, oShowVer, oShowHelp]
processResults :: (Monad m) => Cluster.AllocSolution -> m (String, [Node.Node])
processResults (fstats, successes, sols) =
case sols of
Nothing -> fail "No valid allocation solutions"
Just (best, (_, _, w)) ->
[] -> fail "No valid allocation solutions"
(best, (_, _, w)):[] ->
let tfails = length fstats
info = printf "successes %d, failures %d,\
\ best score: %.8f for node(s) %s"
successes tfails
best (intercalate "/" . map Node.name $ w)::String
in return (info, w)
_ -> fail "Internal error: multiple allocation solutions"
-- | Process a request and return new node lists
processRequest :: Request
......
......@@ -131,9 +131,11 @@ iterateDepth nl il newinst nreq ixes =
Bad s -> Bad s
Ok (errs, _, sols3) ->
case sols3 of
Nothing -> Ok (Cluster.collapseFailures errs, nl, ixes)
Just (_, (xnl, xi, _)) ->
[] -> Ok (Cluster.collapseFailures errs, nl, ixes)
(_, (xnl, xi, _)):[] ->
iterateDepth xnl il newinst nreq $! (xi:ixes)
_ -> Bad "Internal error: multiple solutions for single\
\ allocation"
tieredAlloc :: Node.List
-> Instance.List
......
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