You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2014/07/10 04:16:03 UTC

git commit: AMBARI-6447. Waiting to start ambari server should print output

Repository: ambari
Updated Branches:
  refs/heads/trunk 8af1ee1f2 -> 293421923


AMBARI-6447. Waiting to start ambari server should print output


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

Branch: refs/heads/trunk
Commit: 2934219233c999a5e0fadc183729fda27bae50f4
Parents: 8af1ee1
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Wed Jul 9 17:17:33 2014 -0700
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Wed Jul 9 19:15:38 2014 -0700

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 17 ++++++++++++-----
 .../src/main/python/ambari_server/utils.py      |  5 +++++
 ambari-server/src/test/python/TestUtils.py      | 20 ++++++++++++++++----
 3 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/29342192/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 1aaff95..8aec854 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -2553,19 +2553,26 @@ def start(args):
   print_info_msg("Running server: " + str(param_list))
   subprocess.Popen(param_list, env=environ)
 
+  print "Server PID at: "+pidfile
+  print "Server out at: "+SERVER_OUT_FILE
+  print "Server log at: "+SERVER_LOG_FILE
+
   #wait for server process for SERVER_START_TIMEOUT seconds
-  print "Waiting for server start..."
+  sys.stdout.write('Waiting for server start...')
+  sys.stdout.flush()
 
   pids = utils.looking_for_pid(SERVER_SEARCH_PATTERN, SERVER_INIT_TIMEOUT)
-  if utils.wait_for_pid(pids, SERVER_START_TIMEOUT) <= 0:
+  found_pids = utils.wait_for_pid(pids, SERVER_START_TIMEOUT)
+
+  sys.stdout.write('\n')
+  sys.stdout.flush()
+
+  if found_pids <= 0:
     exitcode = utils.check_exitcode(os.path.join(PID_DIR, EXITCODE_NAME))
     raise FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, SERVER_OUT_FILE))
   else:
     utils.save_main_pid_ex(pids, pidfile, [utils.locate_file('sh', '/bin'),
                                  utils.locate_file('bash', '/bin')], True)
-    print "Server PID at: "+pidfile
-    print "Server out at: "+SERVER_OUT_FILE
-    print "Server log at: "+SERVER_LOG_FILE
 
 
 #

http://git-wip-us.apache.org/repos/asf/ambari/blob/29342192/ambari-server/src/main/python/ambari_server/utils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/utils.py b/ambari-server/src/main/python/ambari_server/utils.py
index 16230df..db9fcb7 100644
--- a/ambari-server/src/main/python/ambari_server/utils.py
+++ b/ambari-server/src/main/python/ambari_server/utils.py
@@ -19,6 +19,7 @@ limitations under the License.
 '''
 import os
 import signal
+import sys
 import time
 from ambari_commons import OSConst
 
@@ -100,6 +101,8 @@ def wait_for_pid(pids, timeout):
   tstart = time.time()
   pid_live = 0
   while int(time.time()-tstart) <= timeout and len(pids) > 0:
+    sys.stdout.write('.')
+    sys.stdout.flush()
     pid_live = 0
     for item in pids:
       if pid_exists(item["pid"]):
@@ -130,6 +133,8 @@ def looking_for_pid(pattern, wait_time=1):
   found_pids = []
 
   while int(time.time()-tstart) <= wait_time:
+    sys.stdout.write('.')
+    sys.stdout.flush()
     pids = [pid for pid in os.listdir(PROC_DIR) if pid.isdigit()]
     found_pids = []  # clear list
     for pid in pids:

http://git-wip-us.apache.org/repos/asf/ambari/blob/29342192/ambari-server/src/test/python/TestUtils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestUtils.py b/ambari-server/src/test/python/TestUtils.py
index 100d0b5..a24b790 100644
--- a/ambari-server/src/test/python/TestUtils.py
+++ b/ambari-server/src/test/python/TestUtils.py
@@ -16,6 +16,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
+import StringIO
+import sys
 from unittest import TestCase
 from mock.mock import patch
 
@@ -88,9 +90,14 @@ class TestUtils(TestCase):
     open_mock.return_value = test_obj
     listdir_mock.return_value = ['1000']
     get_symlink_path_mock.return_value = "/symlinkpath"
-    time_mock.side_effect = [0, 0, 2]
+    time_mock.side_effect = [0, 0, 0, 0, 0, 0, 6]
+
+    out = StringIO.StringIO()
+    sys.stdout = out
+    r = utils.looking_for_pid("test args", 5)
+    self.assertEqual(".....", out.getvalue())
+    sys.stdout = sys.__stdout__
 
-    r = utils.looking_for_pid("test args", 1)
     self.assertEquals(len(r), 1)
     self.assertEquals(r[0], {
        "pid": "1000",
@@ -112,7 +119,10 @@ class TestUtils(TestCase):
   @patch('time.sleep')
   def test_wait_for_pid(self, sleep_mock, pid_exists_mock, time_mock):
     pid_exists_mock.return_value = True
-    time_mock.side_effect = [0, 0, 2]
+    time_mock.side_effect = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11]
+
+    out = StringIO.StringIO()
+    sys.stdout = out
     live_pids = utils.wait_for_pid([
                                    {"pid": "111",
                                     "exe": "",
@@ -122,7 +132,9 @@ class TestUtils(TestCase):
                                     "exe": "",
                                     "cmd": ""
                                     },
-                                   ], 1)
+                                   ], 10)
+    self.assertEqual("..........", out.getvalue())
+    sys.stdout = sys.__stdout__
 
     self.assertEquals(2, live_pids)