from nepi.execution.attribute import Attribute, Flags, Types
from nepi.execution.trace import Trace, TraceAttr
-from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \
- reschedule_delay
+from nepi.execution.resource import ResourceManager, clsinit_copy, \
+ ResourceState, reschedule_delay, failtrap
from nepi.resources.linux.application import LinuxApplication
from nepi.resources.linux.node import OSType
from nepi.util.timefuncs import tnow, tdiffsec
def path(self):
return "PATH=$PATH:${BIN}/%s/" % self.version
+ @failtrap
def deploy(self):
if not self.node or self.node.state < ResourceState.READY:
self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
# ccnd needs to wait until node is deployed and running
self.ec.schedule(reschedule_delay, self.deploy)
else:
- try:
- if not self.get("command"):
- self.set("command", self._start_command)
-
- if not self.get("depends"):
- self.set("depends", self._dependencies)
+ if not self.get("command"):
+ self.set("command", self._start_command)
+
+ if not self.get("depends"):
+ self.set("depends", self._dependencies)
- if not self.get("sources"):
- self.set("sources", self._sources)
+ if not self.get("sources"):
+ self.set("sources", self._sources)
- sources = self.get("sources")
- source = sources.split(" ")[0]
- basename = os.path.basename(source)
- self._version = ( basename.strip().replace(".tar.gz", "")
- .replace(".tar","")
- .replace(".gz","")
- .replace(".zip","") )
+ sources = self.get("sources")
+ source = sources.split(" ")[0]
+ basename = os.path.basename(source)
+ self._version = ( basename.strip().replace(".tar.gz", "")
+ .replace(".tar","")
+ .replace(".gz","")
+ .replace(".zip","") )
- if not self.get("build"):
- self.set("build", self._build)
+ if not self.get("build"):
+ self.set("build", self._build)
- if not self.get("install"):
- self.set("install", self._install)
+ if not self.get("install"):
+ self.set("install", self._install)
- if not self.get("env"):
- self.set("env", self._environment)
+ if not self.get("env"):
+ self.set("env", self._environment)
- command = self.get("command")
+ command = self.get("command")
- self.info("Deploying command '%s' " % command)
+ self.info("Deploying command '%s' " % command)
+
+ self.discover()
+ self.provision()
- self.discover()
- self.provision()
- except:
- self.fail()
- raise
-
self.debug("----- READY ---- ")
- self._ready_time = tnow()
- self._state = ResourceState.READY
+ self.set_ready()
def upload_start_command(self):
command = self.get("command")
env = self.get("env")
- if command:
- # We want to make sure the ccnd is running
- # before the experiment starts.
- # Run the command as a bash script in background,
- # in the host ( but wait until the command has
- # finished to continue )
- env = self.replace_paths(env)
- command = self.replace_paths(command)
+ # We want to make sure the ccnd is running
+ # before the experiment starts.
+ # Run the command as a bash script in background,
+ # in the host ( but wait until the command has
+ # finished to continue )
+ env = self.replace_paths(env)
+ command = self.replace_paths(command)
- shfile = os.path.join(self.app_home, "start.sh")
- self.node.run_and_wait(command, self.run_home,
- shfile = shfile,
- overwrite = False,
- env = env,
- raise_on_error = True)
-
+ shfile = os.path.join(self.app_home, "start.sh")
+ self.node.run_and_wait(command, self.run_home,
+ shfile = shfile,
+ overwrite = False,
+ env = env,
+ raise_on_error = True)
+
+ @failtrap
def start(self):
- if self._state == ResourceState.READY:
+ if self.state == ResourceState.READY:
command = self.get("command")
self.info("Starting command '%s'" % command)
- self._start_time = tnow()
- self._state = ResourceState.STARTED
+ self.set_started()
else:
msg = " Failed to execute command '%s'" % command
self.error(msg, out, err)
- self._state = ResourceState.FAILED
raise RuntimeError, msg
+ @failtrap
def stop(self):
command = self.get('command') or ''
- state = self.state
- if state == ResourceState.STARTED:
+ if self.state == ResourceState.STARTED:
self.info("Stopping command '%s'" % command)
command = "ccndstop"
stdout = "ccndstop_stdout",
stderr = "ccndstop_stderr")
- self._stop_time = tnow()
- self._state = ResourceState.STOPPED
+ self.set_stopped()
@property
def state(self):
state_check_delay = 0.5
if self._state == ResourceState.STARTED and \
tdiffsec(tnow(), self._last_state_check) > state_check_delay:
- (out, err), proc = self._ccndstatus
+ (out, err), proc = self._ccndstatus()
retcode = proc.poll()
if retcode == 1 and err.find("No such file or directory") > -1:
# ccnd is not running (socket not found)
- self._state = ResourceState.FINISHED
+ self.set_finished()
elif retcode:
# other errors ...
msg = " Failed to execute command '%s'" % self.get("command")
self.error(msg, out, err)
- self._state = ResourceState.FAILED
+ self.fail()
self._last_state_check = tnow()
return self._state
- @property
def _ccndstatus(self):
env = self.get('env') or ""
environ = self.node.format_environment(env, inline = True)