Browse Source

AMBARI-9505 Hive service with HDPWIN 2.2 fails to start

Copying the SQL Server JDBC driver into the hadoop shared lib directory.
Florian Barca 10 năm trước cách đây
mục cha
commit
04f54294eb

+ 1 - 0
ambari-common/src/main/python/resource_management/libraries/functions/__init__.py

@@ -43,4 +43,5 @@ IS_WINDOWS = platform.system() == "Windows"
 if IS_WINDOWS:
   from resource_management.libraries.functions.windows_service_utils import *
   from resource_management.libraries.functions.install_hdp_msi import *
+  from resource_management.libraries.functions.install_jdbc_driver import *
   from resource_management.libraries.functions.reload_windows_env import *

+ 48 - 0
ambari-common/src/main/python/resource_management/libraries/functions/install_jdbc_driver.py

@@ -0,0 +1,48 @@
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+
+import os
+
+from ambari_commons.inet_utils import download_file
+from ambari_commons.os_utils import copy_file, search_file
+from resource_management.core.logger import Logger
+
+
+__all__ = ["ensure_jdbc_driver_is_in_classpath"]
+
+
+def ensure_jdbc_driver_is_in_classpath(dest_dir, cache_location, driver_url, driver_files):
+  #Attempt to find the JDBC driver installed locally
+  #If not, attempt to download it from the server resources URL
+  for driver_file in driver_files:
+    dest_path = os.path.join(dest_dir, driver_file)
+    Logger.info("JDBC driver file(s) {0}: Attempting to copy from {1} or download from {2} to {3}".format(
+      str(driver_files), cache_location, driver_url, dest_dir))
+    if not os.path.exists(dest_path):
+      search_path = os.environ["PATH"]
+      if cache_location:
+        search_path += os.pathsep + cache_location  #The locally installed version takes precedence over the cache
+
+      local_path = search_file(driver_file, search_path)
+      if not local_path:
+        download_file(driver_url + "/" + driver_file, dest_path)
+      else:
+        copy_file(local_path, dest_path)

+ 9 - 2
ambari-server/src/main/resources/stacks/HDPWIN/2.1/hooks/after-INSTALL/scripts/hook.py

@@ -19,18 +19,25 @@ limitations under the License.
 
 import sys
 
-from ambari_commons.inet_utils import download_file
 from resource_management import *
 from resource_management.libraries import Hook
 
 
 #Hook for hosts with only client without other components
 class AfterInstallHook(Hook):
-
   def hook(self, env):
     import params
     env.set_params(params)
 
+    #The SQL Server JDBC driver needs to end up in HADOOP_COMMOON_DIR\share\hadoop\common\lib
+    try:
+      ensure_jdbc_driver_is_in_classpath(params.hadoop_common_dir,
+                                         params.config["hostLevelParams"]["agentCacheDir"],
+                                         params.config['hostLevelParams']['jdk_location'],
+                                         ["sqljdbc4.jar", "sqljdbc_auth.dll"])
+    except Exception, e:
+      raise Fail("Unable to deploy the required JDBC driver in the class path. Error info: {0}".format(e.message))
+
     XmlConfig("core-site.xml",
               conf_dir=params.hadoop_conf_dir,
               configurations=params.config['configurations']['core-site'],