# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
# Julien Tribino <julien.tribino@inria.fr>
-from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \
- reschedule_delay
+from nepi.execution.resource import ResourceManager, clsinit_copy, \
+ ResourceState, reschedule_delay
from nepi.execution.attribute import Attribute, Flags
from nepi.resources.omf.omf_resource import ResourceGateway, OMFResource
from nepi.resources.omf.node import OMFNode
from nepi.resources.omf.omf_api import OMFAPIFactory
-
@clsinit_copy
class OMFApplication(OMFResource):
"""
_rtype = "OMFApplication"
_authorized_connections = ["OMFNode"]
- @classmethod
- def stdin_send(cls, old_value, new_value):
- print "AAHHHHHHHH"
-
@classmethod
def _register_attributes(cls):
""" Register the attributes of an OMF application
path = Attribute("path", "Path of the application")
args = Attribute("args", "Argument of the application")
env = Attribute("env", "Environnement variable of the application")
- stdin = Attribute("stdin", "Input of the application", default = "", set_hook = cls.stdin_send )
+ stdin = Attribute("stdin", "Input of the application", default = "")
cls._register_attribute(appid)
cls._register_attribute(path)
cls._register_attribute(args)
self._omf_api = None
+ self.add_set_hook()
+
@property
def exp_id(self):
- if self.ec.exp_id.startswith('exp-'):
- return None
return self.ec.exp_id
@property
if rm_list: return rm_list[0]
return None
+ def stdin_hook(self, old_value, new_value):
+ self._omf_api.send_stdin(self.node.get('hostname'), new_value, self.get('appid'))
+ return new_value
+ def add_set_hook(self):
+ attr = self._attrs["stdin"]
+ attr.set_hook = self.stdin_hook
def valid_connection(self, guid):
""" Check if the connection with the guid in parameter is possible.
return True
- def deploy(self):
+ def do_deploy(self):
""" Deploy the RM. It means nothing special for an application
for now (later it will be upload sources, ...)
It becomes DEPLOYED after getting the xmpp client.
if not self._omf_api :
msg = "Credentials are not initialzed. XMPP Connections impossible"
self.error(msg)
- self.fail()
- return
+ raise RuntimeError, msg
- super(OMFApplication, self).deploy()
+ super(OMFApplication, self).do_deploy()
- def start(self):
+ def do_start(self):
""" Start the RM. It means : Send Xmpp Message Using OMF protocol
to execute the application.
It becomes STARTED before the messages are sent (for coordination)
if not (self.get('appid') and self.get('path')) :
msg = "Application's information are not initialized"
self.error(msg)
- self.fail()
- return
+ raise RuntimeError, msg
if not self.get('args'):
self.set('args', " ")
except AttributeError:
msg = "Credentials are not initialzed. XMPP Connections impossible"
self.error(msg)
- self.fail()
raise
- super(OMFApplication, self).start()
+ super(OMFApplication, self).do_start()
- def stop(self):
+ def do_stop(self):
""" Stop the RM. It means : Send Xmpp Message Using OMF protocol to
kill the application.
State is set to STOPPED after the message is sent.
except AttributeError:
msg = "Credentials were not initialzed. XMPP Connections impossible"
self.error(msg)
- self.fail()
- #raise
+ raise
- super(OMFApplication, self).stop()
+ super(OMFApplication, self).do_stop()
- def release(self):
+ def do_release(self):
""" Clean the RM at the end of the experiment and release the API.
"""
- if self._omf_api :
+ if self._omf_api:
OMFAPIFactory.release_api(self.get('xmppSlice'),
self.get('xmppHost'), self.get('xmppPort'),
self.get('xmppPassword'), exp_id = self.exp_id)
- super(OMFApplication, self).release()
+ super(OMFApplication, self).do_release()