Revision 5183e8be htools/Ganeti/Query/Query.hs
b/htools/Ganeti/Query/Query.hs | ||
---|---|---|
60 | 60 |
import qualified Text.JSON as J |
61 | 61 |
|
62 | 62 |
import Ganeti.BasicTypes |
63 |
import Ganeti.Errors |
|
63 | 64 |
import Ganeti.Config |
64 | 65 |
import Ganeti.JSON |
65 | 66 |
import Ganeti.Rpc |
... | ... | |
146 | 147 |
query :: ConfigData -- ^ The current configuration |
147 | 148 |
-> Bool -- ^ Whether to collect live data |
148 | 149 |
-> Query -- ^ The query (item, fields, filter) |
149 |
-> IO (Result QueryResult) -- ^ Result |
|
150 |
-> IO (ErrorResult QueryResult) -- ^ Result
|
|
150 | 151 |
query cfg live qry = queryInner cfg live qry $ getRequestedNames qry |
151 | 152 |
|
152 | 153 |
-- | Inner query execution function. |
... | ... | |
154 | 155 |
-> Bool -- ^ Whether to collect live data |
155 | 156 |
-> Query -- ^ The query (item, fields, filter) |
156 | 157 |
-> [String] -- ^ Requested names |
157 |
-> IO (Result QueryResult) -- ^ Result |
|
158 |
-> IO (ErrorResult QueryResult) -- ^ Result
|
|
158 | 159 |
|
159 | 160 |
queryInner cfg live (Query QRNode fields qfilter) wanted = runResultT $ do |
160 | 161 |
cfilter <- resultT $ compileFilter nodeFieldsMap qfilter |
... | ... | |
167 | 168 |
_ -> mapM (getNode cfg) wanted |
168 | 169 |
-- runs first pass of the filter, without a runtime context; this |
169 | 170 |
-- will limit the nodes that we'll contact for runtime data |
170 |
fnodes <- resultT $ filterM (\n -> evaluateFilter cfg Nothing n cfilter) nodes |
|
171 |
fnodes <- resultT $ filterM (\n -> evaluateFilter cfg Nothing n cfilter) |
|
172 |
nodes |
|
171 | 173 |
-- here we would run the runtime data gathering, then filter again |
172 | 174 |
-- the nodes, based on existing runtime data |
173 | 175 |
nruntimes <- lift $ maybeCollectLiveData live' cfg fnodes |
... | ... | |
190 | 192 |
return QueryResult {qresFields = fdefs, qresData = fdata } |
191 | 193 |
|
192 | 194 |
queryInner _ _ (Query qkind _ _) _ = |
193 |
return . Bad $ "Query '" ++ show qkind ++ "' not supported" |
|
195 |
return . Bad . GenericError $ "Query '" ++ show qkind ++ "' not supported"
|
|
194 | 196 |
|
195 | 197 |
-- | Helper for 'queryFields'. |
196 | 198 |
fieldsExtractor :: FieldMap a b -> [FilterField] -> QueryFieldsResult |
... | ... | |
201 | 203 |
in QueryFieldsResult (map fst selected) |
202 | 204 |
|
203 | 205 |
-- | Query fields call. |
204 |
queryFields :: QueryFields -> Result QueryFieldsResult |
|
206 |
queryFields :: QueryFields -> ErrorResult QueryFieldsResult
|
|
205 | 207 |
queryFields (QueryFields QRNode fields) = |
206 | 208 |
Ok $ fieldsExtractor nodeFieldsMap fields |
207 | 209 |
|
... | ... | |
209 | 211 |
Ok $ fieldsExtractor groupFieldsMap fields |
210 | 212 |
|
211 | 213 |
queryFields (QueryFields qkind _) = |
212 |
Bad $ "QueryFields '" ++ show qkind ++ "' not supported" |
|
214 |
Bad . GenericError $ "QueryFields '" ++ show qkind ++ "' not supported"
|
|
213 | 215 |
|
214 | 216 |
-- | Classic query converter. It gets a standard query result on input |
215 | 217 |
-- and computes the classic style results. |
216 |
queryCompat :: QueryResult -> Result [[J.JSValue]] |
|
218 |
queryCompat :: QueryResult -> ErrorResult [[J.JSValue]]
|
|
217 | 219 |
queryCompat (QueryResult fields qrdata) = |
218 | 220 |
case map fdefName $ filter ((== QFTUnknown) . fdefKind) fields of |
219 | 221 |
[] -> Ok $ map (map (maybe J.JSNull J.showJSON . rentryValue)) qrdata |
220 |
unknown -> Bad $ "Unknown output fields selected: " ++ |
|
221 |
intercalate ", " unknown |
|
222 |
unknown -> Bad $ OpPrereqError ("Unknown output fields selected: " ++ |
|
223 |
intercalate ", " unknown) ECodeInval |
Also available in: Unified diff