def translate_delegation_to_avro(*, delegation: ABCDelegation) -> DelegationAvro:
     avro_delegation = DelegationAvro()
     avro_delegation.delegation_id = delegation.get_delegation_id()
     avro_delegation.state = delegation.get_state().value
     avro_delegation.slice = Translate.translate_slice_to_avro(slice_obj=delegation.get_slice_object())
     if delegation.get_graph() is not None and not (delegation.is_reclaimed() or delegation.is_closed()):
         avro_delegation.graph = delegation.get_graph().serialize_graph()
     return avro_delegation
Exemple #2
0
 def delegation_update_satisfies(self, *, incoming: ABCDelegation, update_data: UpdateData):
     """
     Check if the incoming delegation satisfies the update
     @param incoming incoming delegation
     @param update_data update data
     """
     if incoming.get_graph() is not None:
         incoming.get_graph().validate_graph()
     return True
Exemple #3
0
 def donate_delegation(self, *, delegation: ABCDelegation):
     """
     Donate an incoming delegation by merging to CBM;
     We take snapshot of CBM before merge, and rollback to snapshot in case merge fails
     :param delegation:
     :return:
     :raises: Exception in case of failure
     """
     self.logger.debug("Donate Delegation")
     self.bind_delegation(delegation=delegation)
     try:
         self.lock.acquire()
         if delegation.get_delegation_id() in self.delegations:
             self.merge_adm(adm_graph=delegation.get_graph())
             self.logger.debug(
                 f"Donated Delegation: {delegation.get_delegation_id()}")
         else:
             self.logger.warning(
                 f"Delegation ignored: {delegation.get_delegation_id()}")
             self.logger.debug(f"Active delegations: {self.delegations}")
     except Exception as e:
         self.logger.error(f"Failed to merge ADM: {delegation}")
         self.logger.error(traceback.format_exc())
         raise e
     finally:
         self.lock.release()
    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 validate_delegation(*,
                            delegation: ABCDelegation,
                            check_requested: bool = False):
        if delegation is None:
            raise RPCException(
                message=Constants.NOT_SPECIFIED_PREFIX.format("delegation"))

        if delegation.get_slice_object() is None:
            raise RPCException(
                message=Constants.NOT_SPECIFIED_PREFIX.format("slice"))

        if check_requested and delegation.get_graph() is None:
            raise RPCException(
                message=Constants.NOT_SPECIFIED_PREFIX.format("graph"))
Exemple #6
0
    def absorb_delegation_update(self, *, incoming: ABCDelegation, update_data: UpdateData):
        """
        Absorbs an incoming delegation update.

        @param incoming
                   incoming delegation update
        @param update_data
                   update data
        @throws Exception
        """
        self.logger.debug("absorb_update: {}".format(incoming))
        if self.authority is None and incoming.get_site_proxy() is not None:
            self.authority = incoming.get_site_proxy()

        self.graph = incoming.get_graph()
        self.policy.update_delegation_complete(delegation=self)
        if self.graph is not None:
            self.graph.delete_graph()
            self.graph = None
Exemple #7
0
    def update_delegation(self, *, incoming: ABCDelegation, update_data: UpdateData):
        """
        Update delegation
        @param incoming incoming delegation
        @param update_data update data
        """
        if self.state == DelegationState.Nascent or self.state == DelegationState.Delegated:
            if self.accept_delegation_update(incoming=incoming, update_data=update_data):
                if incoming.get_graph() is not None:
                    self.transition(prefix="Delegation update", state=DelegationState.Delegated)
                else:
                    self.transition(prefix="Delegation reclaimed", state=DelegationState.Reclaimed)
                self.set_dirty()

        elif self.state == DelegationState.Closed:
            self.logger.warning("Delegation update after close")

        elif self.state == DelegationState.Failed:
            self.logger.error(message="Delegation update on failed delegation: {}".format(update_data))

        elif self.state == DelegationState.Reclaimed:
            self.transition(prefix="ticket update", state=DelegationState.Delegated)