def instantiate_actors(self): for a in self.actor_names: found, primitive, actorclass = self.store.lookup(a) if found and primitive: try: actor = actorclass(a, disable_state_checks=True) if not hasattr(actor, 'test_set'): self.actors[a] = 'no_test' continue actor.attach_API("calvinsys", lambda a: CalvinSys(a, None)) actor.calvinsys.io.file = CalvinSysFileMock() actor.calvinsys.events.timer = CalvinSysTimerMock() actor.init(*actorclass.test_args, **actorclass.test_kwargs) actor.setup_complete() except Exception as e: self.illegal_actors[a] = "Failed to instantiate" sys.stderr.write("Actor %s: %s" % (a, e)) import traceback sys.stderr.write(''.join(traceback.format_exc())) raise e for inport in actor.inports.values(): inport.endpoint = DummyInEndpoint(inport) for outport in actor.outports.values(): outport.fifo.add_reader(actor.id) self.actors[a] = actor elif found and not primitive: self.components[a] = "TODO: Cannot test components (%s)" % ( a, ) else: self.illegal_actors[ a] = "Unknown actor - probably parsing issues"
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.id = calvinuuid.uuid("NODE") self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.control.start(node=self, uri=control_uri) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri self.external_uri = attributes.pop('external_uri', self.uri) \ if attributes else self.uri self.external_control_uri = attributes.pop('external_control_uri', self.control_uri) \ if attributes else self.control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.node_name = self.attributes.get_node_name_as_str() # Obtain node id, when using security also handle runtime certificate self.id = certificate.obtain_cert_node_info(self.node_name)['id'] self.authentication = authentication.Authentication(self) self.authorization = authorization.Authorization(self) try: self.domain = _conf.get("security", "security_domain_name") # cert_name is the node's certificate filename (without file extension) self.cert_name = certificate.get_own_cert_name(self.node_name) except: self.domain = None self.cert_name = None self.metering = metering.set_metering(metering.Metering(self)) self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def _new_actor(self, actor_type): """Return a 'bare' actor of actor_type, raises an exception on failure.""" (found, is_primitive, class_) = ActorStore().lookup(actor_type) if not found or not is_primitive: _log.error("Requested actor %s is not available" % (actor_type)) raise Exception("ERROR_NOT_FOUND") try: # Create a 'bare' instance of the actor a = class_(actor_type) # FIXME: Resolve the required (calvin) APIs and attach them to the actor # (if it has the required access rights) a.attach_API("calvinsys", CalvinSys(self.node)) except Exception as e: _log.exception("") _log.error("The actor %s(%s) can't be instantiated." % (actor_type, class_.__init__)) raise (e) return a
def __init__(self, uris, control_uri, attributes=None): super(Node, self).__init__() self.quitting = False # Warn if its not a uri if not isinstance(uris, list): _log.error("Calvin uris must be a list %s" % uris) raise TypeError("Calvin uris must be a list!") # Uris self.uris = uris if attributes: ext_uris = attributes.pop('external_uri', None) if ext_uris is not None: self.uris += ext_uris # Control uri self.control_uri = control_uri self.external_control_uri = attributes.pop('external_control_uri', self.control_uri) \ if attributes else self.control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.node_name = self.attributes.get_node_name_as_str() # Obtain node id, when using security also handle runtime certificate try: security_dir = _conf.get("security", "security_dir") self.runtime_credentials = RuntimeCredentials(self.node_name, node=self, security_dir=security_dir) self.id = self.runtime_credentials.get_node_id() except Exception as err: _log.debug("No runtime credentials, err={}".format(err)) self.runtime_credentials = None self.id = calvinuuid.uuid("Node") self.certificate_authority = certificate_authority.CertificateAuthority(self) self.authentication = authentication.Authentication(self) self.authorization = authorization.Authorization(self) self.metering = metering.set_metering(metering.Metering(self)) self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.rm = replicationmanager.ReplicationManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) calvinsys = get_calvinsys() calvinsys.init(self) calvinlib = get_calvinlib() calvinlib.init(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def calvinsys(self, actor): """Return a CalvinSys instance""" # FIXME: We still need to sort out actor requirements vs. node capabilities and user permissions. return CalvinSys(actor, self)