def install_packages(self, env, exclude_packages=[]): """ List of packages that are required< by service is received from the server as a command parameter. The method installs all packages from this list """ config = self.get_config() try: package_list_str = config['hostLevelParams']['package_list'] if isinstance(package_list_str, basestring) and len(package_list_str) > 0: package_list = json.loads(package_list_str) for package in package_list: if not package['name'] in exclude_packages: name = package['name'] if OSCheck.is_windows_family(): if name[-4:] == ".msi": #TODO all msis must be located in resource folder of server, change it to repo later Msi(name, http_source=os.path.join(config['hostLevelParams']['jdk_location'])) else: Package(name) except KeyError: pass # No reason to worry if OSCheck.is_windows_family(): #TODO hacky install of windows msi, remove it or move to old(2.1) stack definition when component based install will be implemented install_windows_msi(os.path.join(config['hostLevelParams']['jdk_location'], "hdp.msi"), config["hostLevelParams"]["agentCacheDir"], "hdp.msi", self.get_password("hadoop"), str(config['hostLevelParams']['stack_version'])) reload_windows_env() pass
def install_packages(self, env, exclude_packages=[]): """ List of packages that are required< by service is received from the server as a command parameter. The method installs all packages from this list """ config = self.get_config() try: package_list_str = config['hostLevelParams']['package_list'] if isinstance(package_list_str, basestring) and len(package_list_str) > 0: package_list = json.loads(package_list_str) for package in package_list: if not package['name'] in exclude_packages: name = package['name'] if OSCheck.is_windows_family(): if name[-4:] == ".msi": #TODO all msis must be located in resource folder of server, change it to repo later Msi(name, http_source=os.path.join(config['hostLevelParams']['jdk_location'])) else: Package(name) except KeyError: pass # No reason to worry if OSCheck.is_windows_family(): #TODO hacky install of windows msi, remove it or move to old(2.1) stack definition when component based install will be implemented install_windows_msi(os.path.join(config['hostLevelParams']['jdk_location'], "hdp.msi"), config["hostLevelParams"]["agentCacheDir"], "hdp.msi", self.get_password("hadoop"), str(config['hostLevelParams']['stack_version'])) reload_windows_env() # RepoInstaller.remove_repos(config) pass
def install_packages(self, env, exclude_packages=[]): """ List of packages that are required< by service is received from the server as a command parameter. The method installs all packages from this list """ config = self.get_config() if 'host_sys_prepped' in config['hostLevelParams']: # do not install anything on sys-prepped host if config['hostLevelParams']['host_sys_prepped'] == True: Logger.info("Node has all packages pre-installed. Skipping.") return pass try: package_list_str = config['hostLevelParams']['package_list'] if isinstance(package_list_str, basestring) and len(package_list_str) > 0: package_list = json.loads(package_list_str) for package in package_list: if not package['name'] in exclude_packages: name = package['name'] if OSCheck.is_windows_family(): if name[-4:] == ".msi": #TODO all msis must be located in resource folder of server, change it to repo later Msi(name, http_source=os.path.join( config['hostLevelParams'] ['jdk_location'])) else: Package(name) except KeyError: pass # No reason to worry if OSCheck.is_windows_family(): #TODO hacky install of windows msi, remove it or move to old(2.1) stack definition when component based install will be implemented hadoop_user = config["configurations"]["cluster-env"][ "hadoop.user.name"] install_windows_msi( os.path.join(config['hostLevelParams']['jdk_location'], "hdp.msi"), config["hostLevelParams"]["agentCacheDir"], "hdp.msi", hadoop_user, self.get_password(hadoop_user), str(config['hostLevelParams']['stack_version'])) reload_windows_env() pass
def on_failure(self, pythonCommand, result): """ Log some useful information after task failure. """ logger.info("Command " + pprint.pformat(pythonCommand) + " failed with exitcode=" + str(result['exitcode'])) if OSCheck.is_windows_family(): cmd_list = ["WMIC path win32_process get Caption,Processid,Commandline", "netstat -an"] else: cmd_list = ["ps faux", "netstat -tulpn"] shell_runner = shellRunner() for cmd in cmd_list: ret = shell_runner.run(cmd) logger.info("Command '{0}' returned {1}. {2}{3}".format(cmd, ret["exitCode"], ret["error"], ret["output"]))
def execute_java_home_available_check(self, config): print "Java home check started." java64_home = config['commandParams']['java_home'] print "Java home to check: " + java64_home java_bin = "java" if OSCheck.is_windows_family(): java_bin = "java.exe" if not os.path.isfile(os.path.join(java64_home, "bin", java_bin)): print "Java home doesn't exist!" java_home_check_structured_output = {"exit_code" : 1, "message": "Java home doesn't exist!"} else: print "Java home exists!" java_home_check_structured_output = {"exit_code" : 0, "message": "Java home exists!"} return java_home_check_structured_output
def execute_java_home_available_check(self, config): print "Java home check started." java_home = config['commandParams']['java_home'] print "Java home to check: " + java_home java_bin = "java" if OSCheck.is_windows_family(): java_bin = "java.exe" if not os.path.isfile(os.path.join(java_home, "bin", java_bin)): print "Java home doesn't exist!" java_home_check_structured_output = {"exit_code" : 1, "message": "Java home doesn't exist!"} else: print "Java home exists!" java_home_check_structured_output = {"exit_code" : 0, "message": "Java home exists!"} return java_home_check_structured_output
def log_process_information(logger): """ Check if certain configuration sent from the server has been received. """ if OSCheck.is_windows_family(): cmd_list = [ "WMIC path win32_process get Caption,Processid,Commandline", "netstat -an" ] else: cmd_list = ["export COLUMNS=9999 ; ps faux", "netstat -tulpn"] shell_runner = shellRunner() for cmd in cmd_list: ret = shell_runner.run(cmd) logger.info("Command '{0}' returned {1}. {2}{3}".format( cmd, ret["exitCode"], ret["error"], ret["output"]))
def execute(self): """ Sets up logging; Parses command parameters and executes method relevant to command type """ logger, chout, cherr = Logger.initialize_logger() # parse arguments if len(sys.argv) < 7: logger.error("Script expects at least 6 arguments") print USAGE.format(os.path.basename(sys.argv[0])) # print to stdout sys.exit(1) command_name = str.lower(sys.argv[1]) self.command_data_file = sys.argv[2] self.basedir = sys.argv[3] self.stroutfile = sys.argv[4] self.load_structured_out() self.logging_level = sys.argv[5] Script.tmp_dir = sys.argv[6] logging_level_str = logging._levelNames[self.logging_level] chout.setLevel(logging_level_str) logger.setLevel(logging_level_str) # on windows we need to reload some of env variables manually because there is no default paths for configs(like # /etc/something/conf on linux. When this env vars created by one of the Script execution, they can not be updated # in agent, so other Script executions will not be able to access to new env variables if OSCheck.is_windows_family(): reload_windows_env() try: with open(self.command_data_file, "r") as f: pass Script.config = ConfigDictionary(json.load(f)) #load passwords here(used on windows to impersonate different users) Script.passwords = {} for k, v in _PASSWORD_MAP.iteritems(): if get_path_form_configuration(k,Script.config) and get_path_form_configuration(v, Script.config): Script.passwords[get_path_form_configuration(k,Script.config)] = get_path_form_configuration(v, Script.config) except IOError: logger.exception("Can not read json file with command parameters: ") sys.exit(1) # Run class method depending on a command type try: method = self.choose_method_to_execute(command_name) with Environment(self.basedir, tmp_dir=Script.tmp_dir) as env: env.config.download_path = Script.tmp_dir method(env) except ClientComponentHasNoStatus or ComponentIsNotRunning: # Support of component status checks. # Non-zero exit code is interpreted as an INSTALLED status of a component sys.exit(1) except Fail: logger.exception("Error while executing command '{0}':".format(command_name)) sys.exit(1) finally: if self.should_expose_component_version(command_name): self.save_component_version_to_structured_out()
def execute_db_connection_check(self, config, tmp_dir): print "DB connection check started." # initialize needed data ambari_server_hostname = config['commandParams']['ambari_server_host'] check_db_connection_jar_name = "DBConnectionVerification.jar" jdk_location = config['commandParams']['jdk_location'] java64_home = config['commandParams']['java_home'] db_name = config['commandParams']['db_name'] if db_name == DB_MYSQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MYSQL jdbc_driver = JDBC_DRIVER_MYSQL jdbc_name = JDBC_DRIVER_SYMLINK_MYSQL elif db_name == DB_ORACLE: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_ORACLE jdbc_driver = JDBC_DRIVER_ORACLE jdbc_name = JDBC_DRIVER_SYMLINK_ORACLE elif db_name == DB_POSTGRESQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_POSTGRESQL jdbc_driver = JDBC_DRIVER_POSTGRESQL jdbc_name = JDBC_DRIVER_SYMLINK_POSTGRESQL elif db_name == DB_MSSQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MSSQL jdbc_driver = JDBC_DRIVER_MSSQL jdbc_name = JDBC_DRIVER_SYMLINK_MSSQL db_connection_url = config['commandParams']['db_connection_url'] user_name = config['commandParams']['user_name'] user_passwd = config['commandParams']['user_passwd'] agent_cache_dir = os.path.abspath(config["hostLevelParams"]["agentCacheDir"]) check_db_connection_url = jdk_location + check_db_connection_jar_name jdbc_path = os.path.join(agent_cache_dir, jdbc_name) check_db_connection_path = os.path.join(agent_cache_dir, check_db_connection_jar_name) java_bin = "java" class_path_delimiter = ":" if OSCheck.is_windows_family(): java_bin = "java.exe" class_path_delimiter = ";" java_exec = os.path.join(java64_home, "bin",java_bin) if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \ or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec): message = "Custom java is not available on host. Please install it. Java home should be the same as on server. " \ "\n" print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output environment = { "no_proxy": format("{ambari_server_hostname}") } # download and install java if it doesn't exists if not os.path.isfile(java_exec): jdk_name = config['commandParams']['jdk_name'] jdk_url = "{0}/{1}".format(jdk_location, jdk_name) jdk_download_target = os.path.join(agent_cache_dir, jdk_name) java_dir = os.path.dirname(java64_home) try: download_file(jdk_url, jdk_download_target) except Exception, e: message = "Error downloading JDK from Ambari Server resources. Check network access to " \ "Ambari Server.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output if jdk_name.endswith(".bin"): install_cmd = format("mkdir -p {java_dir} ; chmod +x {jdk_download_target}; cd {java_dir} ; echo A | " \ "{jdk_curl_target} -noregister > /dev/null 2>&1") install_path = ["/bin","/usr/bin/"] elif jdk_name.endswith(".gz"): install_cmd = format("mkdir -p {java_dir} ; cd {java_dir} ; tar -xf {jdk_download_target} > /dev/null 2>&1") install_path = ["/bin","/usr/bin/"] elif jdk_name.endswith(".exe"): install_cmd = "{0} /s INSTALLDIR={1} STATIC=1 WEB_JAVA=0 /L \\var\\log\\ambari-agent".format( os_utils.quote_path(jdk_download_target), os_utils.quote_path(java64_home), ) install_path = [java_dir] try: Execute(install_cmd, path = install_path) except Exception, e: message = "Error installing java.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output
# download DBConnectionVerification.jar from ambari-server resources try: download_file(check_db_connection_url, check_db_connection_path) except Exception, e: message = "Error downloading DBConnectionVerification.jar from Ambari Server resources. Check network access to " \ "Ambari Server.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output # download jdbc driver from ambari-server resources try: download_file(jdbc_url, jdbc_path) if db_name == DB_MSSQL and OSCheck.is_windows_family(): jdbc_auth_path = os.path.join(agent_cache_dir, JDBC_AUTH_SYMLINK_MSSQL) jdbc_auth_url = jdk_location + JDBC_AUTH_SYMLINK_MSSQL download_file(jdbc_auth_url, jdbc_auth_path) except Exception, e: message = format("Error: Ambari Server cannot download the database JDBC driver and is unable to test the " \ "database connection. You must run ambari-server setup --jdbc-db={db_name} " \ "--jdbc-driver=/path/to/your/{db_name}/driver.jar on the Ambari Server host to make the JDBC " \ "driver available for download and to enable testing the database connection.\n") + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output # try to connect to db db_connection_check_command = format("{java_exec} -cp {check_db_connection_path}{class_path_delimiter}" \
def execute_db_connection_check(self, config, tmp_dir): print "DB connection check started." # initialize needed data ambari_server_hostname = config['commandParams']['ambari_server_host'] check_db_connection_jar_name = "DBConnectionVerification.jar" jdk_location = config['commandParams']['jdk_location'] java_home = config['commandParams']['java_home'] db_name = config['commandParams']['db_name'] if db_name == DB_MYSQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MYSQL jdbc_driver_class = JDBC_DRIVER_CLASS_MYSQL jdbc_name = JDBC_DRIVER_SYMLINK_MYSQL elif db_name == DB_ORACLE: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_ORACLE jdbc_driver_class = JDBC_DRIVER_CLASS_ORACLE jdbc_name = JDBC_DRIVER_SYMLINK_ORACLE elif db_name == DB_POSTGRESQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_POSTGRESQL jdbc_driver_class = JDBC_DRIVER_CLASS_POSTGRESQL jdbc_name = JDBC_DRIVER_SYMLINK_POSTGRESQL elif db_name == DB_MSSQL: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MSSQL jdbc_driver_class = JDBC_DRIVER_CLASS_MSSQL jdbc_name = JDBC_DRIVER_SYMLINK_MSSQL elif db_name == DB_SQLA: jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_SQLA jdbc_driver_class = JDBC_DRIVER_CLASS_SQLA jdbc_name = JDBC_DRIVER_SYMLINK_SQLA db_connection_url = config['commandParams']['db_connection_url'] user_name = config['commandParams']['user_name'] user_passwd = config['commandParams']['user_passwd'] agent_cache_dir = os.path.abspath(config["hostLevelParams"]["agentCacheDir"]) check_db_connection_url = jdk_location + check_db_connection_jar_name jdbc_path = os.path.join(agent_cache_dir, jdbc_name) class_path_delimiter = ":" if db_name == DB_SQLA: jdbc_jar_path = agent_cache_dir + JDBC_DRIVER_SQLA_JAR_PATH_IN_ARCHIVE java_library_path = agent_cache_dir + JARS_PATH_IN_ARCHIVE_SQLA + class_path_delimiter + agent_cache_dir + \ LIBS_PATH_IN_ARCHIVE_SQLA else: jdbc_jar_path = jdbc_path java_library_path = agent_cache_dir check_db_connection_path = os.path.join(agent_cache_dir, check_db_connection_jar_name) java_bin = "java" if OSCheck.is_windows_family(): java_bin = "java.exe" class_path_delimiter = ";" java_exec = os.path.join(java_home, "bin",java_bin) if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \ or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec): message = "Custom java is not available on host. Please install it. Java home should be the same as on server. " \ "\n" print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output environment = { "no_proxy": format("{ambari_server_hostname}") } # download and install java if it doesn't exists if not os.path.isfile(java_exec): jdk_name = config['commandParams']['jdk_name'] jdk_url = "{0}/{1}".format(jdk_location, jdk_name) jdk_download_target = os.path.join(agent_cache_dir, jdk_name) java_dir = os.path.dirname(java_home) try: download_file(jdk_url, jdk_download_target) except Exception, e: message = "Error downloading JDK from Ambari Server resources. Check network access to " \ "Ambari Server.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output if jdk_name.endswith(".exe"): install_cmd = "{0} /s INSTALLDIR={1} STATIC=1 WEB_JAVA=0 /L \\var\\log\\ambari-agent".format( os_utils.quote_path(jdk_download_target), os_utils.quote_path(java_home), ) install_path = [java_dir] try: Execute(install_cmd, path = install_path) except Exception, e: message = "Error installing java.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output
# download DBConnectionVerification.jar from ambari-server resources try: download_file(check_db_connection_url, check_db_connection_path) except Exception, e: message = "Error downloading DBConnectionVerification.jar from Ambari Server resources. Check network access to " \ "Ambari Server.\n" + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output # download jdbc driver from ambari-server resources try: download_file(jdbc_url, jdbc_path) if db_name == DB_MSSQL and OSCheck.is_windows_family(): jdbc_auth_path = os.path.join(agent_cache_dir, JDBC_AUTH_SYMLINK_MSSQL) jdbc_auth_url = jdk_location + JDBC_AUTH_SYMLINK_MSSQL download_file(jdbc_auth_url, jdbc_auth_path) elif db_name == DB_SQLA: # unpack tar.gz jdbc which was donaloaded untar_sqla_type2_driver = ('tar', '-xvf', jdbc_path, '-C', agent_cache_dir) Execute(untar_sqla_type2_driver, sudo = True) except Exception, e: message = format("Error: Ambari Server cannot download the database JDBC driver and is unable to test the " \ "database connection. You must run ambari-server setup --jdbc-db={db_name} " \ "--jdbc-driver=/path/to/your/{db_name}/driver.jar on the Ambari Server host to make the JDBC " \ "driver available for download and to enable testing the database connection.\n") + str(e) print message db_connection_check_structured_output = {"exit_code" : 1, "message": message} return db_connection_check_structured_output
def execute(self): """ Sets up logging; Parses command parameters and executes method relevant to command type """ logger, chout, cherr = Logger.initialize_logger() # parse arguments if len(sys.argv) < 7: logger.error("Script expects at least 6 arguments") print USAGE.format(os.path.basename(sys.argv[0])) # print to stdout sys.exit(1) command_name = str.lower(sys.argv[1]) self.command_data_file = sys.argv[2] self.basedir = sys.argv[3] self.stroutfile = sys.argv[4] self.load_structured_out() self.logging_level = sys.argv[5] Script.tmp_dir = sys.argv[6] logging_level_str = logging._levelNames[self.logging_level] chout.setLevel(logging_level_str) logger.setLevel(logging_level_str) # on windows we need to reload some of env variables manually because there is no default paths for configs(like # /etc/something/conf on linux. When this env vars created by one of the Script execution, they can not be updated # in agent, so other Script executions will not be able to access to new env variables if OSCheck.is_windows_family(): reload_windows_env() try: with open(self.command_data_file) as f: pass Script.config = ConfigDictionary(json.load(f)) # load passwords here(used on windows to impersonate different users) Script.passwords = {} for k, v in _PASSWORD_MAP.iteritems(): if get_path_from_configuration(k, Script.config) and get_path_from_configuration(v, Script.config): Script.passwords[get_path_from_configuration(k, Script.config)] = get_path_from_configuration(v, Script.config) except IOError: logger.exception("Can not read json file with command parameters: ") sys.exit(1) # Run class method depending on a command type try: method = self.choose_method_to_execute(command_name) with Environment(self.basedir, tmp_dir=Script.tmp_dir) as env: env.config.download_path = Script.tmp_dir method(env) if command_name == "install": self.set_version() except ClientComponentHasNoStatus or ComponentIsNotRunning: # Support of component status checks. # Non-zero exit code is interpreted as an INSTALLED status of a component sys.exit(1) except Fail: logger.exception("Error while executing command '{0}':".format(command_name)) sys.exit(1) finally: if self.should_expose_component_version(command_name): self.save_component_version_to_structured_out()
from resource_management.core.resources import Execute from resource_management.core.shell import call from resource_management.libraries.functions import format from resource_management.libraries.functions import get_kinit_path from resource_management.libraries.functions import get_klist_path from ambari_commons.os_check import OSConst, OSCheck from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl from urlparse import urlparse import os import re RESULT_CODE_OK = 'OK' RESULT_CODE_CRITICAL = 'CRITICAL' RESULT_CODE_UNKNOWN = 'UNKNOWN' if OSCheck.is_windows_family(): OOZIE_ENV_HTTPS_RE = r"set\s+OOZIE_HTTPS_PORT=(\d+)" else: OOZIE_ENV_HTTPS_RE = r"export\s+OOZIE_HTTPS_PORT=(\d+)" # The configured Kerberos executable search paths, if any KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY = '{{kerberos-env/executable_search_paths}}' OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}' SECURITY_ENABLED = '{{cluster-env/security_enabled}}' OOZIE_USER = '******' OOZIE_CONF_DIR = '/usr/hdp/current/oozie-server/conf' OOZIE_CONF_DIR_LEGACY = '/etc/oozie/conf' OOZIE_HTTPS_PORT = '{{oozie-site/oozie.https.port}}' OOZIE_ENV_CONTENT = '{{oozie-env/content}}'
from resource_management.libraries.script.script import Script # a map of the Ambari role to the component name # for use with <stack-root>/current/<component> SERVER_ROLE_DIRECTORY_MAP = { 'HBASE_MASTER': 'hbase-master', 'HBASE_REGIONSERVER': 'hbase-regionserver', 'HBASE_CLIENT': 'hbase-client' } component_directory = Script.get_component_from_role(SERVER_ROLE_DIRECTORY_MAP, "HBASE_CLIENT") config = Script.get_config() if OSCheck.is_windows_family(): hbase_master_win_service_name = "master" hbase_regionserver_win_service_name = "regionserver" else: pid_dir = config['configurations']['hbase-env']['hbase_pid_dir'] hbase_user = config['configurations']['hbase-env']['hbase_user'] hbase_master_pid_file = format("{pid_dir}/hbase-{hbase_user}-master.pid") regionserver_pid_file = format( "{pid_dir}/hbase-{hbase_user}-regionserver.pid") phoenix_pid_file = format("{pid_dir}/phoenix-{hbase_user}-queryserver.pid") # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env'][ 'security_enabled']
def execute_db_connection_check(self, config, tmp_dir): Logger.info("DB connection check started.") # initialize needed data ambari_server_hostname = config['commandParams']['ambari_server_host'] check_db_connection_jar_name = "DBConnectionVerification.jar" jdk_location = config['commandParams']['jdk_location'] java_home = config['commandParams']['java_home'] db_name = config['commandParams']['db_name'] no_jdbc_error_message = None if db_name == DB_MYSQL: jdbc_driver_mysql_name = default( "/hostLevelParams/custom_mysql_jdbc_name", None) if not jdbc_driver_mysql_name: no_jdbc_error_message = "The MySQL JDBC driver has not been set. Please ensure that you have executed 'ambari-server setup --jdbc-db=mysql --jdbc-driver=/path/to/jdbc_driver'." else: jdbc_url = jdk_location + jdbc_driver_mysql_name jdbc_driver_class = JDBC_DRIVER_CLASS_MYSQL jdbc_name = jdbc_driver_mysql_name elif db_name == DB_ORACLE: jdbc_driver_oracle_name = default( "/hostLevelParams/custom_oracle_jdbc_name", None) if not jdbc_driver_oracle_name: no_jdbc_error_message = "The Oracle JDBC driver has not been set. Please ensure that you have executed 'ambari-server setup --jdbc-db=oracle --jdbc-driver=/path/to/jdbc_driver'." else: jdbc_url = jdk_location + jdbc_driver_oracle_name jdbc_driver_class = JDBC_DRIVER_CLASS_ORACLE jdbc_name = jdbc_driver_oracle_name elif db_name == DB_POSTGRESQL: jdbc_driver_postgres_name = default( "/hostLevelParams/custom_postgres_jdbc_name", None) if not jdbc_driver_postgres_name: no_jdbc_error_message = "The Postgres JDBC driver has not been set. Please ensure that you have executed 'ambari-server setup --jdbc-db=postgres --jdbc-driver=/path/to/jdbc_driver'." else: jdbc_url = jdk_location + jdbc_driver_postgres_name jdbc_driver_class = JDBC_DRIVER_CLASS_POSTGRESQL jdbc_name = jdbc_driver_postgres_name elif db_name == DB_MSSQL: jdbc_driver_mssql_name = default( "/hostLevelParams/custom_mssql_jdbc_name", None) if not jdbc_driver_mssql_name: no_jdbc_error_message = "The MSSQL JDBC driver has not been set. Please ensure that you have executed 'ambari-server setup --jdbc-db=mssql --jdbc-driver=/path/to/jdbc_driver'." else: jdbc_url = jdk_location + jdbc_driver_mssql_name jdbc_driver_class = JDBC_DRIVER_CLASS_MSSQL jdbc_name = jdbc_driver_mssql_name elif db_name == DB_SQLA: jdbc_driver_sqla_name = default( "/hostLevelParams/custom_sqlanywhere_jdbc_name", None) if not jdbc_driver_sqla_name: no_jdbc_error_message = "The SQLAnywhere JDBC driver has not been set. Please ensure that you have executed 'ambari-server setup --jdbc-db=sqlanywhere --jdbc-driver=/path/to/jdbc_driver'." else: jdbc_url = jdk_location + jdbc_driver_sqla_name jdbc_driver_class = JDBC_DRIVER_CLASS_SQLA jdbc_name = jdbc_driver_sqla_name else: no_jdbc_error_message = format( "'{db_name}' database type not supported.") if no_jdbc_error_message: Logger.warning(no_jdbc_error_message) db_connection_check_structured_output = { "exit_code": 1, "message": no_jdbc_error_message } return db_connection_check_structured_output db_connection_url = config['commandParams']['db_connection_url'] user_name = config['commandParams']['user_name'] user_passwd = config['commandParams']['user_passwd'] agent_cache_dir = os.path.abspath( config["hostLevelParams"]["agentCacheDir"]) check_db_connection_url = jdk_location + check_db_connection_jar_name jdbc_path = os.path.join(agent_cache_dir, jdbc_name) class_path_delimiter = ":" if db_name == DB_SQLA: jdbc_jar_path = agent_cache_dir + JDBC_DRIVER_SQLA_JAR_PATH_IN_ARCHIVE java_library_path = agent_cache_dir + JARS_PATH_IN_ARCHIVE_SQLA + class_path_delimiter + agent_cache_dir + \ LIBS_PATH_IN_ARCHIVE_SQLA else: jdbc_jar_path = jdbc_path java_library_path = agent_cache_dir check_db_connection_path = os.path.join(agent_cache_dir, check_db_connection_jar_name) java_bin = "java" if OSCheck.is_windows_family(): java_bin = "java.exe" class_path_delimiter = ";" java_exec = os.path.join(java_home, "bin", java_bin) if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \ or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec): message = "Custom java is not available on host. Please install it. Java home should be the same as on server. " \ "\n" Logger.warning(message) db_connection_check_structured_output = { "exit_code": 1, "message": message } return db_connection_check_structured_output environment = {"no_proxy": format("{ambari_server_hostname}")} # download and install java if it doesn't exists if not os.path.isfile(java_exec): jdk_name = config['commandParams']['jdk_name'] jdk_url = "{0}/{1}".format(jdk_location, jdk_name) jdk_download_target = os.path.join(agent_cache_dir, jdk_name) java_dir = os.path.dirname(java_home) try: download_file(jdk_url, jdk_download_target) except Exception, e: message = "Error downloading JDK from Ambari Server resources. Check network access to " \ "Ambari Server.\n" + str(e) Logger.exception(message) db_connection_check_structured_output = { "exit_code": 1, "message": message } return db_connection_check_structured_output if jdk_name.endswith(".exe"): install_cmd = "{0} /s INSTALLDIR={1} STATIC=1 WEB_JAVA=0 /L \\var\\log\\ambari-agent".format( os_utils.quote_path(jdk_download_target), os_utils.quote_path(java_home), ) install_path = [java_dir] try: Execute(install_cmd, path=install_path) except Exception, e: message = "Error installing java.\n" + str(e) Logger.exception(message) db_connection_check_structured_output = { "exit_code": 1, "message": message } return db_connection_check_structured_output