Example #1
0
def task_update(session, uuid, values):
    values.pop("uuid", None)
    tags = values.pop("tags", None)

    task = session.query(models.Task).filter_by(uuid=uuid).first()
    if not task:
        raise exceptions.DBRecordNotFound(criteria="uuid: %s" % uuid,
                                          table="tasks")
    task.update(values)
    task = task.as_dict()

    if tags is not None:
        # TODO(boris-42): create separate method for tags editing
        tags_in_db = session.query(models.Tag.tag).filter_by(
            uuid=uuid, type=consts.TagType.TASK).distinct()
        new_tags = set(tags) - set(tags_in_db)
        removed_tags = set(tags_in_db) - set(tags)

        (session.query(models.Tag).filter_by(
            uuid=uuid, type=consts.TagType.TASK).filter(
                models.Tag.tag.in_(removed_tags)).delete(
                    synchronize_session=False))

        if new_tags:
            session.bulk_save_objects(
                models.Tag(uuid=uuid, tag=t, type=consts.TagType.TASK)
                for t in set(new_tags))
        task["tags"] = tags
    else:
        task["tags"] = []
    return task
Example #2
0
def verification_create(session, verifier_id, env, tags=None, run_args=None):
    verifier = _verifier_get(session, verifier_id)
    env = env_get(env)
    verification = models.Verification(verifier_uuid=verifier.uuid,
                                       env_uuid=env["uuid"],
                                       run_args=run_args)
    session.add(verification)
    session.commit()

    if tags:
        session.bulk_save_objects(
            models.Tag(uuid=verification.uuid,
                       tag=t,
                       type=consts.TagType.VERIFICATION) for t in set(tags))
    return verification
Example #3
0
def verification_create(verifier_id, env, tags=None, run_args=None):
    verifier = _verifier_get(verifier_id)
    env = env_get(env)
    verification = models.Verification()
    verification.update({
        "verifier_uuid": verifier.uuid,
        "env_uuid": env["uuid"],
        "run_args": run_args
    })
    verification.save(get_session())

    if tags:
        get_session().bulk_save_objects(
            models.Tag(uuid=verification.uuid,
                       tag=t,
                       type=consts.TagType.VERIFICATION) for t in set(tags))
    return verification
Example #4
0
def task_update(uuid, values):
    session = get_session()
    values.pop("uuid", None)
    tags = values.pop("tags", None)
    with session.begin():
        task = _task_get(uuid, session=session)
        task.update(values)

        if tags:
            for t in set(tags):
                tag = models.Tag()
                tag.update({
                    "uuid": task.uuid,
                    "type": consts.TagType.TASK,
                    "tag": t
                })
                tag.save(session)
        # take an updated instance of task
        task = _task_get(uuid, session=session)
    return task
Example #5
0
def task_create(session, values):
    tags = values.pop("tags", [])
    # TODO(ikhudoshyn): currently 'input_task'
    # does not come in 'values'
    # After completely switching to the new
    # DB schema in API we should reconstruct
    # input_task's from associated workloads
    # the same is true for 'pass_sla',
    # 'task_duration', 'validation_result'
    # and 'validation_duration'
    task = models.Task(**values)
    session.add(task)
    session.commit()
    task = task.as_dict()

    if tags:
        session.bulk_save_objects(
            models.Tag(uuid=task["uuid"], tag=t, type=consts.TagType.TASK)
            for t in set(tags))
    task["tags"] = tags
    return task
Example #6
0
def task_create(values):
    tags = values.pop("tags", [])
    # TODO(ikhudoshyn): currently 'input_task'
    # does not come in 'values'
    # After completely switching to the new
    # DB schema in API we should reconstruct
    # input_task's from associated workloads
    # the same is true for 'pass_sla',
    # 'task_duration', 'validation_result'
    # and 'validation_duration'
    task = models.Task()
    task.update(values)
    task.save(get_session())

    if tags:
        get_session().bulk_save_objects(
            models.Tag(uuid=task.uuid, tag=t, type=consts.TagType.TASK)
            for t in set(tags))
        task.tags = sorted(_tags_get(task.uuid, consts.TagType.TASK))
    else:
        task.tags = []
    return task