Revision dd4c56ed

b/src/Rapi.hs
3 3
-}
4 4

  
5 5
module Rapi
6
    where
6
    (
7
      getNodes
8
    , getInstances
9
    ) where
7 10

  
8 11
import Network.Curl
9 12
import Network.Curl.Types ()
b/src/Utils.hs
4 4

  
5 5
import Data.List
6 6
import Data.Either
7
import System
8
import System.IO
9
import Monad
7 10

  
8 11
import Debug.Trace
9 12

  
......
65 68
-- | Coefficient of variation.
66 69
varianceCoeff :: Floating a => [a] -> a
67 70
varianceCoeff lst = (stdDev lst) / (fromIntegral $ length lst)
71

  
72
-- | Get a Right result or print the error and exit
73
readData :: (String -> IO (Either String String)) -> String -> IO String
74
readData fn host = do
75
  nd <- fn host
76
  when (isLeft nd) $
77
       do
78
         putStrLn $ fromLeft nd
79
         exitWith $ ExitFailure 1
80
  return $ fromRight nd
b/src/hbal.hs
121 121
          ioError (userError (concat errs ++ usageInfo header options))
122 122
      where header = "Usage: hbal [OPTION...]"
123 123

  
124
-- | Get a Right result or print the error and exit
125
readData :: (String -> IO (Either String String)) -> String -> IO String
126
readData fn host = do
127
  nd <- fn host
128
  when (isLeft nd) $
129
       do
130
         putStrLn $ fromLeft nd
131
         exitWith $ ExitFailure 1
132
  return $ fromRight nd
133

  
134 124
-- | Main function.
135 125
main :: IO ()
136 126
main = do
b/src/hn1.hs
17 17
import qualified Container
18 18
import qualified Instance
19 19
import qualified Cluster
20
import Utils
21
import Rapi
20 22

  
21 23
-- | Command line options structure.
22 24
data Options = Options
......
28 30
    , optMaxRemovals :: Int
29 31
    , optMinDelta    :: Int
30 32
    , optMaxDelta    :: Int
33
    , optMaster    :: String
31 34
    } deriving Show
32 35

  
33 36
-- | Default values for the command line options.
......
41 44
 , optMaxRemovals = -1
42 45
 , optMinDelta    = 0
43 46
 , optMaxDelta    = -1
47
 , optMaster    = ""
44 48
 }
45 49

  
46 50
{- | Start computing the solution at the given depth and recurse until
......
99 103
     , Option ['l']     ["min-delta"]
100 104
      (ReqArg (\ i opts -> opts { optMinDelta =  (read i)::Int }) "L")
101 105
      "return once a solution with delta L or lower has been found"
106
     , Option ['m']     ["master"]
107
      (ReqArg (\ m opts -> opts { optMaster = m }) "ADDRESS")
108
      "collect data via RAPI at the given ADDRESS"
102 109
     ]
103 110

  
104 111
-- | Command line parser, using the 'options' structure.
......
117 124
  cmd_args <- System.getArgs
118 125
  (opts, _) <- parseOpts cmd_args
119 126
  let min_depth = optMinDepth opts
120
  (nl, il, ktn, kti) <- liftM2 Cluster.loadData
121
                        (readFile $ optNodef opts)
122
                        (readFile $ optInstf opts)
127
  let (node_data, inst_data) =
128
          case optMaster opts of
129
            "" -> (readFile $ optNodef opts,
130
                   readFile $ optInstf opts)
131
            host -> (readData getNodes host,
132
                     readData getInstances host)
133

  
134
  (nl, il, ktn, kti) <- liftM2 Cluster.loadData node_data inst_data
135

  
123 136
  printf "Loaded %d nodes, %d instances\n"
124 137
             (Container.size nl)
125 138
             (Container.size il)

Also available in: Unified diff