Add API for getting total cluster resources. (#1736)

* Add API for getting total cluster resources.

* Add test.
This commit is contained in:
Robert Nishihara
2018-03-20 15:57:00 -07:00
committed by Philipp Moritz
parent 794f547d0a
commit 2922e1c388
2 changed files with 26 additions and 1 deletions
+22
View File
@@ -3,6 +3,7 @@ from __future__ import division
from __future__ import print_function
import copy
from collections import defaultdict
import heapq
import json
import redis
@@ -949,3 +950,24 @@ class GlobalState(object):
if num_tasks is 0:
return 0, 0, 0
return overall_smallest, overall_largest, num_tasks
def cluster_resources(self):
"""Get the current total cluster resources.
Note that this information can grow stale as nodes are added to or
removed from the cluster.
Returns:
A dictionary mapping resource name to the total quantity of that
resource in the cluster.
"""
local_schedulers = self.local_schedulers()
resources = defaultdict(lambda: 0)
for local_scheduler in local_schedulers:
for key, value in local_scheduler.items():
if key not in ["ClientType", "Deleted", "DBClientID",
"AuxAddress", "LocalSchedulerSocketName"]:
resources[key] += value
return dict(resources)