示例#1
0
文件: show.py 项目: hdrodz97/Cook
def tabulate_job(cluster_name, job):
    """Given a job, returns a string containing tables for the job and instance fields"""
    job_definition = [['Cluster',
                       cluster_name], ['Pool', job.get('pool', '-')],
                      ['Memory', format_job_memory(job)],
                      ['CPUs', job['cpus']], ['User', job['user']],
                      ['Priority', job['priority']]]
    if job['max_runtime'] != DEFAULT_MAX_RUNTIME:
        job_definition.append(
            ['Max Runtime',
             millis_to_timedelta(job['max_runtime'])])
    if job['gpus'] > 0:
        job_definition.append(['GPUs', job['gpus']])
    if job['ports'] > 0:
        job_definition.append(['Ports Requested', job['ports']])
    if len(job['constraints']) > 0:
        job_definition.append(['Constraints', format_list(job['constraints'])])
    if len(job['labels']) > 0:
        job_definition.append(['Labels', format_dict(job['labels'])])
    if job['uris'] and len(job['uris']) > 0:
        job_definition.append(['URI(s)', format_list(job['uris'])])
    if 'groups' in job:
        job_definition.append(['Job Group(s)', format_list(job['groups'])])
    if 'application' in job:
        job_definition.append([
            'Application',
            '%s (%s)' %
            (job['application']['name'], job['application']['version'])
        ])
    if 'executor' in job:
        job_definition.append(['Executor', job['executor']])

    job_state = [['Attempts', format_job_attempts(job)],
                 ['Job Status', format_job_status(job)],
                 ['Submitted',
                  millis_to_date_string(job['submit_time'])]]

    job_command = 'Command:\n%s' % job['command']

    if len(job['env']) > 0:
        environment = '\n\nEnvironment:\n%s' % '\n'.join(
            ['%s=%s' % (k, v) for k, v in job['env'].items()])
    else:
        environment = ''

    instances = job['instances']

    job_definition_table = tabulate(job_definition, tablefmt='plain')
    job_state_table = tabulate(job_state, tablefmt='plain')
    job_tables = juxtapose_text(job_definition_table, job_state_table)
    instance_table = tabulate_job_instances(instances)
    return '\n=== Job: %s (%s) ===\n\n%s\n\n%s%s%s' % \
           (job['uuid'], job['name'], job_tables, job_command, environment, instance_table)
示例#2
0
def print_as_table(query_result):
    """Given a collection of (cluster, job) pairs, formats a table showing the most relevant job fields"""
    cluster_job_pairs = query_result_to_cluster_job_pairs(query_result)
    rows = [
        collections.OrderedDict([("Cluster", cluster), ("UUID", job['uuid']),
                                 ("Name", job['name']),
                                 ("Memory", format_job_memory(job)),
                                 ("CPUs", job['cpus']),
                                 ("Priority", job['priority']),
                                 ("Attempts", format_job_attempts(job)),
                                 ("Submitted",
                                  millis_to_date_string(job['submit_time'])),
                                 ("Command", format_job_command(job)),
                                 ("Job Status", format_job_status(job))])
        for (cluster, job) in cluster_job_pairs
    ]
    job_table = tabulate(rows, headers='keys', tablefmt='plain')
    print_info(job_table)
示例#3
0
文件: show.py 项目: scrosby/Cook
def tabulate_job(cluster_name, job):
    """Given a job, returns a string containing tables for the job and instance fields"""
    job_definition = [['Cluster',
                       cluster_name], ['Pool', job.get('pool', '-')],
                      ['Memory', format_job_memory(job)],
                      ['CPUs', job['cpus']], ['User', job['user']],
                      ['Priority', job['priority']]]
    if job['max_runtime'] != DEFAULT_MAX_RUNTIME:
        job_definition.append(
            ['Max Runtime',
             millis_to_timedelta(job['max_runtime'])])
    if job['gpus'] > 0:
        job_definition.append(['GPUs', job['gpus']])
    if 'disk' in job:
        job_definition.append(['Disk Request', job['disk']['request']])
        if 'limit' in job['disk']:
            job_definition.append(['Disk Limit', job['disk']['limit']])
        if 'type' in job['disk']:
            job_definition.append(['Disk Type', job['disk']['type']])
    if job['ports'] > 0:
        job_definition.append(['Ports Requested', job['ports']])
    if len(job['constraints']) > 0:
        job_definition.append(['Constraints', format_list(job['constraints'])])
    if job['uris'] and len(job['uris']) > 0:
        job_definition.append(['URI(s)', format_list(job['uris'])])
    if 'groups' in job:
        job_definition.append(['Job Group(s)', format_list(job['groups'])])
    if 'application' in job:
        job_definition.append([
            'Application',
            '%s (%s)' %
            (job['application']['name'], job['application']['version'])
        ])
    if 'executor' in job:
        job_definition.append(['Executor', job['executor']])

    job_state = [['Attempts', format_job_attempts(job)],
                 ['Job Status', format_job_status(job)],
                 ['Submitted',
                  millis_to_date_string(job['submit_time'])]]
    if 'checkpoint' in job and 'mode' in job['checkpoint']:
        job_state.append(['Checkpoint mode', job['checkpoint']['mode']])

    if len(job['labels']) > 0:
        job_labels_list = sorted([[k, v.replace(',', ',\n')]
                                  for k, v in job['labels'].items()],
                                 key=itemgetter(0))
        job_labels_table = tabulate(job_labels_list, tablefmt='plain')
        job_labels = f'\n\nLabels:\n{job_labels_table}'
    else:
        job_labels = ''

    job_command = 'Command:\n%s' % job['command']

    if len(job['env']) > 0:
        environment = '\n\nEnvironment:\n%s' % '\n'.join(
            ['%s=%s' % (k, v) for k, v in job['env'].items()])
    else:
        environment = ''

    instances = job['instances']

    job_definition_table = tabulate(job_definition, tablefmt='plain')
    job_state_table = tabulate(job_state, tablefmt='plain')
    job_tables = juxtapose_text(job_definition_table, job_state_table)
    instance_table = tabulate_job_instances(instances)
    return f'\n' \
           f'=== Job: {job["uuid"]} ({job["name"]}) ===\n\n' \
           f'{job_tables}{job_labels}\n\n{job_command}{environment}{instance_table}'