Revision c4bf507b src/Ganeti/Query/Query.hs
b/src/Ganeti/Query/Query.hs | ||
---|---|---|
4 | 4 |
|
5 | 5 |
{- |
6 | 6 |
|
7 |
Copyright (C) 2012 Google Inc. |
|
7 |
Copyright (C) 2012, 2013 Google Inc.
|
|
8 | 8 |
|
9 | 9 |
This program is free software; you can redistribute it and/or modify |
10 | 10 |
it under the terms of the GNU General Public License as published by |
... | ... | |
67 | 67 |
import Ganeti.JSON |
68 | 68 |
import Ganeti.Objects |
69 | 69 |
import Ganeti.Query.Common |
70 |
import qualified Ganeti.Query.Export as Export |
|
70 | 71 |
import Ganeti.Query.Filter |
71 | 72 |
import qualified Ganeti.Query.Job as Query.Job |
72 | 73 |
import Ganeti.Query.Group |
... | ... | |
117 | 118 |
-- | Computes the name field for different query types. |
118 | 119 |
nameField :: ItemType -> FilterField |
119 | 120 |
nameField (ItemTypeLuxi QRJob) = "id" |
121 |
nameField (ItemTypeOpCode QRExport) = "node" |
|
120 | 122 |
nameField _ = "name" |
121 | 123 |
|
122 | 124 |
-- | Extracts all quoted strings from a list, ignoring the |
... | ... | |
215 | 217 |
fnetworks |
216 | 218 |
return QueryResult { qresFields = fdefs, qresData = fdata } |
217 | 219 |
|
220 |
queryInner cfg live (Query (ItemTypeOpCode QRExport) fields qfilter) wanted = |
|
221 |
runResultT $ do |
|
222 |
cfilter <- resultT $ compileFilter Export.fieldsMap qfilter |
|
223 |
let selected = getSelectedFields Export.fieldsMap fields |
|
224 |
(fdefs, fgetters, _) = unzip3 selected |
|
225 |
-- we alwyas have live queries in exports, but we keep this for |
|
226 |
-- standard style (in case we add static fields in the future) |
|
227 |
live' = live && needsLiveData fgetters |
|
228 |
nodes <- resultT $ case wanted of |
|
229 |
[] -> Ok . niceSortKey nodeName . |
|
230 |
Map.elems . fromContainer $ configNodes cfg |
|
231 |
_ -> mapM (getNode cfg) wanted |
|
232 |
-- runs first pass of the filter, without a runtime context; this |
|
233 |
-- will limit the nodes that we'll contact for exports |
|
234 |
fnodes <- resultT $ filterM (\n -> evaluateFilter cfg Nothing n cfilter) |
|
235 |
nodes |
|
236 |
-- here we would run the runtime data gathering... |
|
237 |
nruntimes <- lift $ Export.collectLiveData live' cfg fnodes |
|
238 |
-- ... then filter again the results, based on existing export |
|
239 |
-- names, but note that no client sends filters on the export list |
|
240 |
-- today, so it's likely a no-oop |
|
241 |
let fdata = map (\(node, nrt) -> map (execGetter cfg nrt node) fgetters) |
|
242 |
nruntimes |
|
243 |
return QueryResult { qresFields = fdefs, qresData = fdata } |
|
244 |
|
|
218 | 245 |
queryInner _ _ (Query qkind _ _) _ = |
219 | 246 |
return . Bad . GenericError $ "Query '" ++ show qkind ++ "' not supported" |
220 | 247 |
|
... | ... | |
289 | 316 |
queryFields (QueryFields (ItemTypeLuxi QRJob) fields) = |
290 | 317 |
Ok $ fieldsExtractor Query.Job.fieldsMap fields |
291 | 318 |
|
319 |
queryFields (QueryFields (ItemTypeOpCode QRExport) fields) = |
|
320 |
Ok $ fieldsExtractor Export.fieldsMap fields |
|
321 |
|
|
292 | 322 |
queryFields (QueryFields qkind _) = |
293 | 323 |
Bad . GenericError $ "QueryFields '" ++ show qkind ++ "' not supported" |
294 | 324 |
|
Also available in: Unified diff