Skip to content

Commit

Permalink
Address part of twosigma#617, pass job entities in the liberator cont…
Browse files Browse the repository at this point in the history
…ext for /jobs endpoint.

Avoids the same from-uuid to-uuid round-trip in the /jobs endpoint.
Stored in ::jobs-entities.
  • Loading branch information
Scott Crosby committed Jun 4, 2018
1 parent ce1212f commit 9a2d3fa
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions scheduler/src/cook/mesos/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1119,22 +1119,31 @@
(mapv (partial fetch-job-map (db conn) framework-id) (::jobs ctx)))

(defn render-jobs-for-response
"This rendes for response. Fills in in :group UUID's and names as well as map-ifies jobs
It will examine the ctx for ::jobs (containing UUID's) or ::job-entities (containing
datomic job entities) and return the merged set."
[conn framework-id ctx]
(let [db (db conn)

fetch-group
(fn fetch-group [group-uuid]
(let [group (d/entity db [:group/uuid (UUID/fromString group-uuid)])]
{:uuid group-uuid
:name (:group/name group)}))

fetch-job
fetch-job-from-uuid
(fn fetch-job [job-uuid]
(let [job (fetch-job-map db framework-id job-uuid)
groups (mapv fetch-group (:groups job))]
(assoc job :groups groups)))
fetch-job-from-entity
(fn fetch-job [job-ent]
(let [job (fetch-job-map-from-entity db framework-id job-ent)
groups (mapv fetch-group (:groups job))]
(assoc job :groups groups)))]

(mapv fetch-job (::jobs ctx))))
(concat
(when-let [entities (::jobs-entities ctx)]
(mapv fetch-job-from-entity entities))
(when-let [uuids (::jobs ctx)]
(mapv fetch-job-from-uuid uuids)))))

(defn render-instances-for-response
[conn framework-id ctx]
Expand Down Expand Up @@ -1290,14 +1299,9 @@
(histograms/update! list-response-job-count (count job-ents))
job-ents)))

(defn list-jobs
"Queries using the params from ctx and returns the job uuids that were found"
[db include-custom-executor? ctx]
(map :job/uuid (list-jobents db include-custom-executor? ctx)))

(defn jobs-list-exist?
[conn ctx]
[true {::jobs (list-jobs (d/db conn) true ctx)}])
[true {::jobs-entities (list-jobents (d/db conn) true ctx)}])

(defn read-jobs-handler
[conn is-authorized-fn resource-attrs]
Expand Down

0 comments on commit 9a2d3fa

Please sign in to comment.