ganeti

Safe HaskellSafe-Infered

Ganeti.Query.Filter

Description

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).

Synopsis

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) -> (QffMode -> JSValue -> ErrorResult Bool) -> ErrorResult BoolSource

trueFilter :: JSValue -> ErrorResult BoolSource

type Comparator = (Eq a, Ord a) => a -> a -> 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.

makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterFieldSource

Builds a simple filter from a list of names.