aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject incubator-aurora git commit: Improving quota check message in the client.
Date Tue, 06 Jan 2015 23:26:27 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 9f6ec4bd9 -> 8c49029b6


Improving quota check message in the client.

Bugs closed: AURORA-469

Reviewed at https://reviews.apache.org/r/28872/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/8c49029b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/8c49029b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/8c49029b

Branch: refs/heads/master
Commit: 8c49029b640211f7cccf79d79e2b5ca52ac37e2f
Parents: 9f6ec4b
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Tue Jan 6 15:26:07 2015 -0800
Committer: -l <maxim@apache.org>
Committed: Tue Jan 6 15:26:07 2015 -0800

----------------------------------------------------------------------
 .../apache/aurora/client/api/quota_check.py     | 13 ++++++++++++
 .../aurora/client/api/test_quota_check.py       | 21 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8c49029b/src/main/python/apache/aurora/client/api/quota_check.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/quota_check.py b/src/main/python/apache/aurora/client/api/quota_check.py
index c994050..75406ac 100644
--- a/src/main/python/apache/aurora/client/api/quota_check.py
+++ b/src/main/python/apache/aurora/client/api/quota_check.py
@@ -12,6 +12,7 @@
 # limitations under the License.
 #
 
+import math
 import operator
 from copy import deepcopy
 
@@ -56,6 +57,16 @@ class CapacityRequest(object):
   def valid(self):
     return self._quota.numCpus >= 0.0 and self._quota.ramMb >= 0 and self._quota.diskMb
>= 0
 
+  def invert_or_reset(self):
+    """Inverts negative resource and resets positive resource as zero."""
+    def invert_or_reset(val):
+      return math.fabs(val) if val < 0 else 0
+
+    return CapacityRequest(ResourceAggregate(
+        numCpus=invert_or_reset(self._quota.numCpus),
+        ramMb=invert_or_reset(self._quota.ramMb),
+        diskMb=invert_or_reset(self._quota.diskMb)))
+
   def quota(self):
     return deepcopy(self._quota)
 
@@ -99,6 +110,8 @@ class QuotaCheck(object):
       print_quota(allocated.quota(), 'Total allocated quota', job_key.role)
       print_quota(consumed.quota(), 'Consumed quota', job_key.role)
       print_quota(requested.quota(), 'Requested', job_key.name)
+      print_quota(effective.invert_or_reset().quota(), 'Additional quota required', job_key.role)
+
       # TODO(wfarner): Avoid synthesizing scheduler responses.
       return Response(
           responseCode=ResponseCode.INVALID_REQUEST,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8c49029b/src/test/python/apache/aurora/client/api/test_quota_check.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_quota_check.py b/src/test/python/apache/aurora/client/api/test_quota_check.py
index 2fc76d2..2c9bef1 100644
--- a/src/test/python/apache/aurora/client/api/test_quota_check.py
+++ b/src/test/python/apache/aurora/client/api/test_quota_check.py
@@ -15,9 +15,9 @@
 import unittest
 from copy import deepcopy
 
-from mock import create_autospec
+from mock import call, create_autospec, patch
 
-from apache.aurora.client.api.quota_check import CapacityRequest, QuotaCheck
+from apache.aurora.client.api.quota_check import CapacityRequest, print_quota, QuotaCheck
 
 from .api_util import SchedulerThriftApiSpec
 
@@ -110,3 +110,20 @@ class QuotaCheckTest(unittest.TestCase):
 
     self.mock_get_quota(allocated, consumed, response_code=ResponseCode.INVALID_REQUEST)
     self.assert_result(True, released, acquired, ResponseCode.INVALID_REQUEST)
+
+  @patch('apache.aurora.client.api.quota_check.print_quota', spec=print_quota)
+  def test_additional_quota_out(self, mock_print_quota):
+    allocated = ResourceAggregate(numCpus=50.0, ramMb=1000, diskMb=3000)
+    consumed = ResourceAggregate(numCpus=45.0, ramMb=900, diskMb=2900)
+    released = CapacityRequest(ResourceAggregate(numCpus=5.0, ramMb=100, diskMb=100))
+    acquired = CapacityRequest(ResourceAggregate(numCpus=11.0, ramMb=220, diskMb=200))
+    additional = ResourceAggregate(numCpus=1.0, ramMb=20, diskMb=0)
+
+    self.mock_get_quota(allocated, consumed)
+    self.assert_result(True, released, acquired, ResponseCode.INVALID_REQUEST)
+    assert mock_print_quota.mock_calls[:4] == [
+        call(allocated, 'Total allocated quota', self._role),
+        call(consumed, 'Consumed quota', self._role),
+        call((acquired - released).quota(), 'Requested', self._name),
+        call(additional, 'Additional quota required', self._role)
+    ]


Mime
View raw message