def __init__(self, *, manager: ManagementObject, auth: AuthToken): super().__init__(manager=manager, auth=auth) if not isinstance(manager, ActorManagementObject): raise ManageException( "Invalid manager object. Required: {}".format( type(ActorManagementObject)))
def recover(self): actor_name = None if Constants.PROPERTY_ACTOR_NAME in self.serial: actor_name = self.serial[Constants.PROPERTY_ACTOR_NAME] else: raise ManageException( Constants.NOT_SPECIFIED_PREFIX.format("actor name")) actor = ActorRegistrySingleton.get().get_actor( actor_name_or_guid=actor_name) if actor is None: raise ManageException( Constants.OBJECT_NOT_FOUND.format("Managed Object", actor_name)) self.set_actor(actor=actor)
def start(self): try: self.thread_lock.acquire() if self.thread is not None: raise ManageException( "KafkaMgmtMessageProcessor has already been started") self.thread = threading.Thread(target=self.consume) self.thread.setName("KafkaMgmtMessageProcessor") self.thread.setDaemon(True) self.thread.start() self.logger.debug("KafkaMgmtMessageProcessor has been started") finally: self.thread_lock.release()
def get_management_object(self, *, key: ID): try: obj = self.manager.get_management_object(key=key) if obj is None: return None desc_list = obj.get_proxies() if desc_list is None: raise ManageException( "Management object did not specify any proxies") desc = None for d in desc_list: if d.get_protocol() == Constants.PROTOCOL_LOCAL: desc = d break if desc is None or desc.get_proxy_class( ) is None or desc.get_proxy_module() is None: raise ManageException( "Manager object did not specify local proxy") try: mgmt_obj = ReflectionUtils.create_instance_with_params( module_name=desc.get_proxy_module(), class_name=desc.get_proxy_class())(manager=obj, auth=self.auth) return mgmt_obj except Exception as e: traceback.print_exc() raise ManageException( "Could not instantiate proxy {}".format(e)) except Exception as e: traceback.print_exc() raise e
def run(self): result = [] try: for r in reservations: rr, status = self.parent.add_reservation_private( reservation=r) if rr is not None: result.append(str(rr)) else: raise ManageException( "Could not add reservation") except Exception: for r in reservations: self.parent.client.unregister(reservation=r) result.clear() return result
def get_actor(self, *, guid: ID) -> ABCMgmtActor: raise ManageException(Constants.NOT_IMPLEMENTED)
def add_reservations(self, *, reservations: List[ReservationMng]) -> list: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_management_object(self, *, key: ID) -> ABCComponent: raise ManageException(Constants.NOT_IMPLEMENTED)
def add_reservation(self, *, reservation: TicketReservationAvro) -> ID: raise ManageException(Constants.NOT_IMPLEMENTED)
def demand_reservation_rid(self, *, rid: ID) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_controller(self, *, guid: ID) -> ABCMgmtControllerMixin: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_broker(self, *, guid: ID) -> ABCMgmtBrokerMixin: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_name(self) -> str: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_actor_mo(self, *, guid: ID): try: from fabric_cf.actor.core.container.globals import GlobalsSingleton return GlobalsSingleton.get().get_container().get_management_object_manager().get_management_object(key=guid) except Exception as e: raise ManageException("Invalid actor id={}! e={}".format(guid, e))
def reclaim_delegations(self, *, broker: ID, did: ID, id_token: str = None) -> DelegationAvro: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_type_id(self) -> str: raise ManageException("Not implemented")
def get_broker_query_model( self, *, broker: ID, id_token: str, level: int, graph_format: GraphFormat) -> BrokerQueryModelAvro: raise ManageException(Constants.NOT_IMPLEMENTED)
def modify_reservation(self, *, rid: ID, modify_properties: dict) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def extend_reservation(self, *, reservation: ID, new_end_time: datetime) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_actors_from_database(self) -> List[ActorAvro]: raise ManageException(Constants.NOT_IMPLEMENTED)
def reclaim_delegations(self, *, broker: ID, did: str, caller: AuthToken, id_token: str = None) -> ResultDelegationAvro: result = ResultReservationAvro() result.status = ResultAvro() if caller is None or did is None or broker is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result try: if id_token is not None: AccessChecker.check_access( action_id=ActionId.query, resource_type=AuthResourceType.resources, token=id_token, logger=self.logger, actor_type=self.client.get_type(), resource_id=did) my_broker = self.client.get_broker(guid=broker) if my_broker is None: result.status.set_code(ErrorCodes.ErrorNoSuchBroker.value) result.status.set_message( ErrorCodes.ErrorNoSuchBroker.interpret()) return result class Runner(ABCActorRunnable): def __init__(self, *, actor: ABCActorMixin): self.actor = actor def run(self): return self.actor.reclaim_delegation_client( delegation_id=did, broker=my_broker) rc = self.client.execute_on_actor_thread_and_wait(runnable=Runner( actor=self.client)) if rc is not None: result.delegations = [] delegation = Translate.translate_delegation_to_avro( delegation=rc) result.delegations.append(delegation) else: raise ManageException("Internal Error") except Exception as e: self.logger.error(traceback.format_exc()) self.logger.error("reclaim_delegations {}".format(e)) result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result
def get_authority_proxies(self, *, protocol: str) -> List[ProxyAvro]: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_clients(self, *, guid: ID = None, id_token: str = None) -> List[ClientMng]: raise ManageException(Constants.NOT_IMPLEMENTED)
def get_authority(self, *, guid: ID) -> ABCMgmtAuthority: raise ManageException(Constants.NOT_IMPLEMENTED)
def register_client(self, *, client: ClientMng, kafka_topic: str) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def add_broker(self, *, broker: ProxyAvro) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def unregister_client(self, *, guid: ID) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)
def advertise_resources(self, *, delegation: ABCPropertyGraph, delegation_name: str, client: AuthToken) -> ID: raise ManageException(Constants.NOT_IMPLEMENTED)
def demand_reservation(self, *, reservation: ReservationMng) -> bool: raise ManageException(Constants.NOT_IMPLEMENTED)