ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fba...@apache.org
Subject ambari git commit: AMBARI-9390 Ambari Server Setup issues on Windows
Date Tue, 03 Feb 2015 02:23:31 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a2f3be6c9 -> 314ae0b10


AMBARI-9390 Ambari Server Setup issues on Windows

+Fixed erroneous exit when re-running setup after JDK/JCE were installed (Linux primarily,
but Windows is affected too)
+Fixed SQL Server properties update when passing them via command-line arguments


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

Branch: refs/heads/trunk
Commit: 314ae0b10feb3ddb1884ff031d598627e0ba9977
Parents: a2f3be6
Author: Florian Barca <fbarca@hortonworks.com>
Authored: Mon Feb 2 15:17:29 2015 -0800
Committer: Florian Barca <fbarca@hortonworks.com>
Committed: Mon Feb 2 18:23:07 2015 -0800

----------------------------------------------------------------------
 .../src/main/python/ambari_commons/str_utils.py |  16 ++
 ambari-server/src/main/python/ambari-server.py  |   3 +-
 .../python/ambari_server/dbConfiguration.py     |   6 +-
 .../ambari_server/dbConfiguration_windows.py    |   8 +-
 .../python/ambari_server/serverConfiguration.py |   6 +-
 .../main/python/ambari_server/serverSetup.py    | 152 +++++++++++--------
 .../src/test/python/TestAmbariServer.py         |  55 ++++---
 7 files changed, 143 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-common/src/main/python/ambari_commons/str_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/str_utils.py b/ambari-common/src/main/python/ambari_commons/str_utils.py
index 9a9e954..538d7c6 100644
--- a/ambari-common/src/main/python/ambari_commons/str_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/str_utils.py
@@ -28,3 +28,19 @@ def ensure_double_backslashes(s):
   s1 = compress_backslashes(s)
   s2 = s1.replace('\\', '\\\\')
   return s2
+
+def cbool(obj):
+  """
+  Interprets an object as a boolean value.
+
+  :rtype: bool
+  """
+  if isinstance(obj, str):
+    obj = obj.strip().lower()
+    if obj in ('true', 'yes', 'on', 'y', 't', '1'):
+      return True
+    if obj in ('false', 'no', 'off', 'n', 'f', '0'):
+      return False
+    raise ValueError('Unable to interpret value "%s" as boolean' % obj)
+  return bool(obj)
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index bf8f806..3c4c9c7 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -302,8 +302,7 @@ def init_parser_options(parser):
   parser.add_option('-p', '--databasepassword', dest="database_password", default=None,
                     help="Database user password")
   parser.add_option('--jdbc-driver', default=None, dest="jdbc_driver",
-                    help="Specifies the path to the JDBC driver JAR file for the " \
-                         "database type specified with the --jdbc-db option. Used only with
--jdbc-db option.")
+                    help="Specifies the path to the JDBC driver JAR file")
   # -b, -i, -k and -x the remaining available short options
   # -h reserved for help
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/main/python/ambari_server/dbConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration.py b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
index 819c5c3..9962a5d 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
@@ -24,6 +24,7 @@ from ambari_commons import OSConst
 from ambari_commons.exceptions import FatalException
 from ambari_commons.logging_utils import get_silent, print_error_msg, print_info_msg, print_warning_msg,
set_silent
 from ambari_commons.os_family_impl import OsFamilyImpl
+from ambari_commons.str_utils import cbool
 from ambari_server.serverConfiguration import decrypt_password_for_alias, get_value_from_properties,
get_is_secure, \
   is_alias_string, \
   JDBC_PASSWORD_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, PRESS_ENTER_MSG, get_ambari_properties,
update_properties, \
@@ -150,9 +151,8 @@ class DBMSConfig(object):
       raise FatalException(-1, msg)
 
     if result != 1:
-      if self._install_jdbc_driver(properties, result):
-        return True
-    return False
+      result = self._install_jdbc_driver(properties, result)
+    return cbool(result)
 
   def change_db_files_owner(self):
     if self._is_local_database():

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/main/python/ambari_server/dbConfiguration_windows.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_windows.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_windows.py
index 60308a0..027a84f 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_windows.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_windows.py
@@ -25,7 +25,7 @@ from ambari_commons.exceptions import FatalException
 from ambari_commons.logging_utils import print_info_msg, print_warning_msg
 from ambari_commons.os_utils import search_file, run_os_command
 from ambari_commons.os_windows import WinServiceController
-from ambari_commons.str_utils import compress_backslashes, ensure_double_backslashes
+from ambari_commons.str_utils import cbool, compress_backslashes, ensure_double_backslashes
 from ambari_server.dbConfiguration import AMBARI_DATABASE_NAME, DEFAULT_USERNAME, DEFAULT_PASSWORD,
\
   DBMSConfig, DbPropKeys, DbAuthenticationKeys
 from ambari_server.serverConfiguration import JDBC_DRIVER_PROPERTY, JDBC_DRIVER_PATH_PROPERTY,
JDBC_URL_PROPERTY, \
@@ -79,8 +79,8 @@ class SQLServerConfig(DBMSConfig):
     self.database_name = DBMSConfig._init_member_with_prop_default(options, "database_name",
                                                                    properties, self.dbPropKeys.db_name_key,
configDefaults.DEFAULT_DB_NAME)
 
-    self.use_windows_authentication = DBMSConfig._init_member_with_prop_default(options,
"database_windows_auth",
-        properties, self.dbAuthKeys.integrated_auth_key, "False")
+    self.use_windows_authentication = cbool(DBMSConfig._init_member_with_prop_default(options,
"database_windows_auth",
+        properties, self.dbAuthKeys.integrated_auth_key, False))
     self.database_username = DBMSConfig._init_member_with_prop_default(options, "database_username",
                                                                        properties, self.dbAuthKeys.user_name_key,
DEFAULT_USERNAME)
     self.database_password = DBMSConfig._init_member_with_default(options, "database_password",
"")
@@ -115,7 +115,7 @@ class SQLServerConfig(DBMSConfig):
       self.database_host = get_validated_string_input(hostname_prompt, self.database_host,
None, None, False, True)
 
       #prompt for SQL Server authentication method
-      if (not self.use_windows_authentication is None and self.use_windows_authentication.lower()
== "true") or \
+      if not self.use_windows_authentication or \
               self.database_username is None or self.database_username == "":
         auth_option_default = '1'
       else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/main/python/ambari_server/serverConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
index ba5bf4b..aeb2b6c 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -179,8 +179,8 @@ class ServerConfigDefaults(object):
     self.JDK_INSTALL_DIR = ""
     self.JDK_SEARCH_PATTERN = ""
     self.JAVA_EXE_SUBPATH = ""
-    self.JDK_SECURITY_DIR = "jre/lib/security"
-    self.SERVER_RESOURCES_DIR = "/var/lib/ambari-server/resources"
+    self.JDK_SECURITY_DIR = os.path.join("jre", "lib", "security")
+    self.SERVER_RESOURCES_DIR = ""
 
     # Configuration defaults
     self.DEFAULT_CONF_DIR = ""
@@ -256,6 +256,7 @@ class ServerConfigDefaultsWindows(ServerConfigDefaults):
     ]
     self.NR_USERADD_CMD = "cmd /C net user {0} {1} /ADD"
 
+    self.SERVER_RESOURCES_DIR = "resources"
     self.STACK_LOCATION_DEFAULT = "resources\\stacks"
 
     self.DEFAULT_VIEWS_DIR = "resources\\views"
@@ -322,6 +323,7 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults):
     self.NR_USERADD_CMD = 'useradd -M --comment "{1}" ' \
                  '--shell %s -d /var/lib/ambari-server/keys/ {0}' % locate_file('nologin',
'/sbin')
 
+    self.SERVER_RESOURCES_DIR = "/var/lib/ambari-server/resources"
     self.STACK_LOCATION_DEFAULT = "/var/lib/ambari-server/resources/stacks"
 
     self.DEFAULT_VIEWS_DIR = "/var/lib/ambari-server/resources/views"

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/main/python/ambari_server/serverSetup.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py b/ambari-server/src/main/python/ambari_server/serverSetup.py
index 13a1311..e928700 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -30,7 +30,7 @@ from ambari_commons.inet_utils import force_download_file
 from ambari_commons.logging_utils import get_silent, print_info_msg, print_warning_msg, print_error_msg
 from ambari_commons.os_check import OSConst
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
-from ambari_commons.os_utils import run_os_command, is_root
+from ambari_commons.os_utils import copy_files, run_os_command, is_root
 from ambari_commons.str_utils import compress_backslashes
 from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers
 from ambari_server.serverConfiguration import configDefaults, JDKRelease, \
@@ -72,8 +72,6 @@ JDK_PROMPT = "[{0}] {1}\n"
 JDK_CUSTOM_CHOICE_PROMPT = "[{0}] - Custom JDK\n==============================================================================\nEnter
choice ({1}): "
 JDK_VALID_CHOICES = "^[{0}{1:d}]$"
 
-IS_CUSTOM_JDK = False
-
 def get_supported_jdbc_drivers():
   factory = DBMSConfigFactory()
   return factory.get_supported_jdbc_drivers()
@@ -327,19 +325,14 @@ class JDKSetup(object):
   #
   # Downloads and installs the JDK and the JCE policy archive
   #
-  def download_and_install_jdk(self, args):
-    global IS_CUSTOM_JDK
-    properties = get_ambari_properties()
-    if properties == -1:
-      err = "Error getting ambari properties"
-      raise FatalException(-1, err)
-
+  def download_and_install_jdk(self, args, properties):
     conf_file = properties.fileName
-    ok = False
+
     jcePolicyWarn = "JCE Policy files are required for configuring Kerberos security. If
you plan to use Kerberos," \
                     "please make sure JCE Unlimited Strength Jurisdiction Policy Files are
valid on all hosts."
 
     if args.java_home:
+      #java_home was specified among the command-line arguments. Use it as custom JDK location.
       if not validate_jdk(args.java_home):
         err = "Path to java home " + args.java_home + " or java binary file does not exists"
         raise FatalException(1, err)
@@ -351,10 +344,10 @@ class JDKSetup(object):
       properties.process_pair(JAVA_HOME_PROPERTY, args.java_home)
       properties.removeOldProp(JDK_NAME_PROPERTY)
       properties.removeOldProp(JCE_NAME_PROPERTY)
-      update_properties(properties)
 
       self._ensure_java_home_env_var_is_set(args.java_home)
-      return 0
+      self.jdk_index = self.custom_jdk_number
+      return
 
     java_home_var = get_JAVA_HOME()
 
@@ -367,10 +360,10 @@ class JDKSetup(object):
           properties.process_pair(JAVA_HOME_PROPERTY, args.java_home)
           properties.removeOldProp(JDK_NAME_PROPERTY)
           properties.removeOldProp(JCE_NAME_PROPERTY)
-          update_properties(properties)
 
           self._ensure_java_home_env_var_is_set(args.java_home)
-          return 0
+          self.jdk_index = self.custom_jdk_number
+          return
         else:
           # For now, changing the existing JDK to make sure we use a supported one
           pass
@@ -379,11 +372,12 @@ class JDKSetup(object):
       change_jdk = get_YN_input("Do you want to change Oracle JDK [y/n] (n)? ", False)
       if not change_jdk:
         self._ensure_java_home_env_var_is_set(java_home_var)
-        return 0
+        self.jdk_index = self.custom_jdk_number
+        return
 
     #Continue with the normal setup, taking the first listed JDK version as the default option
     jdk_num = str(self.jdk_index + 1)
-    (jdks, jdk_choice_prompt, jdk_valid_choices, custom_jdk_number) = self._populate_jdk_configs(properties,
jdk_num)
+    (self.jdks, jdk_choice_prompt, jdk_valid_choices, self.custom_jdk_number) = self._populate_jdk_configs(properties,
jdk_num)
 
     jdk_num = get_validated_string_input(
       jdk_choice_prompt,
@@ -393,8 +387,9 @@ class JDKSetup(object):
       False
     )
 
-    if jdk_num == str(custom_jdk_number):
-      IS_CUSTOM_JDK = True
+    self.jdk_index = int(jdk_num) - 1
+
+    if self.jdk_index == self.custom_jdk_number:
       print_warning_msg("JDK must be installed on all hosts and JAVA_HOME must be valid on
all hosts.")
       print_warning_msg(jcePolicyWarn)
       args.java_home = get_validated_string_input("Path to JAVA_HOME: ", None, None, None,
False, False)
@@ -406,13 +401,11 @@ class JDKSetup(object):
       properties.process_pair(JAVA_HOME_PROPERTY, args.java_home)
       properties.removeOldProp(JDK_NAME_PROPERTY)
       properties.removeOldProp(JCE_NAME_PROPERTY)
-      update_properties(properties)
 
       self._ensure_java_home_env_var_is_set(args.java_home)
-      return 0
+      return
 
-    self.jdk_index = int(jdk_num) - 1
-    jdk_cfg = jdks[self.jdk_index]
+    jdk_cfg = self.jdks[self.jdk_index]
 
     try:
       resources_dir = properties[RESOURCES_DIR_PROPERTY]
@@ -476,21 +469,47 @@ class JDKSetup(object):
     properties.process_pair(JDK_NAME_PROPERTY, jdk_cfg.dest_file)
     properties.process_pair(JAVA_HOME_PROPERTY, java_home_dir)
 
+    self._ensure_java_home_env_var_is_set(java_home_dir)
+
+  def download_and_unpack_jce_policy(self, properties):
+    conf_file = properties.fileName
+
+    err_msg_stdout = "JCE Policy files are required for secure HDP setup. Please ensure "
\
+              " all hosts have the JCE unlimited strength policy 6, files."
+
+    try:
+      resources_dir = properties[RESOURCES_DIR_PROPERTY]
+    except (KeyError), e:
+      err = 'Property ' + str(e) + ' is not defined at ' + conf_file
+      raise FatalException(1, err)
+
+    jdk_cfg = self.jdks[self.jdk_index]
+
     try:
-      self._download_jce_policy(jdk_cfg, resources_dir, properties)
+      JDKSetup._download_jce_policy(jdk_cfg.jcpol_url, jdk_cfg.dest_jcpol_file, resources_dir,
properties)
     except FatalException, e:
-      print "JCE Policy files are required for secure HDP setup. Please ensure " \
-            " all hosts have the JCE unlimited strength policy 6, files."
+      print err_msg_stdout
       print_error_msg("Failed to download JCE policy files:")
       if e.reason is not None:
         print_error_msg("\nREASON: {0}".format(e.reason))
         # TODO: We don't fail installation if _download_jce_policy fails. Is it OK?
 
-    update_properties(properties)
+    print 'Installing JCE policy...'
+    try:
+      JDKSetup.unpack_jce_policy(jdk_cfg.inst_dir, resources_dir, jdk_cfg.dest_jcpol_file)
+    except FatalException, e:
+      print err_msg_stdout
+      print_error_msg("Failed to install JCE policy files:")
+      if e.reason is not None:
+        print_error_msg("\nREASON: {0}".format(e.reason))
+        # TODO: We don't fail installation if _download_jce_policy fails. Is it OK?
 
-    self._ensure_java_home_env_var_is_set(java_home_dir)
+  @staticmethod
+  def unpack_jce_policy(jdk_path, resources_dir, jce_packed_file):
+    jdk_security_path = os.path.abspath(os.path.join(jdk_path, configDefaults.JDK_SECURITY_DIR))
 
-    return 0
+    jce_zip_path = os.path.abspath(os.path.join(resources_dir, jce_packed_file))
+    expand_jce_zip_file(jce_zip_path, jdk_security_path)
 
   def _populate_jdk_configs(self, properties, jdk_num):
     if properties.has_key(JDK_RELEASES):
@@ -513,7 +532,7 @@ class JDKSetup(object):
     jdk_choice_prompt += self.JDK_CUSTOM_CHOICE_PROMPT.format(n_config, jdk_num)
     jdk_valid_choices = self.JDK_VALID_CHOICES.format(jdk_choices, n_config)
 
-    return (jdks, jdk_choice_prompt, jdk_valid_choices, n_config)
+    return (jdks, jdk_choice_prompt, jdk_valid_choices, n_config - 1)
 
   def _download_jdk(self, jdk_url, dest_file):
     jdk_download_fail_msg = " Failed to download JDK: {0}. Please check that the " \
@@ -530,9 +549,9 @@ class JDKSetup(object):
       err = jdk_download_fail_msg.format(str(e))
       raise FatalException(1, err)
 
-  def _download_jce_policy(self, jdk_cfg, resources_dir, properties):
-    jcpol_url = jdk_cfg.jcpol_url
-    dest_file = os.path.abspath(os.path.join(resources_dir, jdk_cfg.dest_jcpol_file))
+  @staticmethod
+  def _download_jce_policy(jcpol_url, dest_jcpol_file, resources_dir, properties):
+    dest_file = os.path.abspath(os.path.join(resources_dir, dest_jcpol_file))
 
     if not os.path.exists(dest_file):
       print 'Downloading JCE Policy archive from ' + jcpol_url + ' to ' + dest_file
@@ -540,7 +559,6 @@ class JDKSetup(object):
         force_download_file(jcpol_url, dest_file)
 
         print 'Successfully downloaded JCE Policy archive to ' + dest_file
-        properties.process_pair(JCE_NAME_PROPERTY, jdk_cfg.dest_jcpol_file)
       except FatalException:
         raise
       except Exception, e:
@@ -549,6 +567,8 @@ class JDKSetup(object):
     else:
       print "JCE Policy archive already exists, using " + dest_file
 
+    properties.process_pair(JCE_NAME_PROPERTY, dest_jcpol_file)
+
   # Base implementation, overriden in the subclasses
   def _install_jdk(self, java_inst_file, java_home_dir):
     pass
@@ -569,6 +589,9 @@ class JDKSetupWindows(JDKSetup):
                  "Creating (jdk.*)/jre")
     ]
 
+    self.jdks = self.JDK_DEFAULT_CONFIGS
+    self.custom_jdk_number = len(self.jdks)
+
     self.JAVA_BIN = "java.exe"
 
   def _install_jdk(self, java_inst_file, jdk_cfg):
@@ -637,6 +660,9 @@ class JDKSetupLinux(JDKSetup):
                  "Creating (jdk.*)/jre")
     ]
 
+    self.jdks = self.JDK_DEFAULT_CONFIGS
+    self.custom_jdk_number = len(self.jdks)
+
     self.JAVA_BIN = "java"
 
     self.CREATE_JDK_DIR_CMD = "/bin/mkdir -p {0}"
@@ -680,7 +706,20 @@ class JDKSetupLinux(JDKSetup):
     os.environ[JAVA_HOME] = java_home_dir
 
 def download_and_install_jdk(options):
-  return JDKSetup().download_and_install_jdk(options)
+  properties = get_ambari_properties()
+  if properties == -1:
+    err = "Error getting ambari properties"
+    raise FatalException(-1, err)
+
+  jdkSetup = JDKSetup()
+  jdkSetup.download_and_install_jdk(options, properties)
+
+  if jdkSetup.jdk_index != jdkSetup.custom_jdk_number:
+    jdkSetup.download_and_unpack_jce_policy(properties)
+
+  update_properties(properties)
+
+  return 0
 
 
 #
@@ -873,16 +912,10 @@ def extract_views():
   return 0
 
 
-def unpack_jce_policy():
-  properties = get_ambari_properties()
-  jdk_path = properties.get_property(JAVA_HOME_PROPERTY)
-  jdk_security_path = jdk_path + os.sep + configDefaults.JDK_SECURITY_DIR
-
-  jce_name = properties.get_property(JCE_NAME_PROPERTY)
-  jce_zip_path = configDefaults.SERVER_RESOURCES_DIR + os.sep + jce_name
+def expand_jce_zip_file(jce_zip_path, jdk_security_path):
   f = None
-
   import zipfile
+
   if os.path.exists(jdk_security_path) and os.path.exists(jce_zip_path):
     try:
       f = zipfile.ZipFile(jce_zip_path, "r")
@@ -904,15 +937,15 @@ def unpack_jce_policy():
     raise FatalException(1, err)
 
   if unziped_jce_path:
-    from_path = jdk_security_path + os.sep + unziped_jce_path
+    from_path = os.path.join(jdk_security_path, unziped_jce_path)
     jce_files = os.listdir(from_path)
     for i in range(len(jce_files)):
-      jce_files[i] = from_path + os.sep + jce_files[i]
-    from ambari_commons.os_utils import copy_files
+      jce_files[i] = os.path.join(from_path, jce_files[i])
+
     copy_files(jce_files, jdk_security_path)
-    dir_to_delete = jdk_security_path + os.sep + unziped_jce_path.split(os.sep)[0]
+    dir_to_delete = os.path.join(jdk_security_path, unziped_jce_path.split(os.sep)[0])
     shutil.rmtree(dir_to_delete)
-  return 0
+
 
 #
 # Setup the Ambari Server.
@@ -955,14 +988,6 @@ def setup(options):
     err = 'Downloading or installing JDK failed: {0}. Exiting.'.format(e)
     raise FatalException(e.code, err)
 
-  if not IS_CUSTOM_JDK: # If it's not a custom JDK, will also install JCE policy automatically
-    print 'Installing JCE policy...'
-    try:
-      unpack_jce_policy()
-    except FatalException as e:
-      err = 'Installing JCE failed: {0}. Exiting.'.format(e)
-      raise FatalException(e.code, err)
-
   print 'Completing setup...'
   retcode = configure_os_settings()
   if not retcode == 0:
@@ -1003,23 +1028,22 @@ def setup_jce_policy(args):
     err = "Can not run 'setup-jce'. Invalid path {0}.".format(args[1])
     raise FatalException(1, err)
 
-  from ambari_commons.os_utils import search_file
-  from ambari_server.serverConfiguration import AMBARI_PROPERTIES_FILE, get_conf_dir
-  conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
   properties = get_ambari_properties()
+  jdk_path = properties.get_property(JAVA_HOME_PROPERTY)
+  resources_dir = properties.get_property(RESOURCES_DIR_PROPERTY)
+
   zip_name = os.path.split(args[1])[1]
   properties.process_pair(JCE_NAME_PROPERTY, zip_name)
-  try:
-    properties.store(open(conf_file, "w"))
-  except Exception, e:
-    print_error_msg('Could not write ambari config file "%s": %s' % (conf_file, e))
 
   print 'Installing JCE policy...'
   try:
-    unpack_jce_policy()
+    JDKSetup.unpack_jce_policy(jdk_path, resources_dir, zip_name)
   except FatalException as e:
     err = 'Installing JCE failed: {0}. Exiting.'.format(e)
     raise FatalException(e.code, err)
+
+  update_properties(properties)
+
   print 'NOTE: Restart Ambari Server to apply changes' + \
         ' ("ambari-server restart|stop|start")'
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/314ae0b1/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 2971593..fac6637 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -76,7 +76,7 @@ with patch("platform.linux_distribution", return_value = os_distro_value):
         from ambari_server.serverUtils import is_server_runing, refresh_stack_hash
         from ambari_server.serverSetup import check_selinux, check_ambari_user, proceedJDBCProperties,
SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \
           download_and_install_jdk, prompt_db_properties, setup, \
-          AmbariUserChecks, AmbariUserChecksLinux, AmbariUserChecksWindows, JDKSetup, reset,
setup_jce_policy, unpack_jce_policy
+          AmbariUserChecks, AmbariUserChecksLinux, AmbariUserChecksWindows, JDKSetup, reset,
setup_jce_policy, expand_jce_zip_file
         from ambari_server.serverUpgrade import upgrade, upgrade_local_repo, change_objects_owner,
upgrade_stack, \
           run_stack_upgrade, run_metainfo_upgrade, run_schema_upgrade, move_user_custom_actions
         from ambari_server.setupHttps import is_valid_https_port, setup_https, import_cert_and_key_action,
get_fqdn, \
@@ -2028,6 +2028,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("os.path.isfile")
   @patch("os.path.exists")
   @patch("os.chdir")
+  @patch("ambari_server.serverSetup.expand_jce_zip_file")
   @patch("ambari_server.serverSetup.force_download_file")
   @patch("ambari_server.serverSetup.get_YN_input")
   @patch("ambari_server.serverSetup.run_os_command")
@@ -2041,7 +2042,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("sys.exit")
   def test_download_jdk(self, exit_mock, copyfile_mock, get_ambari_properties_mock, get_JAVA_HOME_mock,
\
                         validate_jdk_mock, print_info_msg_mock, get_validated_string_input_mock,
update_properties_mock, \
-                        run_os_command_mock, get_YN_input_mock, force_download_file_mock,
+                        run_os_command_mock, get_YN_input_mock, force_download_file_mock,
expand_jce_zip_file_mock,
                         os_chdir_mock, path_existsMock, path_isfileMock, statMock):
     args = MagicMock()
     args.java_home = "somewhere"
@@ -2659,18 +2660,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     pass
 
 
-  @patch("ambari_server.serverSetup.get_ambari_properties")
   @patch("os.path.exists")
   @patch("zipfile.ZipFile")
   @patch("os.path.split")
   @patch("os.listdir")
-  @patch("ambari_commons.os_utils.copy_files")
+  @patch("ambari_server.serverSetup.copy_files")
   @patch("shutil.rmtree")
-  def test_unpack_jce_policy(self, rmtree_mock, copy_files_mock, os_listdir_mock, os_path_split_mock,
zipfile_mock, exists_mock, get_ambari_properties_mock):
+  def test_unpack_jce_policy(self, rmtree_mock, copy_files_mock, os_listdir_mock, os_path_split_mock,
zipfile_mock, exists_mock):
 
     # Testing the case when the zip file doesn't contains any folder
-    properties = MagicMock()
-    get_ambari_properties_mock.return_value = properties
     exists_mock.return_value = True
     zipfile = MagicMock()
     zipfile_mock.return_value = zipfile
@@ -2678,8 +2676,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     zipfile.namelist.return_value = zip_members
     os_path_split_mock.return_value = [""]
 
-    unpack_jce_policy()
-    self.assertTrue(get_ambari_properties_mock.called)
+    expand_jce_zip_file("", "")
     self.assertTrue(exists_mock.called)
     self.assertTrue(zipfile_mock.called)
     self.assertTrue(os_path_split_mock.called)
@@ -2688,8 +2685,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     unziped_jce_path = "jce"
     os_path_split_mock.return_value = unziped_jce_path
 
-    unpack_jce_policy()
-    self.assertTrue(get_ambari_properties_mock.called)
+    expand_jce_zip_file("", "")
     self.assertTrue(exists_mock.called)
     self.assertTrue(zipfile_mock.called)
     self.assertTrue(os_listdir_mock.called)
@@ -2699,7 +2695,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     # Testing when the jdk_security_path or jce_zip_path doesn't exist
     exists_mock.return_value = False
     try:
-      unpack_jce_policy()
+      expand_jce_zip_file("", "")
     except FatalException:
       self.assertTrue(True)
     exists_mock.return_value = True
@@ -2707,19 +2703,21 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     # Testing when zipfile fail with an error
     zipfile_mock.side_effect = FatalException(1,"Extract error")
     try:
-      unpack_jce_policy()
+      expand_jce_zip_file("", "")
     except FatalException:
       self.assertTrue(True)
 
 
   @patch("os.path.exists")
   @patch("shutil.copy")
-  @patch("ambari_server.serverSetup.os.path.split")
-  @patch("ambari_server.serverSetup.unpack_jce_policy")
+  @patch("os.path.split")
+  @patch("ambari_server.serverSetup.update_properties")
+  @patch.object(JDKSetup, "unpack_jce_policy")
   @patch("ambari_server.serverSetup.get_ambari_properties")
   @patch("ambari_commons.os_utils.search_file")
   @patch("__builtin__.open")
-  def test_setup_jce_policy(self, open_mock, search_file_mock, get_ambari_properties_mock,
unpack_jce_policy_mock, path_split_mock, shutil_copy_mock, exists_mock):
+  def test_setup_jce_policy(self, open_mock, search_file_mock, get_ambari_properties_mock,
unpack_jce_policy_mock,
+                            update_properties_mock, path_split_mock, shutil_copy_mock, exists_mock):
     exists_mock.return_value = True
     properties = MagicMock()
     unpack_jce_policy_mock.return_value = 0
@@ -2733,7 +2731,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     shutil_copy_mock.assert_called_with(args[1], configDefaults.SERVER_RESOURCES_DIR)
     self.assertTrue(unpack_jce_policy_mock.called)
     self.assertTrue(get_ambari_properties_mock.called)
-    self.assertTrue(properties.store.called)
+    self.assertTrue(update_properties_mock.called)
 
     # Testing that if the source and the destination is the same will not try to copy the
file
     path_split_mock.return_value = [configDefaults.SERVER_RESOURCES_DIR, "JCEPolicy.zip"]
@@ -2743,7 +2741,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertFalse(shutil_copy_mock.called)
     self.assertTrue(unpack_jce_policy_mock.called)
     self.assertTrue(get_ambari_properties_mock.called)
-    self.assertTrue(properties.store.called)
+    self.assertTrue(update_properties_mock.called)
     path_split_mock.return_value = ["/path/to", "JCEPolicy.zip"]
 
     # Testing with bad path
@@ -2763,12 +2761,12 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       self.assertTrue(True)
 
     # Testing with an error produced by Properties.store function
-    properties.store.side_effect = Exception("Invalid file.")
+    update_properties_mock.side_effect = Exception("Invalid file.")
     try:
       setup_jce_policy(args)
     except Exception:
       self.assertTrue(True)
-    properties.reset_mock()
+    update_properties_mock.reset_mock()
 
     # Testing with an error produced by unpack_jce_policy
     unpack_jce_policy_mock.side_effect = FatalException(1, "Can not install JCE policy")
@@ -2807,8 +2805,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverSetup.extract_views")
   @patch("ambari_server.serverSetup.adjust_directory_permissions")
   @patch("ambari_server.serverSetup.read_ambari_user")
-  @patch("ambari_server.serverSetup.unpack_jce_policy")
-  def test_setup(self, unpack_jce_policy_mock, read_ambari_user_mock, adjust_dirs_mock, extract_views_mock,
proceedJDBCProperties_mock, is_root_mock,
+  @patch("ambari_server.serverSetup.expand_jce_zip_file")
+  def test_setup(self, expand_jce_zip_file_mock, read_ambari_user_mock, adjust_dirs_mock,
extract_views_mock, proceedJDBCProperties_mock, is_root_mock,
                  disable_security_enhancements_mock, check_jdbc_drivers_mock, check_ambari_user_mock,
                  download_jdk_mock, configure_os_settings_mock, get_ambari_properties_mock,
                  get_YN_input_mock, gvsi_mock, gvsi_1_mock,
@@ -2857,7 +2855,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     check_postgre_up_mock.return_value = (PGConfig.PG_STATUS_RUNNING, 0, "", "")
     configure_postgres_mock.return_value = (0, "", "")
     run_os_command_1_mock.return_value = (0, "", "")
-    unpack_jce_policy_mock.return_value = 0
+    expand_jce_zip_file_mock.return_value = 0
 
     def reset_mocks():
       is_jdbc_user_changed_mock.reset_mock()
@@ -4635,8 +4633,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverSetup.configure_os_settings")
   @patch('__builtin__.raw_input')
   @patch("ambari_server.serverSetup.disable_security_enhancements")
-  @patch("ambari_server.serverSetup.unpack_jce_policy")
-  def test_setup_remote_db_wo_client(self, unpack_jce_policy_mock, check_selinux_mock, raw_input,
configure_os_settings_mock,
+  @patch("ambari_server.serverSetup.expand_jce_zip_file")
+  def test_setup_remote_db_wo_client(self, expand_jce_zip_file_mock, check_selinux_mock,
raw_input, configure_os_settings_mock,
                                      download_jdk_mock, check_ambari_user_mock, is_root_mock,
check_jdbc_drivers_mock,
                                      read_password_mock, ensure_jdbc_driver_installed_mock,
store_remote_properties_mock,
                                      get_validated_string_input_0_mock, get_YN_input_0_mock,
@@ -4674,7 +4672,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0
     verify_setup_allowed_method.return_value = 0
-    unpack_jce_policy_mock.return_value = 0
+    expand_jce_zip_file_mock.return_value = 0
 
     try:
       setup(args)
@@ -6186,8 +6184,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverSetup.adjust_directory_permissions")
   @patch("sys.exit")
   @patch("__builtin__.raw_input")
-  @patch("ambari_server.serverSetup.unpack_jce_policy")
-  def test_ambariServerSetupWithCustomDbName(self, unpack_jce_policy_mock, raw_input, exit_mock,
adjust_dirs_mock, extract_views_mock, store_password_file_mock,
+  @patch("ambari_server.serverSetup.expand_jce_zip_file")
+  def test_ambariServerSetupWithCustomDbName(self, expand_jce_zip_file_mock, raw_input, exit_mock,
adjust_dirs_mock,
+                                             extract_views_mock, store_password_file_mock,
                                              get_is_secure_mock, setup_db_mock, is_root_mock,
#is_local_database_mock,
                                              check_selinux_mock, check_jdbc_drivers_mock,
check_ambari_user_mock,
                                              check_postgre_up_mock, configure_postgres_mock,


Mime
View raw message