ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [1/4] ambari git commit: AMBARI-18501. If ambari-server fails to start, appropriate error message should be displayed.(vbrodetskyi)
Date Tue, 04 Oct 2016 13:43:04 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-18456 aee49b67f -> 23fbfe480


AMBARI-18501. If ambari-server fails to start, appropriate error message should be displayed.(vbrodetskyi)


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

Branch: refs/heads/branch-feature-AMBARI-18456
Commit: 98ba7e075458404f63e2ca16c73068a6df32a800
Parents: ee02ad9
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Mon Oct 3 15:26:52 2016 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Mon Oct 3 15:26:52 2016 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_server/utils.py      | 42 +++++++++++++++++++-
 .../src/main/python/ambari_server_main.py       | 12 ++++--
 ambari-server/src/test/python/TestUtils.py      | 12 ++++--
 3 files changed, 57 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/98ba7e07/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 012d428..c0bacc8 100644
--- a/ambari-server/src/main/python/ambari_server/utils.py
+++ b/ambari-server/src/main/python/ambari_server/utils.py
@@ -26,6 +26,8 @@ import time
 import glob
 import subprocess
 from ambari_commons import OSConst,OSCheck
+from ambari_commons.logging_utils import print_error_msg
+from ambari_commons.exceptions import FatalException
 
 # PostgreSQL settings
 PG_STATUS_RUNNING_DEFAULT = "running"
@@ -139,13 +141,21 @@ def save_main_pid_ex(pids, pidfile, exclude_list=[], kill_exclude_list=False,
sk
       pass
 
 
-def wait_for_pid(pids, timeout):
+def wait_for_pid(pids, server_init_timeout, occupy_port_timeout, init_web_ui_timeout, properties):
   """
     Check pid for existence during timeout
   """
+  ambari_server_ui_port = 8080
+  api_ssl = properties.get_property("api.ssl")
+  ssl_api_port = properties.get_property("client.api.ssl.port")
+  if api_ssl and str(api_ssl).lower() == "true":
+    if ssl_api_port:
+      ambari_server_ui_port = int(ssl_api_port)
+
+  server_ui_port_occupied = False
   tstart = time.time()
   pid_live = 0
-  while int(time.time()-tstart) <= timeout and len(pids) > 0:
+  while int(time.time()-tstart) <= occupy_port_timeout and len(pids) > 0:
     sys.stdout.write('.')
     sys.stdout.flush()
     pid_live = 0
@@ -153,6 +163,34 @@ def wait_for_pid(pids, timeout):
       if pid_exists(item["pid"]):
         pid_live += 1
     time.sleep(1)
+
+    try:
+      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+      sock.settimeout(1)
+      sock.connect(('localhost', ambari_server_ui_port))
+      print "\nServer started listening on " + str(ambari_server_ui_port)
+      server_ui_port_occupied = True
+      break
+    except Exception as e:
+      #print str(e)
+      pass
+
+  if not server_ui_port_occupied:
+    raise FatalException(1, "Server not yet listening on http port " + str(ambari_server_ui_port)
+
+                            " after " + str(occupy_port_timeout) + str(server_init_timeout)
+ " seconds. Exiting.")
+
+  tstart = time.time()
+  print "Waiting for 10 seconds, for server WEB UI initialization"
+  while int(time.time()-tstart) <= init_web_ui_timeout and len(pids) > 0:
+    sys.stdout.write('.')
+    sys.stdout.flush()
+    pid_live = 0
+    for item in pids:
+      if pid_exists(item["pid"]):
+        pid_live += 1
+    time.sleep(1)
+
+
   return pid_live
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/98ba7e07/ambari-server/src/main/python/ambari_server_main.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server_main.py b/ambari-server/src/main/python/ambari_server_main.py
index 57ec58d..a2b50a6 100644
--- a/ambari-server/src/main/python/ambari_server_main.py
+++ b/ambari-server/src/main/python/ambari_server_main.py
@@ -101,8 +101,9 @@ SERVER_START_CMD_DEBUG_WINDOWS = "{0} " \
     "-cp {3} " \
     "org.apache.ambari.server.controller.AmbariServer"
 
-SERVER_INIT_TIMEOUT = 5
-SERVER_START_TIMEOUT = 10
+SERVER_INIT_TIMEOUT = 5   #seconds
+WEB_UI_INIT_TIME = 10     #seconds
+SERVER_START_TIMEOUT = 50 #seconds
 
 SERVER_PING_TIMEOUT_WINDOWS = 5
 SERVER_PING_ATTEMPTS_WINDOWS = 4
@@ -197,12 +198,17 @@ def wait_for_server_start(pidFile, scmStatus):
 
 @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
 def wait_for_server_start(pidFile, scmStatus):
+  properties = get_ambari_properties()
+  if properties == -1:
+    err ="Error getting ambari properties"
+    raise FatalException(-1, err)
+
   #wait for server process for SERVER_START_TIMEOUT seconds
   sys.stdout.write('Waiting for server start...')
   sys.stdout.flush()
 
   pids = looking_for_pid(SERVER_SEARCH_PATTERN, SERVER_INIT_TIMEOUT)
-  found_pids = wait_for_pid(pids, SERVER_START_TIMEOUT)
+  found_pids = wait_for_pid(pids, SERVER_INIT_TIMEOUT, SERVER_START_TIMEOUT, WEB_UI_INIT_TIME,
properties)
 
   sys.stdout.write('\n')
   sys.stdout.flush()

http://git-wip-us.apache.org/repos/asf/ambari/blob/98ba7e07/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 db94d92..14d9b20 100644
--- a/ambari-server/src/test/python/TestUtils.py
+++ b/ambari-server/src/test/python/TestUtils.py
@@ -123,9 +123,13 @@ class TestUtils(TestCase):
   @patch('time.time')
   @patch.object(utils, 'pid_exists')
   @patch('time.sleep')
-  def test_wait_for_pid(self, sleep_mock, pid_exists_mock, time_mock):
+  @patch("ambari_server.serverConfiguration.get_ambari_properties")
+  @patch("socket.socket")
+  def test_wait_for_pid(self, socket_mock, get_properties_mock, sleep_mock, pid_exists_mock,
time_mock):
     pid_exists_mock.return_value = True
-    time_mock.side_effect = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11]
+    time_mock.side_effect = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51]
+    s = socket_mock.return_value
+    s.connect = MagicMock()
 
     out = StringIO.StringIO()
     sys.stdout = out
@@ -138,8 +142,8 @@ class TestUtils(TestCase):
                                     "exe": "",
                                     "cmd": ""
                                     },
-                                   ], 10)
-    self.assertEqual("..........", out.getvalue())
+                                   ], 5, 40, 10, get_properties_mock)
+    self.assertEqual(".\nServer started listening on 8080\nWaiting for 10 seconds, for server
WEB UI initialization\n........", out.getvalue())
     sys.stdout = sys.__stdout__
 
     self.assertEquals(2, live_pids)


Mime
View raw message