<s> from oslo_serialization import jsonutils as json <EOL> import six <EOL> import sahara . exceptions as e <EOL> from sahara . i18n import _ <EOL> import sahara . plugins . exceptions as ex <EOL> from sahara . plugins . mapr . util import event_log as el <EOL> from sahara . plugins . mapr . util import general as g <EOL> from sahara . plugins . mapr . util import service_utils as su <EOL> import sahara . plugins . provisioning as p <EOL> from sahara . utils import files as files <EOL> _INSTALL_PACKAGES_TIMEOUT = <NUM_LIT> <EOL> @ six . add_metaclass ( g . Singleton ) <EOL> class Service ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _name = None <EOL> self . _ui_name = None <EOL> self . _node_processes = [ ] <EOL> self . _version = None <EOL> self . _dependencies = [ ] <EOL> self . _ui_info = [ ] <EOL> self . _cluster_defaults = [ ] <EOL> self . _node_defaults = [ ] <EOL> self . _validation_rules = [ ] <EOL> self . _priority = <NUM_LIT:1> <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ property <EOL> def ui_name ( self ) : <EOL> return self . _ui_name <EOL> @ property <EOL> def version ( self ) : <EOL> return self . _version <EOL> @ property <EOL> def node_processes ( self ) : <EOL> return self . _node_processes <EOL> @ property <EOL> def dependencies ( self ) : <EOL> return self . _dependencies <EOL> @ property <EOL> def ui_info ( self ) : <EOL> return self . _ui_info <EOL> @ property <EOL> def cluster_defaults ( self ) : <EOL> return self . _cluster_defaults <EOL> @ property <EOL> def node_defaults ( self ) : <EOL> return self . _node_defaults <EOL> @ property <EOL> def validation_rules ( self ) : <EOL> return self . _validation_rules <EOL> def install ( self , cluster_context , instances ) : <EOL> g . execute_on_instances ( instances , self . _install_packages_on_instance , <EOL> cluster_context ) <EOL> @ el . provision_event ( instance_reference = <NUM_LIT:1> ) <EOL> def _install_packages_on_instance ( self , instance , cluster_context ) : <EOL> processes = [ p for p in self . node_processes if <EOL> p . ui_name in instance . node_group . node_processes ] <EOL> if processes is not None and len ( processes ) > <NUM_LIT:0> : <EOL> packages = self . _get_packages ( cluster_context , processes ) <EOL> cmd = cluster_context . distro . create_install_cmd ( packages ) <EOL> with instance . remote ( ) as r : <EOL> r . execute_command ( cmd , run_as_root = True , <EOL> timeout = _INSTALL_PACKAGES_TIMEOUT ) <EOL> def _get_packages ( self , cluster_context , node_processes ) : <EOL> result = [ ] <EOL> result += self . dependencies <EOL> result += [ ( np . package , self . version ) for np in node_processes ] <EOL> return result <EOL> def post_install ( self , cluster_context , instances ) : <EOL> pass <EOL> def post_start ( self , cluster_context , instances ) : <EOL> pass <EOL> def configure ( self , cluster_context , instances = None ) : <EOL> pass <EOL> def update ( self , cluster_context , instances = None ) : <EOL> pass <EOL> def get_file_path ( self , file_name ) : <EOL> template = '<STR_LIT>' <EOL> args = { '<STR_LIT>' : self . name , '<STR_LIT>' : file_name } <EOL> return template % args <EOL> def get_configs ( self ) : <EOL> result = [ ] <EOL> for d_file in self . cluster_defaults : <EOL> data = self . _load_config_file ( self . get_file_path ( d_file ) ) <EOL> result += [ self . _create_config_obj ( c , self . ui_name ) for c in data ] <EOL> for d_file in self . node_defaults : <EOL> data = self . _load_config_file ( self . get_file_path ( d_file ) ) <EOL> result += [ self . _create_config_obj ( c , self . ui_name , scope = '<STR_LIT>' ) <EOL> for c in data ] <EOL> return result <EOL> def get_configs_dict ( self ) : <EOL> result = dict ( ) <EOL> for conf_obj in self . get_configs ( ) : <EOL> result . update ( { conf_obj . name : conf_obj . default_value } ) <EOL> return { self . ui_name : result } <EOL> def _load_config_file ( self , file_path = None ) : <EOL> return json . loads ( files . get_file_text ( file_path ) ) <EOL> def get_config_files ( self , cluster_context , configs , instance = None ) : <EOL> return [ ] <EOL> def _create_config_obj ( self , item , target = '<STR_LIT>' , scope = '<STR_LIT>' , <EOL> high_priority = False ) : <EOL> def _prepare_value ( value ) : <EOL> if isinstance ( value , str ) : <EOL> return value . strip ( ) . lower ( ) <EOL> return value <EOL> conf_name = _prepare_value ( item . get ( '<STR_LIT:name>' , None ) ) <EOL> conf_value = _prepare_value ( item . get ( '<STR_LIT:value>' , None ) ) <EOL> if not conf_name : <EOL> raise ex . HadoopProvisionError ( _ ( "<STR_LIT>" ) ) <EOL> if conf_value is None : <EOL> raise e . InvalidDataException ( <EOL> _ ( "<STR_LIT>" ) % conf_name ) <EOL> if high_priority or item . get ( '<STR_LIT>' , <NUM_LIT:2> ) == <NUM_LIT:1> : <EOL> priority = <NUM_LIT:1> <EOL> else : <EOL> priority = <NUM_LIT:2> <EOL> return p . Config ( <EOL> name = conf_name , <EOL> applicable_target = target , <EOL> scope = scope , <EOL> config_type = item . get ( '<STR_LIT>' , "<STR_LIT:string>" ) , <EOL> config_values = item . get ( '<STR_LIT>' , None ) , <EOL> default_value = conf_value , <EOL> is_optional = item . get ( '<STR_LIT>' , True ) , <EOL> description = item . get ( '<STR_LIT:description>' , None ) , <EOL> priority = priority ) <EOL> def get_version_config ( self , versions ) : <EOL> return p . Config ( <EOL> name = '<STR_LIT>' % self . _ui_name , <EOL> applicable_target = self . ui_name , <EOL> scope = '<STR_LIT>' , <EOL> config_type = '<STR_LIT>' , <EOL> config_values = [ ( v , v ) for v in sorted ( versions , reverse = True ) ] , <EOL> is_optional = False , <EOL> description = _ ( '<STR_LIT>' ) , <EOL> priority = <NUM_LIT:1> ) <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , self . __class__ ) : <EOL> version_eq = self . version == other . version <EOL> ui_name_eq = self . ui_name == other . ui_name <EOL> return version_eq and ui_name_eq <EOL> return NotImplemented <EOL> def restart ( self , instances ) : <EOL> for node_process in self . node_processes : <EOL> filtered_instances = su . filter_by_node_process ( instances , <EOL> node_process ) <EOL> if filtered_instances : <EOL> node_process . restart ( filtered_instances ) <EOL> def service_dir ( self , cluster_context ) : <EOL> args = { '<STR_LIT>' : cluster_context . mapr_home , '<STR_LIT:name>' : self . name } <EOL> return '<STR_LIT>' % args <EOL> def home_dir ( self , cluster_context ) : <EOL> args = { <EOL> '<STR_LIT>' : self . service_dir ( cluster_context ) , <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT:version>' : self . version , <EOL> } <EOL> return '<STR_LIT>' % args <EOL> def conf_dir ( self , cluster_context ) : <EOL> return '<STR_LIT>' % self . home_dir ( cluster_context ) <EOL> def post_configure_sh ( self , cluster_context , instances ) : <EOL> pass </s>
