Przeglądaj źródła

AMBARI-17937:Ambari install/init should create a new gpadmin database (lavjain)

ljainpivotalio 9 lat temu
rodzic
commit
8138a9dbee

+ 8 - 6
ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/common.py

@@ -31,7 +31,6 @@ import xml.etree.ElementTree as ET
 import utils
 import hawq_constants
 import custom_params
-import hawqstatus
 
 def setup_user():
   """
@@ -291,15 +290,18 @@ def start_component(component_name, port, data_dir):
                         mode=0755)
     params.HdfsResource(None, action="execute")
 
+  options_str = "{0} -a -v".format(component_name)
   if os.path.exists(os.path.join(data_dir, hawq_constants.postmaster_opts_filename)):
-    return utils.exec_hawq_operation(hawq_constants.START,
-                                     "{0} -a -v".format(component_name),
+    return utils.exec_hawq_operation(hawq_constants.START, options_str,
                                      not_if=utils.generate_hawq_process_status_cmd(component_name, port))
 
-  options_str = "{0} -a -v".format(component_name)
+  # Initialize HAWQ
   if component_name == hawq_constants.MASTER:
-    options_str+=" --ignore-bad-hosts"
-  utils.exec_hawq_operation(hawq_constants.INIT, options_str)
+    utils.exec_hawq_operation(hawq_constants.INIT, options_str + " --ignore-bad-hosts")
+    utils.exec_psql_cmd('create database {0};'.format(hawq_constants.hawq_user),
+                        params.hawqmaster_host, params.hawq_master_address_port, ignore_error=True)
+  else:
+    utils.exec_hawq_operation(hawq_constants.INIT, options_str)
 
 def stop_component(component_name, mode):
   """

+ 3 - 2
ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py

@@ -88,7 +88,7 @@ def exec_ssh_cmd(hostname, cmd):
   return process.returncode, stdout, stderr
 
 
-def exec_psql_cmd(command, host, port, db=hawq_constants.POSTGRES, tuples_only=True):
+def exec_psql_cmd(command, host, port, db=hawq_constants.POSTGRES, tuples_only=True, ignore_error=False):
   """
   Sets up execution environment and runs the HAWQ queries
   """
@@ -100,7 +100,8 @@ def exec_psql_cmd(command, host, port, db=hawq_constants.POSTGRES, tuples_only=T
   retcode, out, err = exec_ssh_cmd(host, cmd)
   if retcode:
     Logger.error("SQL command executed failed: {0}\nReturncode: {1}\nStdout: {2}\nStderr: {3}".format(cmd, retcode, out, err))
-    raise Fail("SQL command executed failed.")
+    if not ignore_error:
+      raise Fail("SQL command executed failed.")
 
   Logger.info("Output:\n{0}".format(out))
   return retcode, out, err