コード例 #1
0
def main():
    args = _parse_args()
    container_id = socket.gethostname()
    docker_inspect = get_docker_inspect(container_id)
    port_and_protocol = _get_port_and_protocol(args.port)
    service_port = int(docker_inspect["NetworkSettings"]["Ports"][port_and_protocol][0]["HostPort"])
    service_filename = microservice_name = os.environ.get("MICROSERVICE_NAME")

    service_id = container_id
    full_service_name = microservice_name
    if args.subservice:
        service_id += ":" + args.subservice
        full_service_name += ":" + args.subservice
        service_filename += "-" + args.subservice

    service_data = {
        "service_id": service_id,
        "service_port": service_port,
        "service_name": full_service_name,
        "service_container_port": args.port,
    }

    if args.health_check:
        service_data["service_health_check_path"] = args.health_check

    _create_service_file(service_filename, service_data)
コード例 #2
0
def main():
    args = _parse_args()
    container_id = socket.gethostname()
    docker_inspect = get_docker_inspect(container_id)
    port_and_protocol = _get_port_and_protocol(args.port)
    service_port = int(docker_inspect['NetworkSettings']['Ports'][port_and_protocol][0]['HostPort'])
    service_filename = microservice_name = os.environ.get('MICROSERVICE_NAME')

    service_id = container_id
    full_service_name = microservice_name
    if args.subservice:
        service_id += ':' + args.subservice
        full_service_name += ':' + args.subservice
        service_filename += '-' + args.subservice

    service_data = {
        "service_id": service_id,
        "service_port": service_port,
        "service_name": full_service_name,
        "service_container_port": args.port,
    }

    if args.health_check:
        service_data["service_health_check_path"] = args.health_check

    _create_service_file(service_filename, service_data)
コード例 #3
0
def main():
    args = _parse_args()
    container_id = socket.gethostname()
    docker_inspect = get_docker_inspect(container_id)

    port_and_protocol = _get_port_and_protocol(args.port)

    service_port = int(docker_inspect['NetworkSettings']['Ports']
                       [port_and_protocol][0]['HostPort'])
    service_filename = microservice_name = os.environ.get('MICROSERVICE_NAME')

    while True:
        try:
            agent_self_dict = consul_query('agent/self')
            if agent_self_dict['Config']:
                break
        except:
            traceback.print_exc()
        time.sleep(1)

    service_id = container_id
    full_service_name = microservice_name
    if args.subservice:
        service_id += ':' + args.subservice
        full_service_name += ':' + args.subservice
        service_filename += '-' + args.subservice

    consul_service_data = {
        'ID': service_id,
        'Name': full_service_name,
        'Port': service_port,
        'Check': {
            'TTL': '15s',
        }
    }
    tags = _create_tags()
    if tags:
        consul_service_data['Tags'] = tags

    print_err('consul_service_data:\n{0}\n'.format(
        json.dumps(consul_service_data)))

    _create_service_file(service_filename, full_service_name, service_id,
                         args.port, args.health_check)
    while True:
        try:
            _register_service(service_id, consul_service_data)
        except:
            print_err('ERROR on registering service:')
            traceback.print_exc()

        try:
            _store_start_timestamp(container_id, docker_inspect["Created"])
        except:
            print_err('ERROR on storing timestamp:')
            traceback.print_exc()

        time.sleep(10 + random.uniform(-2, 2))
コード例 #4
0
ファイル: armada_agent.py プロジェクト: zhengxiongwei/armada
def _register_service_from_file(file_path):
    with open(file_path) as f:
        registration_service_data = json.load(f)

    service_id = registration_service_data['service_id']
    service_name = registration_service_data['service_name']
    service_port = registration_service_data['service_port']
    single_active_instance = registration_service_data[
        'single_active_instance']
    service_tags = _create_tags()

    container_id = service_id.split(':')[0]
    docker_inspect = get_docker_inspect(container_id)
    container_created_timestamp = _datetime_string_to_timestamp(
        docker_inspect["Created"])

    try:
        register_service_in_armada(service_id, service_name, service_port,
                                   service_tags, container_created_timestamp,
                                   single_active_instance)
        return
    except UnsupportedArmadaApiException as e:
        logging.exception(e)
        logging.warning(
            "Armada is using older API than service. '--single-active-instance' flag won't be available "
            "until armada is upgraded.")
    except Exception as e:
        logging.exception(e)

    if _exists_service(service_id):
        return

    consul_service_data = {
        'ID': service_id,
        'Name': service_name,
        'Port': service_port,
        'Check': {
            'TTL': '15s',
        }
    }
    if service_tags:
        consul_service_data['Tags'] = service_tags

    print_err('\nconsul_service_data:\n{0}\n'.format(
        json.dumps(consul_service_data)))

    try:
        _register_service(consul_service_data)
    except:
        print_err('ERROR on registering service:')
        traceback.print_exc()

    try:
        _store_start_timestamp(container_id, container_created_timestamp)
    except:
        print_err('ERROR on storing timestamp:')
        traceback.print_exc()
コード例 #5
0
def main():
    args = _parse_args()
    container_id = socket.gethostname()
    docker_inspect = get_docker_inspect(container_id)

    port_and_protocol = _get_port_and_protocol(args.port)

    service_port = int(docker_inspect['NetworkSettings']['Ports'][port_and_protocol][0]['HostPort'])
    service_filename = microservice_name = os.environ.get('MICROSERVICE_NAME')

    while True:
        try:
            agent_self_dict = consul_query('agent/self')
            if agent_self_dict['Config']:
                break
        except:
            traceback.print_exc()
        time.sleep(1)

    service_id = container_id
    full_service_name = microservice_name
    if args.subservice:
        service_id += ':' + args.subservice
        full_service_name += ':' + args.subservice
        service_filename += "-" + args.subservice

    consul_service_data = {
        'ID': service_id,
        'Name': full_service_name,
        'Port': service_port,
        'Check': {
            'TTL': '15s',
        }
    }
    tags = _create_tags()
    if tags:
        consul_service_data['Tags'] = tags

    print_err('consul_service_data:\n{0}\n'.format(json.dumps(consul_service_data)))

    _create_service_file(service_filename, full_service_name, service_id, args.port, args.health_check)
    while True:
        try:
            _register_service(service_id, consul_service_data)
        except:
            print_err('ERROR on registering service:')
            traceback.print_exc()

        try:
            _store_start_timestamp(container_id, docker_inspect["Created"])
        except:
            print_err('ERROR on storing timestamp:')
            traceback.print_exc()

        time.sleep(10 + random.uniform(-2, 2))
コード例 #6
0
ファイル: armada_agent.py プロジェクト: labuzm/armada
def _register_service_from_file(file_path):
    with open(file_path) as f:
        registration_service_data = json.load(f)

    service_id = registration_service_data['service_id']
    service_name = registration_service_data['service_name']
    service_port = registration_service_data['service_port']
    single_active_instance = registration_service_data['single_active_instance']
    service_tags = _create_tags()

    container_id = service_id.split(':')[0]
    docker_inspect = get_docker_inspect(container_id)
    container_created_timestamp = _datetime_string_to_timestamp(docker_inspect["Created"])

    try:
        register_service_in_armada(service_id, service_name, service_port, service_tags, container_created_timestamp,
                                   single_active_instance)
        return
    except UnsupportedArmadaApiException as e:
        logging.exception(e)
        logging.warning("Armada is using older API than service. '--single-active-instance' flag won't be available "
                        "until armada is upgraded.")
    except Exception as e:
        logging.exception(e)

    if _exists_service(service_id):
        return

    consul_service_data = {
        'ID': service_id,
        'Name': service_name,
        'Port': service_port,
        'Check': {
            'TTL': '15s',
        }
    }
    if service_tags:
        consul_service_data['Tags'] = service_tags

    print_err('\nconsul_service_data:\n{0}\n'.format(json.dumps(consul_service_data)))

    try:
        _register_service(consul_service_data)
    except:
        print_err('ERROR on registering service:')
        traceback.print_exc()

    try:
        _store_start_timestamp(container_id, container_created_timestamp)
    except:
        print_err('ERROR on storing timestamp:')
        traceback.print_exc()
コード例 #7
0
def _register_service_from_file(file_path):
    with open(file_path) as f:
        registration_service_data = json.load(f)

    service_id = registration_service_data['service_id']
    if _exists_service(service_id):
        return

    consul_service_data = {
        'ID': service_id,
        'Name': registration_service_data['service_name'],
        'Port': registration_service_data['service_port'],
        'Check': {
            'TTL': '15s',
        }
    }

    tags = _create_tags()
    if tags:
        consul_service_data['Tags'] = tags

    print_err('\nconsul_service_data:\n{0}\n'.format(
        json.dumps(consul_service_data)))

    try:
        _register_service(consul_service_data)
    except:
        print_err('ERROR on registering service:')
        traceback.print_exc()

    container_id = socket.gethostname()
    docker_inspect = get_docker_inspect(socket.gethostname())

    try:
        _store_start_timestamp(container_id, docker_inspect["Created"])
    except:
        print_err('ERROR on storing timestamp:')
        traceback.print_exc()