Commit 6bc39970 authored by Iustin Pop's avatar Iustin Pop

Add 'Read' instances for most objects

This allows a cluster structure to be easily serialized via "read";
together with the already existing instances of Show, this gives a
poor man's serialization/deserialization implementation.

The patch also exports the compDetailedCV function from Cluster.hs, so
that it can be used by other modules too.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 6eaa7bb8
......@@ -51,6 +51,7 @@ module Ganeti.HTools.Cluster
, doNextBalance
, tryBalance
, compCV
, compDetailedCV
, printStats
, iMoveToJob
-- * IAllocator functions
......@@ -102,7 +103,7 @@ emptySolution = AllocSolution { asFailures = [], asAllocs = 0
-- | The complete state for the balancing solution
data Table = Table Node.List Instance.List Score [Placement]
deriving (Show)
deriving (Show, Read)
data CStats = CStats { csFmem :: Int -- ^ Cluster free mem
, csFdsk :: Int -- ^ Cluster free disk
......@@ -126,7 +127,7 @@ data CStats = CStats { csFmem :: Int -- ^ Cluster free mem
, csScore :: Score -- ^ The cluster score
, csNinst :: Int -- ^ The total number of instances
}
deriving (Show)
deriving (Show, Read)
-- | Currently used, possibly to allocate, unallocable
type AllocStats = (RSpec, RSpec, RSpec)
......
......@@ -44,7 +44,7 @@ data Group = Group
, uuid :: T.GroupID -- ^ The UUID of the group
, idx :: T.Gdx -- ^ Internal index for book-keeping
, allocPolicy :: T.AllocPolicy -- ^ The allocation policy for this group
} deriving (Show, Eq)
} deriving (Show, Read, Eq)
-- Note: we use the name as the alias, and the UUID as the official
-- name
......
......@@ -7,7 +7,7 @@ intelligence is in the "Node" and "Cluster" modules.
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 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
......@@ -62,7 +62,7 @@ data Instance = Instance { name :: String -- ^ The instance name
, util :: T.DynUtil -- ^ Dynamic resource usage
, movable :: Bool -- ^ Can the instance be moved?
, tags :: [String] -- ^ List of instance tags
} deriving (Show)
} deriving (Show, Read)
instance T.Element Instance where
nameOf = name
......
......@@ -70,11 +70,11 @@ data RqType
| Relocate Idx Int [Ndx] -- ^ Move an instance to a new
-- secondary node
| Evacuate [Ndx] -- ^ Evacuate nodes
deriving (Show)
deriving (Show, Read)
-- | A complete request, as received from Ganeti.
data Request = Request RqType ClusterData
deriving (Show)
deriving (Show, Read)
-- | The cluster state.
data ClusterData = ClusterData
......@@ -82,7 +82,7 @@ data ClusterData = ClusterData
, cdNodes :: Node.List -- ^ The node list
, cdInstances :: Instance.List -- ^ The instance list
, cdTags :: [String] -- ^ The cluster tags
} deriving (Show)
} deriving (Show, Read)
-- | An empty cluster.
emptyCluster :: ClusterData
......
......@@ -122,7 +122,7 @@ data Node = Node
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
, group :: T.Gdx -- ^ The node's group (index)
} deriving (Show, Eq)
} deriving (Show, Read, Eq)
instance T.Element Node where
nameOf = name
......
......@@ -98,7 +98,7 @@ data AllocPolicy
-- last-resort, after the preferred groups
| AllocUnallocable -- ^ This group must not be used for new
-- allocations
deriving (Show, Eq, Ord)
deriving (Show, Read, Eq, Ord)
-- | Convert a string to an alloc policy
apolFromString :: (Monad m) => String -> m AllocPolicy
......@@ -127,7 +127,7 @@ data RSpec = RSpec
{ rspecCpu :: Int -- ^ Requested VCPUs
, rspecMem :: Int -- ^ Requested memory
, rspecDsk :: Int -- ^ Requested disk
} deriving (Show, Eq)
} deriving (Show, Read, Eq)
-- | The dynamic resource specs of a machine (i.e. load or load
-- capacity, as opposed to size).
......@@ -136,7 +136,7 @@ data DynUtil = DynUtil
, memWeight :: Weight -- ^ Standardised memory load
, dskWeight :: Weight -- ^ Standardised disk I\/O usage
, netWeight :: Weight -- ^ Standardised network usage
} deriving (Show, Eq)
} deriving (Show, Read, Eq)
-- | Initial empty utilisation
zeroUtil :: DynUtil
......@@ -166,7 +166,7 @@ data IMove = Failover -- ^ Failover the instance (f)
| ReplaceSecondary Ndx -- ^ Replace secondary (r:ns)
| ReplaceAndFailover Ndx -- ^ Replace secondary, failover (r:np, f)
| FailoverAndReplace Ndx -- ^ Failover, replace secondary (f, r:ns)
deriving (Show)
deriving (Show, Read)
-- | Formatted solution output for one move (involved nodes and
-- commands
......@@ -217,7 +217,7 @@ mini-library here
data Result a
= Bad String
| Ok a
deriving (Show)
deriving (Show, Read)
instance Monad Result where
(>>=) (Bad x) _ = Bad x
......@@ -240,7 +240,7 @@ data FailMode = FailMem -- ^ Failed due to not enough RAM
| FailCPU -- ^ Failed due to not enough CPU capacity
| FailN1 -- ^ Failed due to not passing N1 checks
| FailTags -- ^ Failed due to tag exclusion
deriving (Eq, Enum, Bounded, Show)
deriving (Eq, Enum, Bounded, Show, Read)
-- | List with failure statistics
type FailStats = [(FailMode, Int)]
......@@ -248,7 +248,7 @@ type FailStats = [(FailMode, Int)]
-- | Either-like data-type customized for our failure modes
data OpResult a = OpFail FailMode -- ^ Failed operation
| OpGood a -- ^ Success operation
deriving (Show)
deriving (Show, Read)
instance Monad OpResult where
(OpGood x) >>= fn = fn x
......
......@@ -4,7 +4,7 @@
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 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
......@@ -38,7 +38,7 @@ data OpStatus = OP_STATUS_QUEUED
| OP_STATUS_CANCELED
| OP_STATUS_SUCCESS
| OP_STATUS_ERROR
deriving (Eq, Enum, Bounded, Show)
deriving (Eq, Enum, Bounded, Show, Read)
instance JSON OpStatus where
showJSON os = showJSON w
......@@ -70,7 +70,7 @@ data JobStatus = JOB_STATUS_QUEUED
| JOB_STATUS_CANCELING
| JOB_STATUS_CANCELED
| JOB_STATUS_ERROR
deriving (Eq, Enum, Ord, Bounded, Show)
deriving (Eq, Enum, Ord, Bounded, Show, Read)
instance JSON JobStatus where
showJSON js = showJSON w
......
......@@ -76,7 +76,7 @@ data LuxiOp = QueryInstances [String] [String] Bool
| CancelJob Int
| SetDrainFlag Bool
| SetWatcherPause Double
deriving (Show)
deriving (Show, Read)
-- | The serialisation of LuxiOps into strings in messages.
strOfOp :: LuxiOp -> String
......
......@@ -4,7 +4,7 @@
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 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
......@@ -40,7 +40,7 @@ data ReplaceDisksMode = ReplaceOnPrimary
| ReplaceOnSecondary
| ReplaceNewSecondary
| ReplaceAuto
deriving (Show, Eq)
deriving (Show, Read, Eq)
instance JSON ReplaceDisksMode where
showJSON m = case m of
......@@ -60,7 +60,7 @@ data OpCode = OpTestDelay Double Bool [String]
[Int] (Maybe String)
| OpFailoverInstance String Bool
| OpMigrateInstance String Bool Bool
deriving (Show, Eq)
deriving (Show, Read, Eq)
opID :: OpCode -> String
......
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