module Ganeti.Jobs
( OpStatus(..)
, JobStatus(..)
) where
import Text.JSON (readJSON, showJSON, JSON)
import qualified Text.JSON as J
data OpStatus = OP_STATUS_QUEUED
| OP_STATUS_WAITLOCK
| OP_STATUS_CANCELING
| OP_STATUS_RUNNING
| OP_STATUS_CANCELED
| OP_STATUS_SUCCESS
| OP_STATUS_ERROR
deriving (Eq, Enum, Bounded, Show, Read)
instance JSON OpStatus where
showJSON os = showJSON w
where w = case os of
OP_STATUS_QUEUED -> "queued"
OP_STATUS_WAITLOCK -> "waiting"
OP_STATUS_CANCELING -> "canceling"
OP_STATUS_RUNNING -> "running"
OP_STATUS_CANCELED -> "canceled"
OP_STATUS_SUCCESS -> "success"
OP_STATUS_ERROR -> "error"
readJSON s = case readJSON s of
J.Ok "queued" -> J.Ok OP_STATUS_QUEUED
J.Ok "waiting" -> J.Ok OP_STATUS_WAITLOCK
J.Ok "canceling" -> J.Ok OP_STATUS_CANCELING
J.Ok "running" -> J.Ok OP_STATUS_RUNNING
J.Ok "canceled" -> J.Ok OP_STATUS_CANCELED
J.Ok "success" -> J.Ok OP_STATUS_SUCCESS
J.Ok "error" -> J.Ok OP_STATUS_ERROR
_ -> J.Error ("Unknown opcode status " ++ show s)
data JobStatus = JOB_STATUS_QUEUED
| JOB_STATUS_WAITLOCK
| JOB_STATUS_RUNNING
| JOB_STATUS_SUCCESS
| JOB_STATUS_CANCELING
| JOB_STATUS_CANCELED
| JOB_STATUS_ERROR
deriving (Eq, Enum, Ord, Bounded, Show, Read)
instance JSON JobStatus where
showJSON js = showJSON w
where w = case js of
JOB_STATUS_QUEUED -> "queued"
JOB_STATUS_WAITLOCK -> "waiting"
JOB_STATUS_CANCELING -> "canceling"
JOB_STATUS_RUNNING -> "running"
JOB_STATUS_CANCELED -> "canceled"
JOB_STATUS_SUCCESS -> "success"
JOB_STATUS_ERROR -> "error"
readJSON s = case readJSON s of
J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED
J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK
J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING
J.Ok "running" -> J.Ok JOB_STATUS_RUNNING
J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS
J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED
J.Ok "error" -> J.Ok JOB_STATUS_ERROR
_ -> J.Error ("Unknown job status " ++ show s)