Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.9 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 525bfb36 Iustin Pop
-- | Our ADT for the OpCode status at runtime (while in a job).
37 41065165 Iustin Pop
data OpStatus = OP_STATUS_QUEUED
38 47099cd1 Michael Hanselmann
              | OP_STATUS_WAITING
39 41065165 Iustin Pop
              | OP_STATUS_CANCELING
40 41065165 Iustin Pop
              | OP_STATUS_RUNNING
41 41065165 Iustin Pop
              | OP_STATUS_CANCELED
42 41065165 Iustin Pop
              | OP_STATUS_SUCCESS
43 41065165 Iustin Pop
              | OP_STATUS_ERROR
44 6bc39970 Iustin Pop
                deriving (Eq, Enum, Bounded, Show, Read)
45 41065165 Iustin Pop
46 41065165 Iustin Pop
instance JSON OpStatus where
47 41065165 Iustin Pop
    showJSON os = showJSON w
48 41065165 Iustin Pop
      where w = case os of
49 6a5e7dbe Iustin Pop
              OP_STATUS_QUEUED    -> C.opStatusQueued
50 6a5e7dbe Iustin Pop
              OP_STATUS_WAITING   -> C.opStatusWaiting
51 6a5e7dbe Iustin Pop
              OP_STATUS_CANCELING -> C.opStatusCanceling
52 6a5e7dbe Iustin Pop
              OP_STATUS_RUNNING   -> C.opStatusRunning
53 6a5e7dbe Iustin Pop
              OP_STATUS_CANCELED  -> C.opStatusCanceled
54 6a5e7dbe Iustin Pop
              OP_STATUS_SUCCESS   -> C.opStatusSuccess
55 6a5e7dbe Iustin Pop
              OP_STATUS_ERROR     -> C.opStatusError
56 41065165 Iustin Pop
    readJSON s = case readJSON s of
57 6a5e7dbe Iustin Pop
      J.Ok v | v == C.opStatusQueued    -> J.Ok OP_STATUS_QUEUED
58 6a5e7dbe Iustin Pop
             | v == C.opStatusWaiting   -> J.Ok OP_STATUS_WAITING
59 6a5e7dbe Iustin Pop
             | v == C.opStatusCanceling -> J.Ok OP_STATUS_CANCELING
60 6a5e7dbe Iustin Pop
             | v == C.opStatusRunning   -> J.Ok OP_STATUS_RUNNING
61 6a5e7dbe Iustin Pop
             | v == C.opStatusCanceled  -> J.Ok OP_STATUS_CANCELED
62 6a5e7dbe Iustin Pop
             | v == C.opStatusSuccess   -> J.Ok OP_STATUS_SUCCESS
63 6a5e7dbe Iustin Pop
             | v == C.opStatusError     -> J.Ok OP_STATUS_ERROR
64 56c094b4 Iustin Pop
             | otherwise -> J.Error ("Unknown opcode status " ++ v)
65 56c094b4 Iustin Pop
      _ -> J.Error ("Cannot parse opcode status " ++ show s)
66 41065165 Iustin Pop
67 13b6cb3f Iustin Pop
-- | The JobStatus data type. Note that this is ordered especially
68 c4ef235b Iustin Pop
-- such that greater\/lesser comparison on values of this type makes
69 13b6cb3f Iustin Pop
-- sense.
70 7e98f782 Iustin Pop
data JobStatus = JOB_STATUS_QUEUED
71 47099cd1 Michael Hanselmann
               | JOB_STATUS_WAITING
72 7e98f782 Iustin Pop
               | JOB_STATUS_RUNNING
73 7e98f782 Iustin Pop
               | JOB_STATUS_SUCCESS
74 7e98f782 Iustin Pop
               | JOB_STATUS_CANCELING
75 7e98f782 Iustin Pop
               | JOB_STATUS_CANCELED
76 7e98f782 Iustin Pop
               | JOB_STATUS_ERROR
77 6bc39970 Iustin Pop
                 deriving (Eq, Enum, Ord, Bounded, Show, Read)
78 13b6cb3f Iustin Pop
79 13b6cb3f Iustin Pop
instance JSON JobStatus where
80 13b6cb3f Iustin Pop
    showJSON js = showJSON w
81 13b6cb3f Iustin Pop
        where w = case js of
82 6a5e7dbe Iustin Pop
                JOB_STATUS_QUEUED    -> C.jobStatusQueued
83 6a5e7dbe Iustin Pop
                JOB_STATUS_WAITING   -> C.jobStatusWaiting
84 6a5e7dbe Iustin Pop
                JOB_STATUS_CANCELING -> C.jobStatusCanceling
85 6a5e7dbe Iustin Pop
                JOB_STATUS_RUNNING   -> C.jobStatusRunning
86 6a5e7dbe Iustin Pop
                JOB_STATUS_CANCELED  -> C.jobStatusCanceled
87 6a5e7dbe Iustin Pop
                JOB_STATUS_SUCCESS   -> C.jobStatusSuccess
88 6a5e7dbe Iustin Pop
                JOB_STATUS_ERROR     -> C.jobStatusError
89 13b6cb3f Iustin Pop
    readJSON s = case readJSON s of
90 6a5e7dbe Iustin Pop
      J.Ok v | v == C.jobStatusQueued    -> J.Ok JOB_STATUS_QUEUED
91 6a5e7dbe Iustin Pop
             | v == C.jobStatusWaiting   -> J.Ok JOB_STATUS_WAITING
92 6a5e7dbe Iustin Pop
             | v == C.jobStatusCanceling -> J.Ok JOB_STATUS_CANCELING
93 6a5e7dbe Iustin Pop
             | v == C.jobStatusRunning   -> J.Ok JOB_STATUS_RUNNING
94 6a5e7dbe Iustin Pop
             | v == C.jobStatusSuccess   -> J.Ok JOB_STATUS_SUCCESS
95 6a5e7dbe Iustin Pop
             | v == C.jobStatusCanceled  -> J.Ok JOB_STATUS_CANCELED
96 6a5e7dbe Iustin Pop
             | v == C.jobStatusError     -> J.Ok JOB_STATUS_ERROR
97 6a5e7dbe Iustin Pop
             | otherwise -> J.Error ("Unknown job status " ++ v)
98 7e98f782 Iustin Pop
      _ -> J.Error ("Unknown job status " ++ show s)