Commit ac13f473 authored by Guido Trotter's avatar Guido Trotter

Haskell data types for query2

This contains the types to express query2 queries, filters and results.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3a44fd5f
......@@ -415,7 +415,8 @@ HS_LIB_SRCS = \
htools/Ganeti/OpCodes.hs \
htools/Ganeti/Runtime.hs \
htools/Ganeti/Ssconf.hs \
htools/Ganeti/THH.hs
htools/Ganeti/THH.hs \
htools/Ganeti/Query2.hs
HS_BUILT_SRCS = htools/Ganeti/HTools/Version.hs htools/Ganeti/Constants.hs
HS_BUILT_SRCS_IN = $(patsubst %,%.in,$(HS_BUILT_SRCS))
......
{-# LANGUAGE TemplateHaskell #-}
{-| Implementation of the Ganeti Query2 language.
-}
{-
Copyright (C) 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.Query2
( Filter
) where
import Text.JSON.Types
import Text.JSON
import qualified Ganeti.Constants as C
import Ganeti.HTools.JSON
import Ganeti.THH
-- * THH declarations, that require ordering.
-- | Status of a query field.
$(declareIADT "ResultStatus"
[ ("RSNormal", 'C.rsNormal )
, ("RSUnknown", 'C.rsUnknown )
, ("RSNoData", 'C.rsNodata )
, ("RSUnavail", 'C.rsUnavail )
, ("RSOffline", 'C.rsOffline )
])
$(makeJSONInstance ''ResultStatus)
-- | Type of a query field.
$(declareSADT "FieldType"
[ ("QFTUnknown", 'C.qftUnknown )
, ("QFTText", 'C.qftText )
, ("QFTBool", 'C.qftBool )
, ("QFTNumber", 'C.qftNumber )
, ("QFTUnit", 'C.qftUnit )
, ("QFTTimestamp", 'C.qftTimestamp )
, ("QFTOther", 'C.qftOther )
])
$(makeJSONInstance ''FieldType)
-- | Supported items on which Query2 works.
$(declareSADT "ItemType"
[ ("QRCluster", 'C.qrCluster )
, ("QRInstance", 'C.qrInstance )
, ("QRNode", 'C.qrNode )
, ("QRLock", 'C.qrLock )
, ("QRGroup", 'C.qrGroup )
, ("QROs", 'C.qrOs )
, ("QRJob", 'C.qrJob )
, ("QRExport", 'C.qrExport )
])
$(makeJSONInstance ''ItemType)
-- * Main Query2 queries and responses.
-- | Query2 query.
data Query = Query ItemType Fields (Maybe Filter)
-- | Query2 result.
data QueryResult = QueryResult [ FieldDefinition ] [ ResultEntry ]
-- | Query2 Fields query.
-- (to get supported fields names, descriptions, and types)
data QueryFields = QueryFields ItemType Fields
-- | Query2 Fields result.
data QueryFieldsResult = QueryFieldsResult [ FieldDefinition ]
-- * Sub data types for query2 queries and responses.
-- | List of requested fields.
type Fields = [ String ]
-- | Query2 filter expression.
data Filter
= AndFilter [ Filter ] -- ^ & [<expression>, ...]
| OrFilter [ Filter ] -- ^ | [<expression>, ...]
| NotFilter Filter -- ^ ! <expression>
| TrueFilter FilterField -- ^ ? <field>
| EqualFilter FilterField FilterValue -- ^ (=|!=) <field> <value>
| RegexpFilter FilterField FilterRegexp -- ^ =~ <field> <regexp>
| ContainsFilter FilterField FilterValue -- ^ =[] <list-field> <value>
-- | Field name to filter on.
type FilterField = String
-- | Value to compare the field value to, for filtering purposes.
type FilterValue = String
-- | Regexp to apply to the filter value, for filteriong purposes.
type FilterRegexp = String
-- | Definition of a field.
data FieldDefinition = FieldDefinition FieldName FieldTitle FieldType FieldDoc
-- | Name of a field.
type FieldName = String
-- | Title of a field, when represented in tabular format.
type FieldTitle = String
-- | Human redable description of a field.
type FieldDoc = String
--- | Single field entry result.
data ResultEntry = ResultEntry ResultStatus (Maybe ResultValue)
-- | Value of a field, in json encoding.
-- (its type will be depending on ResultStatus and FieldType)
type ResultValue = JSValue
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment