Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Types.hs @ a2e90275

History | View | Annotate | Download (3.7 kB)

1 e4c5beaf Iustin Pop
{-| Some common types.
2 e4c5beaf Iustin Pop
3 e4c5beaf Iustin Pop
-}
4 e4c5beaf Iustin Pop
5 e2fa2baf Iustin Pop
{-
6 e2fa2baf Iustin Pop
7 e2fa2baf Iustin Pop
Copyright (C) 2009 Google Inc.
8 e2fa2baf Iustin Pop
9 e2fa2baf Iustin Pop
This program is free software; you can redistribute it and/or modify
10 e2fa2baf Iustin Pop
it under the terms of the GNU General Public License as published by
11 e2fa2baf Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 e2fa2baf Iustin Pop
(at your option) any later version.
13 e2fa2baf Iustin Pop
14 e2fa2baf Iustin Pop
This program is distributed in the hope that it will be useful, but
15 e2fa2baf Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 e2fa2baf Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 e2fa2baf Iustin Pop
General Public License for more details.
18 e2fa2baf Iustin Pop
19 e2fa2baf Iustin Pop
You should have received a copy of the GNU General Public License
20 e2fa2baf Iustin Pop
along with this program; if not, write to the Free Software
21 e2fa2baf Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 e2fa2baf Iustin Pop
02110-1301, USA.
23 e2fa2baf Iustin Pop
24 e2fa2baf Iustin Pop
-}
25 e2fa2baf Iustin Pop
26 e4c5beaf Iustin Pop
module Ganeti.HTools.Types
27 19f38ee8 Iustin Pop
    ( Idx
28 19f38ee8 Iustin Pop
    , Ndx
29 19f38ee8 Iustin Pop
    , NameAssoc
30 92e32d76 Iustin Pop
    , Score
31 92e32d76 Iustin Pop
    , Placement
32 92e32d76 Iustin Pop
    , IMove(..)
33 0e8ae201 Iustin Pop
    , MoveJob
34 0e8ae201 Iustin Pop
    , JobSet
35 19f38ee8 Iustin Pop
    , Result(..)
36 19f38ee8 Iustin Pop
    , Element(..)
37 f2280553 Iustin Pop
    , FailMode(..)
38 478df686 Iustin Pop
    , FailStats
39 f2280553 Iustin Pop
    , OpResult(..)
40 135a6c6a Iustin Pop
    , connTimeout
41 135a6c6a Iustin Pop
    , queryTimeout
42 19f38ee8 Iustin Pop
    ) where
43 e4c5beaf Iustin Pop
44 9188aeef Iustin Pop
-- | The instance index type.
45 608efcce Iustin Pop
type Idx = Int
46 608efcce Iustin Pop
47 9188aeef Iustin Pop
-- | The node index type.
48 608efcce Iustin Pop
type Ndx = Int
49 608efcce Iustin Pop
50 9188aeef Iustin Pop
-- | The type used to hold name-to-idx mappings.
51 e4c5beaf Iustin Pop
type NameAssoc = [(String, Int)]
52 e4c5beaf Iustin Pop
53 92e32d76 Iustin Pop
-- | A separate name for the cluster score type.
54 92e32d76 Iustin Pop
type Score = Double
55 92e32d76 Iustin Pop
56 92e32d76 Iustin Pop
-- | The description of an instance placement.
57 92e32d76 Iustin Pop
type Placement = ( Idx   -- ^ The index of the instance being moved
58 92e32d76 Iustin Pop
                 , Ndx   -- ^ New primary node
59 92e32d76 Iustin Pop
                 , Ndx   -- ^ New secondary node
60 92e32d76 Iustin Pop
                 , IMove -- ^ The move being performed
61 92e32d76 Iustin Pop
                 , Score -- ^ The score of the cluster after this move
62 92e32d76 Iustin Pop
                 )
63 92e32d76 Iustin Pop
64 92e32d76 Iustin Pop
-- | An instance move definition
65 92e32d76 Iustin Pop
data IMove = Failover                -- ^ Failover the instance (f)
66 92e32d76 Iustin Pop
           | ReplacePrimary Ndx      -- ^ Replace primary (f, r:np, f)
67 92e32d76 Iustin Pop
           | ReplaceSecondary Ndx    -- ^ Replace secondary (r:ns)
68 92e32d76 Iustin Pop
           | ReplaceAndFailover Ndx  -- ^ Replace secondary, failover (r:np, f)
69 92e32d76 Iustin Pop
           | FailoverAndReplace Ndx  -- ^ Failover, replace secondary (f, r:ns)
70 92e32d76 Iustin Pop
             deriving (Show)
71 92e32d76 Iustin Pop
72 0e8ae201 Iustin Pop
-- | Formatted solution output for one move (involved nodes and
73 0e8ae201 Iustin Pop
-- commands
74 a2e90275 Iustin Pop
type MoveJob = ([Ndx], IMove, [String])
75 0e8ae201 Iustin Pop
76 0e8ae201 Iustin Pop
-- | A list of command elements
77 0e8ae201 Iustin Pop
type JobSet = [MoveJob]
78 0e8ae201 Iustin Pop
79 135a6c6a Iustin Pop
-- | Connection timeout (when using non-file methods).
80 135a6c6a Iustin Pop
connTimeout :: Int
81 135a6c6a Iustin Pop
connTimeout = 15
82 135a6c6a Iustin Pop
83 135a6c6a Iustin Pop
-- | The default timeout for queries (when using non-file methods).
84 135a6c6a Iustin Pop
queryTimeout :: Int
85 135a6c6a Iustin Pop
queryTimeout = 60
86 135a6c6a Iustin Pop
87 262a08a2 Iustin Pop
{-|
88 e4c5beaf Iustin Pop
89 e4c5beaf Iustin Pop
This is similar to the JSON library Result type - *very* similar, but
90 e4c5beaf Iustin Pop
we want to use it in multiple places, so we abstract it into a
91 e4c5beaf Iustin Pop
mini-library here
92 e4c5beaf Iustin Pop
93 e4c5beaf Iustin Pop
-}
94 e4c5beaf Iustin Pop
data Result a
95 e4c5beaf Iustin Pop
    = Bad String
96 e4c5beaf Iustin Pop
    | Ok a
97 e4c5beaf Iustin Pop
    deriving (Show)
98 e4c5beaf Iustin Pop
99 e4c5beaf Iustin Pop
instance Monad Result where
100 e4c5beaf Iustin Pop
    (>>=) (Bad x) _ = Bad x
101 e4c5beaf Iustin Pop
    (>>=) (Ok x) fn = fn x
102 e4c5beaf Iustin Pop
    return = Ok
103 e4c5beaf Iustin Pop
    fail = Bad
104 497e30a1 Iustin Pop
105 f2280553 Iustin Pop
-- | Reason for an operation's falure
106 f2280553 Iustin Pop
data FailMode = FailMem  -- ^ Failed due to not enough RAM
107 f2280553 Iustin Pop
              | FailDisk -- ^ Failed due to not enough disk
108 f2280553 Iustin Pop
              | FailCPU  -- ^ Failed due to not enough CPU capacity
109 f2280553 Iustin Pop
              | FailN1   -- ^ Failed due to not passing N1 checks
110 2bbf77cc Iustin Pop
                deriving (Eq, Enum, Bounded, Show)
111 f2280553 Iustin Pop
112 478df686 Iustin Pop
-- | List with failure statistics
113 478df686 Iustin Pop
type FailStats = [(FailMode, Int)]
114 478df686 Iustin Pop
115 f2280553 Iustin Pop
-- | Either-like data-type customized for our failure modes
116 f2280553 Iustin Pop
data OpResult a = OpFail FailMode -- ^ Failed operation
117 f2280553 Iustin Pop
                | OpGood a        -- ^ Success operation
118 f2280553 Iustin Pop
119 f2280553 Iustin Pop
instance Monad OpResult where
120 f2280553 Iustin Pop
    (OpGood x) >>= fn = fn x
121 f2280553 Iustin Pop
    (OpFail y) >>= _ = OpFail y
122 f2280553 Iustin Pop
    return = OpGood
123 f2280553 Iustin Pop
124 9188aeef Iustin Pop
-- | A generic class for items that have updateable names and indices.
125 497e30a1 Iustin Pop
class Element a where
126 9188aeef Iustin Pop
    -- | Returns the name of the element
127 262a08a2 Iustin Pop
    nameOf  :: a -> String
128 9188aeef Iustin Pop
    -- | Returns the index of the element
129 262a08a2 Iustin Pop
    idxOf   :: a -> Int
130 9188aeef Iustin Pop
    -- | Updates the name of the element
131 497e30a1 Iustin Pop
    setName :: a -> String -> a
132 9188aeef Iustin Pop
    -- | Updates the index of the element
133 497e30a1 Iustin Pop
    setIdx  :: a -> Int -> a