Commit 3bdbe4b3 authored by Dato Simó's avatar Dato Simó
Browse files

Jobs.hs: move OpStatus and JobStatus ADTs to Types.hs



This leaves Ganeti/Jobs.hs and Test/Ganeti/Jobs.hs empty, but they're the
target of a future move of some functions, so we leave them around, and
don't delete them, to avoid unnecessary delete/create diffs.
Signed-off-by: default avatarDato Simó <dato@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent de645b5b
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Unittests for ganeti-htools.
-}
......@@ -28,29 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Test.Ganeti.Jobs (testJobs) where
import Test.QuickCheck
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import qualified Ganeti.Jobs as Jobs
-- * Arbitrary instances
$(genArbitrary ''Jobs.OpStatus)
$(genArbitrary ''Jobs.JobStatus)
-- * Test cases
-- | Check that (queued) job\/opcode status serialization is idempotent.
prop_OpStatus_serialization :: Jobs.OpStatus -> Property
prop_OpStatus_serialization = testSerialisation
prop_JobStatus_serialization :: Jobs.JobStatus -> Property
prop_JobStatus_serialization = testSerialisation
testSuite "Jobs"
[ 'prop_OpStatus_serialization
, 'prop_JobStatus_serialization
[
]
......@@ -115,6 +115,8 @@ $(genArbitrary ''NetworkType)
$(genArbitrary ''NICMode)
$(genArbitrary ''JobStatus)
$(genArbitrary ''FinalizedJobStatus)
instance Arbitrary JobId where
......@@ -128,6 +130,8 @@ $(genArbitrary ''JobDependency)
$(genArbitrary ''OpSubmitPriority)
$(genArbitrary ''OpStatus)
-- * Properties
prop_AllocPolicy_serialisation :: AllocPolicy -> Property
......@@ -287,6 +291,14 @@ case_NetworkType_pyequiv = do
prop_NICMode_serialisation :: NICMode -> Property
prop_NICMode_serialisation = testSerialisation
-- | Test 'OpStatus' serialisation.
prop_OpStatus_serialization :: OpStatus -> Property
prop_OpStatus_serialization = testSerialisation
-- | Test 'JobStatus' serialisation.
prop_JobStatus_serialization :: JobStatus -> Property
prop_JobStatus_serialization = testSerialisation
-- | Tests equivalence with Python, based on Constants.hs code.
case_NICMode_pyequiv :: Assertion
case_NICMode_pyequiv = do
......@@ -352,6 +364,8 @@ testSuite "Types"
, 'prop_NetworkType_serialisation
, 'case_NetworkType_pyequiv
, 'prop_NICMode_serialisation
, 'prop_OpStatus_serialization
, 'prop_JobStatus_serialization
, 'case_NICMode_pyequiv
, 'prop_FinalizedJobStatus_serialisation
, 'case_FinalizedJobStatus_pyequiv
......
......@@ -57,11 +57,10 @@ import Ganeti.HTools.ExtLoader
import Ganeti.HTools.Types
import Ganeti.HTools.Loader
import Ganeti.OpCodes (wrapOpCode, setOpComment, OpCode, MetaOpCode)
import Ganeti.Types (fromJobId)
import Ganeti.Types
import Ganeti.Utils
import qualified Ganeti.Luxi as L
import Ganeti.Jobs
import Ganeti.Version (version)
-- | Options list and functions.
......
{-# LANGUAGE TemplateHaskell #-}
{-| Implementation of the job information.
-}
......@@ -26,35 +24,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.Jobs
( OpStatus(..)
, JobStatus(..)
(
) where
import qualified Ganeti.Constants as C
import qualified Ganeti.THH as THH
-- | Our ADT for the OpCode status at runtime (while in a job).
$(THH.declareSADT "OpStatus"
[ ("OP_STATUS_QUEUED", 'C.opStatusQueued)
, ("OP_STATUS_WAITING", 'C.opStatusWaiting)
, ("OP_STATUS_CANCELING", 'C.opStatusCanceling)
, ("OP_STATUS_RUNNING", 'C.opStatusRunning)
, ("OP_STATUS_CANCELED", 'C.opStatusCanceled)
, ("OP_STATUS_SUCCESS", 'C.opStatusSuccess)
, ("OP_STATUS_ERROR", 'C.opStatusError)
])
$(THH.makeJSONInstance ''OpStatus)
-- | The JobStatus data type. Note that this is ordered especially
-- such that greater\/lesser comparison on values of this type makes
-- sense.
$(THH.declareSADT "JobStatus"
[ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued)
, ("JOB_STATUS_WAITING", 'C.jobStatusWaiting)
, ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling)
, ("JOB_STATUS_RUNNING", 'C.jobStatusRunning)
, ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled)
, ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess)
, ("JOB_STATUS_ERROR", 'C.jobStatusError)
])
$(THH.makeJSONInstance ''JobStatus)
......@@ -72,7 +72,6 @@ import Ganeti.BasicTypes
import Ganeti.Constants
import Ganeti.Errors
import Ganeti.JSON
import Ganeti.Jobs (JobStatus)
import Ganeti.OpParams (pTagsObject)
import Ganeti.OpCodes
import qualified Ganeti.Query.Language as Qlang
......
......@@ -74,6 +74,9 @@ module Ganeti.Types
, networkTypeToRaw
, NICMode(..)
, nICModeToRaw
, JobStatus(..)
, jobStatusToRaw
, jobStatusFromRaw
, FinalizedJobStatus(..)
, finalizedJobStatusToRaw
, JobId
......@@ -83,6 +86,9 @@ module Ganeti.Types
, JobIdDep(..)
, JobDependency(..)
, OpSubmitPriority(..)
, OpStatus(..)
, opStatusToRaw
, opStatusFromRaw
) where
import Control.Monad (liftM)
......@@ -363,6 +369,20 @@ $(THH.declareSADT "NICMode"
])
$(THH.makeJSONInstance ''NICMode)
-- | The JobStatus data type. Note that this is ordered especially
-- such that greater\/lesser comparison on values of this type makes
-- sense.
$(THH.declareSADT "JobStatus"
[ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued)
, ("JOB_STATUS_WAITING", 'C.jobStatusWaiting)
, ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling)
, ("JOB_STATUS_RUNNING", 'C.jobStatusRunning)
, ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled)
, ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess)
, ("JOB_STATUS_ERROR", 'C.jobStatusError)
])
$(THH.makeJSONInstance ''JobStatus)
-- | Finalized job status.
$(THH.declareSADT "FinalizedJobStatus"
[ ("JobStatusCanceled", 'C.jobStatusCanceled)
......@@ -429,3 +449,15 @@ $(THH.declareIADT "OpSubmitPriority"
, ("OpPrioHigh", 'C.opPrioHigh)
])
$(THH.makeJSONInstance ''OpSubmitPriority)
-- | Our ADT for the OpCode status at runtime (while in a job).
$(THH.declareSADT "OpStatus"
[ ("OP_STATUS_QUEUED", 'C.opStatusQueued)
, ("OP_STATUS_WAITING", 'C.opStatusWaiting)
, ("OP_STATUS_CANCELING", 'C.opStatusCanceling)
, ("OP_STATUS_RUNNING", 'C.opStatusRunning)
, ("OP_STATUS_CANCELED", 'C.opStatusCanceled)
, ("OP_STATUS_SUCCESS", 'C.opStatusSuccess)
, ("OP_STATUS_ERROR", 'C.opStatusError)
])
$(THH.makeJSONInstance ''OpStatus)
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