Safe Haskell | None |
---|
Implementation of the Ganeti Query2 functionality.
Synopsis
- data CollectorType a b
- = CollectorSimple (Bool -> ConfigData -> [a] -> IO [(a, b)])
- | CollectorFieldAware (Bool -> ConfigData -> [String] -> [a] -> IO [(a, b)])
- mkUnknownFDef :: String -> FieldData a b
- execGetter :: ConfigData -> b -> a -> FieldGetter a b -> ResultEntry
- getSelectedFields :: FieldMap a b -> [String] -> FieldList a b
- needsLiveData :: [FieldGetter a b] -> Bool
- needsNames :: Query -> Maybe [FilterValue]
- nameField :: ItemType -> FilterField
- uuidField :: ItemType -> FilterField
- getAllQuotedStrings :: [FilterValue] -> [String]
- getRequestedNames :: Query -> [String]
- getRequestedJobIDs :: Filter FilterField -> Result [JobId]
- genericQuery :: FieldMap a b -> CollectorType a b -> (a -> String) -> (ConfigData -> Container a) -> (ConfigData -> String -> ErrorResult a) -> ConfigData -> Bool -> [String] -> Filter FilterField -> [String] -> IO (ErrorResult QueryResult)
- recollectLocksData :: ([(GanetiLocks, [(ClientId, OwnerState)])], [(Integer, ClientId, [LockRequest GanetiLocks])]) -> Bool -> ConfigData -> [String] -> IO [(String, RuntimeData)]
- query :: ConfigData -> Bool -> Query -> IO (ErrorResult QueryResult)
- dummyCollectLiveData :: Bool -> ConfigData -> [a] -> IO [(a, NoDataRuntime)]
- queryInner :: ConfigData -> Bool -> Query -> [String] -> IO (ErrorResult QueryResult)
- queryJobs :: ConfigData -> Bool -> [FilterField] -> Filter FilterField -> IO (ErrorResult QueryResult)
- fieldsExtractor :: FieldMap a b -> [FilterField] -> QueryFieldsResult
- queryFields :: QueryFields -> ErrorResult QueryFieldsResult
- queryCompat :: QueryResult -> ErrorResult [[JSValue]]
Documentation
data CollectorType a b Source #
Collector type
CollectorSimple (Bool -> ConfigData -> [a] -> IO [(a, b)]) | |
CollectorFieldAware (Bool -> ConfigData -> [String] -> [a] -> IO [(a, b)]) |
Helper functions
mkUnknownFDef :: String -> FieldData a b Source #
Builds an unknown field definition.
execGetter :: ConfigData -> b -> a -> FieldGetter a b -> ResultEntry Source #
Runs a field getter on the existing contexts.
Main query execution
Helper to build the list of requested fields. This transforms the list of string fields to a list of field defs and getters, with some of them possibly being unknown fields.
needsLiveData :: [FieldGetter a b] -> Bool Source #
Check whether list of queried fields contains live fields.
needsNames :: Query -> Maybe [FilterValue] Source #
Checks whether we have requested exactly some names. This is a
simple wrapper over requestedNames
and nameField
.
nameField :: ItemType -> FilterField Source #
Computes the name field for different query types.
uuidField :: ItemType -> FilterField Source #
Computes the uuid field, or the best possible substitute, for different query types.
getAllQuotedStrings :: [FilterValue] -> [String] Source #
Extracts all quoted strings from a list, ignoring the
NumericValue
entries.
getRequestedNames :: Query -> [String] Source #
Checks that we have either requested a valid set of names, or we have a more complex filter.
getRequestedJobIDs :: Filter FilterField -> Result [JobId] Source #
Compute the requested job IDs. This is custom since we need to handle both strings and integers.
:: FieldMap a b | Maps field names to field definitions |
-> CollectorType a b | Collector of live data |
-> (a -> String) | Object to name function |
-> (ConfigData -> Container a) | Get all objects from config |
-> (ConfigData -> String -> ErrorResult a) | Lookup object |
-> ConfigData | The config to run the query against |
-> Bool | Whether the query should be run live |
-> [String] | List of requested fields |
-> Filter FilterField | Filter field |
-> [String] | List of requested names |
-> IO (ErrorResult QueryResult) |
Generic query implementation for resources that are backed by some configuration objects.
Different query types use the same genericQuery
function by providing
a collector function and a field map. The collector function retrieves
live data, and the field map provides both the requirements and the logic
necessary to retrieve the data needed for the field.
The b
type in the specification is the runtime. Every query can gather
additional live data related to the configuration object using the collector
to perform RPC calls.
The gathered data, or the failure to get it, is expressed through a runtime object. The type of a runtime object is determined by every query type for itself, and used exclusively by that query.
recollectLocksData :: ([(GanetiLocks, [(ClientId, OwnerState)])], [(Integer, ClientId, [LockRequest GanetiLocks])]) -> Bool -> ConfigData -> [String] -> IO [(String, RuntimeData)] Source #
Dummy recollection of the data for a lock from the prefected data for all locks.
:: ConfigData | The current configuration |
-> Bool | Whether to collect live data |
-> Query | The query (item, fields, filter) |
-> IO (ErrorResult QueryResult) | Result |
Main query execution function.
dummyCollectLiveData :: Bool -> ConfigData -> [a] -> IO [(a, NoDataRuntime)] Source #
Dummy data collection fuction
:: ConfigData | The current configuration |
-> Bool | Whether to collect live data |
-> Query | The query (item, fields, filter) |
-> [String] | Requested names |
-> IO (ErrorResult QueryResult) | Result |
Inner query execution function.
:: ConfigData | The current configuration |
-> Bool | Whether to collect live data |
-> [FilterField] | Item |
-> Filter FilterField | Filter |
-> IO (ErrorResult QueryResult) | Result |
Query jobs specific query function, needed as we need to accept
both QuotedString
and NumericValue
as wanted names.
fieldsExtractor :: FieldMap a b -> [FilterField] -> QueryFieldsResult Source #
Helper for queryFields
.
queryFields :: QueryFields -> ErrorResult QueryFieldsResult Source #
Query fields call.
queryCompat :: QueryResult -> ErrorResult [[JSValue]] Source #
Classic query converter. It gets a standard query result on input and computes the classic style results.