root / htools / Ganeti / Jobs.hs @ 2e5eb96a
History | View | Annotate | Download (3.3 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 | 6bc39970 | Iustin Pop | Copyright (C) 2009, 2010 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 | 41065165 | Iustin Pop | data OpStatus = OP_STATUS_QUEUED |
35 | 41065165 | Iustin Pop | | OP_STATUS_WAITLOCK |
36 | 41065165 | Iustin Pop | | OP_STATUS_CANCELING |
37 | 41065165 | Iustin Pop | | OP_STATUS_RUNNING |
38 | 41065165 | Iustin Pop | | OP_STATUS_CANCELED |
39 | 41065165 | Iustin Pop | | OP_STATUS_SUCCESS |
40 | 41065165 | Iustin Pop | | OP_STATUS_ERROR |
41 | 6bc39970 | Iustin Pop | deriving (Eq, Enum, Bounded, Show, Read) |
42 | 41065165 | Iustin Pop | |
43 | 41065165 | Iustin Pop | instance JSON OpStatus where |
44 | 41065165 | Iustin Pop | showJSON os = showJSON w |
45 | 41065165 | Iustin Pop | where w = case os of |
46 | 41065165 | Iustin Pop | OP_STATUS_QUEUED -> "queued" |
47 | 41065165 | Iustin Pop | OP_STATUS_WAITLOCK -> "waiting" |
48 | 41065165 | Iustin Pop | OP_STATUS_CANCELING -> "canceling" |
49 | 41065165 | Iustin Pop | OP_STATUS_RUNNING -> "running" |
50 | 41065165 | Iustin Pop | OP_STATUS_CANCELED -> "canceled" |
51 | 41065165 | Iustin Pop | OP_STATUS_SUCCESS -> "success" |
52 | 41065165 | Iustin Pop | OP_STATUS_ERROR -> "error" |
53 | 41065165 | Iustin Pop | readJSON s = case readJSON s of |
54 | 41065165 | Iustin Pop | J.Ok "queued" -> J.Ok OP_STATUS_QUEUED |
55 | 41065165 | Iustin Pop | J.Ok "waiting" -> J.Ok OP_STATUS_WAITLOCK |
56 | 41065165 | Iustin Pop | J.Ok "canceling" -> J.Ok OP_STATUS_CANCELING |
57 | 41065165 | Iustin Pop | J.Ok "running" -> J.Ok OP_STATUS_RUNNING |
58 | 41065165 | Iustin Pop | J.Ok "canceled" -> J.Ok OP_STATUS_CANCELED |
59 | 41065165 | Iustin Pop | J.Ok "success" -> J.Ok OP_STATUS_SUCCESS |
60 | 41065165 | Iustin Pop | J.Ok "error" -> J.Ok OP_STATUS_ERROR |
61 | 41065165 | Iustin Pop | _ -> J.Error ("Unknown opcode status " ++ show s) |
62 | 41065165 | Iustin Pop | |
63 | 13b6cb3f | Iustin Pop | -- | The JobStatus data type. Note that this is ordered especially |
64 | c4ef235b | Iustin Pop | -- such that greater\/lesser comparison on values of this type makes |
65 | 13b6cb3f | Iustin Pop | -- sense. |
66 | 7e98f782 | Iustin Pop | data JobStatus = JOB_STATUS_QUEUED |
67 | 7e98f782 | Iustin Pop | | JOB_STATUS_WAITLOCK |
68 | 7e98f782 | Iustin Pop | | JOB_STATUS_RUNNING |
69 | 7e98f782 | Iustin Pop | | JOB_STATUS_SUCCESS |
70 | 7e98f782 | Iustin Pop | | JOB_STATUS_CANCELING |
71 | 7e98f782 | Iustin Pop | | JOB_STATUS_CANCELED |
72 | 7e98f782 | Iustin Pop | | JOB_STATUS_ERROR |
73 | 6bc39970 | Iustin Pop | deriving (Eq, Enum, Ord, Bounded, Show, Read) |
74 | 13b6cb3f | Iustin Pop | |
75 | 13b6cb3f | Iustin Pop | instance JSON JobStatus where |
76 | 13b6cb3f | Iustin Pop | showJSON js = showJSON w |
77 | 13b6cb3f | Iustin Pop | where w = case js of |
78 | 7e98f782 | Iustin Pop | JOB_STATUS_QUEUED -> "queued" |
79 | 7e98f782 | Iustin Pop | JOB_STATUS_WAITLOCK -> "waiting" |
80 | 7e98f782 | Iustin Pop | JOB_STATUS_CANCELING -> "canceling" |
81 | 7e98f782 | Iustin Pop | JOB_STATUS_RUNNING -> "running" |
82 | 7e98f782 | Iustin Pop | JOB_STATUS_CANCELED -> "canceled" |
83 | 7e98f782 | Iustin Pop | JOB_STATUS_SUCCESS -> "success" |
84 | 7e98f782 | Iustin Pop | JOB_STATUS_ERROR -> "error" |
85 | 13b6cb3f | Iustin Pop | readJSON s = case readJSON s of |
86 | 7e98f782 | Iustin Pop | J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED |
87 | 7e98f782 | Iustin Pop | J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK |
88 | 7e98f782 | Iustin Pop | J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING |
89 | 7e98f782 | Iustin Pop | J.Ok "running" -> J.Ok JOB_STATUS_RUNNING |
90 | 7e98f782 | Iustin Pop | J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS |
91 | 7e98f782 | Iustin Pop | J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED |
92 | 7e98f782 | Iustin Pop | J.Ok "error" -> J.Ok JOB_STATUS_ERROR |
93 | 7e98f782 | Iustin Pop | _ -> J.Error ("Unknown job status " ++ show s) |