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
Example #2
0
    def recover_delegation(self, *, d: ABCDelegation, slice_obj: ABCSlice):
        """
        Recover delegation
        @param d delegation
        @param slice_obj slice object
        """
        try:

            d.restore(actor=self, slice_obj=slice_obj)

            self.logger.info("Found delegation # {} in state {}".format(
                d.get_delegation_id(), d.get_state_name()))
            if d.is_closed():
                self.logger.info(
                    "Delegation #{} is closed. Nothing to recover.".format(
                        d.get_delegation_id()))
                return

            self.logger.info("Recovering delegation #{}".format(
                d.get_delegation_id()))
            self.logger.debug("Recovering delegation object d={}".format(d))

            self.logger.debug("Registering the delegation with the actor")
            self.re_register_delegation(delegation=d)

            self.logger.info(d)

            self.logger.debug("Revisiting with the Plugin")

            self.plugin.revisit(delegation=d)

            self.logger.info(d)

            self.logger.debug("Revisiting with the actor policy")
            self.policy.revisit_delegation(delegation=d)

            self.logger.info("Recovered delegation #{}".format(
                d.get_delegation_id()))
        except Exception as e:
            self.logger.error(traceback.format_exc())
            self.logger.error(
                "Exception occurred in recovering delegation e={}".format(e))
            raise ActorException("Could not recover delegation #{}".format(d))