ganeti

Safe HaskellNone

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.

type Comparator = forall a. (Eq a, Ord a) => a -> a -> Bool Source #

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
Eq Comparison # 
Instance details

Defined in Ganeti.Query.Filter

Methods

(==) :: Comparison -> Comparison -> Bool

(/=) :: Comparison -> Comparison -> Bool

Ord Comparison # 
Instance details

Defined in Ganeti.Query.Filter

Show Comparison # 
Instance details

Defined in Ganeti.Query.Filter

Methods

showsPrec :: Int -> Comparison -> ShowS

show :: Comparison -> String

showList :: [Comparison] -> ShowS

toCompFun :: Comparison -> Comparator Source #

Turns a comparison into the corresponding Haskell function.

data FilterOp field val where Source #

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) # 
Instance details

Defined in Ganeti.Query.Filter

Methods

(==) :: FilterOp field val -> FilterOp field val -> Bool

(/=) :: FilterOp field val -> FilterOp field val -> Bool

Show (FilterOp field val) # 
Instance details

Defined in Ganeti.Query.Filter

Methods

showsPrec :: Int -> FilterOp field val -> ShowS

show :: FilterOp field val -> String

showList :: [FilterOp field val] -> ShowS

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

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 Bool Source #

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 Bool Source #

Evaluates a Filter on a JSON object.

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 FilterField Source #

Builds a simple filter from a list of names.