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

htools: split more code from hail/main



The logic of request processing is not separated into its own
function, and (beside CLI interaction, e.g. verbosity handling) all
logic is now in IAllocator.hs.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent cabce2f4
...@@ -24,15 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ...@@ -24,15 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-} -}
module Ganeti.HTools.IAlloc module Ganeti.HTools.IAlloc
( parseData ( readRequest
, formatResponse , runIAllocator
, readRequest
, processRequest
, processResults
) where ) where
import Data.Either () import Data.Either ()
import Data.Maybe (fromMaybe, isJust, fromJust) import Data.Maybe (fromMaybe, isJust)
import Data.List import Data.List
import Control.Monad import Control.Monad
import Text.JSON (JSObject, JSValue(JSBool, JSString, JSArray), import Text.JSON (JSObject, JSValue(JSBool, JSString, JSArray),
...@@ -293,3 +290,17 @@ readRequest opts args = do ...@@ -293,3 +290,17 @@ readRequest opts args = do
let Request rqt _ = r1 let Request rqt _ = r1
return $ Request rqt cdata return $ Request rqt cdata
else return r1) else return r1)
-- | Main iallocator pipeline.
runIAllocator :: Request -> String
runIAllocator request =
let Request rq _ = request
sols = processRequest request >>= processResults rq
(ok, info, rn) =
case sols of
Ok as -> (True, "Request successful: " ++
intercalate ", " (Cluster.asLog as),
Cluster.asSolutions as)
Bad s -> (False, "Request failed: " ++ s, [])
resp = formatResponse ok info rq rn
in resp
...@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ...@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Main (main) where module Main (main) where
import Control.Monad import Control.Monad
import Data.List
import Data.Maybe (isJust, fromJust) import Data.Maybe (isJust, fromJust)
import System.IO import System.IO
import qualified System import qualified System
...@@ -35,7 +34,6 @@ import qualified Ganeti.HTools.Cluster as Cluster ...@@ -35,7 +34,6 @@ import qualified Ganeti.HTools.Cluster as Cluster
import Ganeti.HTools.CLI import Ganeti.HTools.CLI
import Ganeti.HTools.IAlloc import Ganeti.HTools.IAlloc
import Ganeti.HTools.Types
import Ganeti.HTools.Loader (Request(..), ClusterData(..)) import Ganeti.HTools.Loader (Request(..), ClusterData(..))
-- | Options list and functions -- | Options list and functions
...@@ -73,12 +71,5 @@ main = do ...@@ -73,12 +71,5 @@ main = do
hPutStrLn stderr $ Cluster.printNodes (cdNodes cdata) hPutStrLn stderr $ Cluster.printNodes (cdNodes cdata)
(fromJust shownodes) (fromJust shownodes)
let sols = processRequest request >>= processResults rq let resp = runIAllocator request
let (ok, info, rn) =
case sols of
Ok as -> (True, "Request successful: " ++
intercalate ", " (Cluster.asLog as),
Cluster.asSolutions as)
Bad s -> (False, "Request failed: " ++ s, [])
resp = formatResponse ok info rq rn
putStrLn resp putStrLn 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