Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Jobs.hs @ 6c30ce16

History | View | Annotate | Download (3.6 kB)

1 13b6cb3f Iustin Pop
{-| Implementation of the job information.
2 13b6cb3f Iustin Pop
3 13b6cb3f Iustin Pop
-}
4 13b6cb3f Iustin Pop
5 13b6cb3f Iustin Pop
{-
6 13b6cb3f Iustin Pop
7 56c094b4 Iustin Pop
Copyright (C) 2009, 2010, 2011 Google Inc.
8 13b6cb3f Iustin Pop
9 13b6cb3f Iustin Pop
This program is free software; you can redistribute it and/or modify
10 13b6cb3f Iustin Pop
it under the terms of the GNU General Public License as published by
11 13b6cb3f Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 13b6cb3f Iustin Pop
(at your option) any later version.
13 13b6cb3f Iustin Pop
14 13b6cb3f Iustin Pop
This program is distributed in the hope that it will be useful, but
15 13b6cb3f Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 13b6cb3f Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 13b6cb3f Iustin Pop
General Public License for more details.
18 13b6cb3f Iustin Pop
19 13b6cb3f Iustin Pop
You should have received a copy of the GNU General Public License
20 13b6cb3f Iustin Pop
along with this program; if not, write to the Free Software
21 13b6cb3f Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 13b6cb3f Iustin Pop
02110-1301, USA.
23 13b6cb3f Iustin Pop
24 13b6cb3f Iustin Pop
-}
25 13b6cb3f Iustin Pop
26 13b6cb3f Iustin Pop
module Ganeti.Jobs
27 41065165 Iustin Pop
    ( OpStatus(..)
28 41065165 Iustin Pop
    , JobStatus(..)
29 13b6cb3f Iustin Pop
    ) where
30 13b6cb3f Iustin Pop
31 13b6cb3f Iustin Pop
import Text.JSON (readJSON, showJSON, JSON)
32 13b6cb3f Iustin Pop
import qualified Text.JSON as J
33 13b6cb3f Iustin Pop
34 56c094b4 Iustin Pop
import qualified Ganeti.Constants as C
35 56c094b4 Iustin Pop
36 41065165 Iustin Pop
data OpStatus = OP_STATUS_QUEUED
37 41065165 Iustin Pop
              | OP_STATUS_WAITLOCK
38 41065165 Iustin Pop
              | OP_STATUS_CANCELING
39 41065165 Iustin Pop
              | OP_STATUS_RUNNING
40 41065165 Iustin Pop
              | OP_STATUS_CANCELED
41 41065165 Iustin Pop
              | OP_STATUS_SUCCESS
42 41065165 Iustin Pop
              | OP_STATUS_ERROR
43 6bc39970 Iustin Pop
                deriving (Eq, Enum, Bounded, Show, Read)
44 41065165 Iustin Pop
45 41065165 Iustin Pop
instance JSON OpStatus where
46 41065165 Iustin Pop
    showJSON os = showJSON w
47 41065165 Iustin Pop
      where w = case os of
48 56c094b4 Iustin Pop
              OP_STATUS_QUEUED -> C.jobStatusQueued
49 56c094b4 Iustin Pop
              OP_STATUS_WAITLOCK -> C.jobStatusWaitlock
50 56c094b4 Iustin Pop
              OP_STATUS_CANCELING -> C.jobStatusCanceling
51 56c094b4 Iustin Pop
              OP_STATUS_RUNNING -> C.jobStatusRunning
52 56c094b4 Iustin Pop
              OP_STATUS_CANCELED -> C.jobStatusCanceled
53 56c094b4 Iustin Pop
              OP_STATUS_SUCCESS -> C.jobStatusSuccess
54 56c094b4 Iustin Pop
              OP_STATUS_ERROR -> C.jobStatusError
55 41065165 Iustin Pop
    readJSON s = case readJSON s of
56 56c094b4 Iustin Pop
      J.Ok v | v == C.jobStatusQueued -> J.Ok OP_STATUS_QUEUED
57 56c094b4 Iustin Pop
             | v == C.jobStatusWaitlock -> J.Ok OP_STATUS_WAITLOCK
58 56c094b4 Iustin Pop
             | v == C.jobStatusCanceling -> J.Ok OP_STATUS_CANCELING
59 56c094b4 Iustin Pop
             | v == C.jobStatusRunning -> J.Ok OP_STATUS_RUNNING
60 56c094b4 Iustin Pop
             | v == C.jobStatusCanceled -> J.Ok OP_STATUS_CANCELED
61 56c094b4 Iustin Pop
             | v == C.jobStatusSuccess -> J.Ok OP_STATUS_SUCCESS
62 56c094b4 Iustin Pop
             | v == C.jobStatusError -> J.Ok OP_STATUS_ERROR
63 56c094b4 Iustin Pop
             | otherwise -> J.Error ("Unknown opcode status " ++ v)
64 56c094b4 Iustin Pop
      _ -> J.Error ("Cannot parse opcode status " ++ show s)
65 41065165 Iustin Pop
66 13b6cb3f Iustin Pop
-- | The JobStatus data type. Note that this is ordered especially
67 c4ef235b Iustin Pop
-- such that greater\/lesser comparison on values of this type makes
68 13b6cb3f Iustin Pop
-- sense.
69 7e98f782 Iustin Pop
data JobStatus = JOB_STATUS_QUEUED
70 7e98f782 Iustin Pop
               | JOB_STATUS_WAITLOCK
71 7e98f782 Iustin Pop
               | JOB_STATUS_RUNNING
72 7e98f782 Iustin Pop
               | JOB_STATUS_SUCCESS
73 7e98f782 Iustin Pop
               | JOB_STATUS_CANCELING
74 7e98f782 Iustin Pop
               | JOB_STATUS_CANCELED
75 7e98f782 Iustin Pop
               | JOB_STATUS_ERROR
76 6bc39970 Iustin Pop
                 deriving (Eq, Enum, Ord, Bounded, Show, Read)
77 13b6cb3f Iustin Pop
78 13b6cb3f Iustin Pop
instance JSON JobStatus where
79 13b6cb3f Iustin Pop
    showJSON js = showJSON w
80 13b6cb3f Iustin Pop
        where w = case js of
81 7e98f782 Iustin Pop
                JOB_STATUS_QUEUED -> "queued"
82 7e98f782 Iustin Pop
                JOB_STATUS_WAITLOCK -> "waiting"
83 7e98f782 Iustin Pop
                JOB_STATUS_CANCELING -> "canceling"
84 7e98f782 Iustin Pop
                JOB_STATUS_RUNNING -> "running"
85 7e98f782 Iustin Pop
                JOB_STATUS_CANCELED -> "canceled"
86 7e98f782 Iustin Pop
                JOB_STATUS_SUCCESS -> "success"
87 7e98f782 Iustin Pop
                JOB_STATUS_ERROR -> "error"
88 13b6cb3f Iustin Pop
    readJSON s = case readJSON s of
89 7e98f782 Iustin Pop
      J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED
90 7e98f782 Iustin Pop
      J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK
91 7e98f782 Iustin Pop
      J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING
92 7e98f782 Iustin Pop
      J.Ok "running" -> J.Ok JOB_STATUS_RUNNING
93 7e98f782 Iustin Pop
      J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS
94 7e98f782 Iustin Pop
      J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED
95 7e98f782 Iustin Pop
      J.Ok "error" -> J.Ok JOB_STATUS_ERROR
96 7e98f782 Iustin Pop
      _ -> J.Error ("Unknown job status " ++ show s)