<s> import re <EOL> from oslo_log import log as logging <EOL> from sahara . i18n import _ <EOL> from sahara . i18n import _LI <EOL> from sahara . plugins import exceptions as ex <EOL> from sahara . plugins . hdp import saharautils <EOL> from sahara . utils import cluster_progress_ops as cpo <EOL> from sahara . utils import files as f <EOL> AMBARI_RPM = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> EPEL_RELEASE_PACKAGE_NAME = '<STR_LIT>' <EOL> HADOOP_SWIFT_RPM = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> HADOOP_SWIFT_LOCAL_RPM = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class HadoopServer ( object ) : <EOL> _master_ip = None <EOL> def __init__ ( self , instance , node_group , ambari_rpm = None ) : <EOL> self . instance = instance <EOL> self . node_group = node_group <EOL> self . ambari_rpm = ambari_rpm or AMBARI_RPM <EOL> def get_event_info ( self ) : <EOL> return self . instance <EOL> @ property <EOL> def cluster_id ( self ) : <EOL> return self . instance . cluster_id <EOL> @ cpo . event_wrapper ( True , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def provision_ambari ( self , ambari_info , cluster_spec ) : <EOL> self . install_rpms ( ) <EOL> global_config = cluster_spec . configurations [ '<STR_LIT>' ] <EOL> jdk_path = global_config . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in self . node_group . components : <EOL> self . _setup_and_start_ambari_server ( ambari_info . port , jdk_path ) <EOL> self . _setup_and_start_ambari_agent ( ambari_info . host . internal_ip ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def rpms_installed ( self , r ) : <EOL> rpm_cmd = '<STR_LIT>' % EPEL_RELEASE_PACKAGE_NAME <EOL> ret_code , stdout = r . execute_command ( rpm_cmd , <EOL> run_as_root = True , <EOL> raise_when_error = False ) <EOL> return ret_code == <NUM_LIT:0> <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def install_rpms ( self , r ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> curl_cmd = ( '<STR_LIT>' % <EOL> self . ambari_rpm ) <EOL> ret_code , stdout = r . execute_command ( curl_cmd , <EOL> run_as_root = True , <EOL> raise_when_error = False ) <EOL> if ret_code == <NUM_LIT:0> : <EOL> yum_cmd = '<STR_LIT>' % EPEL_RELEASE_PACKAGE_NAME <EOL> r . execute_command ( yum_cmd , run_as_root = True ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not self . rpms_installed ( ) : <EOL> raise ex . HadoopProvisionError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> @ cpo . event_wrapper ( True , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def install_swift_integration ( self , r ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> base_rpm_cmd = '<STR_LIT>' <EOL> rpm_cmd = base_rpm_cmd + HADOOP_SWIFT_RPM <EOL> ret_code , stdout = r . execute_command ( rpm_cmd , <EOL> run_as_root = True , <EOL> raise_when_error = False ) <EOL> if ret_code != <NUM_LIT:0> : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ret_code , stdout = r . execute_command ( <EOL> '<STR_LIT>' + HADOOP_SWIFT_LOCAL_RPM , <EOL> run_as_root = True , <EOL> raise_when_error = False ) <EOL> if ret_code == <NUM_LIT:0> : <EOL> rpm_cmd = base_rpm_cmd + HADOOP_SWIFT_LOCAL_RPM <EOL> r . execute_command ( rpm_cmd , run_as_root = True ) <EOL> else : <EOL> raise ex . HadoopProvisionError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> @ cpo . event_wrapper ( True , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def configure_topology ( self , topology_str , r ) : <EOL> r . write_file_to ( <EOL> '<STR_LIT>' , <EOL> f . get_file_text ( <EOL> '<STR_LIT>' ) ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' , run_as_root = True <EOL> ) <EOL> r . write_file_to ( '<STR_LIT>' , topology_str ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def _setup_and_start_ambari_server ( self , port , jdk_path , r ) : <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> r . execute_command ( '<STR_LIT>' , run_as_root = True ) <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> r . execute_command ( '<STR_LIT>' , run_as_root = True ) <EOL> return_code , stdout = r . execute_command ( '<STR_LIT>' . format ( <EOL> jdk_location = jdk_path ) , raise_when_error = False ) <EOL> LOG . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( code = str ( return_code ) ) ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' . format ( <EOL> jdk_arg = '<STR_LIT>' + jdk_path if jdk_path and ( return_code == <NUM_LIT:0> ) <EOL> else '<STR_LIT>' ) , <EOL> run_as_root = True , timeout = <NUM_LIT> <EOL> ) <EOL> self . _configure_ambari_server_api_port ( port ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' , run_as_root = True <EOL> ) <EOL> LOG . info ( _LI ( '<STR_LIT>' ) ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def _configure_ambari_server_api_port ( self , port , r ) : <EOL> if port is None or port == <NUM_LIT> : <EOL> return <EOL> ambari_config_file = '<STR_LIT>' <EOL> LOG . debug ( '<STR_LIT>' . format ( <EOL> port = port ) ) <EOL> data = r . read_file_from ( ambari_config_file ) <EOL> data = '<STR_LIT>' . format ( data , port ) <EOL> r . write_file_to ( ambari_config_file , data , run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def _setup_and_start_ambari_agent ( self , ambari_server_ip , r ) : <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> r . execute_command ( '<STR_LIT>' , run_as_root = True ) <EOL> LOG . debug ( <EOL> '<STR_LIT>' . format ( <EOL> ip = ambari_server_ip ) ) <EOL> r . replace_remote_string ( <EOL> '<STR_LIT>' , '<STR_LIT:localhost>' , <EOL> ambari_server_ip ) <EOL> r . execute_command ( '<STR_LIT>' , run_as_root = True ) <EOL> LOG . info ( _LI ( '<STR_LIT>' ) ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def set_namenode_safemode ( self , jh , r ) : <EOL> r . execute_command ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( jh ) , <EOL> run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def save_namenode_namespace ( self , jh , r ) : <EOL> r . execute_command ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( jh ) , <EOL> run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def initialize_shared_edits ( self , jh , r ) : <EOL> r . execute_command ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( jh ) , <EOL> run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def format_zookeeper_fc ( self , jh , r ) : <EOL> r . execute_command ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( jh ) , <EOL> run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def bootstrap_standby_namenode ( self , jh , r ) : <EOL> r . execute_command ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( jh ) , <EOL> run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def install_httpfs ( self , r ) : <EOL> r . execute_command ( "<STR_LIT>" , run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def start_httpfs ( self , r ) : <EOL> r . execute_command ( "<STR_LIT>" , run_as_root = True ) <EOL> @ saharautils . inject_remote ( '<STR_LIT:r>' ) <EOL> def write_hue_temp_file ( self , filename , content , r ) : <EOL> r . execute_command ( "<STR_LIT>" % ( content , filename ) , <EOL> run_as_root = True ) <EOL> def _log ( self , buf ) : <EOL> LOG . debug ( buf ) <EOL> def _is_component_available ( self , component ) : <EOL> return component in self . node_group . components <EOL> def _is_ganglia_master ( self ) : <EOL> return self . _is_component_available ( '<STR_LIT>' ) <EOL> def _is_ganglia_slave ( self ) : <EOL> return self . _is_component_available ( '<STR_LIT>' ) <EOL> class DefaultPromptMatcher ( object ) : <EOL> prompt_pattern = re . compile ( '<STR_LIT>' , re . DOTALL ) <EOL> def __init__ ( self , terminal_token ) : <EOL> self . eof_token = terminal_token <EOL> def get_response ( self , s ) : <EOL> match = self . prompt_pattern . match ( s ) <EOL> if match : <EOL> response = match . group ( <NUM_LIT:2> ) <EOL> return response <EOL> else : <EOL> return None <EOL> def is_eof ( self , s ) : <EOL> eof = self . eof_token in s <EOL> return eof </s>
