def _configure_pg_hba_ambaridb_users(conf_file, database_username): with open(conf_file, "a") as pgHbaConf: pgHbaConf.write("\n") pgHbaConf.write("local all " + database_username + ",mapred md5") pgHbaConf.write("\n") pgHbaConf.write("host all " + database_username + ",mapred 0.0.0.0/0 md5") pgHbaConf.write("\n") pgHbaConf.write("host all " + database_username + ",mapred ::/0 md5") pgHbaConf.write("\n") retcode, out, err = run_os_command(PGConfig.PG_HBA_RELOAD_CMD) if not retcode == 0: raise FatalException(retcode, err)
def _setup_database(options): properties = get_ambari_properties() if properties == -1: raise FatalException(-1, "Error getting ambari properties") factory = DBMSConfigFactory() dbmsAmbari = factory.create(options, properties, "Ambari") resultA = dbmsAmbari.configure_database(properties) # Now save the properties file if resultA: update_properties(properties) dbmsAmbari.setup_database()
def expand_jce_zip_file(jce_zip_path, jdk_security_path): f = None import zipfile if os.path.exists(jdk_security_path) and os.path.exists(jce_zip_path): try: f = zipfile.ZipFile(jce_zip_path, "r") zip_members = f.namelist() for member in zip_members: if member.endswith(os.sep): os.makedirs(os.path.join(jdk_security_path, member)) else: f.extract(member, jdk_security_path) unziped_jce_path = os.path.split(zip_members[len(zip_members) - 1])[0] finally: try: f.close() except Exception as e: err = "Fail during the extraction of {0}.".format(jce_zip_path) raise FatalException(1, err) else: err = "The path {0} or {1} is invalid.".format(jdk_security_path, jce_zip_path) raise FatalException(1, err) if unziped_jce_path: from_path = os.path.join(jdk_security_path, unziped_jce_path) jce_files = os.listdir(from_path) for i in range(len(jce_files)): jce_files[i] = os.path.join(from_path, jce_files[i]) copy_files(jce_files, jdk_security_path) dir_to_delete = os.path.join(jdk_security_path, unziped_jce_path.split(os.sep)[0]) shutil.rmtree(dir_to_delete)
def _cache_jdbc_driver(args): properties = get_ambari_properties() if properties == -1: err = "Error getting ambari properties" raise FatalException(-1, err) resources_dir = get_resources_location(properties) path, jdbc_name = os.path.split(args.jdbc_driver) custom_db_jdbc_property_name = "custom." + args.jdbc_db + ".jdbc.name" custom_db_jdbc_property_value = properties[custom_db_jdbc_property_name] if custom_db_jdbc_property_value: properties.process_pair("previous." + custom_db_jdbc_property_name, custom_db_jdbc_property_value) else: if args.jdbc_driver.endswith(TAR_GZ_ARCHIVE_TYPE): symlink_name = args.jdbc_db + "-jdbc-driver" + TAR_GZ_ARCHIVE_TYPE else: symlink_name = args.jdbc_db + "-jdbc-driver.jar" if os.path.lexists(os.path.join(resources_dir, symlink_name)): properties.process_pair("previous." + custom_db_jdbc_property_name, default_connectors_map[args.jdbc_db]) properties.process_pair(custom_db_jdbc_property_name, jdbc_name) if os.path.isfile(os.path.join(resources_dir, jdbc_name)): os.remove(os.path.join(resources_dir, jdbc_name)) try: shutil.copy(args.jdbc_driver, resources_dir) print "Copying {0} to {1}".format(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, str(e)) raise FatalException(1, err)
def wait(self, timeout1, timeout2=0): import win32event timeout = int(timeout1 + timeout2) * 1000 result = win32event.WaitForMultipleObjects( [self._heventStop, self._heventHeartbeat], False, timeout) if (win32event.WAIT_OBJECT_0 != result and win32event.WAIT_OBJECT_0 + 1 != result and win32event.WAIT_TIMEOUT != result): raise FatalException( -1, "Error waiting for stop/heartbeat events: " + str(result)) if (win32event.WAIT_TIMEOUT == result): return -1 return result # 0 -> stop, 1 -> heartbeat
def _createDefDbFactory(options): properties = get_ambari_properties() if properties == -1: raise FatalException(-1, "Error getting ambari properties") if not (properties.getPropertyDict().has_key(JDBC_URL_PROPERTY) and properties.getPropertyDict().has_key(JDBC_RCA_URL_PROPERTY)): raise FatalException( -1, "Ambari Server not set up yet. Nothing to reset.") empty_options = optparse.Values() empty_options.must_set_database_options = options.must_set_database_options empty_options.database_index = options.database_index empty_options.database_host = "" empty_options.database_port = "" empty_options.database_name = "" empty_options.database_windows_auth = False empty_options.database_username = "" empty_options.database_password = "" empty_options.init_db_script_file = "" empty_options.cleanup_db_script_file = "" factory = DBMSConfigFactory() return empty_options, factory, properties
def setup_pam(options): if not is_root(): err = 'Ambari-server setup-pam should be run with root-level privileges' raise FatalException(4, err) properties = get_ambari_properties() if get_value_from_properties(properties,CLIENT_SECURITY,"") == 'ldap': query = "LDAP is currently configured, do you wish to use PAM instead [y/n] (n)? " if get_YN_input(query, False): pass else: err = "LDAP is configured. Can not setup PAM." raise FatalException(1, err) pam_property_list_reqd = init_pam_properties_list_reqd(properties, options) pam_property_value_map = {} pam_property_value_map[CLIENT_SECURITY] = 'pam' for pam_prop in pam_property_list_reqd: input = get_validated_string_input(pam_prop.pam_prop_val_prompt, pam_prop.pam_prop_name, pam_prop.prompt_regex, "Invalid characters in the input!", False, pam_prop.allow_empty_prompt, answer = pam_prop.option) if input is not None and input != "": pam_property_value_map[pam_prop.prop_name] = input # Verify that the PAM config file exists, else show warning... pam_config_file = pam_property_value_map[PAM_CONFIG_FILE] if not os.path.exists(pam_config_file): print_warning_msg("The PAM configuration file, {0} does not exist. " \ "Please create it before restarting Ambari.".format(pam_config_file)) update_properties_2(properties, pam_property_value_map) print 'Saving...done' return 0
def validate_options(options): errors = [] if options.tproxy_enabled and not re.match(REGEX_TRUE_FALSE, options.tproxy_enabled): errors.append("--tproxy-enabled should be to either 'true' or 'false'") if options.tproxy_configuration_file_path and options.tproxy_configuration_file_path is not None: if not os.path.isfile(options.tproxy_configuration_file_path): errors.append( "--tproxy-configuration-file-path is set to a non-existing file: {}" .format(options.tproxy_configuration_file_path)) if len(errors) > 0: error_msg = "The following errors occurred while processing your request: {0}" raise FatalException(1, error_msg.format(str(errors)))
def download_and_install_jdk(options): properties = get_ambari_properties() if properties == -1: err = "Error getting ambari properties" raise FatalException(-1, err) jdkSetup = JDKSetup() jdkSetup.download_and_install_jdk(options, properties) if jdkSetup.jdk_index != jdkSetup.custom_jdk_number: jdkSetup.download_and_unpack_jce_policy(properties) update_properties(properties) return 0
def setup_truststore(import_cert=False): if not get_silent(): 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 get_YN_input("Do you want to configure a truststore [y/n] (y)? ", True): #Re-configuration enabled only for option "Setup truststore" if not import_cert and properties.get_property(SSL_TRUSTSTORE_TYPE_PROPERTY)\ and get_YN_input( "The truststore is already configured. Do you want to re-configure " "the truststore [y/n] (y)? ", True): properties.removeProp(SSL_TRUSTSTORE_TYPE_PROPERTY) properties.removeProp(SSL_TRUSTSTORE_PATH_PROPERTY) properties.removeProp(SSL_TRUSTSTORE_PASSWORD_PROPERTY) truststore_type = get_and_persist_truststore_type(properties) truststore_path = get_and_persist_truststore_path(properties) truststore_password = get_and_persist_truststore_password(properties) if import_cert: if get_YN_input("Do you want to import a certificate [y/n] (y)? ", True): alias = get_validated_string_input("Please enter an alias for the certificate: ", "", None, None, False, False) run_os_command(get_delete_cert_command(jdk_path, alias, truststore_path, truststore_password)) import_cert_path = get_validated_filepath_input( \ "Enter path to certificate: ", \ "Certificate not found") run_component_https_cmd(get_import_cert_command(jdk_path, alias, truststore_type, import_cert_path, truststore_path, truststore_password)) else: return conf_file = find_properties_file() f = open(conf_file, 'w') properties.store(f, "Changed by 'ambari-server setup-security' command") else: print "setup-security is not enabled in silent mode."
def _download_jdk(self, jdk_url, dest_file, progress_func=None): jdk_download_fail_msg = " Failed to download JDK: {0}. Please check that the " \ "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: force_download_file(jdk_url, dest_file, progress_func=progress_func) 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)
def _reset_database(options): properties = get_ambari_properties() if properties == -1: print_error_msg("Error getting ambari properties") return -1 persistence_type = properties[PERSISTENCE_TYPE_PROPERTY] if persistence_type == "remote": err = 'Ambari doesn\'t support resetting exernal DB automatically. ' \ 'To reset Ambari Server schema you must first drop and then create it ' \ 'using DDL scripts from "/var/lib/ambari-server/resources/"' raise FatalException(1, err) else: factory = DBMSConfigFactory() dbmsAmbari = factory.create(options, properties) dbmsAmbari.reset_database()
def _download_jce_policy(jcpol_url, dest_jcpol_file, resources_dir, properties): dest_file = os.path.abspath( os.path.join(resources_dir, dest_jcpol_file)) if not os.path.exists(dest_file): print 'Downloading JCE Policy archive from ' + jcpol_url + ' to ' + dest_file try: force_download_file(jcpol_url, dest_file) print 'Successfully downloaded JCE Policy archive to ' + dest_file except FatalException: raise except Exception, e: err = 'Failed to download JCE Policy archive: ' + str(e) raise FatalException(1, err)
def validate_options(options): errors = [] if options.sso_enabled and not re.match(REGEX_TRUE_FALSE, options.sso_enabled): errors.append("--sso-enabled should be to either 'true' or 'false'") if options.sso_enabled == 'true': if not options.sso_provider_url: errors.append("Missing option: --sso-provider-url") if not options.sso_public_cert_file: errors.append("Missing option: --sso-public-cert-file") if options.sso_provider_url and not re.match(REGEX_URL, options.sso_provider_url): errors.append("Invalid --sso-provider-url") if len(errors) > 0: error_msg = "The following errors occurred while processing your request: {0}" raise FatalException(1, error_msg.format(str(errors)))
def setup_sso(options): logger.info("Setup SSO.") if not is_root(): raise FatalException( 4, 'ambari-server setup-sso should be run with root-level privileges') if not get_silent(): validateOptions(options) properties = get_ambari_properties() must_setup_params = False if not options.sso_enabled: sso_enabled = properties.get_property( JWT_AUTH_ENBABLED).lower() in ['true'] if sso_enabled: if get_YN_input( "Do you want to disable SSO authentication [y/n] (n)?", False): properties.process_pair(JWT_AUTH_ENBABLED, "false") else: if get_YN_input( "Do you want to configure SSO authentication [y/n] (y)?", True): properties.process_pair(JWT_AUTH_ENBABLED, "true") must_setup_params = True else: return False else: properties.process_pair(JWT_AUTH_ENBABLED, options.sso_enabled) must_setup_params = options.sso_enabled == 'true' if must_setup_params: populateSsoProviderUrl(options, properties) populateSsoPublicCert(options, properties) populateJwtCookieName(options, properties) populateJwtAudiences(options, properties) update_properties(properties) pass else: warning = "setup-sso is not enabled in silent mode." raise NonFatalException(warning) pass
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) database_type = properties[JDBC_DATABASE_PROPERTY] if not database_type: print_error_msg("Please run \"ambari-server setup\" command" " to initialize ambari db properties.") 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 os_is_root(): ''' Checks whether the current user is a member of the Administrators group Returns True if yes, otherwise False ''' retcode, out, err = os_run_os_command(WHOAMI_GROUPS) if retcode != 0: err_msg = "Unable to check the current user's group memberships. " \ "Command {0} returned exit code {1} with message: {2}".format(WHOAMI_GROUPS, retcode, err) print_warning_msg(err_msg) raise FatalException(retcode, err_msg) #Check for Administrators group membership if -1 != out.find('\n' + ADMIN_ACCOUNT): return True return False
def perform_changes_via_rest_api(properties, admin_login, admin_password, url_postfix, get_method, request_data=None): url = get_ambari_server_api_base(properties) + url_postfix admin_auth = base64.encodestring('%s:%s' % (admin_login, admin_password)).replace('\n', '') request = urllib2.Request(url) request.add_header('Authorization', 'Basic %s' % admin_auth) request.add_header('X-Requested-By', 'ambari') if request_data is not None: request.add_data(json.dumps(request_data)) request.get_method = lambda: get_method with closing(urllib2.urlopen(request, context=get_ssl_context(properties))) as response: response_status_code = response.getcode() if response_status_code not in (200, 201): err = 'Error while performing changes via Ambari REST API. Http status code - ' + str( response_status_code) raise FatalException(1, err)
def process_stack_addon_service_definitions_artifact(artifact, artifact_source_dir, options): """ Process stack addon service definitions artifact :param artifact: Artifact metadata :param artifact_source_dir: Location of artifact in the management pack :param options: Command line options """ # Get ambari mpack properties stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties( ) service_versions_map = None if "service_versions_map" in artifact: service_versions_map = artifact.service_versions_map if not service_versions_map: msg = "Must provide service versions map for " + STACK_ADDON_SERVICE_DEFINITIONS_ARTIFACT_NAME + " artifact!" print_error_msg(msg) raise FatalException(-1, msg) for service_name in sorted(os.listdir(artifact_source_dir)): source_service_path = os.path.join(artifact_source_dir, service_name) for service_version in sorted(os.listdir(source_service_path)): source_service_version_path = os.path.join(source_service_path, service_version) for service_version_entry in service_versions_map: if service_name == service_version_entry.service_name and service_version == service_version_entry.service_version: applicable_stacks = service_version_entry.applicable_stacks for applicable_stack in applicable_stacks: stack_name = applicable_stack.stack_name stack_version = applicable_stack.stack_version dest_stack_path = os.path.join(stack_location, stack_name) dest_stack_version_path = os.path.join( dest_stack_path, stack_version) dest_stack_services_path = os.path.join( dest_stack_version_path, "services") dest_link = os.path.join(dest_stack_services_path, service_name) if os.path.exists(dest_stack_path) and os.path.exists( dest_stack_version_path): if not os.path.exists(dest_stack_services_path): sudo.makedir(dest_stack_services_path, 0755) if options.force and os.path.islink(dest_link): sudo.unlink(dest_link) sudo.symlink(source_service_version_path, dest_link)
def start(options): from ambari_windows_service import AmbariServerService, ctrlHandler status, pid = is_server_runing() if status: err = "Ambari Server is already running." raise FatalException(1, err) AmbariServerService.set_ctrl_c_handler(ctrlHandler) #Run as a normal process. Invoke the ServiceMain directly. childProc = server_process_main(options) childProc.wait() pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME) remove_file(pid_file_path)
def check_database_name_property(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 (properties[JDBC_DATABASE_PROPERTY] not in ["postgres", "oracle", "mysql", "mssql", "derby"] or properties.has_key(JDBC_RCA_SCHEMA_PROPERTY)): # 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", "mssql", "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 _find_all_jars(self, classpath): """ Return the list of absolute paths to jars in classpath. Raise FatalException() if classpath isn't set Keyword arguments: classpath - java class path """ if classpath: jars = [] for wildcard in classpath.split(os.pathsep): for path in glob.glob(wildcard): if os.path.isfile(path) and path.endswith(".jar"): jars.append(path) return jars else: raise FatalException(1, "No classpath specified.") pass
def wait_for_server_start(pidFile, scmStatus): #wait for server process for SERVER_START_TIMEOUT seconds sys.stdout.write('Waiting for server start...') sys.stdout.flush() pids = looking_for_pid(SERVER_SEARCH_PATTERN, SERVER_INIT_TIMEOUT) found_pids = wait_for_pid(pids, SERVER_START_TIMEOUT) sys.stdout.write('\n') sys.stdout.flush() if found_pids <= 0: exitcode = check_exitcode(os.path.join(configDefaults.PID_DIR, EXITCODE_NAME)) raise FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) else: save_main_pid_ex(pids, pidFile, [locate_file('sh', '/bin'), locate_file('bash', '/bin'), locate_file('dash', '/bin')], True)
def _download_jce_policy(jcpol_url, dest_jcpol_file, resources_dir, properties): dest_file = os.path.abspath(os.path.join(resources_dir, dest_jcpol_file)) if not os.path.exists(dest_file): if properties[JCE_DOWNLOAD_SUPPORTED_PROPERTY].upper() == "FALSE": print "ERROR: JCE Policy archive is not found in {1}. JCE Policy archive download is not supported in this distribution. " \ "Please download JCE Policy archive ({0}) from Oracle site, place it into {1} and re-run this script.".format(dest_jcpol_file, dest_file) print 'Exiting...' sys.exit(1) print 'Downloading JCE Policy archive from ' + jcpol_url + ' to ' + dest_file try: force_download_file(jcpol_url, dest_file) print 'Successfully downloaded JCE Policy archive to ' + dest_file except FatalException: raise except Exception, e: err = 'Failed to download JCE Policy archive: ' + str(e) raise FatalException(1, err)
def wait(self, timeout=None): ''' :param timeout: Time to wait, in seconds. :return: 0 == stop event signaled, -1 = timeout ''' import win32event if timeout is None: timeout = win32event.INFINITE else: timeout = timeout * 1000 result = win32event.WaitForSingleObject(self._heventStop, timeout) if(win32event.WAIT_OBJECT_0 != result and win32event.WAIT_TIMEOUT != result): raise FatalException(-1, "Error waiting for stop event: " + str(result)) if (win32event.WAIT_TIMEOUT == result): return -1 logger.info("Stop event received") return result # 0 -> stop
def validate_mpack_prerequisites(mpack_metadata): """ Validate management pack prerequisites :param mpack_metadata: Management pack metadata """ # Get ambari config properties properties = get_ambari_properties() if properties == -1: print_error_msg("Error getting ambari properties") return -1 stack_location = get_stack_location(properties) current_ambari_version = get_ambari_version(properties) fail = False mpack_prerequisites = mpack_metadata.prerequisites if "min_ambari_version" in mpack_prerequisites: min_ambari_version = mpack_prerequisites.min_ambari_version if(compare_versions(min_ambari_version, current_ambari_version, format=True) > 0): print_error_msg("Prerequisite failure! Current Ambari Version = {0}, " "Min Ambari Version = {1}".format(current_ambari_version, min_ambari_version)) fail = True if "max_ambari_version" in mpack_prerequisites: max_ambari_version = mpack_prerequisites.max_ambari_version if(compare_versions(max_ambari_version, current_ambari_version, format=True) < 0): print_error_msg("Prerequisite failure! Current Ambari Version = {0}, " "Max Ambari Version = {1}".format(current_ambari_version, max_ambari_version)) if "min_stack_versions" in mpack_prerequisites: min_stack_versions = mpack_prerequisites.min_stack_versions stack_found = False for min_stack_version in min_stack_versions: stack_name = min_stack_version.stack_name stack_version = min_stack_version.stack_version stack_dir = os.path.join(stack_location, stack_name, stack_version) if os.path.exists(stack_dir) and os.path.isdir(stack_dir): stack_found = True break if not stack_found: print_error_msg("Prerequisite failure! Min applicable stack not found") fail = True if fail: raise FatalException(-1, "Prerequisites for management pack {0}-{1} failed!".format( mpack_metadata.name, mpack_metadata.version))
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: raise FatalException(int(retcode), "Database check failed to complete: {0}. \nPlease check {1} and {2} for more " "information.".format(stdout+stderr, configDefaults.SERVER_LOG_FILE, configDefaults.DB_CHECK_LOG)) else: print str(stdout) if not stdout.startswith("No errors"): print "Ambari Server 'check-database' completed" sys.exit(1)
def _get_default_dbms_index(self, options): try: dbms_name = options.dbms if not dbms_name: dbms_name = "" except AttributeError: dbms_name = "" try: persistence_type = options.persistence_type if not persistence_type: persistence_type = "" except AttributeError: persistence_type = "" try: def_index = self.DBMS_DICT[dbms_name + "-" + persistence_type] except KeyError: # Unsupported database type (e.g. local Oracle, MySQL or MSSQL) raise FatalException(15, "Invalid database selection: {0} {1}".format( getattr(options, "persistence_type", ""), getattr(options, "options.dbms", ""))) return def_index
def check_jdbc_drivers(args): # create jdbc symlinks if jdbc drivers are available in resources properties = get_ambari_properties() if properties == -1: err = "Error getting ambari properties" print_error_msg(err) raise FatalException(-1, err) resources_dir = get_resources_location(properties) try: db_idx_orig = args.database_index except AttributeError: db_idx_orig = None factory = DBMSConfigFactory() # AMBARI-5696 Validate the symlinks for each supported driver, in case various back-end HDP services happen to # use different DBMSes # This is skipped on Windows db_idx = 1 try: while db_idx < len(factory.get_supported_dbms()): args.database_index = db_idx dbms = factory.create(args, properties) if dbms.driver_symlink_name: jdbc_file_path = os.path.join(resources_dir, dbms.driver_file_name) if os.path.isfile(jdbc_file_path): jdbc_symlink = os.path.join(resources_dir, dbms.driver_symlink_name) if os.path.lexists(jdbc_symlink): os.remove(jdbc_symlink) os.symlink(jdbc_file_path, jdbc_symlink) db_idx += 1 finally: args.database_index = db_idx_orig
def is_server_runing(): pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME) if os.path.exists(pid_file_path): try: f = open(pid_file_path, "r") except IOError, ex: raise FatalException(1, str(ex)) pid = f.readline().strip() if not pid.isdigit(): err = "%s is corrupt. Removing" % (pid_file_path) f.close() run_os_command("rm -f " + pid_file_path) raise NonFatalException(err) f.close() retcode, out, err = run_os_command("ps -p " + pid) if retcode == 0: return True, int(pid) else: return False, None