Example #1
0
def tabulate_group(cluster_name, group):
    """Given a group, returns a string containing a table for the group fields"""
    left = [['Cluster', cluster_name]]
    if group['host_placement']['type'] == 'all':
        left.append(['Host Placement', 'all hosts'])
    else:
        left.append(['Host Placement', format_dict(group['host_placement'])])
    if group['straggler_handling']['type'] == 'none':
        left.append(['Straggler Handling', 'none'])
    else:
        left.append(
            ['Straggler Handling',
             format_dict(group['straggler_handling'])])

    right = [['# Completed', group['completed']],
             ['# Running', group['running']], ['# Waiting', group['waiting']]]

    num_jobs = len(group['jobs'])
    jobs = 'Job group contains %s job%s:\n%s' % (
        num_jobs, '' if num_jobs == 1 else 's', '\n'.join(group['jobs']))

    left_table = tabulate(left, tablefmt='plain')
    right_table = tabulate(right, tablefmt='plain')
    group_tables = juxtapose_text(left_table, right_table)
    return '\n=== Job Group: %s (%s) ===\n\n%s\n\n%s' % (
        group['uuid'], group['name'], group_tables, jobs)
Example #2
0
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)