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

htools: start reorganising the IAllocator workflow



Currently, all IAllocator requests return the same result type: a list
of strings (usually nodes, but can also be instance:nodes). This won't
be true in the future, with the new request types that will return
opcode lists.

Therefore we will need to support multiple result types in the
workflow; the first step is to make the final formatResponse step
result-type-indepedent, so we take out the formatRVal invocation out
of this function.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 00152519
......@@ -231,17 +231,16 @@ formatRVal _ elems =
nodes' = map Node.name nodes
in JSArray $ map (JSString . toJSString) nodes'
-- | Formats the response into a valid IAllocator response message.
-- | Formats the result into a valid IAllocator response message.
formatResponse :: Bool -- ^ Whether the request was successful
-> String -- ^ Information text
-> RqType -- ^ Request type
-> [Node.AllocElement] -- ^ The resulting allocations
-> String -- ^ The JSON-formatted message
formatResponse success info rq elems =
-> JSValue -- ^ The JSON encoded result
-> String -- ^ The full JSON-formatted message
formatResponse success info result =
let
e_success = ("success", JSBool success)
e_info = ("info", JSString . toJSString $ info)
e_result = ("result", formatRVal rq elems)
e_result = ("result", result)
in encodeStrict $ makeObj [e_success, e_info, e_result]
processResults :: (Monad m) =>
......@@ -302,5 +301,6 @@ runIAllocator request =
intercalate ", " (Cluster.asLog as),
Cluster.asSolutions as)
Bad s -> (False, "Request failed: " ++ s, [])
resp = formatResponse ok info rq rn
result = formatRVal rq rn
resp = formatResponse ok info result
in resp
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