def get_next_ha_mrcluster():
 global MR_NAME_CACHE
 candidates = all_mrclusters()
 has_ha = (sum([conf.MR_CLUSTERS[name].SUBMIT_TO.get() for name in conf.MR_CLUSTERS.keys()]) >= 2)
 mrcluster = get_default_mrcluster()
 if (mrcluster is None):
  return None
 current_user = mrcluster.user
 for name in conf.MR_CLUSTERS.keys():
  config = conf.MR_CLUSTERS[name]
  if config.SUBMIT_TO.get():
   jt = candidates[name]
   if has_ha:
    try:
     jt.setuser(current_user)
     status = jt.cluster_status()
     if (status.stateAsString == 'RUNNING'):
      MR_NAME_CACHE = name
      LOG.warn(('Picking HA JobTracker: %s' % name))
      return (config, jt)
     else:
      LOG.info(('JobTracker %s is not RUNNING, skipping it: %s' % (name, status)))
    except Exception as ex:
     LOG.exception(('JobTracker %s is not available, skipping it: %s' % (name, ex)))
   else:
    return (config, jt)
 return None

def get_next_ha_mrcluster ( ) : global MR_NAME_CACHE candidates = all_mrclusters ( ) has_ha = ( sum ( [ conf . MR_CLUSTERS [ name ] . SUBMIT_TO . get ( ) for name in conf . MR_CLUSTERS . keys ( ) ] ) >= 2 ) mrcluster = get_default_mrcluster ( ) if ( mrcluster is None ) : return None current_user = mrcluster . user for name in conf . MR_CLUSTERS . keys ( ) : config = conf . MR_CLUSTERS [ name ] if config . SUBMIT_TO . get ( ) : jt = candidates [ name ] if has_ha : try : jt . setuser ( current_user ) status = jt . cluster_status ( ) if ( status . stateAsString == 'RUNNING' ) : MR_NAME_CACHE = name LOG . warn ( ( 'Picking HA JobTracker: %s' % name ) ) return ( config , jt ) else : LOG . info ( ( 'JobTracker %s is not RUNNING, skipping it: %s' % ( name , status ) ) ) except Exception as ex : LOG . exception ( ( 'JobTracker %s is not available, skipping it: %s' % ( name , ex ) ) ) else : return ( config , jt ) return None
return the next available jt instance and cache its name .