Commit 94e05c32 authored by Iustin Pop's avatar Iustin Pop
Browse files

Introduce support for reading the cluster tags

While these are not actually populated from the backends, and all the
programs ignore them, this patch contains the changes in the function
types required.
parent 185297fa
......@@ -83,7 +83,7 @@ parseUtilisation line =
-- | External tool data loader from a variety of sources.
loadExternalData :: Options
-> IO (Node.List, Instance.List, String)
-> IO (Node.List, Instance.List, [String], String)
loadExternalData opts = do
(env_node, env_inst) <- parseEnv ()
let nodef = if optNodeSet opts then optNodeFile opts
......@@ -131,7 +131,7 @@ loadExternalData opts = do
| otherwise -> wrapIO $ Text.loadData nodef instf
let ldresult = input_data >>= Loader.mergeData util_data' exTags
(loaded_nl, il, csf) <-
(loaded_nl, il, tags, csf) <-
(case ldresult of
Ok x -> return x
Bad s -> do
......@@ -144,4 +144,4 @@ loadExternalData opts = do
hPutStrLn stderr "Warning: cluster has inconsistent data:"
hPutStrLn stderr . unlines . map (printf " - %s") $ fix_msgs
return (fixed_nl, il, csf)
return (fixed_nl, il, tags, csf)
......@@ -110,7 +110,7 @@ parseData body = do
iobj <- mapM (\(x,y) ->
asJSObject y >>= parseInstance ktn x . fromJSObject) idata
let (kti, il) = assignIndices iobj
(map_n, map_i, csf) <- mergeData [] [] (nl, il)
(map_n, map_i, _, csf) <- mergeData [] [] (nl, il, [])
req_nodes <- fromObj "required_nodes" request
optype <- fromObj "type" request
rqtype <-
......
......@@ -140,11 +140,10 @@ stripSuffix sflen name = take (length name - sflen) name
-- list and massages it into the correct format.
mergeData :: [(String, DynUtil)] -- ^ Instance utilisation data
-> [String] -- ^ Exclusion tags
-> (Node.AssocList,
Instance.AssocList) -- ^ Data from either Text.loadData
-- or Rapi.loadData
-> Result (Node.List, Instance.List, String)
mergeData um extags (nl, il) =
-> (Node.AssocList, Instance.AssocList, [String])
-- ^ Data from backends
-> Result (Node.List, Instance.List, [String], String)
mergeData um extags (nl, il, tags) =
let il2 = Container.fromAssocList il
il3 = foldl' (\im (name, n_util) ->
case Container.findByName im name of
......@@ -163,7 +162,7 @@ mergeData um extags (nl, il) =
csl = length common_suffix
snl = Container.map (\n -> setName n (stripSuffix csl $ nameOf n)) nl3
sil = Container.map (\i -> setName i (stripSuffix csl $ nameOf i)) il4
in Ok (snl, sil, common_suffix)
in Ok (snl, sil, tags, common_suffix)
-- | Checks the cluster data for consistency.
checkData :: Node.List -> Instance.List
......
......@@ -144,7 +144,7 @@ parseNode v = fail ("Invalid node query result: " ++ show v)
-- | Builds the cluster data from an URL.
loadData :: String -- ^ Unix socket to use as source
-> IO (Result (Node.AssocList, Instance.AssocList))
-> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData master =
E.bracket
(L.getClient master)
......@@ -157,5 +157,5 @@ loadData master =
let (node_names, node_idx) = assignIndices node_data
inst_data <- instances >>= getInstances node_names
let (_, inst_idx) = assignIndices inst_data
return (node_idx, inst_idx)
return (node_idx, inst_idx, [])
)
......@@ -114,7 +114,7 @@ parseNode a = do
-- | Builds the cluster data from an URL.
loadData :: String -- ^ Cluster or URL to use as source
-> IO (Result (Node.AssocList, Instance.AssocList))
-> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData master = do -- IO monad
let url = formatHost master
node_body <- getUrl $ printf "%s/2/nodes?bulk=1" url
......@@ -124,4 +124,4 @@ loadData master = do -- IO monad
let (node_names, node_idx) = assignIndices node_data
inst_data <- inst_body >>= getInstances node_names
let (_, inst_idx) = assignIndices inst_data
return (node_idx, inst_idx)
return (node_idx, inst_idx, [])
......@@ -52,7 +52,7 @@ parseDesc desc =
-- | Builds the cluster data from node\/instance files.
loadData :: String -- ^ Cluster description in text format
-> IO (Result (Node.AssocList, Instance.AssocList))
-> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData ndata = -- IO monad, just for consistency with the other loaders
return $ do
(cnt, disk, mem, cpu) <- parseDesc ndata
......@@ -63,4 +63,4 @@ loadData ndata = -- IO monad, just for consistency with the other loaders
(fromIntegral cpu) False
in (idx, Node.setIdx n idx)
) [1..cnt]
return (nodes, [])
return (nodes, [], [])
......@@ -91,7 +91,7 @@ loadTabular text_data convert_fn = do
-- | Builds the cluster data from node\/instance files.
loadData :: String -- ^ Node data in string format
-> String -- ^ Instance data in string format
-> IO (Result (Node.AssocList, Instance.AssocList))
-> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData nfile ifile = do -- IO monad
ndata <- readFile nfile
idata <- readFile ifile
......@@ -100,4 +100,4 @@ loadData nfile ifile = do -- IO monad
(ktn, nl) <- loadTabular ndata loadNode
{- instance file: name mem disk status pnode snode -}
(_, il) <- loadTabular idata (loadInst ktn)
return (nl, il)
return (nl, il, [])
......@@ -187,7 +187,7 @@ main = do
verbose = optVerbose opts
shownodes = optShowNodes opts
(fixed_nl, il, csf) <- loadExternalData opts
(fixed_nl, il, _, csf) <- loadExternalData opts
let offline_names = optOffline opts
all_nodes = Container.elems fixed_nl
......
......@@ -142,7 +142,7 @@ main = do
Bad err -> printf "\nError: failed to load data. \
\Details:\n%s\n" err
Ok x -> do
let (nl, il, csf) = x
let (nl, il, _, csf) = x
(_, fix_nl) = Loader.checkData nl il
putStrLn $ printCluster fix_nl il
when (isJust shownodes) $
......
......@@ -216,7 +216,7 @@ main = do
ispec = optISpec opts
shownodes = optShowNodes opts
(fixed_nl, il, csf) <- loadExternalData opts
(fixed_nl, il, _, csf) <- loadExternalData opts
printKeys $ map (\(a, fn) -> ("SPEC_" ++ a, fn ispec)) specData
printKeys [ ("SPEC_RQN", printf "%d" (optINodes opts)) ]
......
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