X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fccn%2Fccnd.py;h=48ed807a330176a10991f83505bb77a6a3b472b9;hb=d50ba1a08e541ded7a8b322493ebb1d0cc59c6ff;hp=44c1afb922bd738cc34328faa99cc3d788b7d28b;hpb=54d2a201dca3af3dabf18601d4909bf506960627;p=nepi.git diff --git a/src/nepi/resources/linux/ccn/ccnd.py b/src/nepi/resources/linux/ccn/ccnd.py index 44c1afb9..48ed807a 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 from nepi.resources.linux.application import LinuxApplication from nepi.resources.linux.node import OSType from nepi.util.timefuncs import tnow, tdiffsec @@ -32,7 +32,7 @@ import os @clsinit_copy class LinuxCCND(LinuxApplication): - _rtype = "LinuxCCND" + _rtype = "linux::CCND" @classmethod def _register_attributes(cls): @@ -50,56 +50,56 @@ class LinuxCCND(LinuxApplication): " -1 - max logging \n" " Or apply bitwise OR to these values to get combinations of them", type = Types.Integer, - flags = Flags.ExecReadOnly) + flags = Flags.Design) port = Attribute("port", "Sets the CCN_LOCAL_PORT environmental variable. " "Defaults to 9695 ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) sockname = Attribute("sockname", "Sets the CCN_LOCAL_SCOKNAME environmental variable. " "Defaults to /tmp/.ccnd.sock", - flags = Flags.ExecReadOnly) + flags = Flags.Design) capacity = Attribute("capacity", "Sets the CCND_CAP environmental variable. " "Capacity limit in terms of ContentObjects", - flags = Flags.ExecReadOnly) + flags = Flags.Design) mtu = Attribute("mtu", "Sets the CCND_MTU environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) data_pause = Attribute("dataPauseMicrosec", "Sets the CCND_DATA_PAUSE_MICROSEC environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) default_stale = Attribute("defaultTimeToStale", "Sets the CCND_DEFAULT_TIME_TO_STALE environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) max_stale = Attribute("maxTimeToStale", "Sets the CCND_MAX_TIME_TO_STALE environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) max_rte = Attribute("maxRteMicrosec", "Sets the CCND_MAX_RTE_MICROSEC environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) keystore = Attribute("keyStoreDirectory", "Sets the CCND_KEYSTORE_DIRECTORY environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) listen_on = Attribute("listenOn", "Sets the CCND_LISTEN_ON environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) autoreg = Attribute("autoreg", "Sets the CCND_AUTOREG environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) prefix = Attribute("prefix", "Sets the CCND_PREFIX environmental variable. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) cls._register_attribute(debug) cls._register_attribute(port) @@ -126,13 +126,22 @@ class LinuxCCND(LinuxApplication): def __init__(self, ec, guid): super(LinuxCCND, self).__init__(ec, guid) self._home = "ccnd-%s" % self.guid + self._version = "ccnx" - def deploy(self): + @property + def version(self): + return self._version + + @property + def path(self): + return "PATH=$PATH:${BIN}/%s/" % self.version + + def do_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) + self.ec.schedule(self.reschedule_delay, self.deploy) else: if not self.get("command"): self.set("command", self._start_command) @@ -143,6 +152,14 @@ class LinuxCCND(LinuxApplication): 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","") ) + if not self.get("build"): self.set("build", self._build) @@ -153,66 +170,47 @@ 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.app_home) - - # upload sources - self.upload_sources() - - # upload code - self.upload_code() - - # upload stdin - self.upload_stdin() + self.do_discover() + self.do_provision() - # install dependencies - self.install_dependencies() + self.set_ready() - # build - self.build() + def upload_start_command(self): + command = self.get("command") + env = self.get("env") - # 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) + # 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) - self.node.run_and_wait(command, self.app_home, - env = env, - shfile = "app.sh", - raise_on_error = True) - - self.debug("----- READY ---- ") - self._ready_time = tnow() - self._state = ResourceState.READY + shfile = os.path.join(self.app_home, "start.sh") + self.node.run_and_wait(command, self.run_home, + shfile = shfile, + overwrite = False, + env = env) - 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" @@ -223,16 +221,17 @@ class LinuxCCND(LinuxApplication): env = env and self.replace_paths(env) # Upload the command to a file, and execute asynchronously - self.node.run_and_wait(command, self.app_home, - shfile = "ccndstop.sh", + shfile = os.path.join(self.app_home, "stop.sh") + self.node.run_and_wait(command, self.run_home, + shfile = shfile, + overwrite = False, env = env, pidfile = "ccndstop_pidfile", ecodefile = "ccndstop_exitcode", stdout = "ccndstop_stdout", stderr = "ccndstop_stderr") - self._stop_time = tnow() - self._state = ResourceState.STOPPED + self.set_stopped() @property def state(self): @@ -240,24 +239,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_stopped() 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) @@ -284,7 +282,7 @@ class LinuxCCND(LinuxApplication): @property def _sources(self): - return "http://www.ccnx.org/releases/ccnx-0.7.2.tar.gz" + return "http://www.ccnx.org/releases/ccnx-0.8.2.tar.gz" @property def _build(self): @@ -294,32 +292,35 @@ class LinuxCCND(LinuxApplication): return ( # Evaluate if ccnx binaries are already installed " ( " - " test -f ${EXP_HOME}/ccnx/bin/ccnd && " - " echo 'sources found, nothing to do' " + " test -f ${BIN}/%(version)s/ccnd && " + " echo 'binaries found, nothing to do' " " ) || ( " # If not, untar and build " ( " - " mkdir -p ${SOURCES}/ccnx && " - " tar xf ${SOURCES}/%(sources)s --strip-components=1 -C ${SOURCES}/ccnx " + " mkdir -p ${SRC}/%(version)s && " + " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/%(version)s " " ) && " - "cd ${SOURCES}/ccnx && " + "cd ${SRC}/%(version)s && " # Just execute and silence warnings... " ( ./configure && make ) " - " )") % ({ 'sources': sources }) + " )") % ({ 'sources': sources, + 'version': self.version + }) @property def _install(self): return ( # Evaluate if ccnx binaries are already installed " ( " - " test -f ${EXP_HOME}/ccnx/bin/ccnd && " - " echo 'sources found, nothing to do' " + " test -f ${BIN}/%(version)s/ccnd && " + " echo 'binaries found, nothing to do' " " ) || ( " # If not, install - " mkdir -p ${EXP_HOME}/ccnx/bin && " - " cp -r ${SOURCES}/ccnx ${EXP_HOME}" + " mkdir -p ${BIN}/%(version)s && " + " mv ${SRC}/%(version)s/bin/* ${BIN}/%(version)s/ " " )" - ) + ) % ({ 'version': self.version + }) @property def _environment(self): @@ -339,12 +340,12 @@ class LinuxCCND(LinuxApplication): "prefix" : "CCND_PREFIX", }) - env = "PATH=$PATH:${EXP_HOME}/ccnx/bin " + env = self.path env += " ".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))) \ if self.get(k) else "", envs.keys())) return env - + def valid_connection(self, guid): # TODO: Validate! return True