You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
"Do a query for the quota for a specific user and pool in resource_limits"
67
-
[pool user]
68
-
(sql/execute! (pg/pg-db) ["SELECT resource_limit_type, pool_name, user_name, resource_name, amount from resource_limits WHERE resource_limit_type = 'quota' AND pool_name = ? and user_name = ?" pool user]))
46
+
(defnmake-resource-limit-map-from-sql-row
47
+
"Given a :resource_name and :amount keys in a sql result, map them into the resource limit keywords (:count, :gpus, etc.) and assoc onto the result."
; TODO: This should just cache all of the quota maps and refresh every 30 seconds into a global var for quota and share.
115
-
(split-one-resource-type sqlresult-quota)))
116
-
117
-
118
-
; TODO: This shouldn't exist. We should just cache all of the quota maps and refresh every 30 seconds. This then just delecates to the cache case with the global cache.
119
-
(defnget-quota-dict-pool-user
120
-
[pool-name user]
121
-
(-> (query-quota-pool-user pool-name user)
122
-
sql-result->quotamap
123
-
(get-in [pool-name user])))
124
-
125
-
; TODO: This shouldn't exist. We should just cache all of the quota maps and refresh every 30 seconds. This then just delecates to the cache case with the global cache.
(sql/execute! (pg/pg-db) ["DELETE FROM resource_limits WHERE resource_limit_type = ? AND pool_name = ? and user_name = ?;" resource-limit-type pool user]))
146
162
147
163
(defnretract-quota!
148
164
"Retract quota."
149
-
[pool user]
150
-
(sql/execute! (pg/pg-db) ["DELETE FROM resource_limits WHERE resource_limit_type = 'quota' AND pool_name = ? and user_name = ?;" pool user]))
165
+
[pool user reason]
166
+
(retract-resource-limit!"quota" pool user reason))
151
167
152
-
(defnquota-key-to-sql-key
153
-
"Convert from quota keyword notation to sql resource_type"
168
+
(defnretract-share!
169
+
"Retract share."
170
+
[pool user reason]
171
+
(retract-resource-limit!"share" pool user reason))
172
+
173
+
(defnresource-key-to-sql-key
174
+
"Convert from resource keyword notation to sql resource_type"
154
175
[keyword]
155
176
(case keyword
156
177
:count"count"
157
178
:cpus"cpus"
158
179
:mem"mem"
159
180
:gpus"gpus"
160
181
:launch-rate-saved"launch-rate-saved"
161
-
:launch-rate-per-minute"launch-rate-per-minute"))
182
+
:launch-rate-per-minute"launch-rate-per-minute"))
162
183
163
-
(defnset-quota!
164
-
[pool user kvs reason]
184
+
(defnset-resource-limit!
185
+
[resource-type pool user kvs reason]
165
186
(doseq [[key val] kvs]
166
187
; This is a bit overcomplicated to handle upsert logic, Insert or upate.
167
-
(sql/execute! (pg/pg-db) ["insert into resource_limits as r (resource_limit_type,pool_name,user_name,resource_name,amount,reason) VALUES (?,?,?,?,?,?) ON CONFLICT (resource_limit_type,pool_name,user_name,resource_name) DO UPDATE set amount=excluded.amount, reason=excluded.reason where r.resource_limit_type = excluded.resource_limit_type AND r.pool_name = excluded.pool_name and r.user_name=excluded.user_name and r.resource_name = excluded.resource_name;""quota" pool user (quota-key-to-sql-key key) val reason]))
188
+
(sql/execute! (pg/pg-db) ["insert into resource_limits as r (resource_limit_type,pool_name,user_name,resource_name,amount,reason) VALUES (?,?,?,?,?,?) ON CONFLICT (resource_limit_type,pool_name,user_name,resource_name) DO UPDATE set amount=excluded.amount, reason=excluded.reason where r.resource_limit_type = excluded.resource_limit_type AND r.pool_name = excluded.pool_name and r.user_name=excluded.user_name and r.resource_name = excluded.resource_name;" resource-type pool user (resource-key-to-sql-key key) val reason]))
189
+
; FIXME: does COMMIT do anything?
168
190
(sql/execute! (pg/pg-db) ["COMMIT;"]))
169
191
192
+
(defnset-quota!
193
+
[pool user kvs reason]
194
+
(set-resource-limit!"quota" pool user kvs reason))
195
+
196
+
(defnset-share!
197
+
[pool user kvs reason]
198
+
(set-resource-limit!"share" pool user kvs reason))
199
+
170
200
(defntruncate!
171
-
"Reset the quota table between unit tests"
201
+
"Reset the resource_limits table between unit tests"
172
202
[]
173
-
(sql/execute! (pg/pg-db) ["delete from resource_limits where true;"]))
203
+
(sql/execute! (pg/pg-db) ["delete from resource_limits where true;"]))
0 commit comments