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
# ccnr needs to wait until ccnd is deployed and running
self.ec.schedule(reschedule_delay, self.deploy)
else:
- command = self._start_command
- env = self._environment
+ try:
+ if not self.get("command"):
+ self.set("command", self._start_command)
+
+ if not self.get("env"):
+ self.set("env", self._environment)
- self.set("command", command)
- self.set("env", env)
+ # set content to stdin, so the content will be
+ # uploaded during provision
+ self.set("stdin", self.get("content"))
- # set content to stdin, so the content will be
- # uploaded during provision
- self.set("stdin", self.get("content"))
+ command = self.get("command")
- self.info("Deploying command '%s' " % command)
+ self.info("Deploying command '%s' " % command)
- self.node.mkdir(self.app_home)
+ self.discover()
+ self.provision()
+ except:
+ self.fail()
+ raise
+
+ self.debug("----- READY ---- ")
+ self._ready_time = tnow()
+ self._state = ResourceState.READY
- # upload content
- self.upload_stdin()
+ def upload_start_command(self):
+ command = self.get("command")
+ env = self.get("env")
+ if command:
# We want to make sure the content is published
# before the experiment starts.
# Run the command as a bash script in the background,
# in the host ( but wait until the command has
# finished to continue )
- self.execute_command(command, env)
+ env = self.replace_paths(env)
+ command = self.replace_paths(command)
- self.debug("----- READY ---- ")
- self._ready_time = tnow()
- self._state = ResourceState.READY
+ (out, err), proc = self.execute_command(command, env)
+
+ if proc.poll():
+ self.fail()
+ msg = "Failed to execute command"
+ self.error(msg, out, err)
+ raise RuntimeError, msg
def start(self):
if self._state == ResourceState.READY:
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