def extract_views(options): java_exe_path = get_java_exe_path() if java_exe_path is None: print_error_msg("No JDK found, please run the \"setup\" " "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 vdir = get_value_from_properties(properties, VIEWS_DIR_PROPERTY, configDefaults.DEFAULT_VIEWS_DIR) files = [f for f in os.listdir(vdir) if os.path.isfile(os.path.join(vdir,f))] serverClassPath = ServerClassPath(get_ambari_properties(), options) for f in files: command = VIEW_EXTRACT_CMD.format(java_exe_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), os.path.join(vdir,f)) retcode, stdout, stderr = run_os_command(command) if retcode == 0: sys.stdout.write(f + "\n") 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
def run_stack_upgrade(args, stackName, stackVersion, repo_url, repo_url_os): jdk_path = get_java_exe_path() if jdk_path is None: print_error_msg( "No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 stackId = {} stackId[stackName] = stackVersion if repo_url is not None: stackId['repo_url'] = repo_url if repo_url_os is not None: stackId['repo_url_os'] = repo_url_os serverClassPath = ServerClassPath(get_ambari_properties(), args) command = STACK_UPGRADE_HELPER_CMD.format( jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), "updateStackId", "'" + json.dumps(stackId) + "'") (retcode, stdout, stderr) = run_os_command(command) print_info_msg( "Return code from stack upgrade command, retcode = {0}".format( str(retcode))) if retcode > 0: print_error_msg( "Error executing stack upgrade, please check the server logs.") return retcode
def run_mpack_install_checker(options, mpack_stacks): """ Run MpackInstallChecker to validate that there is no cluster deployed with a stack that is not included in the management pack :param options: Options passed :param mpack_stacks: List of stacks included in the management pack :return: Output of MpackInstallChecker """ properties = get_ambari_properties() database_type = properties[JDBC_DATABASE_PROPERTY] jdk_path = get_java_exe_path() if not jdk_path or not database_type: # Ambari Server has not been setup, so no cluster would be present return (0, "", "") parse_properties_file(options) options.database_index = LINUX_DBMS_KEYS_LIST.index( properties[JDBC_DATABASE_PROPERTY]) ensure_jdbc_driver_is_installed(options, properties) serverClassPath = ServerClassPath(properties, options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = MPACK_INSTALL_CHECKER_CMD.format(jdk_path, class_path, ",".join(mpack_stacks)) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(options, ambari_user, current_user) return run_os_command(command, env=environ)
def run_metainfo_upgrade(args, keyValueMap=None): jdk_path = get_java_exe_path() if jdk_path is None: print_error_msg( "No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) retcode = 1 if keyValueMap: serverClassPath = ServerClassPath(get_ambari_properties(), args) command = STACK_UPGRADE_HELPER_CMD.format( jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), 'updateMetaInfo', "'" + json.dumps(keyValueMap) + "'") (retcode, stdout, stderr) = run_os_command(command) print_info_msg( "Return code from stack upgrade command, retcode = {0}".format( str(retcode))) if retcode > 0: print_error_msg( "Error executing metainfo upgrade, please check the server logs." ) return retcode
def test_server_class_path_default(self, get_conf_dir_mock): properties = Properties() get_conf_dir_mock.return_value = "/etc/ambari-server/conf" expected_classpath = "'/etc/ambari-server/conf:/usr/lib/ambari-server/*'" serverClassPath = ServerClassPath(properties, None) self.assertEquals(expected_classpath, serverClassPath.get_full_ambari_classpath_escaped_for_shell())
def test_server_class_path_find_all_jars(self, get_conf_dir_mock): temp_dir = tempfile.mkdtemp() sub_dir = tempfile.mkdtemp(dir=temp_dir) serverClassPath = ServerClassPath(None, None) jar0 = tempfile.NamedTemporaryFile(suffix='.jar') jar1 = tempfile.NamedTemporaryFile(suffix='.jar', dir=temp_dir) jar2 = tempfile.NamedTemporaryFile(suffix='.jar', dir=temp_dir) jar3 = tempfile.NamedTemporaryFile(suffix='.jar', dir=sub_dir) # test /dir/*:file.jar classpath = str( temp_dir) + os.path.sep + "*" + os.path.pathsep + jar0.name jars = serverClassPath._find_all_jars(classpath) self.assertEqual(len(jars), 3) self.assertTrue(jar0.name in jars) self.assertTrue(jar1.name in jars) self.assertTrue(jar2.name in jars) self.assertFalse(jar3.name in jars) # test no classpath specified try: serverClassPath._find_all_jars(None) self.fail() except FatalException as fe: pass shutil.rmtree(temp_dir)
def run_db_cleanup(options): if validate_args(options): return 1 db_title = get_db_type(get_ambari_properties()).title confirmBackup = get_YN_input("Ambari Server configured for {0}. Confirm you have made a backup of the Ambari Server database [y/n]".format( db_title), True) if not confirmBackup: print_info_msg("Ambari Server Database cleanup aborted") return 0 status, stateDesc = is_server_runing() if status: print_error_msg("The database cleanup cannot proceed while Ambari Server is running. Please shut down Ambari first.") return 1 confirm = get_YN_input( "Ambari server is using db type {0}. Cleanable database entries older than {1} will be cleaned up. Proceed [y/n]".format( db_title, options.cleanup_from_date), True) if not confirm: print_info_msg("Ambari Server Database cleanup aborted") return 0 jdk_path = get_java_exe_path() 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 {0}".format(configDefaults.JDK_INSTALL_DIR)); return 1 ensure_jdbc_driver_is_installed(options, get_ambari_properties()) serverClassPath = ServerClassPath(get_ambari_properties(), options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(options, ambari_user, current_user) print "Cleaning up the database ..." command = DB_CLEANUP_CMD.format(jdk_path, class_path, options.cluster_name, options.cleanup_from_date) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg("Return code from database cleanup command, retcode = " + str(retcode)) if stdout: print "Console output from database cleanup command:" print stdout print if stderr: print "Error output from database cleanup command:" print stderr print if retcode > 0: print_error_msg("Error wncountered while cleaning up the Ambari Server Database. Check the ambari-server.log for details.") else: print "Cleanup completed. Check the ambari-server.log for details." return retcode
def run_schema_upgrade(args): db_title = get_db_type(get_ambari_properties()).title confirm = get_YN_input( "Ambari Server configured for %s. Confirm " "you have made a backup of the Ambari Server database [y/n] (y)? " % db_title, True) if not confirm: print_error_msg("Database backup is not confirmed") return 1 jdk_path = get_java_exe_path() 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 ensure_jdbc_driver_is_installed(args, get_ambari_properties()) print_info_msg('Upgrading database schema', True) serverClassPath = ServerClassPath(get_ambari_properties(), args) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True) set_debug_mode_from_options(args) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SCHEMA_UPGRADE_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' command = SCHEMA_UPGRADE_HELPER_CMD_DEBUG.format( jdk_path, class_path, suspend_mode) if debug_start else SCHEMA_UPGRADE_HELPER_CMD.format( jdk_path, class_path) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(args, ambari_user, current_user) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg( "Return code from schema upgrade command, retcode = {0}".format( str(retcode)), True) if stdout: print_info_msg("Console output from schema upgrade command:", True) print_info_msg(stdout, True) print if retcode > 0: print_error_msg( "Error executing schema upgrade, please check the server logs.") if stderr: print_error_msg("Error output from schema upgrade command:") print_error_msg(stderr) print else: print_info_msg('Schema upgrade completed', True) return retcode
def migrate_ldap_pam(args): properties = get_ambari_properties() if get_value_from_properties(properties,CLIENT_SECURITY,"") != 'pam': err = "PAM is not configured. Please configure PAM authentication first." raise FatalException(1, err) db_title = get_db_type(properties).title confirm = get_YN_input("Ambari Server configured for %s. Confirm " "you have made a backup of the Ambari Server database [y/n] (y)? " % db_title, True) if not confirm: print_error_msg("Database backup is not confirmed") return 1 jdk_path = get_java_exe_path() 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 # At this point, the args does not have the ambari database information. # Augment the args with the correct ambari database information parse_properties_file(args) ensure_jdbc_driver_is_installed(args, properties) print 'Migrating LDAP Users & Groups to PAM' serverClassPath = ServerClassPath(properties, args) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = LDAP_TO_PAM_MIGRATION_HELPER_CMD.format(jdk_path, class_path) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(args, ambari_user, current_user) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg("Return code from LDAP to PAM migration command, retcode = " + str(retcode)) if stdout: print "Console output from LDAP to PAM migration command:" print stdout print if stderr: print "Error output from LDAP to PAM migration command:" print stderr print if retcode > 0: print_error_msg("Error executing LDAP to PAM migration, please check the server logs.") else: print_info_msg('LDAP to PAM migration completed') return retcode
def test_server_class_path_custom_jdbc_path(self, get_native_libs_path_mock, get_jdbc_driver_path_mock, get_conf_dir_mock): properties = Properties() properties.process_pair(JDBC_DRIVER_PATH_PROPERTY, "/ambari/properties/path/to/custom/jdbc.jar") get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar" get_native_libs_path_mock.return_value = None get_conf_dir_mock.return_value = "/etc/ambari-server/conf" expected_classpath = "'/etc/ambari-server/conf:/usr/lib/ambari-server/*:/ambari/properties/path/to/custom/jdbc.jar:/path/to/jdbc.jar'" serverClassPath = ServerClassPath(properties, MagicMock()) actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell() self.assertEquals(expected_classpath, actual_classpath)
def test_server_class_path_custom_env_classpath(self, get_native_libs_path_mock, get_jdbc_driver_path_mock, get_conf_dir_mock): properties = Properties() get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar" get_native_libs_path_mock.return_value = None get_conf_dir_mock.return_value = "/etc/ambari-server/conf" os.environ[SERVER_CLASSPATH_KEY] = "/custom/server/env/classpath" expected_classpath = "'/etc/ambari-server/conf:/custom/server/env/classpath:/usr/lib/ambari-server/*:/path/to/jdbc.jar'" serverClassPath = ServerClassPath(properties, MagicMock()) actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell() del os.environ[SERVER_CLASSPATH_KEY] self.assertEquals(expected_classpath, actual_classpath)
def check_database(options): logger.info("Check database consistency.") jdk_path = serverConfiguration.get_java_exe_path() 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) sys.exit(1) properties = serverConfiguration.get_ambari_properties() serverConfiguration.parse_properties_file(options) database_type = properties[JDBC_DATABASE_PROPERTY] if not database_type: print_error_msg("Please run \"ambari-server setup\" command" " to initialize ambari db properties.") sys.exit(1) options.database_index = LINUX_DBMS_KEYS_LIST.index( properties[JDBC_DATABASE_PROPERTY]) dbConfiguration.ensure_jdbc_driver_is_installed( options, serverConfiguration.get_ambari_properties()) serverClassPath = ServerClassPath( serverConfiguration.get_ambari_properties(), options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = CHECK_DATABASE_HELPER_CMD.format(jdk_path, class_path) ambari_user = serverConfiguration.read_ambari_user() current_user = setupSecurity.ensure_can_start_under_current_user( ambari_user) environ = setupSecurity.generate_env(options, ambari_user, current_user) (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ) if retcode > 0: print str(stdout) raise FatalException( 1, 'Database check failed to complete. Please check ' + configDefaults.SERVER_LOG_FILE + ' and ' + configDefaults.DB_CHECK_LOG + ' for more information.') else: print str(stdout) if not stdout.startswith("No errors"): print "Ambari Server 'check-database' completed" sys.exit(1)
def test_server_class_path_custom_jar(self, get_native_libs_path_mock, get_jdbc_driver_path_mock, get_conf_dir_mock): properties = Properties() get_jdbc_driver_path_mock.return_value = "/path/to/jdbc.jar" get_native_libs_path_mock.return_value = None get_conf_dir_mock.return_value = "/etc/ambari-server/conf" os.environ[AMBARI_SERVER_LIB] = "/custom/ambari/jar/location" expected_classpath ="'/etc/ambari-server/conf:/custom/ambari/jar/location/*:/path/to/jdbc.jar'" serverClassPath = ServerClassPath(properties, MagicMock()) actual_classpath = serverClassPath.get_full_ambari_classpath_escaped_for_shell() del os.environ[AMBARI_SERVER_LIB] self.assertEquals(expected_classpath, actual_classpath)
def save_master_key(options, master_key, key_location, persist=True): if master_key: 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 serverClassPath = ServerClassPath(get_ambari_properties(), options) command = SECURITY_PROVIDER_KEY_CMD.format(get_java_exe_path(), serverClassPath.get_full_ambari_classpath_escaped_for_shell(), master_key, key_location, persist) (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from credential provider save KEY: " + str(retcode)) else: print_error_msg("Master key cannot be None.")
def test_server_class_path_validate_classpath(self, get_conf_dir_mock, find_jars_mock): serverClassPath = ServerClassPath(None, None) # No jars find_jars_mock.return_value = [] try: serverClassPath._validate_classpath(None) except: self.fail() # Correct jars list find_jars_mock.return_value = [ "ambari-metrics-common-2.1.1.236.jar", "ambari-server-2.1.1.236.jar", "jetty-client-8.1.17.v20150415.jar", "spring-core-3.0.7.RELEASE.jar" ] try: serverClassPath._validate_classpath(None) except: self.fail() # Incorrect jars list, multiple versions for ambari-server.jar find_jars_mock.return_value = [ "ambari-metrics-common-2.1.1.236.jar", "ambari-server-2.1.1.236.jar", "ambari-server-2.1.1.hotfixed.jar", "jetty-client-8.1.17.v20150415.jar", "spring-core-3.0.7.RELEASE.jar" ] try: serverClassPath._validate_classpath(None) self.fail() except: pass # Incorrect jars list, multiple versions for not ambari-server.jar find_jars_mock.return_value = [ "ambari-metrics-common-2.1.1.236.jar", "ambari-server-2.1.1.236.jar", "jetty-client-8.1.17.v20150415.jar", "jetty-client-9.jar", "spring-core-3.0.7.RELEASE.jar" ] try: serverClassPath._validate_classpath(None) except: self.fail()
def run_schema_upgrade(args): db_title = get_db_type(get_ambari_properties()).title confirm = get_YN_input("Ambari Server configured for %s. Confirm " "you have made a backup of the Ambari Server database [y/n] (y)? " % db_title, True) if not confirm: print_error_msg("Database backup is not confirmed") return 1 jdk_path = get_java_exe_path() 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 ensure_jdbc_driver_is_installed(args, get_ambari_properties()) print 'Upgrading database schema' serverClassPath = ServerClassPath(get_ambari_properties(), args) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = SCHEMA_UPGRADE_HELPER_CMD.format(jdk_path, class_path) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(args, ambari_user, current_user) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg("Return code from schema upgrade command, retcode = " + str(retcode)) if stdout: print "Console output from schema upgrade command:" print stdout print if stderr: print "Error output from schema upgrade command:" print stderr print if retcode > 0: print_error_msg("Error executing schema upgrade, please check the server logs.") else: print_info_msg('Schema upgrade completed') return retcode
def run_metainfo_upgrade(args, keyValueMap=None): jdk_path = get_java_exe_path() if jdk_path is None: print_error_msg("No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) retcode = 1 if keyValueMap: serverClassPath = ServerClassPath(get_ambari_properties(), args) command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), 'updateMetaInfo', "'" + json.dumps(keyValueMap) + "'") (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from stack upgrade command, retcode = " + str(retcode)) if retcode > 0: print_error_msg("Error executing metainfo upgrade, please check the " "server logs.") return retcode
def run_schema_upgrade(args): db_title = get_db_type(get_ambari_properties()).title confirm = get_YN_input( "Ambari Server configured for %s. Confirm " "you have made a backup of the Ambari Server database [y/n] (y)? " % db_title, True) if not confirm: print_error_msg("Database backup is not confirmed") return 1 jdk_path = get_java_exe_path() 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 ensure_jdbc_driver_is_installed(args, get_ambari_properties()) print 'Upgrading database schema' serverClassPath = ServerClassPath(get_ambari_properties(), args) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = SCHEMA_UPGRADE_HELPER_CMD.format(jdk_path, class_path) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(args, ambari_user, current_user) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg("Return code from schema upgrade command, retcode = " + str(retcode)) if retcode > 0: print_error_msg( "Error executing schema upgrade, please check the server logs.") else: print_info_msg('Schema upgrade completed') return retcode
def check_database(options): jdk_path = serverConfiguration.get_java_exe_path() 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) sys.exit(1) properties = serverConfiguration.get_ambari_properties() serverConfiguration.parse_properties_file(options) options.database_index = LINUX_DBMS_KEYS_LIST.index( properties[JDBC_DATABASE_PROPERTY]) dbConfiguration.ensure_jdbc_driver_is_installed( options, serverConfiguration.get_ambari_properties()) serverClassPath = ServerClassPath( serverConfiguration.get_ambari_properties(), options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = CHECK_DATABASE_HELPER_CMD.format(jdk_path, class_path) ambari_user = serverConfiguration.read_ambari_user() current_user = setupSecurity.ensure_can_start_under_current_user( ambari_user) environ = setupSecurity.generate_env(options, ambari_user, current_user) (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ) print_info_msg("Return code from check database command, retcode = " + str(retcode)) if retcode > 0: print_error_msg( "Database check failed to complete. Please check ambari-server.log and ambari-server-check-database.log for problem." ) raise FatalException(1, 'Database check failed.') else: print str(stdout)
def run_stack_upgrade(args, stackName, stackVersion, repo_url, repo_url_os): jdk_path = get_java_exe_path() if jdk_path is None: print_error_msg("No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 stackId = {} stackId[stackName] = stackVersion if repo_url is not None: stackId['repo_url'] = repo_url if repo_url_os is not None: stackId['repo_url_os'] = repo_url_os serverClassPath = ServerClassPath(get_ambari_properties(), args) command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), "updateStackId", "'" + json.dumps(stackId) + "'") (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from stack upgrade command, retcode = " + str(retcode)) if retcode > 0: print_error_msg("Error executing stack upgrade, please check the server logs.") return retcode
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg( "The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) is_active_instance = get_is_active_instance() if not is_active_instance: print_warning_msg( "This instance of ambari server is not designated as active. Cannot start ambari server." ) err = "This is not an active instance. Shutting down..." raise FatalException(1, err) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() if not options.skip_properties_validation: missing_properties = get_missing_properties(properties) if missing_properties: err = "Required properties are not found: " + str(missing_properties) + ". To skip properties validation " \ "use \"--skip-properties-validation\"" raise FatalException(1, err) # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' if options.skip_database_validation: global jvm_args jvm_args += " -DskipDatabaseConsistencyValidation" param_list = generate_child_process_param_list( ambari_user, java_exe, serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True), debug_start, suspend_mode) environ = generate_env(options, ambari_user, current_user) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): if IS_FOREGROUND: # upstart script is not able to track process from different pgid. return processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format( pidJava, str(e))) pass
def server_process_main(options, scmStatus=None): properties = get_ambari_properties() if properties == -1: err = "Error getting ambari properties" raise FatalException(-1, err) properties_for_print = [] logger.info("Ambari server properties config:") for key, value in properties.getPropertyDict().items(): if "passwd" not in key and "password" not in key: properties_for_print.append(key + "=" + value) logger.info(properties_for_print) # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg( "The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) is_active_instance = get_is_active_instance() if not is_active_instance: print_warning_msg( "This instance of ambari server is not designated as active. Cannot start ambari server." ) err = "This is not an active instance. Shutting down..." raise FatalException(1, err) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) if not options.skip_properties_validation: missing_properties = get_missing_properties(properties) if missing_properties: err = "Required properties are not found: " + str(missing_properties) + ". To skip properties validation " \ "use \"--skip-properties-validation\"" raise FatalException(1, err) # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' environ = generate_env(options, ambari_user, current_user) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True) if options.skip_database_check: global jvm_args jvm_args += " -DskipDatabaseConsistencyCheck" print "Ambari Server is starting with the database consistency check skipped. Do not make any changes to your cluster " \ "topology or perform a cluster upgrade until you correct the database consistency issues. See \"" \ + configDefaults.DB_CHECK_LOG + "\" for more details on the consistency issues." properties.process_pair(CHECK_DATABASE_SKIPPED_PROPERTY, "true") else: print "Ambari database consistency check started..." if options.fix_database_consistency: jvm_args += " -DfixDatabaseConsistency" properties.process_pair(CHECK_DATABASE_SKIPPED_PROPERTY, "false") update_properties(properties) param_list = generate_child_process_param_list(ambari_user, java_exe, class_path, debug_start, suspend_mode) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): if IS_FOREGROUND: # upstart script is not able to track process from different pgid. return processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format( pidJava, str(e))) pass
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg("The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' param_list = generate_child_process_param_list(ambari_user, java_exe, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), debug_start, suspend_mode) environ = generate_env(options, ambari_user, current_user) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format(pidJava, str(e))) pass
def update_host_names(args, options): services_stopped = userInput.get_YN_input("Please, confirm Ambari services are stopped [y/n] (n)? ", False) if not services_stopped: print 'Exiting...' sys.exit(1) pending_commands = userInput.get_YN_input("Please, confirm there are no pending commands on cluster [y/n] (n)? ", False) if not pending_commands: print 'Exiting...' sys.exit(1) db_backup_done = userInput.get_YN_input("Please, confirm you have made backup of the Ambari db [y/n] (n)? ", False) if not db_backup_done: print 'Exiting...' sys.exit(1) status, pid = serverUtils.is_server_runing() if status: raise FatalException(1, "Ambari Server should be stopped") try: host_mapping_file_path = args[1] except IndexError: #host_mapping file is mandatory raise FatalException(1, "Invalid number of host update arguments. Probably, you forgot to add json file with " "host changes.") if not os.path.isfile(host_mapping_file_path): raise FatalException(1, "Invalid file path or file doesn't exist") if not os.access(host_mapping_file_path, os.R_OK): raise FatalException(1, "File is not readable") jdk_path = serverConfiguration.get_java_exe_path() 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) sys.exit(1) properties = serverConfiguration.get_ambari_properties() serverConfiguration.parse_properties_file(options) options.database_index = LINUX_DBMS_KEYS_LIST.index(properties[JDBC_DATABASE_PROPERTY]) dbConfiguration.ensure_jdbc_driver_is_installed(options, serverConfiguration.get_ambari_properties()) serverClassPath = ServerClassPath(serverConfiguration.get_ambari_properties(), options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = HOST_UPDATE_HELPER_CMD.format(jdk_path, class_path, host_mapping_file_path) ambari_user = serverConfiguration.read_ambari_user() current_user = setupSecurity.ensure_can_start_under_current_user(ambari_user) environ = setupSecurity.generate_env(options, ambari_user, current_user) (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ) print_info_msg("Return code from update host names command, retcode = " + str(retcode)) if retcode > 0: print_error_msg("Error executing update host names, please check the server logs.") raise FatalException(1, 'Host names update failed.') else: print_info_msg('Host names update completed successfully')
def update_host_names(args, options): services_stopped = userInput.get_YN_input( "Please, confirm Ambari services are stopped [y/n] (n)? ", False) if not services_stopped: print 'Exiting...' sys.exit(1) pending_commands = userInput.get_YN_input( "Please, confirm there are no pending commands on cluster [y/n] (n)? ", False) if not pending_commands: print 'Exiting...' sys.exit(1) db_backup_done = userInput.get_YN_input( "Please, confirm you have made backup of the Ambari db [y/n] (n)? ", False) if not db_backup_done: print 'Exiting...' sys.exit(1) status, pid = serverUtils.is_server_runing() if status: raise FatalException(1, "Ambari Server should be stopped") try: host_mapping_file_path = args[1] except IndexError: #host_mapping file is mandatory raise FatalException( 1, "Invalid number of host update arguments. Probably, you forgot to add json file with " "host changes.") if not os.path.isfile(host_mapping_file_path): raise FatalException(1, "Invalid file path or file doesn't exist") if not os.access(host_mapping_file_path, os.R_OK): raise FatalException(1, "File is not readable") jdk_path = serverConfiguration.get_java_exe_path() 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) sys.exit(1) properties = serverConfiguration.get_ambari_properties() serverConfiguration.parse_properties_file(options) options.database_index = LINUX_DBMS_KEYS_LIST.index( properties[JDBC_DATABASE_PROPERTY]) dbConfiguration.ensure_jdbc_driver_is_installed( options, serverConfiguration.get_ambari_properties()) serverClassPath = ServerClassPath( serverConfiguration.get_ambari_properties(), options) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell() command = HOST_UPDATE_HELPER_CMD.format(jdk_path, class_path, host_mapping_file_path) ambari_user = serverConfiguration.read_ambari_user() current_user = setupSecurity.ensure_can_start_under_current_user( ambari_user) environ = setupSecurity.generate_env(options, ambari_user, current_user) (retcode, stdout, stderr) = os_utils.run_os_command(command, env=environ) print_info_msg("Return code from update host names command, retcode = " + str(retcode)) if retcode > 0: print_error_msg( "Error executing update host names, please check the server logs.") raise FatalException(1, 'Host names update failed.') else: print_info_msg('Host names update completed successfully')