3 from neco.execution.resource import ResourceManager, clsinit
4 from neco.execution.attribute import Attribute, Flags
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFApplication(ResourceManager):
13 .. class:: Class Args :
15 :param ec: The Experiment controller
16 :type ec: ExperimentController
17 :param guid: guid of the RM
19 :param creds: Credentials to communicate with the rm (XmppClient)
24 This class is used only by the Experiment Controller through the Resource Factory
27 _rtype = "OMFApplication"
28 _authorized_connections = ["OMFNode"]
29 _waiters = ["OMFNode", "OMFChannel", "OMFWifiInterface"]
32 def _register_attributes(cls):
33 """Register the attributes of an OMF application
36 appid = Attribute("appid", "Name of the application")
37 path = Attribute("path", "Path of the application")
38 args = Attribute("args", "Argument of the application")
39 env = Attribute("env", "Environnement variable of the application")
40 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
41 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
42 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
43 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
44 cls._register_attribute(appid)
45 cls._register_attribute(path)
46 cls._register_attribute(args)
47 cls._register_attribute(env)
48 cls._register_attribute(xmppSlice)
49 cls._register_attribute(xmppHost)
50 cls._register_attribute(xmppPort)
51 cls._register_attribute(xmppPassword)
54 def __init__(self, ec, guid):
56 :param ec: The Experiment controller
57 :type ec: ExperimentController
58 :param guid: guid of the RM
60 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
65 super(OMFApplication, self).__init__(ec, guid)
76 self._logger = logging.getLogger("neco.omf.omfApp ")
77 self._logger.setLevel(neco.LOGLEVEL)
80 def _validate_connection(self, guid):
81 """Check if the connection is available.
83 :param guid: Guid of the current RM
88 rm = self.ec.get_resource(guid)
89 if rm.rtype() not in self._authorized_connections:
90 self._logger.debug("Connection between %s %s and %s %s refused : An Application can be connected only to a Node" % (self.rtype(), self._guid, rm.rtype(), guid))
92 elif len(self.connections) != 0 :
93 self._logger.debug("Connection between %s %s and %s %s refused : Already Connected" % (self.rtype(), self._guid, rm.rtype(), guid))
96 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
99 def _get_nodes(self, conn_set):
100 """Get the RM of the node to which the application is connected
102 :param conn_set: Connections of the current Guid
104 :rtype: ResourceManager
108 rm = self.ec.get_resource(elt)
109 if rm.rtype() == "OMFNode":
113 def deploy_action(self):
117 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
118 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
119 super(OMFApplication, self).deploy_action()
122 """Send Xmpp Message Using OMF protocol to execute the application
125 super(OMFApplication, self).start()
126 self._logger.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('appid') + " : " + self.get('path') + " : " + self.get('args') + " : " + self.get('env'))
128 if self.get('appid') and self.get('path') and self.get('args') and self.get('env'):
129 rm_node = self._get_nodes(self._connections)
130 self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), self.get('args'), self.get('path'), self.get('env'))
133 """Send Xmpp Message Using OMF protocol to kill the application
137 rm_node = self._get_nodes(self._connections)
138 self._omf_api.exit(rm_node.get('hostname'),self.get('appid'))
139 super(OMFApplication, self).stop()
142 """Clean the RM at the end of the experiment
145 OMFAPIFactory.release_api(self.get('xmppSlice'),
146 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))