Revision d45a824b
b/htools/Ganeti/Query/Job.hs | ||
---|---|---|
36 | 36 |
import Ganeti.BasicTypes |
37 | 37 |
import qualified Ganeti.Constants as C |
38 | 38 |
import Ganeti.JQueue |
39 |
import Ganeti.OpCodes (opSummary, metaOpCode) |
|
40 | 39 |
import Ganeti.Path |
41 | 40 |
import Ganeti.Query.Common |
42 | 41 |
import Ganeti.Query.Language |
... | ... | |
61 | 60 |
maybeJob _ (Bad _) _ = rsUnavail |
62 | 61 |
maybeJob f (Ok (v, _)) _ = rsNormal $ f v |
63 | 62 |
|
63 |
-- | Wrapper for optional fields that should become unavailable. |
|
64 |
maybeJobOpt :: (J.JSON a) => |
|
65 |
(QueuedJob -> Maybe a) -> RuntimeData -> JobId -> ResultEntry |
|
66 |
maybeJobOpt _ (Bad _) _ = rsUnavail |
|
67 |
maybeJobOpt f (Ok (v, _)) _ = case f v of |
|
68 |
Nothing -> rsUnavail |
|
69 |
Just w -> rsNormal w |
|
70 |
|
|
64 | 71 |
-- | Simple helper for a job getter. |
65 | 72 |
jobGetter :: (J.JSON a) => (QueuedJob -> a) -> FieldGetter JobId RuntimeData |
66 | 73 |
jobGetter = FieldRuntime . maybeJob |
... | ... | |
69 | 76 |
opsGetter :: (J.JSON a) => (QueuedOpCode -> a) -> FieldGetter JobId RuntimeData |
70 | 77 |
opsGetter f = FieldRuntime $ maybeJob (map f . qjOps) |
71 | 78 |
|
79 |
-- | Simple helper for a per-opcode optional field getter. |
|
80 |
opsOptGetter :: (J.JSON a) => |
|
81 |
(QueuedOpCode -> Maybe a) -> FieldGetter JobId RuntimeData |
|
82 |
opsOptGetter f = |
|
83 |
FieldRuntime $ maybeJob (map (\qo -> case f qo of |
|
84 |
Nothing -> J.JSNull |
|
85 |
Just a -> J.showJSON a) . qjOps) |
|
86 |
|
|
72 | 87 |
-- | Archived field name. |
73 | 88 |
archivedField :: String |
74 | 89 |
archivedField = "archived" |
... | ... | |
101 | 116 |
"List of opcode output logs", opsGetter qoLog, QffNormal) |
102 | 117 |
, (FieldDefinition "opstart" "OpCode_start" QFTOther |
103 | 118 |
"List of opcode start timestamps (before acquiring locks)", |
104 |
opsGetter qoStartTimestamp, QffNormal) |
|
119 |
opsOptGetter qoStartTimestamp, QffNormal)
|
|
105 | 120 |
, (FieldDefinition "opexec" "OpCode_exec" QFTOther |
106 | 121 |
"List of opcode execution start timestamps (after acquiring locks)", |
107 |
opsGetter qoExecTimestamp, QffNormal) |
|
122 |
opsOptGetter qoExecTimestamp, QffNormal)
|
|
108 | 123 |
, (FieldDefinition "opend" "OpCode_end" QFTOther |
109 | 124 |
"List of opcode execution end timestamps", |
110 |
opsGetter qoEndTimestamp, QffNormal) |
|
125 |
opsOptGetter qoEndTimestamp, QffNormal)
|
|
111 | 126 |
, (FieldDefinition "oppriority" "OpCode_prio" QFTOther |
112 | 127 |
"List of opcode priorities", opsGetter qoPriority, QffNormal) |
113 | 128 |
, (FieldDefinition "summary" "Summary" QFTOther |
114 | 129 |
"List of per-opcode summaries", |
115 |
opsGetter (opSummary . metaOpCode . qoInput), QffNormal)
|
|
130 |
opsGetter (extractOpSummary . qoInput), QffNormal)
|
|
116 | 131 |
, (FieldDefinition "received_ts" "Received" QFTOther |
117 | 132 |
(tsDoc "Timestamp of when job was received"), |
118 |
jobGetter qjReceivedTimestamp, QffTimestamp)
|
|
133 |
FieldRuntime (maybeJobOpt qjReceivedTimestamp), QffTimestamp)
|
|
119 | 134 |
, (FieldDefinition "start_ts" "Start" QFTOther |
120 | 135 |
(tsDoc "Timestamp of job start"), |
121 |
jobGetter qjStartTimestamp, QffTimestamp)
|
|
136 |
FieldRuntime (maybeJobOpt qjStartTimestamp), QffTimestamp)
|
|
122 | 137 |
, (FieldDefinition "end_ts" "End" QFTOther |
123 | 138 |
(tsDoc "Timestamp of job end"), |
124 |
jobGetter qjEndTimestamp, QffTimestamp)
|
|
139 |
FieldRuntime (maybeJobOpt qjEndTimestamp), QffTimestamp)
|
|
125 | 140 |
] |
126 | 141 |
|
127 | 142 |
-- | The node fields map. |
b/htools/Ganeti/Query/Query.hs | ||
---|---|---|
242 | 242 |
-- big lambda, but we use many variables from outside it... |
243 | 243 |
(\lst jid -> do |
244 | 244 |
job <- lift $ if live' |
245 |
then loadJobFromDisk qdir want_arch jid
|
|
245 |
then loadJobFromDisk qdir True jid
|
|
246 | 246 |
else return disabled_data |
247 | 247 |
pass <- resultT $ evaluateFilter cfg (Just job) jid cfilter |
248 | 248 |
let nlst = if pass |
b/lib/client/gnt_job.py | ||
---|---|---|
102 | 102 |
|
103 | 103 |
qfilter = qlang.MakeSimpleFilter("status", opts.status_filter) |
104 | 104 |
|
105 |
cl = GetClient(query=True) |
|
106 |
|
|
105 | 107 |
return GenericList(constants.QR_JOB, selected_fields, args, None, |
106 | 108 |
opts.separator, not opts.no_headers, |
107 | 109 |
format_override=_JOB_LIST_FORMAT, verbose=opts.verbose, |
108 | 110 |
force_filter=opts.force_filter, namefield="id", |
109 |
qfilter=qfilter, isnumeric=True) |
|
111 |
qfilter=qfilter, isnumeric=True, cl=cl)
|
|
110 | 112 |
|
111 | 113 |
|
112 | 114 |
def ListJobFields(opts, args): |
... | ... | |
119 | 121 |
@return: the desired exit code |
120 | 122 |
|
121 | 123 |
""" |
124 |
cl = GetClient(query=True) |
|
125 |
|
|
122 | 126 |
return GenericListFields(constants.QR_JOB, args, opts.separator, |
123 |
not opts.no_headers) |
|
127 |
not opts.no_headers, cl=cl)
|
|
124 | 128 |
|
125 | 129 |
|
126 | 130 |
def ArchiveJobs(opts, args): |
... | ... | |
292 | 296 |
] |
293 | 297 |
|
294 | 298 |
qfilter = qlang.MakeSimpleFilter("id", _ParseJobIds(args)) |
295 |
result = GetClient().Query(constants.QR_JOB, selected_fields, qfilter).data |
|
299 |
cl = GetClient(query=True) |
|
300 |
result = cl.Query(constants.QR_JOB, selected_fields, qfilter).data |
|
296 | 301 |
|
297 | 302 |
first = True |
298 | 303 |
|
b/lib/rapi/rlib2.py | ||
---|---|---|
295 | 295 |
@return: a dictionary with jobs id and uri. |
296 | 296 |
|
297 | 297 |
""" |
298 |
client = self.GetClient() |
|
298 |
client = self.GetClient(query=True)
|
|
299 | 299 |
|
300 | 300 |
if self.useBulk(): |
301 | 301 |
bulkdata = client.QueryJobs(None, J_FIELDS_BULK) |
... | ... | |
324 | 324 |
|
325 | 325 |
""" |
326 | 326 |
job_id = self.items[0] |
327 |
result = self.GetClient().QueryJobs([job_id, ], J_FIELDS)[0] |
|
327 |
result = self.GetClient(query=True).QueryJobs([job_id, ], J_FIELDS)[0]
|
|
328 | 328 |
if result is None: |
329 | 329 |
raise http.HttpNotFound() |
330 | 330 |
return baserlib.MapFields(J_FIELDS, result) |
Also available in: Unified diff