def pass_delegation(*, delegation: ABCDelegation) -> ABCDelegation: slice_obj = delegation.get_slice_object().clone_request() delegation_new = DelegationFactory.create( did=delegation.get_delegation_id(), slice_id=delegation.get_slice_id()) delegation_new.set_slice_object(slice_object=slice_obj) # TODO if not delegation.is_reclaimed(): delegation_new.set_graph(delegation.get_graph()) return delegation_new
def add_delegation(self, *, delegation: ABCDelegation): self.logger.debug("Adding delegation {} to slice {}".format( delegation.get_delegation_id(), delegation.get_slice_id())) slc_id = self.get_slice_id_from_guid( slice_id=delegation.get_slice_id()) if slc_id is None: raise DatabaseException("Slice with id: {} not found".format( delegation.get_slice_id())) try: self.lock.acquire() properties = pickle.dumps(delegation) self.db.add_delegation(dlg_slc_id=slc_id, dlg_graph_id=str( delegation.get_delegation_id()), dlg_state=delegation.get_state().value, properties=properties) self.logger.debug("Delegation {} added to slice {}".format( delegation.get_delegation_id(), delegation.get_slice_id())) finally: self.lock.release()
def update_delegation(self, *, delegation: ABCDelegation): # Update the delegation only when there are changes to be reflected in database if not delegation.is_dirty(): return delegation.clear_dirty() try: self.lock.acquire() self.logger.debug("Updating delegation {} in slice {}".format( delegation.get_delegation_id(), delegation.get_slice_id())) properties = pickle.dumps(delegation) self.db.update_delegation(dlg_graph_id=str( delegation.get_delegation_id()), dlg_state=delegation.get_state().value, properties=properties) finally: self.lock.release()