Esempio n. 1
0
def check_main(args):
    """Main program for 'status' mode.

    :return: Status of run, 0=OK
    :rtype: int
    """
    return_code = 0
    if args.task_t:
        nodetype = log.NodeType.TASK
    elif args.tmpl_t:
        nodetype = log.NodeType.TEMPLATE
    elif args.program_t:
        nodetype = log.NodeType.PROGRAM
    else:
        nodetype = log.NodeType.ANY
    namelist = args.names
    kvp.Reader.ignore_bad = args.bad_ok
    statuses = None
    program_id = get_last_program_id()
    try:
        statuses = log.check(nodetype, names=namelist, multiple=args.multiple, program_id=program_id)
    except ValueError as err:
        g_log.error(str(err))
        return_code = -1
    if return_code == 0:
        if not statuses:
            report_str("Nothing found")
        else:
            for obj in statuses:
                report_status(obj)
    return return_code
Esempio n. 2
0
def graph_from_log(program_id):
    program = None

    # Get the templates for the given program
    status_templates = log.check('template', program_id=program_id)
    for status_template in status_templates:

        # Create the root_work sequence representation of the program (workflow)
        if not program:
            program = WorkSequence(None, status_template.program_name)

        # Get all of the tasks for the current template
        status_tasks = log.check("task", template_id=status_template.name, program_id=program_id)
        if not status_tasks:
            break

        if status_template.node_type.endswith("parallel"):
            # Parallel Template
            template = WorkParallel(program, status_template.name)
            program.append(template)

            for task in status_tasks:
                template.append(WorkUnit(template, task.name, task.state))

        else:
            template = WorkSequence(program, status_template.name)
            program.append(template)
            if status_template.node_type.endswith("merge"):
                # Merge Template

                # Need to check if there was a parallel task
                status_parallel = log.check("parallel", template_id=status_template.name, program_id=program_id)

                if status_parallel:
                    # Assuming there is only one status (Revisit with nested templates)
                    parallel = status_parallel[0]
                    work_parallel = WorkParallel(template, template.name)
                    template.append(work_parallel)

                    for task in status_tasks[:-1]:
                        work_parallel.append(WorkUnit(work_parallel, task.name, task.state))

                    # Determine if the parallel tasks finished successfully
                    # This fact decides where the last task goes.
                    last_task = WorkUnit(None, status_tasks[-1].name, status_tasks[-1].state)
                    if parallel.state != State.DONE:
                        work_parallel.append(last_task)
                    else:
                        template.append(last_task)
            elif status_template.node_type.endswith("split"):
                # Split Template
                template.append(WorkUnit(None, status_tasks[0].name, status_tasks[0].state))
                work_parallel = WorkParallel(template, template.name)
                template.append(work_parallel)

                if len(status_tasks) > 1:
                    for task in status_tasks[1:]:
                        work_parallel.append(WorkUnit(work_parallel, task.name, task.state))
            elif status_template.node_type.endswith("sequence"):
                for task in status_tasks:
                    template.append(WorkUnit(template, task.name, task.state))

    return dot_execution_string(program)