Revision b46ba79c htools/Ganeti/Types.hs
b/htools/Ganeti/Types.hs | ||
---|---|---|
79 | 79 |
, JobId |
80 | 80 |
, fromJobId |
81 | 81 |
, makeJobId |
82 |
, RelativeJobId |
|
83 |
, JobIdDep(..) |
|
84 |
, JobDependency(..) |
|
85 |
, OpSubmitPriority(..) |
|
82 | 86 |
) where |
83 | 87 |
|
88 |
import Control.Monad (liftM) |
|
84 | 89 |
import qualified Text.JSON as JSON |
90 |
import Text.JSON (JSON, readJSON, showJSON) |
|
85 | 91 |
import Data.Ratio (numerator, denominator) |
86 | 92 |
|
87 | 93 |
import qualified Ganeti.Constants as C |
... | ... | |
388 | 394 |
instance JSON.JSON JobId where |
389 | 395 |
showJSON = JSON.showJSON . fromJobId |
390 | 396 |
readJSON = parseJobId |
397 |
|
|
398 |
-- | Relative job ID type alias. |
|
399 |
type RelativeJobId = Negative Int |
|
400 |
|
|
401 |
-- | Job ID dependency. |
|
402 |
data JobIdDep = JobDepRelative RelativeJobId |
|
403 |
| JobDepAbsolute JobId |
|
404 |
deriving (Show, Eq) |
|
405 |
|
|
406 |
instance JSON.JSON JobIdDep where |
|
407 |
showJSON (JobDepRelative i) = showJSON i |
|
408 |
showJSON (JobDepAbsolute i) = showJSON i |
|
409 |
readJSON v = |
|
410 |
case JSON.readJSON v::JSON.Result (Negative Int) of |
|
411 |
-- first try relative dependency, usually most common |
|
412 |
JSON.Ok r -> return $ JobDepRelative r |
|
413 |
JSON.Error _ -> liftM JobDepAbsolute |
|
414 |
(fromJResult "parsing absolute job id" (readJSON v) >>= |
|
415 |
makeJobId) |
|
416 |
|
|
417 |
-- | Job Dependency type. |
|
418 |
data JobDependency = JobDependency JobIdDep [FinalizedJobStatus] |
|
419 |
deriving (Show, Eq) |
|
420 |
|
|
421 |
instance JSON JobDependency where |
|
422 |
showJSON (JobDependency dep status) = showJSON (dep, status) |
|
423 |
readJSON = liftM (uncurry JobDependency) . readJSON |
|
424 |
|
|
425 |
-- | Valid opcode priorities for submit. |
|
426 |
$(THH.declareIADT "OpSubmitPriority" |
|
427 |
[ ("OpPrioLow", 'C.opPrioLow) |
|
428 |
, ("OpPrioNormal", 'C.opPrioNormal) |
|
429 |
, ("OpPrioHigh", 'C.opPrioHigh) |
|
430 |
]) |
|
431 |
$(THH.makeJSONInstance ''OpSubmitPriority) |
Also available in: Unified diff