Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def __init__(self, uri, control_uri, attributes=None):
     super(Node, self).__init__()
     self.uri = uri
     self.control_uri = control_uri
     self.attributes = attributes
     self.id = calvinuuid.uuid("NODE")
     _log.debug("Calvin init 1")
     self.monitor = Event_Monitor()
     _log.debug("Calvin init 2")
     self.am = actormanager.ActorManager(self)
     _log.debug("Calvin init 3")
     self.control = calvincontrol.get_calvincontrol()
     _log.debug("Calvin init 4")
     self.sched = scheduler.Scheduler(self, self.am, self.monitor)
     _log.debug("Calvin init 5")
     self.control.start(node=self, uri=control_uri)
     self.async_msg_ids = {}
     _log.debug("Calvin init 6")
     self.storage = storage.Storage()
     self.storage.start()
     _log.debug("Calvin init 7")
     self.network = CalvinNetwork(self)
     _log.debug("Calvin init 8")
     self.proto = CalvinProto(self, self.network)
     self.pm = PortManager(self, self.proto)
     _log.debug("Calvin init 9")
     self.app_manager = appmanager.AppManager(self)
     _log.debug("Calvin init 10")
     # The initialization that requires the main loop operating is deferred to start function
     async.DelayedCall(0, self.start)
     _log.debug("Calvin init 11")
Exemplo n.º 3
0
    def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False,
                 disable_state_checks=False, actor_id=None, app_id=""):
        """Should _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        self.master_nodes = []
        _log.debug("New actor id: %s, supplied actor id %s" % (self.id, actor_id))
        self.app_id = app_id
        self._deployment_requirements = []
        self._signature = None
        self._component_members = set([self.id])  # We are only part of component if this is extended
        self._managed = set(('id', 'name', '_deployment_requirements', '_signature', 'master_nodes'))
        self._calvinsys = None
        self._using = {}
        self.control = calvincontrol.get_calvincontrol()
        self.metering = metering.get_metering()
        self._migrating_to = None  # During migration while on the previous node set to the next node id
        self._last_time_warning = 0.0

        self.inports = {p: actorport.InPort(p, self) for p in self.inport_names}
        self.outports = {p: actorport.OutPort(p, self) for p in self.outport_names}

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks,
                             allow_invalid_transitions=allow_invalid_transitions,
                             disable_transition_checks=disable_transition_checks,
                             disable_state_checks=disable_state_checks)
        self.metering.add_actor_info(self)
Exemplo n.º 4
0
    def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False,
                 disable_state_checks=False, actor_id=None):
        """Should _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        self._deployment_requirements = []
        self._managed = set(('id', 'name', '_deployment_requirements'))
        self._calvinsys = None
        self._using = {}
        self.control = calvincontrol.get_calvincontrol()
        self._migrating_to = None  # During migration while on the previous node set to the next node id

        self.inports = {p: actorport.InPort(p, self) for p in self.inport_names}
        self.outports = {p: actorport.OutPort(p, self) for p in self.outport_names}

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks,
                             allow_invalid_transitions=allow_invalid_transitions,
                             disable_transition_checks=disable_transition_checks,
                             disable_state_checks=disable_state_checks)
Exemplo n.º 5
0
    def __init__(self,
                 actor_type,
                 name='',
                 allow_invalid_transitions=True,
                 disable_transition_checks=False,
                 disable_state_checks=False,
                 actor_id=None,
                 security=None):
        """Should _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        _log.debug("New actor id: %s, supplied actor id %s" %
                   (self.id, actor_id))
        self._deployment_requirements = []
        self._signature = None
        self._component_members = set(
            [self.id])  # We are only part of component if this is extended
        self._managed = set(
            ('id', 'name', '_deployment_requirements', '_signature',
             'subject_attributes', 'migration_info'))
        self._calvinsys = None
        self._using = {}
        self.control = calvincontrol.get_calvincontrol()
        self.metering = metering.get_metering()
        self.migration_info = None
        self._migrating_to = None  # During migration while on the previous node set to the next node id
        self._last_time_warning = 0.0
        self.sec = security
        self.subject_attributes = self.sec.get_subject_attributes(
        ) if self.sec is not None else None
        self.authorization_checks = None

        self.inports = {
            p: actorport.InPort(p, self)
            for p in self.inport_names
        }
        self.outports = {
            p: actorport.OutPort(p, self)
            for p in self.outport_names
        }

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(
            Actor.STATUS,
            Actor.STATUS.LOADED,
            Actor.VALID_TRANSITIONS,
            hooks,
            allow_invalid_transitions=allow_invalid_transitions,
            disable_transition_checks=disable_transition_checks,
            disable_state_checks=disable_state_checks)
        self.metering.add_actor_info(self)
Exemplo n.º 6
0
 def __init__(self, control_uri):
     super(StorageNode, self).__init__()
     self.id = calvinuuid.uuid("NODE")
     self.control_uri = control_uri
     self.control = calvincontrol.get_calvincontrol()
     _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler
     self.sched = _scheduler(self, FakeAM(), FakeMonitor())
     self.control.start(node=self, uri=control_uri)
     self.storage = storage.Storage(self)
     async.DelayedCall(0, self.start)
Exemplo n.º 7
0
 def __init__(self, control_uri):
     super(StorageNode, self).__init__()
     self.id = calvinuuid.uuid("NODE")
     self.control_uri = control_uri
     self.control = calvincontrol.get_calvincontrol()
     _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel(
     ) <= logging.DEBUG else scheduler.Scheduler
     self.sched = _scheduler(self, FakeAM(), FakeMonitor())
     self.control.start(node=self, uri=control_uri)
     self.storage = storage.Storage(self)
     async .DelayedCall(0, self.start)
Exemplo n.º 8
0
    def __init__(self, uri, control_uri, attributes=None, self_start=True):
        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.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)

        hb_timeout = _conf.get('global', 'heartbeat_timeout') or DEFAULT_HEARTBEAT_TIMEOUT
        self.heartbeat_timeout = float(hb_timeout)
        hb_delay = _conf.get('global', 'heartbeat_delay') or DEFAULT_HEARTBEAT_DELAY
        self.heartbeat_delay = float(hb_delay)
        self.heartbeat_addr = self._clean_addr()
        self.heartbeat_port = _conf.get('global', 'heartbeat_port') or int(self._clean_uri().split(":")[1]) + DEFAULT_HEARTBEAT_PORT_DIFF
        rr_delay = _conf.get('global', 'resource_reporter_delay') or 0.25
        self.resource_reporter_delay = float(rr_delay)

        # 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)
        self.resource_manager = ResourceManager()

        self.app_monitor = AppMonitor(self, self.app_manager, self.storage)
        self.lost_node_handler = LostNodeHandler(self, self.resource_manager, self.pm, self.am, self.storage)

        self.heartbeat_actor = None
        self.outgoing_heartbeats = defaultdict(list)

        # The initialization that requires the main loop operating is deferred to start function
        if self_start:
            async.DelayedCall(0, self.start)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def __init__(self,
                 actor_type,
                 name='',
                 allow_invalid_transitions=True,
                 disable_transition_checks=False,
                 disable_state_checks=False,
                 actor_id=None):
        """Should _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        self._deployment_requirements = []
        self._managed = set(('id', 'name', '_deployment_requirements'))
        self._calvinsys = None
        self._using = {}
        self.control = calvincontrol.get_calvincontrol()
        self._migrating_to = None  # During migration while on the previous node set to the next node id

        self.inports = {
            p: actorport.InPort(p, self)
            for p in self.inport_names
        }
        self.outports = {
            p: actorport.OutPort(p, self)
            for p in self.outport_names
        }

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(
            Actor.STATUS,
            Actor.STATUS.LOADED,
            Actor.VALID_TRANSITIONS,
            hooks,
            allow_invalid_transitions=allow_invalid_transitions,
            disable_transition_checks=disable_transition_checks,
            disable_state_checks=disable_state_checks)
Exemplo n.º 11
0
    def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False,
                 disable_state_checks=False, actor_id=None):
        """Should normally _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        self._managed = set(('id', 'name'))
        self.calvinsys = None # CalvinSys(node)
        self.control = calvincontrol.get_calvincontrol()

        self.inports = {p: actorport.InPort(p, self) for p in self.inport_names}
        self.outports = {p: actorport.OutPort(p, self) for p in self.outport_names}

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks,
                             allow_invalid_transitions=allow_invalid_transitions,
                             disable_transition_checks=disable_transition_checks,
                             disable_state_checks=disable_state_checks)
Exemplo n.º 12
0
 def __init__(self, uri, control_uri, attributes=None):
     super(Node, self).__init__()
     self.uri = uri
     self.control_uri = control_uri
     self.attributes = attributes
     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.storage = storage.Storage()
     self.storage.start()
     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
     # FIXME: Don't use delayed call in calvin-tiny
     async.DelayedCall(0, self.start)
Exemplo n.º 13
0
    def __init__(self,
                 actor_type,
                 name='',
                 allow_invalid_transitions=True,
                 disable_transition_checks=False,
                 disable_state_checks=False,
                 actor_id=None):
        """Should normally _not_ be overridden in subclasses."""
        super(Actor, self).__init__()
        self._type = actor_type
        self.name = name  # optional: human_readable_name
        self.id = actor_id or calvinuuid.uuid("ACTOR")
        self._managed = set(('id', 'name'))
        self.calvinsys = None  # CalvinSys(node)
        self.control = calvincontrol.get_calvincontrol()

        self.inports = {
            p: actorport.InPort(p, self)
            for p in self.inport_names
        }
        self.outports = {
            p: actorport.OutPort(p, self)
            for p in self.outport_names
        }

        hooks = {
            (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
            (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
        }
        self.fsm = Actor.FSM(
            Actor.STATUS,
            Actor.STATUS.LOADED,
            Actor.VALID_TRANSITIONS,
            hooks,
            allow_invalid_transitions=allow_invalid_transitions,
            disable_transition_checks=disable_transition_checks,
            disable_state_checks=disable_state_checks)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
def test_get_calvincontrol_returns_xxx():
    control = get_calvincontrol()
    assert control == get_calvincontrol()
Exemplo n.º 16
0
    def __init__(self, uris, control_uri, attributes=None):
        super(Node, self).__init__()
        self.quitting = False
        self.super_node_class = None

        # 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.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
        # _scheduler = scheduler.NonPreemptiveScheduler
        # _scheduler = scheduler.RoundRobinScheduler
        _scheduler = scheduler.SimpleScheduler
        # _scheduler = scheduler.BaselineScheduler
        self.sched = _scheduler(self, self.am)
        self.async_msg_ids = {}
        calvinsys = get_calvinsys()
        calvinsys.init(self)
        calvinlib = get_calvinlib()
        calvinlib.init()

        # 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)

        self.cpu_monitor = CpuMonitor(self.id, self.storage)
        self.mem_monitor = MemMonitor(self.id, self.storage)

        self.proxy_handler = ProxyHandler(self)

        # The initialization that requires the main loop operating is deferred to start function
        async.DelayedCall(0, self.start)
Exemplo n.º 17
0
def test_get_calvincontrol_returns_xxx():
    control = get_calvincontrol()
    assert control == get_calvincontrol()