Browse Source

AMBARI-10368 [WinTP2] Hive is broken

Fixed Hive parameters. Fixed process exit code propagation from cmd script.
Florian Barca 10 years ago
parent
commit
0de10b795b

+ 5 - 0
ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/HIVE/configuration/hive-site.xml

@@ -16,6 +16,11 @@
     <description>Driver class name for a JDBC metastore</description>
   </property>
 
+  <property>
+    <name>datanucleus.autoCreateSchema</name>
+    <value>false</value>
+  </property>
+
   <property>
     <name>hive.querylog.location</name>
     <value>c:\hadoop\logs\hive</value>

+ 28 - 1
ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/HIVE/package/scripts/hive.py

@@ -31,4 +31,31 @@ def hive(name=None):
             configuration_attributes=params.config['configuration_attributes']['hive-site']
   )
   if name in ["hiveserver2","metastore"]:
-    Execute(format("cmd /c hadoop fs -mkdir -p {hive_warehouse_dir}"), logoutput=True, user=params.hadoop_user)
+    Execute(format("cmd /c hadoop fs -mkdir -p {hive_warehouse_dir}"), logoutput=True, user=params.hadoop_user)
+
+  if name == 'metastore':
+    if params.init_metastore_schema:
+      check_schema_created_cmd = format('cmd /c "{hive_bin}\\hive.cmd --service schematool -info '
+                                        '-dbType {hive_metastore_db_type} '
+                                        '-userName {hive_metastore_user_name} '
+                                        '-passWord {hive_metastore_user_passwd!p}'
+                                        '&set EXITCODE=%ERRORLEVEL%&exit /B %EXITCODE%"', #cmd "feature", propagate the process exit code manually
+                                        hive_bin=params.hive_bin,
+                                        hive_metastore_db_type=params.hive_metastore_db_type,
+                                        hive_metastore_user_name=params.hive_metastore_user_name,
+                                        hive_metastore_user_passwd=params.hive_metastore_user_passwd)
+      try:
+        Execute(check_schema_created_cmd)
+      except Fail:
+        create_schema_cmd = format('cmd /c {hive_bin}\\hive.cmd --service schematool -initSchema '
+                                   '-dbType {hive_metastore_db_type} '
+                                   '-userName {hive_metastore_user_name} '
+                                   '-passWord {hive_metastore_user_passwd!p}',
+                                   hive_bin=params.hive_bin,
+                                   hive_metastore_db_type=params.hive_metastore_db_type,
+                                   hive_metastore_user_name=params.hive_metastore_user_name,
+                                   hive_metastore_user_passwd=params.hive_metastore_user_passwd)
+        Execute(create_schema_cmd,
+                user = params.hive_user,
+                logoutput=True
+      )

+ 16 - 0
ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/HIVE/package/scripts/params.py

@@ -23,6 +23,10 @@ from resource_management import *
 # server configurations
 config = Script.get_config()
 
+# This is expected to be of the form #.#.#.#
+stack_version_unformatted = str(config['hostLevelParams']['stack_version'])
+hdp_stack_version = format_hdp_stack_version(stack_version_unformatted)
+
 hdp_root = os.path.abspath(os.path.join(os.environ["HADOOP_HOME"],".."))
 hive_conf_dir = os.environ["HIVE_CONF_DIR"]
 hive_home = os.environ["HIVE_HOME"]
@@ -37,3 +41,15 @@ hive_warehouse_dir = config['configurations']['hive-site']['hive.metastore.wareh
 hive_user = "hadoop"
 hadoop_user = "hadoop"
 hcat_user = "hadoop"
+
+hive_bin = os.path.join(hive_home, "bin")
+hive_metastore_db_type = config['configurations']['hive-env']['hive_database_type']
+hive_metastore_user_name = config['configurations']['hive-site']['javax.jdo.option.ConnectionUserName']
+hive_metastore_user_passwd = config['configurations']['hive-site']['javax.jdo.option.ConnectionPassword']
+
+######## Metastore Schema
+if hdp_stack_version != "" and compare_versions(hdp_stack_version, "2.1.0.0") < 0:
+  init_metastore_schema = False
+else:
+  init_metastore_schema = True
+