root / src / Ganeti / Types.hs @ 2522c59e
History | View | Annotate | Download (16.1 kB)
1 |
{-# LANGUAGE TemplateHaskell #-} |
---|---|
2 |
|
3 |
{-| Some common Ganeti types. |
4 |
|
5 |
This holds types common to both core work, and to htools. Types that |
6 |
are very core specific (e.g. configuration objects) should go in |
7 |
'Ganeti.Objects', while types that are specific to htools in-memory |
8 |
representation should go into 'Ganeti.HTools.Types'. |
9 |
|
10 |
-} |
11 |
|
12 |
{- |
13 |
|
14 |
Copyright (C) 2012, 2013 Google Inc. |
15 |
|
16 |
This program is free software; you can redistribute it and/or modify |
17 |
it under the terms of the GNU General Public License as published by |
18 |
the Free Software Foundation; either version 2 of the License, or |
19 |
(at your option) any later version. |
20 |
|
21 |
This program is distributed in the hope that it will be useful, but |
22 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 |
General Public License for more details. |
25 |
|
26 |
You should have received a copy of the GNU General Public License |
27 |
along with this program; if not, write to the Free Software |
28 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
29 |
02110-1301, USA. |
30 |
|
31 |
-} |
32 |
|
33 |
module Ganeti.Types |
34 |
( AllocPolicy(..) |
35 |
, allocPolicyFromRaw |
36 |
, allocPolicyToRaw |
37 |
, InstanceStatus(..) |
38 |
, instanceStatusFromRaw |
39 |
, instanceStatusToRaw |
40 |
, DiskTemplate(..) |
41 |
, diskTemplateToRaw |
42 |
, diskTemplateFromRaw |
43 |
, NonNegative |
44 |
, fromNonNegative |
45 |
, mkNonNegative |
46 |
, Positive |
47 |
, fromPositive |
48 |
, mkPositive |
49 |
, Negative |
50 |
, fromNegative |
51 |
, mkNegative |
52 |
, NonEmpty |
53 |
, fromNonEmpty |
54 |
, mkNonEmpty |
55 |
, NonEmptyString |
56 |
, MigrationMode(..) |
57 |
, VerifyOptionalChecks(..) |
58 |
, DdmSimple(..) |
59 |
, DdmFull(..) |
60 |
, CVErrorCode(..) |
61 |
, cVErrorCodeToRaw |
62 |
, Hypervisor(..) |
63 |
, OobCommand(..) |
64 |
, StorageType(..) |
65 |
, NodeEvacMode(..) |
66 |
, FileDriver(..) |
67 |
, InstCreateMode(..) |
68 |
, RebootType(..) |
69 |
, ExportMode(..) |
70 |
, IAllocatorTestDir(..) |
71 |
, IAllocatorMode(..) |
72 |
, iAllocatorModeToRaw |
73 |
, NICMode(..) |
74 |
, nICModeToRaw |
75 |
, JobStatus(..) |
76 |
, jobStatusToRaw |
77 |
, jobStatusFromRaw |
78 |
, FinalizedJobStatus(..) |
79 |
, finalizedJobStatusToRaw |
80 |
, JobId |
81 |
, fromJobId |
82 |
, makeJobId |
83 |
, makeJobIdS |
84 |
, RelativeJobId |
85 |
, JobIdDep(..) |
86 |
, JobDependency(..) |
87 |
, OpSubmitPriority(..) |
88 |
, opSubmitPriorityToRaw |
89 |
, parseSubmitPriority |
90 |
, fmtSubmitPriority |
91 |
, OpStatus(..) |
92 |
, opStatusToRaw |
93 |
, opStatusFromRaw |
94 |
, ELogType(..) |
95 |
, InstReasonSrc(..) |
96 |
) where |
97 |
|
98 |
import Control.Monad (liftM) |
99 |
import qualified Text.JSON as JSON |
100 |
import Text.JSON (JSON, readJSON, showJSON) |
101 |
import Data.Ratio (numerator, denominator) |
102 |
|
103 |
import qualified Ganeti.Constants as C |
104 |
import qualified Ganeti.THH as THH |
105 |
import Ganeti.JSON |
106 |
import Ganeti.Utils |
107 |
|
108 |
-- * Generic types |
109 |
|
110 |
-- | Type that holds a non-negative value. |
111 |
newtype NonNegative a = NonNegative { fromNonNegative :: a } |
112 |
deriving (Show, Eq) |
113 |
|
114 |
-- | Smart constructor for 'NonNegative'. |
115 |
mkNonNegative :: (Monad m, Num a, Ord a, Show a) => a -> m (NonNegative a) |
116 |
mkNonNegative i | i >= 0 = return (NonNegative i) |
117 |
| otherwise = fail $ "Invalid value for non-negative type '" ++ |
118 |
show i ++ "'" |
119 |
|
120 |
instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (NonNegative a) where |
121 |
showJSON = JSON.showJSON . fromNonNegative |
122 |
readJSON v = JSON.readJSON v >>= mkNonNegative |
123 |
|
124 |
-- | Type that holds a positive value. |
125 |
newtype Positive a = Positive { fromPositive :: a } |
126 |
deriving (Show, Eq) |
127 |
|
128 |
-- | Smart constructor for 'Positive'. |
129 |
mkPositive :: (Monad m, Num a, Ord a, Show a) => a -> m (Positive a) |
130 |
mkPositive i | i > 0 = return (Positive i) |
131 |
| otherwise = fail $ "Invalid value for positive type '" ++ |
132 |
show i ++ "'" |
133 |
|
134 |
instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (Positive a) where |
135 |
showJSON = JSON.showJSON . fromPositive |
136 |
readJSON v = JSON.readJSON v >>= mkPositive |
137 |
|
138 |
-- | Type that holds a negative value. |
139 |
newtype Negative a = Negative { fromNegative :: a } |
140 |
deriving (Show, Eq) |
141 |
|
142 |
-- | Smart constructor for 'Negative'. |
143 |
mkNegative :: (Monad m, Num a, Ord a, Show a) => a -> m (Negative a) |
144 |
mkNegative i | i < 0 = return (Negative i) |
145 |
| otherwise = fail $ "Invalid value for negative type '" ++ |
146 |
show i ++ "'" |
147 |
|
148 |
instance (JSON.JSON a, Num a, Ord a, Show a) => JSON.JSON (Negative a) where |
149 |
showJSON = JSON.showJSON . fromNegative |
150 |
readJSON v = JSON.readJSON v >>= mkNegative |
151 |
|
152 |
-- | Type that holds a non-null list. |
153 |
newtype NonEmpty a = NonEmpty { fromNonEmpty :: [a] } |
154 |
deriving (Show, Eq) |
155 |
|
156 |
-- | Smart constructor for 'NonEmpty'. |
157 |
mkNonEmpty :: (Monad m) => [a] -> m (NonEmpty a) |
158 |
mkNonEmpty [] = fail "Received empty value for non-empty list" |
159 |
mkNonEmpty xs = return (NonEmpty xs) |
160 |
|
161 |
instance (JSON.JSON a) => JSON.JSON (NonEmpty a) where |
162 |
showJSON = JSON.showJSON . fromNonEmpty |
163 |
readJSON v = JSON.readJSON v >>= mkNonEmpty |
164 |
|
165 |
-- | A simple type alias for non-empty strings. |
166 |
type NonEmptyString = NonEmpty Char |
167 |
|
168 |
-- * Ganeti types |
169 |
|
170 |
-- | Instance disk template type. |
171 |
$(THH.declareSADT "DiskTemplate" |
172 |
[ ("DTDiskless", 'C.dtDiskless) |
173 |
, ("DTFile", 'C.dtFile) |
174 |
, ("DTSharedFile", 'C.dtSharedFile) |
175 |
, ("DTPlain", 'C.dtPlain) |
176 |
, ("DTBlock", 'C.dtBlock) |
177 |
, ("DTDrbd8", 'C.dtDrbd8) |
178 |
, ("DTRbd", 'C.dtRbd) |
179 |
, ("DTExt", 'C.dtExt) |
180 |
]) |
181 |
$(THH.makeJSONInstance ''DiskTemplate) |
182 |
|
183 |
instance HasStringRepr DiskTemplate where |
184 |
fromStringRepr = diskTemplateFromRaw |
185 |
toStringRepr = diskTemplateToRaw |
186 |
|
187 |
-- | The Group allocation policy type. |
188 |
-- |
189 |
-- Note that the order of constructors is important as the automatic |
190 |
-- Ord instance will order them in the order they are defined, so when |
191 |
-- changing this data type be careful about the interaction with the |
192 |
-- desired sorting order. |
193 |
$(THH.declareSADT "AllocPolicy" |
194 |
[ ("AllocPreferred", 'C.allocPolicyPreferred) |
195 |
, ("AllocLastResort", 'C.allocPolicyLastResort) |
196 |
, ("AllocUnallocable", 'C.allocPolicyUnallocable) |
197 |
]) |
198 |
$(THH.makeJSONInstance ''AllocPolicy) |
199 |
|
200 |
-- | The Instance real state type. FIXME: this could be improved to |
201 |
-- just wrap a /NormalState AdminStatus | ErrorState ErrorCondition/. |
202 |
$(THH.declareSADT "InstanceStatus" |
203 |
[ ("StatusDown", 'C.inststAdmindown) |
204 |
, ("StatusOffline", 'C.inststAdminoffline) |
205 |
, ("ErrorDown", 'C.inststErrordown) |
206 |
, ("ErrorUp", 'C.inststErrorup) |
207 |
, ("NodeDown", 'C.inststNodedown) |
208 |
, ("NodeOffline", 'C.inststNodeoffline) |
209 |
, ("Running", 'C.inststRunning) |
210 |
, ("WrongNode", 'C.inststWrongnode) |
211 |
]) |
212 |
$(THH.makeJSONInstance ''InstanceStatus) |
213 |
|
214 |
-- | Migration mode. |
215 |
$(THH.declareSADT "MigrationMode" |
216 |
[ ("MigrationLive", 'C.htMigrationLive) |
217 |
, ("MigrationNonLive", 'C.htMigrationNonlive) |
218 |
]) |
219 |
$(THH.makeJSONInstance ''MigrationMode) |
220 |
|
221 |
-- | Verify optional checks. |
222 |
$(THH.declareSADT "VerifyOptionalChecks" |
223 |
[ ("VerifyNPlusOneMem", 'C.verifyNplusoneMem) |
224 |
]) |
225 |
$(THH.makeJSONInstance ''VerifyOptionalChecks) |
226 |
|
227 |
-- | Cluster verify error codes. |
228 |
$(THH.declareSADT "CVErrorCode" |
229 |
[ ("CvECLUSTERCFG", 'C.cvEclustercfgCode) |
230 |
, ("CvECLUSTERCERT", 'C.cvEclustercertCode) |
231 |
, ("CvECLUSTERFILECHECK", 'C.cvEclusterfilecheckCode) |
232 |
, ("CvECLUSTERDANGLINGNODES", 'C.cvEclusterdanglingnodesCode) |
233 |
, ("CvECLUSTERDANGLINGINST", 'C.cvEclusterdanglinginstCode) |
234 |
, ("CvEINSTANCEBADNODE", 'C.cvEinstancebadnodeCode) |
235 |
, ("CvEINSTANCEDOWN", 'C.cvEinstancedownCode) |
236 |
, ("CvEINSTANCELAYOUT", 'C.cvEinstancelayoutCode) |
237 |
, ("CvEINSTANCEMISSINGDISK", 'C.cvEinstancemissingdiskCode) |
238 |
, ("CvEINSTANCEFAULTYDISK", 'C.cvEinstancefaultydiskCode) |
239 |
, ("CvEINSTANCEWRONGNODE", 'C.cvEinstancewrongnodeCode) |
240 |
, ("CvEINSTANCESPLITGROUPS", 'C.cvEinstancesplitgroupsCode) |
241 |
, ("CvEINSTANCEPOLICY", 'C.cvEinstancepolicyCode) |
242 |
, ("CvENODEDRBD", 'C.cvEnodedrbdCode) |
243 |
, ("CvENODEDRBDHELPER", 'C.cvEnodedrbdhelperCode) |
244 |
, ("CvENODEFILECHECK", 'C.cvEnodefilecheckCode) |
245 |
, ("CvENODEHOOKS", 'C.cvEnodehooksCode) |
246 |
, ("CvENODEHV", 'C.cvEnodehvCode) |
247 |
, ("CvENODELVM", 'C.cvEnodelvmCode) |
248 |
, ("CvENODEN1", 'C.cvEnoden1Code) |
249 |
, ("CvENODENET", 'C.cvEnodenetCode) |
250 |
, ("CvENODEOS", 'C.cvEnodeosCode) |
251 |
, ("CvENODEORPHANINSTANCE", 'C.cvEnodeorphaninstanceCode) |
252 |
, ("CvENODEORPHANLV", 'C.cvEnodeorphanlvCode) |
253 |
, ("CvENODERPC", 'C.cvEnoderpcCode) |
254 |
, ("CvENODESSH", 'C.cvEnodesshCode) |
255 |
, ("CvENODEVERSION", 'C.cvEnodeversionCode) |
256 |
, ("CvENODESETUP", 'C.cvEnodesetupCode) |
257 |
, ("CvENODETIME", 'C.cvEnodetimeCode) |
258 |
, ("CvENODEOOBPATH", 'C.cvEnodeoobpathCode) |
259 |
, ("CvENODEUSERSCRIPTS", 'C.cvEnodeuserscriptsCode) |
260 |
, ("CvENODEFILESTORAGEPATHS", 'C.cvEnodefilestoragepathsCode) |
261 |
]) |
262 |
$(THH.makeJSONInstance ''CVErrorCode) |
263 |
|
264 |
-- | Dynamic device modification, just add\/remove version. |
265 |
$(THH.declareSADT "DdmSimple" |
266 |
[ ("DdmSimpleAdd", 'C.ddmAdd) |
267 |
, ("DdmSimpleRemove", 'C.ddmRemove) |
268 |
]) |
269 |
$(THH.makeJSONInstance ''DdmSimple) |
270 |
|
271 |
-- | Dynamic device modification, all operations version. |
272 |
$(THH.declareSADT "DdmFull" |
273 |
[ ("DdmFullAdd", 'C.ddmAdd) |
274 |
, ("DdmFullRemove", 'C.ddmRemove) |
275 |
, ("DdmFullModify", 'C.ddmModify) |
276 |
]) |
277 |
$(THH.makeJSONInstance ''DdmFull) |
278 |
|
279 |
-- | Hypervisor type definitions. |
280 |
$(THH.declareSADT "Hypervisor" |
281 |
[ ( "Kvm", 'C.htKvm ) |
282 |
, ( "XenPvm", 'C.htXenPvm ) |
283 |
, ( "Chroot", 'C.htChroot ) |
284 |
, ( "XenHvm", 'C.htXenHvm ) |
285 |
, ( "Lxc", 'C.htLxc ) |
286 |
, ( "Fake", 'C.htFake ) |
287 |
]) |
288 |
$(THH.makeJSONInstance ''Hypervisor) |
289 |
|
290 |
-- | Oob command type. |
291 |
$(THH.declareSADT "OobCommand" |
292 |
[ ("OobHealth", 'C.oobHealth) |
293 |
, ("OobPowerCycle", 'C.oobPowerCycle) |
294 |
, ("OobPowerOff", 'C.oobPowerOff) |
295 |
, ("OobPowerOn", 'C.oobPowerOn) |
296 |
, ("OobPowerStatus", 'C.oobPowerStatus) |
297 |
]) |
298 |
$(THH.makeJSONInstance ''OobCommand) |
299 |
|
300 |
-- | Storage type. |
301 |
$(THH.declareSADT "StorageType" |
302 |
[ ("StorageFile", 'C.stFile) |
303 |
, ("StorageLvmPv", 'C.stLvmPv) |
304 |
, ("StorageLvmVg", 'C.stLvmVg) |
305 |
, ("StorageDiskless", 'C.stDiskless) |
306 |
, ("StorageBlock", 'C.stBlock) |
307 |
, ("StorageRados", 'C.stRados) |
308 |
, ("StorageExt", 'C.stExt) |
309 |
]) |
310 |
$(THH.makeJSONInstance ''StorageType) |
311 |
|
312 |
-- | Node evac modes. |
313 |
$(THH.declareSADT "NodeEvacMode" |
314 |
[ ("NEvacPrimary", 'C.iallocatorNevacPri) |
315 |
, ("NEvacSecondary", 'C.iallocatorNevacSec) |
316 |
, ("NEvacAll", 'C.iallocatorNevacAll) |
317 |
]) |
318 |
$(THH.makeJSONInstance ''NodeEvacMode) |
319 |
|
320 |
-- | The file driver type. |
321 |
$(THH.declareSADT "FileDriver" |
322 |
[ ("FileLoop", 'C.fdLoop) |
323 |
, ("FileBlktap", 'C.fdBlktap) |
324 |
]) |
325 |
$(THH.makeJSONInstance ''FileDriver) |
326 |
|
327 |
-- | The instance create mode. |
328 |
$(THH.declareSADT "InstCreateMode" |
329 |
[ ("InstCreate", 'C.instanceCreate) |
330 |
, ("InstImport", 'C.instanceImport) |
331 |
, ("InstRemoteImport", 'C.instanceRemoteImport) |
332 |
]) |
333 |
$(THH.makeJSONInstance ''InstCreateMode) |
334 |
|
335 |
-- | Reboot type. |
336 |
$(THH.declareSADT "RebootType" |
337 |
[ ("RebootSoft", 'C.instanceRebootSoft) |
338 |
, ("RebootHard", 'C.instanceRebootHard) |
339 |
, ("RebootFull", 'C.instanceRebootFull) |
340 |
]) |
341 |
$(THH.makeJSONInstance ''RebootType) |
342 |
|
343 |
-- | Export modes. |
344 |
$(THH.declareSADT "ExportMode" |
345 |
[ ("ExportModeLocal", 'C.exportModeLocal) |
346 |
, ("ExportModeRemove", 'C.exportModeRemote) |
347 |
]) |
348 |
$(THH.makeJSONInstance ''ExportMode) |
349 |
|
350 |
-- | IAllocator run types (OpTestIAllocator). |
351 |
$(THH.declareSADT "IAllocatorTestDir" |
352 |
[ ("IAllocatorDirIn", 'C.iallocatorDirIn) |
353 |
, ("IAllocatorDirOut", 'C.iallocatorDirOut) |
354 |
]) |
355 |
$(THH.makeJSONInstance ''IAllocatorTestDir) |
356 |
|
357 |
-- | IAllocator mode. FIXME: use this in "HTools.Backend.IAlloc". |
358 |
$(THH.declareSADT "IAllocatorMode" |
359 |
[ ("IAllocatorAlloc", 'C.iallocatorModeAlloc) |
360 |
, ("IAllocatorMultiAlloc", 'C.iallocatorModeMultiAlloc) |
361 |
, ("IAllocatorReloc", 'C.iallocatorModeReloc) |
362 |
, ("IAllocatorNodeEvac", 'C.iallocatorModeNodeEvac) |
363 |
, ("IAllocatorChangeGroup", 'C.iallocatorModeChgGroup) |
364 |
]) |
365 |
$(THH.makeJSONInstance ''IAllocatorMode) |
366 |
|
367 |
-- | Network mode. |
368 |
$(THH.declareSADT "NICMode" |
369 |
[ ("NMBridged", 'C.nicModeBridged) |
370 |
, ("NMRouted", 'C.nicModeRouted) |
371 |
, ("NMOvs", 'C.nicModeOvs) |
372 |
]) |
373 |
$(THH.makeJSONInstance ''NICMode) |
374 |
|
375 |
-- | The JobStatus data type. Note that this is ordered especially |
376 |
-- such that greater\/lesser comparison on values of this type makes |
377 |
-- sense. |
378 |
$(THH.declareSADT "JobStatus" |
379 |
[ ("JOB_STATUS_QUEUED", 'C.jobStatusQueued) |
380 |
, ("JOB_STATUS_WAITING", 'C.jobStatusWaiting) |
381 |
, ("JOB_STATUS_CANCELING", 'C.jobStatusCanceling) |
382 |
, ("JOB_STATUS_RUNNING", 'C.jobStatusRunning) |
383 |
, ("JOB_STATUS_CANCELED", 'C.jobStatusCanceled) |
384 |
, ("JOB_STATUS_SUCCESS", 'C.jobStatusSuccess) |
385 |
, ("JOB_STATUS_ERROR", 'C.jobStatusError) |
386 |
]) |
387 |
$(THH.makeJSONInstance ''JobStatus) |
388 |
|
389 |
-- | Finalized job status. |
390 |
$(THH.declareSADT "FinalizedJobStatus" |
391 |
[ ("JobStatusCanceled", 'C.jobStatusCanceled) |
392 |
, ("JobStatusSuccessful", 'C.jobStatusSuccess) |
393 |
, ("JobStatusFailed", 'C.jobStatusError) |
394 |
]) |
395 |
$(THH.makeJSONInstance ''FinalizedJobStatus) |
396 |
|
397 |
-- | The Ganeti job type. |
398 |
newtype JobId = JobId { fromJobId :: Int } |
399 |
deriving (Show, Eq) |
400 |
|
401 |
-- | Builds a job ID. |
402 |
makeJobId :: (Monad m) => Int -> m JobId |
403 |
makeJobId i | i >= 0 = return $ JobId i |
404 |
| otherwise = fail $ "Invalid value for job ID ' " ++ show i ++ "'" |
405 |
|
406 |
-- | Builds a job ID from a string. |
407 |
makeJobIdS :: (Monad m) => String -> m JobId |
408 |
makeJobIdS s = tryRead "parsing job id" s >>= makeJobId |
409 |
|
410 |
-- | Parses a job ID. |
411 |
parseJobId :: (Monad m) => JSON.JSValue -> m JobId |
412 |
parseJobId (JSON.JSString x) = makeJobIdS $ JSON.fromJSString x |
413 |
parseJobId (JSON.JSRational _ x) = |
414 |
if denominator x /= 1 |
415 |
then fail $ "Got fractional job ID from master daemon?! Value:" ++ show x |
416 |
-- FIXME: potential integer overflow here on 32-bit platforms |
417 |
else makeJobId . fromIntegral . numerator $ x |
418 |
parseJobId x = fail $ "Wrong type/value for job id: " ++ show x |
419 |
|
420 |
instance JSON.JSON JobId where |
421 |
showJSON = JSON.showJSON . fromJobId |
422 |
readJSON = parseJobId |
423 |
|
424 |
-- | Relative job ID type alias. |
425 |
type RelativeJobId = Negative Int |
426 |
|
427 |
-- | Job ID dependency. |
428 |
data JobIdDep = JobDepRelative RelativeJobId |
429 |
| JobDepAbsolute JobId |
430 |
deriving (Show, Eq) |
431 |
|
432 |
instance JSON.JSON JobIdDep where |
433 |
showJSON (JobDepRelative i) = showJSON i |
434 |
showJSON (JobDepAbsolute i) = showJSON i |
435 |
readJSON v = |
436 |
case JSON.readJSON v::JSON.Result (Negative Int) of |
437 |
-- first try relative dependency, usually most common |
438 |
JSON.Ok r -> return $ JobDepRelative r |
439 |
JSON.Error _ -> liftM JobDepAbsolute (parseJobId v) |
440 |
|
441 |
-- | Job Dependency type. |
442 |
data JobDependency = JobDependency JobIdDep [FinalizedJobStatus] |
443 |
deriving (Show, Eq) |
444 |
|
445 |
instance JSON JobDependency where |
446 |
showJSON (JobDependency dep status) = showJSON (dep, status) |
447 |
readJSON = liftM (uncurry JobDependency) . readJSON |
448 |
|
449 |
-- | Valid opcode priorities for submit. |
450 |
$(THH.declareIADT "OpSubmitPriority" |
451 |
[ ("OpPrioLow", 'C.opPrioLow) |
452 |
, ("OpPrioNormal", 'C.opPrioNormal) |
453 |
, ("OpPrioHigh", 'C.opPrioHigh) |
454 |
]) |
455 |
$(THH.makeJSONInstance ''OpSubmitPriority) |
456 |
|
457 |
-- | Parse submit priorities from a string. |
458 |
parseSubmitPriority :: (Monad m) => String -> m OpSubmitPriority |
459 |
parseSubmitPriority "low" = return OpPrioLow |
460 |
parseSubmitPriority "normal" = return OpPrioNormal |
461 |
parseSubmitPriority "high" = return OpPrioHigh |
462 |
parseSubmitPriority str = fail $ "Unknown priority '" ++ str ++ "'" |
463 |
|
464 |
-- | Format a submit priority as string. |
465 |
fmtSubmitPriority :: OpSubmitPriority -> String |
466 |
fmtSubmitPriority OpPrioLow = "low" |
467 |
fmtSubmitPriority OpPrioNormal = "normal" |
468 |
fmtSubmitPriority OpPrioHigh = "high" |
469 |
|
470 |
-- | Our ADT for the OpCode status at runtime (while in a job). |
471 |
$(THH.declareSADT "OpStatus" |
472 |
[ ("OP_STATUS_QUEUED", 'C.opStatusQueued) |
473 |
, ("OP_STATUS_WAITING", 'C.opStatusWaiting) |
474 |
, ("OP_STATUS_CANCELING", 'C.opStatusCanceling) |
475 |
, ("OP_STATUS_RUNNING", 'C.opStatusRunning) |
476 |
, ("OP_STATUS_CANCELED", 'C.opStatusCanceled) |
477 |
, ("OP_STATUS_SUCCESS", 'C.opStatusSuccess) |
478 |
, ("OP_STATUS_ERROR", 'C.opStatusError) |
479 |
]) |
480 |
$(THH.makeJSONInstance ''OpStatus) |
481 |
|
482 |
-- | Type for the job message type. |
483 |
$(THH.declareSADT "ELogType" |
484 |
[ ("ELogMessage", 'C.elogMessage) |
485 |
, ("ELogRemoteImport", 'C.elogRemoteImport) |
486 |
, ("ELogJqueueTest", 'C.elogJqueueTest) |
487 |
]) |
488 |
$(THH.makeJSONInstance ''ELogType) |
489 |
|
490 |
-- | Type for the source of the state change of instances. |
491 |
$(THH.declareSADT "InstReasonSrc" |
492 |
[ ("IRSCli", 'C.instanceReasonSourceCli) |
493 |
, ("IRSRapi", 'C.instanceReasonSourceRapi) |
494 |
]) |
495 |
$(THH.makeJSONInstance ''InstReasonSrc) |
496 |
|
497 |
|