You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ds...@apache.org on 2015/10/08 19:22:07 UTC

ambari git commit: AMBARI-13283 Class not found exception while running step "ambari-server upgradestack HDP-2.3" for upgrade path 2.2 -> 2.3.2 Amabri DB is Oracle (dsen)

Repository: ambari
Updated Branches:
  refs/heads/trunk 588d43138 -> 7bb91551e


AMBARI-13283 Class not found exception while running step "ambari-server upgradestack HDP-2.3" for upgrade path 2.2 -> 2.3.2 Amabri DB is Oracle (dsen)


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

Branch: refs/heads/trunk
Commit: 7bb91551e772756c4ffcc12a79114aa074145130
Parents: 588d431
Author: Dmytro Sen <ds...@apache.org>
Authored: Thu Oct 8 20:21:54 2015 +0300
Committer: Dmytro Sen <ds...@apache.org>
Committed: Thu Oct 8 20:21:54 2015 +0300

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  |   4 +-
 .../python/ambari_server/serverClassPath.py     | 115 +++++++++++++++++++
 .../python/ambari_server/serverConfiguration.py |  42 +------
 .../main/python/ambari_server/serverSetup.py    |  10 +-
 .../main/python/ambari_server/serverUpgrade.py  |  27 ++---
 .../main/python/ambari_server/setupSecurity.py  |  18 +--
 .../src/main/python/ambari_server_main.py       |  28 +----
 .../src/test/python/TestAmbariServer.py         |  73 +++++-------
 .../src/test/python/TestServerClassPath.py      |  89 ++++++++++++++
 9 files changed, 274 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/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 7d46f69..7e07497 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -189,7 +189,7 @@ def refresh_stack_hash_action():
 def create_setup_security_actions(args):
   action_list = [
       ['Enable HTTPS for Ambari server.', UserActionRestart(setup_https, args)],
-      ['Encrypt passwords stored in ambari.properties file.', UserAction(setup_master_key)],
+      ['Encrypt passwords stored in ambari.properties file.', UserAction(setup_master_key, args)],
       ['Setup Ambari kerberos JAAS configuration.', UserAction(setup_ambari_krb5_jaas)],
       ['Setup truststore.', UserActionRestart(setup_truststore)],
       ['Import certificate to truststore.', UserActionRestart(setup_truststore, True)],
@@ -200,7 +200,7 @@ def create_setup_security_actions(args):
 def create_setup_security_actions(args):
   action_list = [
       ['Enable HTTPS for Ambari server.', UserActionRestart(setup_https, args)],
-      ['Encrypt passwords stored in ambari.properties file.', UserAction(setup_master_key)],
+      ['Encrypt passwords stored in ambari.properties file.', UserAction(setup_master_key, args)],
       ['Setup Ambari kerberos JAAS configuration.', UserAction(setup_ambari_krb5_jaas)],
       ['Setup truststore.', UserActionRestart(setup_truststore)],
       ['Import certificate to truststore.', UserActionRestart(setup_truststore, True)],

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/ambari-server/src/main/python/ambari_server/serverClassPath.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverClassPath.py b/ambari-server/src/main/python/ambari_server/serverClassPath.py
new file mode 100644
index 0000000..d3ade3e
--- /dev/null
+++ b/ambari-server/src/main/python/ambari_server/serverClassPath.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+import datetime
+import glob
+import os
+import re
+import shutil
+import stat
+import string
+import sys
+import tempfile
+
+import ambari_server
+from ambari_commons.logging_utils import print_info_msg
+from resource_management.core.shell import quote_bash_args
+AMBARI_CONF_VAR = "AMBARI_CONF_DIR"
+SERVER_CLASSPATH_KEY = "SERVER_CLASSPATH"
+LIBRARY_PATH_KEY = "LD_LIBRARY_PATH"
+AMBARI_SERVER_LIB = "AMBARI_SERVER_LIB"
+JDBC_DRIVER_PATH_PROPERTY = "server.jdbc.driver.path"
+
+
+
+class ServerClassPath():
+
+  properties = None
+  options = None
+  configDefaults = None
+
+
+  def __init__(self, properties, options):
+    self.properties = properties
+    self.options = options
+    self.configDefaults = ambari_server.serverConfiguration.ServerConfigDefaults()
+
+
+  def _get_ambari_jars(self):
+    try:
+      conf_dir = os.environ[AMBARI_SERVER_LIB]
+      return conf_dir
+    except KeyError:
+      default_jar_location = self.configDefaults.DEFAULT_LIBS_DIR
+      print_info_msg(AMBARI_SERVER_LIB + " is not set, using default "
+                     + default_jar_location)
+      return default_jar_location
+
+  def _get_jdbc_cp(self):
+    jdbc_jar_path = ""
+    if self.properties != -1:
+      jdbc_jar_path = self.properties[JDBC_DRIVER_PATH_PROPERTY]
+    return jdbc_jar_path
+
+  def _get_ambari_classpath(self):
+    ambari_class_path = os.path.abspath(self._get_ambari_jars() + os.sep + "*")
+
+    # Add classpath from server.jdbc.driver.path property
+    jdbc_cp = self._get_jdbc_cp()
+    if len(jdbc_cp) > 0:
+      ambari_class_path = ambari_class_path + os.pathsep + jdbc_cp
+
+    # Add classpath from environment (SERVER_CLASSPATH)
+    if SERVER_CLASSPATH_KEY in os.environ:
+      ambari_class_path =  os.environ[SERVER_CLASSPATH_KEY] + os.pathsep + ambari_class_path
+
+    # Add jdbc driver classpath
+    if self.options:
+      jdbc_driver_path = ambari_server.dbConfiguration.get_jdbc_driver_path(self.options, self.properties)
+      if jdbc_driver_path not in ambari_class_path:
+        ambari_class_path = ambari_class_path + os.pathsep + jdbc_driver_path
+
+    # Add conf_dir to class_path
+    conf_dir = ambari_server.serverConfiguration.get_conf_dir()
+    ambari_class_path = conf_dir + os.pathsep + ambari_class_path
+
+    return ambari_class_path
+
+  def get_full_ambari_classpath_escaped_for_shell(self):
+    class_path = self._get_ambari_classpath()
+
+    # When classpath is required we should also set native libs os env variable
+    # This is required for some jdbc (ex. sqlAnywhere)
+    self.set_native_libs_path()
+
+    return quote_bash_args(class_path)
+
+
+  #
+  # Set native libs os env
+  #
+  def set_native_libs_path(self):
+    if self.options:
+      native_libs_path = ambari_server.dbConfiguration.get_native_libs_path(self.options, self.properties)
+      if native_libs_path is not None:
+        if LIBRARY_PATH_KEY in os.environ:
+          native_libs_path = os.environ[LIBRARY_PATH_KEY] + os.pathsep + native_libs_path
+        os.environ[LIBRARY_PATH_KEY] = native_libs_path
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/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 bc9823c..7435a39 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -27,6 +27,7 @@ import stat
 import string
 import sys
 import tempfile
+import ambari_server.serverClassPath
 
 from ambari_commons.exceptions import FatalException
 from ambari_commons.os_check import OSCheck, OSConst
@@ -83,8 +84,6 @@ JCE_NAME_PROPERTY = "jce.name"
 JDK_DOWNLOAD_SUPPORTED_PROPERTY = "jdk.download.supported"
 JCE_DOWNLOAD_SUPPORTED_PROPERTY = "jce.download.supported"
 
-# JDBC
-JDBC_PATTERNS = {"oracle": "*ojdbc*.jar", "mysql": "*mysql*.jar", "mssql": "*sqljdbc*.jar"}
 
 #TODO property used incorrectly in local case, it was meant to be dbms name, not postgres database name,
 # has workaround for now, as we don't need dbms name if persistence_type=local
@@ -107,7 +106,6 @@ SERVER_VERSION_FILE_PATH = "server.version.file"
 
 PERSISTENCE_TYPE_PROPERTY = "server.persistence.type"
 JDBC_DRIVER_PROPERTY = "server.jdbc.driver"
-JDBC_DRIVER_PATH_PROPERTY = "server.jdbc.driver.path"
 JDBC_URL_PROPERTY = "server.jdbc.url"
 
 # connection pool (age and time are in seconds)
@@ -777,8 +775,9 @@ def read_passwd_for_alias(alias, masterKey=""):
     if masterKey is None or masterKey == "":
       masterKey = "None"
 
+    serverClassPath = ambari_server.serverClassPath.ServerClassPath(get_ambari_properties(), None)
     command = SECURITY_PROVIDER_GET_CMD.format(get_java_exe_path(),
-                                               get_full_ambari_classpath(), alias, tempFilePath, masterKey)
+                                               serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, tempFilePath, masterKey)
     (retcode, stdout, stderr) = run_os_command(command)
     print_info_msg("Return code from credential provider get passwd: " +
                    str(retcode))
@@ -818,8 +817,9 @@ def save_passwd_for_alias(alias, passwd, masterKey=""):
     if masterKey is None or masterKey == "":
       masterKey = "None"
 
+    serverClassPath = ambari_server.serverClassPath.ServerClassPath(get_ambari_properties(), None)
     command = SECURITY_PROVIDER_PUT_CMD.format(get_java_exe_path(),
-                                               get_full_ambari_classpath(), alias, passwd, masterKey)
+                                               serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, passwd, masterKey)
     (retcode, stdout, stderr) = run_os_command(command)
     print_info_msg("Return code from credential provider save passwd: " +
                    str(retcode))
@@ -1217,38 +1217,6 @@ class JDKRelease:
     return (desc, url, dest_file, jcpol_url, jcpol_file, inst_dir, reg_exp)
   pass
 
-def get_ambari_jars():
-  try:
-    conf_dir = os.environ[AMBARI_SERVER_LIB]
-    return conf_dir
-  except KeyError:
-    default_jar_location = configDefaults.DEFAULT_LIBS_DIR
-    print_info_msg(AMBARI_SERVER_LIB + " is not set, using default "
-                 + default_jar_location)
-    return default_jar_location
-
-def get_jdbc_cp():
-  jdbc_jar_path = ""
-  properties = get_ambari_properties()
-  if properties != -1:
-    jdbc_jar_path = properties[JDBC_DRIVER_PATH_PROPERTY]
-  return jdbc_jar_path
-
-def get_ambari_classpath():
-  ambari_cp = os.path.abspath(get_ambari_jars() + os.sep + "*")
-  jdbc_cp = get_jdbc_cp()
-  if len(jdbc_cp) > 0:
-    ambari_cp = ambari_cp + os.pathsep + jdbc_cp
-  return ambari_cp
-
-def get_full_ambari_classpath(conf_dir = None):
-  if conf_dir is None:
-    conf_dir = get_conf_dir()
-  cp = conf_dir + os.pathsep + get_ambari_classpath()
-  if cp.find(' ') != -1:
-    cp = '"' + cp + '"'
-  return cp
-
 def get_JAVA_HOME():
   properties = get_ambari_properties()
   if properties == -1:

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/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 b3e6e21..558a3ee 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -35,7 +35,7 @@ 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, \
-  get_ambari_properties, get_full_ambari_classpath, get_is_secure, get_is_persisted, get_java_exe_path, get_JAVA_HOME, \
+  get_ambari_properties, get_is_secure, get_is_persisted, get_java_exe_path, get_JAVA_HOME, \
   get_resources_location, get_value_from_properties, read_ambari_user, update_properties, validate_jdk, write_property, \
   JAVA_HOME, JAVA_HOME_PROPERTY, JCE_NAME_PROPERTY, JDBC_RCA_URL_PROPERTY, JDBC_URL_PROPERTY, \
   JDK_NAME_PROPERTY, JDK_RELEASES, NR_USER_PROPERTY, OS_FAMILY, OS_FAMILY_PROPERTY, OS_TYPE, OS_TYPE_PROPERTY, OS_VERSION, \
@@ -44,6 +44,7 @@ from ambari_server.serverUtils import is_server_runing
 from ambari_server.setupSecurity import adjust_directory_permissions
 from ambari_server.userInput import get_YN_input, get_validated_string_input
 from ambari_server.utils import locate_file
+from ambari_server.serverClassPath import ServerClassPath
 
 
 # selinux commands
@@ -988,7 +989,7 @@ def _reset_database(options):
 #
 # Extract the system views
 #
-def extract_views():
+def extract_views(options):
   java_exe_path = get_java_exe_path()
   if java_exe_path is None:
     print_error_msg("No JDK found, please run the \"setup\" "
@@ -1004,9 +1005,10 @@ def extract_views():
   vdir = get_value_from_properties(properties, VIEWS_DIR_PROPERTY, configDefaults.DEFAULT_VIEWS_DIR)
 
   files = [f for f in os.listdir(vdir) if os.path.isfile(os.path.join(vdir,f))]
+  serverClassPath = ServerClassPath(get_ambari_properties(), options)
   for f in files:
     command = VIEW_EXTRACT_CMD.format(java_exe_path,
-                                      get_full_ambari_classpath(), os.path.join(vdir,f))
+                                      serverClassPath.get_full_ambari_classpath_escaped_for_shell(), os.path.join(vdir,f))
     retcode, stdout, stderr = run_os_command(command)
     if retcode == 0:
       sys.stdout.write(f + "\n")
@@ -1128,7 +1130,7 @@ def setup(options):
   check_jdbc_drivers(options)
 
   print 'Extracting system views...'
-  retcode = extract_views()
+  retcode = extract_views(options)
   if not retcode == 0:
     err = 'Error while extracting system views. Exiting'
     raise FatalException(retcode, err)

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/ambari-server/src/main/python/ambari_server/serverUpgrade.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverUpgrade.py b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
index 3545b65..7048812 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -34,9 +34,9 @@ from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers,
   get_jdbc_driver_path, ensure_jdbc_driver_is_installed
 from ambari_server.properties import Properties
 from ambari_server.serverConfiguration import configDefaults, \
-  check_database_name_property, get_ambari_properties, get_ambari_version, get_full_ambari_classpath, \
+  check_database_name_property, get_ambari_properties, get_ambari_version, \
   get_java_exe_path, get_stack_location, parse_properties_file, read_ambari_user, update_ambari_properties, \
-  update_database_name_property, get_admin_views_dir, get_views_dir,\
+  update_database_name_property, get_admin_views_dir, get_views_dir, \
   AMBARI_PROPERTIES_FILE, IS_LDAP_CONFIGURED, LDAP_PRIMARY_URL_PROPERTY, RESOURCES_DIR_PROPERTY, \
   SETUP_OR_UPGRADE_MSG, update_krb_jaas_login_properties, AMBARI_KRB_JAAS_LOGIN_FILE, get_db_type, update_ambari_env, \
   AMBARI_ENV_FILE
@@ -45,6 +45,7 @@ from ambari_server.setupSecurity import adjust_directory_permissions, \
 from ambari_server.utils import compare_versions
 from ambari_server.serverUtils import is_server_runing, get_ambari_server_api_base
 from ambari_server.userInput import get_validated_string_input, get_prompt_default, read_password, get_YN_input
+from ambari_server.serverClassPath import ServerClassPath
 
 # constants
 STACK_NAME_VER_SEP = "-"
@@ -86,7 +87,7 @@ def upgrade_stack(args):
     repo_url_os = None
 
   stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP)
-  retcode = run_stack_upgrade(stack_name, stack_version, repo_url, repo_url_os)
+  retcode = run_stack_upgrade(args, stack_name, stack_version, repo_url, repo_url_os)
 
   if not retcode == 0:
     raise FatalException(retcode, 'Stack upgrade failed.')
@@ -114,7 +115,7 @@ def load_stack_values(version, filename):
   return values
 
 
-def run_stack_upgrade(stackName, stackVersion, repo_url, repo_url_os):
+def run_stack_upgrade(args, stackName, stackVersion, repo_url, repo_url_os):
   jdk_path = get_java_exe_path()
   if jdk_path is None:
     print_error_msg("No JDK found, please run the \"setup\" "
@@ -128,7 +129,8 @@ def run_stack_upgrade(stackName, stackVersion, repo_url, repo_url_os):
   if repo_url_os is not None:
     stackId['repo_url_os'] = repo_url_os
 
-  command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, get_full_ambari_classpath(),
+  serverClassPath = ServerClassPath(get_ambari_properties(), args)
+  command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(),
                                             "updateStackId",
                                             "'" + json.dumps(stackId) + "'")
   (retcode, stdout, stderr) = run_os_command(command)
@@ -137,7 +139,7 @@ def run_stack_upgrade(stackName, stackVersion, repo_url, repo_url_os):
     print_error_msg("Error executing stack upgrade, please check the server logs.")
   return retcode
 
-def run_metainfo_upgrade(keyValueMap=None):
+def run_metainfo_upgrade(args, keyValueMap=None):
   jdk_path = get_java_exe_path()
   if jdk_path is None:
     print_error_msg("No JDK found, please run the \"setup\" "
@@ -146,7 +148,8 @@ def run_metainfo_upgrade(keyValueMap=None):
 
   retcode = 1
   if keyValueMap:
-    command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, get_full_ambari_classpath(),
+    serverClassPath = ServerClassPath(get_ambari_properties(), args)
+    command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(),
                                               'updateMetaInfo',
                                               "'" + json.dumps(keyValueMap) + "'")
     (retcode, stdout, stderr) = run_os_command(command)
@@ -211,7 +214,7 @@ def upgrade_local_repo(args):
           if repo_url != local_url:
             metainfo_update_items[k] = local_url
 
-    run_metainfo_upgrade(metainfo_update_items)
+    run_metainfo_upgrade(args, metainfo_update_items)
 
 #
 # Schema upgrade
@@ -237,16 +240,14 @@ def run_schema_upgrade(args):
 
   print 'Upgrading database schema'
 
-  class_path = get_full_ambari_classpath()
-  jdbc_driver_path = get_jdbc_driver_path(args, get_ambari_properties())
-  if jdbc_driver_path not in class_path:
-    class_path = class_path + os.pathsep + jdbc_driver_path
+  serverClassPath = ServerClassPath(get_ambari_properties(), args)
+  class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell()
 
   command = SCHEMA_UPGRADE_HELPER_CMD.format(jdk_path, class_path)
 
   ambari_user = read_ambari_user()
   current_user = ensure_can_start_under_current_user(ambari_user)
-  environ = generate_env(ambari_user, current_user)
+  environ = generate_env(args, ambari_user, current_user)
 
   (retcode, stdout, stderr) = run_os_command(command, env=environ)
   print_info_msg("Return code from schema upgrade command, retcode = " + str(retcode))

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/ambari-server/src/main/python/ambari_server/setupSecurity.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupSecurity.py b/ambari-server/src/main/python/ambari_server/setupSecurity.py
index 9b88bef..593236f 100644
--- a/ambari-server/src/main/python/ambari_server/setupSecurity.py
+++ b/ambari-server/src/main/python/ambari_server/setupSecurity.py
@@ -38,7 +38,7 @@ from ambari_commons.os_utils import is_root, set_file_permissions, \
   run_os_command, search_file, is_valid_filepath, change_owner, get_ambari_repo_file_full_name, get_file_owner
 from ambari_server.serverConfiguration import configDefaults, \
   encrypt_password, find_jdk, find_properties_file, get_alias_string, get_ambari_properties, get_conf_dir, \
-  get_credential_store_location, get_full_ambari_classpath, get_is_persisted, get_is_secure, get_master_key_location, \
+  get_credential_store_location, get_is_persisted, get_is_secure, get_master_key_location, \
   get_original_master_key, get_value_from_properties, get_java_exe_path, is_alias_string, read_ambari_user, \
   read_passwd_for_alias, remove_password_file, save_passwd_for_alias, store_password_file, update_properties_2, \
   BLIND_PASSWORD, BOOTSTRAP_DIR_PROPERTY, IS_LDAP_CONFIGURED, JDBC_PASSWORD_FILENAME, JDBC_PASSWORD_PROPERTY, \
@@ -52,6 +52,7 @@ from ambari_server.serverConfiguration import configDefaults, \
 from ambari_server.serverUtils import is_server_runing, get_ambari_server_api_base
 from ambari_server.setupActions import SETUP_ACTION, LDAP_SETUP_ACTION
 from ambari_server.userInput import get_validated_string_input, get_prompt_default, read_password, get_YN_input
+from ambari_server.serverClassPath import ServerClassPath
 
 
 REGEX_IP_ADDRESS = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
@@ -95,7 +96,7 @@ def read_master_key(isReset=False):
 
   return masterKey
 
-def save_master_key(master_key, key_location, persist=True):
+def save_master_key(options, master_key, key_location, persist=True):
   if master_key:
     jdk_path = find_jdk()
     if jdk_path is None:
@@ -103,8 +104,9 @@ def save_master_key(master_key, key_location, persist=True):
                       "command to install a JDK automatically or install any "
                       "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
       return 1
+    serverClassPath = ServerClassPath(get_ambari_properties(), options)
     command = SECURITY_PROVIDER_KEY_CMD.format(get_java_exe_path(),
-      get_full_ambari_classpath(), master_key, key_location, persist)
+      serverClassPath.get_full_ambari_classpath_escaped_for_shell(), master_key, key_location, persist)
     (retcode, stdout, stderr) = run_os_command(command)
     print_info_msg("Return code from credential provider save KEY: " +
                    str(retcode))
@@ -375,7 +377,7 @@ def sync_ldap(options):
   sys.stdout.write('\n')
   sys.stdout.flush()
 
-def setup_master_key():
+def setup_master_key(options):
   if not is_root():
     err = 'Ambari-server setup should be run with ' \
           'root-level privileges'
@@ -465,7 +467,7 @@ def setup_master_key():
                            " or the start will prompt for the master key."
                            " Persist [y/n] (y)? ", True)
     if persist:
-      save_master_key(masterKey, get_master_key_location(properties) + os.sep +
+      save_master_key(options, masterKey, get_master_key_location(properties) + os.sep +
                       SECURITY_MASTER_KEY_FILENAME, persist)
     elif not persist and masterKeyFile:
       try:
@@ -719,7 +721,7 @@ def setup_ldap():
   return 0
 
 @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
-def generate_env(ambari_user, current_user):
+def generate_env(options, ambari_user, current_user):
   properties = get_ambari_properties()
   isSecure = get_is_secure(properties)
   (isPersisted, masterKeyFile) = get_is_persisted(properties)
@@ -753,7 +755,7 @@ def generate_env(ambari_user, current_user):
       masterKey = get_original_master_key(properties)
       tempDir = tempfile.gettempdir()
       tempFilePath = tempDir + os.sep + "masterkey"
-      save_master_key(masterKey, tempFilePath, True)
+      save_master_key(options, masterKey, tempFilePath, True)
       if ambari_user != current_user:
         uid = pwd.getpwnam(ambari_user).pw_uid
         gid = pwd.getpwnam(ambari_user).pw_gid
@@ -767,7 +769,7 @@ def generate_env(ambari_user, current_user):
   return environ
 
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
-def generate_env(ambari_user, current_user):
+def generate_env(options, ambari_user, current_user):
   return os.environ.copy()
 
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/ambari-server/src/main/python/ambari_server_main.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server_main.py b/ambari-server/src/main/python/ambari_server_main.py
index 4f532f3..e9bdec3 100644
--- a/ambari-server/src/main/python/ambari_server_main.py
+++ b/ambari-server/src/main/python/ambari_server_main.py
@@ -27,9 +27,8 @@ from ambari_commons.logging_utils import get_debug_mode, print_warning_msg, prin
 from ambari_commons.os_check import OSConst
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
 from ambari_commons.os_utils import is_root
-from ambari_server.dbConfiguration import ensure_dbms_is_running, ensure_jdbc_driver_is_installed, \
-  get_native_libs_path, get_jdbc_driver_path
-from ambari_server.serverConfiguration import configDefaults, find_jdk, get_ambari_classpath, get_ambari_properties, \
+from ambari_server.dbConfiguration import ensure_dbms_is_running, ensure_jdbc_driver_is_installed
+from ambari_server.serverConfiguration import configDefaults, find_jdk, get_ambari_properties, \
   get_conf_dir, get_is_persisted, get_is_secure, get_java_exe_path, get_original_master_key, read_ambari_user, \
   get_is_active_instance, \
   PID_NAME, SECURITY_KEY_ENV_VAR_NAME, SECURITY_MASTER_KEY_LOCATION, \
@@ -40,6 +39,7 @@ from ambari_server.setupSecurity import generate_env, \
   ensure_can_start_under_current_user
 from ambari_server.utils import check_reverse_lookup, save_pid, locate_file, looking_for_pid, wait_for_pid, \
   save_main_pid_ex, check_exitcode
+from ambari_server.serverClassPath import ServerClassPath
 
 
 # debug settings
@@ -95,9 +95,6 @@ SERVER_START_TIMEOUT = 10
 SERVER_PING_TIMEOUT_WINDOWS = 5
 SERVER_PING_ATTEMPTS_WINDOWS = 4
 
-SERVER_CLASSPATH_KEY = "SERVER_CLASSPATH"
-LIBRARY_PATH_KEY = "LD_LIBRARY_PATH"
-
 SERVER_SEARCH_PATTERN = "org.apache.ambari.server.controller.AmbariServer"
 
 EXITCODE_NAME = "ambari-server.exitcode"
@@ -263,20 +260,7 @@ def server_process_main(options, scmStatus=None):
 
   java_exe = get_java_exe_path()
 
-  class_path = get_conf_dir()
-  class_path = os.path.abspath(class_path) + os.pathsep + get_ambari_classpath()
-  jdbc_driver_path = get_jdbc_driver_path(options, properties)
-  if jdbc_driver_path not in class_path:
-    class_path = class_path + os.pathsep + jdbc_driver_path
-
-  if SERVER_CLASSPATH_KEY in os.environ:
-      class_path =  os.environ[SERVER_CLASSPATH_KEY] + os.pathsep + class_path
-
-  native_libs_path = get_native_libs_path(options, properties)
-  if native_libs_path is not None:
-    if LIBRARY_PATH_KEY in os.environ:
-      native_libs_path = os.environ[LIBRARY_PATH_KEY] + os.pathsep + native_libs_path
-    os.environ[LIBRARY_PATH_KEY] = native_libs_path
+  serverClassPath = ServerClassPath(properties, options)
 
   debug_mode = get_debug_mode()
   debug_start = (debug_mode & 1) or SERVER_START_DEBUG
@@ -284,9 +268,9 @@ def server_process_main(options, scmStatus=None):
   suspend_mode = 'y' if suspend_start else 'n'
 
   param_list = generate_child_process_param_list(ambari_user, java_exe,
-                                                 class_path, debug_start,
+                                                 serverClassPath.get_full_ambari_classpath_escaped_for_shell(), debug_start,
                                                  suspend_mode)
-  environ = generate_env(ambari_user, current_user)
+  environ = generate_env(options, ambari_user, current_user)
 
   if not os.path.exists(configDefaults.PID_DIR):
     os.makedirs(configDefaults.PID_DIR, 0755)

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/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 056dac8..9a92621 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -61,7 +61,7 @@ with patch("platform.linux_distribution", return_value = os_distro_value):
         from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
         from ambari_server.serverConfiguration import configDefaults, \
           check_database_name_property, OS_FAMILY_PROPERTY, \
-          find_properties_file, get_ambari_classpath, get_ambari_jars, get_ambari_properties, get_JAVA_HOME, \
+          find_properties_file, get_ambari_properties, get_JAVA_HOME, \
           parse_properties_file, read_ambari_user, update_ambari_properties, update_properties_2, write_property, find_jdk, \
           get_is_active_instance, \
           AMBARI_CONF_VAR, AMBARI_SERVER_LIB, JDBC_DATABASE_PROPERTY, JDBC_RCA_PASSWORD_FILE_PROPERTY, \
@@ -93,6 +93,7 @@ with patch("platform.linux_distribution", return_value = os_distro_value):
         from ambari_server.userInput import get_YN_input, get_choice_string_input, get_validated_string_input, \
           read_password
         from ambari_server_main import get_ulimit_open_files, ULIMIT_OPEN_FILES_KEY, ULIMIT_OPEN_FILES_DEFAULT
+        from ambari_server.serverClassPath import ServerClassPath
 
 CURR_AMBARI_VERSION = "2.0.0"
 
@@ -1063,20 +1064,6 @@ class TestAmbariServer(TestCase):
     self.assertTrue(printInfoMsg_mock.called)
     pass
 
-  @patch("glob.glob")
-  @patch("ambari_server.serverConfiguration.print_info_msg")
-  @patch("ambari_server.serverConfiguration.get_ambari_properties")
-  def test_get_ambari_classpath(self, get_ambari_properties_mock, printInfoMsg_mock, globMock):
-    globMock.return_value = ["one"]
-    result = get_ambari_classpath()
-    self.assertTrue(get_ambari_jars() in result)
-    globMock.return_value = []
-    result = get_ambari_classpath()
-    self.assertTrue(get_ambari_jars() in result)
-    self.assertFalse(":" in result[2:])
-    pass
-
-  @not_for_platform(PLATFORM_WINDOWS)
   @patch("ambari_server.serverConfiguration.print_info_msg")
   def test_get_conf_dir(self, printInfoMsg_mock):
     env = "/dummy/ambari/conf"
@@ -4189,6 +4176,8 @@ class TestAmbariServer(TestCase):
 
 
   @not_for_platform(PLATFORM_WINDOWS)
+  @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell",
+                new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12'))
   @patch("ambari_server_main.get_is_active_instance")
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("sys.stdout.flush")
@@ -4683,7 +4672,7 @@ class TestAmbariServer(TestCase):
     upgrade_stack(args)
 
     self.assertTrue(run_stack_upgrade_mock.called)
-    run_stack_upgrade_mock.assert_called_with("HDP", "2.0", None, None)
+    run_stack_upgrade_mock.assert_called_with(['', 'HDP-2.0'], "HDP", "2.0", None, None)
     pass
 
   @patch("ambari_server.serverUpgrade.get_ambari_properties")
@@ -4707,46 +4696,42 @@ class TestAmbariServer(TestCase):
 
 
   @patch("ambari_server.serverConfiguration.get_conf_dir")
-  @patch("ambari_server.serverConfiguration.get_ambari_classpath")
   @patch("ambari_server.serverUpgrade.run_os_command")
   @patch("ambari_server.serverUpgrade.get_java_exe_path")
   def test_run_stack_upgrade(self, java_exe_path_mock, run_os_command_mock,
-                             get_ambari_classpath_mock, get_conf_dir_mock):
+                             get_conf_dir_mock):
     java_exe_path_mock.return_value = "/usr/lib/java/bin/java"
     run_os_command_mock.return_value = (0, None, None)
-    get_ambari_classpath_mock.return_value = 'test:path12'
     get_conf_dir_mock.return_value = '/etc/conf'
     stackIdMap = {'HDP' : '2.0', 'repo_url' : 'http://test.com'}
 
-    run_stack_upgrade('HDP', '2.0', 'http://test.com', None)
+    run_stack_upgrade(None, 'HDP', '2.0', 'http://test.com', None)
 
     self.assertTrue(java_exe_path_mock.called)
-    self.assertTrue(get_ambari_classpath_mock.called)
     self.assertTrue(get_conf_dir_mock.called)
     self.assertTrue(run_os_command_mock.called)
-    run_os_command_mock.assert_called_with('/usr/lib/java/bin/java -cp /etc/conf' + os.pathsep + 'test:path12 '
+    run_os_command_mock.assert_called_with('/usr/lib/java/bin/java -cp \'/etc/conf:/usr/lib/ambari-server/*\' '
                                           'org.apache.ambari.server.upgrade.StackUpgradeHelper '
                                           'updateStackId ' + "'" + json.dumps(stackIdMap) + "'" +
                                           ' > ' + os.sep + 'var' + os.sep + 'log' + os.sep + 'ambari-server' + os.sep +
                                           'ambari-server.out 2>&1')
     pass
 
+  @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell",
+                  new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12'))
   @patch("ambari_server.serverConfiguration.get_conf_dir")
-  @patch("ambari_server.serverConfiguration.get_ambari_classpath")
   @patch("ambari_server.serverUpgrade.run_os_command")
   @patch("ambari_server.serverUpgrade.get_java_exe_path")
   def test_run_stack_upgrade_with_url_os(self, java_exe_path_mock, run_os_command_mock,
-                             get_ambari_classpath_mock, get_conf_dir_mock):
+                             get_conf_dir_mock):
     java_exe_path_mock.return_value = "/usr/lib/java/bin/java"
     run_os_command_mock.return_value = (0, None, None)
-    get_ambari_classpath_mock.return_value = 'test:path12'
     get_conf_dir_mock.return_value = '/etc/conf'
     stackIdMap = {'HDP' : '2.0', 'repo_url': 'http://test.com', 'repo_url_os': 'centos5,centos6'}
 
-    run_stack_upgrade('HDP', '2.0', 'http://test.com', 'centos5,centos6')
+    run_stack_upgrade(None, 'HDP', '2.0', 'http://test.com', 'centos5,centos6')
 
     self.assertTrue(java_exe_path_mock.called)
-    self.assertTrue(get_ambari_classpath_mock.called)
     self.assertTrue(get_conf_dir_mock.called)
     self.assertTrue(run_os_command_mock.called)
     run_os_command_mock.assert_called_with('/usr/lib/java/bin/java -cp /etc/conf' + os.pathsep + 'test:path12 '
@@ -4757,25 +4742,26 @@ class TestAmbariServer(TestCase):
     pass
 
 
+  @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell",
+                new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' +
+                                               os.pathsep + 'path12' + os.pathsep +'/path/to/jdbc.jar'))
   @patch("ambari_server.serverUpgrade.ensure_jdbc_driver_is_installed")
   @patch("ambari_server.serverUpgrade.get_jdbc_driver_path")
   @patch("ambari_server.serverUpgrade.ensure_can_start_under_current_user")
   @patch("ambari_server.serverUpgrade.generate_env")
   @patch("ambari_server.serverUpgrade.read_ambari_user")
   @patch("ambari_server.serverConfiguration.get_conf_dir")
-  @patch("ambari_server.serverConfiguration.get_ambari_classpath")
   @patch("ambari_server.serverUpgrade.run_os_command")
   @patch("ambari_server.serverUpgrade.get_java_exe_path")
   @patch("ambari_server.serverUpgrade.get_ambari_properties")
   @patch("ambari_server.serverUpgrade.get_YN_input")
   def test_run_schema_upgrade(self, get_YN_input_mock, get_ambari_properties_mock, java_exe_path_mock, run_os_command_mock,
-                              get_ambari_classpath_mock, get_conf_dir_mock,
+                              get_conf_dir_mock,
                               read_ambari_user_mock, generate_env_mock,
                               ensure_can_start_under_current_user_mock, get_jdbc_mock,
                               ensure_jdbc_driver_is_installed_mock):
     java_exe_path_mock.return_value = "/usr/lib/java/bin/java"
     run_os_command_mock.return_value = (0, None, None)
-    get_ambari_classpath_mock.return_value = 'test' + os.pathsep + 'path12'
     get_conf_dir_mock.return_value = '/etc/conf'
     command = '/usr/lib/java/bin/java -cp /etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12' + \
               os.pathsep +'/path/to/jdbc.jar ' \
@@ -4797,31 +4783,26 @@ class TestAmbariServer(TestCase):
     self.assertTrue(ensure_can_start_under_current_user_mock.called)
     self.assertTrue(generate_env_mock.called)
     self.assertTrue(read_ambari_user_mock.called)
-    self.assertTrue(get_ambari_classpath_mock.called)
-    self.assertTrue(get_conf_dir_mock.called)
     self.assertTrue(run_os_command_mock.called)
     run_os_command_mock.assert_called_with(command, env=environ)
 
   @patch("ambari_server.serverConfiguration.get_conf_dir")
-  @patch("ambari_server.serverConfiguration.get_ambari_classpath")
+  @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = 'test' + os.pathsep + 'path12'))
   @patch("ambari_server.serverUpgrade.run_os_command")
   @patch("ambari_server.serverUpgrade.get_java_exe_path")
   def test_run_metainfo_upgrade(self, java_exe_path_mock, run_os_command_mock,
-                                get_ambari_classpath_mock, get_conf_dir_mock):
+                                get_conf_dir_mock):
     java_exe_path_mock.return_value = "/usr/lib/java/bin/java"
     run_os_command_mock.return_value = (0, None, None)
-    get_ambari_classpath_mock.return_value = 'test' + os.pathsep + 'path12'
     get_conf_dir_mock.return_value = '/etc/conf'
 
     json_map = {'a': 'http://newurl'}
-    run_metainfo_upgrade(json_map)
+    run_metainfo_upgrade(None, json_map)
 
     self.assertTrue(java_exe_path_mock.called)
-    self.assertTrue(get_ambari_classpath_mock.called)
-    self.assertTrue(get_conf_dir_mock.called)
     self.assertTrue(run_os_command_mock.called)
     run_os_command_mock.assert_called_with('/usr/lib/java/bin/java '
-                                           '-cp /etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12 '
+                                           '-cp test' + os.pathsep + 'path12 '
                                            'org.apache.ambari.server.upgrade.StackUpgradeHelper updateMetaInfo ' +
                                            "'" + json.dumps(json_map) + "'" +
                                            ' > ' + os.sep + 'var' + os.sep + 'log' + os.sep + 'ambari-server' +
@@ -6616,7 +6597,7 @@ class TestAmbariServer(TestCase):
     get_is_secure_method.return_value = False
     exists_mock.return_value = False
 
-    setup_master_key()
+    setup_master_key(MagicMock())
 
     self.assertTrue(get_YN_input_method.called)
     self.assertTrue(read_master_key_method.called)
@@ -6682,7 +6663,7 @@ class TestAmbariServer(TestCase):
     exists_mock.return_value = False
     save_passwd_for_alias_method.return_value = 0
 
-    setup_master_key()
+    setup_master_key(MagicMock())
 
     self.assertTrue(get_YN_input_method.called)
     self.assertTrue(read_master_key_method.called)
@@ -6727,7 +6708,7 @@ class TestAmbariServer(TestCase):
     # Testing call under non-root
     is_root_method.return_value = False
     try:
-      setup_master_key()
+      setup_master_key(MagicMock())
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -6754,7 +6735,7 @@ class TestAmbariServer(TestCase):
     save_passwd_for_alias_method.return_value = 0
     exists_mock.return_value = False
 
-    setup_master_key()
+    setup_master_key(MagicMock())
 
     self.assertTrue(save_master_key_method.called)
     self.assertTrue(get_YN_input_method.called)
@@ -6826,7 +6807,7 @@ class TestAmbariServer(TestCase):
     get_is_secure_method.return_value = True
     get_is_persisted_method.return_value = (True, "filePath")
 
-    setup_master_key()
+    setup_master_key(MagicMock())
 
     self.assertFalse(save_master_key_method.called)
     self.assertTrue(get_YN_input_method.called)
@@ -8051,7 +8032,7 @@ class TestAmbariServer(TestCase):
     self.assertTrue(get_ambari_properties_mock.called)
     self.assertTrue(load_stack_values_mock.called)
     self.assertTrue(run_metainfo_upgrade_mock.called)
-    run_metainfo_upgrade_mock.assert_called_with({'a': 'http://newurl'})
+    run_metainfo_upgrade_mock.assert_called_with(args, {'a': 'http://newurl'})
     pass
 
   @patch("os.listdir")
@@ -8087,7 +8068,7 @@ class TestAmbariServer(TestCase):
     self.assertTrue(get_ambari_properties_mock.called)
     self.assertTrue(load_stack_values_mock.called)
     self.assertTrue(run_metainfo_upgrade_mock.called)
-    run_metainfo_upgrade_mock.assert_called_with({})
+    run_metainfo_upgrade_mock.assert_called_with(args, {})
     pass
 
   @patch("os.path.exists")

http://git-wip-us.apache.org/repos/asf/ambari/blob/7bb91551/ambari-server/src/test/python/TestServerClassPath.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestServerClassPath.py b/ambari-server/src/test/python/TestServerClassPath.py
new file mode 100644
index 0000000..e6c5ca8
--- /dev/null
+++ b/ambari-server/src/test/python/TestServerClassPath.py
@@ -0,0 +1,89 @@
+'''
+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.
+'''
+
+import os
+from mock.mock import patch, MagicMock
+from unittest import TestCase
+from ambari_server.properties import Properties
+from ambari_server.dbConfiguration import get_jdbc_driver_path, get_native_libs_path
+from ambari_server.serverConfiguration import get_conf_dir
+from ambari_server.serverClassPath import ServerClassPath, AMBARI_SERVER_LIB, SERVER_CLASSPATH_KEY, JDBC_DRIVER_PATH_PROPERTY
+
+class TestConfigs(TestCase):
+
+
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  def test_server_class_path_default(self, get_conf_dir_mock):
+    properties = Properties()
+    get_conf_dir_mock.return_value = "/etc/ambari-server/conf"
+
+    expected_classpath = "'/etc/ambari-server/conf:/usr/lib/ambari-server/*'"
+    serverClassPath = ServerClassPath(properties, None)
+    self.assertEquals(expected_classpath, serverClassPath.get_full_ambari_classpath_escaped_for_shell())
+
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  @patch("ambari_server.dbConfiguration.get_jdbc_driver_path")
+  @patch("ambari_server.dbConfiguration.get_native_libs_path")
+  def test_server_class_path_custom_jar(self, get_native_libs_path_mock, get_jdbc_driver_path_mock,
+                                     get_conf_dir_mock):
+    properties = Properties()
+    get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar"
+    get_native_libs_path_mock.return_value = None
+    get_conf_dir_mock.return_value = "/etc/ambari-server/conf"
+    os.environ[AMBARI_SERVER_LIB] = "/custom/ambari/jar/location"
+
+
+    expected_classpath ="'/etc/ambari-server/conf:/custom/ambari/jar/location/*:/path/to/jdbc.jar'"
+    serverClassPath = ServerClassPath(properties, MagicMock())
+    actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell()
+    del os.environ[AMBARI_SERVER_LIB]
+    self.assertEquals(expected_classpath, actual_classpath)
+
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  @patch("ambari_server.dbConfiguration.get_jdbc_driver_path")
+  @patch("ambari_server.dbConfiguration.get_native_libs_path")
+  def test_server_class_path_custom_env_classpath(self, get_native_libs_path_mock, get_jdbc_driver_path_mock,
+                                        get_conf_dir_mock):
+    properties = Properties()
+    get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar"
+    get_native_libs_path_mock.return_value = None
+    get_conf_dir_mock.return_value = "/etc/ambari-server/conf"
+    os.environ[SERVER_CLASSPATH_KEY] = "/custom/server/env/classpath"
+
+    expected_classpath = "'/etc/ambari-server/conf:/custom/server/env/classpath:/usr/lib/ambari-server/*:/path/to/jdbc.jar'"
+    serverClassPath = ServerClassPath(properties, MagicMock())
+    actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell()
+    del os.environ[SERVER_CLASSPATH_KEY]
+    self.assertEquals(expected_classpath, actual_classpath)
+
+  @patch("ambari_server.serverConfiguration.get_conf_dir")
+  @patch("ambari_server.dbConfiguration.get_jdbc_driver_path")
+  @patch("ambari_server.dbConfiguration.get_native_libs_path")
+  def test_server_class_path_custom_jdbc_path(self, get_native_libs_path_mock, get_jdbc_driver_path_mock,
+                                                  get_conf_dir_mock):
+    properties = Properties()
+    properties.process_pair(JDBC_DRIVER_PATH_PROPERTY, "/ambari/properties/path/to/custom/jdbc.jar")
+    get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar"
+    get_native_libs_path_mock.return_value = None
+    get_conf_dir_mock.return_value = "/etc/ambari-server/conf"
+
+    expected_classpath = "'/etc/ambari-server/conf:/usr/lib/ambari-server/*:/ambari/properties/path/to/custom/jdbc.jar:/path/to/jdbc.jar'"
+    serverClassPath = ServerClassPath(properties, MagicMock())
+    actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell()
+    self.assertEquals(expected_classpath, actual_classpath)
+