Ejemplo n.º 1
0
def command_getart(args):
    cmd_config = pspace.get_cmd_config(args)

    print("Retrieving artifacts for job " + cmd_config['job_id'] + " ...")
    pspace.get_artifacts(cmd_config['job_id'], cmd_config['destdir'])
    # TODO 20190422: error handling
    pspace.save_log(cmd_config['job_id'], cmd_config['destdir'])
Ejemplo n.º 2
0
def command_tail(args):
    cmd_config = pspace.get_cmd_config(args,
                                       ['total_log_lines', 'last_job_id'])

    try:
        if cmd_config['last'].startswith('a') or cmd_config['last'].startswith(
                'A'):
            # tail_lines = 0 is special value that indicates show all lines
            cmd_config['last'] = 0
    except AttributeError:
        pass
    tail_lines = int(cmd_config['last'])

    job_id = cmd_config['job_id']
    if job_id is None:
        print("Cannot determine job id.")
        return

    line_start = 0
    if tail_lines != 0:
        if (cmd_config['total_log_lines']
                is not None) and (cmd_config['last_job_id'] == job_id):
            line_start = max(0, cmd_config['total_log_lines'] - tail_lines)

    (job_info, total_log_lines) = pspace.print_last_log_lines(
        job_id, tail_lines, line_start, follow=cmd_config['follow'])
    if 'error' in job_info:
        pspace.print_error(job_info)
        return

    extra_save_info = {
        'total_log_lines': total_log_lines,
        'last_job_id': job_id,
    }
    pspace.save_last_info(job_info, extra_save_info)
Ejemplo n.º 3
0
def command_jobs(args):
    cmd_config = pspace.get_cmd_config(args)

    if cmd_config['state'] is not None:
        # match any state argument case-insensitively, only first chars are
        #   needed
        state = cmd_config['state'][0].upper() + cmd_config['state'][1:]
        matching_state = [x for x in VALID_JOB_STATES
                          if x.startswith(state)][0]
        cmd_config['state'] = matching_state

    list_kwargs = cmd_config.copy()
    list_kwargs.pop('last')
    job_list = pspace.jobs_list(**list_kwargs)
    # job_list appears to be in chronological order (first is earliest)
    if cmd_config['last'] is not None:
        job_list = job_list[-cmd_config['last']:]

    print_keys = [
        'name',
        'state',
        'entrypoint',
        'project',
        'Started',
        'Finished',
        'exitCode',
        'machineType',
    ]
    first = True
    for job in job_list:
        if not first:
            print("")
        pspace.print_job_status(job, print_keys, utc_str=cmd_config['utc'])
        first = False
Ejemplo n.º 4
0
def command_stop(args):
    cmd_config = pspace.get_cmd_config(args)

    print("Stopping job " + cmd_config['job_id'] + " ...")
    returnval = pspace.stop_job(cmd_config['job_id'])
    if not returnval:
        print("Success")
    else:
        pspace.print_error(returnval)
Ejemplo n.º 5
0
def command_status(args):
    cmd_config = pspace.get_cmd_config(args)
    job_id = cmd_config['job_id']
    if job_id is None:
        print("Cannot determine job id.")
        return

    job_info = pspace.get_job_info(job_id)
    if 'error' in job_info:
        pspace.print_error(job_info)
        return

    pspace.save_last_info(job_info)

    print_keys = ['state', 'Started', 'Finished', 'Duration', 'exitCode']
    pspace.print_job_status(job_info, print_keys, utc_str=cmd_config['utc'])
Ejemplo n.º 6
0
def command_create(args):
    cmd_config = pspace.get_cmd_config(args)

    if cmd_config['project'] is None:
        cmd_config['project'] = pathlib.Path.cwd().name

    print('Submitting with options:')
    pspace.print_create_options(cmd_config)

    job_info = pspace.jobs_create(**cmd_config)
    if 'error' in job_info:
        pspace.print_error(job_info)
        return

    print("Job " + job_info['id'] + " created.")

    pspace.save_last_info(job_info)