You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/01/24 02:37:11 UTC

[7/8] ambari git commit: AMBARI-8317 Refactor the OS-dependent Ambari Server Windows components - Part 1.4

http://git-wip-us.apache.org/repos/asf/ambari/blob/49955a35/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 ea072ab..f67d697 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -41,25 +41,49 @@ import random
 import json
 import base64
 
-from ambari_commons import OSCheck, OSConst, Firewall
+from ambari_commons import OSCheck, OSConst
 from ambari_commons.exceptions import FatalException, NonFatalException
 from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \
-  set_debug_mode, print_info_msg, print_warning_msg, print_error_msg
-from ambari_commons.os_utils import is_root, run_in_shell, run_os_command, search_file
+  set_debug_mode, print_info_msg, print_warning_msg, print_error_msg, set_debug_mode_from_options
+from ambari_commons.os_utils import is_root, run_os_command, search_file, copy_file, remove_file, \
+  set_file_permissions
 from ambari_server.BackupRestore import main as BackupRestore_main
+from ambari_server.dbConfiguration import DATABASE_NAMES, DATABASE_FULL_NAMES
 from ambari_server.properties import Properties
 from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
 from ambari_server.serverConfiguration import AMBARI_PROPERTIES_FILE, configDefaults, \
-  backup_file_in_temp, find_properties_file, get_conf_dir, get_value_from_properties, is_alias_string, is_local_database, \
-  read_ambari_user, remove_property, update_ambari_properties, write_property, SCHEMA_UPGRADE_HELPER_CMD
+  backup_file_in_temp, check_database_name_property, find_jdbc_driver, find_jdk, find_properties_file, get_ambari_classpath, \
+  get_ambari_properties, get_conf_dir, get_full_ambari_classpath, get_value_from_properties, is_alias_string, \
+  parse_properties_file, read_ambari_user, \
+  BLIND_PASSWORD, SETUP_OR_UPGRADE_MSG, JDBC_RCA_PASSWORD_ALIAS, \
+  JDBC_PASSWORD_PROPERTY, JDBC_PASSWORD_FILENAME, JDBC_RCA_PASSWORD_FILE_PROPERTY, \
+  GET_FQDN_SERVICE_URL, get_stack_location, IS_LDAP_CONFIGURED, LDAP_PRIMARY_URL_PROPERTY, LDAP_MGR_PASSWORD_PROPERTY, \
+  LDAP_MGR_PASSWORD_ALIAS, LDAP_MGR_PASSWORD_FILENAME, LDAP_MGR_USERNAME_PROPERTY, PID_NAME, \
+  read_passwd_for_alias, get_credential_store_location, get_master_key_location, get_is_secure, get_is_persisted, \
+  get_original_master_key, SECURITY_PROVIDER_PUT_CMD, get_java_exe_path, SECURITY_PROVIDER_KEY_CMD, \
+  SECURITY_IS_ENCRYPTION_ENABLED, SECURITY_KERBEROS_JASS_FILENAME, SECURITY_KEY_ENV_VAR_NAME, \
+  SECURITY_MASTER_KEY_FILENAME, SECURITY_MASTER_KEY_LOCATION, \
+  SSL_TRUSTSTORE_PASSWORD_ALIAS, SSL_TRUSTSTORE_PASSWORD_PROPERTY, SSL_TRUSTSTORE_PATH_PROPERTY, SSL_TRUSTSTORE_TYPE_PROPERTY, \
+  update_debug_mode
+from ambari_server.serverSetup import reset, setup, is_server_runing
+from ambari_server.serverUpgrade import upgrade, upgrade_stack
+
+if not OSCheck.is_windows_family():
+  from ambari_server.dbConfiguration_linux import PGConfig
+
+from ambari_server.setupActions import SETUP_ACTION, START_ACTION, STOP_ACTION, RESET_ACTION, STATUS_ACTION, \
+  UPGRADE_ACTION, UPGRADE_STACK_ACTION, LDAP_SETUP_ACTION, LDAP_SYNC_ACTION, SETUP_SECURITY_ACTION, \
+  REFRESH_STACK_HASH_ACTION, BACKUP_ACTION, RESTORE_ACTION, ACTION_REQUIRE_RESTART
+from ambari_server.setupSecurity import adjust_directory_permissions, read_password, store_password_file, \
+  remove_password_file, encrypt_password, get_truststore_password
 from ambari_server.userInput import get_YN_input, get_validated_string_input, get_validated_filepath_input, \
   get_prompt_default
-from ambari_server.utils import check_exitcode, get_postgre_hba_dir, get_postgre_running_status, locate_file, \
+from ambari_server.utils import check_exitcode, locate_file, \
   looking_for_pid, save_main_pid_ex, wait_for_pid
 
 # debug settings
-
 SERVER_START_DEBUG = False
+SUSPEND_START_MODE = False
 
 # ldap settings
 LDAP_SYNC_ALL = False
@@ -67,55 +91,10 @@ LDAP_SYNC_EXISTING = False
 LDAP_SYNC_USERS = None
 LDAP_SYNC_GROUPS = None
 
-# OS info
-OS_VERSION = OSCheck().get_os_major_version()
-OS_TYPE = OSCheck.get_os_type()
-OS_FAMILY = OSCheck.get_os_family()
-
-# action commands
-SETUP_ACTION = "setup"
-START_ACTION = "start"
-STOP_ACTION = "stop"
-RESET_ACTION = "reset"
-UPGRADE_ACTION = "upgrade"
-UPGRADE_STACK_ACTION = "upgradestack"
-STATUS_ACTION = "status"
-SETUP_HTTPS_ACTION = "setup-https"
-LDAP_SETUP_ACTION = "setup-ldap"
-LDAP_SYNC_ACTION = "sync-ldap"
-SETUP_GANGLIA_HTTPS_ACTION = "setup-ganglia-https"
-ENCRYPT_PASSWORDS_ACTION = "encrypt-passwords"
-SETUP_SECURITY_ACTION = "setup-security"
-REFRESH_STACK_HASH_ACTION = "refresh-stack-hash"
-BACKUP_ACTION = "backup"
-RESTORE_ACTION = "restore"
-
-ACTION_REQUIRE_RESTART = [RESET_ACTION, UPGRADE_ACTION, UPGRADE_STACK_ACTION,
-                          SETUP_SECURITY_ACTION, LDAP_SETUP_ACTION]
-
-# selinux commands
-GET_SE_LINUX_ST_CMD = locate_file('sestatus', '/usr/sbin')
-SE_SETENFORCE_CMD = "setenforce 0"
-SE_STATUS_DISABLED = "disabled"
-SE_STATUS_ENABLED = "enabled"
-SE_MODE_ENFORCING = "enforcing"
-SE_MODE_PERMISSIVE = "permissive"
-
 # server commands
 ambari_provider_module_option = ""
 ambari_provider_module = os.environ.get('AMBARI_PROVIDER_MODULE')
 
-# Non-root user setup commands
-NR_USER_PROPERTY = "ambari-server.user"
-NR_USER_COMMENT = "Ambari user"
-NR_GET_OWNER_CMD = 'stat -c "%U" {0}'
-NR_USERADD_CMD = 'useradd -M --comment "{1}" ' \
-                 '--shell %s -d /var/lib/ambari-server/keys/ {0}' % locate_file('nologin', '/sbin')
-NR_SET_USER_COMMENT_CMD = 'usermod -c "{0}" {1}'
-NR_CHMOD_CMD = 'chmod {0} {1} {2}'
-NR_CHOWN_CMD = 'chown {0} {1} {2}'
-
-RECURSIVE_RM_CMD = 'rm -rf {0}'
 
 SSL_PASSWORD_FILE = "pass.txt"
 SSL_PASSIN_FILE = "passin.txt"
@@ -133,8 +112,6 @@ KEYTOOL_KEYSTORE = " -keystore '{0}'"
 
 # constants
 STACK_NAME_VER_SEP = "-"
-JAVA_SHARE_PATH = "/usr/share/java"
-BLIND_PASSWORD = "*****"
 
 # api properties
 SERVER_API_HOST = '127.0.0.1'
@@ -142,19 +119,8 @@ SERVER_API_PROTOCOL = 'http'
 SERVER_API_PORT = '8080'
 SERVER_API_LDAP_URL = '/api/v1/ldap_sync_events'
 
-# terminal styles
-BOLD_ON = '\033[1m'
-BOLD_OFF = '\033[0m'
-
-#Common messages
-PRESS_ENTER_MSG = "Press <enter> to continue."
-
-#Common setup or upgrade message
-SETUP_OR_UPGRADE_MSG = "- If this is a new setup, then run the \"ambari-server setup\" command to create the user\n" \
-"- If this is an upgrade of an existing setup, run the \"ambari-server upgrade\" command.\n" \
-"Refer to the Ambari documentation for more information on setup and upgrade."
-
 AMBARI_SERVER_DIE_MSG = "Ambari Server java process died with exitcode {0}. Check {1} for more information."
+
 #SSL certificate metainfo
 COMMON_NAME_ATTR = 'CN'
 NOT_BEFORE_ATTR = 'notBefore'
@@ -164,2119 +130,99 @@ if ambari_provider_module is not None:
   ambari_provider_module_option = "-Dprovider.module.class=" +\
                                   ambari_provider_module + " "
 
-SERVER_START_CMD = "{0}" + os.sep + "bin" + os.sep +\
-                 "java -server -XX:NewRatio=3 "\
+SERVER_START_CMD = "{0} -server -XX:NewRatio=3 "\
                  "-XX:+UseConcMarkSweepGC " +\
-                 "-XX:-UseGCOverheadLimit -XX:CMSInitiatingOccupancyFraction=60 " +\
-                 ambari_provider_module_option +\
-                 os.getenv('AMBARI_JVM_ARGS', '-Xms512m -Xmx2048m') +\
-                 " -cp {1}" + os.pathsep + "{2}" +\
-                 " org.apache.ambari.server.controller.AmbariServer "\
-                 ">" + configDefaults.SERVER_OUT_FILE + " 2>&1 || echo $? > {3} &"
-SERVER_START_CMD_DEBUG = "{0}" + os.sep + "bin" + os.sep +\
-                       "java -server -XX:NewRatio=2 -XX:+UseConcMarkSweepGC " +\
-                       ambari_provider_module_option +\
-                       os.getenv('AMBARI_JVM_ARGS', '-Xms512m -Xmx2048m') +\
-                       " -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,"\
-                       "server=y,suspend=n -cp {1}" + os.pathsep + "{2}" +\
-                       " org.apache.ambari.server.controller.AmbariServer"
-SERVER_SEARCH_PATTERN = "org.apache.ambari.server.controller.AmbariServer"
-SECURITY_PROVIDER_GET_CMD = "{0}" + os.sep + "bin" + os.sep + "java -cp {1}" +\
-                          os.pathsep + "{2} " +\
-                          "org.apache.ambari.server.security.encryption" +\
-                          ".CredentialProvider GET {3} {4} {5} " +\
-                          "> " + configDefaults.SERVER_OUT_FILE + " 2>&1"
-
-SECURITY_PROVIDER_PUT_CMD = "{0}" + os.sep + "bin" + os.sep + "java -cp {1}" +\
-                          os.pathsep + "{2} " +\
-                          "org.apache.ambari.server.security.encryption" +\
-                          ".CredentialProvider PUT {3} {4} {5} " +\
-                          "> " + configDefaults.SERVER_OUT_FILE + " 2>&1"
-
-SECURITY_PROVIDER_KEY_CMD = "{0}" + os.sep + "bin" + os.sep + "java -cp {1}" +\
-                          os.pathsep + "{2} " +\
-                          "org.apache.ambari.server.security.encryption" +\
-                          ".MasterKeyServiceImpl {3} {4} {5} " +\
-                          "> " + configDefaults.SERVER_OUT_FILE + " 2>&1"
-
-STACK_UPGRADE_HELPER_CMD = "{0}" + os.sep + "bin" + os.sep + "java -cp {1}" +\
-                          os.pathsep + "{2} " +\
-                          "org.apache.ambari.server.upgrade.StackUpgradeHelper" +\
-                          " {3} {4} > " + configDefaults.SERVER_OUT_FILE + " 2>&1"
-
-
-VIEW_EXTRACT_CMD = "{0}" + os.sep + "bin" + os.sep + "java -cp {1}" +\
-                          os.pathsep + "{2} " +\
-                          "org.apache.ambari.server.view.ViewRegistry extract {3} " +\
-                          "> " + configDefaults.SERVER_OUT_FILE + " 2>&1"
-
-
-ULIMIT_CMD = "ulimit -n"
-SERVER_INIT_TIMEOUT = 5
-SERVER_START_TIMEOUT = 10
-SECURITY_KEYS_DIR = "security.server.keys_dir"
-SECURITY_MASTER_KEY_LOCATION = "security.master.key.location"
-SECURITY_KEY_IS_PERSISTED = "security.master.key.ispersisted"
-SECURITY_KEY_ENV_VAR_NAME = "AMBARI_SECURITY_MASTER_KEY"
-SECURITY_MASTER_KEY_FILENAME = "master"
-SECURITY_IS_ENCRYPTION_ENABLED = "security.passwords.encryption.enabled"
-SECURITY_KERBEROS_JASS_FILENAME = "krb5JAASLogin.conf"
-
-SSL_KEY_DIR = 'security.server.keys_dir'
-SSL_API_PORT = 'client.api.ssl.port'
-SSL_API = 'api.ssl'
-SSL_SERVER_CERT_NAME = 'client.api.ssl.cert_name'
-SSL_SERVER_KEY_NAME = 'client.api.ssl.key_name'
-SSL_CERT_FILE_NAME = "https.crt"
-SSL_KEY_FILE_NAME = "https.key"
-SSL_KEYSTORE_FILE_NAME = "https.keystore.p12"
-SSL_KEY_PASSWORD_FILE_NAME = "https.pass.txt"
-SSL_KEY_PASSWORD_LENGTH = 50
-DEFAULT_SSL_API_PORT = 8443
-SSL_DATE_FORMAT = '%b  %d %H:%M:%S %Y GMT'
-
-GANGLIA_HTTPS = 'ganglia.https'
-
-JDBC_RCA_PASSWORD_ALIAS = "ambari.db.password"
-CLIENT_SECURITY_KEY = "client.security"
-
-IS_LDAP_CONFIGURED = "ambari.ldap.isConfigured"
-LDAP_MGR_PASSWORD_ALIAS = "ambari.ldap.manager.password"
-LDAP_MGR_PASSWORD_PROPERTY = "authentication.ldap.managerPassword"
-LDAP_MGR_PASSWORD_FILENAME = "ldap-password.dat"
-LDAP_MGR_USERNAME_PROPERTY = "authentication.ldap.managerDn"
-LDAP_PRIMARY_URL_PROPERTY = "authentication.ldap.primaryUrl"
-
-SSL_TRUSTSTORE_PASSWORD_ALIAS = "ambari.ssl.trustStore.password"
-SSL_TRUSTSTORE_PATH_PROPERTY = "ssl.trustStore.path"
-SSL_TRUSTSTORE_PASSWORD_PROPERTY = "ssl.trustStore.password"
-SSL_TRUSTSTORE_TYPE_PROPERTY = "ssl.trustStore.type"
-
-AMBARI_CONF_VAR = "AMBARI_CONF_DIR"
-AMBARI_SERVER_LIB = "AMBARI_SERVER_LIB"
-JAVA_HOME = "JAVA_HOME"
-BOOTSTRAP_DIR_PROPERTY = "bootstrap.dir"
-PID_NAME = "ambari-server.pid"
-EXITCODE_NAME = "ambari-server.exitcode"
-RESOURCES_DIR_PROPERTY = "resources.dir"
-
-SETUP_DB_CONNECT_TIMEOUT = 5
-SETUP_DB_CONNECT_ATTEMPTS = 3
-SETUP_DB_CMD = ['su', '-', 'postgres',
-        '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'" -v dbname="{3}"']
-UPGRADE_STACK_CMD = ['su', 'postgres',
-        '--command=psql -f {0} -v stack_name="\'{1}\'"  -v stack_version="\'{2}\'" -v dbname="{3}"']
-
-CHANGE_OWNER_COMMAND = ['su', '-', 'postgres',
-                        '--command=/var/lib/ambari-server/resources/scripts/change_owner.sh -d {0} -s {1} -o {2}']
-
-PG_ERROR_BLOCKED = "is being accessed by other users"
-PG_STATUS_RUNNING = get_postgre_running_status(OS_TYPE)
-PG_DEFAULT_PASSWORD = "bigdata"
-SERVICE_CMD = "/usr/bin/env service"
-PG_SERVICE_NAME = "postgresql"
-PG_HBA_DIR = get_postgre_hba_dir(OS_FAMILY)
-
-PG_ST_CMD = "%s %s status" % (SERVICE_CMD, PG_SERVICE_NAME)
-if os.path.isfile("/usr/bin/postgresql-setup"):
-    PG_INITDB_CMD = "/usr/bin/postgresql-setup initdb"
-else:
-    PG_INITDB_CMD = "%s %s initdb" % (SERVICE_CMD, PG_SERVICE_NAME)
-
-PG_START_CMD = "%s %s start" % (SERVICE_CMD, PG_SERVICE_NAME)
-PG_RESTART_CMD = "%s %s restart" % (SERVICE_CMD, PG_SERVICE_NAME)
-PG_HBA_RELOAD_CMD = "%s %s reload" % (SERVICE_CMD, PG_SERVICE_NAME)
-
-PG_HBA_CONF_FILE = os.path.join(PG_HBA_DIR, "pg_hba.conf")
-PG_HBA_CONF_FILE_BACKUP = os.path.join(PG_HBA_DIR, "pg_hba_bak.conf.old")
-POSTGRESQL_CONF_FILE = os.path.join(PG_HBA_DIR, "postgresql.conf")
-
-SERVER_VERSION_FILE_PATH = "server.version.file"
-
-JDBC_DATABASE_PROPERTY = "server.jdbc.database"             # E.g., embedded|oracle|mysql|postgres
-JDBC_DATABASE_NAME_PROPERTY = "server.jdbc.database_name"   # E.g., ambari
-JDBC_HOSTNAME_PROPERTY = "server.jdbc.hostname"
-JDBC_PORT_PROPERTY = "server.jdbc.port"
-JDBC_POSTGRES_SCHEMA_PROPERTY = "server.jdbc.postgres.schema"   # Only for postgres, defaults to same value as DB name
-
-VIEWS_DIR_PROPERTY = "views.dir"
-DEFAULT_VIEWS_DIR = "/var/lib/ambari-server/resources/views"
-
-JDBC_USER_NAME_PROPERTY = "server.jdbc.user.name"
-JDBC_PASSWORD_PROPERTY = "server.jdbc.user.passwd"
-JDBC_PASSWORD_FILENAME = "password.dat"
-JDBC_RCA_PASSWORD_FILENAME = "rca_password.dat"
-
-CLIENT_API_PORT_PROPERTY = "client.api.port"
-CLIENT_API_PORT = "8080"
-
-SRVR_TWO_WAY_SSL_PORT_PROPERTY = "security.server.two_way_ssl.port"
-SRVR_TWO_WAY_SSL_PORT = "8441"
-
-SRVR_ONE_WAY_SSL_PORT_PROPERTY = "security.server.one_way_ssl.port"
-SRVR_ONE_WAY_SSL_PORT = "8440"
-
-PERSISTENCE_TYPE_PROPERTY = "server.persistence.type"
-JDBC_DRIVER_PROPERTY = "server.jdbc.driver"
-JDBC_URL_PROPERTY = "server.jdbc.url"
-
-JDBC_RCA_DRIVER_PROPERTY = "server.jdbc.rca.driver"
-JDBC_RCA_URL_PROPERTY = "server.jdbc.rca.url"
-JDBC_RCA_USER_NAME_PROPERTY = "server.jdbc.rca.user.name"
-JDBC_RCA_PASSWORD_FILE_PROPERTY = "server.jdbc.rca.user.passwd"
-
-CHECK_COMMAND_EXIST_CMD = "type {0}"
-
-DATABASE_INDEX = 0
-PROMPT_DATABASE_OPTIONS = False
-USERNAME_PATTERN = "^[a-zA-Z_][a-zA-Z0-9_\-]*$"
-PASSWORD_PATTERN = "^[a-zA-Z0-9_-]*$"
-DATABASE_TYPES = ["postgres", "oracle", "mysql"]
-DATABASE_STORAGE_NAMES = ["Database", "Service", "Database"]
-DATABASE_PORTS = ["5432", "1521", "3306"]
-DATABASE_DRIVER_NAMES = ["org.postgresql.Driver", "oracle.jdbc.driver.OracleDriver", "com.mysql.jdbc.Driver"]
-DATABASE_CONNECTION_STRINGS = [
-                  "jdbc:postgresql://{0}:{1}/{2}",
-                  "jdbc:oracle:thin:@{0}:{1}/{2}",
-                  "jdbc:mysql://{0}:{1}/{2}"]
-DATABASE_CONNECTION_STRINGS_ALT = [
-                  "jdbc:postgresql://{0}:{1}/{2}",
-                  "jdbc:oracle:thin:@{0}:{1}:{2}",
-                  "jdbc:mysql://{0}:{1}/{2}"]
-ORACLE_SID_PATTERN = "jdbc:oracle:thin:@.+:.+/.+"
-ORACLE_SNAME_PATTERN = "jdbc:oracle:thin:@.+:.+:.+"
-
-DATABASE_CLI_TOOLS = [["psql"], ["sqlplus", "sqlplus64"], ["mysql"]]
-DATABASE_CLI_TOOLS_DESC = ["psql", "sqlplus", "mysql"]
-DATABASE_CLI_TOOLS_USAGE = ['su -postgres --command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'"',
-                            'sqlplus {1}/{2} < {0} ',
-                            'mysql --user={1} --password={2} {3}<{0}']
-
-MYSQL_INIT_SCRIPT = '/var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql'
-DATABASE_INIT_SCRIPTS = ['/var/lib/ambari-server/resources/Ambari-DDL-Postgres-CREATE.sql',
-                         '/var/lib/ambari-server/resources/Ambari-DDL-Oracle-CREATE.sql',
-                         MYSQL_INIT_SCRIPT]
-DATABASE_DROP_SCRIPTS = ['/var/lib/ambari-server/resources/Ambari-DDL-Postgres-DROP.sql',
-                         '/var/lib/ambari-server/resources/Ambari-DDL-Oracle-DROP.sql',
-                         '/var/lib/ambari-server/resources/Ambari-DDL-MySQL-DROP.sql']
-
-JDBC_PROPERTIES_PREFIX = "server.jdbc.properties."
-DATABASE_JDBC_PROPERTIES = [
-                         [ ],
-                         [
-                           ["oracle.net.CONNECT_TIMEOUT", "2000"], # socket level timeout
-                           ["oracle.net.READ_TIMEOUT", "2000"], # socket level timeout
-                           ["oracle.jdbc.ReadTimeout", "8000"] # query fetch timeout
-                         ],
-                         [ ]
-                        ]
-
-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])$"
-REGEX_HOSTNAME = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
-REGEX_HOSTNAME_PORT = "^(.*:[0-9]{1,5}$)"
-REGEX_TRUE_FALSE = "^(true|false)?$"
-REGEX_ANYTHING = ".*"
-
-
-POSTGRES_EXEC_ARGS = "-h {0} -p {1} -d {2} -U {3} -f {4} -v username='{3}'"
-ORACLE_EXEC_ARGS = "-S -L '{0}/{1}@(description=(address=(protocol=TCP)(host={2})(port={3}))(connect_data=({6}={4})))' @{5} {0}"
-MYSQL_EXEC_ARGS_WITH_USER_VARS = "--host={0} --port={1} --user={2} --password={3} {4} " \
-                 "-e\"set @schema=\'{4}\'; set @username=\'{2}\'; source {5};\""
-MYSQL_EXEC_ARGS_WO_USER_VARS = "--force --host={0} --port={1} --user={2} --password={3} --database={4} < {5} 2> /dev/null"
-MYSQL_UPGRADE_STACK_ARGS = "--host={0} --port={1} --user={2} --password={3} --database={4} " \
-                 "-e\"set @stackName=\'{6}\'; set @stackVersion=\'{7}\'; source {5};\""
-
-ORACLE_UPGRADE_STACK_ARGS = "-S -L '{0}/{1}@(description=(address=(protocol=TCP)(host={2})(port={3}))(connect_data=({6}={4})))' @{5} {7} {8}"
-
-JDBC_PATTERNS = {"oracle": "*ojdbc*.jar", "mysql": "*mysql*.jar"}
-DATABASE_FULL_NAMES = {"oracle": "Oracle", "mysql": "MySQL", "postgres": "PostgreSQL"}
-JDBC_DB_OPTION_VALUES = ["postgres", "mysql", "oracle", "mssql"]
-JDBC_DB_DEFAULT_DRIVER = {"postgresql" : "postgresql-jdbc.jar", "mysql" : "mysql-connector-java.jar", "oracle" : "ojdbc6.jar"}
-ORACLE_DB_ID_TYPES = ["Service Name", "SID"]
-
-
-# jdk commands
-JDK_NAMES = ["jdk-7u67-linux-x64.tar.gz", "jdk-6u31-linux-x64.bin"]
-JDK_URL_PROPERTIES = ["jdk1.7.url", "jdk1.6.url"]
-JCE_URL_PROPERTIES = ["jce_policy1.7.url", "jce_policy1.6.url"]
-DEFAULT_JDK16_LOCATION = "/usr/jdk64/jdk1.6.0_31"
-JDK_INDEX = 0
-JDK_VERSION_REs = ["(jdk.*)/jre", "Creating (jdk.*)/jre"]
-CUSTOM_JDK_NUMBER = "3"
-JDK_MIN_FILESIZE = 5000
-CREATE_JDK_DIR_CMD = "/bin/mkdir -p " + configDefaults.JDK_INSTALL_DIR
-MAKE_FILE_EXECUTABLE_CMD = "chmod a+x {0}"
-JAVA_HOME_PROPERTY = "java.home"
-JDK_NAME_PROPERTY = "jdk.name"
-JCE_NAME_PROPERTY = "jce.name"
-OS_TYPE_PROPERTY = "server.os_type"
-OS_FAMILY_PROPERTY = "server.os_family"
-GET_FQDN_SERVICE_URL = "server.fqdn.service.url"
-
-JDK_DOWNLOAD_CMD = "curl --create-dirs -o {0} {1}"
-JDK_DOWNLOAD_SIZE_CMD = "curl -I {0}"
-
-# use --no-same-owner when running as root to prevent uucp as the user (AMBARI-6478)
-UNTAR_JDK_ARCHIVE = "tar --no-same-owner -xvf {0}"
-
-#JCE Policy files
-JCE_POLICY_FILENAMES = ["UnlimitedJCEPolicyJDK7.zip", "jce_policy-6.zip"]
-JCE_DOWNLOAD_CMD = "curl -o {0} {1}"
-JCE_MIN_FILESIZE = 5000
-
-DEFAULT_DB_NAME = "ambari"
-
-# stack repo upgrade
-STACK_LOCATION_KEY = 'metadata.path'
-STACK_LOCATION_DEFAULT = '/var/lib/ambari-server/resources/stacks'
-
-# linux open-file limit
-ULIMIT_OPEN_FILES_KEY = 'ulimit.open.files'
-ULIMIT_OPEN_FILES_DEFAULT = 10000
-
-#Apache License Header
-ASF_LICENSE_HEADER = '''
-# Copyright 2011 The Apache Software Foundation
-#
-# 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.
-'''
-
-### System interaction ###
-
-
-def get_exec_path(cmd):
-  cmd = 'which {0}'.format(cmd)
-  ret, out, err = run_in_shell(cmd)
-  if ret == 0:
-    return out.strip()
-  else:
-    return None
-
-
-#
-# Checks SELinux
-#
-def check_selinux():
-  try:
-    retcode, out, err = run_os_command(GET_SE_LINUX_ST_CMD)
-    se_status = re.search('(disabled|enabled)', out).group(0)
-    print "SELinux status is '" + se_status + "'"
-    if se_status == SE_STATUS_DISABLED:
-      return 0
-    else:
-      try:
-        se_mode = re.search('(enforcing|permissive)', out).group(0)
-      except AttributeError:
-        err = "Error determining SELinux mode. Exiting."
-        raise FatalException(1, err)
-      print "SELinux mode is '" + se_mode + "'"
-      if se_mode == SE_MODE_ENFORCING:
-        print "Temporarily disabling SELinux"
-        run_os_command(SE_SETENFORCE_CMD)
-      print_warning_msg(
-        "SELinux is set to 'permissive' mode and temporarily disabled.")
-      ok = get_YN_input("OK to continue [y/n] (y)? ", True)
-      if not ok:
-        raise FatalException(1, None)
-      return 0
-  except OSError:
-    print_warning_msg("Could not run {0}: OK".format(GET_SE_LINUX_ST_CMD))
-  return 0
-
-
-def adjust_directory_permissions(ambari_user):
-  properties = get_ambari_properties()
-  bootstrap_dir = get_value_from_properties(properties, BOOTSTRAP_DIR_PROPERTY)
-  print_info_msg("Cleaning bootstrap directory ({0}) contents...".format(bootstrap_dir))
-  cmd = RECURSIVE_RM_CMD.format(bootstrap_dir)
-  run_os_command(cmd)
-  os.makedirs(bootstrap_dir)
-  # Add master key and credential store if exists
-  keyLocation = get_master_key_location(properties)
-  masterKeyFile = search_file(SECURITY_MASTER_KEY_FILENAME, keyLocation)
-  if masterKeyFile:
-    configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((masterKeyFile, "600", "{0}", "{0}", False))
-  credStoreFile = get_credential_store_location(properties)
-  if os.path.exists(credStoreFile):
-    configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((credStoreFile, "600", "{0}", "{0}", False))
-  trust_store_location = properties[SSL_TRUSTSTORE_PATH_PROPERTY]
-  if trust_store_location:
-    configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((trust_store_location, "600", "{0}", "{0}", False))
-  print "Adjusting ambari-server permissions and ownership..."
-  
-  for pack in configDefaults.NR_ADJUST_OWNERSHIP_LIST:
-    file = pack[0]
-    mod = pack[1]
-    user = pack[2].format(ambari_user)
-    recursive = pack[3]
-    set_file_permissions(file, mod, user, recursive)
-
-
-def set_file_permissions(file, mod, user, recursive):
-  WARN_MSG = "Command {0} returned exit code {1} with message: {2}"
-  if recursive:
-    params = " -R "
-  else:
-    params = ""
-  if os.path.exists(file):
-    command = NR_CHMOD_CMD.format(params, mod, file)
-    retcode, out, err = run_os_command(command)
-    if retcode != 0:
-      print_warning_msg(WARN_MSG.format(command, file, err))
-    command = NR_CHOWN_CMD.format(params, user, file)
-    retcode, out, err = run_os_command(command)
-    if retcode != 0:
-      print_warning_msg(WARN_MSG.format(command, file, err))
-  else:
-    print_info_msg("File %s does not exist" % file)
-
-
-def create_custom_user():
-  user = get_validated_string_input(
-    "Enter user account for ambari-server daemon (root):",
-    "root",
-    "^[a-z_][a-z0-9_-]{1,31}$",
-    "Invalid username.",
-    False
-  )
-
-  print_info_msg("Trying to create user {0}".format(user))
-  command = NR_USERADD_CMD.format(user, NR_USER_COMMENT)
-  retcode, out, err = run_os_command(command)
-  if retcode == 9:  # 9 = username already in use
-    print_info_msg("User {0} already exists, "
-                      "skipping user creation".format(user))
-
-  elif retcode != 0:  # fail
-    print_warning_msg("Can't create user {0}. Command {1} "
-                      "finished with {2}: \n{3}".format(user, command, retcode, err))
-    return retcode, None
-
-  print_info_msg("User configuration is done.")
-  return 0, user
-
-def check_reverse_lookup():
-  """
-  Check if host fqdn resolves to current host ip
-  """
-  try:
-    host_name = socket.gethostname().lower()
-    host_ip = socket.gethostbyname(host_name)
-    host_fqdn = socket.getfqdn().lower()
-    fqdn_ip = socket.gethostbyname(host_fqdn)
-    return host_ip == fqdn_ip
-  except socket.error:
-    pass
-  return False
-
-def check_ambari_user():
-  try:
-    user = read_ambari_user()
-    create_user = False
-    update_user_setting = False
-    if user is not None:
-      create_user = get_YN_input("Ambari-server daemon is configured to run under user '{0}'."
-                        " Change this setting [y/n] (n)? ".format(user), False)
-      update_user_setting = create_user  # Only if we will create another user
-    else:  # user is not configured yet
-      update_user_setting = True  # Write configuration anyway
-      create_user = get_YN_input("Customize user account for ambari-server "
-                   "daemon [y/n] (n)? ", False)
-      if not create_user:
-        user = "root"
-
-    if create_user:
-      (retcode, user) = create_custom_user()
-      if retcode != 0:
-        return retcode
-
-    if update_user_setting:
-      write_property(NR_USER_PROPERTY, user)
-
-    adjust_directory_permissions(user)
-  except OSError as e:
-    print_error_msg("Failed: %s" % e.strerror)
-    return 4
-  except Exception as e:
-    print_error_msg("Unexpected error %s" % e)
-    return 1
-  return 0
-
-### Postgres ###
-
-
-def configure_pg_hba_ambaridb_users():
-  args = optparse.Values()
-  configure_database_username_password(args)
-
-  with open(PG_HBA_CONF_FILE, "a") as pgHbaConf:
-    pgHbaConf.write("\n")
-    pgHbaConf.write("local  all  " + args.database_username +
-                    ",mapred md5")
-    pgHbaConf.write("\n")
-    pgHbaConf.write("host  all   " + args.database_username +
-                    ",mapred 0.0.0.0/0  md5")
-    pgHbaConf.write("\n")
-    pgHbaConf.write("host  all   " + args.database_username +
-                    ",mapred ::/0 md5")
-    pgHbaConf.write("\n")
-  retcode, out, err = run_os_command(PG_HBA_RELOAD_CMD)
-  if not retcode == 0:
-    raise FatalException(retcode, err)
-
-
-def configure_pg_hba_postgres_user():
-  postgresString = "all   postgres"
-  for line in fileinput.input(PG_HBA_CONF_FILE, inplace=1):
-    print re.sub('all\s*all', postgresString, line),
-  os.chmod(PG_HBA_CONF_FILE, 0644)
-
-
-def configure_postgresql_conf():
-  listenAddress = "listen_addresses = '*'        #"
-  for line in fileinput.input(POSTGRESQL_CONF_FILE, inplace=1):
-    print re.sub('#+listen_addresses.*?(#|$)', listenAddress, line),
-  os.chmod(POSTGRESQL_CONF_FILE, 0644)
-
-
-def configure_postgres():
-  if os.path.isfile(PG_HBA_CONF_FILE):
-    if not os.path.isfile(PG_HBA_CONF_FILE_BACKUP):
-      shutil.copyfile(PG_HBA_CONF_FILE, PG_HBA_CONF_FILE_BACKUP)
-    else:
-      #Postgres has been configured before, must not override backup
-      print "Backup for pg_hba found, reconfiguration not required"
-      return 0, "", ""
-  configure_pg_hba_postgres_user()
-  configure_pg_hba_ambaridb_users()
-  os.chmod(PG_HBA_CONF_FILE, 0644)
-  configure_postgresql_conf()
-  #restart postgresql if already running
-  pg_status, retcode, out, err = get_postgre_status()
-  if pg_status == PG_STATUS_RUNNING:
-    retcode, out, err = restart_postgres()
-    return retcode, out, err
-  return 0, "", ""
-
-
-def restart_postgres():
-  print "Restarting PostgreSQL"
-  process = subprocess.Popen(PG_RESTART_CMD.split(' '),
-                            stdout=subprocess.PIPE,
-                            stdin=subprocess.PIPE,
-                            stderr=subprocess.PIPE
-                             )
-  time.sleep(5)
-  result = process.poll()
-  if result is None:
-    print_info_msg("Killing restart PostgresSQL process")
-    process.kill()
-    pg_status, retcode, out, err = get_postgre_status()
-    # SUSE linux set status of stopped postgresql proc to unused
-    if pg_status == "unused" or pg_status == "stopped":
-      print_info_msg("PostgreSQL is stopped. Restarting ...")
-      retcode, out, err = run_os_command(PG_START_CMD)
-      return retcode, out, err
-  return 0, "", ""
-
-
-def setup_db(args):
-  #password access to ambari-server and mapred
-  configure_database_username_password(args)
-  dbname = args.database_name
-  scriptFile = args.init_script_file
-  username = args.database_username
-  password = args.database_password
-
-  #setup DB
-  command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(scriptFile, username, password, dbname)
-
-  for i in range(SETUP_DB_CONNECT_ATTEMPTS):
-    sys.stdout.write('Connecting to local database...')
-    retcode, outdata, errdata = run_os_command(command)
-    if retcode == 0:
-      print 'done.'
-      return retcode, outdata, errdata
-    timeOutMsg = 'connection timed out'
-    if (i+1) < SETUP_DB_CONNECT_ATTEMPTS:
-      timeOutMsg += '...retrying (%d)' % (i+1)
-      print timeOutMsg
-      time.sleep(SETUP_DB_CONNECT_TIMEOUT)
-
-  print 'unable to connect to database'
-  print_error_msg(errdata)
-  return retcode, outdata, errdata
-
-
-def store_password_file(password, filename):
-  conf_file = find_properties_file()
-  passFilePath = os.path.join(os.path.dirname(conf_file),
-    filename)
-
-  with open(passFilePath, 'w+') as passFile:
-    passFile.write(password)
-  print_info_msg("Adjusting filesystem permissions")
-  ambari_user = read_ambari_user()
-  set_file_permissions(passFilePath, "660", ambari_user, False)
-
-  return passFilePath
-
-
-def remove_password_file(filename):
-  conf_file = find_properties_file()
-  passFilePath = os.path.join(os.path.dirname(conf_file),
-    filename)
-
-  if os.path.exists(passFilePath):
-    try:
-      os.remove(passFilePath)
-    except Exception, e:
-      print_warning_msg('Unable to remove password file: ' + str(e))
-      return 1
-  pass
-  return 0
-
-
-def execute_db_script(args, file):
-  #password access to ambari-server and mapred
-  configure_database_username_password(args)
-  dbname = args.database_name
-  username = args.database_username
-  password = args.database_password
-  command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(file, username, password, dbname)
-  retcode, outdata, errdata = run_os_command(command)
-  if not retcode == 0:
-    print errdata
-  return retcode
-
-
-def check_db_consistency(args, file):
-  #password access to ambari-server and mapred
-  configure_database_username_password(args)
-  dbname = args.database_name
-  username = args.database_username
-  password = args.database_password
-  command = SETUP_DB_CMD[:]
-  command[-1] = command[-1].format(file, username, password, dbname)
-  retcode, outdata, errdata = run_os_command(command)
-  if not retcode == 0:
-    print errdata
-    return retcode
-  else:
-    # Assumes that the output is of the form ...\n<count>
-    print_info_msg("Parsing output: " + outdata)
-    lines = outdata.splitlines()
-    if (lines[-1] == '3' or lines[-1] == '0'):
-      return 0
-  return -1
-
-
-def get_postgre_status():
-  retcode, out, err = run_os_command(PG_ST_CMD)
-  try:
-    pg_status = re.search('(stopped|running)', out, re.IGNORECASE).group(0).lower()
-  except AttributeError:
-    pg_status = None
-  return pg_status, retcode, out, err
-
-
-def check_postgre_up():
-  pg_status, retcode, out, err = get_postgre_status()
-  if pg_status == PG_STATUS_RUNNING:
-    print_info_msg("PostgreSQL is running")
-    return pg_status, 0, out, err
-  else:
-    # run initdb only on non ubuntu systems as ubuntu does not have initdb cmd.
-    if OS_TYPE != OSConst.OS_UBUNTU:
-      print "Running initdb: This may take upto a minute."
-      retcode, out, err = run_os_command(PG_INITDB_CMD)
-      if retcode == 0:
-        print out
-    print "About to start PostgreSQL"
-    try:
-      process = subprocess.Popen(PG_START_CMD.split(' '),
-                                 stdout=subprocess.PIPE,
-                                 stdin=subprocess.PIPE,
-                                 stderr=subprocess.PIPE
-                                 )
-      if OS_TYPE == OSConst.OS_SUSE:
-        time.sleep(20)
-        result = process.poll()
-        print_info_msg("Result of postgres start cmd: " + str(result))
-        if result is None:
-          process.kill()
-          pg_status, retcode, out, err = get_postgre_status()
-        else:
-          retcode = result
-      else:
-        out, err = process.communicate()
-        retcode = process.returncode
-      if pg_status == PG_STATUS_RUNNING:
-        print_info_msg("Postgres process is running. Returning...")
-        return pg_status, 0, out, err
-    except (Exception), e:
-      pg_status, retcode, out, err = get_postgre_status()
-      if pg_status == PG_STATUS_RUNNING:
-        return pg_status, 0, out, err
-      else:
-        print_error_msg("Postgres start failed. " + str(e))
-    return pg_status, retcode, out, err
-
-
-def get_validated_db_name(database_name):
-  return get_validated_string_input(
-        DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " Name ("
-        + database_name + "): ",
-        database_name,
-        ".*",
-        "Invalid " + DATABASE_STORAGE_NAMES[DATABASE_INDEX] + " name.",
-        False
-        )
-
-def get_validated_db_schema(postgres_schema):
-    return get_validated_string_input(
-        "Postgres schema (" + postgres_schema + "): ",
-        postgres_schema,
-        "^[a-zA-Z0-9_\-]*$",
-        "Invalid schema name.",
-        False, allowEmpty=True
-    )
-
-def get_validated_service_name(service_name, index):
-  return get_validated_string_input(
-            ORACLE_DB_ID_TYPES[index] + " (" + service_name + "): ",
-            service_name,
-            ".*",
-            "Invalid " + ORACLE_DB_ID_TYPES[index] + ".",
-            False
-            )
-
-
-def read_password(passwordDefault=PG_DEFAULT_PASSWORD,
-                  passwordPattern=PASSWORD_PATTERN,
-                  passwordPrompt=None,
-                  passwordDescr=None):
-  # setup password
-  if passwordPrompt is None:
-    passwordPrompt = 'Password (' + passwordDefault + '): '
-
-  if passwordDescr is None:
-    passwordDescr = "Invalid characters in password. Use only alphanumeric or " \
-                    "_ or - characters"
-
-  password = get_validated_string_input(passwordPrompt, passwordDefault,
-                                        passwordPattern, passwordDescr, True)
-
-  if not password:
-    print 'Password cannot be blank.'
-    return read_password(passwordDefault, passwordPattern, passwordPrompt,
-                   passwordDescr)
-
-  if password != passwordDefault:
-    password1 = get_validated_string_input("Re-enter password: ",
-                                           passwordDefault, passwordPattern, passwordDescr, True)
-    if password != password1:
-      print "Passwords do not match"
-      return read_password(passwordDefault, passwordPattern, passwordPrompt,
-                      passwordDescr)
-
-  return password
-
-
-def get_pass_file_path(conf_file):
-  return os.path.join(os.path.dirname(conf_file),
-                      JDBC_PASSWORD_FILENAME)
-
-
-# Set database properties to default values
-def load_default_db_properties(args):
-  args.persistence_type = 'local'
-  args.dbms = DATABASE_TYPES[DATABASE_INDEX]
-  args.database_host = "localhost"
-  args.database_port = DATABASE_PORTS[DATABASE_INDEX]
-  args.database_name = DEFAULT_DB_NAME
-  args.postgres_schema = DEFAULT_DB_NAME
-  args.database_username = "ambari"
-  args.database_password = "bigdata"
-  args.sid_or_sname = "sname"
-  pass
-
-
-# Ask user for database conenction properties
-def prompt_db_properties(args):
-  global DATABASE_INDEX
-
-  if PROMPT_DATABASE_OPTIONS:
-    load_default_db_properties(args)
-    ok = get_YN_input("Enter advanced database configuration [y/n] (n)? ", False)
-    if ok:
-
-      print "=============================================================================="
-      print "Choose one of the following options:"
-
-      database_num = str(DATABASE_INDEX + 1)
-      database_num = get_validated_string_input(
-        "[1] - PostgreSQL (Embedded)\n[2] - Oracle\n[3] - MySQL\n[4] - PostgreSQL\n"
-        "==============================================================================\n"
-        "Enter choice (" + database_num + "): ",
-        database_num,
-        "^[1234]$",
-        "Invalid number.",
-        False
-      )
-
-      if int(database_num) == 1:
-        args.persistence_type = 'local'
-        args.database_index = 0
-      else:
-        args.persistence_type = 'remote'
-        selected_db_option = int(database_num)
-
-        if selected_db_option == 2:
-          args.database_index = 1
-        elif selected_db_option == 3:
-          args.database_index = 2
-        elif selected_db_option == 4:
-          args.database_index = 0
-        else:
-          print_info_msg('Unknown db option, default to embbeded postgres.')
-          args.database_index = 0
-        pass
-      pass
-
-      DATABASE_INDEX = args.database_index
-      args.dbms = DATABASE_TYPES[args.database_index]
-
-      if args.persistence_type != 'local':
-        args.database_host = get_validated_string_input(
-          "Hostname (" + args.database_host + "): ",
-          args.database_host,
-          "^[a-zA-Z0-9.\-]*$",
-          "Invalid hostname.",
-          False
-        )
-
-        args.database_port = DATABASE_PORTS[DATABASE_INDEX]
-        args.database_port = get_validated_string_input(
-          "Port (" + args.database_port + "): ",
-          args.database_port,
-          "^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$",
-          "Invalid port.",
-          False
-        )
-
-        if args.dbms == "oracle":
-          # Oracle uses service name or service id
-          idType = "1"
-          idType = get_validated_string_input(
-            "Select Oracle identifier type:\n1 - " + ORACLE_DB_ID_TYPES[0] +
-            "\n2 - " + ORACLE_DB_ID_TYPES[1] + "\n(" + idType + "): ",
-            idType,
-            "^[12]$",
-            "Invalid number.",
-            False
-          )
-
-          if idType == "2":
-            args.sid_or_sname = "sid"
-
-          IDTYPE_INDEX = int(idType) - 1
-          args.database_name = get_validated_service_name(args.database_name,
-                                                          IDTYPE_INDEX)
-        elif args.dbms in ["mysql", "postgres"]:
-          args.database_name = get_validated_db_name(args.database_name)
-
-          if args.dbms in ["postgres", ]:
-              args.postgres_schema = get_validated_db_schema(args.postgres_schema)
-        else:
-          # other DB types
-          pass
-        pass
-      else:
-        args.database_host = "localhost"
-        args.database_port = DATABASE_PORTS[DATABASE_INDEX]
-
-        args.database_name = get_validated_db_name(args.database_name)
-        if args.dbms in ["postgres", ]:
-            args.postgres_schema = get_validated_db_schema(args.postgres_schema)
-
-      # Username is common for Oracle/MySQL/Postgres
-      args.database_username = get_validated_string_input(
-        'Username (' + args.database_username + '): ',
-        args.database_username,
-        USERNAME_PATTERN,
-        "Invalid characters in username. Start with _ or alpha "
-        "followed by alphanumeric or _ or - characters",
-        False
-      )
-      args.database_password = configure_database_password(True)
-
-  print_info_msg('Using database options: {database},{host},{port},{name},{schema},{user},{password}'.format(
-    database=args.dbms,
-    host=args.database_host,
-    port=args.database_port,
-    name=args.database_name,
-    schema=args.postgres_schema,
-    user=args.database_username,
-    password=args.database_password
-  ))
-
-# extract the system views
-def extract_views():
-  jdk_path = find_jdk()
-  if jdk_path is None:
-    print_error_msg("No JDK found, please run the \"setup\" "
-                    "command to install a JDK automatically or install any "
-                    "JDK manually to " + configDefaults.JDK_INSTALL_DIR)
-    return 1
-
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  if not VIEWS_DIR_PROPERTY in properties.keys():
-    vdir = DEFAULT_VIEWS_DIR
-  else:
-    vdir = properties.get_property(VIEWS_DIR_PROPERTY)
-
-  files = [f for f in os.listdir(vdir) if os.path.isfile(os.path.join(vdir,f))]
-  for f in files:
-
-    command = VIEW_EXTRACT_CMD.format(jdk_path, get_conf_dir(),
-      get_ambari_classpath(), os.path.join(vdir,f))
-
-    retcode, stdout, stderr = run_os_command(command)
-    if retcode == 0:
-      sys.stdout.write(f + "\n")
-    elif retcode == 2:
-      sys.stdout.write("Error extracting " + f + "\n")
-    else:
-      sys.stdout.write(".")
-      sys.stdout.flush()
-
-    print_info_msg("Return code from extraction of view archive " + f + ": " +
-                   str(retcode))
-
-  sys.stdout.write("\n")
-  return 0
-
-# Store set of properties for remote database connection
-def store_remote_properties(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  isSecure = get_is_secure(properties)
-
-  properties.process_pair(PERSISTENCE_TYPE_PROPERTY, "remote")
-
-  properties.process_pair(JDBC_DATABASE_PROPERTY, args.dbms)
-  properties.process_pair(JDBC_HOSTNAME_PROPERTY, args.database_host)
-  properties.process_pair(JDBC_PORT_PROPERTY, args.database_port)
-  properties.process_pair(JDBC_DATABASE_NAME_PROPERTY, args.database_name)
-  if args.dbms == "postgres":
-    properties.process_pair(JDBC_POSTGRES_SCHEMA_PROPERTY, args.postgres_schema)
-  properties.process_pair(JDBC_DRIVER_PROPERTY, DATABASE_DRIVER_NAMES[DATABASE_INDEX])
-  # fully qualify the hostname to make sure all the other hosts can connect
-  # to the jdbc hostname since its passed onto the agents for RCA
-  jdbc_hostname = args.database_host
-  if (args.database_host == "localhost"):
-    jdbc_hostname = socket.getfqdn().lower()
-
-  connectionStringFormat = DATABASE_CONNECTION_STRINGS
-  if args.sid_or_sname == "sid":
-    connectionStringFormat = DATABASE_CONNECTION_STRINGS_ALT
-  properties.process_pair(JDBC_URL_PROPERTY, connectionStringFormat[DATABASE_INDEX].format(jdbc_hostname, args.database_port, args.database_name))
-  properties.process_pair(JDBC_USER_NAME_PROPERTY, args.database_username)
-  properties.process_pair(JDBC_PASSWORD_PROPERTY,
-      store_password_file(args.database_password, JDBC_PASSWORD_FILENAME))
-
-  # save any other defined properties to pass to JDBC
-  if DATABASE_INDEX < len(DATABASE_JDBC_PROPERTIES):
-    for pair in DATABASE_JDBC_PROPERTIES[DATABASE_INDEX]:
-      properties.process_pair(JDBC_PROPERTIES_PREFIX + pair[0], pair[1])
-
-  if isSecure:
-    encrypted_password = encrypt_password(JDBC_RCA_PASSWORD_ALIAS, args.database_password)
-    if encrypted_password != args.database_password:
-      properties.process_pair(JDBC_PASSWORD_PROPERTY, encrypted_password)
-  pass
-
-  properties.process_pair(JDBC_RCA_DRIVER_PROPERTY, DATABASE_DRIVER_NAMES[DATABASE_INDEX])
-  properties.process_pair(JDBC_RCA_URL_PROPERTY, connectionStringFormat[DATABASE_INDEX].format(jdbc_hostname, args.database_port, args.database_name))
-  properties.process_pair(JDBC_RCA_USER_NAME_PROPERTY, args.database_username)
-  properties.process_pair(JDBC_RCA_PASSWORD_FILE_PROPERTY,
-      store_password_file(args.database_password, JDBC_PASSWORD_FILENAME))
-  if isSecure:
-    encrypted_password = encrypt_password(JDBC_RCA_PASSWORD_ALIAS, args.database_password)
-    if encrypted_password != args.database_password:
-      properties.process_pair(JDBC_RCA_PASSWORD_FILE_PROPERTY, encrypted_password)
-  pass
-
-  conf_file = properties.fileName
-
-  try:
-    properties.store(open(conf_file, "w"))
-  except Exception, e:
-    print 'Could not write ambari config file "%s": %s' % (conf_file, e)
-    return -1
-
-  return 0
-
-
-# Initialize remote database schema
-def setup_remote_db(args):
-
-  setup_msg = "Before starting Ambari Server, you must run the following DDL " \
-              "against the database to create the schema: {0}".format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
-
-  print_warning_msg(setup_msg)
-
-  proceed = get_YN_input("Proceed with configuring remote database connection properties [y/n] (y)? ", True)
-  retCode = 0 if proceed else -1
-
-  return retCode
-
-
-# Get database client executable path
-def get_db_cli_tool(args):
-  for tool in DATABASE_CLI_TOOLS[DATABASE_INDEX]:
-    cmd = CHECK_COMMAND_EXIST_CMD.format(tool)
-    ret, out, err = run_in_shell(cmd)
-    if ret == 0:
-      return get_exec_path(tool)
-
-  return None
-
-#execute SQL script on remote database: Deprecated
-def execute_remote_script(args, scriptPath):
-  print_warning_msg("Deprecated method called.")
-  tool = get_db_cli_tool(args)
-  if not tool:
-    # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    if get_verbose():
-      print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    return -1, "Client wasn't found", "Client wasn't found"
-  CMD = get_remote_script_line(args, scriptPath, False)
-  if CMD:
-    retcode, out, err = run_in_shell(CMD)
-    return retcode, out, err
-  else:
-    return -2, "Wrong database", "Wrong database"
-
-
-def get_remote_script_line(args, scriptPath, forPrint=True):
-  tool = get_db_cli_tool(args)
-  if not tool:
-    # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    if get_verbose() or args.persistence_type == "remote":
-      print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    return None
-  if args.dbms == "postgres":
-    os.environ["PGPASSWORD"] = args.database_password
-    return '{0} {1}'.format(tool, POSTGRES_EXEC_ARGS.format(
-      args.database_host,
-      args.database_port,
-      args.database_name,
-      args.database_username,
-      scriptPath
-    ))
-  elif args.dbms == "oracle":
-    sid_or_sname = "sid"
-    if (hasattr(args, 'sid_or_sname') and args.sid_or_sname == "sname") or \
-        (hasattr(args, 'jdbc_url') and args.jdbc_url and re.match(ORACLE_SNAME_PATTERN, args.jdbc_url)):
-      print_info_msg("using SERVICE_NAME instead of SID for Oracle")
-      sid_or_sname = "service_name"
-
-    return '{0} {1}'.format(tool, ORACLE_EXEC_ARGS.format(
-      args.database_username,
-      args.database_password if not forPrint else BLIND_PASSWORD,
-      args.database_host,
-      args.database_port,
-      args.database_name,
-      scriptPath,
-      sid_or_sname
-    ))
-  elif args.dbms == "mysql":
-    MYSQL_EXEC_ARGS = MYSQL_EXEC_ARGS_WO_USER_VARS if MYSQL_INIT_SCRIPT == scriptPath else MYSQL_EXEC_ARGS_WITH_USER_VARS
-    return '{0} {1}'.format(tool, MYSQL_EXEC_ARGS.format(
-      args.database_host,
-      args.database_port,
-      args.database_username,
-      args.database_password if not forPrint else BLIND_PASSWORD,
-      args.database_name,
-      scriptPath
-    ))
-
-  return None
-
-
-def configure_database_password(showDefault=True):
-  passwordDefault = PG_DEFAULT_PASSWORD
-  if showDefault:
-    passwordPrompt = 'Enter Database Password (' + passwordDefault + '): '
-  else:
-    passwordPrompt = 'Enter Database Password: '
-  passwordPattern = "^[a-zA-Z0-9_-]*$"
-  passwordDescr = "Invalid characters in password. Use only alphanumeric or "\
-                  "_ or - characters"
-
-  password = read_password(passwordDefault, passwordPattern, passwordPrompt,
-    passwordDescr)
-
-  return password
-
-
-def get_ambari_version(properties):
-  """
-  :param properties: Ambari properties
-  :return: Return a string of the ambari version. When comparing versions, please use "compare_versions" function.
-  """
-  version = None
-  try:
-    server_version_file_path = properties[SERVER_VERSION_FILE_PATH]
-    if server_version_file_path and os.path.exists(server_version_file_path):
-      with open(server_version_file_path, 'r') as file:
-        version = file.read().strip()
-  except:
-    print_error_msg("Error getting ambari version")
-  return version
-
-
-def get_db_type(properties):
-  db_type = None
-  if properties[JDBC_URL_PROPERTY]:
-    jdbc_url = properties[JDBC_URL_PROPERTY].lower()
-    if "postgres" in jdbc_url:
-      db_type = "postgres"
-    elif "oracle" in jdbc_url:
-      db_type = "oracle"
-    elif "mysql" in jdbc_url:
-      db_type = "mysql"
-    elif "derby" in jdbc_url:
-      db_type = "derby"
-
-  return db_type
-
-
-def check_database_name_property(args, upgrade=False):
-  """
-  :param upgrade: If Ambari is being upgraded.
-  :return:
-  """
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  version = get_ambari_version(properties)
-  if upgrade and compare_versions(version, "1.7.0") == 0:
-
-    # This code exists for historic reasons in which property names changed from Ambari 1.6.1 to 1.7.0
-    persistence_type = properties[PERSISTENCE_TYPE_PROPERTY]
-    if persistence_type == "remote":
-      db_name = properties["server.jdbc.schema"]  # this was a property in Ambari 1.6.1, but not after 1.7.0
-      if db_name:
-        write_property(JDBC_DATABASE_NAME_PROPERTY, db_name)
-
-      # If DB type is missing, attempt to reconstruct it from the JDBC URL
-      db_type = properties[JDBC_DATABASE_PROPERTY]
-      if db_type is None or db_type.strip().lower() not in ["postgres", "oracle", "mysql", "derby"]:
-        db_type = get_db_type(properties)
-        if db_type:
-          write_property(JDBC_DATABASE_PROPERTY, db_type)
-
-      properties = get_ambari_properties()
-    elif persistence_type == "local":
-      # Ambari 1.6.1, had "server.jdbc.database" as the DB name, and the
-      # DB type was assumed to be "postgres" if was embedded ("local")
-      db_name = properties[JDBC_DATABASE_PROPERTY]
-      if db_name:
-        write_property(JDBC_DATABASE_NAME_PROPERTY, db_name)
-        write_property(JDBC_DATABASE_PROPERTY, "postgres")
-        properties = get_ambari_properties()
-
-  dbname = properties[JDBC_DATABASE_NAME_PROPERTY]
-  if dbname is None or dbname == "":
-    err = "DB Name property not set in config file.\n" + SETUP_OR_UPGRADE_MSG
-    raise FatalException(-1, err)
-
-
-def configure_database_username_password(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  username = properties[JDBC_USER_NAME_PROPERTY]
-  passwordProp = properties[JDBC_PASSWORD_PROPERTY]
-  dbname = properties[JDBC_DATABASE_NAME_PROPERTY]
-
-  if username and passwordProp and dbname:
-    print_info_msg("Database username + password already configured")
-    args.database_username = username
-    args.database_name = dbname
-    if is_alias_string(passwordProp):
-      args.database_password = decrypt_password_for_alias(JDBC_RCA_PASSWORD_ALIAS)
-    else:
-      if os.path.exists(passwordProp):
-        with open(passwordProp, 'r') as file:
-          args.database_password = file.read()
-
-    return 1
-  else:
-    print_error_msg("Connection properties not set in config file.")
-
-
-# Check if jdbc user is changed
-def is_jdbc_user_changed(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return None
-
-  previos_user = properties[JDBC_USER_NAME_PROPERTY]
-  new_user = args.database_username
-
-  if previos_user and new_user:
-    if previos_user != new_user:
-      return True
-    else:
-      return False
-
-  return None
-
-
-# Store local database connection properties
-def store_local_properties(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  isSecure = get_is_secure(properties)
-
-  properties.removeOldProp(JDBC_DATABASE_PROPERTY)
-  properties.removeOldProp(JDBC_DATABASE_NAME_PROPERTY)
-  properties.removeOldProp(JDBC_POSTGRES_SCHEMA_PROPERTY)
-  properties.removeOldProp(JDBC_HOSTNAME_PROPERTY)
-  properties.removeOldProp(JDBC_RCA_DRIVER_PROPERTY)
-  properties.removeOldProp(JDBC_RCA_URL_PROPERTY)
-  properties.removeOldProp(JDBC_PORT_PROPERTY)
-  properties.removeOldProp(JDBC_DRIVER_PROPERTY)
-  properties.removeOldProp(JDBC_URL_PROPERTY)
-
-  # Store the properties
-  properties.process_pair(PERSISTENCE_TYPE_PROPERTY, "local")
-  properties.process_pair(JDBC_DATABASE_PROPERTY, args.dbms)
-  properties.process_pair(JDBC_DATABASE_NAME_PROPERTY, args.database_name)
-  if args.dbms == "postgres":
-    properties.process_pair(JDBC_POSTGRES_SCHEMA_PROPERTY, args.postgres_schema)
-  properties.process_pair(JDBC_USER_NAME_PROPERTY, args.database_username)
-  properties.process_pair(JDBC_PASSWORD_PROPERTY,
-      store_password_file(args.database_password, JDBC_PASSWORD_FILENAME))
-
-  if isSecure:
-    encrypted_password = encrypt_password(JDBC_RCA_PASSWORD_ALIAS, args.database_password)
-    if args.database_password != encrypted_password:
-      properties.process_pair(JDBC_PASSWORD_PROPERTY, encrypted_password)
-    pass
-  pass
-
-  conf_file = properties.fileName
-
-  try:
-    properties.store(open(conf_file, "w"))
-  except Exception, e:
-    print 'Unable to write ambari.properties configuration file "%s": %s' % (conf_file, e)
-    return -1
-  return 0
-
-
-# Load ambari properties and return dict with values
-def get_ambari_properties():
-  conf_file = find_properties_file()
-
-  properties = None
-  try:
-    properties = Properties()
-    properties.load(open(conf_file))
-  except (Exception), e:
-    print 'Could not read "%s": %s' % (conf_file, e)
-    return -1
-  return properties
-
-
-# Load database connection properties from conf file
-def parse_properties_file(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  args.server_version_file_path = properties[SERVER_VERSION_FILE_PATH]
-  args.persistence_type = properties[PERSISTENCE_TYPE_PROPERTY]
-  args.jdbc_url = properties[JDBC_URL_PROPERTY]
-
-  args.dbms = properties[JDBC_DATABASE_PROPERTY]
-  if not args.persistence_type:
-    args.persistence_type = "local"
-
-  if args.persistence_type == 'remote':
-    args.database_host = properties[JDBC_HOSTNAME_PROPERTY]
-    args.database_port = properties[JDBC_PORT_PROPERTY]
-    global DATABASE_INDEX
-    try:
-      DATABASE_INDEX = DATABASE_TYPES.index(args.dbms)
-    except ValueError:
-      pass
-
-  args.database_name = properties[JDBC_DATABASE_NAME_PROPERTY]
-  args.postgres_schema = properties[JDBC_POSTGRES_SCHEMA_PROPERTY] \
-      if JDBC_POSTGRES_SCHEMA_PROPERTY in properties.propertyNames() else None
-  args.database_username = properties[JDBC_USER_NAME_PROPERTY]
-  args.database_password_file = properties[JDBC_PASSWORD_PROPERTY]
-  if args.database_password_file:
-    if not is_alias_string(args.database_password_file):
-      args.database_password = open(properties[JDBC_PASSWORD_PROPERTY]).read()
-    else:
-      args.database_password = args.database_password_file
-
-  return 0
-
-
-### JDK ###
-
-
-def get_ambari_jars():
-  try:
-    conf_dir = os.environ[AMBARI_SERVER_LIB]
-    return conf_dir
-  except KeyError:
-    default_jar_location = "/usr/lib/ambari-server"
-    print_info_msg(AMBARI_SERVER_LIB + " is not set, using default "
-                 + default_jar_location)
-    return default_jar_location
-
-
-def get_share_jars():
-  share_jars = ""
-  file_list = []
-  file_list.extend(glob.glob(JAVA_SHARE_PATH + os.sep + "*mysql*"))
-  file_list.extend(glob.glob(JAVA_SHARE_PATH + os.sep + "*ojdbc*"))
-  if len(file_list) > 0:
-    share_jars = string.join(file_list, os.pathsep)
-  return share_jars
-
-
-def get_ambari_classpath():
-  ambari_cp = get_ambari_jars() + os.sep + "*"
-  share_cp = get_share_jars()
-  if len(share_cp) > 0:
-    ambari_cp = ambari_cp + os.pathsep + share_cp
-  return ambari_cp
-
-
-def dlprogress(base_name, count, blockSize, totalSize):
-  percent = int(count * blockSize * 100 / totalSize)
-
-  if (totalSize < blockSize):
-    sys.stdout.write("\r" + base_name + "... %d%%" % (100))
-  else:
-    sys.stdout.write("\r" + base_name + "... %d%% (%.1f MB of %.1f MB)" % (
-      percent, count * blockSize / 1024 / 1024.0, totalSize / 1024 / 1024.0))
-
-  if (percent == 100 or totalSize < blockSize):
-    sys.stdout.write("\n")
-  sys.stdout.flush()
-
-
-def track_jdk(base_name, url, local_name):
-  u = urllib2.urlopen(url)
-  h = u.info()
-  totalSize = int(h["Content-Length"])
-  fp = open(local_name, "wb")
-  blockSize = 8192
-  count = 0
-  while True:
-    chunk = u.read(blockSize)
-    if not chunk:
-      break
-    fp.write(chunk)
-    count += 1
-
-    dlprogress(base_name, count, blockSize, totalSize)
-
-  fp.flush()
-  fp.close()
-
-
-def install_jce_manualy(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    err = "Error getting ambari properties"
-    raise FatalException(-1, err)
-  if args.jce_policy:
-    if os.path.exists(args.jce_policy):
-      if os.path.isdir(args.jce_policy):
-        err = "JCE Policy path is a directory: " + args.jce_policy
-        raise FatalException(-1, err)
-      jce_destination = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAMES[JDK_INDEX])
-      try:
-        shutil.copy(args.jce_policy, jce_destination)
-      except Exception, e:
-        err = "Can not copy file {0} to {1} due to: {2}. Please check file " \
-              "permissions and free disk space.".format(args.jce_policy, jce_destination, e)
-        raise FatalException(-1, err)
-      print "JCE policy copied from " + args.jce_policy + " to " + jce_destination
-      return 0
-    else:
-      err = "JCE Policy path " + args.jce_policy + " doesn't exists."
-      raise FatalException(-1, err)
-  else:
-    return 1
-
-
-#
-# Downloads the JDK
-#
-def download_jdk(args):
-  global JDK_INDEX
-  properties = get_ambari_properties()
-  if properties == -1:
-    err = "Error getting ambari properties"
-    raise FatalException(-1, err)
-  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:
-    if not os.path.exists(args.java_home) or not os.path.isfile(os.path.join(args.java_home, "bin", "java")):
-      err = "Path to java home " + args.java_home + " or java binary file does not exists"
-      raise FatalException(1, err)
-
-    print_warning_msg("JAVA_HOME " + args.java_home + " must be valid on ALL hosts")
-    print_warning_msg(jcePolicyWarn)
-    write_property(JAVA_HOME_PROPERTY, args.java_home)
-    remove_property(JDK_NAME_PROPERTY)
-    remove_property(JCE_NAME_PROPERTY)
-    return 0
-  else:
-    if get_JAVA_HOME():
-      change_jdk = get_YN_input("Do you want to change Oracle JDK [y/n] (n)? ", False)
-      if not change_jdk:
-        return 0
-
-    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_num = str(JDK_INDEX + 1)
-    jdk_num = get_validated_string_input(
-"""[1] - Oracle JDK 1.7 + Java Cryptography Extension (JCE) Policy Files 7
-[2] - Oracle JDK 1.6 + Java Cryptography Extension (JCE) Policy Files 6
-[3] - Custom JDK
-==============================================================================
-Enter choice (""" + jdk_num + "):",
-      jdk_num,
-      "^[123]$",
-      "Invalid number.",
-      False
-    )
-
-    if jdk_num == 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)
-      if not os.path.exists(args.java_home) or not os.path.isfile(os.path.join(args.java_home, "bin", "java")):
-        err = "Java home path or java binary file is unavailable. Please put correct path to java home."
-        raise FatalException(1, err)
-      print "Validating JDK on Ambari Server...done."
-      write_property(JAVA_HOME_PROPERTY, args.java_home)
-      remove_property(JDK_NAME_PROPERTY)
-      remove_property(JCE_NAME_PROPERTY)
-      return 0
-
-    JDK_INDEX = int(jdk_num) - 1
-    JDK_FILENAME = JDK_NAMES[JDK_INDEX]
-    JDK_URL_PROPERTY = JDK_URL_PROPERTIES[JDK_INDEX]
-
-    try:
-      jdk_url = properties[JDK_URL_PROPERTY]
-    except (KeyError), e:
-      err = 'Property ' + str(e) + ' is not defined at ' + conf_file
-      raise FatalException(1, err)
-    dest_file = resources_dir + os.sep + JDK_FILENAME
-    if os.path.exists(dest_file):
-      print "JDK already exists, using " + dest_file
-    else:
-      ok = get_YN_input("To download the Oracle JDK and the Java Cryptography Extension (JCE) "
-                        "Policy Files you must accept the "
-                        "license terms found at "
-                        "http://www.oracle.com/technetwork/java/javase/"
-                        "terms/license/index.html and not accepting will "
-                        "cancel the Ambari Server setup and you must install the JDK and JCE "
-                        "files manually.\nDo you accept the "
-                        "Oracle Binary Code License Agreement [y/n] (y)? ", True)
-      if not ok:
-        print 'Exiting...'
-        sys.exit(1)
-
-      print 'Downloading JDK from ' + jdk_url + ' to ' + dest_file
-      jdk_download_fail_msg = " Failed to download JDK: {0}. Please check that Oracle " \
-        "JDK is available at {1}. Also you may specify JDK file " \
-        "location in local filesystem using --jdk-location command " \
-        "line argument.".format("{0}", jdk_url)
-      try:
-        size_command = JDK_DOWNLOAD_SIZE_CMD.format(jdk_url)
-        #Get Header from url,to get file size then
-        retcode, out, err = run_os_command(size_command)
-        if out.find("Content-Length") == -1:
-          err = jdk_download_fail_msg.format("Request header doesn't contain Content-Length")
-          raise FatalException(1, err)
-        start_with = int(out.find("Content-Length") + len("Content-Length") + 2)
-        end_with = out.find("\r\n", start_with)
-        src_size = int(out[start_with:end_with])
-        print 'JDK distribution size is ' + str(src_size) + ' bytes'
-        file_exists = os.path.isfile(dest_file)
-        file_size = -1
-        if file_exists:
-          file_size = os.stat(dest_file).st_size
-        if file_exists and file_size == src_size:
-          print_info_msg("File already exists")
-        else:
-          track_jdk(JDK_FILENAME, jdk_url, dest_file)
-          print 'Successfully downloaded JDK distribution to ' + dest_file
-      except FatalException:
-        raise
-      except Exception, e:
-        err = jdk_download_fail_msg.format(str(e))
-        raise FatalException(1, err)
-      downloaded_size = os.stat(dest_file).st_size
-      if downloaded_size != src_size or downloaded_size < JDK_MIN_FILESIZE:
-        err = 'Size of downloaded JDK distribution file is ' \
-                      + str(downloaded_size) + ' bytes, it is probably \
-                      damaged or incomplete'
-        raise FatalException(1, err)
-
-    try:
-       out = install_jdk(dest_file)
-       jdk_version = re.search(JDK_VERSION_REs[JDK_INDEX], out).group(1)
-       write_property(JDK_NAME_PROPERTY, JDK_FILENAME)
-    except Exception, e:
-       print "Installation of JDK has failed: %s\n" % e
-       file_exists = os.path.isfile(dest_file)
-       if file_exists:
-          ok = get_YN_input("JDK found at "+dest_file+". "
-                      "Would you like to re-download the JDK [y/n] (y)? ", True)
-          if not ok:
-             err = "Unable to install JDK. Please remove JDK file found at " + \
-                   dest_file + " and re-run Ambari Server setup"
-             raise FatalException(1, err)
-          else:
-             track_jdk(JDK_FILENAME, jdk_url, dest_file)
-             print 'Successfully re-downloaded JDK distribution to ' + dest_file
-             try:
-                 out = install_jdk(dest_file)
-                 jdk_version = re.search(JDK_VERSION_REs[JDK_INDEX], out).group(1)
-                 write_property(JDK_NAME_PROPERTY, JDK_FILENAME)
-             except Exception, e:
-               print "Installation of JDK was failed: %s\n" % e
-               err = "Unable to install JDK. Please remove JDK, file found at " + \
-                     dest_file + " and re-run Ambari Server setup"
-               raise FatalException(1, err)
-
-       else:
-           err = "Unable to install JDK. File " + dest_file + " does not exist, " \
-                                        "please re-run Ambari Server setup"
-           raise FatalException(1, err)
-
-    print "Successfully installed JDK to {0}/{1}".\
-        format(configDefaults.JDK_INSTALL_DIR, jdk_version)
-    write_property(JAVA_HOME_PROPERTY, "{0}/{1}".
-        format(configDefaults.JDK_INSTALL_DIR, jdk_version))
-
-  try:
-    download_jce_policy(properties, ok)
-  except FatalException as e:
-    print "JCE Policy files are required for secure HDP setup. Please ensure " \
-            " all hosts have the JCE unlimited strength policy 6, files."
-    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?
-  return 0
-
-
-def download_jce_policy(properties, accpeted_bcl):
-  JCE_URL_PROPERTY = JCE_URL_PROPERTIES[JDK_INDEX]
-  JCE_POLICY_FILENAME = JCE_POLICY_FILENAMES[JDK_INDEX]
-  try:
-    jce_url = properties[JCE_URL_PROPERTY]
-    resources_dir = properties[RESOURCES_DIR_PROPERTY]
-  except KeyError, e:
-    err = 'Property ' + str(e) + ' is not defined in properties file'
-    raise FatalException(1, err)
-  dest_file = resources_dir + os.sep + JCE_POLICY_FILENAME
-  if not os.path.exists(dest_file):
-    print 'Downloading JCE Policy archive from ' + jce_url + ' to ' + dest_file
-    jce_download_fail_msg = " Failed to download JCE Policy archive : {0}. " \
-        "Please check that JCE Policy archive is available at {1} . "
-    try:
-      size_command = JDK_DOWNLOAD_SIZE_CMD.format(jce_url)
-      #Get Header from url,to get file size then
-      retcode, out, err = run_os_command(size_command)
-      if out.find("Content-Length") == -1:
-        err = jce_download_fail_msg.format(
-            "Request header doesn't contain Content-Length")
-        raise FatalException(1, err)
-      start_with = int(out.find("Content-Length") + len("Content-Length") + 2)
-      end_with = out.find("\r\n", start_with)
-      src_size = int(out[start_with:end_with])
-      print_info_msg('JCE zip distribution size is ' + str(src_size) + ' bytes')
-      file_exists = os.path.isfile(dest_file)
-      file_size = -1
-      if file_exists:
-        file_size = os.stat(dest_file).st_size
-      if file_exists and file_size == src_size:
-        print_info_msg("File already exists")
-      else:
-        #BCL license before download
-        jce_download_cmd = JCE_DOWNLOAD_CMD.format(dest_file, jce_url)
-        print_info_msg("JCE download cmd: " + jce_download_cmd)
-        if accpeted_bcl:
-          retcode, out, err = run_os_command(jce_download_cmd)
-          if retcode == 0:
-            write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
-            print 'Successfully downloaded JCE Policy archive to ' + dest_file
-          else:
-            raise FatalException(1, err)
-        else:
-          ok = get_YN_input("To download the JCE Policy files you must "
-                            "accept the license terms found at "
-                            "http://www.oracle.com/technetwork/java/javase"
-                            "/terms/license/index.html"
-                            "Not accepting will result in errors when "
-                            "configuring Kerberos security. \nDo you accept the "
-                            "Oracle Binary Code License Agreement [y/n] (y)? ", True)
-          if ok:
-            retcode, out, err = run_os_command(jce_download_cmd)
-            if retcode == 0:
-              write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
-              print 'Successfully downloaded JCE Policy archive to ' + dest_file
-          else:
-            raise FatalException(1, None)
-    except FatalException:
-        raise
-    except Exception, e:
-      err = 'Failed to download JCE Policy archive: ' + str(e)
-      raise FatalException(1, err)
-    downloaded_size = os.stat(dest_file).st_size
-    if downloaded_size != src_size or downloaded_size < JCE_MIN_FILESIZE:
-      err = 'Size of downloaded JCE Policy archive is ' \
-                      + str(downloaded_size) + ' bytes, it is probably \
-                    damaged or incomplete'
-      raise FatalException(1, err)
-  else:
-    write_property(JCE_NAME_PROPERTY, JCE_POLICY_FILENAME)
-    print "JCE Policy archive already exists, using " + dest_file
-
-
-class RetCodeException(Exception):
-  pass
-
-
-def install_jdk(dest_file):
-  print "Installing JDK to {0}".format(configDefaults.JDK_INSTALL_DIR)
-  retcode, out, err = run_os_command(CREATE_JDK_DIR_CMD)
-  retcode, out, err = run_os_command(MAKE_FILE_EXECUTABLE_CMD.format(configDefaults.JDK_INSTALL_DIR))
-  savedPath = os.getcwd()
-  os.chdir(configDefaults.JDK_INSTALL_DIR)
-
-  if dest_file.endswith(".bin"):
-    retcode, out, err = run_os_command(MAKE_FILE_EXECUTABLE_CMD.format(dest_file))
-    retcode, out, err = run_os_command(dest_file + ' -noregister')
-  elif dest_file.endswith(".gz"):
-    retcode, out, err = run_os_command(UNTAR_JDK_ARCHIVE.format(dest_file))
-  else:
-    err = "JDK installation failed.Unknown file mask."
-    raise FatalException(1, err)
-
-  os.chdir(savedPath)
-  if retcode != 0:
-    err = "Installation of JDK returned exit code %s" % retcode
-    raise FatalException(retcode, err)
-  return out
-
-
-#
-# Configures the OS settings in ambari properties.
-#
-def configure_os_settings():
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-  try:
-    conf_os_type = properties[OS_TYPE_PROPERTY]
-    if conf_os_type != '':
-      print_info_msg("os_type already setting in properties file")
-      return 0
-  except (KeyError):
-    print_error_msg("os_type is not set in properties file")
-
-  os_system = platform.system()
-  if os_system != 'Linux':
-    print_error_msg("Non-Linux systems are not supported")
-    return -1
-
-  # to check server/agent compatibility
-  master_os_family = OS_FAMILY + OS_VERSION
-  # to check supported os_types
-  master_os_type = OS_TYPE + OS_VERSION
-
-  write_property(OS_FAMILY_PROPERTY, master_os_family)
-  write_property(OS_TYPE_PROPERTY, master_os_type)
-  return 0
-
-
-def get_JAVA_HOME():
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return None
-
-  java_home = properties[JAVA_HOME_PROPERTY]
-
-  if (not 0 == len(java_home)) and (os.path.exists(java_home)):
-    return java_home
-
-  return None
-
-
-#
-# Checks jdk path for correctness
-#
-def validate_jdk(jdk_path):
-  if jdk_path:
-    return os.path.exists(jdk_path) and os.path.exists(
-      jdk_path + os.sep + 'bin' + os.sep + 'java')
-  else:
-    return False
-
-
-#
-# Finds the available JDKs.
-#
-def find_jdk():
-  jdkPath = get_JAVA_HOME()
-  if jdkPath:
-    if validate_jdk(jdkPath):
-      return jdkPath
-  print "Looking for available JDKs at " + configDefaults.JDK_INSTALL_DIR
-  jdks = glob.glob(configDefaults.JDK_INSTALL_DIR + os.sep + "jdk*")
-  jdks.sort()
-  print "Found: " + str(jdks)
-  if len(jdks) == 0:
-    return
-  for jdkPath in jdks:
-    print "Trying to use JDK {0}".format(jdkPath)
-    if validate_jdk(jdkPath):
-      print "Selected JDK {0}".format(jdkPath)
-      return jdkPath
-    else:
-      print "JDK {0} is invalid".format(jdkPath)
-  return
-
-
-#Check if required jdbc drivers present
-def find_jdbc_driver(args):
-  if args.dbms in JDBC_PATTERNS.keys():
-    drivers = []
-    drivers.extend(glob.glob(JAVA_SHARE_PATH + os.sep + JDBC_PATTERNS[args.dbms]))
-    if drivers:
-      return drivers
-    return -1
-  return 0
-
-
-def copy_file(src, dest_file):
-  try:
-    shutil.copyfile(src, dest_file)
-  except Exception, e:
-    err = "Can not copy file {0} to {1} due to: {2} . Please check file " \
-              "permissions and free disk space.".format(src, dest_file, e)
-    raise FatalException(1, err)
-
-
-def remove_file(filePath):
-  if os.path.exists(filePath):
-    try:
-      os.remove(filePath)
-    except Exception, e:
-      print_warning_msg('Unable to remove file: ' + str(e))
-      return 1
-  pass
-  return 0
-
-
-def copy_files(files, dest_dir):
-  if os.path.isdir(dest_dir):
-    for filepath in files:
-      shutil.copy(filepath, dest_dir)
-    return 0
-  else:
-    return -1
-
-#
-# Wait for Popen process and returns exit code if process was finished in
-# timeout seconds, otherwise returns None
-#
-def wait_popen(popen, timeout=0):
-  begin = time.time()
-  while popen.poll() is None and not time.time() - begin > timeout:
-    time.sleep(1)
-  return popen.poll()
-
-def check_jdbc_drivers(args):
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  result = find_jdbc_driver(args)
-
-  msg = 'Before starting Ambari Server, ' \
-        'you must copy the {0} JDBC driver JAR file to {1}.'.format(
-        DATABASE_FULL_NAMES[args.dbms],
-        JAVA_SHARE_PATH)
-
-  if result == -1:
-    if get_silent():
-      print_error_msg(msg)
-      raise FatalException(-1, msg)
-    else:
-      print_warning_msg(msg)
-      raw_input(PRESS_ENTER_MSG)
-      result = find_jdbc_driver(args)
-      if result == -1:
-        print_error_msg(msg)
-        raise FatalException(-1, msg)
-
-  # Check if selected RDBMS requires drivers to copy
-  if type(result) is not int:
-    print 'Copying JDBC drivers to server resources...'
-    try:
-      resources_dir = properties[RESOURCES_DIR_PROPERTY]
-    except KeyError:
-      print_error_msg("There is no value for " + RESOURCES_DIR_PROPERTY + "in " + AMBARI_PROPERTIES_FILE)
-      return -1
-
-    db_name = DATABASE_FULL_NAMES[args.dbms].lower()
-    jdbc_symlink = os.path.join(resources_dir, db_name + "-jdbc-driver.jar")
-    db_default_driver_path = os.path.join(JAVA_SHARE_PATH, JDBC_DB_DEFAULT_DRIVER[db_name])
-
-    if os.path.lexists(jdbc_symlink):
-      os.remove(jdbc_symlink)
-
-    copy_status = copy_files(result, resources_dir)
-
-    if not copy_status == 0:
-      raise FatalException(-1, "Failed to copy JDBC drivers to server resources")
-
-    if db_default_driver_path in result:
-      os.symlink(os.path.join(resources_dir, JDBC_DB_DEFAULT_DRIVER[db_name]), jdbc_symlink)
-
-  return 0
-
-
-def verify_setup_allowed():
-  properties = get_ambari_properties()
-  if properties == -1:
-    print_error_msg("Error getting ambari properties")
-    return -1
-
-  isSecure = get_is_secure(properties)
-  (isPersisted, masterKeyFile) = get_is_persisted(properties)
-  if isSecure and not isPersisted and get_silent():
-    print "ERROR: Cannot run silent 'setup' with password encryption enabled " \
-          "and Master Key not persisted."
-    print "Ambari Server 'setup' exiting."
-    return 1
-  return 0
-
-
-#
-# Setup the Ambari Server.
-#
-def setup(args):
-  retcode = verify_setup_allowed()
-  if not retcode == 0:
-    raise FatalException(1, None)
-
-  if not is_root():
-    err = 'Ambari-server setup should be run with '\
-                     'root-level privileges'
-    raise FatalException(4, err)
-
-  # proceed jdbc properties if they were set
-  if args.jdbc_driver is not None and args.jdbc_db is not None:
-    proceedJDBCProperties(args)
-    return
-
-  print 'Checking SELinux...'
-  retcode = check_selinux()
-  if not retcode == 0:
-    err = 'Failed to disable SELinux. Exiting.'
-    raise FatalException(retcode, err)
-
-  # Create ambari user, if needed
-  retcode = check_ambari_user()
-  
-  if not retcode == 0:
-    err = 'Failed to create user. Exiting.'
-    raise FatalException(retcode, err)
-
-  print 'Checking firewall...'
-  firewall_obj = Firewall().getFirewallObject()
-  firewall_on = firewall_obj.check_iptables()
-  if firewall_obj.stderrdata and len(firewall_obj.stderrdata) > 0:
-    print firewall_obj.stderrdata
-  if firewall_on:
-    print_warning_msg("%s is running. Confirm the necessary Ambari ports are accessible. " %
-                      firewall_obj.FIREWALL_SERVICE_NAME +
-                      "Refer to the Ambari documentation for more details on ports.")
-    ok = get_YN_input("OK to continue [y/n] (y)? ", True)
-    if not ok:
-      raise FatalException(1, None)
-
-
-
-
-  # proceed jdbc properties if they were set
-  if args.jdbc_driver is not None and args.jdbc_db is not None:
-    proceedJDBCProperties(args)
-
-  print 'Checking JDK...'
-  try:
-    download_jdk(args)
-  except FatalException as e:
-    err = 'Downloading or installing JDK failed: {0}. Exiting.'.format(e)
-    raise FatalException(e.code, err)
-
-  print 'Completing setup...'
-  retcode = configure_os_settings()
-  if not retcode == 0:
-    err = 'Configure of OS settings in ambari.properties failed. Exiting.'
-    raise FatalException(retcode, err)
-
-  print 'Configuring database...'
-  prompt_db_properties(args)
-
-  #DB setup should be done last after doing any setup.
-
-  if is_local_database(args):
-    #check if jdbc user is changed
-    is_user_changed = is_jdbc_user_changed(args)
-
-    print 'Default properties detected. Using built-in database.'
-    store_local_properties(args)
-
-    print 'Checking PostgreSQL...'
-    pg_status, retcode, out, err = check_postgre_up()
-    if not retcode == 0:
-      err = 'Unable to start PostgreSQL server. Status {0}. {1}.' \
-            ' Exiting'.format(pg_status, err)
-      raise FatalException(retcode, err)
-
-    print 'Configuring local database...'
-    retcode, outdata, errdata = setup_db(args)
-    if not retcode == 0:
-      err = 'Running database init script was failed. {0}. Exiting.'.format(errdata)
-      raise FatalException(retcode, err)
-
-    if is_user_changed:
-      #remove backup for pg_hba in order to reconfigure postgres
-      remove_file(PG_HBA_CONF_FILE_BACKUP)
-
-    print 'Configuring PostgreSQL...'
-    retcode, out, err = configure_postgres()
-    if not retcode == 0:
-      err = 'Unable to configure PostgreSQL server. {0} Exiting'.format(err)
-      raise FatalException(retcode, err)
-
-  else:
-    retcode = store_remote_properties(args)
-    if retcode != 0:
-      err = 'Unable to save config file'
-      raise FatalException(retcode, err)
-
-    check_jdbc_drivers(args)
-
-    print 'Configuring remote database connection properties...'
-    retcode = setup_remote_db(args)
-    if retcode == -1:
-      err = "Remote database setup aborted."
-      raise NonFatalException(err)
-
-    if not retcode == 0:
-      err = 'Error while configuring connection properties. Exiting'
-      raise FatalException(retcode, err)
-    check_jdbc_drivers(args)
-
-  print 'Extracting system views...'
-  retcode = extract_views()
-  if not retcode == 0:
-    err = 'Error while extracting system views. Exiting'
-    raise FatalException(retcode, err)
-  
-  # we've already done this, but new files were created so run it one time.
-  adjust_directory_permissions(read_ambari_user())
+                 "-XX:-UseGCOverheadLimit -XX:CMSInitiatingOccupancyFraction=60 " +\
+                 ambari_provider_module_option +\
+                 os.getenv('AMBARI_JVM_ARGS', '-Xms512m -Xmx2048m') +\
+                 " -cp {1}" + os.pathsep + "{2}" +\
+                 " org.apache.ambari.server.controller.AmbariServer "\
+                 ">" + configDefaults.SERVER_OUT_FILE + " 2>&1 || echo $? > {3} &"
+SERVER_START_CMD_DEBUG = "{0} -server -XX:NewRatio=2 -XX:+UseConcMarkSweepGC " +\
+                       ambari_provider_module_option +\
+                       os.getenv('AMBARI_JVM_ARGS', '-Xms512m -Xmx2048m') +\
+                       " -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,"\
+                       "server=y,suspend={4} -cp {1}" + os.pathsep + "{2}" +\
+                       " org.apache.ambari.server.controller.AmbariServer" \
+                       ">" + configDefaults.SERVER_OUT_FILE + " 2>&1 || echo $? > {3} &"
+SERVER_SEARCH_PATTERN = "org.apache.ambari.server.controller.AmbariServer"
 
 
-def proceedJDBCProperties(args):
-  if not os.path.isfile(args.jdbc_driver):
-    err = "File {0} does not exist!".format(args.jdbc_driver)
-    raise FatalException(1, err)
+ULIMIT_CMD = "ulimit -n"
+SERVER_INIT_TIMEOUT = 5
+SERVER_START_TIMEOUT = 10
 
-  if args.jdbc_db not in JDBC_DB_OPTION_VALUES:
-    err = "Unsupported database name {0}. Please see help for more information.".format(args.jdbc_db)
-    raise FatalException(1, err)
+SSL_KEY_DIR = 'security.server.keys_dir'
+SSL_API_PORT = 'client.api.ssl.port'
+SSL_API = 'api.ssl'
+SSL_SERVER_CERT_NAME = 'client.api.ssl.cert_name'
+SSL_SERVER_KEY_NAME = 'client.api.ssl.key_name'
+SSL_CERT_FILE_NAME = "https.crt"
+SSL_KEY_FILE_NAME = "https.key"
+SSL_KEYSTORE_FILE_NAME = "https.keystore.p12"
+SSL_KEY_PASSWORD_FILE_NAME = "https.pass.txt"
+SSL_KEY_PASSWORD_LENGTH = 50
+DEFAULT_SSL_API_PORT = 8443
+SSL_DATE_FORMAT = '%b  %d %H:%M:%S %Y GMT'
 
-  properties = get_ambari_properties()
-  if properties == -1:
-    err = "Error getting ambari properties"
-    raise FatalException(-1, err)
-  conf_file = properties.fileName
+GANGLIA_HTTPS = 'ganglia.https'
 
-  try:
-    resources_dir = properties[RESOURCES_DIR_PROPERTY]
-  except (KeyError), e:
-    err = 'Property ' + str(e) + ' is not defined at ' + conf_file
-    raise FatalException(1, err)
+CLIENT_SECURITY_KEY = "client.security"
 
-  symlink_name = args.jdbc_db + "-jdbc-driver.jar"
-  jdbc_symlink = os.path.join(resources_dir, symlink_name)
-  path, jdbc_name = os.path.split(args.jdbc_driver)
+EXITCODE_NAME = "ambari-server.exitcode"
 
-  if os.path.lexists(jdbc_symlink):
-    os.remove(jdbc_symlink)
+SRVR_TWO_WAY_SSL_PORT_PROPERTY = "security.server.two_way_ssl.port"
+SRVR_TWO_WAY_SSL_PORT = "8441"
 
-  if not os.path.isfile(os.path.join(resources_dir, jdbc_name)):
-    try:
-      shutil.copy(args.jdbc_driver, resources_dir)
-    except Exception, e:
-      err = "Can not copy file {0} to {1} due to: {2} . Please check file " \
-            "permissions and free disk space.".format(args.jdbc_driver, resources_dir, e)
-      raise FatalException(1, err)
+SRVR_ONE_WAY_SSL_PORT_PROPERTY = "security.server.one_way_ssl.port"
+SRVR_ONE_WAY_SSL_PORT = "8440"
 
-  os.symlink(os.path.join(resources_dir,jdbc_name), jdbc_symlink)
-  print "JDBC driver was successfully initialized ."
+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])$"
+REGEX_HOSTNAME = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
+REGEX_HOSTNAME_PORT = "^(.*:[0-9]{1,5}$)"
+REGEX_TRUE_FALSE = "^(true|false)?$"
+REGEX_ANYTHING = ".*"
 
+# linux open-file limit
+ULIMIT_OPEN_FILES_KEY = 'ulimit.open.files'
+ULIMIT_OPEN_FILES_DEFAULT = 10000
 
+#Apache License Header
+ASF_LICENSE_HEADER = '''
+# Copyright 2011 The Apache Software Foundation
 #
-# Resets the Ambari Server.
+# 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
 #
-def reset(args):
-  #force reset if silent option provided
-  if get_silent():
-    default = "yes"
-  else:
-    default = "no"
-
-  if not is_root():
-    err = 'Ambari-server reset should be run with ' \
-          'root-level privileges'
-    raise FatalException(4, err)
-  status, pid = is_server_runing()
-  if status:
-    err = 'Ambari-server must be stopped to reset'
-    raise FatalException(1, err)
-  choice = get_YN_input("**** WARNING **** You are about to reset and clear the "
-                     "Ambari Server database. This will remove all cluster "
-                     "host and configuration information from the database. "
-                     "You will be required to re-configure the Ambari server "
-                     "and re-run the cluster wizard. \n"
-                     "Are you SURE you want to perform the reset "
-                     "[yes/no] ({0})? ".format(default), get_silent())
-  okToRun = choice
-
-  if not okToRun:
-    err = "Ambari Server 'reset' cancelled"
-    raise FatalException(1, err)
-
-  check_database_name_property(args)
-  parse_properties_file(args)
-
-  if args.persistence_type == "remote":
-    client_usage_cmd_drop = get_remote_script_line(args, DATABASE_DROP_SCRIPTS[DATABASE_INDEX])
-    client_usage_cmd_init = get_remote_script_line(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
-    if not client_usage_cmd_drop or not client_usage_cmd_init:
-      raise NonFatalException("Could`t create command lines for {0} DB".format(args.dbms))
-
-    print_warning_msg('To reset Ambari Server schema ' +
-                      'you must run the following DDL against the database to '
-                      + 'drop the schema:' + os.linesep + client_usage_cmd_drop
-                      + os.linesep + 'Then you must run the following DDL ' +
-                      'against the database to create the schema: ' + os.linesep +
-                      client_usage_cmd_init + os.linesep)
-    if args.dbms == "postgres":
-      raise NonFatalException("Please set DB password to PGPASSWORD env variable before running DDL`s!")
-    else:
-      raise NonFatalException("Please replace '*' symbols with password before running DDL`s!")
-  else:
-    # Run automatic reset only for embedded DB
-    okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), get_silent())
+#     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.
+'''
 
-    if not okToRun:
-      err = "Ambari Server 'reset' cancelled"
-      raise FatalException(1, err)
+### System interaction ###
 
-    print "Resetting the Server database..."
-
-    dbname = args.database_name
-    filename = args.drop_script_file
-    username = args.database_username
-    password = args.database_password
-    command = SETUP_DB_CMD[:]
-    command[-1] = command[-1].format(filename, username, password, dbname)
-    drop_retcode, drop_outdata, drop_errdata = run_os_command(command)
-    if not drop_retcode == 0:
-      raise FatalException(1, drop_errdata)
-    if drop_errdata and PG_ERROR_BLOCKED in drop_errdata:
-      raise FatalException(1, "Database is in use. Please, make sure all connections to the database are closed")
-    if drop_errdata and get_verbose():
-      print_warnin

<TRUNCATED>