示例#1
0
def _clean_up_kv_store():
    global next_kv_clean_up_timestamp
    if time.time() < next_kv_clean_up_timestamp:
        return
    get_logger().info('Cleaning up kv-store:')
    next_kv_clean_up_timestamp = get_next_kv_clean_up_timestamp()

    services = get_list()
    valid_container_ids = set(
        service.get('container_id') for service in services)

    start_timestamp_keys = kv.kv_list('start_timestamp/') or []
    for key in start_timestamp_keys:
        container_id = key.split('/')[-1]
        if container_id not in valid_container_ids:
            get_logger().info('Removing key: {}'.format(key))
            kv.kv_remove(key)

    single_active_instance_keys = kv.kv_list('single_active_instance/') or []
    for key in single_active_instance_keys:
        container_id = key.split('/')[-1].split(':')[0]
        if container_id not in valid_container_ids:
            get_logger().info('Removing key: {}'.format(key))
            kv.kv_remove(key)
    get_logger().info('Finished cleaning up kv-store.')
示例#2
0
def _consul_discover(service_name):
    services = get_list(service_name)
    service_addresses = set()
    for service in services:
        if service['status'] in ['passing', 'warning']:
            service_addresses.add(service['address'])
    return service_addresses
示例#3
0
def wait_for_consul_ready(timeout_seconds=60):
    timeout_expiration = time.time() + timeout_seconds
    last_exception = None
    while time.time() < timeout_expiration:
        time.sleep(1)
        try:
            armada_instances = get_list('armada', local=True)
            if armada_instances[0]['status'] == 'passing':
                return True
        except Exception as e:
            last_exception = e
    if last_exception:
        logging.exception(last_exception)
    return False
示例#4
0
def _get_running_armada_services():
    return get_list('armada')