Safe Haskell | Safe-Infered |
---|
Implementation of the Ganeti Query2 filterning.
The filtering of results should be done in two phases.
In the first phase, before contacting any remote nodes for runtime
data, the filtering should be executed with Nothing
for the runtime
context. This will make all non-runtime filters filter correctly,
whereas all runtime filters will respond successfully. As described in
the Python version too, this makes for example Or filters very
inefficient if they contain runtime fields.
Once this first filtering phase has been done, we hopefully eliminated
some remote nodes out of the list of candidates, we run the remote
data gathering, and we evaluate the filter again, this time with a
Just
runtime context. This will make all filters work correctly.
Note that the second run will re-evaluate the config/simple fields, without caching; this is not perfect, but we consider config accesses very cheap (and the configuration snapshot we have won't change between the two runs, hence we will not get inconsistent results).
- compileFilter :: FieldMap a b -> Filter FilterField -> ErrorResult (Filter (FieldGetter a b, QffMode))
- qffField :: QffMode -> JSValue -> ErrorResult JSValue
- wrapGetter :: ConfigData -> Maybe b -> a -> (FieldGetter a b, QffMode) -> (JSValue -> ErrorResult Bool) -> ErrorResult Bool
- trueFilter :: JSValue -> ErrorResult Bool
- type Comparator = (Eq a, Ord a) => a -> a -> Bool
- binOpFilter :: Comparator -> FilterValue -> JSValue -> ErrorResult Bool
- regexpFilter :: FilterRegex -> JSValue -> ErrorResult Bool
- containsFilter :: FilterValue -> JSValue -> ErrorResult Bool
- evaluateFilter :: ConfigData -> Maybe b -> a -> Filter (FieldGetter a b, QffMode) -> ErrorResult Bool
- tryGetter :: ConfigData -> Maybe b -> a -> FieldGetter a b -> Maybe ResultEntry
- requestedNames :: FilterField -> Filter FilterField -> Maybe [FilterValue]
- type FilterConstructor = String -> [Either String Integer] -> Filter FilterField
- makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterField
- reSpecialSymbols :: String
- quoteForRegex :: String -> String
- makeHostnameFilter :: String -> [Either String Integer] -> Filter FilterField
Documentation
compileFilter :: FieldMap a b -> Filter FilterField -> ErrorResult (Filter (FieldGetter a b, QffMode))Source
Compiles a filter based on field names to one based on getters.
qffField :: QffMode -> JSValue -> ErrorResult JSValueSource
wrapGetter :: ConfigData -> Maybe b -> a -> (FieldGetter a b, QffMode) -> (JSValue -> ErrorResult Bool) -> ErrorResult BoolSource
trueFilter :: JSValue -> ErrorResult BoolSource
type Comparator = (Eq a, Ord a) => a -> a -> BoolSource
binOpFilter :: Comparator -> FilterValue -> JSValue -> ErrorResult BoolSource
regexpFilter :: FilterRegex -> JSValue -> ErrorResult BoolSource
containsFilter :: FilterValue -> JSValue -> ErrorResult BoolSource
evaluateFilter :: ConfigData -> Maybe b -> a -> Filter (FieldGetter a b, QffMode) -> ErrorResult BoolSource
Verifies if a given item passes a filter. The runtime context might be missing, in which case most of the filters will consider this as passing the filter.
Note: we use explicit recursion to reduce unneeded memory use;
any
and all
do not play nice with monadic values, resulting in
either too much memory use or in too many thunks being created.
tryGetter :: ConfigData -> Maybe b -> a -> FieldGetter a b -> Maybe ResultEntrySource
requestedNames :: FilterField -> Filter FilterField -> Maybe [FilterValue]Source
Computes the requested names, if only names were requested (and
with equality). Otherwise returns Nothing
.
type FilterConstructor = String -> [Either String Integer] -> Filter FilterFieldSource
makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterFieldSource
Builds a simple filter from a list of names.
reSpecialSymbols :: StringSource
quoteForRegex :: String -> StringSource
makeHostnameFilter :: String -> [Either String Integer] -> Filter FilterFieldSource
Builds a filter for hostnames from a list of names.