From d6cf394e1a166debf69ccee371e7010464bddc79 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sat, 2 Jul 2011 09:29:50 +0200 Subject: [PATCH] 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: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htools/Ganeti/HTools/IAlloc.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htools/Ganeti/HTools/IAlloc.hs b/htools/Ganeti/HTools/IAlloc.hs index 20bb51509..05a807b56 100644 --- a/htools/Ganeti/HTools/IAlloc.hs +++ b/htools/Ganeti/HTools/IAlloc.hs @@ -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 -- GitLab