<s> from sahara . i18n import _ <EOL> from sahara . plugins import utils as u <EOL> from sahara . plugins . vanilla . hadoop2 import config <EOL> from sahara . plugins . vanilla . hadoop2 import config_helper as c_helper <EOL> from sahara . plugins . vanilla . hadoop2 import run_scripts as run <EOL> from sahara . plugins . vanilla . hadoop2 import utils as pu <EOL> from sahara . plugins . vanilla import utils as vu <EOL> from sahara . swift import swift_helper <EOL> from sahara . utils import cluster_progress_ops as cpo <EOL> from sahara . utils import poll_utils <EOL> HADOOP_CONF_DIR = config . HADOOP_CONF_DIR <EOL> def scale_cluster ( pctx , cluster , instances ) : <EOL> config . configure_instances ( pctx , instances ) <EOL> _update_include_files ( cluster ) <EOL> run . refresh_hadoop_nodes ( cluster ) <EOL> rm = vu . get_resourcemanager ( cluster ) <EOL> if rm : <EOL> run . refresh_yarn_nodes ( cluster ) <EOL> config . configure_topology_data ( pctx , cluster ) <EOL> run . start_dn_nm_processes ( instances ) <EOL> swift_helper . install_ssl_certs ( instances ) <EOL> def _get_instances_with_service ( instances , service ) : <EOL> return [ instance for instance in instances <EOL> if service in instance . node_group . node_processes ] <EOL> @ cpo . event_wrapper ( True , step = _ ( "<STR_LIT>" ) , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def _update_include_files ( cluster , dec_instances = None ) : <EOL> dec_instances = dec_instances or [ ] <EOL> dec_instances_ids = [ instance . id for instance in dec_instances ] <EOL> instances = u . get_instances ( cluster ) <EOL> inst_filter = lambda inst : inst . id not in dec_instances_ids <EOL> datanodes = filter ( inst_filter , vu . get_datanodes ( cluster ) ) <EOL> nodemanagers = filter ( inst_filter , vu . get_nodemanagers ( cluster ) ) <EOL> dn_hosts = u . generate_fqdn_host_names ( datanodes ) <EOL> nm_hosts = u . generate_fqdn_host_names ( nodemanagers ) <EOL> for instance in instances : <EOL> with instance . remote ( ) as r : <EOL> r . execute_command ( <EOL> '<STR_LIT>' % ( <EOL> dn_hosts , HADOOP_CONF_DIR ) ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' % ( <EOL> nm_hosts , HADOOP_CONF_DIR ) ) <EOL> def decommission_nodes ( pctx , cluster , instances ) : <EOL> datanodes = _get_instances_with_service ( instances , '<STR_LIT>' ) <EOL> nodemanagers = _get_instances_with_service ( instances , '<STR_LIT>' ) <EOL> _update_exclude_files ( cluster , instances ) <EOL> run . refresh_hadoop_nodes ( cluster ) <EOL> rm = vu . get_resourcemanager ( cluster ) <EOL> if rm : <EOL> run . refresh_yarn_nodes ( cluster ) <EOL> _check_nodemanagers_decommission ( cluster , nodemanagers ) <EOL> _check_datanodes_decommission ( cluster , datanodes ) <EOL> _update_include_files ( cluster , instances ) <EOL> _clear_exclude_files ( cluster ) <EOL> run . refresh_hadoop_nodes ( cluster ) <EOL> config . configure_topology_data ( pctx , cluster ) <EOL> def _update_exclude_files ( cluster , instances ) : <EOL> datanodes = _get_instances_with_service ( instances , '<STR_LIT>' ) <EOL> nodemanagers = _get_instances_with_service ( instances , '<STR_LIT>' ) <EOL> dn_hosts = u . generate_fqdn_host_names ( datanodes ) <EOL> nm_hosts = u . generate_fqdn_host_names ( nodemanagers ) <EOL> for instance in u . get_instances ( cluster ) : <EOL> with instance . remote ( ) as r : <EOL> r . execute_command ( <EOL> '<STR_LIT>' % ( <EOL> dn_hosts , HADOOP_CONF_DIR ) ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' % ( <EOL> nm_hosts , HADOOP_CONF_DIR ) ) <EOL> def _clear_exclude_files ( cluster ) : <EOL> for instance in u . get_instances ( cluster ) : <EOL> with instance . remote ( ) as r : <EOL> r . execute_command ( <EOL> '<STR_LIT>' % HADOOP_CONF_DIR ) <EOL> r . execute_command ( <EOL> '<STR_LIT>' % HADOOP_CONF_DIR ) <EOL> def is_decommissioned ( cluster , check_func , instances ) : <EOL> statuses = check_func ( cluster ) <EOL> for instance in instances : <EOL> if statuses [ instance . fqdn ( ) ] != '<STR_LIT>' : <EOL> return False <EOL> return True <EOL> def _check_decommission ( cluster , instances , check_func , option ) : <EOL> poll_utils . plugin_option_poll ( <EOL> cluster , is_decommissioned , option , _ ( "<STR_LIT>" ) , <EOL> <NUM_LIT:5> , { '<STR_LIT>' : cluster , '<STR_LIT>' : check_func , <EOL> '<STR_LIT>' : instances } ) <EOL> @ cpo . event_wrapper ( <EOL> True , step = _ ( "<STR_LIT>" ) % "<STR_LIT>" , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def _check_nodemanagers_decommission ( cluster , instances ) : <EOL> _check_decommission ( cluster , instances , pu . get_nodemanagers_status , <EOL> c_helper . NODEMANAGERS_DECOMMISSIONING_TIMEOUT ) <EOL> @ cpo . event_wrapper ( <EOL> True , step = _ ( "<STR_LIT>" ) % "<STR_LIT>" , param = ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def _check_datanodes_decommission ( cluster , instances ) : <EOL> _check_decommission ( cluster , instances , pu . get_datanodes_status , <EOL> c_helper . DATANODES_DECOMMISSIONING_TIMEOUT ) </s>
