def logbook_get(lb_id): session = db_session.get_session() try: lb_m = _logbook_get_model(lb_id, session=session) return _convert_lb_to_external(lb_m) except sql_exc.DBAPIError as e: raise exc.StorageError("Failed getting" " logbook %s: %s" % (lb_id, e), e)
def logbook_destroy(lb_id): session = db_session.get_session() with session.begin(): try: lb = _logbook_get_model(lb_id, session=session) session.delete(lb) except sql_exc.DBAPIError as e: raise exc.StorageError("Failed destroying" " logbook %s: %s" % (lb_id, e), e)
def taskdetails_save(td): # Must already exist since a tasks details has a strong connection to # a flow details, and tasks details can not be saved on there own since # they *must* have a connection to an existing flow details. session = db_session.get_session() with session.begin(): td_m = _task_details_get_model(td.uuid, session=session) td_m = _taskdetails_merge(td_m, td) td_m = session.merge(td_m) return _convert_td_to_external(td_m)
def clear_all(): session = db_session.get_session() with session.begin(): # NOTE(harlowja): due to how we have our relationship setup and # cascading deletes are enabled, this will cause all associated task # details and flow details to automatically be purged. try: return session.query(models.LogBook).delete() except sql_exc.DBAPIError as e: raise exc.StorageError("Failed clearing all entries: %s" % e, e)
def logbook_destroy(lb_id): session = db_session.get_session() with session.begin(): try: lb = _logbook_get_model(lb_id, session=session) session.delete(lb) except sql_exc.DBAPIError as e: raise exc.StorageError( "Failed destroying" " logbook %s: %s" % (lb_id, e), e)
def save(self, session=None): """Save this object.""" if not session: session = sa.get_session() # NOTE(boris-42): This part of code should be look like: # sesssion.add(self) # session.flush() # But there is a bug in sqlalchemy and eventlet that # raises NoneType exception if there is no running # transaction and rollback is called. As long as # sqlalchemy has this bug we have to create transaction # explicity. with session.begin(subtransactions=True): session.add(self) session.flush()
def logbook_save(lb): session = db_session.get_session() with session.begin(): try: lb_m = _logbook_get_model(lb.uuid, session=session) # NOTE(harlowja): Merge them (note that this doesn't provide 100% # correct update semantics due to how databases have MVCC). This # is where a stored procedure or a better backing store would # handle this better (something more suited to this type of data). for fd in lb: existing_fd = False for fd_m in lb_m.flowdetails: if fd_m.uuid == fd.uuid: existing_fd = True if fd_m.meta != fd.meta: fd_m.meta = fd.meta if fd_m.state != fd.state: fd_m.state = fd.state for td in fd: existing_td = False for td_m in fd_m.taskdetails: if td_m.uuid == td.uuid: existing_td = True td_m = _taskdetails_merge(td_m, td) break if not existing_td: td_m = _convert_td_to_internal(td, fd_m.uuid) fd_m.taskdetails.append(td_m) if not existing_fd: lb_m.flowdetails.append( _convert_fd_to_internal(fd, lb_m.uuid)) except exc.NotFound: lb_m = _convert_lb_to_internal(lb) try: lb_m = session.merge(lb_m) return _convert_lb_to_external(lb_m) except sql_exc.DBAPIError as e: raise exc.StorageError( "Failed saving" " logbook %s: %s" % (lb.uuid, e), e)
def logbook_save(lb): session = db_session.get_session() with session.begin(): try: lb_m = _logbook_get_model(lb.uuid, session=session) # NOTE(harlowja): Merge them (note that this doesn't provide 100% # correct update semantics due to how databases have MVCC). This # is where a stored procedure or a better backing store would # handle this better (something more suited to this type of data). for fd in lb: existing_fd = False for fd_m in lb_m.flowdetails: if fd_m.uuid == fd.uuid: existing_fd = True if fd_m.meta != fd.meta: fd_m.meta = fd.meta if fd_m.state != fd.state: fd_m.state = fd.state for td in fd: existing_td = False for td_m in fd_m.taskdetails: if td_m.uuid == td.uuid: existing_td = True td_m = _taskdetails_merge(td_m, td) break if not existing_td: td_m = _convert_td_to_internal(td, fd_m.uuid) fd_m.taskdetails.append(td_m) if not existing_fd: lb_m.flowdetails.append(_convert_fd_to_internal(fd, lb_m.uuid)) except exc.NotFound: lb_m = _convert_lb_to_internal(lb) try: lb_m = session.merge(lb_m) return _convert_lb_to_external(lb_m) except sql_exc.DBAPIError as e: raise exc.StorageError("Failed saving" " logbook %s: %s" % (lb.uuid, e), e)
def flowdetails_save(fd): # Must already exist since a flow details has a strong connection to # a logbook, and flow details can not be saved on there own since they # *must* have a connection to an existing logbook. session = db_session.get_session() with session.begin(): fd_m = _flow_details_get_model(fd.uuid, session=session) if fd_m.meta != fd.meta: fd_m.meta = fd.meta if fd_m.state != fd.state: fd_m.state = fd.state for td in fd: updated = False for td_m in fd_m.taskdetails: if td_m.uuid == td.uuid: updated = True td_m = _taskdetails_merge(td_m, td) break if not updated: fd_m.taskdetails.append(_convert_td_to_internal(td, fd_m.uuid)) fd_m = session.merge(fd_m) return _convert_fd_to_external(fd_m)