Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
def publish_stats():
    JBoxUserV2.calc_stats()
    JBoxUserV2.log_debug("stats: %r", JBoxUserV2.STATS)
    JBoxDynConfig.set_stat(CloudHost.INSTALL_ID, JBoxUserV2.STAT_NAME,
                           JBoxUserV2.STATS)
Exemplo n.º 6
0
def publish_stats():
    JBoxUserV2.calc_stats()
    JBoxDynConfig.set_stat(CloudHost.INSTALL_ID, JBoxUserV2.STAT_NAME, JBoxUserV2.STATS)