Commit e41f4ba0 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix iallocator crash when no solutions exist

Commit 54365762 added an un-guarded `head' call, which crashes with
“Prelude.head: empty list” when no results exists for the per-instance
allocation/relocation calls.

This patch fixes this, and also adds another check for an unguarded
`head' call during parsing of input data.
parent be811997
......@@ -64,7 +64,9 @@ parseInstance :: NameAssoc -- ^ The node name-to-index association list
parseInstance ktn n a = do
base <- parseBaseInstance n a
nodes <- fromObj "nodes" a
pnode <- readEitherString $ head nodes
pnode <- if null nodes
then Bad $ "empty node list for instance " ++ n
else readEitherString $ head nodes
pidx <- lookupNode ktn n pnode
let snodes = tail nodes
sidx <- (if null snodes then return Node.noSecondary
......@@ -140,8 +142,10 @@ parseData body = do
other -> fail ("Invalid request type '" ++ other ++ "'")
return $ Request rqtype map_n map_i ptags csf
formatRVal :: String -> RqType
-> [Node.AllocElement] -> JSValue
-- | Format the result
formatRVal :: String -> RqType -> [Node.AllocElement] -> JSValue
formatRVal _ _ [] = JSArray []
formatRVal csf (Evacuate _) elems =
let sols = map (\(_, inst, nl) ->
let names = Instance.name inst : map Node.name nl
......@@ -154,7 +158,6 @@ formatRVal csf _ elems =
nodes' = map ((++ csf) . Node.name) nodes
in JSArray $ map (JSString . toJSString) nodes'
-- | Formats the response into a valid IAllocator response message.
formatResponse :: Bool -- ^ Whether the request was successful
-> String -- ^ Information text
......
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