Commit 74b3f734 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Use ClockTime instead of Double in fields in Objects.hs



This affects "mtime" and "ctime" fields in all data types.

This also forces explicit declaration of how the fields are serialized
in Query.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 836ccf52
......@@ -43,7 +43,7 @@ $(buildObject "InstStatus" "iStat"
, simpleField "actualState" [t| ActualState |]
, optionalNullSerField $
simpleField "uptime" [t| String |]
, simpleField "mtime" [t| Double |]
, timeAsDoubleField "mtime"
, simpleField "state_reason" [t| ReasonTrail |]
, simpleField "status" [t| DCStatus |]
])
......
......@@ -94,6 +94,7 @@ import Data.Maybe
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Word
import System.Time (ClockTime(..))
import Text.JSON (showJSON, readJSON, JSON, JSValue(..), fromJSString)
import qualified Text.JSON as J
......@@ -125,8 +126,8 @@ type OsParams = Container String
-- | Class of objects that have timestamps.
class TimeStampObject a where
cTimeOf :: a -> Double
mTimeOf :: a -> Double
cTimeOf :: a -> ClockTime
mTimeOf :: a -> ClockTime
-- | Class of objects that have an UUID.
class UuidObject a where
......
......@@ -135,9 +135,9 @@ rpcErrorToStatus _ = RSNoData
timeStampFields :: (TimeStampObject a) => FieldList a b
timeStampFields =
[ (FieldDefinition "ctime" "CTime" QFTTimestamp "Creation timestamp",
FieldSimple (rsNormal . cTimeOf), QffNormal)
FieldSimple (rsNormal . TimeAsDoubleJSON . cTimeOf), QffNormal)
, (FieldDefinition "mtime" "MTime" QFTTimestamp "Modification timestamp",
FieldSimple (rsNormal . mTimeOf), QffNormal)
FieldSimple (rsNormal . TimeAsDoubleJSON . mTimeOf), QffNormal)
]
-- | The list of UUID fields.
......
......@@ -53,6 +53,7 @@ import Ganeti.ConfigReader
import Ganeti.BasicTypes
import Ganeti.JQueue
import Ganeti.JQScheduler
import Ganeti.JSON (TimeAsDoubleJSON(..))
import Ganeti.Logging
import Ganeti.Luxi
import qualified Ganeti.Query.Language as Qlang
......@@ -143,8 +144,8 @@ handleCall _ _ cdata QueryClusterInfo =
showJSON $ clusterGlusterStorageDir cluster)
, ("maintain_node_health",
showJSON $ clusterMaintainNodeHealth cluster)
, ("ctime", showJSON $ clusterCtime cluster)
, ("mtime", showJSON $ clusterMtime cluster)
, ("ctime", showJSON . TimeAsDoubleJSON $ clusterCtime cluster)
, ("mtime", showJSON . TimeAsDoubleJSON $ clusterMtime cluster)
, ("uuid", showJSON $ clusterUuid cluster)
, ("tags", showJSON $ clusterTags cluster)
, ("uid_pool", showJSON $ clusterUidPool cluster)
......
......@@ -316,10 +316,9 @@ loadFnOpt field expr o
-- | Timestamp fields description.
timeStampFields :: [Field]
timeStampFields =
[ defaultField [| 0::Double |] $ simpleField "ctime" [t| Double |]
, defaultField [| 0::Double |] $ simpleField "mtime" [t| Double |]
]
timeStampFields = map (defaultField [| TOD 0 0 |] . timeAsDoubleField)
["ctime", "mtime"]
-- | Serial number fields description.
serialFields :: [Field]
......
......@@ -32,6 +32,7 @@ module Test.Ganeti.Query.Instance
import qualified Data.Map as Map
import qualified Data.Set as Set
import System.Time (ClockTime(..))
import Ganeti.JSON
import Ganeti.Objects
......@@ -52,7 +53,8 @@ createInstance name pnodeUuid adminState =
(GenericContainer Map.empty)
(PartialBeParams Nothing Nothing Nothing Nothing Nothing Nothing)
(GenericContainer Map.empty)
adminState [] [] DTDrbd8 False Nothing 0.0 0.0 "" 0 Set.empty
adminState [] [] DTDrbd8 False Nothing epochTime epochTime "" 0 Set.empty
where epochTime = TOD 0 0
-- | A fake InstanceInfo to be used to check values.
fakeInstanceInfo :: InstanceInfo
......
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