root / htools / Ganeti / Jobs.hs @ d72ff6c3
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 | 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 | 41065165 | Iustin Pop | | OP_STATUS_WAITLOCK |
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 | 56c094b4 | Iustin Pop | OP_STATUS_QUEUED -> C.jobStatusQueued |
50 | 56c094b4 | Iustin Pop | OP_STATUS_WAITLOCK -> C.jobStatusWaitlock |
51 | 56c094b4 | Iustin Pop | OP_STATUS_CANCELING -> C.jobStatusCanceling |
52 | 56c094b4 | Iustin Pop | OP_STATUS_RUNNING -> C.jobStatusRunning |
53 | 56c094b4 | Iustin Pop | OP_STATUS_CANCELED -> C.jobStatusCanceled |
54 | 56c094b4 | Iustin Pop | OP_STATUS_SUCCESS -> C.jobStatusSuccess |
55 | 56c094b4 | Iustin Pop | OP_STATUS_ERROR -> C.jobStatusError |
56 | 41065165 | Iustin Pop | readJSON s = case readJSON s of |
57 | 56c094b4 | Iustin Pop | J.Ok v | v == C.jobStatusQueued -> J.Ok OP_STATUS_QUEUED |
58 | 56c094b4 | Iustin Pop | | v == C.jobStatusWaitlock -> J.Ok OP_STATUS_WAITLOCK |
59 | 56c094b4 | Iustin Pop | | v == C.jobStatusCanceling -> J.Ok OP_STATUS_CANCELING |
60 | 56c094b4 | Iustin Pop | | v == C.jobStatusRunning -> J.Ok OP_STATUS_RUNNING |
61 | 56c094b4 | Iustin Pop | | v == C.jobStatusCanceled -> J.Ok OP_STATUS_CANCELED |
62 | 56c094b4 | Iustin Pop | | v == C.jobStatusSuccess -> J.Ok OP_STATUS_SUCCESS |
63 | 56c094b4 | Iustin Pop | | v == C.jobStatusError -> 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 | 7e98f782 | Iustin Pop | | JOB_STATUS_WAITLOCK |
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 | 7e98f782 | Iustin Pop | JOB_STATUS_QUEUED -> "queued" |
83 | 7e98f782 | Iustin Pop | JOB_STATUS_WAITLOCK -> "waiting" |
84 | 7e98f782 | Iustin Pop | JOB_STATUS_CANCELING -> "canceling" |
85 | 7e98f782 | Iustin Pop | JOB_STATUS_RUNNING -> "running" |
86 | 7e98f782 | Iustin Pop | JOB_STATUS_CANCELED -> "canceled" |
87 | 7e98f782 | Iustin Pop | JOB_STATUS_SUCCESS -> "success" |
88 | 7e98f782 | Iustin Pop | JOB_STATUS_ERROR -> "error" |
89 | 13b6cb3f | Iustin Pop | readJSON s = case readJSON s of |
90 | 7e98f782 | Iustin Pop | J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED |
91 | 7e98f782 | Iustin Pop | J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK |
92 | 7e98f782 | Iustin Pop | J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING |
93 | 7e98f782 | Iustin Pop | J.Ok "running" -> J.Ok JOB_STATUS_RUNNING |
94 | 7e98f782 | Iustin Pop | J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS |
95 | 7e98f782 | Iustin Pop | J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED |
96 | 7e98f782 | Iustin Pop | J.Ok "error" -> J.Ok JOB_STATUS_ERROR |
97 | 7e98f782 | Iustin Pop | _ -> J.Error ("Unknown job status " ++ show s) |