Example #1
0
def marathon_job_status(mstatus, client, job_config, verbose):
    try:
        app_id = job_config.format_marathon_app_dict()['id']
    except NoDockerImageError:
        error_msg = "Docker image is not in deployments.json."
        mstatus['error_message'] = error_msg
        return

    mstatus['app_id'] = app_id
    if verbose is True:
        mstatus['slaves'] = list({
            task.slave['hostname']
            for task in get_running_tasks_from_frameworks(app_id)
        })
    mstatus['expected_instance_count'] = job_config.get_instances()

    deploy_status = marathon_tools.get_marathon_app_deploy_status(
        client, app_id)
    mstatus['deploy_status'] = marathon_tools.MarathonDeployStatus.tostring(
        deploy_status)

    # by comparing running count with expected count, callers can figure
    # out if the instance is in Healthy, Warning or Critical state.
    if deploy_status == marathon_tools.MarathonDeployStatus.NotRunning:
        mstatus['running_instance_count'] = 0
    else:
        mstatus['running_instance_count'] = client.get_app(
            app_id).tasks_running

    if deploy_status == marathon_tools.MarathonDeployStatus.Delayed:
        _, backoff_seconds = marathon_tools.get_app_queue_status(
            client, app_id)
        mstatus['backoff_seconds'] = backoff_seconds
Example #2
0
def marathon_job_status(mstatus, client, job_config):
    try:
        app_id = job_config.format_marathon_app_dict()['id']
    except NoDockerImageError:
        error_msg = "Docker image is not in deployments.json."
        mstatus['error_message'] = error_msg
        return

    mstatus['app_id'] = app_id
    mstatus['slaves'] = list({task.slave['hostname'] for task in get_running_tasks_from_active_frameworks(app_id)})
    mstatus['expected_instance_count'] = job_config.get_instances()

    deploy_status = marathon_tools.get_marathon_app_deploy_status(client, app_id)
    mstatus['deploy_status'] = marathon_tools.MarathonDeployStatus.tostring(deploy_status)

    # by comparing running count with expected count, callers can figure
    # out if the instance is in Healthy, Warning or Critical state.
    if deploy_status == marathon_tools.MarathonDeployStatus.NotRunning:
        mstatus['running_instance_count'] = 0
    else:
        mstatus['running_instance_count'] = client.get_app(app_id).tasks_running

    if deploy_status == marathon_tools.MarathonDeployStatus.Delayed:
        _, backoff_seconds = marathon_tools.get_app_queue_status(client, app_id)
        mstatus['backoff_seconds'] = backoff_seconds
Example #3
0
def status_marathon_job(service, instance, app_id, normal_instance_count, client):
    status = marathon_tools.get_marathon_app_deploy_status(client, app_id)
    if status == marathon_tools.MarathonDeployStatus.Delayed:
        _, backoff_seconds = marathon_tools.get_app_queue_status(client, app_id)
        deploy_status_human = marathon_app_deploy_status_human(status, backoff_seconds)
    else:
        deploy_status_human = marathon_app_deploy_status_human(status)

    if status == marathon_tools.MarathonDeployStatus.NotRunning:
        running_instances = 0
    else:
        running_instances = client.get_app(app_id).tasks_running
    return status_marathon_job_human(service, instance, deploy_status_human, app_id,
                                     running_instances, normal_instance_count)
Example #4
0
def status_marathon_job(service, instance, app_id, normal_instance_count, client):
    status = marathon_tools.get_marathon_app_deploy_status(client, app_id)
    if status == marathon_tools.MarathonDeployStatus.Delayed:
        _, backoff_seconds = marathon_tools.get_app_queue_status(client, app_id)
        deploy_status_human = marathon_app_deploy_status_human(status, backoff_seconds)
    else:
        deploy_status_human = marathon_app_deploy_status_human(status)

    if status == marathon_tools.MarathonDeployStatus.NotRunning:
        running_instances = 0
    else:
        running_instances = client.get_app(app_id).tasks_running
    return status_marathon_job_human(service, instance, deploy_status_human, app_id,
                                     running_instances, normal_instance_count)
Example #5
0
def marathon_job_status(
    mstatus: MutableMapping[str, Any],
    client,
    job_config,
    verbose: bool,
) -> None:
    try:
        app_id = job_config.format_marathon_app_dict()['id']
    except NoDockerImageError:
        error_msg = "Docker image is not in deployments.json."
        mstatus['error_message'] = error_msg
        return

    mstatus['app_id'] = app_id
    if verbose is True:
        mstatus['slaves'] = list(
            {
                a_sync.block(task.slave)['hostname']
                for task in a_sync.block(get_running_tasks_from_frameworks,
                                         app_id)
            }, )
    mstatus['expected_instance_count'] = job_config.get_instances()

    try:
        app = client.get_app(app_id)
    except marathon.exceptions.NotFoundError:
        mstatus[
            'deploy_status'] = marathon_tools.MarathonDeployStatus.tostring(
                marathon_tools.MarathonDeployStatus.NotRunning, )
        mstatus['running_instance_count'] = 0
    else:
        deploy_status = marathon_tools.get_marathon_app_deploy_status(
            client, app)
        mstatus[
            'deploy_status'] = marathon_tools.MarathonDeployStatus.tostring(
                deploy_status)
        # by comparing running count with expected count, callers can figure
        # out if the instance is in Healthy, Warning or Critical state.
        mstatus['running_instance_count'] = app.tasks_running

        if deploy_status == marathon_tools.MarathonDeployStatus.Delayed:
            _, backoff_seconds = marathon_tools.get_app_queue_status(
                client, app_id)
            mstatus['backoff_seconds'] = backoff_seconds
Example #6
0
def status_marathon_job(service, instance, app_id, normal_instance_count,
                        client):
    name = PaastaColors.cyan(compose_job_id(service, instance))
    if marathon_tools.is_app_id_running(app_id, client):
        app = client.get_app(app_id)
        running_instances = app.tasks_running

        if len(app.deployments) == 0:
            deploy_status = PaastaColors.bold("Running")
        elif app.instances == 0 and app.tasks_running == 0:
            deploy_status = PaastaColors.grey("Stopped")
        else:
            # App is currently deploying so we should check the launch queue for more info
            is_overdue, backoff_seconds = marathon_tools.get_app_queue_status(
                client, app_id)

            if is_overdue:
                deploy_status = "%s (new tasks are not launching due to lack of capacity)" % PaastaColors.red(
                    "Waiting")
            elif backoff_seconds:
                deploy_status = "%s (next task won't launch for %s seconds due to previous failures)" % (
                    PaastaColors.red("Delayed"), backoff_seconds)
            else:
                deploy_status = PaastaColors.yellow("Deploying")

        if running_instances >= normal_instance_count:
            status = PaastaColors.green("Healthy")
            instance_count = PaastaColors.green(
                "(%d/%d)" % (running_instances, normal_instance_count))
        elif running_instances == 0:
            status = PaastaColors.yellow("Critical")
            instance_count = PaastaColors.red(
                "(%d/%d)" % (running_instances, normal_instance_count))
        else:
            status = PaastaColors.yellow("Warning")
            instance_count = PaastaColors.yellow(
                "(%d/%d)" % (running_instances, normal_instance_count))
        return "Marathon:   %s - up with %s instances. Status: %s" % (
            status, instance_count, deploy_status)
    else:
        red_not = PaastaColors.red("NOT")
        status = PaastaColors.red("Critical")
        return "Marathon:   %s - %s (app %s) is %s running in Marathon." % (
            status, name, app_id, red_not)
Example #7
0
def status_marathon_job(service, instance, app_id, normal_instance_count, client):
    name = PaastaColors.cyan(compose_job_id(service, instance))
    if marathon_tools.is_app_id_running(app_id, client):
        app = client.get_app(app_id)
        running_instances = app.tasks_running

        if len(app.deployments) == 0:
            deploy_status = PaastaColors.bold("Running")
        elif app.instances == 0 and app.tasks_running == 0:
            deploy_status = PaastaColors.grey("Stopped")
        else:
            # App is currently deploying so we should check the launch queue for more info
            is_overdue, backoff_seconds = marathon_tools.get_app_queue_status(client, app_id)

            if is_overdue:
                deploy_status = "%s (new tasks are not launching due to lack of capacity)" % PaastaColors.red("Waiting")
            elif backoff_seconds:
                deploy_status = "%s (next task won't launch for %s seconds due to previous failures)" % (
                                PaastaColors.red("Delayed"), backoff_seconds)
            else:
                deploy_status = PaastaColors.yellow("Deploying")

        if running_instances >= normal_instance_count:
            status = PaastaColors.green("Healthy")
            instance_count = PaastaColors.green("(%d/%d)" % (running_instances, normal_instance_count))
        elif running_instances == 0:
            status = PaastaColors.yellow("Critical")
            instance_count = PaastaColors.red("(%d/%d)" % (running_instances, normal_instance_count))
        else:
            status = PaastaColors.yellow("Warning")
            instance_count = PaastaColors.yellow("(%d/%d)" % (running_instances, normal_instance_count))
        return "Marathon:   %s - up with %s instances. Status: %s" % (status, instance_count, deploy_status)
    else:
        red_not = PaastaColors.red("NOT")
        status = PaastaColors.red("Critical")
        return "Marathon:   %s - %s (app %s) is %s running in Marathon." % (status, name, app_id, red_not)