Commit 57587760 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.
(cherry picked from commit e41f4ba0)
parent 934c62dc
...@@ -64,7 +64,9 @@ parseInstance :: NameAssoc -- ^ The node name-to-index association list ...@@ -64,7 +64,9 @@ parseInstance :: NameAssoc -- ^ The node name-to-index association list
parseInstance ktn n a = do parseInstance ktn n a = do
base <- parseBaseInstance n a base <- parseBaseInstance n a
nodes <- fromObj "nodes" 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 pidx <- lookupNode ktn n pnode
let snodes = tail nodes let snodes = tail nodes
sidx <- (if null snodes then return Node.noSecondary sidx <- (if null snodes then return Node.noSecondary
...@@ -141,8 +143,10 @@ parseData body = do ...@@ -141,8 +143,10 @@ parseData body = do
other -> fail ("Invalid request type '" ++ other ++ "'") other -> fail ("Invalid request type '" ++ other ++ "'")
return $ Request rqtype map_n map_i ptags csf return $ Request rqtype map_n map_i ptags csf
formatRVal :: String -> RqType -- | Format the result
-> [Node.AllocElement] -> JSValue formatRVal :: String -> RqType -> [Node.AllocElement] -> JSValue
formatRVal _ _ [] = JSArray []
formatRVal csf (Evacuate _) elems = formatRVal csf (Evacuate _) elems =
let sols = map (\(_, inst, nl) -> let sols = map (\(_, inst, nl) ->
let names = Instance.name inst : map Node.name nl let names = Instance.name inst : map Node.name nl
...@@ -155,7 +159,6 @@ formatRVal csf _ elems = ...@@ -155,7 +159,6 @@ formatRVal csf _ elems =
nodes' = map ((++ csf) . Node.name) nodes nodes' = map ((++ csf) . Node.name) nodes
in JSArray $ map (JSString . toJSString) nodes' in JSArray $ map (JSString . toJSString) nodes'
-- | Formats the response into a valid IAllocator response message. -- | Formats the response into a valid IAllocator response message.
formatResponse :: Bool -- ^ Whether the request was successful formatResponse :: Bool -- ^ Whether the request was successful
-> String -- ^ Information text -> 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