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

trueFilter :: JSValue -> ErrorResult BoolSource

type Comparator = forall a. (Eq a, Ord a) => a -> a -> BoolSource

A type synonim for a rank-2 comparator function. This is used so that we can pass the usual <=, >, == functions to binOpFilter and for them to be used in multiple contexts.

data Comparison Source

Ways we can compare things in the filter language.

Constructors

Eq 
Lt 
Le 
Gt 
Ge 

Instances

toCompFun :: Comparison -> ComparatorSource

Turns a comparison into the corresponding Haskell function.

data FilterOp field val whereSource

Operations in the leaves of the Ganeti filter language.

Constructors

Truth :: FilterOp field () 
Comp :: Comparison -> FilterOp field FilterValue 
Regex :: FilterOp field FilterRegex 
Contains :: FilterOp field FilterValue 

Instances

Eq (FilterOp field val) 
Show (FilterOp field val) 

evaluateFilterM :: (Monad m, Applicative m) => (forall val. FilterOp field val -> field -> val -> m Bool) -> Filter field -> m BoolSource

Checks if a filter matches.

The leaves of the filter are evaluated against an object using the passed opFun; that is why the object need not be passed in.

The field type describes the accessors that are used to query values from the object; those values are to be matched against the val type in the filter leaves.

Useful monads m for this are ErrorResult and Maybe.

evaluateQueryFilter :: 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.

evaluateFilterJSON :: Filter JSValue -> ErrorResult BoolSource

Evaluates a Filter on a JSON object.

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.