Commit d45a824b authored by Iustin Pop's avatar Iustin Pop
Browse files

Enable job queries via confd in gnt-node and RAPI



This patch is enabling split queries for jobs for gnt-node and rapi
access (only for job listing, not job waiting).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 1ba01ff7
......@@ -36,7 +36,6 @@ import qualified Text.JSON as J
import Ganeti.BasicTypes
import qualified Ganeti.Constants as C
import Ganeti.JQueue
import Ganeti.OpCodes (opSummary, metaOpCode)
import Ganeti.Path
import Ganeti.Query.Common
import Ganeti.Query.Language
......@@ -61,6 +60,14 @@ maybeJob :: (J.JSON a) =>
maybeJob _ (Bad _) _ = rsUnavail
maybeJob f (Ok (v, _)) _ = rsNormal $ f v
-- | Wrapper for optional fields that should become unavailable.
maybeJobOpt :: (J.JSON a) =>
(QueuedJob -> Maybe a) -> RuntimeData -> JobId -> ResultEntry
maybeJobOpt _ (Bad _) _ = rsUnavail
maybeJobOpt f (Ok (v, _)) _ = case f v of
Nothing -> rsUnavail
Just w -> rsNormal w
-- | Simple helper for a job getter.
jobGetter :: (J.JSON a) => (QueuedJob -> a) -> FieldGetter JobId RuntimeData
jobGetter = FieldRuntime . maybeJob
......@@ -69,6 +76,14 @@ jobGetter = FieldRuntime . maybeJob
opsGetter :: (J.JSON a) => (QueuedOpCode -> a) -> FieldGetter JobId RuntimeData
opsGetter f = FieldRuntime $ maybeJob (map f . qjOps)
-- | Simple helper for a per-opcode optional field getter.
opsOptGetter :: (J.JSON a) =>
(QueuedOpCode -> Maybe a) -> FieldGetter JobId RuntimeData
opsOptGetter f =
FieldRuntime $ maybeJob (map (\qo -> case f qo of
Nothing -> J.JSNull
Just a -> J.showJSON a) . qjOps)
-- | Archived field name.
archivedField :: String
archivedField = "archived"
......@@ -101,27 +116,27 @@ jobFields =
"List of opcode output logs", opsGetter qoLog, QffNormal)
, (FieldDefinition "opstart" "OpCode_start" QFTOther
"List of opcode start timestamps (before acquiring locks)",
opsGetter qoStartTimestamp, QffNormal)
opsOptGetter qoStartTimestamp, QffNormal)
, (FieldDefinition "opexec" "OpCode_exec" QFTOther
"List of opcode execution start timestamps (after acquiring locks)",
opsGetter qoExecTimestamp, QffNormal)
opsOptGetter qoExecTimestamp, QffNormal)
, (FieldDefinition "opend" "OpCode_end" QFTOther
"List of opcode execution end timestamps",
opsGetter qoEndTimestamp, QffNormal)
opsOptGetter qoEndTimestamp, QffNormal)
, (FieldDefinition "oppriority" "OpCode_prio" QFTOther
"List of opcode priorities", opsGetter qoPriority, QffNormal)
, (FieldDefinition "summary" "Summary" QFTOther
"List of per-opcode summaries",
opsGetter (opSummary . metaOpCode . qoInput), QffNormal)
opsGetter (extractOpSummary . qoInput), QffNormal)
, (FieldDefinition "received_ts" "Received" QFTOther
(tsDoc "Timestamp of when job was received"),
jobGetter qjReceivedTimestamp, QffTimestamp)
FieldRuntime (maybeJobOpt qjReceivedTimestamp), QffTimestamp)
, (FieldDefinition "start_ts" "Start" QFTOther
(tsDoc "Timestamp of job start"),
jobGetter qjStartTimestamp, QffTimestamp)
FieldRuntime (maybeJobOpt qjStartTimestamp), QffTimestamp)
, (FieldDefinition "end_ts" "End" QFTOther
(tsDoc "Timestamp of job end"),
jobGetter qjEndTimestamp, QffTimestamp)
FieldRuntime (maybeJobOpt qjEndTimestamp), QffTimestamp)
]
-- | The node fields map.
......
......@@ -242,7 +242,7 @@ queryJobs cfg live fields qfilter =
-- big lambda, but we use many variables from outside it...
(\lst jid -> do
job <- lift $ if live'
then loadJobFromDisk qdir want_arch jid
then loadJobFromDisk qdir True jid
else return disabled_data
pass <- resultT $ evaluateFilter cfg (Just job) jid cfilter
let nlst = if pass
......
......@@ -102,11 +102,13 @@ def ListJobs(opts, args):
qfilter = qlang.MakeSimpleFilter("status", opts.status_filter)
cl = GetClient(query=True)
return GenericList(constants.QR_JOB, selected_fields, args, None,
opts.separator, not opts.no_headers,
format_override=_JOB_LIST_FORMAT, verbose=opts.verbose,
force_filter=opts.force_filter, namefield="id",
qfilter=qfilter, isnumeric=True)
qfilter=qfilter, isnumeric=True, cl=cl)
def ListJobFields(opts, args):
......@@ -119,8 +121,10 @@ def ListJobFields(opts, args):
@return: the desired exit code
"""
cl = GetClient(query=True)
return GenericListFields(constants.QR_JOB, args, opts.separator,
not opts.no_headers)
not opts.no_headers, cl=cl)
def ArchiveJobs(opts, args):
......@@ -292,7 +296,8 @@ def ShowJobs(opts, args):
]
qfilter = qlang.MakeSimpleFilter("id", _ParseJobIds(args))
result = GetClient().Query(constants.QR_JOB, selected_fields, qfilter).data
cl = GetClient(query=True)
result = cl.Query(constants.QR_JOB, selected_fields, qfilter).data
first = True
......
......@@ -295,7 +295,7 @@ class R_2_jobs(baserlib.ResourceBase):
@return: a dictionary with jobs id and uri.
"""
client = self.GetClient()
client = self.GetClient(query=True)
if self.useBulk():
bulkdata = client.QueryJobs(None, J_FIELDS_BULK)
......@@ -324,7 +324,7 @@ class R_2_jobs_id(baserlib.ResourceBase):
"""
job_id = self.items[0]
result = self.GetClient().QueryJobs([job_id, ], J_FIELDS)[0]
result = self.GetClient(query=True).QueryJobs([job_id, ], J_FIELDS)[0]
if result is None:
raise http.HttpNotFound()
return baserlib.MapFields(J_FIELDS, result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment