<s> from oslo_serialization import jsonutils as json <EOL> import six <EOL> from sahara . plugins . cdh . client import role_config_groups <EOL> from sahara . plugins . cdh . client import roles <EOL> from sahara . plugins . cdh . client import types <EOL> SERVICES_PATH = "<STR_LIT>" <EOL> SERVICE_PATH = "<STR_LIT>" <EOL> ROLETYPES_CFG_KEY = '<STR_LIT>' <EOL> def create_service ( resource_root , name , service_type , <EOL> cluster_name = "<STR_LIT:default>" ) : <EOL> """<STR_LIT>""" <EOL> apiservice = ApiService ( resource_root , name , service_type ) <EOL> return types . call ( resource_root . post , SERVICES_PATH % ( cluster_name , ) , <EOL> ApiService , True , data = [ apiservice ] ) [ <NUM_LIT:0> ] <EOL> def get_service ( resource_root , name , cluster_name = "<STR_LIT:default>" ) : <EOL> """<STR_LIT>""" <EOL> return _get_service ( resource_root , "<STR_LIT>" <EOL> % ( SERVICES_PATH % ( cluster_name , ) , name ) ) <EOL> def _get_service ( resource_root , path ) : <EOL> return types . call ( resource_root . get , path , ApiService ) <EOL> def get_all_services ( resource_root , cluster_name = "<STR_LIT:default>" , view = None ) : <EOL> """<STR_LIT>""" <EOL> return types . call ( resource_root . get , SERVICES_PATH % ( cluster_name , ) , <EOL> ApiService , True , <EOL> params = ( dict ( view = view ) if view else None ) ) <EOL> def delete_service ( resource_root , name , cluster_name = "<STR_LIT:default>" ) : <EOL> """<STR_LIT>""" <EOL> return types . call ( resource_root . delete , <EOL> "<STR_LIT>" % ( SERVICES_PATH % ( cluster_name , ) , name ) , <EOL> ApiService ) <EOL> class ApiService ( types . BaseApiResource ) : <EOL> _ATTRIBUTES = { <EOL> '<STR_LIT:name>' : None , <EOL> '<STR_LIT:type>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( types . ApiClusterRef ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> '<STR_LIT>' : types . ROAttr ( ) , <EOL> } <EOL> def __init__ ( self , resource_root , name = None , type = None ) : <EOL> types . BaseApiObject . init ( self , resource_root , locals ( ) ) <EOL> def __str__ ( self ) : <EOL> return ( "<STR_LIT>" <EOL> % ( self . name , self . _get_cluster_name ( ) ) ) <EOL> def _get_cluster_name ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . clusterRef : <EOL> return self . clusterRef . clusterName <EOL> return None <EOL> def _path ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _get_cluster_name ( ) : <EOL> return SERVICE_PATH % ( self . _get_cluster_name ( ) , self . name ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _role_cmd ( self , cmd , roles , api_version = <NUM_LIT:1> ) : <EOL> return self . _post ( "<STR_LIT>" + cmd , types . ApiBulkCommandList , <EOL> data = roles , api_version = api_version ) <EOL> def _parse_svc_config ( self , json_dic , view = None ) : <EOL> """<STR_LIT>""" <EOL> svc_config = types . json_to_config ( json_dic , view == '<STR_LIT>' ) <EOL> rt_configs = { } <EOL> if ROLETYPES_CFG_KEY in json_dic : <EOL> for rt_config in json_dic [ ROLETYPES_CFG_KEY ] : <EOL> rt_configs [ rt_config [ '<STR_LIT>' ] ] = types . json_to_config ( <EOL> rt_config , view == '<STR_LIT>' ) <EOL> return ( svc_config , rt_configs ) <EOL> def create_yarn_job_history_dir ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , api_version = <NUM_LIT:6> ) <EOL> def get_config ( self , view = None ) : <EOL> """<STR_LIT>""" <EOL> path = self . _path ( ) + '<STR_LIT>' <EOL> resp = self . _get_resource_root ( ) . get ( <EOL> path , params = ( dict ( view = view ) if view else None ) ) <EOL> return self . _parse_svc_config ( resp , view ) <EOL> def update_config ( self , svc_config , ** rt_configs ) : <EOL> """<STR_LIT>""" <EOL> path = self . _path ( ) + '<STR_LIT>' <EOL> if svc_config : <EOL> data = types . config_to_api_list ( svc_config ) <EOL> else : <EOL> data = { } <EOL> if rt_configs : <EOL> rt_list = [ ] <EOL> for rt , cfg in six . iteritems ( rt_configs ) : <EOL> rt_data = types . config_to_api_list ( cfg ) <EOL> rt_data [ '<STR_LIT>' ] = rt <EOL> rt_list . append ( rt_data ) <EOL> data [ ROLETYPES_CFG_KEY ] = rt_list <EOL> resp = self . _get_resource_root ( ) . put ( path , data = json . dumps ( data ) ) <EOL> return self . _parse_svc_config ( resp ) <EOL> def create_role ( self , role_name , role_type , host_id ) : <EOL> """<STR_LIT>""" <EOL> return roles . create_role ( self . _get_resource_root ( ) , self . name , <EOL> role_type , role_name , host_id , <EOL> self . _get_cluster_name ( ) ) <EOL> def delete_role ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return roles . delete_role ( self . _get_resource_root ( ) , self . name , name , <EOL> self . _get_cluster_name ( ) ) <EOL> def get_roles_by_type ( self , role_type , view = None ) : <EOL> """<STR_LIT>""" <EOL> return roles . get_roles_by_type ( self . _get_resource_root ( ) , self . name , <EOL> role_type , self . _get_cluster_name ( ) , <EOL> view ) <EOL> def get_all_role_config_groups ( self ) : <EOL> """<STR_LIT>""" <EOL> return role_config_groups . get_all_role_config_groups ( <EOL> self . _get_resource_root ( ) , self . name , self . _get_cluster_name ( ) ) <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT:start>' ) <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def restart ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def get_health_summary ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , None ) <EOL> def get_health_checks_status ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , None ) <EOL> def start_roles ( self , * role_names ) : <EOL> """<STR_LIT>""" <EOL> return self . _role_cmd ( '<STR_LIT:start>' , role_names ) <EOL> def create_hbase_root ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def create_hdfs_tmp ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def refresh ( self , * role_names ) : <EOL> """<STR_LIT>""" <EOL> return self . _role_cmd ( '<STR_LIT>' , role_names ) <EOL> def decommission ( self , * role_names ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , data = role_names ) <EOL> def deploy_client_config ( self , * role_names ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , data = role_names ) <EOL> def format_hdfs ( self , * namenodes ) : <EOL> """<STR_LIT>""" <EOL> return self . _role_cmd ( '<STR_LIT>' , namenodes ) <EOL> def install_oozie_sharelib ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , api_version = <NUM_LIT:3> ) <EOL> def create_oozie_db ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , api_version = <NUM_LIT:2> ) <EOL> def upgrade_oozie_db ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , api_version = <NUM_LIT:6> ) <EOL> def create_hive_metastore_tables ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' , api_version = <NUM_LIT:3> ) <EOL> def create_hive_warehouse ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def create_hive_userdir ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _cmd ( '<STR_LIT>' ) <EOL> def enable_nn_ha ( self , active_name , standby_host_id , nameservice , jns , <EOL> standby_name_dir_list = None , qj_name = None , <EOL> standby_name = None , active_fc_name = None , <EOL> standby_fc_name = None , zk_service_name = None , <EOL> force_init_znode = True , <EOL> clear_existing_standby_name_dirs = True , <EOL> clear_existing_jn_edits_dir = True ) : <EOL> """<STR_LIT>""" <EOL> args = dict ( <EOL> activeNnName = active_name , <EOL> standbyNnName = standby_name , <EOL> standbyNnHostId = standby_host_id , <EOL> standbyNameDirList = standby_name_dir_list , <EOL> nameservice = nameservice , <EOL> qjName = qj_name , <EOL> activeFcName = active_fc_name , <EOL> standbyFcName = standby_fc_name , <EOL> zkServiceName = zk_service_name , <EOL> forceInitZNode = force_init_znode , <EOL> clearExistingStandbyNameDirs = clear_existing_standby_name_dirs , <EOL> clearExistingJnEditsDir = clear_existing_jn_edits_dir , <EOL> jns = jns <EOL> ) <EOL> return self . _cmd ( '<STR_LIT>' , data = args , api_version = <NUM_LIT:6> ) <EOL> def enable_rm_ha ( self , new_rm_host_id , zk_service_name = None ) : <EOL> """<STR_LIT>""" <EOL> args = dict ( <EOL> newRmHostId = new_rm_host_id , <EOL> zkServiceName = zk_service_name <EOL> ) <EOL> return self . _cmd ( '<STR_LIT>' , data = args ) <EOL> class ApiServiceSetupInfo ( ApiService ) : <EOL> _ATTRIBUTES = { <EOL> '<STR_LIT:name>' : None , <EOL> '<STR_LIT:type>' : None , <EOL> '<STR_LIT>' : types . Attr ( types . ApiConfig ) , <EOL> '<STR_LIT>' : types . Attr ( roles . ApiRole ) , <EOL> } <EOL> def __init__ ( self , name = None , type = None , <EOL> config = None , roles = None ) : <EOL> resource_root = None <EOL> types . BaseApiObject . init ( self , None , locals ( ) ) <EOL> def set_config ( self , config ) : <EOL> """<STR_LIT>""" <EOL> if self . config is None : <EOL> self . config = { } <EOL> self . config . update ( types . config_to_api_list ( config ) ) <EOL> def add_role_info ( self , role_name , role_type , host_id , config = None ) : <EOL> """<STR_LIT>""" <EOL> if self . roles is None : <EOL> self . roles = [ ] <EOL> api_config_list = ( config is not None <EOL> and types . config_to_api_list ( config ) <EOL> or None ) <EOL> self . roles . append ( { <EOL> '<STR_LIT:name>' : role_name , <EOL> '<STR_LIT:type>' : role_type , <EOL> '<STR_LIT>' : { '<STR_LIT>' : host_id } , <EOL> '<STR_LIT>' : api_config_list } ) </s>
