Exemple #1
0
    def frcp_create(self, msg_id, topic, rtype, props = None, guards = None ):
        """ Publish a create message

        """
        timestamp = tsformat()
        payload = self._message.create_function(msg_id, self._src, rtype, timestamp , props = props ,guards = guards) 
        self._client.publish(payload, topic)
Exemple #2
0
    def frcp_request(self, topic, props = None, guards = None ):
        """ Execute command on the node

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.request_function(msg_id, self._src, timestamp, props = props ,guards = guards) 
        self._client.publish(payload, xmpp_node)
Exemple #3
0
    def frcp_configure(self, topic, props = None, guards = None ):
        """ Publish a configure message

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.configure_function(msg_id, self._src, timestamp ,props = props ,guards = guards) 
        self._client.publish(payload, topic)
Exemple #4
0
    def frcp_inform(self, topic, cid, itype):
        """ Publish an inform message

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.inform_function(msg_id, self._src, timestamp, props = props ,guards = guards) 
        
        self._client.publish(payload, xmpp_node)
Exemple #5
0
def xmlencode(s):
    if isinstance(s, str):
        rv = s.decode("latin1")
    if isinstance(s, datetime.datetime):
        rv = tsformat(s)
    elif not isinstance(s, unicode):
        rv = unicode(s)
    else:
        rv = s
    return rv.replace(u'\x00',u'�')
Exemple #6
0
def xmlencode(s):
    if isinstance(s, str):
        rv = s.decode("latin1")
    if isinstance(s, datetime.datetime):
        rv = tsformat(s)
    elif not isinstance(s, unicode):
        rv = unicode(s)
    else:
        rv = s
    return rv.replace(u'\x00', u'�')
Exemple #7
0
    def frcp_release(self, msg_id, parent, child, res_id = None, props = None, guards = None ):
        """ Publish a release message

        """
        timestamp = tsformat()
        payload = self._message.release_function(msg_id, self._src, timestamp, res_id = res_id, props = props ,guards = guards) 
        self._client.publish(payload, parent)

        if child in self._topics:
            self._topics.remove(child)

        self._client.unsubscribe(child)
Exemple #8
0
    def frcp_request(self, topic, props=None, guards=None):
        """ Execute command on the node

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.request_function(msg_id,
                                                 self._src,
                                                 timestamp,
                                                 props=props,
                                                 guards=guards)
        self._client.publish(payload, xmpp_node)
Exemple #9
0
    def frcp_create(self, msg_id, topic, rtype, props=None, guards=None):
        """ Publish a create message

        """
        timestamp = tsformat()
        payload = self._message.create_function(msg_id,
                                                self._src,
                                                rtype,
                                                timestamp,
                                                props=props,
                                                guards=guards)
        self._client.publish(payload, topic)
Exemple #10
0
    def frcp_configure(self, topic, props=None, guards=None):
        """ Publish a configure message

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.configure_function(msg_id,
                                                   self._src,
                                                   timestamp,
                                                   props=props,
                                                   guards=guards)
        self._client.publish(payload, topic)
Exemple #11
0
    def frcp_inform(self, topic, cid, itype):
        """ Publish an inform message

        """
        msg_id = os.urandom(16).encode('hex')
        timestamp = tsformat()
        payload = self._message.inform_function(msg_id,
                                                self._src,
                                                timestamp,
                                                props=props,
                                                guards=guards)

        self._client.publish(payload, xmpp_node)
Exemple #12
0
    def frcp_release(self,
                     msg_id,
                     parent,
                     child,
                     res_id=None,
                     props=None,
                     guards=None):
        """ Publish a release message

        """
        timestamp = tsformat()
        payload = self._message.release_function(msg_id,
                                                 self._src,
                                                 timestamp,
                                                 res_id=res_id,
                                                 props=props,
                                                 guards=guards)
        self._client.publish(payload, parent)

        if child in self._topics:
            self._topics.remove(child)

        self._client.unsubscribe(child)
Exemple #13
0
    def __init__(self,
                 exp_id=None,
                 local_dir=None,
                 persist=False,
                 fm=None,
                 add_node_callback=None,
                 add_edge_callback=None,
                 **kwargs):
        """ ExperimentController entity to model an execute a network 
        experiment.
        
        :param exp_id: Human readable name to identify the experiment
        :type exp_id: str

        :param local_dir: Path to local directory where to store experiment
            related files
        :type local_dir: str

        :param persist: Save an XML description of the experiment after 
        completion at local_dir
        :type persist: bool

        :param fm: FailureManager object. If None is given, the default 
            FailureManager class will be used
        :type fm: FailureManager

        :param add_node_callback: Callback to invoke for node instantiation
        when automatic topology creation mode is used 
        :type add_node_callback: function

        :param add_edge_callback: Callback to invoke for edge instantiation 
        when automatic topology creation mode is used 
        :type add_edge_callback: function

        """
        super(ExperimentController, self).__init__()

        # Logging
        self._logger = logging.getLogger("ExperimentController")

        # Run identifier. It identifies a concrete execution instance (run)
        # of an experiment.
        # Since a same experiment (same configuration) can be executed many
        # times, this run_id permits to separate result files generated on
        # different experiment executions
        self._run_id = tsformat()

        # Experiment identifier. Usually assigned by the user
        # Identifies the experiment scenario (i.e. configuration,
        # resources used, etc)
        self._exp_id = exp_id or "exp-%s" % os.urandom(8).encode('hex')

        # Local path where to store experiment related files (results, etc)
        if not local_dir:
            local_dir = tempfile.gettempdir()  # /tmp

        self._local_dir = local_dir
        self._exp_dir = os.path.join(local_dir, self.exp_id)
        self._run_dir = os.path.join(self.exp_dir, self.run_id)

        # If True persist the experiment controller in XML format, after completion
        self._persist = persist

        # generator of globally unique ids
        self._guid_generator = guid.GuidGenerator()

        # Resource managers
        self._resources = dict()

        # Scheduler. It a queue that holds tasks scheduled for
        # execution, and yields the next task to be executed
        # ordered by execution and arrival time
        self._scheduler = HeapScheduler()

        # Tasks
        self._tasks = dict()

        # RM groups (for deployment)
        self._groups = dict()

        # generator of globally unique id for groups
        self._group_id_generator = guid.GuidGenerator()

        # Flag to stop processing thread
        self._stop = False

        # Entity in charge of managing system failures
        if not fm:
            self._fm = FailureManager()
        self._fm.set_ec(self)

        # EC state
        self._state = ECState.RUNNING

        # Automatically construct experiment description
        self._netgraph = None
        if add_node_callback or add_edge_callback or kwargs.get("topology"):
            self._build_from_netgraph(add_node_callback, add_edge_callback,
                                      **kwargs)

        # The runner is a pool of threads used to parallelize
        # execution of tasks
        self._nthreads = 20
        self._runner = None

        # Event processing thread
        self._cond = threading.Condition()
        self._thread = threading.Thread(target=self._process)
        self._thread.setDaemon(True)
        self._thread.start()
Exemple #14
0
    def __init__(self, exp_id = None, local_dir = None, persist = False,
            fm = None, add_node_callback = None, add_edge_callback = None, 
            **kwargs):
        """ ExperimentController entity to model an execute a network 
        experiment.
        
        :param exp_id: Human readable name to identify the experiment
        :type exp_id: str

        :param local_dir: Path to local directory where to store experiment
            related files
        :type local_dir: str

        :param persist: Save an XML description of the experiment after 
        completion at local_dir
        :type persist: bool

        :param fm: FailureManager object. If None is given, the default 
            FailureManager class will be used
        :type fm: FailureManager

        :param add_node_callback: Callback to invoke for node instantiation
        when automatic topology creation mode is used 
        :type add_node_callback: function

        :param add_edge_callback: Callback to invoke for edge instantiation 
        when automatic topology creation mode is used 
        :type add_edge_callback: function

        """
        super(ExperimentController, self).__init__()

        # Logging
        self._logger = logging.getLogger("ExperimentController")

        # Run identifier. It identifies a concrete execution instance (run) 
        # of an experiment.
        # Since a same experiment (same configuration) can be executed many 
        # times, this run_id permits to separate result files generated on 
        # different experiment executions
        self._run_id = tsformat()

        # Experiment identifier. Usually assigned by the user
        # Identifies the experiment scenario (i.e. configuration, 
        # resources used, etc)
        self._exp_id = exp_id or "exp-%s" % os.urandom(8).encode('hex')

        # Local path where to store experiment related files (results, etc)
        if not local_dir:
            local_dir = tempfile.gettempdir() # /tmp

        self._local_dir = local_dir
        self._exp_dir = os.path.join(local_dir, self.exp_id)
        self._run_dir = os.path.join(self.exp_dir, self.run_id)

        # If True persist the experiment controller in XML format, after completion
        self._persist = persist

        # generator of globally unique ids
        self._guid_generator = guid.GuidGenerator()
        
        # Resource managers
        self._resources = dict()

        # Scheduler. It a queue that holds tasks scheduled for
        # execution, and yields the next task to be executed 
        # ordered by execution and arrival time
        self._scheduler = HeapScheduler()

        # Tasks
        self._tasks = dict()

        # RM groups (for deployment) 
        self._groups = dict()

        # generator of globally unique id for groups
        self._group_id_generator = guid.GuidGenerator()

        # Flag to stop processing thread
        self._stop = False
    
        # Entity in charge of managing system failures
        if not fm:
            self._fm = FailureManager()
        self._fm.set_ec(self)

        # EC state
        self._state = ECState.RUNNING

        # Automatically construct experiment description 
        self._netgraph = None
        if add_node_callback or add_edge_callback or kwargs.get("topology"):
            self._build_from_netgraph(add_node_callback, add_edge_callback, 
                    **kwargs)

        # The runner is a pool of threads used to parallelize 
        # execution of tasks
        self._nthreads = 20
        self._runner = None

        # Event processing thread
        self._cond = threading.Condition()
        self._thread = threading.Thread(target = self._process)
        self._thread.setDaemon(True)
        self._thread.start()