Statistics
| Branch: | Tag: | Revision:

root / Ganeti / Jobs.hs @ 6bc39970

History | View | Annotate | Download (3.3 kB)

1
{-| Implementation of the job information.
2

    
3
-}
4

    
5
{-
6

    
7
Copyright (C) 2009, 2010 Google Inc.
8

    
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13

    
14
This program is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
General Public License for more details.
18

    
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
02110-1301, USA.
23

    
24
-}
25

    
26
module Ganeti.Jobs
27
    ( OpStatus(..)
28
    , JobStatus(..)
29
    ) where
30

    
31
import Text.JSON (readJSON, showJSON, JSON)
32
import qualified Text.JSON as J
33

    
34
data OpStatus = OP_STATUS_QUEUED
35
              | OP_STATUS_WAITLOCK
36
              | OP_STATUS_CANCELING
37
              | OP_STATUS_RUNNING
38
              | OP_STATUS_CANCELED
39
              | OP_STATUS_SUCCESS
40
              | OP_STATUS_ERROR
41
                deriving (Eq, Enum, Bounded, Show, Read)
42

    
43
instance JSON OpStatus where
44
    showJSON os = showJSON w
45
      where w = case os of
46
              OP_STATUS_QUEUED -> "queued"
47
              OP_STATUS_WAITLOCK -> "waiting"
48
              OP_STATUS_CANCELING -> "canceling"
49
              OP_STATUS_RUNNING -> "running"
50
              OP_STATUS_CANCELED -> "canceled"
51
              OP_STATUS_SUCCESS -> "success"
52
              OP_STATUS_ERROR -> "error"
53
    readJSON s = case readJSON s of
54
      J.Ok "queued" -> J.Ok OP_STATUS_QUEUED
55
      J.Ok "waiting" -> J.Ok OP_STATUS_WAITLOCK
56
      J.Ok "canceling" -> J.Ok OP_STATUS_CANCELING
57
      J.Ok "running" -> J.Ok OP_STATUS_RUNNING
58
      J.Ok "canceled" -> J.Ok OP_STATUS_CANCELED
59
      J.Ok "success" -> J.Ok OP_STATUS_SUCCESS
60
      J.Ok "error" -> J.Ok OP_STATUS_ERROR
61
      _ -> J.Error ("Unknown opcode status " ++ show s)
62

    
63
-- | The JobStatus data type. Note that this is ordered especially
64
-- such that greater\/lesser comparison on values of this type makes
65
-- sense.
66
data JobStatus = JOB_STATUS_QUEUED
67
               | JOB_STATUS_WAITLOCK
68
               | JOB_STATUS_RUNNING
69
               | JOB_STATUS_SUCCESS
70
               | JOB_STATUS_CANCELING
71
               | JOB_STATUS_CANCELED
72
               | JOB_STATUS_ERROR
73
                 deriving (Eq, Enum, Ord, Bounded, Show, Read)
74

    
75
instance JSON JobStatus where
76
    showJSON js = showJSON w
77
        where w = case js of
78
                JOB_STATUS_QUEUED -> "queued"
79
                JOB_STATUS_WAITLOCK -> "waiting"
80
                JOB_STATUS_CANCELING -> "canceling"
81
                JOB_STATUS_RUNNING -> "running"
82
                JOB_STATUS_CANCELED -> "canceled"
83
                JOB_STATUS_SUCCESS -> "success"
84
                JOB_STATUS_ERROR -> "error"
85
    readJSON s = case readJSON s of
86
      J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED
87
      J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK
88
      J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING
89
      J.Ok "running" -> J.Ok JOB_STATUS_RUNNING
90
      J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS
91
      J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED
92
      J.Ok "error" -> J.Ok JOB_STATUS_ERROR
93
      _ -> J.Error ("Unknown job status " ++ show s)