Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Optimize user-defined-constraint (#1685)
Browse files Browse the repository at this point in the history
* extract job-constant values into defrecord

* pass in job constraints instead of job itself

Co-authored-by: Kathryn Zhou <kathrynzhou@college.harvard.edu>
  • Loading branch information
kathryn-zhou and Kathryn Zhou authored Sep 25, 2020
1 parent 460e4da commit f2adddd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions scheduler/src/cook/scheduler/constraints.clj
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
; threads and we want to avoid contention in LazySeq
vec)))

(defrecord user-defined-constraint [job]
(defrecord user-defined-constraint [constraints]
JobConstraint
(job-constraint-name [this] (get-class-name this))
(job-constraint-evaluate
Expand All @@ -243,7 +243,6 @@
(log/error (str "Unknown operator " operator
" api.clj should have prevented this from happening."))
true))))
constraints (job->constraints job)
passes? (every? vm-passes-constraint? constraints)]
[passes? (when-not passes?
"Host doesn't pass at least one user supplied constraint.")]))
Expand All @@ -255,7 +254,7 @@
"Constructs a user-defined-constraint.
The constraint asserts that the vm passes the constraints the user supplied as host constraints"
[job]
(->user-defined-constraint job))
(->user-defined-constraint (job->constraints job)))

(defrecord estimated-completion-constraint [estimated-end-time host-lifetime-mins]
JobConstraint
Expand Down
3 changes: 1 addition & 2 deletions scheduler/test/cook/test/scheduler/constraints.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
{:constraint/attribute "instance_type"
:constraint/operator :constraint.operator/equals
:constraint/pattern "mem.large"}]
job {:job/constraint constraints}
user-defined-constraint (constraints/->user-defined-constraint job)]
user-defined-constraint (constraints/->user-defined-constraint constraints)]
(is (= true (first (constraints/job-constraint-evaluate user-defined-constraint nil {"is_spot" "true" "instance_type" "mem.large"}))))
(is (= false (first (constraints/job-constraint-evaluate user-defined-constraint nil {"is_spot" "true" "instance_type" "cpu.large"}))))
(is (= false (first (constraints/job-constraint-evaluate user-defined-constraint nil {"is_spot" "false" "instance_type" "mem.large"}))))
Expand Down

0 comments on commit f2adddd

Please sign in to comment.