X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fccn%2Fccnd.py;h=081435cae7ebed3cf42557cc0116a75a30e035e5;hb=09ac796bac9aa2c41c5ad830f404fe128fffb22d;hp=cc30823d38c0e9822314924b78da6472c8fbb7bd;hpb=46da4690c5120b820385fd47b7fbf995c1bff2a0;p=nepi.git diff --git a/src/nepi/resources/linux/ccn/ccnd.py b/src/nepi/resources/linux/ccn/ccnd.py index cc30823d..081435ca 100644 --- a/src/nepi/resources/linux/ccn/ccnd.py +++ b/src/nepi/resources/linux/ccn/ccnd.py @@ -19,8 +19,8 @@ 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 from nepi.resources.linux.application import LinuxApplication from nepi.resources.linux.node import OSType from nepi.util.timefuncs import tnow, tdiffsec @@ -136,7 +136,7 @@ class LinuxCCND(LinuxApplication): def path(self): return "PATH=$PATH:${BIN}/%s/" % self.version - def deploy(self): + def do_deploy(self): if not self.node or self.node.state < ResourceState.READY: self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state ) @@ -170,68 +170,49 @@ class LinuxCCND(LinuxApplication): self.set("env", self._environment) command = self.get("command") - env = self.get("env") self.info("Deploying command '%s' " % command) - # create home dir for application - self.node.mkdir(self.run_home) + self.do_discover() + self.do_provision() - # upload sources - self.upload_sources() - - # upload code - self.upload_code() - - # upload stdin - self.upload_stdin() - - # install dependencies - self.install_dependencies() - - # build - self.build() - - # Install - self.install() - - # We want to make sure the repository 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) - 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") + + # 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) - def start(self): - if self._state == ResourceState.READY: + def do_start(self): + 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 - def stop(self): + def do_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" @@ -252,8 +233,7 @@ class LinuxCCND(LinuxApplication): stdout = "ccndstop_stdout", stderr = "ccndstop_stderr") - self._stop_time = tnow() - self._state = ResourceState.STOPPED + self.set_stopped() @property def state(self): @@ -261,24 +241,23 @@ class LinuxCCND(LinuxApplication): 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)