couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [1/4] couchdb commit: updated refs/heads/master to 9f5ae10
Date Wed, 08 Apr 2015 18:55:52 GMT
Repository: couchdb
Updated Branches:
  refs/heads/master 772add2ad -> 9f5ae101b


More verbose check nodes for being alive


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

Branch: refs/heads/master
Commit: ae65aed40a1111514d6918619f1d3da2f5247216
Parents: 772add2
Author: Alexander Shorin <kxepal@apache.org>
Authored: Sat Apr 4 23:33:09 2015 +0300
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Wed Apr 8 17:10:04 2015 +0300

----------------------------------------------------------------------
 dev/run | 64 +++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/ae65aed4/dev/run
----------------------------------------------------------------------
diff --git a/dev/run b/dev/run
index fcf9514..501c3cf 100755
--- a/dev/run
+++ b/dev/run
@@ -50,13 +50,13 @@ def log(msg):
                     sys.stdout.flush()
             callargs = dict(zip(inspect.getargspec(func).args, args))
             callargs.update(kwargs)
-            print_(msg.format(**callargs) + '... ')
+            print_(msg.format(**callargs) + ' ... ')
             try:
                 res = func(*args, **kwargs)
             except KeyboardInterrupt:
                 print_('ok\n')
-            except:
-                print_('failed\n')
+            except Exception as err:
+                print_('failed: %s\n' % err)
                 raise
             else:
                 print_('ok\n')
@@ -230,6 +230,7 @@ def hashify(pwd, salt=COMMON_SALT, iterations=10, keylen=20):
 def startup(ctx):
     atexit.register(kill_processes, ctx)
     boot_nodes(ctx)
+    ensure_all_nodes_alive(ctx)
     join_nodes(ctx, "127.0.0.1", 15986)
 
 
@@ -243,30 +244,44 @@ def boot_nodes(ctx):
     for node in ctx['nodes']:
         ctx['procs'].append(boot_node(ctx, node))
 
-    ensure_nodes_stated(ctx)
-
-
-@log('Ensure all nodes are run')
-def ensure_nodes_stated(ctx):
-    for _ in range(30):
-        if all_nodes_alive(ctx):
-            break
-        time.sleep(1)
-
 
-def all_nodes_alive(ctx):
-    for num in range(ctx['N']):
-        local_port, _ = get_ports(num + 1)
-        url = "http://127.0.0.1:{0}/".format(local_port)
-        while True:
-            try:
-                with contextlib.closing(urlopen(url)):
-                    pass
-            except IOError:
-                time.sleep(0.25)
+def ensure_all_nodes_alive(ctx):
+    status = dict((num, False) for num in range(ctx['N']))
+    for _ in range(10):
+        for num in range(ctx['N']):
+            if status[num]:
                 continue
+            local_port, _ = get_ports(num + 1)
+            url = "http://127.0.0.1:{0}/".format(local_port)
+            try:
+                check_node_alive(url)
+            except:
+                pass
+            else:
+                status[num] = True
+        if all(status.values()):
+            return
+        time.sleep(1)
+    if not all(status.values()):
+        print('Failed to start all the nodes.'
+              ' Check the dev/logs/*.log for errors.')
+        sys.exit(1)
+
+
+@log('Check node at {url}')
+def check_node_alive(url):
+    error = None
+    for _ in range(10):
+        try:
+            with contextlib.closing(urlopen(url)):
+                pass
+        except Exception as exc:
+            error = exc
+            time.sleep(1)
+        else:
             break
-    return True
+    if error is not None:
+        raise error
 
 
 @log('Start node {node}')
@@ -332,6 +347,7 @@ def run_command(ctx, cmd):
 def reboot_nodes(ctx):
     kill_processes(ctx)
     boot_nodes(ctx)
+    ensure_all_nodes_alive(ctx)
 
 
 if __name__ == "__main__":


Mime
View raw message