ec.set(node, "hostname", host)
ec.set(node, "username", user)
ec.set(node, "identity", ssh_key)
- #ec.set(node, "cleanHome", True)
+ ec.set(node, "cleanHome", True)
ec.set(node, "cleanProcesses", True)
return node
# TODO: During provisioning, everything that is not scp could be
# uploaded to a same script, http_sources download, etc...
# and like that require performing less ssh connections!!!
+# TODO: Make stdin be a symlink to the original file in ${SHARE}
+# - later use md5sum to check wether the file needs to be re-upload
@clsinit
step()
+ self.upload_start_command()
+
+ self.info("Provisioning finished")
+
+ super(LinuxApplication, self).provision()
+
+ def upload_start_command(self):
# Upload command to remote bash script
# - only if command can be executed in background and detached
command = self.get("command")
env = self.get("env")
env = env and self.replace_paths(env)
- shfile = os.path.join(self.app_home, "app.sh")
+ shfile = os.path.join(self.app_home, "start.sh")
self.node.upload_command(command,
shfile = shfile,
env = env)
-
- self.info("Provisioning finished")
-
- super(LinuxApplication, self).provision()
def upload_sources(self):
sources = self.get("sources")
# The command to run was previously uploaded to a bash script
# during deployment, now we launch the remote script using 'run'
# method from the node.
- cmd = "bash %s" % os.path.join(self.app_home, "app.sh")
+ cmd = "bash %s" % os.path.join(self.app_home, "start.sh")
(out, err), proc = self.node.run(cmd, self.run_home,
stdin = stdin,
stdout = stdout,
#
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
-from nepi.execution.resource import clsinit_copy, ResourceState, \
- ResourceAction
+from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \
+ reschedule_delay
from nepi.resources.linux.application import LinuxApplication
from nepi.resources.linux.ccn.ccnd import LinuxCCND
+from nepi.util.timefuncs import tnow, tdiffsec
import os
return None
def deploy(self):
- if not self.get("env"):
- self.set("env", self._environment)
+ if not self.ccnd or self.ccnd.state < ResourceState.READY:
+ self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
+ self.ec.schedule(reschedule_delay, self.deploy)
+ else:
+ try:
+ command = self.get("command") or ""
- super(LinuxCCNApplication, self).deploy()
+ self.info("Deploying command '%s' " % command)
+
+ if not self.get("env"):
+ self.set("env", self._environment)
+
+ self.discover()
+ self.provision()
+ except:
+ self._state = ResourceState.FAILED
+ raise
+
+ self.debug("----- READY ---- ")
+ self._ready_time = tnow()
+ self._state = ResourceState.READY
@property
def _environment(self):
- env = "PATH=$PATH:${STORE}/ccnx/bin "
- return env
+ return self.ccnd.path
def execute_command(self, command, env):
environ = self.node.format_environment(env, inline = True)
from nepi.execution.attribute import Attribute, Flags, Types
from nepi.execution.resource import clsinit_copy, ResourceState, \
ResourceAction, reschedule_delay
-from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
+from nepi.resources.linux.application import LinuxApplication
from nepi.resources.linux.ccn.ccnr import LinuxCCNR
from nepi.util.timefuncs import tnow
import os
@clsinit_copy
-class LinuxCCNContent(LinuxCCNApplication):
+class LinuxCCNContent(LinuxApplication):
_rtype = "LinuxCCNContent"
@classmethod
if ccnr: return ccnr[0]
return None
+ @property
+ def ccnd(self):
+ if self.ccnr: return self.ccnr.ccnd
+ return None
+
@property
def node(self):
if self.ccnr: return self.ccnr.node
return None
+
def deploy(self):
if not self.ccnr or self.ccnr.state < ResourceState.READY:
self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
self.info("Deploying command '%s' " % command)
- self.node.mkdir(self.app_home)
+ # create run dir for application
+ self.node.mkdir(self.run_home)
# upload content
self.upload_stdin()
return "ccnseqwriter -r %s < %s" % (self.get("contentName"),
os.path.join(self.app_home, 'stdin'))
+ @property
+ def _environment(self):
+ return self.ccnd.path
+
+ def execute_command(self, command, env):
+ environ = self.node.format_environment(env, inline = True)
+ command = environ + command
+ command = self.replace_paths(command)
+
+ return self.node.execute(command)
+
def valid_connection(self, guid):
# TODO: Validate!
return True
def __init__(self, ec, guid):
super(LinuxCCND, self).__init__(ec, guid)
self._home = "ccnd-%s" % self.guid
- self._version = None
- self._environment = None
+ self._version = "ccnx"
+
+ @property
+ def version(self):
+ return self._version
+
+ @property
+ def path(self):
+ return "PATH=$PATH:${BIN}/%s/" % self.version
def deploy(self):
if not self.node or self.node.state < ResourceState.READY:
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)
self.info("Deploying command '%s' " % command)
# create home dir for application
- self.node.mkdir(self.app_home)
+ self.node.mkdir(self.run_home)
# upload sources
self.upload_sources()
env = self.replace_paths(env)
command = self.replace_paths(command)
- self.node.run_and_wait(command, self.app_home,
+ shfile = os.path.join(self.app_home, "start.sh")
+ self.node.run_and_wait(command, self.run_home,
+ shfile = shfile,
+ overwrite = False,
env = env,
- shfile = "app.sh",
raise_on_error = True)
self.debug("----- READY ---- ")
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",
return (
# Evaluate if ccnx binaries are already installed
" ( "
- " test -f ${STORE}/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 ${STORE}/ccnx && "
- " tar xf ${STORE}/%(sources)s --strip-components=1 -C ${STORE}/ccnx "
+ " mkdir -p ${SRC}/%(version)s && "
+ " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/%(version)s "
" ) && "
- "cd ${STORE}/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 ${SOURCES}/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 ${SOURCES}/ccnx/bin && "
- " cp -r ${}/ccnx ${STORE}"
+ " mkdir -p ${BIN}/%(version)s && "
+ " mv ${SRC}/%(version)s/bin/* ${BIN}/%(version)s/ "
" )"
- )
+ ) % ({ 'version': self.version
+ })
@property
def _environment(self):
"prefix" : "CCND_PREFIX",
})
- env = "PATH=$PATH:${SOURCES}/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
from nepi.execution.trace import Trace, TraceAttr
from nepi.execution.resource import clsinit_copy, ResourceState, \
ResourceAction, reschedule_delay
-from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
+from nepi.resources.linux.application import LinuxApplication
from nepi.resources.linux.ccn.ccnd import LinuxCCND
from nepi.util.timefuncs import tnow
import os
@clsinit_copy
-class LinuxCCNR(LinuxCCNApplication):
+class LinuxCCNR(LinuxApplication):
_rtype = "LinuxCCNR"
@classmethod
super(LinuxCCNR, self).__init__(ec, guid)
self._home = "ccnr-%s" % self.guid
+ @property
+ def ccnd(self):
+ ccnd = self.get_connected(LinuxCCND.rtype())
+ if ccnd: return ccnd[0]
+ return None
+
+ @property
+ def node(self):
+ if self.ccnd: return self.ccnd.node
+ return None
+
def deploy(self):
if not self.ccnd or self.ccnd.state < ResourceState.READY:
self.debug("---- RESCHEDULING DEPLOY ---- CCND state %s " % self.ccnd.state )
self.info("Deploying command '%s' " % command)
- self.node.mkdir(self.app_home)
+ self.node.mkdir(self.run_home)
# upload sources
self.upload_sources()
env = self.replace_paths(env)
command = self.replace_paths(command)
- self.node.run_and_wait(command, self.app_home,
+ shfile = os.path.join(self.app_home, "start.sh")
+ self.node.run_and_wait(command, self.run_home,
+ shfile = shfile,
+ overwrite = False,
env = env,
- shfile = "app.sh",
raise_on_error = True)
-
+
self.debug("----- READY ---- ")
self._ready_time = tnow()
self._state = ResourceState.READY
"ccnsSyncScope": "CCNS_SYNC_SCOPE",
})
- env = "PATH=$PATH:${STORE}/ccnx/bin "
+ env = self.ccnd.path
env += " ".join(map(lambda k: "%s=%s" % (envs.get(k), self.get(k)) \
if self.get(k) else "", envs.keys()))
from nepi.execution.trace import Trace, TraceAttr
from nepi.execution.resource import clsinit_copy, ResourceState, \
ResourceAction, reschedule_delay
-from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
+from nepi.resources.linux.application import LinuxApplication
+from nepi.resources.linux.ccn.ccnd import LinuxCCND
from nepi.util.timefuncs import tnow
import os
# Implement ENTRY DELETE!!
@clsinit_copy
-class LinuxFIBEntry(LinuxCCNApplication):
+class LinuxFIBEntry(LinuxApplication):
_rtype = "LinuxFIBEntry"
@classmethod
super(LinuxFIBEntry, self).__init__(ec, guid)
self._home = "fib-%s" % self.guid
+ @property
+ def ccnd(self):
+ ccnd = self.get_connected(LinuxCCND.rtype())
+ if ccnd: return ccnd[0]
+ return None
+
+ @property
+ def node(self):
+ if self.ccnd: return self.ccnd.node
+ return None
+
def deploy(self):
# Wait until associated ccnd is provisioned
if not self.ccnd or self.ccnd.state < ResourceState.READY:
self.set("env", env)
self.info("Deploying command '%s' " % command)
-
- self.node.mkdir(self.app_home)
+
+ # create run dir for application
+ self.node.mkdir(self.run_home)
+
(out, err), proc = self.execute_command(command, env)
if proc.poll():
self.error(msg, out, err)
raise RuntimeError, msg
-
self.debug("----- READY ---- ")
self._ready_time = tnow()
self._state = ResourceState.READY
"port": port
})
+ @property
+ def _environment(self):
+ return self.ccnd.path
+
+ def execute_command(self, command, env):
+ environ = self.node.format_environment(env, inline = True)
+ command = environ + command
+ command = self.replace_paths(command)
+
+ return self.node.execute(command)
+
def valid_connection(self, guid):
# TODO: Validate!
return True