aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Fixing error reporting in v1 client updater.
Date Tue, 28 Oct 2014 20:53:44 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 9fb2ce4c5 -> a675213fc


Fixing error reporting in v1 client updater.

Bugs closed: AURORA-901

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


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

Branch: refs/heads/master
Commit: a675213fc9343146c466ac43b7e4bd4a81aee548
Parents: 9fb2ce4
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Tue Oct 28 13:53:09 2014 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Tue Oct 28 13:53:09 2014 -0700

----------------------------------------------------------------------
 src/main/python/apache/aurora/client/api/BUILD  |  1 +
 .../python/apache/aurora/client/api/updater.py  | 13 ++++++--
 src/main/python/apache/aurora/client/base.py    |  3 +-
 src/test/python/apache/aurora/client/BUILD      |  7 +++++
 .../apache/aurora/client/api/test_updater.py    |  3 ++
 .../apache/aurora/client/commands/util.py       |  1 +
 .../python/apache/aurora/client/test_base.py    | 31 ++++++++++++++++++++
 7 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/main/python/apache/aurora/client/api/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/BUILD b/src/main/python/apache/aurora/client/api/BUILD
index 5787175..6d2a1bf 100644
--- a/src/main/python/apache/aurora/client/api/BUILD
+++ b/src/main/python/apache/aurora/client/api/BUILD
@@ -165,6 +165,7 @@ python_library(
     ':updater_util',
     ':quota_check',
     '3rdparty/python:twitter.common.log',
+    'src/main/python/apache/aurora/client:base',
     'src/main/thrift/org/apache/aurora/gen:py-thrift',
   ]
 )

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/main/python/apache/aurora/client/api/updater.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/updater.py b/src/main/python/apache/aurora/client/api/updater.py
index 2e6bc9f..2092ff3 100644
--- a/src/main/python/apache/aurora/client/api/updater.py
+++ b/src/main/python/apache/aurora/client/api/updater.py
@@ -24,6 +24,8 @@ from thrift.TSerialization import serialize
 from twitter.common import log
 from twitter.common.quantity import Amount, Time
 
+from apache.aurora.client.base import format_response
+
 from .error_handling_thread import ExecutionError, spawn_worker
 from .instance_watcher import InstanceWatcher
 from .job_monitor import JobMonitor
@@ -644,7 +646,12 @@ class Updater(object):
     return TaskQuery(jobKeys=[self._job_key], statuses=ACTIVE_STATES, instanceIds=instanceIds)
 
   def _failed_response(self, message):
-    return Response(responseCode=ResponseCode.ERROR, details=[ResponseDetail(message=message)])
+    # This is a synthetic Scheduler response that should follow the dual-write approach for
error
+    # messages to simplify caller's handling logic until the deprecation (AURORA-466) is
complete.
+    return Response(
+        responseCode=ResponseCode.ERROR,
+        details=[ResponseDetail(message=message)],
+        messageDEPRECATED=message)
 
   def update(self, instances=None):
     """Performs the job update, blocking until it completes.
@@ -710,8 +717,8 @@ class Updater(object):
 
     Raises Error in case of unexpected response status.
     """
-    name, message = ResponseCode._VALUES_TO_NAMES[resp.responseCode], resp.messageDEPRECATED
+    message = format_response(resp)
     if resp.responseCode == ResponseCode.OK:
-      log.debug('Response from scheduler: %s (message: %s)' % (name, message))
+      log.debug(message)
     else:
       raise self.Error(message)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/main/python/apache/aurora/client/base.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/base.py b/src/main/python/apache/aurora/client/base.py
index 0c8e97e..2c7d816 100644
--- a/src/main/python/apache/aurora/client/base.py
+++ b/src/main/python/apache/aurora/client/base.py
@@ -42,7 +42,8 @@ def die(msg):
 
 def format_response(resp):
   return 'Response from scheduler: %s (message: %s)' % (
-    ResponseCode._VALUES_TO_NAMES[resp.responseCode], resp.messageDEPRECATED)
+    ResponseCode._VALUES_TO_NAMES[resp.responseCode],
+    ", ".join([m.message for m in resp.details]) if resp.details else resp.messageDEPRECATED)
 
 
 def check_and_log_response(resp):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/test/python/apache/aurora/client/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/BUILD b/src/test/python/apache/aurora/client/BUILD
index 170227c..e31e434 100644
--- a/src/test/python/apache/aurora/client/BUILD
+++ b/src/test/python/apache/aurora/client/BUILD
@@ -34,6 +34,13 @@ python_tests(
   ],
 )
 
+python_tests(name = 'base',
+  sources = ['test_base.py'],
+  dependencies = [
+    'src/main/python/apache/aurora/client:base',
+  ],
+)
+
 python_tests(name = 'config',
   sources = ['test_config.py'],
   dependencies = [

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/test/python/apache/aurora/client/api/test_updater.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_updater.py b/src/test/python/apache/aurora/client/api/test_updater.py
index f0e45e3..a10e05c 100644
--- a/src/test/python/apache/aurora/client/api/test_updater.py
+++ b/src/test/python/apache/aurora/client/api/test_updater.py
@@ -354,6 +354,9 @@ class UpdaterTest(TestCase):
       assert message in resp.details[0].message, (
         "Expected %s message not found in: %s" % (message, resp.details[0].message))
 
+      assert message in resp.messageDEPRECATED, (
+        "Expected %s message not found in: %s" % (message, resp.messageDEPRECATED))
+
   def test_grow(self):
     """Adds instances to the existing job."""
     old_configs = self.make_task_configs(3)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/test/python/apache/aurora/client/commands/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/util.py b/src/test/python/apache/aurora/client/commands/util.py
index 65a358a..fb84258 100644
--- a/src/test/python/apache/aurora/client/commands/util.py
+++ b/src/test/python/apache/aurora/client/commands/util.py
@@ -33,6 +33,7 @@ class AuroraClientCommandTest(unittest.TestCase):
     response.responseCode = code
     response.messageDEPRECATED = msg
     response.result = Mock(spec=Result)
+    response.details = []
     return response
 
   @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a675213f/src/test/python/apache/aurora/client/test_base.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/test_base.py b/src/test/python/apache/aurora/client/test_base.py
new file mode 100644
index 0000000..785784b
--- /dev/null
+++ b/src/test/python/apache/aurora/client/test_base.py
@@ -0,0 +1,31 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import unittest
+
+from apache.aurora.client import base
+
+from gen.apache.aurora.api.ttypes import Response, ResponseCode, ResponseDetail
+
+
+class TestBase(unittest.TestCase):
+
+  def test_format_response_with_message(self):
+    resp = Response(responseCode=ResponseCode.ERROR, messageDEPRECATED='Error')
+    formatted = base.format_response(resp)
+    assert formatted == 'Response from scheduler: ERROR (message: Error)'
+
+  def test_format_response_with_details(self):
+    resp = Response(responseCode=ResponseCode.ERROR, details=[ResponseDetail(message='Error')])
+    formatted = base.format_response(resp)
+    assert formatted == 'Response from scheduler: ERROR (message: Error)'


Mime
View raw message