You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2013/12/09 21:23:03 UTC

git commit: Adding support for a 'locked job warning' in client APIs

Updated Branches:
  refs/heads/master cf7ee5a64 -> 67191a910


Adding support for a 'locked job warning' in client APIs


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

Branch: refs/heads/master
Commit: 67191a9101e0c1cd4f17d744d333f1378b73cf9d
Parents: cf7ee5a
Author: Maxim Khutornenko <mk...@twitter.com>
Authored: Mon Dec 9 12:22:40 2013 -0800
Committer: Maxim Khutornenko <mk...@twitter.com>
Committed: Mon Dec 9 12:22:40 2013 -0800

----------------------------------------------------------------------
 src/main/python/twitter/aurora/client/api/BUILD      |  1 +
 src/main/python/twitter/aurora/client/api/updater.py | 15 ++++-----------
 src/main/python/twitter/aurora/client/base.py        | 15 ++++++++++++++-
 3 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/67191a91/src/main/python/twitter/aurora/client/api/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/twitter/aurora/client/api/BUILD b/src/main/python/twitter/aurora/client/api/BUILD
index 4935b8a..6818a75 100644
--- a/src/main/python/twitter/aurora/client/api/BUILD
+++ b/src/main/python/twitter/aurora/client/api/BUILD
@@ -91,6 +91,7 @@ python_library(
     pants(':instance_watcher'),
     pants(':updater_util'),
     pants('aurora/twitterdeps/src/python/twitter/common/log'),
+    pants('src/main/python/twitter/aurora/client:base'),
     pants('src/main/thrift/com/twitter/aurora/gen:py-thrift'),
   ]
 )

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/67191a91/src/main/python/twitter/aurora/client/api/updater.py
----------------------------------------------------------------------
diff --git a/src/main/python/twitter/aurora/client/api/updater.py b/src/main/python/twitter/aurora/client/api/updater.py
index 3e6e642..24c811b 100644
--- a/src/main/python/twitter/aurora/client/api/updater.py
+++ b/src/main/python/twitter/aurora/client/api/updater.py
@@ -4,6 +4,8 @@ from difflib import unified_diff
 from twitter.common import log
 
 from gen.twitter.aurora.constants import ACTIVE_STATES
+
+from twitter.aurora.client.base import check_and_log_locked_response
 from gen.twitter.aurora.ttypes import (
     AddInstancesConfig,
     JobConfigValidation,
@@ -23,16 +25,7 @@ from .scheduler_client import SchedulerProxy
 
 class Updater(object):
   """Update the instances of a job in batches."""
-  UPDATE_FAILURE_WARNING = """
-Note: if the scheduler detects that an update is in progress (or was not
-properly completed) it will reject subsequent updates.  This is because your
-job is likely in a partially-updated state.  You should only begin another
-update if you are confident that no other team members are updating this
-job, and that the job is in a state suitable for an update.
-
-After checking on the above, you may release the update lock on the job by
-invoking cancel_update.
-"""
+
   class Error(Exception): pass
   class InvalidConfigError(Error): pass
   class InvalidStateError(Error): pass
@@ -72,7 +65,7 @@ invoking cancel_update.
       self._lock = resp.result.acquireLockResult.lock
     else:
       log.error('Error starting update: %s' % resp.message)
-      log.error(self.UPDATE_FAILURE_WARNING)
+      check_and_log_locked_response(resp)
     return resp
 
   def _finish(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/67191a91/src/main/python/twitter/aurora/client/base.py
----------------------------------------------------------------------
diff --git a/src/main/python/twitter/aurora/client/base.py b/src/main/python/twitter/aurora/client/base.py
index 9584df6..0936743 100644
--- a/src/main/python/twitter/aurora/client/base.py
+++ b/src/main/python/twitter/aurora/client/base.py
@@ -7,18 +7,31 @@ from twitter.common import app, log
 
 from gen.twitter.aurora.ttypes import ResponseCode
 
+LOCKED_WARNING = """
+Note: if the scheduler detects that a job update is in progress (or was not
+properly completed) it will reject subsequent updates.  This is because your
+job is likely in a partially-updated state.  You should only begin another
+update if you are confident that nobody is updating this job, and that
+the job is in a state suitable for an update.
+
+After checking on the above, you may release the update lock on the job by
+invoking cancel_update.
+"""
 
 def die(msg):
   log.fatal(msg)
   sys.exit(1)
 
-
 def check_and_log_response(resp):
   log.info('Response from scheduler: %s (message: %s)'
       % (ResponseCode._VALUES_TO_NAMES[resp.responseCode], resp.message))
   if resp.responseCode != ResponseCode.OK:
+    check_and_log_locked_response(resp)
     sys.exit(1)
 
+def check_and_log_locked_response(resp):
+  if resp.responseCode == ResponseCode.LOCK_ERROR:
+    log.info(LOCKED_WARNING)
 
 def deprecation_warning(text):
   log.warning('')