root / src / Ganeti / Query / Query.hs @ bac48afe
History | View | Annotate | Download (12.7 kB)
1 | 4cbe9bda | Iustin Pop | {-| Implementation of the Ganeti Query2 functionality. |
---|---|---|---|
2 | 4cbe9bda | Iustin Pop | |
3 | 4cbe9bda | Iustin Pop | -} |
4 | 4cbe9bda | Iustin Pop | |
5 | 4cbe9bda | Iustin Pop | {- |
6 | 4cbe9bda | Iustin Pop | |
7 | c4bf507b | Iustin Pop | Copyright (C) 2012, 2013 Google Inc. |
8 | 4cbe9bda | Iustin Pop | |
9 | 4cbe9bda | Iustin Pop | This program is free software; you can redistribute it and/or modify |
10 | 4cbe9bda | Iustin Pop | it under the terms of the GNU General Public License as published by |
11 | 4cbe9bda | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
12 | 4cbe9bda | Iustin Pop | (at your option) any later version. |
13 | 4cbe9bda | Iustin Pop | |
14 | 4cbe9bda | Iustin Pop | This program is distributed in the hope that it will be useful, but |
15 | 4cbe9bda | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | 4cbe9bda | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | 4cbe9bda | Iustin Pop | General Public License for more details. |
18 | 4cbe9bda | Iustin Pop | |
19 | 4cbe9bda | Iustin Pop | You should have received a copy of the GNU General Public License |
20 | 4cbe9bda | Iustin Pop | along with this program; if not, write to the Free Software |
21 | 4cbe9bda | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | 4cbe9bda | Iustin Pop | 02110-1301, USA. |
23 | 4cbe9bda | Iustin Pop | |
24 | 4cbe9bda | Iustin Pop | -} |
25 | 4cbe9bda | Iustin Pop | |
26 | 8a65c02b | Iustin Pop | {- |
27 | 8a65c02b | Iustin Pop | |
28 | 8a65c02b | Iustin Pop | TODO: problems with the current model: |
29 | 8a65c02b | Iustin Pop | |
30 | 8a65c02b | Iustin Pop | 1. There's nothing preventing a result such as ResultEntry RSNormal |
31 | 8a65c02b | Iustin Pop | Nothing, or ResultEntry RSNoData (Just ...); ideally, we would |
32 | 8a65c02b | Iustin Pop | separate the the RSNormal and other types; we would need a new data |
33 | 8a65c02b | Iustin Pop | type for this, though, with JSON encoding/decoding |
34 | 8a65c02b | Iustin Pop | |
35 | 8a65c02b | Iustin Pop | 2. We don't have a way to 'bind' a FieldDefinition's field type |
36 | 8a65c02b | Iustin Pop | (e.q. QFTBool) with the actual value that is returned from a |
37 | 8a65c02b | Iustin Pop | FieldGetter. This means that the various getter functions can return |
38 | 8a65c02b | Iustin Pop | divergent types for the same field when evaluated against multiple |
39 | 8a65c02b | Iustin Pop | items. This is bad; it only works today because we 'hide' everything |
40 | 8a65c02b | Iustin Pop | behind JSValue, but is not nice at all. We should probably remove the |
41 | 8a65c02b | Iustin Pop | separation between FieldDefinition and the FieldGetter, and introduce |
42 | 8a65c02b | Iustin Pop | a new abstract data type, similar to QFT*, that contains the values |
43 | 8a65c02b | Iustin Pop | too. |
44 | 8a65c02b | Iustin Pop | |
45 | 8a65c02b | Iustin Pop | -} |
46 | 8a65c02b | Iustin Pop | |
47 | 4cbe9bda | Iustin Pop | module Ganeti.Query.Query |
48 | 4cbe9bda | Iustin Pop | ( query |
49 | 518023a9 | Iustin Pop | , queryFields |
50 | cd67e337 | Iustin Pop | , queryCompat |
51 | bc4cdeef | Iustin Pop | , getRequestedNames |
52 | cd67e337 | Iustin Pop | , nameField |
53 | 4cbe9bda | Iustin Pop | ) where |
54 | 4cbe9bda | Iustin Pop | |
55 | a7e484c4 | Iustin Pop | import Control.DeepSeq |
56 | a7e484c4 | Iustin Pop | import Control.Monad (filterM, liftM, foldM) |
57 | 7f0fd838 | Agata Murawska | import Control.Monad.Trans (lift) |
58 | cd67e337 | Iustin Pop | import Data.List (intercalate) |
59 | 046fe3f5 | Iustin Pop | import Data.Maybe (fromMaybe) |
60 | 046fe3f5 | Iustin Pop | import qualified Data.Map as Map |
61 | cd67e337 | Iustin Pop | import qualified Text.JSON as J |
62 | 046fe3f5 | Iustin Pop | |
63 | 4cbe9bda | Iustin Pop | import Ganeti.BasicTypes |
64 | 0ec87781 | Iustin Pop | import Ganeti.Config |
65 | a7e484c4 | Iustin Pop | import Ganeti.Errors |
66 | a7e484c4 | Iustin Pop | import Ganeti.JQueue |
67 | f3baf5ef | Iustin Pop | import Ganeti.JSON |
68 | a7e484c4 | Iustin Pop | import Ganeti.Objects |
69 | 046fe3f5 | Iustin Pop | import Ganeti.Query.Common |
70 | c4bf507b | Iustin Pop | import qualified Ganeti.Query.Export as Export |
71 | 8a65c02b | Iustin Pop | import Ganeti.Query.Filter |
72 | a7e484c4 | Iustin Pop | import qualified Ganeti.Query.Job as Query.Job |
73 | 36162faf | Iustin Pop | import qualified Ganeti.Query.Group as Group |
74 | a7e484c4 | Iustin Pop | import Ganeti.Query.Language |
75 | 36162faf | Iustin Pop | import qualified Ganeti.Query.Network as Network |
76 | 36162faf | Iustin Pop | import qualified Ganeti.Query.Node as Node |
77 | a7e484c4 | Iustin Pop | import Ganeti.Query.Types |
78 | a7e484c4 | Iustin Pop | import Ganeti.Path |
79 | a7e484c4 | Iustin Pop | import Ganeti.Types |
80 | a41c337e | Iustin Pop | import Ganeti.Utils |
81 | 4cbe9bda | Iustin Pop | |
82 | 046fe3f5 | Iustin Pop | -- * Helper functions |
83 | 046fe3f5 | Iustin Pop | |
84 | 046fe3f5 | Iustin Pop | -- | Builds an unknown field definition. |
85 | 046fe3f5 | Iustin Pop | mkUnknownFDef :: String -> FieldData a b |
86 | 046fe3f5 | Iustin Pop | mkUnknownFDef name = |
87 | 046fe3f5 | Iustin Pop | ( FieldDefinition name name QFTUnknown ("Unknown field '" ++ name ++ "'") |
88 | f94a9680 | Iustin Pop | , FieldUnknown |
89 | f94a9680 | Iustin Pop | , QffNormal ) |
90 | 046fe3f5 | Iustin Pop | |
91 | 046fe3f5 | Iustin Pop | -- | Runs a field getter on the existing contexts. |
92 | 046fe3f5 | Iustin Pop | execGetter :: ConfigData -> b -> a -> FieldGetter a b -> ResultEntry |
93 | 046fe3f5 | Iustin Pop | execGetter _ _ item (FieldSimple getter) = getter item |
94 | 046fe3f5 | Iustin Pop | execGetter cfg _ item (FieldConfig getter) = getter cfg item |
95 | 046fe3f5 | Iustin Pop | execGetter _ rt item (FieldRuntime getter) = getter rt item |
96 | 046fe3f5 | Iustin Pop | execGetter _ _ _ FieldUnknown = rsUnknown |
97 | 046fe3f5 | Iustin Pop | |
98 | 046fe3f5 | Iustin Pop | -- * Main query execution |
99 | 046fe3f5 | Iustin Pop | |
100 | 046fe3f5 | Iustin Pop | -- | Helper to build the list of requested fields. This transforms the |
101 | 046fe3f5 | Iustin Pop | -- list of string fields to a list of field defs and getters, with |
102 | 046fe3f5 | Iustin Pop | -- some of them possibly being unknown fields. |
103 | 046fe3f5 | Iustin Pop | getSelectedFields :: FieldMap a b -- ^ Defined fields |
104 | 046fe3f5 | Iustin Pop | -> [String] -- ^ Requested fields |
105 | 046fe3f5 | Iustin Pop | -> FieldList a b -- ^ Selected fields |
106 | 046fe3f5 | Iustin Pop | getSelectedFields defined = |
107 | 046fe3f5 | Iustin Pop | map (\name -> fromMaybe (mkUnknownFDef name) $ name `Map.lookup` defined) |
108 | 046fe3f5 | Iustin Pop | |
109 | 7f0fd838 | Agata Murawska | -- | Check whether list of queried fields contains live fields. |
110 | 7f0fd838 | Agata Murawska | needsLiveData :: [FieldGetter a b] -> Bool |
111 | a2ae14e9 | Iustin Pop | needsLiveData = any isRuntimeField |
112 | 7f0fd838 | Agata Murawska | |
113 | bc4cdeef | Iustin Pop | -- | Checks whether we have requested exactly some names. This is a |
114 | bc4cdeef | Iustin Pop | -- simple wrapper over 'requestedNames' and 'nameField'. |
115 | bc4cdeef | Iustin Pop | needsNames :: Query -> Maybe [FilterValue] |
116 | bc4cdeef | Iustin Pop | needsNames (Query kind _ qfilter) = requestedNames (nameField kind) qfilter |
117 | bc4cdeef | Iustin Pop | |
118 | bc4cdeef | Iustin Pop | -- | Computes the name field for different query types. |
119 | bc4cdeef | Iustin Pop | nameField :: ItemType -> FilterField |
120 | 1283cc38 | Iustin Pop | nameField (ItemTypeLuxi QRJob) = "id" |
121 | c4bf507b | Iustin Pop | nameField (ItemTypeOpCode QRExport) = "node" |
122 | 1283cc38 | Iustin Pop | nameField _ = "name" |
123 | bc4cdeef | Iustin Pop | |
124 | bc4cdeef | Iustin Pop | -- | Extracts all quoted strings from a list, ignoring the |
125 | bc4cdeef | Iustin Pop | -- 'NumericValue' entries. |
126 | bc4cdeef | Iustin Pop | getAllQuotedStrings :: [FilterValue] -> [String] |
127 | bc4cdeef | Iustin Pop | getAllQuotedStrings = |
128 | bc4cdeef | Iustin Pop | concatMap extractor |
129 | bc4cdeef | Iustin Pop | where extractor (NumericValue _) = [] |
130 | bc4cdeef | Iustin Pop | extractor (QuotedString val) = [val] |
131 | bc4cdeef | Iustin Pop | |
132 | bc4cdeef | Iustin Pop | -- | Checks that we have either requested a valid set of names, or we |
133 | bc4cdeef | Iustin Pop | -- have a more complex filter. |
134 | bc4cdeef | Iustin Pop | getRequestedNames :: Query -> [String] |
135 | bc4cdeef | Iustin Pop | getRequestedNames qry = |
136 | bc4cdeef | Iustin Pop | case needsNames qry of |
137 | bc4cdeef | Iustin Pop | Just names -> getAllQuotedStrings names |
138 | bc4cdeef | Iustin Pop | Nothing -> [] |
139 | bc4cdeef | Iustin Pop | |
140 | a7e484c4 | Iustin Pop | -- | Compute the requested job IDs. This is custom since we need to |
141 | a7e484c4 | Iustin Pop | -- handle both strings and integers. |
142 | a7e484c4 | Iustin Pop | getRequestedJobIDs :: Filter FilterField -> Result [JobId] |
143 | a7e484c4 | Iustin Pop | getRequestedJobIDs qfilter = |
144 | a7e484c4 | Iustin Pop | case requestedNames (nameField (ItemTypeLuxi QRJob)) qfilter of |
145 | a7e484c4 | Iustin Pop | Nothing -> Ok [] |
146 | a7e484c4 | Iustin Pop | Just [] -> Ok [] |
147 | a7e484c4 | Iustin Pop | Just vals -> |
148 | a7e484c4 | Iustin Pop | mapM (\e -> case e of |
149 | a7e484c4 | Iustin Pop | QuotedString s -> makeJobIdS s |
150 | a7e484c4 | Iustin Pop | NumericValue i -> makeJobId $ fromIntegral i |
151 | a7e484c4 | Iustin Pop | ) vals |
152 | a7e484c4 | Iustin Pop | |
153 | d5b2753a | Iustin Pop | -- | Generic query implementation for resources that are backed by |
154 | d5b2753a | Iustin Pop | -- some configuration objects. |
155 | d5b2753a | Iustin Pop | genericQuery :: FieldMap a b -- ^ Field map |
156 | d5b2753a | Iustin Pop | -> (Bool -> ConfigData -> [a] -> IO [(a, b)]) -- ^ Collector |
157 | d5b2753a | Iustin Pop | -> (a -> String) -- ^ Object to name function |
158 | d5b2753a | Iustin Pop | -> (ConfigData -> Container a) -- ^ Get all objects from config |
159 | d5b2753a | Iustin Pop | -> (ConfigData -> String -> ErrorResult a) -- ^ Lookup object |
160 | d5b2753a | Iustin Pop | -> ConfigData -- ^ The config to run the query against |
161 | d5b2753a | Iustin Pop | -> Bool -- ^ Whether the query should be run live |
162 | d5b2753a | Iustin Pop | -> [String] -- ^ List of requested fields |
163 | d5b2753a | Iustin Pop | -> Filter FilterField -- ^ Filter field |
164 | d5b2753a | Iustin Pop | -> [String] -- ^ List of requested names |
165 | d5b2753a | Iustin Pop | -> IO (ErrorResult QueryResult) |
166 | d5b2753a | Iustin Pop | genericQuery fieldsMap collector nameFn configFn getFn cfg |
167 | d5b2753a | Iustin Pop | live fields qfilter wanted = |
168 | d5b2753a | Iustin Pop | runResultT $ do |
169 | d5b2753a | Iustin Pop | cfilter <- resultT $ compileFilter fieldsMap qfilter |
170 | d5b2753a | Iustin Pop | let selected = getSelectedFields fieldsMap fields |
171 | d5b2753a | Iustin Pop | (fdefs, fgetters, _) = unzip3 selected |
172 | d5b2753a | Iustin Pop | live' = live && needsLiveData fgetters |
173 | d5b2753a | Iustin Pop | objects <- resultT $ case wanted of |
174 | d5b2753a | Iustin Pop | [] -> Ok . niceSortKey nameFn . |
175 | d5b2753a | Iustin Pop | Map.elems . fromContainer $ configFn cfg |
176 | d5b2753a | Iustin Pop | _ -> mapM (getFn cfg) wanted |
177 | d5b2753a | Iustin Pop | -- runs first pass of the filter, without a runtime context; this |
178 | d5b2753a | Iustin Pop | -- will limit the objects that we'll contact for exports |
179 | d5b2753a | Iustin Pop | fobjects <- resultT $ filterM (\n -> evaluateFilter cfg Nothing n cfilter) |
180 | d5b2753a | Iustin Pop | objects |
181 | d5b2753a | Iustin Pop | -- here run the runtime data gathering... |
182 | d5b2753a | Iustin Pop | runtimes <- lift $ collector live' cfg fobjects |
183 | d5b2753a | Iustin Pop | -- ... then filter again the results, based on gathered runtime data |
184 | d5b2753a | Iustin Pop | let fdata = map (\(obj, runtime) -> |
185 | d5b2753a | Iustin Pop | map (execGetter cfg runtime obj) fgetters) |
186 | d5b2753a | Iustin Pop | runtimes |
187 | d5b2753a | Iustin Pop | return QueryResult { qresFields = fdefs, qresData = fdata } |
188 | d5b2753a | Iustin Pop | |
189 | 4cbe9bda | Iustin Pop | -- | Main query execution function. |
190 | 4cbe9bda | Iustin Pop | query :: ConfigData -- ^ The current configuration |
191 | fa2c927c | Agata Murawska | -> Bool -- ^ Whether to collect live data |
192 | 4cbe9bda | Iustin Pop | -> Query -- ^ The query (item, fields, filter) |
193 | 5183e8be | Iustin Pop | -> IO (ErrorResult QueryResult) -- ^ Result |
194 | a7e484c4 | Iustin Pop | query cfg live (Query (ItemTypeLuxi QRJob) fields qfilter) = |
195 | a7e484c4 | Iustin Pop | queryJobs cfg live fields qfilter |
196 | a41c337e | Iustin Pop | query cfg live qry = queryInner cfg live qry $ getRequestedNames qry |
197 | 046fe3f5 | Iustin Pop | |
198 | a41c337e | Iustin Pop | -- | Inner query execution function. |
199 | a41c337e | Iustin Pop | queryInner :: ConfigData -- ^ The current configuration |
200 | a41c337e | Iustin Pop | -> Bool -- ^ Whether to collect live data |
201 | a41c337e | Iustin Pop | -> Query -- ^ The query (item, fields, filter) |
202 | a41c337e | Iustin Pop | -> [String] -- ^ Requested names |
203 | 5183e8be | Iustin Pop | -> IO (ErrorResult QueryResult) -- ^ Result |
204 | a41c337e | Iustin Pop | |
205 | 1283cc38 | Iustin Pop | queryInner cfg live (Query (ItemTypeOpCode QRNode) fields qfilter) wanted = |
206 | d5b2753a | Iustin Pop | genericQuery Node.fieldsMap Node.collectLiveData nodeName configNodes getNode |
207 | d5b2753a | Iustin Pop | cfg live fields qfilter wanted |
208 | 046fe3f5 | Iustin Pop | |
209 | d5b2753a | Iustin Pop | queryInner cfg live (Query (ItemTypeOpCode QRGroup) fields qfilter) wanted = |
210 | d5b2753a | Iustin Pop | genericQuery Group.fieldsMap Group.collectLiveData groupName configNodegroups |
211 | d5b2753a | Iustin Pop | getGroup cfg live fields qfilter wanted |
212 | 05092772 | Helga Velroyen | |
213 | d5b2753a | Iustin Pop | queryInner cfg live (Query (ItemTypeOpCode QRNetwork) fields qfilter) wanted = |
214 | d5b2753a | Iustin Pop | genericQuery Network.fieldsMap Network.collectLiveData |
215 | d5b2753a | Iustin Pop | (fromNonEmpty . networkName) |
216 | d5b2753a | Iustin Pop | configNetworks getNetwork cfg live fields qfilter wanted |
217 | 40246fa0 | Agata Murawska | |
218 | c4bf507b | Iustin Pop | queryInner cfg live (Query (ItemTypeOpCode QRExport) fields qfilter) wanted = |
219 | d5b2753a | Iustin Pop | genericQuery Export.fieldsMap Export.collectLiveData nodeName configNodes |
220 | d5b2753a | Iustin Pop | getNode cfg live fields qfilter wanted |
221 | c4bf507b | Iustin Pop | |
222 | a41c337e | Iustin Pop | queryInner _ _ (Query qkind _ _) _ = |
223 | 5183e8be | Iustin Pop | return . Bad . GenericError $ "Query '" ++ show qkind ++ "' not supported" |
224 | 518023a9 | Iustin Pop | |
225 | a7e484c4 | Iustin Pop | -- | Query jobs specific query function, needed as we need to accept |
226 | a7e484c4 | Iustin Pop | -- both 'QuotedString' and 'NumericValue' as wanted names. |
227 | a7e484c4 | Iustin Pop | queryJobs :: ConfigData -- ^ The current configuration |
228 | a7e484c4 | Iustin Pop | -> Bool -- ^ Whether to collect live data |
229 | a7e484c4 | Iustin Pop | -> [FilterField] -- ^ Item |
230 | a7e484c4 | Iustin Pop | -> Filter FilterField -- ^ Filter |
231 | a7e484c4 | Iustin Pop | -> IO (ErrorResult QueryResult) -- ^ Result |
232 | a7e484c4 | Iustin Pop | queryJobs cfg live fields qfilter = |
233 | a7e484c4 | Iustin Pop | runResultT $ do |
234 | a7e484c4 | Iustin Pop | rootdir <- lift queueDir |
235 | a7e484c4 | Iustin Pop | let wanted_names = getRequestedJobIDs qfilter |
236 | a7e484c4 | Iustin Pop | want_arch = Query.Job.wantArchived fields |
237 | a7e484c4 | Iustin Pop | rjids <- case wanted_names of |
238 | a7e484c4 | Iustin Pop | Bad msg -> resultT . Bad $ GenericError msg |
239 | a7e484c4 | Iustin Pop | Ok [] -> if live |
240 | a7e484c4 | Iustin Pop | -- we can check the filesystem for actual jobs |
241 | a7e484c4 | Iustin Pop | then lift $ liftM sortJobIDs |
242 | a7e484c4 | Iustin Pop | (determineJobDirectories rootdir want_arch >>= |
243 | a7e484c4 | Iustin Pop | getJobIDs) |
244 | a7e484c4 | Iustin Pop | -- else we shouldn't look at the filesystem... |
245 | a7e484c4 | Iustin Pop | else return [] |
246 | a7e484c4 | Iustin Pop | Ok v -> resultT $ Ok v |
247 | a7e484c4 | Iustin Pop | cfilter <- resultT $ compileFilter Query.Job.fieldsMap qfilter |
248 | a7e484c4 | Iustin Pop | let selected = getSelectedFields Query.Job.fieldsMap fields |
249 | a7e484c4 | Iustin Pop | (fdefs, fgetters, _) = unzip3 selected |
250 | a7e484c4 | Iustin Pop | live' = live && needsLiveData fgetters |
251 | a7e484c4 | Iustin Pop | disabled_data = Bad "live data disabled" |
252 | a7e484c4 | Iustin Pop | -- runs first pass of the filter, without a runtime context; this |
253 | a7e484c4 | Iustin Pop | -- will limit the jobs that we'll load from disk |
254 | a7e484c4 | Iustin Pop | jids <- resultT $ |
255 | a7e484c4 | Iustin Pop | filterM (\jid -> evaluateFilter cfg Nothing jid cfilter) rjids |
256 | a7e484c4 | Iustin Pop | -- here we run the runtime data gathering, filtering and evaluation, |
257 | a7e484c4 | Iustin Pop | -- all in the same step, so that we don't keep jobs in memory longer |
258 | a7e484c4 | Iustin Pop | -- than we need; we can't be fully lazy due to the multiple monad |
259 | a7e484c4 | Iustin Pop | -- wrapping across different steps |
260 | a7e484c4 | Iustin Pop | qdir <- lift queueDir |
261 | a7e484c4 | Iustin Pop | fdata <- foldM |
262 | a7e484c4 | Iustin Pop | -- big lambda, but we use many variables from outside it... |
263 | a7e484c4 | Iustin Pop | (\lst jid -> do |
264 | a7e484c4 | Iustin Pop | job <- lift $ if live' |
265 | d45a824b | Iustin Pop | then loadJobFromDisk qdir True jid |
266 | a7e484c4 | Iustin Pop | else return disabled_data |
267 | a7e484c4 | Iustin Pop | pass <- resultT $ evaluateFilter cfg (Just job) jid cfilter |
268 | a7e484c4 | Iustin Pop | let nlst = if pass |
269 | a7e484c4 | Iustin Pop | then let row = map (execGetter cfg job jid) fgetters |
270 | a7e484c4 | Iustin Pop | in rnf row `seq` row:lst |
271 | a7e484c4 | Iustin Pop | else lst |
272 | a7e484c4 | Iustin Pop | -- evaluate nlst (to WHNF), otherwise we're too lazy |
273 | a7e484c4 | Iustin Pop | return $! nlst |
274 | a7e484c4 | Iustin Pop | ) [] jids |
275 | a7e484c4 | Iustin Pop | return QueryResult { qresFields = fdefs, qresData = reverse fdata } |
276 | a7e484c4 | Iustin Pop | |
277 | b04dc242 | Iustin Pop | -- | Helper for 'queryFields'. |
278 | b04dc242 | Iustin Pop | fieldsExtractor :: FieldMap a b -> [FilterField] -> QueryFieldsResult |
279 | b04dc242 | Iustin Pop | fieldsExtractor fieldsMap fields = |
280 | b04dc242 | Iustin Pop | let selected = if null fields |
281 | b04dc242 | Iustin Pop | then map snd $ Map.toAscList fieldsMap |
282 | b04dc242 | Iustin Pop | else getSelectedFields fieldsMap fields |
283 | f94a9680 | Iustin Pop | in QueryFieldsResult (map (\(defs, _, _) -> defs) selected) |
284 | b04dc242 | Iustin Pop | |
285 | 518023a9 | Iustin Pop | -- | Query fields call. |
286 | 5183e8be | Iustin Pop | queryFields :: QueryFields -> ErrorResult QueryFieldsResult |
287 | 1283cc38 | Iustin Pop | queryFields (QueryFields (ItemTypeOpCode QRNode) fields) = |
288 | 36162faf | Iustin Pop | Ok $ fieldsExtractor Node.fieldsMap fields |
289 | 518023a9 | Iustin Pop | |
290 | 1283cc38 | Iustin Pop | queryFields (QueryFields (ItemTypeOpCode QRGroup) fields) = |
291 | 36162faf | Iustin Pop | Ok $ fieldsExtractor Group.fieldsMap fields |
292 | 40246fa0 | Agata Murawska | |
293 | dce08ad3 | Iustin Pop | queryFields (QueryFields (ItemTypeOpCode QRNetwork) fields) = |
294 | dce08ad3 | Iustin Pop | Ok $ fieldsExtractor Network.fieldsMap fields |
295 | dce08ad3 | Iustin Pop | |
296 | a7e484c4 | Iustin Pop | queryFields (QueryFields (ItemTypeLuxi QRJob) fields) = |
297 | a7e484c4 | Iustin Pop | Ok $ fieldsExtractor Query.Job.fieldsMap fields |
298 | a7e484c4 | Iustin Pop | |
299 | c4bf507b | Iustin Pop | queryFields (QueryFields (ItemTypeOpCode QRExport) fields) = |
300 | c4bf507b | Iustin Pop | Ok $ fieldsExtractor Export.fieldsMap fields |
301 | c4bf507b | Iustin Pop | |
302 | 518023a9 | Iustin Pop | queryFields (QueryFields qkind _) = |
303 | 5183e8be | Iustin Pop | Bad . GenericError $ "QueryFields '" ++ show qkind ++ "' not supported" |
304 | cd67e337 | Iustin Pop | |
305 | cd67e337 | Iustin Pop | -- | Classic query converter. It gets a standard query result on input |
306 | cd67e337 | Iustin Pop | -- and computes the classic style results. |
307 | 5183e8be | Iustin Pop | queryCompat :: QueryResult -> ErrorResult [[J.JSValue]] |
308 | cd67e337 | Iustin Pop | queryCompat (QueryResult fields qrdata) = |
309 | cd67e337 | Iustin Pop | case map fdefName $ filter ((== QFTUnknown) . fdefKind) fields of |
310 | cd67e337 | Iustin Pop | [] -> Ok $ map (map (maybe J.JSNull J.showJSON . rentryValue)) qrdata |
311 | 5183e8be | Iustin Pop | unknown -> Bad $ OpPrereqError ("Unknown output fields selected: " ++ |
312 | 5183e8be | Iustin Pop | intercalate ", " unknown) ECodeInval |