예제 #1
0
async def start_service(
    app: web.Application,
    user_id: str,
    project_id: str,
    service_key: str,
    service_tag: str,
    node_uuid: str,
    node_base_path: str,
) -> Dict:
    # pylint: disable=C0103
    log.debug(
        "starting service %s:%s using uuid %s, basepath %s",
        service_key,
        service_tag,
        node_uuid,
        node_base_path,
    )
    # first check the uuid is available
    async with docker_utils.docker_client() as client:  # pylint: disable=not-async-context-manager
        await _check_node_uuid_available(client, node_uuid)
        list_of_images = await _get_repos_from_key(app, service_key)
        service_tag = await _find_service_tag(list_of_images, service_key,
                                              service_tag)
        log.debug("Found service to start %s:%s", service_key, service_tag)
        list_of_services_to_start = [{"key": service_key, "tag": service_tag}]
        # find the service dependencies
        list_of_dependencies = await _get_dependant_repos(
            app, service_key, service_tag)
        log.debug("Found service dependencies: %s", list_of_dependencies)
        if list_of_dependencies:
            list_of_services_to_start.extend(list_of_dependencies)

        containers_meta_data = await _create_node(
            app,
            client,
            user_id,
            project_id,
            list_of_services_to_start,
            node_uuid,
            node_base_path,
        )
        node_details = containers_meta_data[0]
        if config.MONITORING_ENABLED:
            service_started(
                app,
                user_id,
                project_id,
                node_uuid,
                service_key,
                service_tag,
                "DYNAMIC",
            )
        # we return only the info of the main service
        return node_details
async def instrumentation_message_handler(message: aio_pika.IncomingMessage,
                                          app: web.Application) -> None:
    data = json.loads(message.body)
    if data["metrics"] == "service_started":
        service_started(app,
                        **{key: data[key]
                           for key in SERVICE_STARTED_LABELS})
    elif data["metrics"] == "service_stopped":
        service_stopped(app,
                        **{key: data[key]
                           for key in SERVICE_STOPPED_LABELS})
    await message.ack()
async def instrumentation_message_handler(message: aio_pika.IncomingMessage,
                                          app: web.Application) -> None:
    data = json.loads(message.body)
    if data["metrics"] == "service_started":
        service_started(
            app,
            **{key: value
               for key, value in data.items() if key != "metrics"})
    elif data["metrics"] == "service_stopped":
        service_stopped(
            app,
            **{key: value
               for key, value in data.items() if key != "metrics"})
    await message.ack()