def is_cluster_leader(): if not CloudHost.ENABLED['cloudwatch']: return False cluster = CloudHost.INSTALL_ID instances = CloudHost.get_autoscaled_instances() leader = JBoxDynConfig.get_cluster_leader(cluster) ami_recentness = CloudHost.get_ami_recentness() JBoxDB.log_debug( "cluster: %s. instances: %s. leader: %s. ami_recentness: %d", cluster, repr(instances), repr(leader), ami_recentness) # if none set, or set instance is dead elect self as leader, but wait till next cycle to prevent conflicts if (leader is None) or (leader not in instances) and (ami_recentness >= 0): JBoxDB.log_info("setting self (%s) as cluster leader", CloudHost.instance_id()) JBoxDynConfig.set_cluster_leader(cluster, CloudHost.instance_id()) return False is_leader = (leader == CloudHost.instance_id()) # if running an older ami, step down from cluster leader if (ami_recentness < 0) and is_leader: JBoxDB.log_info("unmarking self (%s) as cluster leader", CloudHost.instance_id()) JBoxDynConfig.unset_cluster_leader(cluster) return False return is_leader
def is_cluster_leader(): if not CloudHost.ENABLED['cloudwatch']: return False cluster = CloudHost.INSTALL_ID instances = CloudHost.get_autoscaled_instances() leader = JBoxDynConfig.get_cluster_leader(cluster) ami_recentness = CloudHost.get_ami_recentness() JBoxDB.log_debug("cluster: %s. instances: %s. leader: %s. ami_recentness: %d", cluster, repr(instances), repr(leader), ami_recentness) # if none set, or set instance is dead elect self as leader, but wait till next cycle to prevent conflicts if (leader is None) or (leader not in instances) and (ami_recentness >= 0): JBoxDB.log_info("setting self (%s) as cluster leader", CloudHost.instance_id()) JBoxDynConfig.set_cluster_leader(cluster, CloudHost.instance_id()) return False is_leader = (leader == CloudHost.instance_id()) # if running an older ami, step down from cluster leader if (ami_recentness < 0) and is_leader: JBoxDB.log_info("unmarking self (%s) as cluster leader", CloudHost.instance_id()) JBoxDynConfig.unset_cluster_leader(cluster) return False return is_leader
def is_proposed_cluster_leader(): if not CloudHost.ENABLED['cloudwatch']: return False cluster = CloudHost.INSTALL_ID leader = JBoxDynConfig.get_cluster_leader(cluster) return leader == CloudHost.instance_id()
def is_proposed_cluster_leader(): if not CloudHost.ENABLED['cloudwatch']: return False cluster = CloudHost.INSTALL_ID leader = JBoxDynConfig.get_cluster_leader(cluster) return leader == CloudHost.instance_id()
def try_launch_container(cls, user_id, max_hop=False): sessname = unique_sessname(user_id) cont = JBoxContainer.get_by_name(sessname) cls.log_debug("have existing container for %s: %r", sessname, None != cont) if cont is not None: cls.log_debug("container running: %r", cont.is_running()) if max_hop: self_load = CloudHost.get_instance_stats(CloudHost.instance_id(), 'Load') if self_load < 100: JBoxContainer.async_launch_by_name(sessname, user_id, True) return True is_leader = is_proposed_cluster_leader() if ((cont is None) or (not cont.is_running())) and (not CloudHost.should_accept_session(is_leader)): if cont is not None: cont.async_backup_and_cleanup() return False JBoxContainer.async_launch_by_name(sessname, user_id, True) return True
def try_launch_container(cls, user_id, max_hop=False): sessname = unique_sessname(user_id) cont = JBoxContainer.get_by_name(sessname) cls.log_debug("have existing container for %s: %r", sessname, None != cont) if cont is not None: cls.log_debug("container running: %r", cont.is_running()) if max_hop: self_load = CloudHost.get_instance_stats(CloudHost.instance_id(), 'Load') if self_load < 100: JBoxContainer.async_launch_by_name(sessname, user_id, True) return True is_leader = is_proposed_cluster_leader() if ((cont is None) or (not cont.is_running())) and ( not CloudHost.should_accept_session(is_leader)): if cont is not None: cont.async_backup_and_cleanup() return False JBoxContainer.async_launch_by_name(sessname, user_id, True) return True
def set_lb_tracker_cookie(self): self.set_cookie('lb', signstr(CloudHost.instance_id(), self.config('sesskey')), expires_days=30)
def set_lb_tracker_cookie(self): self.set_cookie('lb', signstr(CloudHost.instance_id(), self.config('sesskey')), expires_days=30)