def save_logbook(self, book): # Get a existing logbook model (or create it if it isn't there). try: e_lb = self.backend.log_books[book.uuid] except KeyError: e_lb = logbook.LogBook(book.name, book.uuid, updated_at=book.updated_at, created_at=timeutils.utcnow()) self.backend.log_books[e_lb.uuid] = e_lb else: # TODO(harlowja): figure out a better way to set this property # without actually setting a 'private' property. e_lb._updated_at = timeutils.utcnow() p_utils.logbook_merge(e_lb, book, deep_copy=True) # Add anything in to the new logbook that isn't already # in the existing logbook. for flow_detail in book: try: e_fd = self.backend.flow_details[flow_detail.uuid] except KeyError: e_fd = logbook.FlowDetail(name=flow_detail.name, uuid=flow_detail.uuid) e_lb.add(flow_detail) self.backend.flow_details[flow_detail.uuid] = e_fd p_utils.flow_details_merge(e_fd, flow_detail, deep_copy=True) self._save_flowdetail_tasks(e_fd, flow_detail) return e_lb
def save_logbook(self, book): # Get a existing logbook model (or create it if it isn't there). try: e_lb = self.backend.log_books[book.uuid] except KeyError: e_lb = logbook.LogBook(book.name, book.uuid, updated_at=book.updated_at, created_at=timeutils.utcnow()) self.backend.log_books[e_lb.uuid] = e_lb else: # TODO(harlowja): figure out a better way to set this property # without actually setting a 'private' property. e_lb._updated_at = timeutils.utcnow() p_utils.logbook_merge(e_lb, book, deep_copy=True) # Add anything in to the new logbook that isn't already in the existing # logbook. for flow_detail in book: try: e_fd = self.backend.flow_details[flow_detail.uuid] except KeyError: e_fd = logbook.FlowDetail(name=flow_detail.name, uuid=flow_detail.uuid) e_lb.add(flow_detail) self.backend.flow_details[flow_detail.uuid] = e_fd p_utils.flow_details_merge(e_fd, flow_detail, deep_copy=True) self._save_flowdetail_tasks(e_fd, flow_detail) return e_lb
def _save_logbook(self, book): # See if we have an existing logbook to merge with. e_lb = None try: e_lb = self._get_logbook(book.uuid) except exc.NotFound: pass if e_lb is not None: e_lb = p_utils.logbook_merge(e_lb, book) for fd in book: if e_lb.find(fd.uuid) is None: e_lb.add(fd) book = e_lb book_path = os.path.join(self._book_path, book.uuid) misc.ensure_tree(book_path) created_at = None if e_lb is not None: created_at = e_lb.created_at self._write_to(os.path.join(book_path, 'metadata'), jsonutils.dumps( p_utils.format_logbook(book, created_at=created_at))) if len(book): flow_path = os.path.join(book_path, 'flows') misc.ensure_tree(flow_path) self._run_with_process_lock('flow', self._save_flows_and_link, list(book), flow_path) return book
def save_logbook(self, book): # Get a existing logbook model (or create it if it isn't there). try: e_lb = p_utils.logbook_merge(_LOG_BOOKS[book.uuid], book) # Add anything in to the new logbook that isn't already # in the existing logbook. for flow_detail in book: if e_lb.find(flow_detail.uuid) is None: _FLOW_DETAILS[flow_detail.uuid] = _copy(flow_detail) e_lb.add(flow_detail) if flow_detail.uuid not in _FLOW_DETAILS: _FLOW_DETAILS[flow_detail.uuid] = _copy(flow_detail) flow_detail.update(self.update_flow_details(flow_detail)) # TODO(harlowja): figure out a better way to set this property # without actually setting a 'private' property. e_lb._updated_at = timeutils.utcnow() except KeyError: # Ok the one given is now the one we will save e_lb = _copy(book) # TODO(harlowja): figure out a better way to set this property # without actually setting a 'private' property. e_lb._created_at = timeutils.utcnow() # Record all the pieces as being saved. _LOG_BOOKS[e_lb.uuid] = e_lb for flow_detail in e_lb: _FLOW_DETAILS[flow_detail.uuid] = _copy(flow_detail) flow_detail.update(self.update_flow_details(flow_detail)) return e_lb
def _logbook_merge(lb_m, lb): lb_m = persistence_utils.logbook_merge(lb_m, lb) for fd in lb: existing_fd = False for fd_m in lb_m.flowdetails: if fd_m.uuid == fd.uuid: existing_fd = True fd_m = _flowdetails_merge(fd_m, fd) if not existing_fd: lb_m.flowdetails.append(_convert_fd_to_internal(fd, lb_m.uuid)) return lb_m
def _update_logbook(lb_path, lb_data, txn): e_lb = p_utils.unformat_logbook(lb.uuid, misc.decode_json(lb_data)) e_lb = p_utils.logbook_merge(e_lb, lb) lb_data = p_utils.format_logbook(e_lb, created_at=lb.created_at) txn.set_data(lb_path, misc.binary_encode(jsonutils.dumps(lb_data))) for fd in lb: fd_path = paths.join(lb_path, fd.uuid) if not self._client.exists(fd_path): # NOTE(harlowja): create an entry in the logbook path # for the provided flow detail so that a reference exists # from the logbook to its flow details. txn.create(fd_path) e_fd = self._update_flow_details(fd, txn, create_missing=True) e_lb.add(e_fd) return e_lb