ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [03/35] ambari git commit: AMBARI-21110. ambari-server setup fails with default postgres (aonishuk)
Date Thu, 25 May 2017 17:24:13 GMT
AMBARI-21110. ambari-server setup fails with default postgres (aonishuk)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: b9ecb1fa5c5e602d2ea1ae70be2dbbca8368a59f
Parents: ff0c525
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Wed May 24 21:52:17 2017 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Wed May 24 21:52:17 2017 +0300

----------------------------------------------------------------------
 .../main/python/ambari_commons/inet_utils.py    | 12 +++++++++
 .../ambari_server/dbConfiguration_linux.py      | 27 ++++++++++----------
 2 files changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b9ecb1fa/ambari-common/src/main/python/ambari_commons/inet_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/inet_utils.py b/ambari-common/src/main/python/ambari_commons/inet_utils.py
index 66f6544..22eaaf5 100644
--- a/ambari-common/src/main/python/ambari_commons/inet_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/inet_utils.py
@@ -19,6 +19,7 @@ limitations under the License.
 '''
 
 import os
+import time
 import sys
 import urllib2
 import socket
@@ -70,6 +71,17 @@ def download_progress(file_name, downloaded_size, blockSize, totalSize):
   sys.stdout.write(status)
   sys.stdout.flush()
 
+def wait_for_port_opened(hostname, port, tries_count, try_sleep):
+  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+  sock.settimeout(2)
+
+  for i in range(tries_count):
+    if sock.connect_ex((hostname, port)) == 0:
+      return True
+    time.sleep(try_sleep)
+
+  return False
+
 
 def find_range_components(meta):
   file_size = 0

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9ecb1fa/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
index 797466d..dac3141 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -46,7 +46,7 @@ from ambari_server.serverConfiguration import encrypt_password, store_password_f
     PERSISTENCE_TYPE_PROPERTY, JDBC_CONNECTION_POOL_TYPE, JDBC_CONNECTION_POOL_ACQUISITION_SIZE,
\
     JDBC_CONNECTION_POOL_IDLE_TEST_INTERVAL, JDBC_CONNECTION_POOL_MAX_AGE, JDBC_CONNECTION_POOL_MAX_IDLE_TIME,
\
     JDBC_CONNECTION_POOL_MAX_IDLE_TIME_EXCESS, JDBC_SQLA_SERVER_NAME, LOCAL_DATABASE_ADMIN_PROPERTY
-
+from ambari_commons.inet_utils import wait_for_port_opened
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 
 from ambari_server.userInput import get_YN_input, get_validated_string_input, read_password
@@ -59,6 +59,10 @@ ORACLE_SNAME_PATTERN = "jdbc:oracle:thin:@.+:.+:.+"
 
 JDBC_PROPERTIES_PREFIX = "server.jdbc.properties."
 
+PG_PORT_CHECK_TRIES_COUNT = 30
+PG_PORT_CHECK_INTERVAL = 1
+PG_PORT = 5432
+
 class LinuxDBMSConfig(DBMSConfig):
   def __init__(self, options, properties, storage_type):
     super(LinuxDBMSConfig, self).__init__(options, properties, storage_type)
@@ -622,19 +626,14 @@ class PGConfig(LinuxDBMSConfig):
                                    stdin=subprocess.PIPE,
                                    stderr=subprocess.PIPE
         )
-        if OSCheck.is_suse_family():
-          time.sleep(20)
-          result = process.poll()
-          print_info_msg("Result of postgres start cmd: " + str(result))
-          if result is None:
-            process.kill()
-            pg_status, retcode, out, err = PGConfig._get_postgre_status()
-          else:
-            retcode = result
-        else:
-          out, err = process.communicate()
-          retcode = process.returncode
-          pg_status, retcode, out, err = PGConfig._get_postgre_status()
+        out, err = process.communicate()
+        retcode = process.returncode
+
+        print_info_msg("Waiting for postgres to start at port {0}...".format(PG_PORT))
+        wait_for_port_opened('127.0.0.1', PG_PORT, PG_PORT_CHECK_TRIES_COUNT, PG_PORT_CHECK_INTERVAL)
+
+        pg_status, retcode, out, err = PGConfig._get_postgre_status()
+
         if pg_status == PGConfig.PG_STATUS_RUNNING:
           print_info_msg("Postgres process is running. Returning...")
           return pg_status, 0, out, err


Mime
View raw message