Parcourir la source

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

Srimanth Gunturi il y a 11 ans
Parent
commit
2934219233

+ 12 - 5
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
 
 
 #

+ 5 - 0
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:

+ 16 - 4
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)