2 NEPI, a framework to manage network experiments
3 Copyright (C) 2013 INRIA
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from nepi.execution.resource import ResourceManager, clsinit
21 from nepi.execution.attribute import Attribute, Flags
22 from nepi.resources.omf.omf_api import OMFAPIFactory
25 class OMFApplication(ResourceManager):
27 .. class:: Class Args :
29 :param ec: The Experiment controller
30 :type ec: ExperimentController
31 :param guid: guid of the RM
33 :param creds: Credentials to communicate with the rm (XmppClient)
38 This class is used only by the Experiment Controller through the Resource Factory
41 _rtype = "OMFApplication"
42 _authorized_connections = ["OMFNode"]
43 _waiters = ["OMFNode", "OMFChannel", "OMFWifiInterface"]
46 def _register_attributes(cls):
47 """Register the attributes of an OMF application
50 appid = Attribute("appid", "Name of the application")
51 path = Attribute("path", "Path of the application")
52 args = Attribute("args", "Argument of the application")
53 env = Attribute("env", "Environnement variable of the application")
54 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
55 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
56 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
57 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
58 cls._register_attribute(appid)
59 cls._register_attribute(path)
60 cls._register_attribute(args)
61 cls._register_attribute(env)
62 cls._register_attribute(xmppSlice)
63 cls._register_attribute(xmppHost)
64 cls._register_attribute(xmppPort)
65 cls._register_attribute(xmppPassword)
68 def __init__(self, ec, guid):
70 :param ec: The Experiment controller
71 :type ec: ExperimentController
72 :param guid: guid of the RM
74 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
79 super(OMFApplication, self).__init__(ec, guid)
90 def _validate_connection(self, guid):
91 """Check if the connection is available.
93 :param guid: Guid of the current RM
98 rm = self.ec.get_resource(guid)
99 if rm.rtype() not in self._authorized_connections:
100 msg = "Connection between %s %s and %s %s refused : An Application can be connected only to a Node" % (self.rtype(), self._guid, rm.rtype(), guid)
101 self._logger.debug(msg)
103 elif len(self.connections) != 0 :
104 msg = "Connection between %s %s and %s %s refused : Already Connected" % (self.rtype(), self._guid, rm.rtype(), guid)
105 self._logger.debug(msg)
108 msg = "Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid)
109 self._logger.debug(msg)
112 def _get_nodes(self, conn_set):
113 """Get the RM of the node to which the application is connected
115 :param conn_set: Connections of the current Guid
117 :rtype: ResourceManager
121 rm = self.ec.get_resource(elt)
122 if rm.rtype() == "OMFNode":
130 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
131 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
132 super(OMFApplication, self).deploy()
135 """Send Xmpp Message Using OMF protocol to execute the application
138 super(OMFApplication, self).start()
139 msg = " " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('appid') + " : " + self.get('path') + " : " + self.get('args') + " : " + self.get('env')
142 if self.get('appid') and self.get('path') and self.get('args') and self.get('env'):
143 rm_node = self._get_nodes(self._connections)
144 self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), self.get('args'), self.get('path'), self.get('env'))
147 """Send Xmpp Message Using OMF protocol to kill the application
151 rm_node = self._get_nodes(self._connections)
152 self._omf_api.exit(rm_node.get('hostname'),self.get('appid'))
153 super(OMFApplication, self).stop()
156 """Clean the RM at the end of the experiment
159 OMFAPIFactory.release_api(self.get('xmppSlice'),
160 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))